rpcd-mod-luci: fix reporting network device flags
authorJo-Philipp Wich <[email protected]>
Mon, 6 Feb 2023 14:46:49 +0000 (15:46 +0100)
committerJo-Philipp Wich <[email protected]>
Tue, 7 Feb 2023 09:15:13 +0000 (10:15 +0100)
Fix reporting of ceertain flag values larger than 255, such as IFF_PROMISC
by explicitly casting the bit test expression to a boolean result since
the implicit integer truncation to uint8_t will turn the `0x100` result of
a set IFF_PROMISC bit into just `0x0`.

Signed-off-by: Jo-Philipp Wich <[email protected]>
(cherry picked from commit a570e300061fae7250999c35e4e7215940bca82d)

libs/rpcd-mod-luci/src/luci.c

index 131180a750a23eb78d043e075981bd1a16cbc79e..338d50ac59dc082fd1b62d9a5f3be0eee8b4c2d0 100644 (file)
@@ -788,13 +788,13 @@ rpc_luci_parse_network_device_sys(const char *name, struct ifaddrs *ifaddr)
        blobmsg_close_table(&blob, o2);
 
        o2 = blobmsg_open_table(&blob, "flags");
-       blobmsg_add_u8(&blob, "up", ifa_flags & IFF_UP);
-       blobmsg_add_u8(&blob, "broadcast", ifa_flags & IFF_BROADCAST);
-       blobmsg_add_u8(&blob, "promisc", ifa_flags & IFF_PROMISC);
-       blobmsg_add_u8(&blob, "loopback", ifa_flags & IFF_LOOPBACK);
-       blobmsg_add_u8(&blob, "noarp", ifa_flags & IFF_NOARP);
-       blobmsg_add_u8(&blob, "multicast", ifa_flags & IFF_MULTICAST);
-       blobmsg_add_u8(&blob, "pointtopoint", ifa_flags & IFF_POINTOPOINT);
+       blobmsg_add_u8(&blob, "up", !!(ifa_flags & IFF_UP));
+       blobmsg_add_u8(&blob, "broadcast", !!(ifa_flags & IFF_BROADCAST));
+       blobmsg_add_u8(&blob, "promisc", !!(ifa_flags & IFF_PROMISC));
+       blobmsg_add_u8(&blob, "loopback", !!(ifa_flags & IFF_LOOPBACK));
+       blobmsg_add_u8(&blob, "noarp", !!(ifa_flags & IFF_NOARP));
+       blobmsg_add_u8(&blob, "multicast", !!(ifa_flags & IFF_MULTICAST));
+       blobmsg_add_u8(&blob, "pointtopoint", !!(ifa_flags & IFF_POINTOPOINT));
        blobmsg_close_table(&blob, o2);
 
        o2 = blobmsg_open_table(&blob, "link");