From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
Branch: master

netlink: IFA_ADDRESS needs to go first

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 <jwkozac...@gmail.com>

---
diff --git a/bsd/sys/compat/linux/linux_netlink.cc 
b/bsd/sys/compat/linux/linux_netlink.cc
--- a/bsd/sys/compat/linux/linux_netlink.cc
+++ b/bsd/sys/compat/linux/linux_netlink.cc
@@ -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
@@ -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);
                }
 

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/000000000000c58a0205e1559730%40google.com.

Reply via email to