summaryrefslogtreecommitdiff
path: root/src/network/networkd-dhcp4.c
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-09-08 13:02:36 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-09-14 15:21:10 +0900
commit429dc05a72644ea677066b2933af893624b95838 (patch)
tree5d68d916648cb10eba475ca0bdf18f54aa1f05db /src/network/networkd-dhcp4.c
parent8be102f8b8019a9bd7e445532cad632cbc6986d3 (diff)
downloadsystemd-429dc05a72644ea677066b2933af893624b95838.tar.gz
network: move common route settings to {dhcp4,ndisc}_request_route()
Diffstat (limited to 'src/network/networkd-dhcp4.c')
-rw-r--r--src/network/networkd-dhcp4.c42
1 files changed, 10 insertions, 32 deletions
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c
index dcc16e0a5d..d7c063267f 100644
--- a/src/network/networkd-dhcp4.c
+++ b/src/network/networkd-dhcp4.c
@@ -197,6 +197,16 @@ static int dhcp4_request_route(Route *in, Link *link) {
assert(route);
assert(link);
+ route->family = AF_INET;
+ if (!route->protocol_set)
+ route->protocol = RTPROT_DHCP;
+ if (!route->priority_set)
+ route->priority = link->network->dhcp_route_metric;
+ if (!route->table_set)
+ route->table = link_get_dhcp_route_table(link);
+ if (route->mtu == 0)
+ route->mtu = link->network->dhcp_route_mtu;
+
r = link_has_route(link, route);
if (r < 0)
return r;
@@ -243,14 +253,10 @@ static int dhcp4_request_prefix_route(Link *link) {
if (r < 0)
return r;
- route->family = AF_INET;
route->dst.in.s_addr = address.s_addr & netmask.s_addr;
route->dst_prefixlen = in4_addr_netmask_to_prefixlen(&netmask);
route->prefsrc.in = address;
route->scope = RT_SCOPE_LINK;
- route->protocol = RTPROT_DHCP;
- route->table = link_get_dhcp_route_table(link);
- route->mtu = link->network->dhcp_route_mtu;
return dhcp4_request_route(TAKE_PTR(route), link);
}
@@ -272,15 +278,10 @@ static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw)
if (r < 0)
return r;
- route->family = AF_INET;
route->dst.in = *gw;
route->dst_prefixlen = 32;
route->prefsrc.in = address;
route->scope = RT_SCOPE_LINK;
- route->protocol = RTPROT_DHCP;
- route->priority = link->network->dhcp_route_metric;
- route->table = link_get_dhcp_route_table(link);
- route->mtu = link->network->dhcp_route_mtu;
return dhcp4_request_route(TAKE_PTR(route), link);
}
@@ -454,12 +455,7 @@ static int dhcp4_request_static_routes(Link *link, struct in_addr *ret_default_g
if (r < 0)
return r;
- route->family = AF_INET;
route->gw_family = AF_INET;
- route->protocol = RTPROT_DHCP;
- route->priority = link->network->dhcp_route_metric;
- route->table = link_get_dhcp_route_table(link);
- route->mtu = link->network->dhcp_route_mtu;
r = sd_dhcp_route_get_gateway(static_routes[i], &gw);
if (r < 0)
@@ -537,14 +533,9 @@ static int dhcp4_request_gateway(Link *link, struct in_addr *gw) {
return r;
/* Next, add a default gateway. */
- route->family = AF_INET;
route->gw_family = AF_INET;
route->gw.in = router[0];
route->prefsrc.in = address;
- route->protocol = RTPROT_DHCP;
- route->priority = link->network->dhcp_route_metric;
- route->table = link_get_dhcp_route_table(link);
- route->mtu = link->network->dhcp_route_mtu;
r = dhcp4_request_route(TAKE_PTR(route), link);
if (r < 0)
@@ -586,14 +577,6 @@ static int dhcp4_request_semi_static_routes(Link *link, const struct in_addr *gw
return r;
route->gw.in = *gw;
- if (!route->protocol_set)
- route->protocol = RTPROT_DHCP;
- if (!route->priority_set)
- route->priority = link->network->dhcp_route_metric;
- if (!route->table_set)
- route->table = link_get_dhcp_route_table(link);
- if (route->mtu == 0)
- route->mtu = link->network->dhcp_route_mtu;
r = dhcp4_request_route(TAKE_PTR(route), link);
if (r < 0)
@@ -627,13 +610,8 @@ static int dhcp4_request_routes_to_servers(
if (r < 0)
return r;
- route->family = AF_INET;
route->dst.in = servers[i];
route->dst_prefixlen = 32;
- route->protocol = RTPROT_DHCP;
- route->priority = link->network->dhcp_route_metric;
- route->table = link_get_dhcp_route_table(link);
- route->mtu = link->network->dhcp_route_mtu;
r = dhcp4_request_route_auto(TAKE_PTR(route), link, gw);
if (r < 0)