diff --git a/libnetwork/drivers/bridge/bridge.go b/libnetwork/drivers/bridge/bridge.go index ef3550dc36..5e4502d418 100644 --- a/libnetwork/drivers/bridge/bridge.go +++ b/libnetwork/drivers/bridge/bridge.go @@ -39,6 +39,7 @@ type Configuration struct { EnableICC bool EnableIPForwarding bool AllowNonDefaultBridge bool + Mtu int } // EndpointConfiguration represents the user specified configuration for the sandbox endpoint @@ -347,6 +348,11 @@ func (d *driver) CreateEndpoint(nid, eid types.UUID, sboxKey string, epOptions i if err != nil { return nil, err } + defer func() { + if err != nil { + netlink.LinkDel(sbox) + } + }() // Add user specified attributes if epConfig != nil && epConfig.MacAddress != nil { @@ -356,11 +362,17 @@ func (d *driver) CreateEndpoint(nid, eid types.UUID, sboxKey string, epOptions i } } - defer func() { + // Add bridge inherited attributes to pipe interfaces + if config.Mtu != 0 { + err = netlink.LinkSetMTU(host, config.Mtu) if err != nil { - netlink.LinkDel(sbox) + return nil, err } - }() + err = netlink.LinkSetMTU(sbox, config.Mtu) + if err != nil { + return nil, err + } + } // Attach host side pipe interface into the bridge if err = netlink.LinkSetMaster(host, diff --git a/libnetwork/drivers/bridge/network_test.go b/libnetwork/drivers/bridge/network_test.go index 9680ec0ee8..96662d6303 100644 --- a/libnetwork/drivers/bridge/network_test.go +++ b/libnetwork/drivers/bridge/network_test.go @@ -13,8 +13,10 @@ func TestLinkCreate(t *testing.T) { _, d := New() dr := d.(*driver) + mtu := 1490 config := &Configuration{ BridgeName: DefaultBridgeName, + Mtu: mtu, EnableIPv6: true} if err := d.Config(config); err != nil { t.Fatalf("Failed to setup driver config: %v", err) @@ -43,11 +45,23 @@ func TestLinkCreate(t *testing.T) { t.Fatalf("Failed to detect invalid config") } + // Good endpoint creation sinfo, err = d.CreateEndpoint("dummy", "ep", "cc", nil) if err != nil { t.Fatalf("Failed to create a link: %s", err.Error()) } + // Verify sbox endoint interface inherited MTU value from bridge config + sboxLnk, err := netlink.LinkByName(sinfo.Interfaces[0].SrcName) + if err != nil { + t.Fatal(err) + } + if mtu != sboxLnk.Attrs().MTU { + t.Fatalf("Sandbox endpoint interface did not inherit bridge interface MTU config") + } + // TODO: if we could get peer name from (sboxLnk.(*netlink.Veth)).PeerName + // then we could check the MTU on hostLnk as well. + _, err = d.CreateEndpoint("dummy", "ep", "cc2", nil) if err == nil { t.Fatalf("Failed to detect duplicate endpoint id on same network")