diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-11-12 14:29:12 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2021-11-14 14:41:37 +0900 |
commit | 18b23bd49356e3b5a527badae76761be46517d00 (patch) | |
tree | f5bc7f4460e5c3aef16894e8b33cf00350d7657a /src/network | |
parent | 344b3cff36ecb9b30c56cc924d14676952660664 (diff) | |
download | systemd-18b23bd49356e3b5a527badae76761be46517d00.tar.gz |
network: introduce route_flags_to_string_alloc()
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-route-util.c | 26 | ||||
-rw-r--r-- | src/network/networkd-route-util.h | 2 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/network/networkd-route-util.c b/src/network/networkd-route-util.c index 77e8c2bfb9..c1ab437fac 100644 --- a/src/network/networkd-route-util.c +++ b/src/network/networkd-route-util.c @@ -219,6 +219,32 @@ static const char * const route_protocol_full_table[] = { 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 */ + }; + + 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; + + *ret = TAKE_PTR(str); + return 0; +} + static const char * const route_table_table[] = { [RT_TABLE_DEFAULT] = "default", [RT_TABLE_MAIN] = "main", diff --git a/src/network/networkd-route-util.h b/src/network/networkd-route-util.h index 4b1f778d93..3dd3d3ace8 100644 --- a/src/network/networkd-route-util.h +++ b/src/network/networkd-route-util.h @@ -26,6 +26,8 @@ int route_protocol_to_string_alloc(int t, char **ret); int route_protocol_full_from_string(const char *s); int route_protocol_full_to_string_alloc(int t, char **ret); +int route_flags_to_string_alloc(uint32_t flags, char **ret); + int manager_get_route_table_from_string(const Manager *m, const char *table, uint32_t *ret); int manager_get_route_table_to_string(const Manager *m, uint32_t table, char **ret); |