Skip to content

Commit

Permalink
Add link flags
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 4, 2024
1 parent 3613ac6 commit 215cfe8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions experimental/libbox/link_flags_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package libbox

import (
"net"
"syscall"
)

// copied from net.linkFlags
func linkFlags(rawFlags uint32) net.Flags {
var f net.Flags
if rawFlags&syscall.IFF_UP != 0 {
f |= net.FlagUp
}
if rawFlags&syscall.IFF_RUNNING != 0 {
f |= net.FlagRunning
}
if rawFlags&syscall.IFF_BROADCAST != 0 {
f |= net.FlagBroadcast
}
if rawFlags&syscall.IFF_LOOPBACK != 0 {
f |= net.FlagLoopback
}
if rawFlags&syscall.IFF_POINTOPOINT != 0 {
f |= net.FlagPointToPoint
}
if rawFlags&syscall.IFF_MULTICAST != 0 {
f |= net.FlagMulticast
}
return f
}
11 changes: 11 additions & 0 deletions experimental/libbox/link_flags_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//go:build !linux

package libbox

import (
"net"
)

func linkFlags(rawFlags uint32) net.Flags {
panic("stub!")
}
1 change: 1 addition & 0 deletions experimental/libbox/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type NetworkInterface struct {
MTU int32
Name string
Addresses StringIterator
Flags int32
}

type WIFIState struct {
Expand Down
1 change: 1 addition & 0 deletions experimental/libbox/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func (w *platformInterfaceWrapper) Interfaces() ([]control.Interface, error) {
MTU: int(netInterface.MTU),
Name: netInterface.Name,
Addresses: common.Map(iteratorToArray[string](netInterface.Addresses), netip.MustParsePrefix),
Flags: linkFlags(uint32(netInterface.Flags)),
})
}
return interfaces, nil
Expand Down

0 comments on commit 215cfe8

Please sign in to comment.