Skip to content

Commit c4d24e8

Browse files
authored
Merge pull request #809 from squeed/bridge-refresh-mac
bridge: refresh host-veth mac after port add
2 parents 0924b71 + 2c4c27e commit c4d24e8

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

plugins/main/bridge/bridge.go

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ func loadNetConf(bytes []byte, envArgs string) (*NetConf, string, error) {
126126

127127
// calcGateways processes the results from the IPAM plugin and does the
128128
// following for each IP family:
129-
// - Calculates and compiles a list of gateway addresses
130-
// - Adds a default route if needed
129+
// - Calculates and compiles a list of gateway addresses
130+
// - Adds a default route if needed
131131
func calcGateways(result *current.Result, n *NetConf) (*gwInfo, *gwInfo, error) {
132132

133133
gwsV4 := &gwInfo{}
@@ -517,24 +517,6 @@ func cmdAdd(args *skel.CmdArgs) error {
517517
return err
518518
}
519519

520-
// check bridge port state
521-
retries := []int{0, 50, 500, 1000, 1000}
522-
for idx, sleep := range retries {
523-
time.Sleep(time.Duration(sleep) * time.Millisecond)
524-
525-
hostVeth, err := netlink.LinkByName(hostInterface.Name)
526-
if err != nil {
527-
return err
528-
}
529-
if hostVeth.Attrs().OperState == netlink.OperUp {
530-
break
531-
}
532-
533-
if idx == len(retries)-1 {
534-
return fmt.Errorf("bridge port in error state: %s", hostVeth.Attrs().OperState)
535-
}
536-
}
537-
538520
if n.IsGW {
539521
var firstV4Addr net.IP
540522
var vlanInterface *current.Interface
@@ -601,6 +583,29 @@ func cmdAdd(args *skel.CmdArgs) error {
601583
}
602584
}
603585

586+
var hostVeth netlink.Link
587+
588+
// check bridge port state
589+
retries := []int{0, 50, 500, 1000, 1000}
590+
for idx, sleep := range retries {
591+
time.Sleep(time.Duration(sleep) * time.Millisecond)
592+
593+
hostVeth, err = netlink.LinkByName(hostInterface.Name)
594+
if err != nil {
595+
return err
596+
}
597+
if hostVeth.Attrs().OperState == netlink.OperUp {
598+
break
599+
}
600+
601+
if idx == len(retries)-1 {
602+
return fmt.Errorf("bridge port in error state: %s", hostVeth.Attrs().OperState)
603+
}
604+
}
605+
606+
// In certain circumstances, the host-side of the veth may change addrs
607+
hostInterface.Mac = hostVeth.Attrs().HardwareAddr.String()
608+
604609
// Refetch the bridge since its MAC address may change when the first
605610
// veth is added or after its IP address is set
606611
br, err = bridgeByName(n.BrName)

0 commit comments

Comments
 (0)