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

"dummy" network adapters do not work with GetInterfaceIP #31

Open
karl-tpio opened this issue Feb 22, 2019 · 1 comment
Open

"dummy" network adapters do not work with GetInterfaceIP #31

karl-tpio opened this issue Feb 22, 2019 · 1 comment

Comments

@karl-tpio
Copy link

karl-tpio commented Feb 22, 2019

A picture console log is worth 1000 words:

TL;DR: interfaces of type "dummy" (like a loopback, but usually not given an address in the 127.x space) are not supported(?) by the GetInterfaceIP template function

  1. Grab the binary to play around:
root@ip-172-25-26-131:~/go/bin# go get -u github.com/hashicorp/go-sockaddr/cmd/sockaddr
  1. List all the network interfaces on the host:
root@ip-172-25-26-131:~/go/bin# ip -o link show | awk -F': ' '{print $2}'
lo
ens5
dummy0
docker0
  1. demonstrate the tool works:
root@ip-172-25-26-131:~/go/bin# ./sockaddr eval -d 'GetInterfaceIP "ens5"'
[0] in: "{{GetInterfaceIP \"ens5\"}}"
[0] out: "172.25.26.131"

root@ip-172-25-26-131:~/go/bin# ifconfig ens5
ens5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 9001
        inet 172.25.26.131  netmask 255.255.240.0  broadcast 172.25.31.255
        inet6 fe80::e9:d4ff:fe2c:7eb4  prefixlen 64  scopeid 0x20<link>
        inet6 2600:1f1c:61e:1701:d208:ba80:cf7c:9e9e  prefixlen 128  scopeid 0x0<global>
        ether 02:e9:d4:2c:7e:b4  txqueuelen 1000  (Ethernet)
        RX packets 159045  bytes 89658689 (89.6 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 83925  bytes 13061624 (13.0 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  1. test the tool with the intended interface:
root@ip-172-25-26-131:~/go/bin# ./sockaddr eval -d 'GetInterfaceIP "dummy0"'
[0] in: "{{GetInterfaceIP \"dummy0\"}}"
[0] out: ""

a Nil result was not expected.

  1. Show the expected result:
root@ip-172-25-26-131:~/go/bin# ifconfig dummy0
dummy0: flags=195<UP,BROADCAST,RUNNING,NOARP>  mtu 1500
        inet 169.254.1.1  netmask 255.255.255.255  broadcast 0.0.0.0
        inet6 fe80::1cc3:f6ff:fe14:c441  prefixlen 64  scopeid 0x20<link>
        ether 1e:c3:f6:14:c4:41  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11  bytes 770 (770.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
  1. show how the dummy interface came into existence:
root@ip-172-25-26-131:~/go/bin# cat /etc/systemd/network/dummy0.netdev
# Creates a "dummy" network interface
# we'll configure this interface with a link-local address
# See: https://www.freedesktop.org/software/systemd/man/systemd.netdev.html
##

[NetDev]
Name=dummy0
Kind=dummy

Additional info that may be helpful:

root@ip-172-25-26-131:~/go/bin# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.2 LTS
Release:	18.04
Codename:	bionic

For context, this issue was discovered while troubleshooting this specific configuration of consul:
hashicorp/consul#5371

@karl-tpio
Copy link
Author

After a casual conversation w/ a colleague, i think i have a "why" for the bug and possibly a solution, too.

I'm not a golang person, but i think i can read well enough to figure out what's going on.

  1. Gets all interfaces
  2. Filters on the name match
  3. Filters on forwardable flag: https://github.com/hashicorp/go-sockaddr/blob/master/ifaddrs.go#L688

Here's where the bug happens. Because the dummy interface has an IP of 169.254.1.1, which is in the 169.254.0.0/16 range that MustIPv4Addr("169.254.0.0/16") filters out here: https://github.com/hashicorp/go-sockaddr/blob/master/rfc.go#L902

Basically: It appears that the GetInterfaceIP is not well named. That is, the GetInterfaceIP function should have been named GetForwardableInterfaceIP or similar. I can understand why adjusting the existing function name may not be ideal and would suggest an alternative:

  • keep the GetInterfaceIP function, but add documentation indicated the limitations w/r/t the filtered address ranges

  • create a new GetInterfaceIPRegardlessOfInterrfaceFlags function which will omit the check against ForwardingBlacklist.

  • update the documentation describing the limits in GetInterfaceIP to indicate that there's an alternative function, GetInterfaceIPRegardlessOfInterrfaceFlags that may be better suited to the users purposes.

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

No branches or pull requests

1 participant