mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
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:
parent
914ad10ea4
commit
198e3d3ee9
2 changed files with 29 additions and 3 deletions
|
@ -39,6 +39,7 @@ type Configuration struct {
|
||||||
EnableICC bool
|
EnableICC bool
|
||||||
EnableIPForwarding bool
|
EnableIPForwarding bool
|
||||||
AllowNonDefaultBridge bool
|
AllowNonDefaultBridge bool
|
||||||
|
Mtu int
|
||||||
}
|
}
|
||||||
|
|
||||||
// EndpointConfiguration represents the user specified configuration for the sandbox endpoint
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
netlink.LinkDel(sbox)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Add user specified attributes
|
// Add user specified attributes
|
||||||
if epConfig != nil && epConfig.MacAddress != nil {
|
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 {
|
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
|
// Attach host side pipe interface into the bridge
|
||||||
if err = netlink.LinkSetMaster(host,
|
if err = netlink.LinkSetMaster(host,
|
||||||
|
|
|
@ -13,8 +13,10 @@ func TestLinkCreate(t *testing.T) {
|
||||||
_, d := New()
|
_, d := New()
|
||||||
dr := d.(*driver)
|
dr := d.(*driver)
|
||||||
|
|
||||||
|
mtu := 1490
|
||||||
config := &Configuration{
|
config := &Configuration{
|
||||||
BridgeName: DefaultBridgeName,
|
BridgeName: DefaultBridgeName,
|
||||||
|
Mtu: mtu,
|
||||||
EnableIPv6: true}
|
EnableIPv6: true}
|
||||||
if err := d.Config(config); err != nil {
|
if err := d.Config(config); err != nil {
|
||||||
t.Fatalf("Failed to setup driver config: %v", err)
|
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")
|
t.Fatalf("Failed to detect invalid config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Good endpoint creation
|
||||||
sinfo, err = d.CreateEndpoint("dummy", "ep", "cc", nil)
|
sinfo, err = d.CreateEndpoint("dummy", "ep", "cc", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to create a link: %s", err.Error())
|
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)
|
_, err = d.CreateEndpoint("dummy", "ep", "cc2", nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Failed to detect duplicate endpoint id on same network")
|
t.Fatalf("Failed to detect duplicate endpoint id on same network")
|
||||||
|
|
Loading…
Add table
Reference in a new issue