Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: support hotplug a nic several times
Browse files Browse the repository at this point in the history
Bind back the nic's MAC in HotDetach. So we don't need to modify
nic's MAC in description to hotplug it again.

Fixes: #894

Signed-off-by: Ruidong Cao <[email protected]>
  • Loading branch information
caoruidong committed Nov 9, 2018
1 parent d895cd0 commit 2f98b3e
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions virtcontainers/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,15 @@ func untapNetworkPair(endpoint Endpoint) error {
return err
}

hardAddr, err := net.ParseMAC(netPair.TAPIface.HardAddr)
if err != nil {
return err
}
if err := netHandle.LinkSetHardwareAddr(link, hardAddr); err != nil {
return fmt.Errorf("Could not set MAC address %s for veth interface %s: %s",
netPair.VirtIface.HardAddr, netPair.VirtIface.Name, err)
}

if err := netHandle.LinkSetDown(link); err != nil {
return fmt.Errorf("Could not disable veth %s: %s", netPair.VirtIface.Name, err)
}
Expand Down Expand Up @@ -1038,6 +1047,15 @@ func unBridgeNetworkPair(endpoint Endpoint) error {
return err
}

hardAddr, err := net.ParseMAC(netPair.TAPIface.HardAddr)
if err != nil {
return err
}
if err := netHandle.LinkSetHardwareAddr(link, hardAddr); err != nil {
return fmt.Errorf("Could not set MAC address %s for veth interface %s: %s",
netPair.VirtIface.HardAddr, netPair.VirtIface.Name, err)
}

if err := netHandle.LinkSetDown(link); err != nil {
return fmt.Errorf("Could not disable veth %s: %s", netPair.VirtIface.Name, err)
}
Expand Down

0 comments on commit 2f98b3e

Please sign in to comment.