Skip to content

Commit

Permalink
netlink: IFA_ADDRESS needs to go first
Browse files Browse the repository at this point in the history
Golang uses the netlink interface RTM_GETADDR to query the network interfaces and IPs.
It assumes that the 1st attribute in the RTM_NEWADDR response is IFA_ADDRESS. This
patch changes the order in which RTM_NEWADDR attributes are sent to make
sure the IFA_ADDRESS goes first and IFA_LABEL last.

This does not seem to be documented anywhere but Linux sends RTM_NEWADDR responses
with the IFA_ADDRESS attribute first so we follow suit.

Signed-off-by: Waldemar Kozaczuk <[email protected]>
  • Loading branch information
wkozaczuk committed Jun 13, 2022
1 parent f8c1f96 commit 73d5664
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bsd/sys/compat/linux/linux_netlink.cc
Original file line number Diff line number Diff line change
Expand Up @@ -599,10 +599,6 @@ netlink_process_getaddr_msg(struct socket *so, struct nlmsghdr *nlm)
ifm->ifa_prefixlen = get_sockaddr_mask_prefix_len(ifa->ifa_netmask);
ifm->ifa_flags = ifp->if_flags | ifp->if_drv_flags;
ifm->ifa_scope = 0; // FIXME:
if (nla_put_string(m, IFA_LABEL, ifp->if_xname)) {
error = ENOBUFS;
goto done;
}
#ifdef INET6
if (ifa->ifa_addr && ifa->ifa_addr->sa_family == AF_INET6){
// FreeBSD embeds the IPv6 scope ID in the IPv6 address
Expand Down Expand Up @@ -635,6 +631,10 @@ netlink_process_getaddr_msg(struct socket *so, struct nlmsghdr *nlm)
goto done;
}
}
if (nla_put_string(m, IFA_LABEL, ifp->if_xname)) {
error = ENOBUFS;
goto done;
}
nlmsg_end(m, nlh);
}

Expand Down

0 comments on commit 73d5664

Please sign in to comment.