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>
---
 bsd/sys/compat/linux/linux_netlink.cc | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/bsd/sys/compat/linux/linux_netlink.cc 
b/bsd/sys/compat/linux/linux_netlink.cc
index ea0cf609..4208ce7f 100644
--- 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);
                }
 
-- 
2.35.1

-- 
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/20220604012837.214986-3-jwkozaczuk%40gmail.com.

Reply via email to