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: Incorrect handling of IP numbered addressing over ethernet link encapsulation #11338

Closed
aulanov opened this issue Jun 22, 2015 · 7 comments
Milestone

Comments

@aulanov
Copy link

aulanov commented Jun 22, 2015

We have an ethernet interface configured as follows:

$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1460 qdisc pfifo_fast state UP qlen 1000
    link/ether 42:01:0a:f0:62:56 brd ff:ff:ff:ff:ff:ff
    inet 10.240.98.86 peer 10.240.0.1/32 brd 10.240.98.86 scope global eth0
       valid_lft forever preferred_lft forever

For this interface net.Interface.Addrs() returns 10.240.0.1 instead of 10.240.98.86

$ cat ip.go 
package main

import (
    "log"
    "net"
)

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

    for _, intf := range intfs {
        intf, err := net.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)
        }
    }
}
$ go run ip.go
2015/06/22 23:21:57 lo
2015/06/22 23:21:57     127.0.0.1/8
2015/06/22 23:21:57 eth0
2015/06/22 23:21:57     10.240.0.1/32
@aulanov
Copy link
Author

aulanov commented Jun 22, 2015

Relevant piece of code: http://golang.org/src/net/interface_linux.go#L175
In this case IFA_LOCAL is 10.240.98.86 and IFA_ADDRESS is 10.240.0.1. FlagPointToPoint is not set.

As far as I can tell this function should always use IFA_LOCAL whenever it's available regardless of PointToPoint flag.
Here's relevant piece of code from iproute2 (i.e. "ip" command implementation):

        if (!rta_tb[IFA_LOCAL])
                rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS];
        if (!rta_tb[IFA_ADDRESS])
                rta_tb[IFA_ADDRESS] = rta_tb[IFA_LOCAL];

...

        if (rta_tb[IFA_LOCAL]) {
                fprintf(fp, "%s", format_host(ifa->ifa_family,
                                              RTA_PAYLOAD(rta_tb[IFA_LOCAL]),
                                              RTA_DATA(rta_tb[IFA_LOCAL]),
                                              abuf, sizeof(abuf)));

                if (rta_tb[IFA_ADDRESS] == NULL ||
                    memcmp(RTA_DATA(rta_tb[IFA_ADDRESS]), RTA_DATA(rta_tb[IFA_LOCAL]),
                           ifa->ifa_family == AF_INET ? 4 : 16) == 0) {
                        fprintf(fp, "/%d ", ifa->ifa_prefixlen);
                } else {
                        fprintf(fp, " peer %s/%d ",
                                format_host(ifa->ifa_family,
                                            RTA_PAYLOAD(rta_tb[IFA_ADDRESS]),
                                            RTA_DATA(rta_tb[IFA_ADDRESS]),
                                            abuf, sizeof(abuf)),
                                ifa->ifa_prefixlen);
                }
        }

@mikioh mikioh changed the title Incorrect handling of ip addresses in src/net/interface_linux.go net: Incorrect handling of IP numbered addressing over broadcast link encapsulation Jun 22, 2015
@mikioh
Copy link
Contributor

mikioh commented Jun 22, 2015

Thanks for the report. Which version of Linux are you running?

@aulanov
Copy link
Author

aulanov commented Jun 22, 2015

$ uname -s -r 
Linux 3.18.0

@mikioh
Copy link
Contributor

mikioh commented Jun 22, 2015

Out of curiosity, what's the purpose of that configuration to eth0? Are you running sort of segmented routing stuff?

@mikioh mikioh added this to the Go1.5 milestone Jun 22, 2015
@aulanov
Copy link
Author

aulanov commented Jun 23, 2015

The node is a VM running inside Google Cloud Compute Engine. The interface is essentially point-to-point interface (even though not marked as such) where 10.240.0.1 acts as a gateway to the outside world. Not sure if setting the peer IP really changes anything, though.

@mikioh mikioh changed the title net: Incorrect handling of IP numbered addressing over broadcast link encapsulation net: Incorrect handling of IP numbered addressing over ethernet link encapsulation Jun 23, 2015
@mikioh
Copy link
Contributor

mikioh commented Jun 23, 2015

https://golang.org/cl/11352

Hm, the bot stops to mention changes.

@gopherbot
Copy link

CL https://golang.org/cl/11352 mentions this issue.

@mikioh mikioh closed this as completed in 258bf65 Jun 27, 2015
@golang golang locked and limited conversation to collaborators Jun 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants