You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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)
}
I am testing in Ubuntu 22.04, kernel 5.15 with netlink v1.1.0
The text was updated successfully, but these errors were encountered:
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 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 fromip link show
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.I am testing in Ubuntu 22.04, kernel 5.15 with netlink v1.1.0
The text was updated successfully, but these errors were encountered: