Skip to content

Commit

Permalink
Only delete macvlan when setting bridge as master
Browse files Browse the repository at this point in the history
  • Loading branch information
yaocw2020 authored and guangbochen committed Sep 22, 2021
1 parent e88b235 commit 48c1114
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/network/iface/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,18 @@ func (l *Link) DelBridgeVlan(vid uint16) error {
return nil
}

// clearSublink to delete all the sublink
func (l *Link) clearSubLink() error {
// clearMacvlan to delete all the macvlan interfaces whose parent index equals l.Index()
func (l *Link) clearMacVlan() error {
links, err := netlink.LinkList()
if err != nil {
return err
}
for _, link := range links {
if link.Attrs().ParentIndex == l.Index() {
if link.Attrs().ParentIndex == l.Index() && link.Type() == "macvlan" {
if err := netlink.LinkDel(link); err != nil {
return err
}
klog.Infof("delete macvlan interface %s", link.Attrs().Name)
}
}

Expand All @@ -133,7 +134,7 @@ func (l *Link) SetMaster(br *Bridge, vids []uint16) error {
return nil
}

if err := l.clearSubLink(); err != nil {
if err := l.clearMacVlan(); err != nil {
return err
}
if err := netlink.LinkSetMaster(l.link, br.bridge); err != nil {
Expand Down Expand Up @@ -171,7 +172,7 @@ func (l *Link) SetNoMaster() error {
if err != nil {
return err
}
if err := masterLink.clearSubLink(); err != nil {
if err := masterLink.clearMacVlan(); err != nil {
return err
}
if err := netlink.LinkSetNoMaster(l.link); err != nil {
Expand Down

0 comments on commit 48c1114

Please sign in to comment.