From: Yu Watanabe Date: Thu, 29 Apr 2021 14:30:51 +0000 (+0900) Subject: network: make log_route_debug() show multipath routes and Gateway=_dhcp4 or _ipv6ra X-Git-Tag: v249-rc1~240^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b19afdfef89d399d9b2524277acdabf4e28fa3a4;p=thirdparty%2Fsystemd.git network: make log_route_debug() show multipath routes and Gateway=_dhcp4 or _ipv6ra --- diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 35fc1184f90..88dd3d4a2af 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -743,13 +743,14 @@ bool manager_address_is_reachable(Manager *manager, int family, const union in_a return false; } -static void log_route_debug(const Route *route, const char *str, const Link *link, const Manager *m) { - _cleanup_free_ char *dst = NULL, *src = NULL, *gw = NULL, *prefsrc = NULL, +static void log_route_debug(const Route *route, const char *str, const Link *link, const Manager *manager) { + _cleanup_free_ char *dst = NULL, *src = NULL, *gw_alloc = NULL, *prefsrc = NULL, *table = NULL, *scope = NULL, *proto = NULL; + const char *gw = NULL; assert(route); assert(str); - assert(m); + assert(manager); /* link may be NULL. */ @@ -760,12 +761,32 @@ static void log_route_debug(const Route *route, const char *str, const Link *lin (void) in_addr_prefix_to_string(route->family, &route->dst, route->dst_prefixlen, &dst); if (in_addr_is_set(route->family, &route->src)) (void) in_addr_to_string(route->family, &route->src, &src); - if (in_addr_is_set(route->gw_family, &route->gw)) - (void) in_addr_to_string(route->gw_family, &route->gw, &gw); + if (in_addr_is_set(route->gw_family, &route->gw)) { + (void) in_addr_to_string(route->gw_family, &route->gw, &gw_alloc); + gw = gw_alloc; + } else if (route->gateway_from_dhcp_or_ra) { + if (route->gw_family == AF_INET) + gw = "_dhcp4"; + else if (route->gw_family == AF_INET6) + gw = "_ipv6ra"; + } else { + MultipathRoute *m; + + ORDERED_SET_FOREACH(m, route->multipath_routes) { + _cleanup_free_ char *buf = NULL, *joined = NULL; + union in_addr_union a = m->gateway.address; + + (void) in_addr_to_string(m->gateway.family, &a, &buf); + joined = strjoin(gw_alloc, gw_alloc ? "," : "", strna(buf), m->ifname ? "@" : "", strempty(m->ifname)); + if (joined) + free_and_replace(gw_alloc, joined); + } + gw = gw_alloc; + } if (in_addr_is_set(route->family, &route->prefsrc)) (void) in_addr_to_string(route->family, &route->prefsrc, &prefsrc); (void) route_scope_to_string_alloc(route->scope, &scope); - (void) manager_get_route_table_to_string(m, route->table, &table); + (void) manager_get_route_table_to_string(manager, route->table, &table); (void) route_protocol_full_to_string_alloc(route->protocol, &proto); log_link_debug(link,