Merge pull request #833 from mrjana/overlay
Cleanup vxlan interface by id before creating
This commit is contained in:
commit
28c0e8fb6f
2 changed files with 24 additions and 2 deletions
|
@ -267,8 +267,8 @@ func (n *network) initSubnetSandbox(s *subnet) error {
|
||||||
|
|
||||||
vxlanName := n.generateVxlanName(s)
|
vxlanName := n.generateVxlanName(s)
|
||||||
|
|
||||||
// Try to delete the vxlan interface if already present
|
// Try to delete the vxlan interface by vni if already present
|
||||||
deleteVxlan(vxlanName)
|
deleteVxlanByVNI(n.vxlanID(s))
|
||||||
|
|
||||||
err := createVxlan(vxlanName, n.vxlanID(s))
|
err := createVxlan(vxlanName, n.vxlanID(s))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -81,3 +81,25 @@ func deleteVxlan(name string) error {
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteVxlanByVNI(vni uint32) error {
|
||||||
|
defer osl.InitOSContext()()
|
||||||
|
|
||||||
|
links, err := netlink.LinkList()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to list interfaces while deleting vxlan interface by vni: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, l := range links {
|
||||||
|
if l.Type() == "vxlan" && l.(*netlink.Vxlan).VxlanId == int(vni) {
|
||||||
|
err = netlink.LinkDel(l)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error deleting vxlan interface with id %d: %v", vni, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Errorf("could not find a vxlan interface to delete with id %d", vni)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue