[Babel-users] [PATCH v2] Use per-table dumps on kernels where this is available

Toke Høiland-Jørgensen toke at toke.dk
Sat Apr 16 22:55:46 BST 2022


Toke Høiland-Jørgensen <toke at toke.dk> writes:

> Daniel Gröber <dxld at darkboxed.org> writes:
>
>> Hi Toke,
>>
>> That still doesn't seem to work, I get
>>
>>     Interface eth0 has no link-local address.
>>
>> so it seems to getaddr stuff is still not working.
>
> Huh, that's odd. What's the debug output? If I keep the 'struct rtmsg'
> for GETADDR, I get this (running './babeld -C "interface testns" -d 1000'):
>
> Warning: couldn't find router id -- using random value.
> Noticed ifindex change for testns.
> Noticed status change for testns.
> Sending seqno 10686 from address 0x560a9f65b2d0 (dump)
> Netlink message: [multi] {seq:10686}(done)
>
> Interface testns has no link-local address.
> setsockopt(IPV6_LEAVE_GROUP): Cannot assign requested address
>
> But with v2 (changed to ifaddrmsg):
>
> Warning: couldn't find router id -- using random value.
> Noticed ifindex change for testns.
> Noticed status change for testns.
> Sending seqno 10633 from address 0x558297f642d0 (dump)
> Netlink message: [multi] {seq:10633}(msg -> "found address on interface lo(1): 127.0.0.1
> " 0), 
> Netlink message: [multi] {seq:10633}(msg -> "found address on interface lo(1): ::1
> " 0), [multi] {seq:10633}(msg -> "found address on interface testns(6): fc00:dead:cafe:1::1
> " 0), [multi] {seq:10633}(msg -> "found address on interface testns(6): fe80::f886:d0ff:fe92:87e5
> " 1), 
> Netlink message: [multi] {seq:10633}(done)
>
> Upped interface testns (cost=96, channel=-2).

Here's another patch (on top of the v2) which adds extack support to
babeld as a debugging aid. With this I get:

Warning: couldn't find router id -- using random value.
Noticed ifindex change for testns.
Noticed status change for testns.
Sending seqno 14782 from address 0x5565815462d0 (dump)
Netlink message: [multi] {seq:14782} extack: 'bytes leftover after parsing attributes' (done)

Interface testns has no link-local address.
setsockopt(IPV6_LEAVE_GROUP): Cannot assign requested address

-Toke



commit b72fbe315eb99614fc4fdc853877261379453c1f
Author: Toke Høiland-Jørgensen <toke at toke.dk>
Date:   Sat Apr 16 23:51:41 2022 +0200

    Enable extended acknowledgements for netlink messages
    
    When something goes wrong with a netlink request, the kernel may return a
    human-friendly error message using the 'extack' functionality. This is
    opt-in however, so this patch adds parsing and display of such error
    messages to the netlink debug output.
    
    Signed-off-by: Toke Høiland-Jørgensen <toke at toke.dk>

diff --git a/kernel_netlink.c b/kernel_netlink.c
index d400c1153d74..dd2597f5cb64 100644
--- a/kernel_netlink.c
+++ b/kernel_netlink.c
@@ -288,7 +288,7 @@ static int nl_setup = 0;
 static int
 netlink_socket(struct netlink *nl, uint32_t groups)
 {
-    int rc, strict = 1;
+    int rc, one = 1;
     int rcvsize = 512 * 1024;
 
     nl->sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
@@ -324,8 +324,14 @@ netlink_socket(struct netlink *nl, uint32_t groups)
         }
     }
 
+    /* may not be supported, so ignore return code */
+    rc = setsockopt(nl->sock, SOL_NETLINK, NETLINK_EXT_ACK,
+                    &one, sizeof(one));
+    if(rc < 0)
+        goto fail;
+
     rc = setsockopt(nl->sock, SOL_NETLINK, NETLINK_GET_STRICT_CHK,
-                    &strict, sizeof(strict));
+                    &one, sizeof(one));
     per_table_dumps = (rc == 0);
 
     rc = bind(nl->sock, (struct sockaddr *)&nl->sockaddr, nl->socklen);
@@ -348,6 +354,43 @@ netlink_socket(struct netlink *nl, uint32_t groups)
     }
 }
 
+#define NLA_OK(nla,len) ((len) >= (int)sizeof(struct nlattr) && \
+			 (nla)->nla_len >= sizeof(struct nlattr) && \
+			 (nla)->nla_len <= (len))
+#define NLA_NEXT(nla,attrlen)	((attrlen) -= NLA_ALIGN((nla)->nla_len), \
+				 (struct nlattr*)(((char*)(nla)) + NLA_ALIGN((nla)->nla_len)))
+#define NLA_LENGTH(len)	(NLA_ALIGN(sizeof(struct nlattr)) + (len))
+#define NLA_DATA(nla)   ((void*)(((char*)(nla)) + NLA_LENGTH(0)))
+
+static int netlink_get_extack(struct nlmsghdr *nh, int len, int done)
+{
+    const char *msg = NULL;
+    struct nlattr *nla;
+
+    if (done) {
+        nla = NLMSG_DATA(nh) + sizeof(int);
+        len -= NLMSG_ALIGN(int);
+    } else {
+        nla = NLMSG_DATA(nh) + sizeof(struct nlmsgerr);
+        len -= NLMSG_ALIGN(sizeof(struct nlmsgerr));
+
+        if (!(nh->nlmsg_flags & NLM_F_ACK_TLVS))
+            return 0;
+    }
+
+    while(NLA_OK(nla, len)) {
+        if(nla->nla_type == NLMSGERR_ATTR_MSG)
+            msg = NLA_DATA(nla);
+
+        nla = NLA_NEXT(nla, len);
+    }
+
+    if(msg && *msg != '\0')
+        kdebugf(" extack: '%s' ", msg);
+
+    return 0;
+}
+
 static int
 netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
              struct kernel_filter *filter)
@@ -434,11 +477,13 @@ netlink_read(struct netlink *nl, struct netlink *nl_ignore, int answer,
                         nh->nlmsg_pid, nl->sockaddr.nl_pid);
                 continue;
             } else if(nh->nlmsg_type == NLMSG_DONE) {
+                netlink_get_extack(nh, len, 1);
                 kdebugf("(done)\n");
                 done = 1;
                 break;
             } else if(nh->nlmsg_type == NLMSG_ERROR) {
                 struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(nh);
+                netlink_get_extack(nh, len, 0);
                 if(err->error == 0) {
                     kdebugf("(ACK)\n");
                     return 0;



More information about the Babel-users mailing list