2015-02-23 01:58:52 +00:00
|
|
|
package bridge
|
|
|
|
|
2015-05-14 21:56:15 +00:00
|
|
|
import (
|
2016-01-07 02:13:08 +00:00
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/libnetwork/types"
|
2015-05-14 21:56:15 +00:00
|
|
|
"github.com/vishvananda/netlink"
|
|
|
|
)
|
2015-02-23 01:58:52 +00:00
|
|
|
|
2015-05-22 17:56:36 +00:00
|
|
|
func setupVerifyAndReconcile(config *networkConfiguration, i *bridgeInterface) error {
|
2015-02-23 01:58:52 +00:00
|
|
|
// Fetch a single IPv4 and a slice of IPv6 addresses from the bridge.
|
2015-03-04 21:25:43 +00:00
|
|
|
addrv4, addrsv6, err := i.addresses()
|
2015-02-23 01:58:52 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-02-25 02:41:17 +00:00
|
|
|
// Verify that the bridge does have an IPv4 address.
|
|
|
|
if addrv4.IPNet == nil {
|
2015-05-14 21:56:15 +00:00
|
|
|
return &ErrNoIPAddr{}
|
2015-02-25 02:41:17 +00:00
|
|
|
}
|
|
|
|
|
2015-02-23 01:58:52 +00:00
|
|
|
// Verify that the bridge IPv4 address matches the requested configuration.
|
2015-04-15 05:25:42 +00:00
|
|
|
if config.AddressIPv4 != nil && !addrv4.IP.Equal(config.AddressIPv4.IP) {
|
2015-05-14 21:56:15 +00:00
|
|
|
return &IPv4AddrNoMatchError{IP: addrv4.IP, CfgIP: config.AddressIPv4.IP}
|
2015-02-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that one of the bridge IPv6 addresses matches the requested
|
|
|
|
// configuration.
|
2015-04-15 05:25:42 +00:00
|
|
|
if config.EnableIPv6 && !findIPv6Address(netlink.Addr{IPNet: bridgeIPv6}, addrsv6) {
|
2015-04-17 02:47:12 +00:00
|
|
|
return (*IPv6AddrNoMatchError)(bridgeIPv6)
|
2015-02-23 01:58:52 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 02:13:08 +00:00
|
|
|
// Release any residual IPv6 address that might be there because of older daemon instances
|
|
|
|
for _, addrv6 := range addrsv6 {
|
|
|
|
if addrv6.IP.IsGlobalUnicast() && !types.CompareIPNet(addrv6.IPNet, i.bridgeIPv6) {
|
|
|
|
if err := netlink.AddrDel(i.Link, &addrv6); err != nil {
|
|
|
|
log.Warnf("Failed to remove residual IPv6 address %s from bridge: %v", addrv6.IPNet, err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-16 05:02:21 +00:00
|
|
|
|
2015-02-25 02:41:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func findIPv6Address(addr netlink.Addr, addresses []netlink.Addr) bool {
|
|
|
|
for _, addrv6 := range addresses {
|
|
|
|
if addrv6.String() == addr.String() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
2015-02-23 01:58:52 +00:00
|
|
|
}
|