interface: warn if ip6hint is truncated
authorUwe Kleine-König <uwe@kleine-koenig.org>
Wed, 20 Nov 2019 18:11:31 +0000 (19:11 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Fri, 29 Nov 2019 17:39:31 +0000 (18:39 +0100)
When for example a /60 is assigned to a network the last 4 bits of the
ip6hint are unused. Emit a warning if any of these unused bits is set as
it indicates that someone didn't understand how the hint is used. (As I
did earlier today resulting in spending some time understanding the
code.)

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
interface.c

index 028dc6ccd5e53fd26ffe498699ba6621461311b9..2fa0613167ad82e4ff9db79aa7c415fd27c51a05 100644 (file)
@@ -863,9 +863,15 @@ interface_alloc(const char *name, struct blob_attr *config, bool dynamic)
        }
 
        iface->assignment_hint = -1;
-       if ((cur = tb[IFACE_ATTR_IP6HINT]))
-               iface->assignment_hint = strtol(blobmsg_get_string(cur), NULL, 16) &
-                               ~((1 << (64 - iface->assignment_length)) - 1);
+       if ((cur = tb[IFACE_ATTR_IP6HINT])) {
+               int32_t assignment_hint = strtol(blobmsg_get_string(cur), NULL, 16);
+
+               iface->assignment_hint = assignment_hint & ~((1 << (64 - iface->assignment_length)) - 1);
+
+               if (iface->assignment_hint != assignment_hint)
+                       netifd_log_message(L_WARNING, "Using truncated assignment hint %d (0x%x) for interface '%s'\n",
+                                          iface->assignment_hint, iface->assignment_hint, iface->name);
+       }
 
        if ((cur = tb[IFACE_ATTR_IP6CLASS]))
                interface_add_assignment_classes(iface, cur);