Misc fixes to ip allocation in bridge driver

Two changes were missing:
- On allocation of bridge ip was not passing canonical subnet
- Canonical subnet has to be passed on ip release
  as well, otherwise ipallocator will attempt
  ip release from a non registered nw

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch 2015-07-24 16:59:27 -07:00
parent dbe595343e
commit 88c2c05ce9
3 changed files with 16 additions and 6 deletions

View file

@ -947,8 +947,7 @@ func (d *driver) CreateEndpoint(nid, eid types.UUID, epInfo driverapi.EndpointIn
}
// v4 address for the sandbox side pipe interface
sub := types.GetIPNetCopy(n.bridge.bridgeIPv4)
sub.IP = sub.IP.Mask(sub.Mask)
sub := types.GetIPNetCanonical(n.bridge.bridgeIPv4)
ip4, err := ipAllocator.RequestIP(sub, nil)
if err != nil {
return err
@ -1075,7 +1074,8 @@ func (d *driver) DeleteEndpoint(nid, eid types.UUID) error {
n.releasePorts(ep)
// Release the v4 address allocated to this endpoint's sandbox interface
err = ipAllocator.ReleaseIP(n.bridge.bridgeIPv4, ep.addr.IP)
sub := types.GetIPNetCanonical(n.bridge.bridgeIPv4)
err = ipAllocator.ReleaseIP(sub, ep.addr.IP)
if err != nil {
return err
}

View file

@ -76,7 +76,8 @@ func setupBridgeIPv4(config *networkConfiguration, i *bridgeInterface) error {
}
func allocateBridgeIP(config *networkConfiguration, i *bridgeInterface) error {
ipAllocator.RequestIP(i.bridgeIPv4, i.bridgeIPv4.IP)
sub := types.GetIPNetCanonical(i.bridgeIPv4)
ipAllocator.RequestIP(sub, i.bridgeIPv4.IP)
return nil
}
@ -112,8 +113,7 @@ func setupGatewayIPv4(config *networkConfiguration, i *bridgeInterface) error {
}
// Pass the real network subnet to ip allocator (no host bits set)
sub := types.GetIPNetCopy(i.bridgeIPv4)
sub.IP = sub.IP.Mask(sub.Mask)
sub := types.GetIPNetCanonical(i.bridgeIPv4)
if _, err := ipAllocator.RequestIP(sub, config.DefaultGatewayIPv4); err != nil {
return err
}

View file

@ -173,6 +173,16 @@ func GetIPNetCopy(from *net.IPNet) *net.IPNet {
return &net.IPNet{IP: GetIPCopy(from.IP), Mask: bm}
}
// GetIPNetCanonical returns the canonical form for the passed network
func GetIPNetCanonical(nw *net.IPNet) *net.IPNet {
if nw == nil {
return nil
}
c := GetIPNetCopy(nw)
c.IP = c.IP.Mask(nw.Mask)
return c
}
// CompareIPNet returns equal if the two IP Networks are equal
func CompareIPNet(a, b *net.IPNet) bool {
if a == b {