Skip to content

Commit

Permalink
ensure vxlan mac will be correct with systemd-network MACAddressPolic…
Browse files Browse the repository at this point in the history
…y=random

issue: flannel-io#1795
  • Loading branch information
zhangguanzhang committed Aug 21, 2023
1 parent c17e715 commit b890085
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/backend/vxlan/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,17 @@ func (dev *vxlanDevice) Configure(ipa ip.IP4Net, flannelnet ip.IP4Net) error {
return fmt.Errorf("failed to set interface %s to UP state: %s", dev.link.Attrs().Name, err)
}

// ensure vxlan device hadware mac
// See https://github.com/flannel-io/flannel/issues/1795
nLink, err := netlink.LinkByName(dev.link.LinkAttrs.Name)
if err == nil {
if vxlan, ok := nLink.(*netlink.Vxlan); ok {
if vxlan.Attrs().HardwareAddr.String() != dev.MACAddr().String() {
return fmt.Errorf("%s's mac address wanted: %s, but got: %v", dev.link.Name, dev.MACAddr().String(), vxlan.HardwareAddr)
}
}
}

return nil
}

Expand All @@ -142,6 +153,17 @@ func (dev *vxlanDevice) ConfigureIPv6(ipn ip.IP6Net, flannelnet ip.IP6Net) error
return fmt.Errorf("failed to set v6 interface %s to UP state: %w", dev.link.Attrs().Name, err)
}

// ensure vxlan device hadware mac
// See https://github.com/flannel-io/flannel/issues/1795
nLink, err := netlink.LinkByName(dev.link.LinkAttrs.Name)
if err == nil {
if vxlan, ok := nLink.(*netlink.Vxlan); ok {
if vxlan.Attrs().HardwareAddr.String() != dev.MACAddr().String() {
return fmt.Errorf("%s's v6 mac address wanted: %s, but got: %v", dev.link.Name, dev.MACAddr().String(), vxlan.HardwareAddr)
}
}
}

return nil
}

Expand Down

0 comments on commit b890085

Please sign in to comment.