Libnetwork bridge to handle MTU option

- This address one of the requirements of Issue #78
- Bridge MTU will be enforced on the veth pair ifaces
  for each endpoint being added to the network.

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch 2015-04-23 13:39:41 -07:00
parent 914ad10ea4
commit 198e3d3ee9
2 changed files with 29 additions and 3 deletions

View file

@ -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,

View file

@ -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")