|
@@ -76,6 +76,21 @@ func checkRouteOverlaps(networks []*net.IPNet, dockerNetwork *net.IPNet) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func checkNameserverOverlaps(nameservers []string, dockerNetwork *net.IPNet) error {
|
|
|
|
+ if len(nameservers) > 0 {
|
|
|
|
+ for _, ns := range nameservers {
|
|
|
|
+ _, nsNetwork, err := net.ParseCIDR(ns)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ if networkOverlaps(dockerNetwork, nsNetwork) {
|
|
|
|
+ return fmt.Errorf("%s overlaps nameserver %s", dockerNetwork, nsNetwork)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
// CreateBridgeIface creates a network bridge interface on the host system with the name `ifaceName`,
|
|
// CreateBridgeIface creates a network bridge interface on the host system with the name `ifaceName`,
|
|
// and attempts to configure it with an address which doesn't conflict with any other interface on the host.
|
|
// and attempts to configure it with an address which doesn't conflict with any other interface on the host.
|
|
// If it can't find an address which doesn't conflict, it will return an error.
|
|
// If it can't find an address which doesn't conflict, it will return an error.
|
|
@@ -100,6 +115,16 @@ func CreateBridgeIface(config *DaemonConfig) error {
|
|
"192.168.44.1/24",
|
|
"192.168.44.1/24",
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ nameservers := []string{}
|
|
|
|
+ resolvConf, _ := utils.GetResolvConf()
|
|
|
|
+ // we don't check for an error here, because we don't really care
|
|
|
|
+ // if we can't read /etc/resolv.conf. So instead we skip the append
|
|
|
|
+ // if resolvConf is nil. It either doesn't exist, or we can't read it
|
|
|
|
+ // for some reason.
|
|
|
|
+ if resolvConf != nil {
|
|
|
|
+ nameservers = append(nameservers, utils.GetNameserversAsCIDR(resolvConf)...)
|
|
|
|
+ }
|
|
|
|
+
|
|
var ifaceAddr string
|
|
var ifaceAddr string
|
|
for _, addr := range addrs {
|
|
for _, addr := range addrs {
|
|
_, dockerNetwork, err := net.ParseCIDR(addr)
|
|
_, dockerNetwork, err := net.ParseCIDR(addr)
|
|
@@ -111,8 +136,10 @@ func CreateBridgeIface(config *DaemonConfig) error {
|
|
return err
|
|
return err
|
|
}
|
|
}
|
|
if err := checkRouteOverlaps(routes, dockerNetwork); err == nil {
|
|
if err := checkRouteOverlaps(routes, dockerNetwork); err == nil {
|
|
- ifaceAddr = addr
|
|
|
|
- break
|
|
|
|
|
|
+ if err := checkNameserverOverlaps(nameservers, dockerNetwork); err == nil {
|
|
|
|
+ ifaceAddr = addr
|
|
|
|
+ break
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
utils.Debugf("%s: %s", addr, err)
|
|
utils.Debugf("%s: %s", addr, err)
|
|
}
|
|
}
|