moby / ipvs

IPVS networking for containers (package derived from moby/libnetwork)
Apache License 2.0
97 stars 37 forks source link

Update IP parsing based on netlink address attribute format #19

Closed andrewsykim closed 4 years ago

andrewsykim commented 4 years ago

The netlink address attribute returns IPv4 addresses in a way that is not easily consumable by Go's standard net library. For example, an IPv4 address like 10.0.0.1 is received from netlink as:

[]byte{10 0 0 1 0 0 0 0 0 0 0 0 0 0]

which Go's net library considers an IPv6 address based on this check.

Due to this limitation, this PR updates the address family check for destination servers (only in older kernels < 3.18) so that any address attribute value that has 12 leading 0s is considered an IPv4 address, otherwise we assume the address family is IPv6.

andrewsykim commented 4 years ago

Ran tests on CentOS 7 (3.10 kernel):

[root@ipvs-test ipvs]# uname -a
Linux ipvs-test 3.10.0-1062.18.1.el7.x86_64 #1 SMP Tue Mar 17 23:49:17 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

[root@ipvs-test ipvs]# go test ./...
ok      github.com/moby/ipvs    1.367s
?       github.com/moby/ipvs/ns [no test files]
justincormack commented 4 years ago

I mean this seems pretty gross but its only for old kernels, someone should file a bug with Red Hat to add family into their broken franeknkernel.

thaJeztah commented 4 years ago

ping @arkodg @kolyshkin PTAL