mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Cleanup any stale overlay bridge with overlapping subnet in hostMode
Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
parent
01b8eb7a84
commit
0deffeac4b
2 changed files with 41 additions and 2 deletions
|
@ -361,7 +361,11 @@ func (n *network) generateBridgeName(s *subnet) string {
|
||||||
id = n.id[:5]
|
id = n.id[:5]
|
||||||
}
|
}
|
||||||
|
|
||||||
return "ov-" + fmt.Sprintf("%06x", n.vxlanID(s)) + "-" + id
|
return n.getBridgeNamePrefix(s) + "-" + id
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n *network) getBridgeNamePrefix(s *subnet) string {
|
||||||
|
return "ov-" + fmt.Sprintf("%06x", n.vxlanID(s))
|
||||||
}
|
}
|
||||||
|
|
||||||
func isOverlap(nw *net.IPNet) bool {
|
func isOverlap(nw *net.IPNet) bool {
|
||||||
|
@ -388,7 +392,9 @@ func (n *network) initSubnetSandbox(s *subnet) error {
|
||||||
|
|
||||||
if hostMode {
|
if hostMode {
|
||||||
// Try to delete stale bridge interface if it exists
|
// Try to delete stale bridge interface if it exists
|
||||||
deleteInterface(brName)
|
if err := deleteInterface(brName); err != nil {
|
||||||
|
deleteInterfaceBySubnet(n.getBridgeNamePrefix(s), s)
|
||||||
|
}
|
||||||
// Try to delete the vxlan interface by vni if already present
|
// Try to delete the vxlan interface by vni if already present
|
||||||
deleteVxlanByVNI("", n.vxlanID(s))
|
deleteVxlanByVNI("", n.vxlanID(s))
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,9 @@ package overlay
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/libnetwork/netutils"
|
"github.com/docker/libnetwork/netutils"
|
||||||
"github.com/docker/libnetwork/ns"
|
"github.com/docker/libnetwork/ns"
|
||||||
"github.com/docker/libnetwork/osl"
|
"github.com/docker/libnetwork/osl"
|
||||||
|
@ -69,6 +71,37 @@ func createVxlan(name string, vni uint32) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteInterfaceBySubnet(brPrefix string, s *subnet) error {
|
||||||
|
defer osl.InitOSContext()()
|
||||||
|
|
||||||
|
nlh := ns.NlHandle()
|
||||||
|
links, err := nlh.LinkList()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to list interfaces while deleting bridge interface by subnet: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, l := range links {
|
||||||
|
name := l.Attrs().Name
|
||||||
|
if _, ok := l.(*netlink.Bridge); ok && strings.HasPrefix(name, brPrefix) {
|
||||||
|
addrList, err := nlh.AddrList(l, netlink.FAMILY_V4)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("error getting AddressList for bridge %s", name)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
for _, addr := range addrList {
|
||||||
|
if netutils.NetworkOverlaps(addr.IPNet, s.subnetIP) {
|
||||||
|
err = nlh.LinkDel(l)
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorf("error deleting bridge (%s) with subnet %v: %v", name, addr.IPNet, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func deleteInterface(name string) error {
|
func deleteInterface(name string) error {
|
||||||
defer osl.InitOSContext()()
|
defer osl.InitOSContext()()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue