Cleanup vxlan interface by id before creating
Currently we are cleaning up vxlan interfaces by name before trying to setup an interface with the same name. But this doesn't work for properly cleaning up vxlan interfaces with the same vni, if the interface has a a different name than the one expected. The fix is to delete the interface based on vni. Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
parent
b464d40ce6
commit
66141b879f
2 changed files with 24 additions and 2 deletions
|
@ -267,8 +267,8 @@ func (n *network) initSubnetSandbox(s *subnet) error {
|
|||
|
||||
vxlanName := n.generateVxlanName(s)
|
||||
|
||||
// Try to delete the vxlan interface if already present
|
||||
deleteVxlan(vxlanName)
|
||||
// Try to delete the vxlan interface by vni if already present
|
||||
deleteVxlanByVNI(n.vxlanID(s))
|
||||
|
||||
err := createVxlan(vxlanName, n.vxlanID(s))
|
||||
if err != nil {
|
||||
|
|
|
@ -81,3 +81,25 @@ func deleteVxlan(name string) error {
|
|||
|
||||
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…
Reference in a new issue