network: add IPv4LL route right after .network file is parsed
Previously, the route is added when the .network config is assigned to a Link. So, if multiple links match the .network file, the route entry becomes duplicated in the corresponding Network object.
This commit is contained in:
parent
48315d3dca
commit
fa7cd7117f
|
@ -423,6 +423,10 @@ int network_load_one(Manager *manager, const char *filename) {
|
|||
|
||||
network_apply_anonymize_if_set(network);
|
||||
|
||||
r = network_add_ipv4ll_route(network);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "%s: Failed to add IPv4LL route, ignoring: %m", network->filename);
|
||||
|
||||
LIST_PREPEND(networks, manager->networks, network);
|
||||
network->manager = manager;
|
||||
|
||||
|
@ -637,33 +641,11 @@ int network_get(Manager *manager, sd_device *device,
|
|||
}
|
||||
|
||||
int network_apply(Network *network, Link *link) {
|
||||
int r;
|
||||
|
||||
assert(network);
|
||||
assert(link);
|
||||
|
||||
link->network = network;
|
||||
|
||||
if (network->ipv4ll_route) {
|
||||
Route *route;
|
||||
|
||||
r = route_new_static(network, NULL, 0, &route);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = inet_pton(AF_INET, "169.254.0.0", &route->dst.in);
|
||||
if (r == 0)
|
||||
return -EINVAL;
|
||||
if (r < 0)
|
||||
return -errno;
|
||||
|
||||
route->family = AF_INET;
|
||||
route->dst_prefixlen = 16;
|
||||
route->scope = RT_SCOPE_LINK;
|
||||
route->priority = IPV4LL_ROUTE_METRIC;
|
||||
route->protocol = RTPROT_STATIC;
|
||||
}
|
||||
|
||||
if (network->n_dns > 0 ||
|
||||
!strv_isempty(network->ntp) ||
|
||||
!ordered_set_isempty(network->search_domains) ||
|
||||
|
|
|
@ -677,6 +677,34 @@ int route_configure(
|
|||
return 0;
|
||||
}
|
||||
|
||||
int network_add_ipv4ll_route(Network *network) {
|
||||
_cleanup_(route_freep) Route *n = NULL;
|
||||
int r;
|
||||
|
||||
assert(network);
|
||||
|
||||
if (!network->ipv4ll_route)
|
||||
return 0;
|
||||
|
||||
/* IPv4LLRoute= is in [Network] section. */
|
||||
r = route_new_static(network, NULL, 0, &n);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = in_addr_from_string(AF_INET, "169.254.0.0", &n->dst);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
n->family = AF_INET;
|
||||
n->dst_prefixlen = 16;
|
||||
n->scope = RT_SCOPE_LINK;
|
||||
n->priority = IPV4LL_ROUTE_METRIC;
|
||||
n->protocol = RTPROT_STATIC;
|
||||
|
||||
TAKE_PTR(n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_gateway(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
|
|
|
@ -59,6 +59,8 @@ int route_expire_handler(sd_event_source *s, uint64_t usec, void *userdata);
|
|||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Route*, route_free);
|
||||
|
||||
int network_add_ipv4ll_route(Network *network);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_destination);
|
||||
|
|
Loading…
Reference in New Issue