From da109f3af037352af24f935b1ea57ba8a7f26cad Mon Sep 17 00:00:00 2001 From: Patrick Hemmer Date: Tue, 1 Jul 2014 19:56:00 -0400 Subject: [PATCH 1/2] enable hairpin mode on virtual interface bridge port This is to support being able to DNAT/MASQ traffic from a container back into itself (dotcloud/docker#4442) Docker-DCO-1.1-Signed-off-by: Patrick Hemmer (github: phemmer) --- network/veth.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/network/veth.go b/network/veth.go index 3d7dc8729..240da5798 100644 --- a/network/veth.go +++ b/network/veth.go @@ -39,6 +39,9 @@ func (v *Veth) Create(n *Network, nspid int, networkState *NetworkState) error { if err := SetMtu(name1, n.Mtu); err != nil { return err } + if err := SetHairpinMode(name1, true); err != nil { + return err + } if err := InterfaceUp(name1); err != nil { return err } From 190e50b08dbd72fd1d9f21f20581fa27a498481c Mon Sep 17 00:00:00 2001 From: Arnaud Porterie Date: Mon, 9 Feb 2015 15:22:50 -0800 Subject: [PATCH 2/2] Selectively enable hairpin NAT Offer the ability to enable hairpin NAT on a per network basis, while keeping it disable by default as it is unsupported by older kernel. Signed-off-by: Arnaud Porterie --- network/types.go | 6 ++++++ network/veth.go | 6 ++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/network/types.go b/network/types.go index dcf00420f..a1668e06c 100644 --- a/network/types.go +++ b/network/types.go @@ -38,6 +38,12 @@ type Network struct { // container's interfaces if a pair is created, specifically in the case of type veth // Note: This does not apply to loopback interfaces. TxQueueLen int `json:"txqueuelen,omitempty"` + + // HairpinMode specifies if hairpin NAT should be enabled on the virtual interface + // bridge port in the case of type veth + // Note: This is unsupported on some systems. + // Note: This does not apply to loopback interfaces. + HairpinMode bool `json:"hairpin_mode"` } // Struct describing the network specific runtime state that will be maintained by libcontainer for all running containers diff --git a/network/veth.go b/network/veth.go index 240da5798..25e559d1b 100644 --- a/network/veth.go +++ b/network/veth.go @@ -39,8 +39,10 @@ func (v *Veth) Create(n *Network, nspid int, networkState *NetworkState) error { if err := SetMtu(name1, n.Mtu); err != nil { return err } - if err := SetHairpinMode(name1, true); err != nil { - return err + if n.HairpinMode { + if err := SetHairpinMode(name1, true); err != nil { + return err + } } if err := InterfaceUp(name1); err != nil { return err