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: #1795
  • Loading branch information
zhangguanzhang authored and rbrtbnfgl committed Sep 18, 2023
1 parent ea28613 commit 8bb937c
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 8bb937c

Please sign in to comment.