Lines Matching refs:link
29 bool link_ipv6_accept_ra_enabled(Link *link) { in link_ipv6_accept_ra_enabled() argument
30 assert(link); in link_ipv6_accept_ra_enabled()
35 if (link->flags & IFF_LOOPBACK) in link_ipv6_accept_ra_enabled()
38 if (link->iftype == ARPHRD_CAN) in link_ipv6_accept_ra_enabled()
41 if (link->hw_addr.length != ETH_ALEN && !streq_ptr(link->kind, "wwan")) in link_ipv6_accept_ra_enabled()
47 if (!link->network) in link_ipv6_accept_ra_enabled()
50 if (!link_may_have_ipv6ll(link)) in link_ipv6_accept_ra_enabled()
53 assert(link->network->ipv6_accept_ra >= 0); in link_ipv6_accept_ra_enabled()
54 return link->network->ipv6_accept_ra; in link_ipv6_accept_ra_enabled()
81 static int ndisc_remove(Link *link, struct in6_addr *router) { in ndisc_remove() argument
89 assert(link); in ndisc_remove()
91 SET_FOREACH(route, link->routes) { in ndisc_remove()
103 route_cancel_request(route, link); in ndisc_remove()
106 SET_FOREACH(address, link->addresses) { in ndisc_remove()
121 SET_FOREACH(rdnss, link->ndisc_rdnss) { in ndisc_remove()
127 free(set_remove(link->ndisc_rdnss, rdnss)); in ndisc_remove()
131 SET_FOREACH(dnssl, link->ndisc_dnssl) { in ndisc_remove()
137 free(set_remove(link->ndisc_dnssl, dnssl)); in ndisc_remove()
142 link_dirty(link); in ndisc_remove()
147 static int ndisc_check_ready(Link *link);
153 assert(address->link); in ndisc_address_ready_callback()
155 SET_FOREACH(a, address->link->addresses) in ndisc_address_ready_callback()
159 return ndisc_check_ready(address->link); in ndisc_address_ready_callback()
162 static int ndisc_check_ready(Link *link) { in ndisc_check_ready() argument
167 assert(link); in ndisc_check_ready()
169 if (link->ndisc_messages > 0) { in ndisc_check_ready()
170 log_link_debug(link, "%s(): SLAAC addresses and routes are not set.", __func__); in ndisc_check_ready()
174 SET_FOREACH(address, link->addresses) { in ndisc_check_ready()
187 SET_FOREACH(address, link->addresses) in ndisc_check_ready()
191 log_link_debug(link, "%s(): no SLAAC address is ready.", __func__); in ndisc_check_ready()
195 link->ndisc_configured = true; in ndisc_check_ready()
196 log_link_debug(link, "SLAAC addresses and routes set."); in ndisc_check_ready()
198 r = ndisc_remove(link, NULL); in ndisc_check_ready()
202 link_check_ready(link); in ndisc_check_ready()
206 static int ndisc_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, R… in ndisc_route_handler() argument
209 assert(link); in ndisc_route_handler()
211 r = route_configure_handler_internal(rtnl, m, link, "Could not set NDisc route"); in ndisc_route_handler()
215 r = ndisc_check_ready(link); in ndisc_route_handler()
217 link_enter_failed(link); in ndisc_route_handler()
222 static int ndisc_request_route(Route *in, Link *link, sd_ndisc_router *rt) { in ndisc_request_route() argument
229 assert(link); in ndisc_request_route()
239 route->table = link_get_ipv6_accept_ra_route_table(link); in ndisc_request_route()
241 route->priority = link->network->ipv6_accept_ra_route_metric; in ndisc_request_route()
245 if (route_get(NULL, link, route, &existing) < 0) in ndisc_request_route()
246 link->ndisc_configured = false; in ndisc_request_route()
250 return link_request_route(link, TAKE_PTR(route), true, &link->ndisc_messages, in ndisc_request_route()
254 static int ndisc_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link,… in ndisc_address_handler() argument
257 assert(link); in ndisc_address_handler()
259 r = address_configure_handler_internal(rtnl, m, link, "Could not set NDisc address"); in ndisc_address_handler()
263 r = ndisc_check_ready(link); in ndisc_address_handler()
265 link_enter_failed(link); in ndisc_address_handler()
270 static int ndisc_request_address(Address *in, Link *link, sd_ndisc_router *rt) { in ndisc_request_address() argument
277 assert(link); in ndisc_request_address()
287 if (address_get(link, address, &existing) < 0) in ndisc_request_address()
288 link->ndisc_configured = false; in ndisc_request_address()
292 return link_request_address(link, TAKE_PTR(address), true, &link->ndisc_messages, in ndisc_request_address()
296 static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) { in ndisc_router_process_default() argument
304 assert(link); in ndisc_router_process_default()
305 assert(link->network); in ndisc_router_process_default()
308 if (!link->network->ipv6_accept_ra_use_gateway && in ndisc_router_process_default()
309 hashmap_isempty(link->network->routes_by_section)) in ndisc_router_process_default()
314 return log_link_error_errno(link, r, "Failed to get gateway lifetime from RA: %m"); in ndisc_router_process_default()
321 return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); in ndisc_router_process_default()
327 return log_link_error_errno(link, r, "Failed to get gateway address from RA: %m"); in ndisc_router_process_default()
329 if (link_get_ipv6_address(link, &gateway, 0, NULL) >= 0) { in ndisc_router_process_default()
334 … log_link_debug(link, "No NDisc route added, gateway %s matches local address", in ndisc_router_process_default()
342 … return log_link_error_errno(link, r, "Failed to get default router preference from RA: %m"); in ndisc_router_process_default()
344 if (link->network->ipv6_accept_ra_use_mtu) { in ndisc_router_process_default()
347 … return log_link_error_errno(link, r, "Failed to get default router MTU from RA: %m"); in ndisc_router_process_default()
350 if (link->network->ipv6_accept_ra_use_gateway) { in ndisc_router_process_default()
364 r = ndisc_request_route(TAKE_PTR(route), link, rt); in ndisc_router_process_default()
366 return log_link_error_errno(link, r, "Could not request default route: %m"); in ndisc_router_process_default()
370 HASHMAP_FOREACH(route_gw, link->network->routes_by_section) { in ndisc_router_process_default()
390 r = ndisc_request_route(TAKE_PTR(route), link, rt); in ndisc_router_process_default()
392 return log_link_error_errno(link, r, "Could not request gateway: %m"); in ndisc_router_process_default()
398 static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *rt) { in ndisc_router_process_autonomous_prefix() argument
406 assert(link); in ndisc_router_process_autonomous_prefix()
407 assert(link->network); in ndisc_router_process_autonomous_prefix()
410 if (!link->network->ipv6_accept_ra_use_autonomous_prefix) in ndisc_router_process_autonomous_prefix()
415 return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); in ndisc_router_process_autonomous_prefix()
419 return log_link_error_errno(link, r, "Failed to get prefix address: %m"); in ndisc_router_process_autonomous_prefix()
423 return log_link_error_errno(link, r, "Failed to get prefix length: %m"); in ndisc_router_process_autonomous_prefix()
430 … log_link_debug(link, "Prefix is longer than 64, ignoring autonomous prefix %s.", strna(buf)); in ndisc_router_process_autonomous_prefix()
436 return log_link_error_errno(link, r, "Failed to get prefix valid lifetime: %m"); in ndisc_router_process_autonomous_prefix()
439 log_link_debug(link, "Ignoring prefix as its valid lifetime is zero."); in ndisc_router_process_autonomous_prefix()
445 return log_link_error_errno(link, r, "Failed to get prefix preferred lifetime: %m"); in ndisc_router_process_autonomous_prefix()
454 r = ndisc_generate_addresses(link, &prefix, prefixlen, &addresses); in ndisc_router_process_autonomous_prefix()
456 return log_link_error_errno(link, r, "Failed to generate SLAAC addresses: %m"); in ndisc_router_process_autonomous_prefix()
476 r = address_get(link, address, &e); in ndisc_router_process_autonomous_prefix()
484 r = ndisc_request_address(TAKE_PTR(address), link, rt); in ndisc_router_process_autonomous_prefix()
486 return log_link_error_errno(link, r, "Could not request SLAAC address: %m"); in ndisc_router_process_autonomous_prefix()
492 static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) { in ndisc_router_process_onlink_prefix() argument
499 assert(link); in ndisc_router_process_onlink_prefix()
500 assert(link->network); in ndisc_router_process_onlink_prefix()
503 if (!link->network->ipv6_accept_ra_use_onlink_prefix) in ndisc_router_process_onlink_prefix()
508 return log_link_error_errno(link, r, "Failed to get prefix lifetime: %m"); in ndisc_router_process_onlink_prefix()
515 return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); in ndisc_router_process_onlink_prefix()
519 return log_link_error_errno(link, r, "Failed to get prefix length: %m"); in ndisc_router_process_onlink_prefix()
532 return log_link_error_errno(link, r, "Failed to get prefix address: %m"); in ndisc_router_process_onlink_prefix()
534 r = ndisc_request_route(TAKE_PTR(route), link, rt); in ndisc_router_process_onlink_prefix()
536 return log_link_error_errno(link, r, "Could not request prefix route: %m");; in ndisc_router_process_onlink_prefix()
541 static int ndisc_router_process_prefix(Link *link, sd_ndisc_router *rt) { in ndisc_router_process_prefix() argument
547 assert(link); in ndisc_router_process_prefix()
548 assert(link->network); in ndisc_router_process_prefix()
553 return log_link_error_errno(link, r, "Failed to get prefix address: %m"); in ndisc_router_process_prefix()
557 return log_link_error_errno(link, r, "Failed to get prefix length: %m"); in ndisc_router_process_prefix()
559 …if (in6_prefix_is_filtered(&a, prefixlen, link->network->ndisc_allow_listed_prefix, link->network-… in ndisc_router_process_prefix()
564 if (!set_isempty(link->network->ndisc_allow_listed_prefix)) in ndisc_router_process_prefix()
565 … log_link_debug(link, "Prefix '%s' is not in allow list, ignoring", strna(b)); in ndisc_router_process_prefix()
567 … log_link_debug(link, "Prefix '%s' is in deny list, ignoring", strna(b)); in ndisc_router_process_prefix()
574 return log_link_error_errno(link, r, "Failed to get RA prefix flags: %m"); in ndisc_router_process_prefix()
577 r = ndisc_router_process_onlink_prefix(link, rt); in ndisc_router_process_prefix()
583 r = ndisc_router_process_autonomous_prefix(link, rt); in ndisc_router_process_prefix()
591 static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) { in ndisc_router_process_route() argument
599 assert(link); in ndisc_router_process_route()
601 if (!link->network->ipv6_accept_ra_use_route_prefix) in ndisc_router_process_route()
606 return log_link_error_errno(link, r, "Failed to get route lifetime from RA: %m"); in ndisc_router_process_route()
613 return log_link_error_errno(link, r, "Failed to get route destination address: %m"); in ndisc_router_process_route()
617 return log_link_error_errno(link, r, "Failed to get route prefix length: %m"); in ndisc_router_process_route()
620 log_link_debug(link, "Route prefix is ::/0, ignoring"); in ndisc_router_process_route()
624 …if (in6_prefix_is_filtered(&dst, prefixlen, link->network->ndisc_allow_listed_route_prefix, link->… in ndisc_router_process_route()
629 if (!set_isempty(link->network->ndisc_allow_listed_route_prefix)) in ndisc_router_process_route()
630 … log_link_debug(link, "Route prefix '%s' is not in allow list, ignoring", strna(buf)); in ndisc_router_process_route()
632 … log_link_debug(link, "Route prefix '%s' is in deny list, ignoring", strna(buf)); in ndisc_router_process_route()
639 return log_link_error_errno(link, r, "Failed to get gateway address from RA: %m"); in ndisc_router_process_route()
641 if (link_get_ipv6_address(link, &gateway, 0, NULL) >= 0) { in ndisc_router_process_route()
646 …log_link_debug(link, "Advertised route gateway %s is local to the link, ignoring route", strna(buf… in ndisc_router_process_route()
653 … return log_link_error_errno(link, r, "Failed to get default router preference from RA: %m"); in ndisc_router_process_route()
657 return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); in ndisc_router_process_route()
671 r = ndisc_request_route(TAKE_PTR(route), link, rt); in ndisc_router_process_route()
673 return log_link_error_errno(link, r, "Could not request additional route: %m"); in ndisc_router_process_route()
693 static int ndisc_router_process_rdnss(Link *link, sd_ndisc_router *rt) { in ndisc_router_process_rdnss() argument
701 assert(link); in ndisc_router_process_rdnss()
702 assert(link->network); in ndisc_router_process_rdnss()
705 if (!link->network->ipv6_accept_ra_use_dns) in ndisc_router_process_rdnss()
710 return log_link_error_errno(link, r, "Failed to get router address from RA: %m"); in ndisc_router_process_rdnss()
714 return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); in ndisc_router_process_rdnss()
718 return log_link_error_errno(link, r, "Failed to get RDNSS lifetime: %m"); in ndisc_router_process_rdnss()
727 return log_link_error_errno(link, n, "Failed to get RDNSS addresses: %m"); in ndisc_router_process_rdnss()
730 …log_link_warning(link, "Too many RDNSS records per link. Only first %i records will be used.", NDI… in ndisc_router_process_rdnss()
740 rdnss = set_get(link->ndisc_rdnss, &d); in ndisc_router_process_rdnss()
758 r = set_ensure_consume(&link->ndisc_rdnss, &ndisc_rdnss_hash_ops, TAKE_PTR(x)); in ndisc_router_process_rdnss()
767 link_dirty(link); in ndisc_router_process_rdnss()
787 static int ndisc_router_process_dnssl(Link *link, sd_ndisc_router *rt) { in ndisc_router_process_dnssl() argument
795 assert(link); in ndisc_router_process_dnssl()
796 assert(link->network); in ndisc_router_process_dnssl()
799 if (link->network->ipv6_accept_ra_use_domains == DHCP_USE_DOMAINS_NO) in ndisc_router_process_dnssl()
804 return log_link_error_errno(link, r, "Failed to get router address from RA: %m"); in ndisc_router_process_dnssl()
808 return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); in ndisc_router_process_dnssl()
812 return log_link_error_errno(link, r, "Failed to get DNSSL lifetime: %m"); in ndisc_router_process_dnssl()
821 return log_link_error_errno(link, r, "Failed to get DNSSL addresses: %m"); in ndisc_router_process_dnssl()
824 …log_link_warning(link, "Too many DNSSL records per link. Only first %i records will be used.", NDI… in ndisc_router_process_dnssl()
839 dnssl = set_get(link->ndisc_dnssl, s); in ndisc_router_process_dnssl()
850 r = set_ensure_consume(&link->ndisc_dnssl, &ndisc_dnssl_hash_ops, TAKE_PTR(s)); in ndisc_router_process_dnssl()
859 link_dirty(link); in ndisc_router_process_dnssl()
864 static int ndisc_router_process_options(Link *link, sd_ndisc_router *rt) { in ndisc_router_process_options() argument
867 assert(link); in ndisc_router_process_options()
868 assert(link->network); in ndisc_router_process_options()
875 … return log_link_error_errno(link, r, "Failed to iterate through options: %m"); in ndisc_router_process_options()
881 return log_link_error_errno(link, r, "Failed to get RA option type: %m"); in ndisc_router_process_options()
886 r = ndisc_router_process_prefix(link, rt); in ndisc_router_process_options()
892 r = ndisc_router_process_route(link, rt); in ndisc_router_process_options()
898 r = ndisc_router_process_rdnss(link, rt); in ndisc_router_process_options()
904 r = ndisc_router_process_dnssl(link, rt); in ndisc_router_process_options()
912 static void ndisc_mark(Link *link, const struct in6_addr *router) { in ndisc_mark() argument
916 assert(link); in ndisc_mark()
919 link_mark_addresses(link, NETWORK_CONFIG_SOURCE_NDISC, router); in ndisc_mark()
920 link_mark_routes(link, NETWORK_CONFIG_SOURCE_NDISC, router); in ndisc_mark()
922 SET_FOREACH(rdnss, link->ndisc_rdnss) in ndisc_mark()
926 SET_FOREACH(dnssl, link->ndisc_dnssl) in ndisc_mark()
931 static int ndisc_start_dhcp6_client(Link *link, sd_ndisc_router *rt) { in ndisc_start_dhcp6_client() argument
934 assert(link); in ndisc_start_dhcp6_client()
935 assert(link->network); in ndisc_start_dhcp6_client()
937 switch (link->network->ipv6_accept_ra_start_dhcp6_client) { in ndisc_start_dhcp6_client()
946 return log_link_warning_errno(link, r, "Failed to get RA flags: %m"); in ndisc_start_dhcp6_client()
954 r = dhcp6_start_on_ra(link, !(flags & ND_RA_FLAG_MANAGED)); in ndisc_start_dhcp6_client()
960 r = dhcp6_start_on_ra(link, /* information_request = */ false); in ndisc_start_dhcp6_client()
968 … return log_link_error_errno(link, r, "Could not acquire DHCPv6 lease on NDisc request: %m"); in ndisc_start_dhcp6_client()
970 log_link_debug(link, "Acquiring DHCPv6 lease on NDisc request"); in ndisc_start_dhcp6_client()
974 static int ndisc_router_handler(Link *link, sd_ndisc_router *rt) { in ndisc_router_handler() argument
978 assert(link); in ndisc_router_handler()
979 assert(link->network); in ndisc_router_handler()
980 assert(link->manager); in ndisc_router_handler()
985 return log_link_error_errno(link, r, "Failed to get router address from RA: %m"); in ndisc_router_handler()
987 …if (in6_prefix_is_filtered(&router, 128, link->network->ndisc_allow_listed_router, link->network->… in ndisc_router_handler()
992 if (!set_isempty(link->network->ndisc_allow_listed_router)) in ndisc_router_handler()
993 … log_link_debug(link, "Router '%s' is not in allow list, ignoring", strna(buf)); in ndisc_router_handler()
995 … log_link_debug(link, "Router '%s' is in deny list, ignoring", strna(buf)); in ndisc_router_handler()
1000 ndisc_mark(link, &router); in ndisc_router_handler()
1002 r = ndisc_start_dhcp6_client(link, rt); in ndisc_router_handler()
1006 r = ndisc_router_process_default(link, rt); in ndisc_router_handler()
1010 r = ndisc_router_process_options(link, rt); in ndisc_router_handler()
1014 if (link->ndisc_messages == 0) { in ndisc_router_handler()
1015 link->ndisc_configured = true; in ndisc_router_handler()
1017 r = ndisc_remove(link, &router); in ndisc_router_handler()
1021 log_link_debug(link, "Setting SLAAC addresses and router."); in ndisc_router_handler()
1023 if (!link->ndisc_configured) in ndisc_router_handler()
1024 link_set_state(link, LINK_STATE_CONFIGURING); in ndisc_router_handler()
1026 link_check_ready(link); in ndisc_router_handler()
1031 Link *link = userdata; in ndisc_handler() local
1034 assert(link); in ndisc_handler()
1036 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in ndisc_handler()
1042 r = ndisc_router_handler(link, rt); in ndisc_handler()
1044 link_enter_failed(link); in ndisc_handler()
1050 log_link_debug(link, "NDisc handler get timeout event"); in ndisc_handler()
1051 if (link->ndisc_messages == 0) { in ndisc_handler()
1052 link->ndisc_configured = true; in ndisc_handler()
1053 link_check_ready(link); in ndisc_handler()
1061 static int ndisc_configure(Link *link) { in ndisc_configure() argument
1064 assert(link); in ndisc_configure()
1066 if (!link_ipv6_accept_ra_enabled(link)) in ndisc_configure()
1069 if (link->ndisc) in ndisc_configure()
1072 r = sd_ndisc_new(&link->ndisc); in ndisc_configure()
1076 r = sd_ndisc_attach_event(link->ndisc, link->manager->event, 0); in ndisc_configure()
1080 r = sd_ndisc_set_mac(link->ndisc, &link->hw_addr.ether); in ndisc_configure()
1084 r = sd_ndisc_set_ifindex(link->ndisc, link->ifindex); in ndisc_configure()
1088 r = sd_ndisc_set_callback(link->ndisc, ndisc_handler, link); in ndisc_configure()
1095 int ndisc_start(Link *link) { in ndisc_start() argument
1098 assert(link); in ndisc_start()
1100 if (!link->ndisc || !link->dhcp6_client) in ndisc_start()
1103 if (!link_has_carrier(link)) in ndisc_start()
1106 if (in6_addr_is_null(&link->ipv6ll_address)) in ndisc_start()
1109 log_link_debug(link, "Discovering IPv6 routers"); in ndisc_start()
1111 r = sd_ndisc_start(link->ndisc); in ndisc_start()
1118 static int ndisc_process_request(Request *req, Link *link, void *userdata) { in ndisc_process_request() argument
1121 assert(link); in ndisc_process_request()
1123 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in ndisc_process_request()
1126 if (link->hw_addr.length != ETH_ALEN || hw_addr_is_null(&link->hw_addr)) in ndisc_process_request()
1130 r = ndisc_configure(link); in ndisc_process_request()
1132 … return log_link_warning_errno(link, r, "Failed to configure IPv6 Router Discovery: %m"); in ndisc_process_request()
1134 r = ndisc_start(link); in ndisc_process_request()
1136 return log_link_warning_errno(link, r, "Failed to start IPv6 Router Discovery: %m"); in ndisc_process_request()
1138 log_link_debug(link, "IPv6 Router Discovery is configured%s.", in ndisc_process_request()
1143 int link_request_ndisc(Link *link) { in link_request_ndisc() argument
1146 assert(link); in link_request_ndisc()
1148 if (!link_ipv6_accept_ra_enabled(link)) in link_request_ndisc()
1151 if (link->ndisc) in link_request_ndisc()
1154 r = link_queue_request(link, REQUEST_TYPE_NDISC, ndisc_process_request, NULL); in link_request_ndisc()
1156 …return log_link_warning_errno(link, r, "Failed to request configuring of the IPv6 Router Discovery… in link_request_ndisc()
1158 log_link_debug(link, "Requested configuring of the IPv6 Router Discovery."); in link_request_ndisc()
1162 void ndisc_vacuum(Link *link) { in ndisc_vacuum() argument
1167 assert(link); in ndisc_vacuum()
1173 SET_FOREACH(r, link->ndisc_rdnss) in ndisc_vacuum()
1175 free(set_remove(link->ndisc_rdnss, r)); in ndisc_vacuum()
1177 SET_FOREACH(d, link->ndisc_dnssl) in ndisc_vacuum()
1179 free(set_remove(link->ndisc_dnssl, d)); in ndisc_vacuum()
1182 void ndisc_flush(Link *link) { in ndisc_flush() argument
1183 assert(link); in ndisc_flush()
1187 link->ndisc_rdnss = set_free(link->ndisc_rdnss); in ndisc_flush()
1188 link->ndisc_dnssl = set_free(link->ndisc_dnssl); in ndisc_flush()