From 8a7da94082bf611ed57f6ddc19acefa1a1473048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 26 Nov 2021 12:05:18 +0100 Subject: [PATCH] networkd: replace a table with log2 fields by a list --- src/network/networkd-route-util.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/network/networkd-route-util.c b/src/network/networkd-route-util.c index c1ab437fac..c57adbe0ab 100644 --- a/src/network/networkd-route-util.c +++ b/src/network/networkd-route-util.c @@ -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;