summaryrefslogtreecommitdiffstats
path: root/src/network
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2024-09-22 23:34:02 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2024-10-11 20:26:07 +0200
commit19931a6d8d2f6e731b4473e08bcbe2ee98d2e9ff (patch)
treecf7d73b845d154862d544a58bfa1e8d71b3d3f17 /src/network
parentnetwork/route: use generic [Route] section parser more (diff)
downloadsystemd-19931a6d8d2f6e731b4473e08bcbe2ee98d2e9ff.tar.xz
systemd-19931a6d8d2f6e731b4473e08bcbe2ee98d2e9ff.zip
network/route: use log_section_warning() more
Diffstat (limited to 'src/network')
-rw-r--r--src/network/networkd-route-nexthop.c72
-rw-r--r--src/network/networkd-route.c2
2 files changed, 28 insertions, 46 deletions
diff --git a/src/network/networkd-route-nexthop.c b/src/network/networkd-route-nexthop.c
index f6f6b4a804..bf0271807b 100644
--- a/src/network/networkd-route-nexthop.c
+++ b/src/network/networkd-route-nexthop.c
@@ -804,6 +804,16 @@ int route_nexthops_read_netlink_message(Route *route, sd_netlink_message *messag
return 0;
}
+#define log_route_section(route, fmt, ...) \
+ ({ \
+ const Route *_route = (route); \
+ log_section_warning_errno( \
+ _route ? _route->section : NULL, \
+ SYNTHETIC_ERRNO(EINVAL), \
+ fmt " Ignoring [Route] section.", \
+ ##__VA_ARGS__); \
+ })
+
int route_section_verify_nexthops(Route *route) {
assert(route);
assert(route->section);
@@ -815,37 +825,30 @@ int route_section_verify_nexthops(Route *route) {
/* When deprecated Gateway=_dhcp is set, then assume gateway family based on other settings. */
switch (route->family) {
case AF_UNSPEC:
- log_warning("%s: Deprecated value \"_dhcp\" is specified for Gateway= in [Route] section from line %u. "
- "Please use \"_dhcp4\" or \"_ipv6ra\" instead. Assuming \"_dhcp4\".",
- route->section->filename, route->section->line);
+ log_section_warning(route->section,
+ "Deprecated value \"_dhcp\" is specified for Gateway=. "
+ "Please use \"_dhcp4\" or \"_ipv6ra\" instead. Assuming \"_dhcp4\".");
route->nexthop.family = route->family = AF_INET;
break;
case AF_INET:
case AF_INET6:
- log_warning("%s: Deprecated value \"_dhcp\" is specified for Gateway= in [Route] section from line %u. "
- "Assuming \"%s\" based on Destination=, Source=, or PreferredSource= setting.",
- route->section->filename, route->section->line, route->family == AF_INET ? "_dhcp4" : "_ipv6ra");
+ log_section_warning(route->section,
+ "Deprecated value \"_dhcp\" is specified for Gateway=. "
+ "Assuming \"%s\" based on Destination=, Source=, or PreferredSource= setting.",
+ route->family == AF_INET ? "_dhcp4" : "_ipv6ra");
route->nexthop.family = route->family;
break;
default:
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: Invalid route family. Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "Invalid route family.");
}
if (route->nexthop.family == AF_INET && !FLAGS_SET(route->network->dhcp, ADDRESS_FAMILY_IPV4))
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: Gateway=\"_dhcp4\" is specified but DHCPv4 client is disabled. "
- "Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "Gateway=\"_dhcp4\" is specified but DHCPv4 client is disabled.");
if (route->nexthop.family == AF_INET6 && route->network->ndisc == 0)
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: Gateway=\"_ipv6ra\" is specified but IPv6AcceptRA= is disabled. "
- "Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "Gateway=\"_ipv6ra\" is specified but IPv6AcceptRA= is disabled.");
}
/* When only Gateway= is specified, assume the route family based on the Gateway address. */
@@ -855,20 +858,14 @@ int route_section_verify_nexthops(Route *route) {
if (route->family == AF_UNSPEC) {
assert(route->section);
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: Route section without Gateway=, Destination=, Source=, "
- "or PreferredSource= field configured. "
- "Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "Route section without Gateway=, Destination=, Source=, or PreferredSource= field configured.");
}
if (route->gateway_onlink < 0 && in_addr_is_set(route->nexthop.family, &route->nexthop.gw) &&
route->network && ordered_hashmap_isempty(route->network->addresses_by_section)) {
/* If no address is configured, in most cases the gateway cannot be reachable.
* TODO: we may need to improve the condition above. */
- log_warning("%s: Gateway= without static address configured. "
- "Enabling GatewayOnLink= option.",
- route->section->filename);
+ log_section_warning(route->section, "Gateway= without static address configured. Enabling GatewayOnLink= option.");
route->gateway_onlink = true;
}
@@ -877,45 +874,30 @@ int route_section_verify_nexthops(Route *route) {
if (route->family == AF_INET6) {
if (route->nexthop.family == AF_INET)
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: IPv4 gateway is configured for IPv6 route. "
- "Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "IPv4 gateway is configured for IPv6 route.");
RouteNextHop *nh;
ORDERED_SET_FOREACH(nh, route->nexthops)
if (nh->family == AF_INET)
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: IPv4 multipath route is specified for IPv6 route. "
- "Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "IPv4 multipath route is specified for IPv6 route.");
}
if (route->nexthop_id != 0 &&
(route->gateway_from_dhcp_or_ra ||
in_addr_is_set(route->nexthop.family, &route->nexthop.gw) ||
!ordered_set_isempty(route->nexthops)))
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: NextHopId= cannot be specified with Gateway= or MultiPathRoute=. "
- "Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "NextHopId= cannot be specified with Gateway= or MultiPathRoute=.");
if (route_is_reject(route) &&
(route->gateway_from_dhcp_or_ra ||
in_addr_is_set(route->nexthop.family, &route->nexthop.gw) ||
!ordered_set_isempty(route->nexthops)))
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: reject type route cannot be specified with Gateway= or MultiPathRoute=. "
- "Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "Reject type route cannot be specified with Gateway= or MultiPathRoute=.");
if ((route->gateway_from_dhcp_or_ra ||
in_addr_is_set(route->nexthop.family, &route->nexthop.gw)) &&
!ordered_set_isempty(route->nexthops))
- return log_warning_errno(SYNTHETIC_ERRNO(EINVAL),
- "%s: Gateway= cannot be specified with MultiPathRoute=. "
- "Ignoring [Route] section from line %u.",
- route->section->filename, route->section->line);
+ return log_route_section(route, "Gateway= cannot be specified with MultiPathRoute=.");
if (ordered_set_size(route->nexthops) == 1) {
_cleanup_(route_nexthop_freep) RouteNextHop *nh = ordered_set_steal_first(route->nexthops);
diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c
index ff88ea20d1..3be737ae49 100644
--- a/src/network/networkd-route.c
+++ b/src/network/networkd-route.c
@@ -1960,7 +1960,7 @@ int route_section_verify(Route *route) {
/* IPv6 route */
if (route->family == AF_INET6) {
if (route->scope != RT_SCOPE_UNIVERSE) {
- log_warning("%s: Scope= is specified for IPv6 route. It will be ignored.", route->section->filename);
+ log_section_warning(route->section, "Scope= is specified for IPv6 route. It will be ignored.");
route->scope = RT_SCOPE_UNIVERSE;
}