diff --git a/pkg/nl/create.go b/pkg/nl/create.go index 86f90b9c..42f40dbd 100644 --- a/pkg/nl/create.go +++ b/pkg/nl/create.go @@ -36,7 +36,7 @@ func (n *NetlinkManager) createVRF(vrfName string, table int) (*netlink.Vrf, err return &netlinkVrf, nil } -func (n *NetlinkManager) createBridge(bridgeName string, macAddress *net.HardwareAddr, masterIdx, mtu int) (*netlink.Bridge, error) { +func (n *NetlinkManager) createBridge(bridgeName string, macAddress *net.HardwareAddr, masterIdx, mtu int, underlayRMAC bool) (*netlink.Bridge, error) { netlinkBridge := netlink.Bridge{ LinkAttrs: netlink.LinkAttrs{ Name: bridgeName, @@ -48,6 +48,17 @@ func (n *NetlinkManager) createBridge(bridgeName string, macAddress *net.Hardwar } if macAddress != nil { netlinkBridge.LinkAttrs.HardwareAddr = *macAddress + } else if underlayRMAC { + _, vxlanIP, err := getUnderlayInterfaceAndIP() + if err != nil { + return nil, err + } + + generatedMac, err := generateMAC(vxlanIP) + if err != nil { + return nil, err + } + netlinkBridge.LinkAttrs.HardwareAddr = generatedMac } if err := netlink.LinkAdd(&netlinkBridge); err != nil { @@ -61,7 +72,7 @@ func (n *NetlinkManager) createBridge(bridgeName string, macAddress *net.Hardwar } func (n *NetlinkManager) createVXLAN(vxlanName string, bridgeIdx, vni, mtu int, hairpin, neighSuppression bool) (*netlink.Vxlan, error) { - vxlanIf, vxlanIP, err := getInterfaceAndIP(underlayLoopback) + vxlanIf, vxlanIP, err := getUnderlayInterfaceAndIP() if err != nil { return nil, err } @@ -155,7 +166,7 @@ func (*NetlinkManager) setUp(intfName string) error { } func generateUnderlayMAC() (net.HardwareAddr, error) { - _, vxlanIP, err := getInterfaceAndIP(underlayLoopback) + _, vxlanIP, err := getUnderlayInterfaceAndIP() if err != nil { return nil, err } @@ -167,8 +178,8 @@ func generateUnderlayMAC() (net.HardwareAddr, error) { return generatedMac, nil } -func getInterfaceAndIP(name string) (int, net.IP, error) { - dummy := netlink.Dummy{LinkAttrs: netlink.LinkAttrs{Name: name}} +func getUnderlayInterfaceAndIP() (int, net.IP, error) { + dummy := netlink.Dummy{LinkAttrs: netlink.LinkAttrs{Name: underlayLoopback}} addresses, err := netlink.AddrList(&dummy, netlink.FAMILY_V4) if err != nil { diff --git a/pkg/nl/layer2.go b/pkg/nl/layer2.go index f5d8258d..fb96e7b7 100644 --- a/pkg/nl/layer2.go +++ b/pkg/nl/layer2.go @@ -100,7 +100,7 @@ func (n *NetlinkManager) CreateL2(info *Layer2Information) error { } func (n *NetlinkManager) setupBridge(info *Layer2Information, masterIdx int) (*netlink.Bridge, error) { - bridge, err := n.createBridge(fmt.Sprintf("%s%d", layer2Prefix, info.VlanID), info.AnycastMAC, masterIdx, info.MTU) + bridge, err := n.createBridge(fmt.Sprintf("%s%d", layer2Prefix, info.VlanID), info.AnycastMAC, masterIdx, info.MTU, false) if err != nil { return nil, err } diff --git a/pkg/nl/layer3.go b/pkg/nl/layer3.go index e9896402..3574d9ab 100644 --- a/pkg/nl/layer3.go +++ b/pkg/nl/layer3.go @@ -39,7 +39,7 @@ func (n *NetlinkManager) CreateL3(info VRFInformation) error { return err } - bridge, err := n.createBridge(bridgePrefix+info.Name, nil, vrf.Attrs().Index, defaultMtu) + bridge, err := n.createBridge(bridgePrefix+info.Name, nil, vrf.Attrs().Index, defaultMtu, true) if err != nil { return err } diff --git a/pkg/nl/manager.go b/pkg/nl/manager.go index 7fcd2dcb..8873b742 100644 --- a/pkg/nl/manager.go +++ b/pkg/nl/manager.go @@ -29,6 +29,6 @@ type NetlinkManager struct { } func (*NetlinkManager) GetUnderlayIP() (net.IP, error) { - _, ip, err := getInterfaceAndIP(underlayLoopback) + _, ip, err := getUnderlayInterfaceAndIP() return ip, err }