1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-08 21:17:47 +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) {
_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;