Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: inconsistent VTEP device MAC address in Ubuntu 22.04 #993

Open
luc99hen opened this issue Jul 22, 2024 · 1 comment
Open

Bug: inconsistent VTEP device MAC address in Ubuntu 22.04 #993

luc99hen opened this issue Jul 22, 2024 · 1 comment

Comments

@luc99hen
Copy link

I use netlink to create a vxlan device and get the created device MAC address directly afterwards. However I found that the MAC address get from netlink is different from ip link show
image

After further digging, I found that the interval is important. When I add a interval after creating, the MAC address is correct.
The test script is as following. Notice that time.Sleep(time.Second*10) makes a difference.

import (
        "fmt"
        "log"
        "net"
        "time"

        "github.com/vishvananda/netlink"
)

func main() {
        vxlanName := "vxlan0"
        vxlanID := 10
        vtepIP := "10.0.0.1"

        // Set up the VXLAN link attributes
        vxlan := &netlink.Vxlan{
                LinkAttrs: netlink.LinkAttrs{
                        Name: vxlanName,
                },
                VxlanId:      vxlanID,
                VtepDevIndex: 0, // Index 0 represents no specific interface bound for VTEP, adjust as necessary
                SrcAddr:      net.ParseIP(vtepIP),
                Port:         4789, // Default VXLAN UDP port
        }

        // Create the VXLAN link
        if err := netlink.LinkAdd(vxlan); err != nil {
                log.Fatalf("Failed to create VXLAN link: %v", err)
        }

        // !!!! This line makes a difference 
        time.Sleep(time.Second*10)

        // Get the link by name
        link, err := netlink.LinkByName(vxlanName)
        if err != nil {
                log.Fatalf("Failed to get VXLAN link: %v", err)
        }

        // Get the MAC address
        mac := link.Attrs().HardwareAddr
        fmt.Printf("MAC address of %s: %s\n", vxlanName, mac)
}

image

I am testing in Ubuntu 22.04, kernel 5.15 with netlink v1.1.0

@luc99hen
Copy link
Author

Now I can confirm that this systemd udev configuration MACAddressPolicy=persistentis the cause of the inconsistency.
When I remove /usr/lib/systemd/network/99-default.link this problem is solved.

I think this may be caused by the race of udev and kernel.

netlink may need to wait udev finishing initializing before performing following task in specific systemd version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant