@@ -49,8 +49,16 @@ func (n *bridgeNetwork) allocatePortsInternal(bindings []types.PortBinding, cont
4949 }
5050 bs = append (bs , bIPv4 )
5151 }
52+
5253 // Allocate IPv6 Port mappings
53- if ok := n .validatePortBindingIPv6 (& bIPv6 , containerIPv6 , defHostIP ); ok {
54+ // If the container has no IPv6 address, allow proxying host IPv6 traffic to it
55+ // by setting up the binding with the IPv4 interface if the userland proxy is enabled
56+ // This change was added to keep backward compatibility
57+ containerIP := containerIPv6
58+ if ulPxyEnabled && (containerIPv6 == nil ) {
59+ containerIP = containerIPv4
60+ }
61+ if ok := n .validatePortBindingIPv6 (& bIPv6 , containerIP , defHostIP ); ok {
5462 if err := n .allocatePort (& bIPv6 , ulPxyEnabled ); err != nil {
5563 // On allocation failure, release previously allocated ports. On cleanup error, just log a warning message
5664 if cuErr := n .releasePortsInternal (bs ); cuErr != nil {
@@ -67,7 +75,7 @@ func (n *bridgeNetwork) allocatePortsInternal(bindings []types.PortBinding, cont
6775// validatePortBindingIPv4 validates the port binding, populates the missing Host IP field and returns true
6876// if this is a valid IPv4 binding, else returns false
6977func (n * bridgeNetwork ) validatePortBindingIPv4 (bnd * types.PortBinding , containerIPv4 , defHostIP net.IP ) bool {
70- //Return early if there is a valid Host IP, but its not a IPv6 address
78+ //Return early if there is a valid Host IP, but its not a IPv4 address
7179 if len (bnd .HostIP ) > 0 && bnd .HostIP .To4 () == nil {
7280 return false
7381 }
@@ -85,10 +93,10 @@ func (n *bridgeNetwork) validatePortBindingIPv4(bnd *types.PortBinding, containe
8593}
8694
8795// validatePortBindingIPv6 validates the port binding, populates the missing Host IP field and returns true
88- // if this is a valid IP6v binding, else returns false
89- func (n * bridgeNetwork ) validatePortBindingIPv6 (bnd * types.PortBinding , containerIPv6 , defHostIP net.IP ) bool {
90- // Return early if there is no IPv6 container endpoint
91- if containerIPv6 == nil {
96+ // if this is a valid IPv6 binding, else returns false
97+ func (n * bridgeNetwork ) validatePortBindingIPv6 (bnd * types.PortBinding , containerIP , defHostIP net.IP ) bool {
98+ // Return early if there is no container endpoint
99+ if containerIP == nil {
92100 return false
93101 }
94102 // Return early if there is a valid Host IP, which is a IPv4 address
@@ -108,9 +116,8 @@ func (n *bridgeNetwork) validatePortBindingIPv6(bnd *types.PortBinding, containe
108116 return false
109117 }
110118 }
111- bnd .IP = containerIPv6
119+ bnd .IP = containerIP
112120 return true
113-
114121}
115122
116123func (n * bridgeNetwork ) allocatePort (bnd * types.PortBinding , ulPxyEnabled bool ) error {
0 commit comments