vishvananda/netlink

LinkAttrs.Alias not being set by LinkAdd

maxmoehl opened this issue · 0 comments

TL;DR: When creating a device which has the alias set in its link attributes the alias is not present on the device after creation. This is most likely because the linux kernel does not support that property when creating new devices.

When I noticed this behaviour I started tracing what exactly was being sent via netlink by using strace. The property is being sent like this [{nla_len=11, nla_type=IFLA_IFALIAS}, "foobar"] but when fetching the device after creation this property is missing in the response. After modifying the device with netlink.LinkSetAlias which results in this syscall:

sendto(3, [{nlmsg_len=44, nlmsg_type=RTM_SETLINK, nlmsg_flags=NLM_F_REQUEST|NLM_F_ACK, nlmsg_seq=6, nlmsg_pid=0}, {ifi_family=AF_UNSPEC, ifi_type=ARPHRD_NETROM, ifi_index=if_nametoindex("test0"), ifi_flags=0, ifi_change=0}, [{nla_len=10, nla_type=IFLA_IFALIAS}, "foobar"...]], 44, 0, {sa_family=AF_NETLINK, nl_pid=0, nl_groups=00000000}, 12) = 44

the alias is set and can be retrieved.

I started looking at the kernel implementation and found __rtnl_newlink. It distinguishes between new and existing devices and if the device exists, it is modified using do_setlink which does indeed set the alias. But if the device does not exist, rtnl_newlink_create is called which only sets very few properties.

Proposal: Set the link alias after the device has been created, like it's already done for the device master.

I'll prepare a PR for this if it's accepted.