First cut of adding hairpin functionality to weave
This commit is contained in:
1 parent
ca64ab54e7
commit
c05955d598
5 files changed
+27
-11
No files matched your search
+6
-2
@@ -113,7 +113,7 @@ func interfaceExistsInNamespace(netNSPath string, ifName string) bool {
|
|||||||
|
|
||||||
// NB: This function can be used only by a process that terminates immediately
|
// NB: This function can be used only by a process that terminates immediately
|
||||||
// after calling the function as it changes netns via WithNetNSLinkUnsafe.
|
// after calling the function as it changes netns via WithNetNSLinkUnsafe.
|
||||||
func AttachContainer(netNSPath, id, ifName, bridgeName string, mtu int, withMulticastRoute bool, cidrs []*net.IPNet, keepTXOn bool) error {
|
func AttachContainer(netNSPath, id, ifName, bridgeName string, mtu int, withMulticastRoute bool, cidrs []*net.IPNet, keepTXOn bool, hairpinMode bool) error {
|
||||||
ns, err := netns.GetFromPath(netNSPath)
|
ns, err := netns.GetFromPath(netNSPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -131,7 +131,7 @@ func AttachContainer(netNSPath, id, ifName, bridgeName string, mtu int, withMult
|
|||||||
id = id[:maxIDLen] // trim passed ID if too long
|
id = id[:maxIDLen] // trim passed ID if too long
|
||||||
}
|
}
|
||||||
name, peerName := vethPrefix+"pl"+id, vethPrefix+"pg"+id
|
name, peerName := vethPrefix+"pl"+id, vethPrefix+"pg"+id
|
||||||
_, err := CreateAndAttachVeth(name, peerName, bridgeName, mtu, keepTXOn, func(veth netlink.Link) error {
|
veth, err := CreateAndAttachVeth(name, peerName, bridgeName, mtu, keepTXOn, func(veth netlink.Link) error {
|
||||||
if err := netlink.LinkSetNsFd(veth, int(ns)); err != nil {
|
if err := netlink.LinkSetNsFd(veth, int(ns)); err != nil {
|
||||||
return fmt.Errorf("failed to move veth to container netns: %s", err)
|
return fmt.Errorf("failed to move veth to container netns: %s", err)
|
||||||
}
|
}
|
||||||
@@ -143,6 +143,10 @@ func AttachContainer(netNSPath, id, ifName, bridgeName string, mtu int, withMult
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err = netlink.LinkSetHairpin(veth, hairpinMode); err != nil {
|
||||||
|
return fmt.Errorf("unable to set hairpin mode to %t for bridge side of veth %s: %s", hairpinMode, name, err)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := WithNetNSLinkUnsafe(ns, ifName, func(veth netlink.Link) error {
|
if err := WithNetNSLinkUnsafe(ns, ifName, func(veth netlink.Link) error {
|
||||||
|
|||||||
+6
-5
@@ -128,7 +128,7 @@ func (c *CNIPlugin) CmdAdd(args *skel.CmdArgs) error {
|
|||||||
id = fmt.Sprintf("%x", data)
|
id = fmt.Sprintf("%x", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := weavenet.AttachContainer(args.Netns, id, args.IfName, conf.BrName, conf.MTU, false, []*net.IPNet{&ip.Address}, false); err != nil {
|
if err := weavenet.AttachContainer(args.Netns, id, args.IfName, conf.BrName, conf.MTU, false, []*net.IPNet{&ip.Address}, false, conf.HairpinMode); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := weavenet.WithNetNSLinkUnsafe(ns, args.IfName, func(link netlink.Link) error {
|
if err := weavenet.WithNetNSLinkUnsafe(ns, args.IfName, func(link netlink.Link) error {
|
||||||
@@ -218,8 +218,9 @@ func logOnStderr(err error) {
|
|||||||
|
|
||||||
type NetConf struct {
|
type NetConf struct {
|
||||||
types.NetConf
|
types.NetConf
|
||||||
BrName string `json:"bridge"`
|
BrName string `json:"bridge"`
|
||||||
IsGW bool `json:"isGateway"`
|
IsGW bool `json:"isGateway"`
|
||||||
IPMasq bool `json:"ipMasq"`
|
IPMasq bool `json:"ipMasq"`
|
||||||
MTU int `json:"mtu"`
|
MTU int `json:"mtu"`
|
||||||
|
HairpinMode bool `json:"hairpinMode"`
|
||||||
}
|
}
|
||||||
@@ -14,11 +14,12 @@ import (
|
|||||||
|
|
||||||
func attach(args []string) error {
|
func attach(args []string) error {
|
||||||
if len(args) < 4 {
|
if len(args) < 4 {
|
||||||
cmdUsage("attach-container", "[--no-multicast-route] [--keep-tx-on] <container-id> <bridge-name> <mtu> <cidr>...")
|
cmdUsage("attach-container", "[--no-multicast-route] [--keep-tx-on] [--hairpin-mode=true|false] <container-id> <bridge-name> <mtu> <cidr>...")
|
||||||
}
|
}
|
||||||
|
|
||||||
keepTXOn := false
|
keepTXOn := false
|
||||||
withMulticastRoute := true
|
withMulticastRoute := true
|
||||||
|
hairpinMode := true
|
||||||
for i := 0; i < len(args); {
|
for i := 0; i < len(args); {
|
||||||
switch args[i] {
|
switch args[i] {
|
||||||
case "--no-multicast-route":
|
case "--no-multicast-route":
|
||||||
@@ -27,6 +28,9 @@ func attach(args []string) error {
|
|||||||
case "--keep-tx-on":
|
case "--keep-tx-on":
|
||||||
keepTXOn = true
|
keepTXOn = true
|
||||||
args = append(args[:i], args[i+1:]...)
|
args = append(args[:i], args[i+1:]...)
|
||||||
|
case "--hairpin-mode=false":
|
||||||
|
hairpinMode = false
|
||||||
|
args = append(args[:i], args[i+1:]...)
|
||||||
default:
|
default:
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
@@ -55,7 +59,7 @@ func attach(args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = weavenet.AttachContainer(weavenet.NSPathByPid(pid), fmt.Sprint(pid), weavenet.VethName, args[1], mtu, withMulticastRoute, cidrs, keepTXOn)
|
err = weavenet.AttachContainer(weavenet.NSPathByPid(pid), fmt.Sprint(pid), weavenet.VethName, args[1], mtu, withMulticastRoute, cidrs, keepTXOn, hairpinMode)
|
||||||
// If we detected an error but the container has died, tell the user that instead.
|
// If we detected an error but the container has died, tell the user that instead.
|
||||||
if err != nil && !processExists(pid) {
|
if err != nil && !processExists(pid) {
|
||||||
err = fmt.Errorf("Container %s died", args[0])
|
err = fmt.Errorf("Container %s died", args[0])
|
||||||
|
|||||||
@@ -241,3 +241,7 @@ The list of variables you can set is:
|
|||||||
a larger size for better performance if your network supports jumbo
|
a larger size for better performance if your network supports jumbo
|
||||||
frames - see [here](/site/using-weave/fastdp.md#mtu) for more
|
frames - see [here](/site/using-weave/fastdp.md#mtu) for more
|
||||||
details.
|
details.
|
||||||
|
* `HAIRPIN_MODE` - Weave Net defaults to enabling hairpin on the bridge side of
|
||||||
|
the `veth` pair for containers attached. If you need to disable hairpin, e.g. your
|
||||||
|
kernel is one of those that can panic if hairpin is enabled, then you can disable it
|
||||||
|
by setting `HAIRPIN_MODE=false`.
|
||||||
@@ -1070,17 +1070,20 @@ create_cni_config() {
|
|||||||
cat >"$1" <<EOF
|
cat >"$1" <<EOF
|
||||||
{
|
{
|
||||||
"name": "weave",
|
"name": "weave",
|
||||||
"type": "weave-net"
|
"type": "weave-net",
|
||||||
|
"hairpinMode": $2
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_cni() {
|
setup_cni() {
|
||||||
|
# if env var HAIRPIN_MODE is not set, default it to true
|
||||||
|
HAIRPIN_MODE=${HAIRPIN_MODE:-true}
|
||||||
if install_cni_plugin $CNI_PLUGIN_DIR ; then
|
if install_cni_plugin $CNI_PLUGIN_DIR ; then
|
||||||
upgrade_cni_plugin $CNI_PLUGIN_DIR
|
upgrade_cni_plugin $CNI_PLUGIN_DIR
|
||||||
fi
|
fi
|
||||||
if [ -d $HOST_ROOT/etc/cni/net.d -a ! -f $HOST_ROOT/etc/cni/net.d/10-weave.conf ] ; then
|
if [ -d $HOST_ROOT/etc/cni/net.d -a ! -f $HOST_ROOT/etc/cni/net.d/10-weave.conf ] ; then
|
||||||
create_cni_config $HOST_ROOT/etc/cni/net.d/10-weave.conf
|
create_cni_config $HOST_ROOT/etc/cni/net.d/10-weave.conf $HAIRPIN_MODE
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user