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

net: add Sys field to Interface for retrieving platform-specific information #17445

Open
hickeng opened this issue Oct 14, 2016 · 15 comments
Open
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@hickeng
Copy link

hickeng commented Oct 14, 2016

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

go version go1.7 linux/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/vagrant/vicsmb"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build018341538=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"

What did you do?

package main

import (
    "fmt"
    "net"
    "os"
    "os/exec"
)

func main() {

    alias := "testalias"

    ipalias := exec.Command("/sbin/ip", "link", "set", "dev", "lo", "alias", alias)
    _, err := ipalias.CombinedOutput()
    if err != nil {
        fmt.Printf("failed to invoke /sbin/ip to set alias on loopback interface: %s", err)
        os.Exit(1)
    }

    intf, err := net.InterfaceByName(alias)
    if intf == nil {
        fmt.Printf("failed to locate interface by alias %s: %s\n", alias, err)
        os.Exit(1)
    }

    fmt.Println("success!!")
}

What did you expect to see?

Aliasing link lo
success!!

What did you see instead?

Aliasing link lo
failed to locate interface by alias testalias: route ip+net: no such network interface

#  ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    alias testalias

If InterfaceByName doens't check aliases on systems that support them then interface aliases become problematic. If you have to know that the name is an aliases it defeats the point.

@robpike
Copy link
Contributor

robpike commented Oct 14, 2016

Can you please create a reproducing case for this that does not involve an external repository?

@hickeng
Copy link
Author

hickeng commented Oct 14, 2016

@robpike updated to invoke /sbin/ip instead of setting alias inline.

@mikioh mikioh changed the title InterfaceByName ignores interface aliases net: InterfaceByName ignores interface aliases Oct 14, 2016
@mikioh
Copy link
Contributor

mikioh commented Oct 14, 2016

Any good use case of IFLA_IFALIAS doesn't come to my mind.

# ip link set alias lo rack/chassis/slot/port-convention

# ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    alias rack/chassis/slot/port-convention

# ip link show rack/chassis/slot/port-convention
Device "rack/chassis/slot/port-convention" does not exist.

# ip addr add 1.2.3.4/24 dev rack/chassis/slot/port-convention
Device "rack/chassis/slot/port-convention" does not exist.

# ip route add 10.0.0.0/16 nexthop dev rack/chassis/slot/port-convention
Cannot find device "rack/chassis/slot/port-convention"

Besides current API doesn't expose such platform-specific information for consistency across platforms; for example, it never displays information related to route-labels, similar to IFLA_IFALIAS of Linux, on OpenBSD. I'm fine to have x/net/netlink package for some Linux-specific use case as we have x/net/route for BSD variants, but I'm not keen to add support for IFLA_IFALIAS into net package.

@hickeng
Copy link
Author

hickeng commented Oct 15, 2016

@mikioh I'll admit the internet's not been much help in explaining an intended use of alias outside of https://tools.ietf.org/html/rfc2233 - however I'm wanting to use it for exactly that case (although not formally an NMA):

ifAlias, provides a location in which a network management application can store a non-volatile interface-naming value of its own choice

That the ip command semantics don't abide by the dictionary definition of alias is a different conversation, although consistency can be an extremely compelling argument.

@mikioh
Copy link
Contributor

mikioh commented Oct 16, 2016

For pure management plane or hybrid control/management plane stuff, how about this?

  • Add Sys field to the existing Interface struct to expose platform-specific information the same as os.FileInfo, os.ProcAttr
  • Network interface identification API never retrieves aliases, descriptions or other opaque strings as its key to avoid unnecessary confusion for interworking w/ de facto or de jule protocols that transport interface names

@bradfitz
Copy link
Contributor

@mikioh, and I assume the Sys field would be of type interface{}? What's the concrete type of the net.Interface.Sys value you'd put in there for, say, Linux?

@quentinmit quentinmit added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 17, 2016
@quentinmit
Copy link
Contributor

Are interface aliases in the same namespace as interface names? Can I add the alias lo to my eth0 interface or does that fail?

@quentinmit quentinmit added this to the Unplanned milestone Oct 17, 2016
@mikioh
Copy link
Contributor

mikioh commented Oct 18, 2016

On Linux IFLA_IFALIAS is an attribute that represents an opaque string member in netdevice structure. It doesn't collaborate with any control plane process.

Can I add the alias lo to my eth0

Yes.

@mikioh
Copy link
Contributor

mikioh commented Oct 18, 2016

I'd like to see Sys []interface{} rather than Sys interface{} to separate at least miscellaneous data and statistical information. On Linux I guess that type InterfaceData { Alias string /* interface alias */; Type int /* platform-dependent interface type */} is enough as a first step. Anyway I'd like to know how @hickeng feels about it.

@mikioh mikioh added WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed OS-Linux labels Oct 18, 2016
@hickeng
Copy link
Author

hickeng commented Oct 25, 2016

@mikioh If alias aren't used as a direct alias for interface names in InterfaceByName then I'd be fine with any implementation that allows me to associate an application role with an interface. Aliases seemed a neat way of doing so.

Bit of background - I'm associating various aspects of the system with application level roles so that one program can set those up, and others can use a known name at build time to acquire the XXX that they need.
Other devices you can use mknod to create a duplicate device node in a known location, ditto with symlinks for anything that presents as a file. I couldn't find something similar to allow mapping of an interface to a role however; not one that is viable if multiple roles share that interface. IP address yes, but interface no.

@mikioh
Copy link
Contributor

mikioh commented Oct 25, 2016

@hickeng,

Do you want to see this Sys feature in Go 1.8? Or not so rush?

@mikioh mikioh changed the title net: InterfaceByName ignores interface aliases net: add Sys field to Interface for retrieving platform-specific information Oct 25, 2016
@mikioh
Copy link
Contributor

mikioh commented Oct 25, 2016

Bit of background

Perhaps, you can share your pain with people who are working on NETCONF+NETMOD, ASN.1+MIB+SNMP, Telcordia or 3GPP OSS/BSS stuff. ;)

@mikioh
Copy link
Contributor

mikioh commented Oct 28, 2016

31st October is the cut-off day for Go 1.8, so this doesn't happen in Go 1.8.

@hickeng
Copy link
Author

hickeng commented Nov 7, 2016

@mikioh Apologies for the silence - we've had to take an alternate path already so no rush.

@mikioh mikioh removed the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 16, 2016
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/162037 mentions this issue: net, syscall: add Sys field to Interface for system-dependent information

@seankhliao seankhliao added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

7 participants