1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-10 01:17:44 +03:00

networkd: replace a table with log2 fields by a list

This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-11-26 12:05:18 +01:00
parent 0580badc15
commit 8a7da94082

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