network: move common route settings to {dhcp4,ndisc}_request_route()
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -403,6 +403,13 @@ static int ndisc_request_route(Route *in, Link *link, sd_ndisc_router *rt) {
|
||||
assert(link);
|
||||
assert(rt);
|
||||
|
||||
if (!route->table_set)
|
||||
route->table = link_get_ipv6_accept_ra_route_table(link);
|
||||
if (!route->priority_set)
|
||||
route->priority = link->network->ipv6_accept_ra_route_metric;
|
||||
if (!route->protocol_set)
|
||||
route->protocol = RTPROT_RA;
|
||||
|
||||
r = link_has_route(link, route);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@@ -536,7 +543,7 @@ static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) {
|
||||
static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
|
||||
_cleanup_(route_freep) Route *route = NULL;
|
||||
struct in6_addr gateway;
|
||||
uint32_t table, mtu = 0;
|
||||
uint32_t mtu = 0;
|
||||
unsigned preference;
|
||||
uint16_t lifetime;
|
||||
usec_t time_now;
|
||||
@@ -581,16 +588,11 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
|
||||
return log_link_error_errno(link, r, "Failed to get default router MTU from RA: %m");
|
||||
}
|
||||
|
||||
table = link_get_ipv6_accept_ra_route_table(link);
|
||||
|
||||
r = route_new(&route);
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
route->family = AF_INET6;
|
||||
route->table = table;
|
||||
route->priority = link->network->ipv6_accept_ra_route_metric;
|
||||
route->protocol = RTPROT_RA;
|
||||
route->pref = preference;
|
||||
route->gw_family = AF_INET6;
|
||||
route->gw.in6 = gateway;
|
||||
@@ -614,12 +616,6 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
|
||||
return r;
|
||||
|
||||
route->gw.in6 = gateway;
|
||||
if (!route->table_set)
|
||||
route->table = table;
|
||||
if (!route->priority_set)
|
||||
route->priority = link->network->ipv6_accept_ra_route_metric;
|
||||
if (!route->protocol_set)
|
||||
route->protocol = RTPROT_RA;
|
||||
if (!route->pref_set)
|
||||
route->pref = preference;
|
||||
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
|
||||
@@ -878,9 +874,6 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
|
||||
return log_oom();
|
||||
|
||||
route->family = AF_INET6;
|
||||
route->table = link_get_ipv6_accept_ra_route_table(link);
|
||||
route->priority = link->network->ipv6_accept_ra_route_metric;
|
||||
route->protocol = RTPROT_RA;
|
||||
route->flags = RTM_F_PREFIX;
|
||||
route->dst_prefixlen = prefixlen;
|
||||
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
|
||||
@@ -961,9 +954,6 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
|
||||
return log_oom();
|
||||
|
||||
route->family = AF_INET6;
|
||||
route->table = link_get_ipv6_accept_ra_route_table(link);
|
||||
route->priority = link->network->ipv6_accept_ra_route_metric;
|
||||
route->protocol = RTPROT_RA;
|
||||
route->pref = preference;
|
||||
route->gw.in6 = gateway;
|
||||
route->gw_family = AF_INET6;
|
||||
|
||||
Reference in New Issue
Block a user