Page MenuHomeFreeBSD

Return first address for legacy ioctls SIOCGIFBRDADDR, SIOCGIFDSTADDR, SIOCGIFNETMASK and SIOCGIFADDR.
ClosedPublic

Authored by delphij on Aug 21 2014, 6:18 PM.

Details

Summary

The legacy ioctls, SIOCGIFADDR, SIOCGIFBRDADDR, SIOCGIFDSTADDR,
SIOCGIFNETMASK should return first address instead of testing against
the address passed in.

Test Plan

Run 'mdnsd --debug' from net/mDNSresponder.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

delphij retitled this revision from to Return first address for legacy ioctls SIOCGIFBRDADDR, SIOCGIFDSTADDR, SIOCGIFNETMASK and SIOCGIFADDR..
delphij updated this object.
delphij edited the test plan for this revision. (Show Details)
delphij added a reviewer: glebius.

Hi Xin,

Can you please explain what problem you were hitting that you'r trying to fix with this patch?

In D667#3, @hiren wrote:

Hi Xin,

Can you please explain what problem you were hitting that you'r trying to fix with this patch?

On -CURRENT, the 'mdnsd' will stop right after it starts. With ktrace it shows shows:

1005 mdnsd    CALL  ioctl(0x6,SIOCGIFNETMASK,0x7fffffffea40)
1005 mdnsd    RET   ioctl 0
1005 mdnsd    CALL  ioctl(0x6,SIOCGIFBRDADDR,0x7fffffffea40)
1005 mdnsd    RET   ioctl -1 errno 49 Can't assign requested address

Older versions of FreeBSD would return successfully. The usage in mdnsd can be found here (they should probably zero the ifreq structure before calling):

https://opensource.apple.com/source/mDNSResponder/mDNSResponder-544/mDNSPosix/mDNSUNP.c

hiren added a reviewer: hiren.

URL: http://svnweb.freebsd.org/changeset/base/257737

Log:

Fix my braino in r257692. For SIOCG*ADDR we don't need exact match on
specified address, actually in most cases the address isn't specified.

This looks like the relevant rev which broke it for you. As per my limited knowledge, the commit log says "For SIOCG*ADDR" but that change was only made for SIOCGIFADDR.

in that regard, your changes look good to me.

This revision is now accepted and ready to land.Aug 22 2014, 12:27 AM

Here you simply overwrite anything that user has supplied into INADDR_ANY. I will not be surprised if that would break a lot (albeit fixing mDNS).

delphij edited the test plan for this revision. (Show Details)
delphij edited edge metadata.

Updated patch: this reverts the code to previous behavior: match if possible, and
first if not found, finally if nothing found give error.

Updating D667: Return first address for legacy ioctls SIOCGIFBRDADDR, SIOCGIFDSTADDR,

SIOCGIFNETMASK and SIOCGIFADDR.

In D667#10, @glebius wrote:

Here you simply overwrite anything that user has supplied into INADDR_ANY. I will not be surprised if that would break a lot (albeit fixing mDNS).

Good point. I have re-read the code in FreeBSD stable/5 and stable/10 and now have a different patch, can you review it and see if this one would address compatibility concerns?

You don't need prison_check_ip4(), it was already done above.

In D667#15, @glebius wrote:

You don't need prison_check_ip4(), it was already done above.

I think I do need that check: the previous check is on the request (so that jailed process can not use these ioctls to determine if the host system have an IP address). The new check is to prevent jailed process to know the first IP address...

Gleb's version of patch.

Updating D667: Return first address for legacy ioctls SIOCGIFBRDADDR, SIOCGIFDSTADDR,

SIOCGIFNETMASK and SIOCGIFADDR.

Gleb have found another issue that the existing code would return first IP if INADDR_ANY is specified. This would also be a subtle issue when jail is used.

I think this version is good to go.

delphij updated this revision to Diff 1231.

Closed by commit rS270347 (authored by @delphij).