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: Interface.Addrs doesn't return any configured & connected IPv6 addresses on point-to-point link for Linux #6433

Closed
gopherbot opened this issue Sep 20, 2013 · 9 comments

Comments

Projects
None yet
3 participants
@gopherbot
Copy link

commented Sep 20, 2013

by justin@fathomdb.com:

I noticed that some interfaces did not return any IP addresses from Addrs(), but e.g. ip
addr show would show the IP addresses.

By hacking up the code, I believe the issue is here:

http://golang.org/src/pkg/net/interface_linux.go?#L152

if ifi.Flags&FlagPointToPoint != 0 && a.Attr.Type == syscall.IFA_LOCAL ||
   ifi.Flags&FlagPointToPoint == 0 && a.Attr.Type == syscall.IFA_ADDRESS {

I have an IP address that is up|pointtopoint|multicast, but the address type is
IFA_LOCAL.  This is an IPv6 address on a SSH-created tunnel device.  I added the IP
address myself using ip addr add, so I may well have done it wrong.

But, ip addr show does show the IP, whereas Go skips over it.

I'm not quite sure of the logic behind the skipping.

Here's how to reproduce...

sudo ssh -f -N -i ~username/.ssh/id_rsa -w99:99 root@SERVER_IP
sudo ip addr add 172.16.1.1/24 dev tun99
sudo ip addr add fd00::f00d/96 dev tun99
sudo ip link set tun99 up


A quick test program...

package main

import (
    "log"
    "net"
)

func main() {
    intfs, err := net.Interfaces()
    if err != nil {
        log.Panic(err)
    }

    for _, intf := range intfs {
        intf, err := InterfaceByName(intf.Name)
        if err != nil {
            log.Panic(err)
        }

        addrs, err := intf.Addrs()
        if err != nil {
            log.Panic(err)
        }

        log.Printf("%v", intf.Name)
        for _, addr := range addrs {
            log.Printf("\t%s", addr)
        }
    }

    log.Printf("DONE")
}

This prints (the relevant bit for tun99):

2013/09/20 11:42:31 tun99
2013/09/20 11:42:31     172.16.1.1/24


The IPv6 address is missing.  "ip addr show" includes it:

ip addr show dev tun99

63: tun99: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 500
    link/none 
    inet 172.16.1.1/24 scope global tun99
    inet6 fd00::f00d/128 scope global 
       valid_lft forever preferred_lft forever



By hacking up newAddr to insert a println when the loop condition is not hit:

    log.Printf("Skipped: %v %v", ifi, a.Attr.Type)

2013/09/20 11:44:44 Skipped: &{63 1500 tun99  up|pointtopoint|multicast} 1
2013/09/20 11:44:44 Skipped: &{63 1500 tun99  up|pointtopoint|multicast} 1
2013/09/20 11:44:44 Skipped: &{63 1500 tun99  up|pointtopoint|multicast} 6



So I think the problem is that - for the Ipv6 address on the pointtopoint tun device,
we're only getting an IFA_ADDRESS record, and no IFA_LOCAL record.
@mikioh

This comment has been minimized.

Copy link
Contributor

commented Sep 21, 2013

Comment 2:

/usr/include/linux/if_addr.h:
/*
 * Important comment:
 * IFA_ADDRESS is prefix address, rather than local interface address.
 * It makes no difference for normally configured broadcast interfaces,
 * but for point-to-point IFA_ADDRESS is DESTINATION address,
 * local address is supplied in IFA_LOCAL attribute.
 */
enum {
        IFA_UNSPEC,
        IFA_ADDRESS,
        IFA_LOCAL,
        IFA_LABEL,
        IFA_BROADCAST,
        IFA_ANYCAST,
        IFA_CACHEINFO,
        IFA_MULTICAST,
        __IFA_MAX,
};
@mikioh

This comment has been minimized.

Copy link
Contributor

commented Sep 21, 2013

Comment 3:

Labels changed: added go1.2, removed priority-triage.

Status changed to Accepted.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Sep 24, 2013

Comment 4:

Labels changed: added go1.2maybe, removed go1.2.

Owner changed to @mikioh.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Oct 2, 2013

Comment 5:

Labels changed: added go1.3, removed go1.2maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 6:

Labels changed: added release-go1.3.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 7:

Labels changed: removed go1.3.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 8:

Labels changed: added repo-main.

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 14, 2014

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Feb 14, 2014

Comment 10:

This issue was closed by revision 8c0a52f.

Status changed to Fixed.

@rsc rsc added this to the Go1.3 milestone Apr 14, 2015

@rsc rsc removed the release-go1.3 label Apr 14, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.