Browse Source

Merge pull request #86 from aboch/utm

Libnetwork bridge to handle MTU option
Madhu Venugopal 10 years ago
parent
commit
35a0dc89b7
2 changed files with 29 additions and 3 deletions
  1. 15 3
      libnetwork/drivers/bridge/bridge.go
  2. 14 0
      libnetwork/drivers/bridge/network_test.go

+ 15 - 3
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,

+ 14 - 0
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")