|
@@ -8,7 +8,6 @@ import (
|
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
log "github.com/Sirupsen/logrus"
|
|
"github.com/docker/libnetwork/netutils"
|
|
"github.com/docker/libnetwork/netutils"
|
|
- "github.com/docker/libnetwork/types"
|
|
|
|
"github.com/vishvananda/netlink"
|
|
"github.com/vishvananda/netlink"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -76,8 +75,12 @@ func setupBridgeIPv4(config *networkConfiguration, i *bridgeInterface) error {
|
|
}
|
|
}
|
|
|
|
|
|
func allocateBridgeIP(config *networkConfiguration, i *bridgeInterface) error {
|
|
func allocateBridgeIP(config *networkConfiguration, i *bridgeInterface) error {
|
|
- sub := types.GetIPNetCanonical(i.bridgeIPv4)
|
|
|
|
- ipAllocator.RequestIP(sub, i.bridgeIPv4.IP)
|
|
|
|
|
|
+ // Because of the way ipallocator manages the container address space,
|
|
|
|
+ // reserve bridge address only if it belongs to the container network
|
|
|
|
+ // (if defined), no need otherwise
|
|
|
|
+ if config.FixedCIDR == nil || config.FixedCIDR.Contains(i.bridgeIPv4.IP) {
|
|
|
|
+ ipAllocator.RequestIP(i.bridgeIPv4, i.bridgeIPv4.IP)
|
|
|
|
+ }
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
@@ -112,10 +115,13 @@ func setupGatewayIPv4(config *networkConfiguration, i *bridgeInterface) error {
|
|
return &ErrInvalidGateway{}
|
|
return &ErrInvalidGateway{}
|
|
}
|
|
}
|
|
|
|
|
|
- // Pass the real network subnet to ip allocator (no host bits set)
|
|
|
|
- sub := types.GetIPNetCanonical(i.bridgeIPv4)
|
|
|
|
- if _, err := ipAllocator.RequestIP(sub, config.DefaultGatewayIPv4); err != nil {
|
|
|
|
- return err
|
|
|
|
|
|
+ // Because of the way ipallocator manages the container address space,
|
|
|
|
+ // reserve default gw address only if it belongs to the container network
|
|
|
|
+ // (if defined), no need otherwise
|
|
|
|
+ if config.FixedCIDR == nil || config.FixedCIDR.Contains(config.DefaultGatewayIPv4) {
|
|
|
|
+ if _, err := ipAllocator.RequestIP(i.bridgeIPv4, config.DefaultGatewayIPv4); err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
// Store requested default gateway
|
|
// Store requested default gateway
|