From 7cf0ed03f27c5facb4d1ca7edba33404290deee8 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 9 Dec 2021 06:51:29 +0900 Subject: [PATCH 1/3] network: route: show prefix length of the source in debugging logs Similar fix to b489d6a26e44d430a997e756ac81767f6e646976. --- src/network/networkd-route.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 82873e9a91..0693cbdee4 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -560,8 +560,8 @@ static void log_route_debug(const Route *route, const char *str, const Link *lin (void) network_config_state_to_string_alloc(route->state, &state); if (in_addr_is_set(route->family, &route->dst) || route->dst_prefixlen > 0) (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->family, &route->src) || route->src_prefixlen > 0) + (void) in_addr_prefix_to_string(route->family, &route->src, route->src_prefixlen, &src); 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; From e944711fba9243b3d141879dc78f4a2ee6f12292 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 9 Dec 2021 06:56:26 +0900 Subject: [PATCH 2/3] network: json: add src address when its prefix length is non-zero This should not change anything. Just for consistency with route_set_netlink_message(), which sets RTA_SRC attribute when prefix length is non-zero. --- src/network/networkd-json.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/network/networkd-json.c b/src/network/networkd-json.c index aa0c606543..f2bd4982fe 100644 --- a/src/network/networkd-json.c +++ b/src/network/networkd-json.c @@ -299,9 +299,9 @@ static int route_build_json(Route *route, JsonVariant **ret) { JSON_BUILD_PAIR_IN_ADDR("Destination", &route->dst, route->family), JSON_BUILD_PAIR_UNSIGNED("DestinationPrefixLength", route->dst_prefixlen), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Gateway", &route->gw, route->gw_family), - JSON_BUILD_PAIR_IN_ADDR_NON_NULL("Source", &route->src, route->family), - JSON_BUILD_PAIR_CONDITION(in_addr_is_set(route->family, &route->src), - "SourcePrefixLength", JSON_BUILD_UNSIGNED(route->src_prefixlen)), + JSON_BUILD_PAIR_CONDITION(route->src_prefixlen > 0, + "Source", JSON_BUILD_IN_ADDR(&route->src, route->family)), + JSON_BUILD_PAIR_UNSIGNED_NON_ZERO("SourcePrefixLength", route->src_prefixlen), JSON_BUILD_PAIR_IN_ADDR_NON_NULL("PreferredSource", &route->prefsrc, route->family), JSON_BUILD_PAIR_UNSIGNED("Scope", route->scope), JSON_BUILD_PAIR_STRING("ScopeString", scope), From 72fa19239d8e11d993ea9a73b129b0bd6deaf736 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 9 Dec 2021 07:01:47 +0900 Subject: [PATCH 3/3] network: route: mask lower bits of destination or source prefix Let's gracefully handle user's misconfiguration, e.g. Destination=192.168.0.1/24 --- src/network/networkd-route.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index 0693cbdee4..d791c4d044 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -2124,6 +2124,8 @@ int config_parse_destination( return 0; } + (void) in_addr_mask(n->family, buffer, *prefixlen); + TAKE_PTR(n); return 0; }