tech-net archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: getifaddrs(3) returns 2 AF_LINK instances for the same interface
On Fri, Apr 17, 2009 at 09:35:55PM +0100, Roy Marples wrote:
> David Young wrote:
>> On Fri, Apr 17, 2009 at 08:55:15PM +0100, Roy Marples wrote:
>>> So something like this?
>>>
>>> Index: sys/net/rtsock.c
>>> ===================================================================
>>> RCS file: /cvsroot/src/sys/net/rtsock.c,v
>>> retrieving revision 1.125
>>> diff -u -p -r1.125 rtsock.c
>>> --- sys/net/rtsock.c 2 Apr 2009 21:02:06 -0000 1.125
>>> +++ sys/net/rtsock.c 17 Apr 2009 19:51:33 -0000
>>> @@ -1061,7 +1061,8 @@ sysctl_iflist(int af, struct rt_walkarg
>>> }
>>> }
>>> IFADDR_FOREACH(ifa, ifp) {
>>> - if (af && af != ifa->ifa_addr->sa_family)
>>> + if (ifa == ifp->if_dl ||
>>> + (af && af != ifa->ifa_addr->sa_family))
>>> continue;
>>> info.rti_info[RTAX_IFA] = ifa->ifa_addr;
>>> info.rti_info[RTAX_NETMASK] = ifa->ifa_netmask;
>>
>> The kernel copies out the interface information in an RTM_IFINFO
>> message, then each of the addresses in an RTM_NEWADDR message. There
>> is overlap between the _IFINFO and _NEWADDR information, but it's not
>> a *total* overlap, so you really do have to copy out one _NEWADDR per
>> ifaddr.
>
> So what info is present in _NEWADDR that isn't in _IFINFO for ifp->if_dl?
I don't know. You will have to find out. IIRC, one of the AF_LINK
records produced by getifaddrs(3) has the wrong netmask (should be
all-1s), and the other has the struct if_data filled out. I don't know
remember what other differences there are.
> How is userland supposed to pick the right AF_LINK or are they both right?
I guess it depends on your purposes which is right. There may be more
than two AF_LINK ifaddrs on an interface, BTW.
>> Have another look at the doco and source for getifaddrs(3). I think
>> that if there is a bug, you will find it there.
>
> I have checked and the last change of note was over 7 years ago.
> So are you suggesting that getifaddrs(3) should ignore the _IFINFO
> message or somehow merge it into the _NEWADDR one - if it's present?
Based on my recollections, above, my guess is that getifaddrs(3) should
merge the messages.
Dave
--
David Young OJC Technologies
dyoung%ojctech.com@localhost Urbana, IL * (217) 278-3933
Home |
Main Index |
Thread Index |
Old Index