Azure / DotNetty

DotNetty project – a port of netty, event-driven asynchronous network application framework
Other
4.09k stars 977 forks source link

GetBestMacAddress NullReferenceException #309

Closed spantazi closed 6 years ago

spantazi commented 6 years ago

In https://github.com/Azure/DotNetty/blob/58a82a0e3c336ae7e9b771edf01666a2b06008a3/src/DotNetty.Common/Internal/MacAddressUtil.cs#L63 there is no check if the network interface has a physical address. If for example the interface is a VPN tun interface or a bridge, it does not have a HWAddr resulting in and NullRerenceException upon calling .GetAddressBytes(). A check if .GetPhysicalAddress() != null should be included.

yyjdelete commented 6 years ago

Both VPN tun and bridge does has an mac address in my pc(windows). So what is the result of ipconfig /all in your pc, or that only happen on special system?


Loopback has an zero length mac address, but not null.

spantazi commented 6 years ago

@yyjdelete. Tested with .net core 2.0 on Linux (ubuntu 16.04). On Linux hosts some interface types returns null physical address.

yyjdelete commented 6 years ago

Will create an PR to add an workaround later.

But still not sure what happened on your machine, it's strange that there is already an assert in corefx's code to ensure GetPhysicalAddress() return not null, maybe you can also file an issue to https://github.com/dotnet/corefx to see what happened.


Also tested on Ubuntu17.10(vbox) and CentOS6(docker) with netcore2.0, both get 6 bytes 00h for loopback, and 4/6 bytes 00h not zero value for tunnel/bridge. image

spantazi commented 6 years ago

@yyjdelete Thank you for your quick response. Your fix works as expected, so the issue should be closed after merge! I will also open this in corefx, in case GetPhysicalAddress() is defined to always return a value.

Just for the record see my output below: image

My tun0 interface (Ubuntu 16.04 - vbox), for which .NET returns a null physical address, is an OpenVPN tunnel created from within a privileged docker container, Debian 9(docker). Probably not the most common setup!

yyjdelete commented 6 years ago

Successfully get null mac with tun on the same machine with openvpn/tunctl.