Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ioctl SIOCGIFCONF Returns Details of disconnected adapters (and shouldn't) #3904

Closed
f948lan opened this issue Mar 8, 2019 · 4 comments
Closed

Comments

@f948lan
Copy link

f948lan commented Mar 8, 2019

Your Windows build number:

  • Version 10.0.18346.1

What you're doing and what's happening:
Using software that gets a list of local IPs using SIOCGIFCONF ioctl
On WSL, this includes disconnected adapters, like bluetooth adapter and (3!) wifi adapters, showing 169.x.x.x address for each. Running ifconfig -a also lists these as configured addresses:

root@DESKTOP-G9KNLSL:~# ifconfig -a
eth0: flags=64<RUNNING>  mtu 1500
        inet 169.254.126.141  netmask 255.255.0.0
        inet6 fe80::fd22:dd14:d7:7e8d  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 44:1c:a8:e1:4c:bc  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=64<RUNNING>  mtu 1500
        unspec [NONE SET]  netmask 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
        ether 9c:eb:e8:35:4c:72  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.30.2.130  netmask 255.255.255.0  broadcast 172.30.2.255
        inet6 fe80::c9f4:5dff:f4d9:4c69  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 20:47:47:f5:9d:b2  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 1500
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0xfe<compat,link,site,host>
        loop  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wifi0: flags=64<RUNNING>  mtu 1500
        inet 169.254.228.39  netmask 255.255.0.0
        inet6 fe80::acf2:ea6e:3033:e427  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 44:1c:a8:e1:4c:bb  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wifi1: flags=64<RUNNING>  mtu 1500
        inet 169.254.169.58  netmask 255.255.0.0
        inet6 fe80::f94d:41a0:9ebd:a93a  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 46:1c:a8:e1:4c:bb  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wifi2: flags=64<RUNNING>  mtu 1500
        inet 169.254.79.97  netmask 255.255.0.0
        inet6 fe80::708c:2910:4e37:4f61  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 46:1c:a8:e1:44:bb  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

What's wrong / what should be happening instead:
This information is false. The addresses are not bound locally and not in the routing table. Any attempt to connect to these will result in trying to use the default route and an eventual timeout. This affects the behavior of software that relies on this method.

ipconfig in Windows correctly lists them as disconnected:

C:\WINDOWS\system32>ipconfig

Windows IP Configuration


Ethernet adapter Ethernet 4:

   Connection-specific DNS Suffix  . : office.alatronic.com
   Link-local IPv6 Address . . . . . : fe80::c9f4:5dff:f4d9:4c69%26
   IPv4 Address. . . . . . . . . . . : 172.30.2.130
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 172.30.2.1

Wireless LAN adapter Wi-Fi:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . : office.alatronic.com

Wireless LAN adapter Local Area Connection* 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Wireless LAN adapter Local Area Connection* 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

Ethernet adapter Bluetooth Network Connection:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :

On a real Linux system ifconfig -a will show disconnected interfaces with no IP address, and SIOCGIFCONF will not list them:

debian:~$ ifconfig -a
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 08:00:27:72:c3:ec  txqueuelen 1000  (Ethernet)
        RX packets 567384  bytes 240661678 (229.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 393510  bytes 468220693 (446.5 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 310620  bytes 382544575 (364.8 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 310620  bytes 382544575 (364.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Strace of the failing command, if applicable:

WSL:

root@DESKTOP-G9KNLSL:~# strace ifconfig 2>&1 | grep SIOCGIFCONF
ioctl(3, SIOCGIFCONF, {30 * sizeof(struct ifreq) => 6 * sizeof(struct ifreq), [{ifr_name="eth0", ifr_addr={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("169.254.126.141")}}, {ifr_name="eth2", ifr_addr={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("172.30.2.130")}}, {ifr_name="lo", ifr_addr={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")}}, {ifr_name="wifi0", ifr_addr={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("169.254.228.39")}}, {ifr_name="wifi1", ifr_addr={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("169.254.169.58")}}, {ifr_name="wifi2", ifr_addr={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("169.254.79.97")}}]}) = 0

(All interfaces showing with 169.x.x.x addresses are not actually connected, as shown above in windows ipconfig output).

Linux VM, disconnected adapter:

debian:~$ strace ifconfig 2>&1 | grep SIOCGIFCONF
ioctl(4, SIOCGIFCONF, {30 * sizeof(struct ifreq) => 1 * sizeof(struct ifreq), [{ifr_name="lo", ifr_addr={sa_family=AF_INET, sin_port=htons(0), sin_addr=inet_addr("127.0.0.1")}}]}) = 0

Only lo shown, as enp0s3 has no IP.

@therealkenc
Copy link
Collaborator

therealkenc commented Mar 9, 2019

Ref #3368 (message) which is related.

As many details about your actual Windows 10 setup (hardware and 3rd party software) will help a lot here, because (like the #3368 post) the devs in Redmond won't be able to repro your case exactly. Also ipconfig.exe /all output just to make sure we're getting everything Windows thinks is there.

The VM and bare metal Linux analogies are problematic because with WSL, if Windows thinks those interfaces exist -- then they exist. But granted entirely: one can quibble over whether a given interface is <RUNNING> but it sure ain't <UP>. It doesn't make sense to have a not-UP interface with an assigned IP address.

I suspect WSL could be improved at least a little to fudge the fact we don't have iwconfig(1). If those wifi adapters aren't in a connected state maybe those interfaces could (should?) be filtered outright, <RUNNING> or otherwise. But if Windows (contrast say Linux in a VM with virtual interfaces) really does think you have three hardwired ethernet addresses (sic) then they'd show up in ifconfig -a. [In an alternate WSL universe one could even imagine being able to bring them <UP>.]

@f948lan
Copy link
Author

f948lan commented Mar 10, 2019

I can post ipconfig /all on Monday when I'm back in the office, but I think you may be misunderstanding the issue I'm raising here, so just to clarify a couple of points now:

  • The issue is not that the adapters are listed in ifconfig /all - that's expected even for disconnected adapters. The issue is that they are reported as having an IP (v4) address when they do not.
    • Per the documentation SIOCGIFCONF should only return adapters with IPv4 addresses
    • The (169.x.x.x) addresses reported for the disconnected adapters are false. They are not bound and do not respond (eg. to ping from the local machine). As exemplified in ROS Gazebo black screen #3368 above, some software uses this to find an address to connect back to the local system, so reporting invalid addresses causes such software to fail.
    • iwconfig or Wifi in particular are nothing (specifically) to do with this issue. (It just so happens in my example above that the output of ifconfig above is confused by the appearance of 3 wifi adapters, all with false address, when there is only one real adapter present. But that is not what this ticket is for - I suspect that's related to Windows renaming the adapter when an updated driver was installed).
    • You will see there are also two LAN adapters (in this case USB devices the system has seen before but are not even connected to the USB bus at the point I ran the commands above) and the Bluetooth Adapter, all listed by ifconfig. Two of which show IP addresses that are not active.
  • After posting I also reproduced the same on another (1809 build) system. It's very easy to reproduce:
    • Have a disconnected network adapter - wired with cable pulled, wifi disconnected, bluetooth adapter disconnected, they will all highlight this issue in my experience.
    • Run ifconfig /all
    • See the disconnected adapter listed with a 169.x.x.x address
    • Try ping false-169-address
    • Watch the ping fail as the address does not respond.

Note: Thinking about it I suspect the adapter may have to be configured for DHCP for this to happen. Will be interesting to see what the behaviour is in the case of a disconnected adapter that was previously configured with a static IPv4 address. Will try and test this Monday.

Hope that helps.

@therealkenc
Copy link
Collaborator

therealkenc commented Mar 10, 2019

but I think you may be misunderstanding the issue I'm raising here

No you were quite clear in your description. Verbose. But clear.

The issue is that they are reported as having an IP (v4) address when they do not.

Yes. That is why I said quoth: "It doesn't make sense to have a not-UP interface with an assigned IP address."

It's very easy to reproduce
Have a disconnected network adapter - wired with cable pulled

A wired ethernet interface can (and classically does) have an IP address even with the cable pulled. The Real Linux™ kernel does not care whether the wire is connected (on your adapter, or on some adapter halfway to Japan). The interface is brought down by systemd-networkd(8) and/or some other userspace infrastructure. Your WSL userspace has no daemon performing that function. Fire up a minimalist userspace on a Real Linux kernel and you'll see the same behavior. The ping will just time out.

Note: Thinking about it I suspect the adapter may have to be configured for DHCP for this to happen.

DHCP is tangentially related, but only affects how an IP address is assigned. You can have a static IP and the ping will still time out, unless some daemon goes out of its way to take the interface down. Or you take it down manually.

@f948lan
Copy link
Author

f948lan commented Mar 13, 2019

A wired ethernet interface can (and classically does) have an IP address even with the cable pulled. The Real Linux™ kernel does not care whether the wire is connected (on your adapter, or on some adapter halfway to Japan). The interface is brought down by systemd-networkd(8) and/or some other userspace infrastructure. Your WSL userspace has no daemon performing that function. Fire up a minimalist userspace on a Real Linux kernel and you'll see the same behavior. The ping will just time out.

The first part I understand and agree with, the last sentence is not my experience. On "real linux" if an IP is assigned, the address is valid, will route traffic for that address to the local machine, and will respond to pings. (Firewall permitting.) This is true regardless of the physical connection state of the adapter. Same for a disconnected Wifi adapter if you manually force an address. If wifi is disabled though (rfkill) it is not possible to assign an address.
Also while WSL doesn't have a daemon performing the function, the underlying OS (Windows) does, so this comparison is not entirely accurate IMHO. I may be wrong but I suspect it's this Windows component that is returning the 169.x.x.x address (I doubt the WSL layer is making it up, but it should be filtering the list based on adapter state).

DHCP is tangentially related, but only affects how an IP address is assigned. You can have a static IP and the ping will still time out, unless some daemon goes out of its way to take the interface down. Or you take it down manually.

Agreed, DHCP seemed related in the fact is is generally what falls back to the APIPA range 169.254.x.x addresses seen in this case.
Actually just checked, and even if I manually set an IP for an adapter, when 'disconnected' (see below) it still returns a 169.254.x.x IP address in WSL.

Finally, as requested ipconfig /all vs ifconfig -a on the same machine, with a 'disconnected' bluetooth adapter and 2 inactive wifi-direct adapters showing (along with one active wifi adapter):

C:\Users\graham>ipconfig /all

Windows IP Configuration

   Host Name . . . . . . . . . . . . : YOGA
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . : Hybrid
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . : controleur.wifipass.org

Wireless LAN adapter Local Area Connection* 3:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #2
   Physical Address. . . . . . . . . : 2C-D0-5A-D1-7D-D8
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Local Area Connection* 4:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter #3
   Physical Address. . . . . . . . . : 2C-D0-5A-D1-7D-D8
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes

Ethernet adapter Bluetooth Network Connection 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Bluetooth Device (Personal Area Network)
   Physical Address. . . . . . . . . : 2C-D0-5A-D1-A4-E4
   DHCP Enabled. . . . . . . . . . . : No
   Autoconfiguration Enabled . . . . : Yes

Wireless LAN adapter Wi-Fi:

   Connection-specific DNS Suffix  . : controleur.wifipass.org
   Description . . . . . . . . . . . : Realtek RTL8723AU Wireless LAN 802.11n USB 2.0 Network Adapter
   Physical Address. . . . . . . . . : 2C-D0-5A-D1-7D-D8
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
   Link-local IPv6 Address . . . . . : fe80::1df1:567e:3755:5085%25(Preferred)
   IPv4 Address. . . . . . . . . . . : 10.192.2.246(Preferred)
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Lease Obtained. . . . . . . . . . : 13 March 2019 01:48:43
   Lease Expires . . . . . . . . . . : 13 March 2019 02:48:43
   Default Gateway . . . . . . . . . : 10.192.168.1
   DHCP Server . . . . . . . . . . . : 10.192.168.1
   DHCPv6 IAID . . . . . . . . . . . : 170709082
   DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-18-FD-B3-F4-2C-D0-5A-D1-7D-D8
   DNS Servers . . . . . . . . . . . : 10.192.168.1
   NetBIOS over Tcpip. . . . . . . . : Enabled
eth0: flags=64<RUNNING>  mtu 1500
        inet 169.254.161.122  netmask 255.255.0.0
        inet6 fe80::517:727c:7dea:a17a  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 2c:d0:5a:d1:a4:e4  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 1500
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0xfe<compat,link,site,host>
        loop  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wifi0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.192.2.246  netmask 255.255.0.0  broadcast 10.192.255.255
        inet6 fe80::1df1:567e:3755:5085  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 2c:d0:5a:d1:7d:d8  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wifi1: flags=64<RUNNING>  mtu 1500
        inet 169.254.245.158  netmask 255.255.0.0
        inet6 fe80::f59c:e3c6:2090:f59e  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 2c:d0:5a:d1:7d:d8  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wifi2: flags=64<RUNNING>  mtu 1500
        inet 169.254.159.255  netmask 255.255.0.0
        inet6 fe80::3cd8:17f2:5cce:9fff  prefixlen 64  scopeid 0xfd<compat,link,site,host>
        ether 2c:d0:5a:d1:7d:d8  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants