Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/net: expose LOWER_UP flag in NICs #42488

Open
x1unix opened this issue Nov 10, 2020 · 7 comments
Open

x/net: expose LOWER_UP flag in NICs #42488

x1unix opened this issue Nov 10, 2020 · 7 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@x1unix
Copy link

x1unix commented Nov 10, 2020

What version of Go are you using (go version)?

$ go version 1.15.4

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/x1unix/.cache/go-build"
GOENV="/home/x1unix/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/x1unix/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/x1unix/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS="-w"
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build478690309=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Hello. I want to be able to detect if network interface is physical or virtual.
In Linux, there is a special LOWER_UP flag that indicates that NIC is physical, not virtual.

Currently, net package exposes only a few flags, but not LOWER_UP flag:

const (
	FlagUp           Flags = 1 << iota // interface is up
	FlagBroadcast                      // interface supports broadcast access capability
	FlagLoopback                       // interface is a loopback interface
	FlagPointToPoint                   // interface belongs to a point-to-point link
	FlagMulticast                      // interface supports multicast access capability
)

LOWER_UP is described as IFF_LOWER_UP at include/uapi/linux/if.h

What did you expect to see?

Can you add please LowerUp flag to net package?

What did you see instead?

@gopherbot gopherbot added this to the Unreleased milestone Nov 10, 2020
@networkimprov
Copy link

networkimprov commented Nov 12, 2020

cc @odeke-em @ianlancetaylor

@cagedmantis cagedmantis changed the title x/net: [feature] expose LOWER_UP flag in NICs x/net: expose LOWER_UP flag in NICs Nov 13, 2020
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 13, 2020
@cagedmantis
Copy link
Contributor

/cc @bradfitz @ianlancetaylor

@prattmic prattmic changed the title x/net: expose LOWER_UP flag in NICs net: expose LOWER_UP flag in NICs Dec 11, 2020
@GanShun
Copy link

GanShun commented Dec 11, 2020

Hi, the Uroot team also has an ip implementation at https://github.com/u-root/u-root/tree/master/cmds/core/ip which at this point uses net.Flags. This means we're restricted to displaying only the 5 flags currently supported. While we could read the raw flags directly and do all the parsing ourselves, it seems like it would be much nicer to have the official net package support it.

@ianlancetaylor
Copy link
Contributor

I'm not clear if this should be in the net package or the x/net package.

I don't see any difficulty to adding it to the x/net package.

@prattmic
Copy link
Member

The existing type is in the net package, so I think any additions would have to go there: https://cs.opensource.google/go/go/+/master:src/net/interface.go;l=30-46;drc=58e381b0b22352dda355f6d95fa101b773766c72?ss=go

Interface could also potentially have a RawFlags method that returns the underlying OS-specific flags, though I'm not sure if that would be useful to folks, or if having the OS-neutral flags is the main benefit here.

@x1unix
Copy link
Author

x1unix commented Dec 12, 2020

@prattmic is it possible to introduce a flag with OS-neutral name but with the same purposes?
Windows also allows to check if NIC is virtual or physical, so this solution can be cross-platform.

@prattmic
Copy link
Member

@x1unix I'm not really the best person to answer that question, as I'm not particularly involved in net. That sounds reasonable to me (net.Flags is in fact an OS-neutral type). I don't think it would work for @GanShun's use case, which IIUC, depends on net.Flags.String() returning the Linux name, but perhaps that is just out of scope.

@x1unix x1unix changed the title net: expose LOWER_UP flag in NICs x/net: expose LOWER_UP flag in NICs Oct 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

7 participants