Skip to content

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

@hickeng

Description

@hickeng

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureRequestIssues asking for a new feature that does not need a proposal.NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions