Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 15 Nov 2011 23:14:53 +0100
From:      Kristof Provost <kristof@sigsegv.be>
To:        GR <freebsd@gomor.org>
Cc:        freebsd-current@freebsd.org, freebsd-stable@freebsd.org
Subject:   Re: SIOCGIFADDR broken on 9.0-RC1?
Message-ID:  <20111115221453.GO53701@thebe.jupiter.sigsegv.be>
In-Reply-To: <ba681b9d-4096-4966-9fff-590716a78ed0@ubuntu64>
References:  <ee0855d0-f04c-4bdb-8578-bb9c74284f83@ubuntu64> <ba681b9d-4096-4966-9fff-590716a78ed0@ubuntu64>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2011-11-15 18:10:01 (+0100), GR <freebsd@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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111115221453.GO53701>