Vista: Multiple IP addresses on virtual network adapters
When hosting a virtual network in LAN Bridger, the virtual network adapter’s IP address is set statically through WMI. This functionality was first implemented in LAN Bridger in a Windows XP development environment.
Everything worked fine up until a couple of months ago. I was working on another feature for LAN Bridger when by coincidence I happened to notice that the virtual network adapter that ships with LAN Bridger had been assigned multiple IP addresses.
I had recently moved to another city, and as a result my network configuration had changed. Therefore, I assumed this was most likely an issue with the way LAN Bridger accessed WMI since I hadn’t seen it previously and also hadn’t received any complaints from any of the beta users.
After a little testing, I noticed that the virtual network adapter was often assigned multiple IP addresses when I was moving from one network to another (e.g. from work to my apartment), and that the IP addresses were all ones that I had assigned to the adapter in the past.
At the time I began noticing the problem, LAN Bridger selected the subnet for a virtual network from the private address ranges, as long as it didn’t conflict with any other subnets in use on the user’s machine. For instance, if I had been assigned the IP address 172.16.1.1/24 on my physical network, LAN Bridger would automatically pick either 10.0.0.0/24 or 192.168.1.0/24 to avoid IP address conflicts [footnote: the logic as to exactly which subnet LB chose has been significantly simplified in this post, and has changed since then].
When I moved my laptop from work to my apartment, the LAN address on my physical network adapter would change to 10.0.0.0/24, and thus LAN Bridger would have to choose another private range, such as 172.16.1.1/24 or 192.168.1.0/24, for its virtual networks.
However, once I launched LAN Bridger at my apartment the virtual network adapter would suddenly have two IP addresses bound to it: 172.16.1.1/24 and 10.0.0.1/24. Unfortunately, the router at my apartment was already using 10.0.0.0/16 (don’t ask me who set the subnet mask to /16 …), and thus my machine would have an IP address conflict causing my Internet connection to be dropped as soon as I launched LAN Bridger and the virtual network adapter came online (this was actually how I initially became aware of the problem).
Since I had only reproduced the problem on my own computer, and I had other more important things to work on, the issue was backburner’d. A few weeks later, however, I was implementing a similar functionality (setting a static IP address on an adapter through WMI) in a another project, and while testing the multiple IP addresses issue surfaced again in a couple of virtual machines running Vista. It suddenly occurred to me that the issue had only surfaced on that particular operating system, which is why I hadn’t noticed the problem when I was originally implementing the functionality on my Windows XP box. Furthermore, most, if not all, of the LAN Bridger beta testers were running Windows XP and thus never experienced the issue either.
Now that I had identified the issue, I wanted to know why it happened, and after a bit of testing it became clear that the problem was much more extensive than I initially expected. My first thought was that I might be using the COM interfaces to WMI incorrectly, but I could easily reproduce the behavior using ‘wbemtest‘ (Microsoft’s official WMI tester tool). Next, I thought it might be that the LAN Bridger virtual network adapter that was at fault; after all, I had implemented the driver myself. Once again, however, I was able reproduce the behavior with Microsoft’s own Loopback adapter as well as the ‘netvmini’ sample that ships with the WDK. Even worse, though, was that I managed to reproduce the behavior using the Windows UI in the network adapter’s TCP/IP Properties dialog. This indicated that the problem went beyond WMI.
I also noticed that once I had set the static IP address using WMI, the settings in the TCP/IP Properties dialog would look disturbingly incorrect.
However, the output from ‘ipconfig’ shows another IP address as being assigned to the adapter:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Echobit Virtual Ethernet Adapter
Physical Address. . . . . . . . . : 00-00-2E-67-83-1E
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::c18b:63e4:67ba:304d%30 (Preferred)
IPv4 Address. . . . . . . . . . . : 172.16.1.1 (Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled
You can reproduce the multiple IP addresses on a virtual network adapter by assigning it a static IP address, enabling DHCP, assigning it another static IP address, and re-enabling DHCP. You can keep on repeating these steps to add as many addresses as you’d like to the adapter. In the ‘ipconfig’ output below I’ve bound four different static IP addresses to the LAN Bridger virtual network adapter:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Echobit Virtual Ethernet Adapter
Physical Address. . . . . . . . . : 00-00-16-C6-83-FC
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::6011:13c6:52f5:29e4%34(Preferred)
IPv4 Address. . . . . . . . . . . : 172.16.1.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.0.1(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 192.168.0.2(Preferred)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
IPv4 Address. . . . . . . . . . . : 172.16.50.1(Tentative)
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
fec0:0:0:ffff::2%1
fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled
So far, the only way I’ve managed to get rid of all of the lingering IP addresses on an adapter has been by removing the network adapter via Device Manager and reinstalling it.
I have reported the issue to Microsoft and they are currently working on a solution to the problem. For now, all that I can recommend to get around the issue is to use the ‘netsh’ tool. Personally, I think it’s a major hack having to use an external tool rather than an API to do a basic operation such as setting a static IP address, but I don’t see a lot of other options. IP Helper, for instance, doesn’t allow you to disable DHCP on an adapter when calling AddIPAddress.
You can set the IP address of an adapter through ‘netsh’ by using the following command:
netsh interface ip set address "Local Area Connection" static 10.0.0.10 255.255.255.0 10.0.0.1
One way of executing the command from your application is to call CreateProcess with the with the STARTUPINFO structure’s wShowWindow member set to SW_HIDE. You can obtain the connection name of your network adapter via the WMI class Win32_NetworkAdapter (take a look at the NetConnectionID member).
For now, we just have to sit tight and wait for Microsoft to come up with a better solution than the ‘netsh’ hack.
About this entry
You’re currently reading “Vista: Multiple IP addresses on virtual network adapters,” an entry on Inside Echobit
- Written by:
- Soren Dreijer
- Published:
- 09.18.07 / 10pm
- Category:
- Development
1 Comment
Jump to comment form | comments rss [?] | trackback uri [?]