]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
networkd: replace a table with log2 fields by a list
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 26 Nov 2021 11:05:18 +0000 (12:05 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 29 Nov 2021 10:16:15 +0000 (11:16 +0100)
src/network/networkd-route-util.c

index c1ab437facfd03fff71b82603dd7dfacb5f36de7..c57adbe0ab0a671e3540aa6c070ae34d83c2b082 100644 (file)
@@ -221,25 +221,22 @@ DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(route_protocol_full, int, UINT8_MAX);
 
 int route_flags_to_string_alloc(uint32_t flags, char **ret) {
         _cleanup_free_ char *str = NULL;
-        static const struct {
-                uint32_t flag;
-                const char *name;
-        } map[] = {
-                { RTNH_F_DEAD,       "dead"       }, /* Nexthop is dead (used by multipath) */
-                { RTNH_F_PERVASIVE,  "pervasive"  }, /* Do recursive gateway lookup */
-                { RTNH_F_ONLINK,     "onlink"     }, /* Gateway is forced on link */
-                { RTNH_F_OFFLOAD,    "offload"    }, /* Nexthop is offloaded */
-                { RTNH_F_LINKDOWN,   "linkdown"   }, /* carrier-down on nexthop */
-                { RTNH_F_UNRESOLVED, "unresolved" }, /* The entry is unresolved (ipmr) */
-                { RTNH_F_TRAP,       "trap"       }, /* Nexthop is trapping packets */
+        static const char* map[] = {
+                [LOG2U(RTNH_F_DEAD)]       = "dead",       /* Nexthop is dead (used by multipath) */
+                [LOG2U(RTNH_F_PERVASIVE)]  = "pervasive",  /* Do recursive gateway lookup */
+                [LOG2U(RTNH_F_ONLINK)]     = "onlink" ,    /* Gateway is forced on link */
+                [LOG2U(RTNH_F_OFFLOAD)]    = "offload",    /* Nexthop is offloaded */
+                [LOG2U(RTNH_F_LINKDOWN)]   = "linkdown",   /* carrier-down on nexthop */
+                [LOG2U(RTNH_F_UNRESOLVED)] = "unresolved", /* The entry is unresolved (ipmr) */
+                [LOG2U(RTNH_F_TRAP)]       = "trap",       /* Nexthop is trapping packets */
         };
 
         assert(ret);
 
         for (size_t i = 0; i < ELEMENTSOF(map); i++)
-                if (flags & map[i].flag &&
-                    !strextend_with_separator(&str, ",", map[i].name))
-                        return -ENOMEM;
+                if (FLAGS_SET(flags, 1 << i) && map[i])
+                        if (!strextend_with_separator(&str, ",", map[i]))
+                                return -ENOMEM;
 
         *ret = TAKE_PTR(str);
         return 0;