0001-fix-port-forwarding-with-ipv6.disable-1.patch 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. From 7b9c2905883df5171fda10a364a81b8c6176c8e2 Mon Sep 17 00:00:00 2001
  2. From: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  3. Date: Mon, 26 Apr 2021 15:28:40 +0900
  4. Subject: [PATCH] fix port forwarding with ipv6.disable=1
  5. Make `docker run -p 80:80` functional again on environments with kernel boot parameter `ipv6.disable=1`.
  6. Fix moby/moby issue 42288
  7. Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  8. [Upstream: https://github.com/moby/libnetwork/pull/2635,
  9. https://github.com/moby/moby/pull/42322]
  10. [Rework path/drop test for docker-engine]
  11. Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
  12. ---
  13. vendor/github.com/docker/libnetwork/drivers/bridge/port_mapping.go | 31 +++++++++++++++++++++++++++++++
  14. 1 file changed, 35 insertions(+), 0 deletion(-)
  15. diff --git a/vendor/github.com/docker/libnetwork/drivers/bridge/port_mapping.go b/vendor/github.com/docker/libnetwork/drivers/bridge/port_mapping.go
  16. index 946130ec..17bf36f9 100644
  17. --- a/vendor/github.com/docker/libnetwork/drivers/bridge/port_mapping.go
  18. +++ b/vendor/github.com/docker/libnetwork/drivers/bridge/port_mapping.go
  19. @@ -5,6 +5,7 @@ import (
  20. "errors"
  21. "fmt"
  22. "net"
  23. + "sync"
  24. "github.com/docker/libnetwork/types"
  25. "github.com/ishidawataru/sctp"
  26. @@ -50,6 +51,13 @@ func (n *bridgeNetwork) allocatePortsInternal(bindings []types.PortBinding, cont
  27. bs = append(bs, bIPv4)
  28. }
  29. + // skip adding implicit v6 addr, when the kernel was booted with `ipv6.disable=1`
  30. + // https://github.com/moby/moby/issues/42288
  31. + isV6Binding := c.HostIP != nil && c.HostIP.To4() == nil
  32. + if !isV6Binding && !IsV6Listenable() {
  33. + continue
  34. + }
  35. +
  36. // Allocate IPv6 Port mappings
  37. // If the container has no IPv6 address, allow proxying host IPv6 traffic to it
  38. // by setting up the binding with the IPv4 interface if the userland proxy is enabled
  39. @@ -211,3 +219,26 @@ func (n *bridgeNetwork) releasePort(bnd types.PortBinding) error {
  40. return portmapper.Unmap(host)
  41. }
  42. +
  43. +var (
  44. + v6ListenableCached bool
  45. + v6ListenableOnce sync.Once
  46. +)
  47. +
  48. +// IsV6Listenable returns true when `[::1]:0` is listenable.
  49. +// IsV6Listenable returns false mostly when the kernel was booted with `ipv6.disable=1` option.
  50. +func IsV6Listenable() bool {
  51. + v6ListenableOnce.Do(func() {
  52. + ln, err := net.Listen("tcp6", "[::1]:0")
  53. + if err != nil {
  54. + // When the kernel was booted with `ipv6.disable=1`,
  55. + // we get err "listen tcp6 [::1]:0: socket: address family not supported by protocol"
  56. + // https://github.com/moby/moby/issues/42288
  57. + logrus.Debugf("port_mapping: v6Listenable=false (%v)", err)
  58. + } else {
  59. + v6ListenableCached = true
  60. + ln.Close()
  61. + }
  62. + })
  63. + return v6ListenableCached
  64. +}
  65. --
  66. 2.20.1