Bug 8736

Summary: IPV6 forced on in busybox
Product: buildroot Reporter: Kenric Smith <ksmith>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: trivial CC: buildroot
Priority: P5    
Version: 2015.11   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Host: Target:
Build:
Attachments: Patch to package makefile to remove forcing IPV6

Description Kenric Smith 2016-03-03 17:07:18 UTC
Created attachment 6371 [details]
Patch to package makefile to remove forcing IPV6

It appears from the commit logs that the IPV6 config option was removed for buildroot, but the remnants of the removal are forcing FEATURE_IPV6 in busybox.  The attached patch would remove setting that feature in busybox.

Without this patch, the ntpd applet in busybox doesn't function properly, attempting to contact IPV6 hosts.
Comment 1 Peter Korsgaard 2016-03-03 20:59:56 UTC
(In reply to Kenric Smith from comment #0)

That sounds like a bug in busybox that should be fixed instead of worked around then. What exactly goes wrong? Have you reported the bug to the busybox developers?
Comment 2 Kenric Smith 2016-03-03 21:05:45 UTC
Sorry for the confusion.  Busybox is acting as it should, the issue is that Buildroot is telling Busybox to enable IPV6 no matter what.  For Buildroot systems where IPV6 is not enabled (in the kernel), Buildroot shouldn't enable IPV6 in Busybox.

Previously it appears that IPV6 was a Buildroot configuration option and that option was properly being passed into Busybox.  When that option was removed, IPV6 was forced on in Busybox by the Buildroot configuration.

The patch attached just allows Busybox to be configured or not for IPV6, in the menuconfig option of Busybox, instead of forcing it to be enabled in Busybox.
Comment 3 Peter Korsgaard 2016-03-03 21:09:48 UTC
(In reply to Kenric Smith from comment #0)

Notice: I'm not against us removing the forced IPv6 (and just enable it in the default defconfig instead). We should probably also do it for largefile now that we always have that enabled, but I would like to understand what the problem is you are seeing.

I did a quick test with qemu_arm_versatile_defconfig and the busybox defconfig tweaked to enable the ntpd daemon, and everything seems to work OK here:

# date
Thu Jan  1 00:00:50 UTC 1970
# ntpd -d -n -p pool.ntp.org
ntpd: sending query to 77.243.43.213
ntpd: reply from 77.243.43.213: offset:+1457039097.162244 delay:0.036664 status:0x24 strat:2 refid:0xf00726c0 rootdelay:0.003418 reach:0x01
ntpd: sending query to 77.243.43.213
ntpd: reply from 77.243.43.213: offset:+1457039097.161038 delay:0.032410 status:0x24 strat:2 refid:0xf00726c0 rootdelay:0.003418 reach:0x03
ntpd: setting time to 2016-03-03 21:06:05.090957 (offset +1457039097.161038s)
ntpd: sending query to 77.243.43.213
ntpd: reply from 77.243.43.213: offset:+0.001327 delay:0.033226 status:0x24 strat:2 refid:0xf00726c0 rootdelay:0.003418 reach:0x07
Comment 4 Kenric Smith 2016-03-03 21:13:15 UTC
Try ntp.vt.edu.

When I try it, I get:


[root ~]# nslookup ntp.vt.edu
Server:    ********
Address 1: ********

Name:      ntp.vt.edu
Address 1: 2001:468:c80:2101:0:14b:a768:154f ntp-1.ipv6.vt.edu
Address 2: 198.82.247.108 ntp-3.vt.edu
Address 3: 198.82.247.51 ntp-1.vt.edu
Address 4: 198.82.247.131 ntp-4.vt.edu
Address 5: 198.82.247.71 ntp-2.vt.edu


[root ~]# ntpd -w -p ntp.vt.edu
ntpd: socket: Address family not supported by protocol
Comment 5 Kenric Smith 2016-03-03 21:17:57 UTC
I should have added, with the patch enabled, I get this behavior:

[root ~]# nslookup ntp.vt.edu
Server:    *******
Address 1: *******

Name:      ntp.vt.edu
Address 1: (null)
Address 2: 198.82.247.51 ntp-1.vt.edu
Address 3: 198.82.247.131 ntp-4.vt.edu
Address 4: 198.82.247.108 ntp-3.vt.edu
Address 5: 198.82.247.71 ntp-2.vt.edu

[root ~]# ntpd -w -d -p ntp.vt.edu
ntpd: sending query to 198.82.247.131
ntpd: reply from 198.82.247.131: offset:+21623.503688 delay:0.048829 status:0x24 strat:2 refid:0xa4f752c6 rootdelay:0.000381 reach:0x01
Comment 6 Peter Korsgaard 2016-03-03 21:43:14 UTC
(In reply to Kenric Smith from comment #4)

So I tried again, this time with IPv6 support disabled in the kernel but enabled in the toolchain (external codesourcery/glibc):

buildroot login: root
# ifconfig 
eth0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1152 (1.1 KiB)  TX bytes:684 (684.0 B)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

# date
Thu Jan  1 00:00:13 UTC 1970

# ntpd -w -p ntp.vt.edu
ntpd: reply from 198.82.247.51: offset:+1457040206.437536 delay:0.123510 status:0x24 strat:2 refid:0xa4f752c6 rootdelay:0.000351 reach:0x01
ntpd: reply from 198.82.247.51: offset:+1457040206.437670 delay:0.109456 status:0x24 strat:2 refid:0xa4f752c6 rootdelay:0.000351 reach:0x03
ntpd: reply from 198.82.247.51: offset:+1457040206.438839 delay:0.109959 status:0x24 strat:2 refid:0xa4f752c6 rootdelay:0.000351 reach:0x07
ntpd: reply from 198.82.247.51: offset:+1457040206.437485 delay:0.107279 status:0x24 strat:2 refid:0xa4f752c6 rootdelay:0.000351 reach:0x0f
random: nonblocking pool is initialized

So that works. If I instead try ntp-1.ipv6.vt.edu (which only has an AAAA record) it indeed fails:

# ntpd -w -p ntp-1.ipv6.vt.edu
ntpd: socket: Address family not supported by protocol

Which makes sense as it cannot create an IPv6 socket:
socket(PF_INET6, SOCK_DGRAM, IPPROTO_IP) = -1 EAFNOSUPPORT (Address family not supported by protocol)
write(2, "ntpd: socket: Address family not"..., 55ntpd: socket: Address family not supported by protocol
) = 55

Looking at the ntpd code, it ends up calling xhost2sockaddr() on the peer name, which ends up doing a getnameinfo() with AF_UNSPEC, and using the first result without checking that it can create a socket - So if your C library prefers IPv6 over IPv4 this explains it.

The function does contain a workaround though: If you enable ENABLE_FEATURE_PREFER_IPV4_ADDRESS then it will use the first AF_INET result if available.

What C library do you use?
Comment 7 Kenric Smith 2016-03-03 21:47:05 UTC
uClibc-ng and the default config file for it.
Comment 8 Kenric Smith 2016-03-03 22:33:26 UTC
Confirmed setting ENABLE_FEATURE_PREFER_IPV4_ADDRESS also corrects the behavior. 

I personally still think forcing IPV6 in Busybox isn't great, but I also understand if you don't want to change the configuration.

Feel free to close the issue as resolved, if you want to change the forced IPV6 in Busybox is up to you. (it results in a 20% larger executable for me)
Comment 9 Kenric Smith 2016-03-03 22:40:51 UTC
Disregard 20% comment. It was incorrect, it is only slightly larger.
Comment 10 Peter Korsgaard 2016-03-04 16:10:53 UTC
Fixed in git by:

commit 7a5be2a042f3c1d55c5599ad819333a2150955ff
Author: Peter Korsgaard <peter@korsgaard.com>
Date:   Fri Mar 4 16:47:38 2016 +0100

    busybox: tweak IPv6/largefile handling
    
    Fixes #8736
    
    When IPv6 and largefile options were removed from Buildroot, the code to
    force these options in busybox were still left in.
    
    There's no strong reason to forcefully enable these options (only to disable
    options if the system cannot support it like we do for nommu), so instead
    enable the options in our default defconfig, allowing people to override
    this if they use a custom config.
    
    While we're at it, enable the prefer-ipv4 option so network applets like
    ntpd doesn't fail when dual stacked hosts are resolved from a system without
    IPv6 support enabled in the kernel.
    
    Signed-off-by: Peter Korsgaard <peter@korsgaard.com>