SIOCGIFADDR broken on 9.0-RC1?

Kristof Provost kristof at sigsegv.be
Tue Nov 15 22:14:56 UTC 2011


On 2011-11-15 18:10:01 (+0100), GR <freebsd at gomor.org> wrote:
> more insights since my last post. Here is a small code to trigger the bug (end of email).
> When you run it on 9.0-RC1, it gets an alias address instead of the main inet address:
> 
> % ./get-ip re0          
> inet: 192.168.2.10
> # Main address being 192.168.1.148
> 
> On 8.2-RELEASE, all goes well:
> % ./get-ip re0
> inet: PUBLIC_IP4
> 
> Is something broken, or a behaviour has changed since 8.2-RELEASE?
> 

I think the relevant bit of the code is found in sys/netinet/in.c.

If your ioctl doesn't specify an IP address we end up in this bit:
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
        iap = ifatoia(ifa);
        if (iap->ia_addr.sin_family == AF_INET) {
                if (td != NULL &&
                    prison_check_ip4(td->td_ucred,
                    &iap->ia_addr.sin_addr) != 0)
                        continue;
                ia = iap;
                break;
        }
}

The 'ia' pointer is later used to return the IP address. 

In other words: it returns the first address on the interface
of type IF_INET (which isn't assigned to a jail). 

I think the order of the addresses is not fixed, or rather it depends on 
the order in which you assign addresses. In the handling of SIOCSIFADDR
new addresses are just appended:

TAILQ_INSERT_TAIL(&ifp->if_addrhead, ifa, ifa_link);

I don't believe this has changed since 8.0. Is it possible something
changed in the network initialisation, leading to the addresses being
assigned in a different order?

Eagerly awaiting to be told I'm wrong,
Kristof



More information about the freebsd-stable mailing list