Browse code

vendor libnetwork to fix mix up between IPv4 and IPv6

Signed-off-by: Tibor Vass <tibor@docker.com>

Tibor Vass authored on 2020/11/25 08:22:31
Showing 6 changed files
... ...
@@ -3,7 +3,7 @@
3 3
 # LIBNETWORK_COMMIT is used to build the docker-userland-proxy binary. When
4 4
 # updating the binary version, consider updating github.com/docker/libnetwork
5 5
 # in vendor.conf accordingly
6
-: "${LIBNETWORK_COMMIT:=6b51d028f4bbb9a4cc8d3eaba13baa9f848af546}"
6
+: "${LIBNETWORK_COMMIT:=a543cbc4871f904b0efe205708eb45d72e65fd8b}"
7 7
 
8 8
 install_proxy() {
9 9
 	case "$1" in
... ...
@@ -47,7 +47,7 @@ github.com/grpc-ecosystem/go-grpc-middleware        3c51f7f332123e8be5a157c0802a
47 47
 # libnetwork
48 48
 
49 49
 # When updating, also update LIBNETWORK_COMMIT in hack/dockerfile/install/proxy.installer accordingly
50
-github.com/docker/libnetwork                        6b51d028f4bbb9a4cc8d3eaba13baa9f848af546 
50
+github.com/docker/libnetwork                        a543cbc4871f904b0efe205708eb45d72e65fd8b
51 51
 github.com/docker/go-events                         e31b211e4f1cd09aa76fe4ac244571fab96ae47f
52 52
 github.com/armon/go-radix                           e39d623f12e8e41c7b5529e9a9dd67a1e2261f80
53 53
 github.com/armon/go-metrics                         eb0af217e5e9747e41dd5303755356b62d28e3ec
... ...
@@ -1055,7 +1055,7 @@ func CreateOptionLoadBalancer() EndpointOption {
1055 1055
 
1056 1056
 // JoinOptionPriority function returns an option setter for priority option to
1057 1057
 // be passed to the endpoint.Join() method.
1058
-func JoinOptionPriority(ep Endpoint, prio int) EndpointOption {
1058
+func JoinOptionPriority(prio int) EndpointOption {
1059 1059
 	return func(ep *endpoint) {
1060 1060
 		// ep lock already acquired
1061 1061
 		c := ep.network.getController()
... ...
@@ -151,7 +151,7 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
151 151
 	}
152 152
 
153 153
 	containerIP, containerPort := getIPAndPort(m.container)
154
-	if hostIP.To4() != nil || hostIP.To16() != nil {
154
+	if pm.checkIP(hostIP) {
155 155
 		if err := pm.AppendForwardingTableEntry(m.proto, hostIP, allocatedHostPort, containerIP.String(), containerPort); err != nil {
156 156
 			return nil, err
157 157
 		}
... ...
@@ -160,7 +160,7 @@ func (pm *PortMapper) MapRange(container net.Addr, hostIP net.IP, hostPortStart,
160 160
 	cleanup := func() error {
161 161
 		// need to undo the iptables rules before we return
162 162
 		m.userlandProxy.Stop()
163
-		if hostIP.To4() != nil || hostIP.To16() != nil {
163
+		if pm.checkIP(hostIP) {
164 164
 			pm.DeleteForwardingTableEntry(m.proto, hostIP, allocatedHostPort, containerIP.String(), containerPort)
165 165
 			if err := pm.Allocator.ReleasePort(hostIP, m.proto, allocatedHostPort); err != nil {
166 166
 				return err
... ...
@@ -44,3 +44,11 @@ func (pm *PortMapper) forward(action iptables.Action, proto string, sourceIP net
44 44
 	}
45 45
 	return pm.chain.Forward(action, sourceIP, sourcePort, proto, containerIP, containerPort, pm.bridgeName)
46 46
 }
47
+
48
+// checkIP checks if IP is valid and matching to chain version
49
+func (pm *PortMapper) checkIP(ip net.IP) bool {
50
+	if pm.chain == nil || pm.chain.IPTable.Version == iptables.IPv4 {
51
+		return ip.To4() != nil
52
+	}
53
+	return ip.To16() != nil
54
+}
... ...
@@ -29,3 +29,9 @@ func (pm *PortMapper) AppendForwardingTableEntry(proto string, sourceIP net.IP,
29 29
 func (pm *PortMapper) DeleteForwardingTableEntry(proto string, sourceIP net.IP, sourcePort int, containerIP string, containerPort int) error {
30 30
 	return nil
31 31
 }
32
+
33
+// checkIP checks if IP is valid and matching to chain version
34
+func (pm *PortMapper) checkIP(ip net.IP) bool {
35
+	// no IPv6 for port mapper on windows -> only IPv4 valid
36
+	return ip.To4() != nil
37
+}