Lines Matching refs:link
30 static int dhcp4_request_address_and_routes(Link *link, bool announce);
57 static int dhcp4_remove_address_and_routes(Link *link, bool only_marked) { in dhcp4_remove_address_and_routes() argument
62 assert(link); in dhcp4_remove_address_and_routes()
64 SET_FOREACH(route, link->routes) { in dhcp4_remove_address_and_routes()
74 route_cancel_request(route, link); in dhcp4_remove_address_and_routes()
77 SET_FOREACH(address, link->addresses) { in dhcp4_remove_address_and_routes()
93 static int dhcp4_address_get(Link *link, Address **ret) { in dhcp4_address_get() argument
96 assert(link); in dhcp4_address_get()
98 SET_FOREACH(address, link->addresses) { in dhcp4_address_get()
114 assert(address->link); in dhcp4_address_ready_callback()
119 return dhcp4_check_ready(address->link); in dhcp4_address_ready_callback()
122 int dhcp4_check_ready(Link *link) { in dhcp4_check_ready() argument
126 assert(link); in dhcp4_check_ready()
128 if (link->dhcp4_messages > 0) { in dhcp4_check_ready()
129 log_link_debug(link, "%s(): DHCPv4 address and routes are not set.", __func__); in dhcp4_check_ready()
133 if (dhcp4_address_get(link, &address) < 0) { in dhcp4_check_ready()
134 log_link_debug(link, "%s(): DHCPv4 address is not set.", __func__); in dhcp4_check_ready()
139 log_link_debug(link, "%s(): DHCPv4 address is not ready.", __func__); in dhcp4_check_ready()
144 link->dhcp4_configured = true; in dhcp4_check_ready()
145 log_link_debug(link, "DHCPv4 address and routes set."); in dhcp4_check_ready()
148 r = dhcp4_remove_address_and_routes(link, /* only_marked = */ true); in dhcp4_check_ready()
152 r = sd_ipv4ll_stop(link->ipv4ll); in dhcp4_check_ready()
154 … return log_link_warning_errno(link, r, "Failed to drop IPv4 link-local address: %m"); in dhcp4_check_ready()
156 link_check_ready(link); in dhcp4_check_ready()
160 static int dhcp4_retry(Link *link) { in dhcp4_retry() argument
163 assert(link); in dhcp4_retry()
165 r = dhcp4_remove_address_and_routes(link, /* only_marked = */ false); in dhcp4_retry()
169 r = link_request_static_nexthops(link, true); in dhcp4_retry()
173 r = link_request_static_routes(link, true); in dhcp4_retry()
177 return dhcp4_request_address_and_routes(link, false); in dhcp4_retry()
180 static int dhcp4_route_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link, R… in dhcp4_route_handler() argument
184 assert(link); in dhcp4_route_handler()
187 if (r == -ENETUNREACH && !link->dhcp4_route_retrying) { in dhcp4_route_handler()
192 … log_link_message_debug_errno(link, m, r, "Could not set DHCPv4 route, retrying later"); in dhcp4_route_handler()
193 link->dhcp4_route_failed = true; in dhcp4_route_handler()
194 link->manager->dhcp4_prefix_root_cannot_set_table = true; in dhcp4_route_handler()
196 log_link_message_warning_errno(link, m, r, "Could not set DHCPv4 route"); in dhcp4_route_handler()
197 link_enter_failed(link); in dhcp4_route_handler()
201 if (link->dhcp4_messages == 0 && link->dhcp4_route_failed) { in dhcp4_route_handler()
202 link->dhcp4_route_failed = false; in dhcp4_route_handler()
203 link->dhcp4_route_retrying = true; in dhcp4_route_handler()
205 r = dhcp4_retry(link); in dhcp4_route_handler()
207 link_enter_failed(link); in dhcp4_route_handler()
212 r = dhcp4_check_ready(link); in dhcp4_route_handler()
214 link_enter_failed(link); in dhcp4_route_handler()
219 static int dhcp4_request_route(Route *in, Link *link) { in dhcp4_request_route() argument
226 assert(link); in dhcp4_request_route()
227 assert(link->dhcp_lease); in dhcp4_request_route()
229 r = sd_dhcp_lease_get_server_identifier(link->dhcp_lease, &server); in dhcp4_request_route()
231 return log_link_debug_errno(link, r, "Failed to get DHCP server IP address: %m"); in dhcp4_request_route()
239 route->priority = link->network->dhcp_route_metric; in dhcp4_request_route()
241 route->table = link_get_dhcp4_route_table(link); in dhcp4_request_route()
243 route->mtu = link->network->dhcp_route_mtu; in dhcp4_request_route()
245 if (route_get(NULL, link, route, &existing) < 0) /* This is a new route. */ in dhcp4_request_route()
246 link->dhcp4_configured = false; in dhcp4_request_route()
250 return link_request_route(link, TAKE_PTR(route), true, &link->dhcp4_messages, in dhcp4_request_route()
254 static bool link_prefixroute(Link *link) { in link_prefixroute() argument
255 return !link->network->dhcp_route_table_set || in link_prefixroute()
256 link->network->dhcp_route_table == RT_TABLE_MAIN || in link_prefixroute()
257 link->manager->dhcp4_prefix_root_cannot_set_table; in link_prefixroute()
260 static int dhcp4_request_prefix_route(Link *link) { in dhcp4_request_prefix_route() argument
265 assert(link); in dhcp4_request_prefix_route()
266 assert(link->dhcp_lease); in dhcp4_request_prefix_route()
268 if (link_prefixroute(link)) in dhcp4_request_prefix_route()
272 r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); in dhcp4_request_prefix_route()
276 r = sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask); in dhcp4_request_prefix_route()
289 return dhcp4_request_route(TAKE_PTR(route), link); in dhcp4_request_prefix_route()
292 static int dhcp4_request_route_to_gateway(Link *link, const struct in_addr *gw) { in dhcp4_request_route_to_gateway() argument
297 assert(link); in dhcp4_request_route_to_gateway()
298 assert(link->dhcp_lease); in dhcp4_request_route_to_gateway()
301 r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); in dhcp4_request_route_to_gateway()
314 return dhcp4_request_route(TAKE_PTR(route), link); in dhcp4_request_route_to_gateway()
319 Link *link, in dhcp4_request_route_auto() argument
328 assert(link); in dhcp4_request_route_auto()
329 assert(link->dhcp_lease); in dhcp4_request_route_auto()
332 r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); in dhcp4_request_route_auto()
336 r = sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask); in dhcp4_request_route_auto()
345 … log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is localhost, " in dhcp4_request_route_auto()
356 …log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is equivalent to… in dhcp4_request_route_auto()
368 …log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is in the assign… in dhcp4_request_route_auto()
381 …log_link_debug(link, "DHCP: requested route destination "IPV4_ADDRESS_FMT_STR"/%u is not in the as… in dhcp4_request_route_auto()
388 r = dhcp4_request_route_to_gateway(link, gw); in dhcp4_request_route_auto()
398 return dhcp4_request_route(TAKE_PTR(route), link); in dhcp4_request_route_auto()
401 static int dhcp4_request_static_routes(Link *link, struct in_addr *ret_default_gw) { in dhcp4_request_static_routes() argument
408 assert(link); in dhcp4_request_static_routes()
409 assert(link->dhcp_lease); in dhcp4_request_static_routes()
412 r = sd_dhcp_lease_get_static_routes(link->dhcp_lease, &static_routes); in dhcp4_request_static_routes()
420 r = sd_dhcp_lease_get_classless_routes(link->dhcp_lease, &classless_routes); in dhcp4_request_static_routes()
429 log_link_debug(link, "DHCP: No static routes received from DHCP server."); in dhcp4_request_static_routes()
436 …log_link_debug(link, "Classless static routes received from DHCP server: ignoring static-route opt… in dhcp4_request_static_routes()
438 if (!link->network->dhcp_use_routes) { in dhcp4_request_static_routes()
512 r = dhcp4_request_route_auto(TAKE_PTR(route), link, &gw); in dhcp4_request_static_routes()
521 static int dhcp4_request_gateway(Link *link, struct in_addr *gw) { in dhcp4_request_gateway() argument
527 assert(link); in dhcp4_request_gateway()
528 assert(link->dhcp_lease); in dhcp4_request_gateway()
531 r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); in dhcp4_request_gateway()
535 r = sd_dhcp_lease_get_router(link->dhcp_lease, &router); in dhcp4_request_gateway()
537 log_link_debug(link, "DHCP: No gateway received from DHCP server."); in dhcp4_request_gateway()
543 log_link_debug(link, "DHCP: Received gateway address is null."); in dhcp4_request_gateway()
547 if (!link->network->dhcp_use_gateway) { in dhcp4_request_gateway()
559 r = dhcp4_request_route_to_gateway(link, &router[0]); in dhcp4_request_gateway()
572 r = dhcp4_request_route(TAKE_PTR(route), link); in dhcp4_request_gateway()
582 static int dhcp4_request_semi_static_routes(Link *link, const struct in_addr *gw) { in dhcp4_request_semi_static_routes() argument
586 assert(link); in dhcp4_request_semi_static_routes()
587 assert(link->dhcp_lease); in dhcp4_request_semi_static_routes()
588 assert(link->network); in dhcp4_request_semi_static_routes()
594 HASHMAP_FOREACH(rt, link->network->routes_by_section) { in dhcp4_request_semi_static_routes()
603 r = dhcp4_request_route_to_gateway(link, gw); in dhcp4_request_semi_static_routes()
613 r = dhcp4_request_route(TAKE_PTR(route), link); in dhcp4_request_semi_static_routes()
622 Link *link, in dhcp4_request_routes_to_servers() argument
629 assert(link); in dhcp4_request_routes_to_servers()
630 assert(link->dhcp_lease); in dhcp4_request_routes_to_servers()
631 assert(link->network); in dhcp4_request_routes_to_servers()
648 r = dhcp4_request_route_auto(TAKE_PTR(route), link, gw); in dhcp4_request_routes_to_servers()
656 static int dhcp4_request_routes_to_dns(Link *link, const struct in_addr *gw) { in dhcp4_request_routes_to_dns() argument
660 assert(link); in dhcp4_request_routes_to_dns()
661 assert(link->dhcp_lease); in dhcp4_request_routes_to_dns()
662 assert(link->network); in dhcp4_request_routes_to_dns()
665 if (!link->network->dhcp_use_dns || in dhcp4_request_routes_to_dns()
666 !link->network->dhcp_routes_to_dns) in dhcp4_request_routes_to_dns()
669 r = sd_dhcp_lease_get_dns(link->dhcp_lease, &dns); in dhcp4_request_routes_to_dns()
675 return dhcp4_request_routes_to_servers(link, dns, r, gw); in dhcp4_request_routes_to_dns()
678 static int dhcp4_request_routes_to_ntp(Link *link, const struct in_addr *gw) { in dhcp4_request_routes_to_ntp() argument
682 assert(link); in dhcp4_request_routes_to_ntp()
683 assert(link->dhcp_lease); in dhcp4_request_routes_to_ntp()
684 assert(link->network); in dhcp4_request_routes_to_ntp()
687 if (!link->network->dhcp_use_ntp || in dhcp4_request_routes_to_ntp()
688 !link->network->dhcp_routes_to_ntp) in dhcp4_request_routes_to_ntp()
691 r = sd_dhcp_lease_get_ntp(link->dhcp_lease, &ntp); in dhcp4_request_routes_to_ntp()
697 return dhcp4_request_routes_to_servers(link, ntp, r, gw); in dhcp4_request_routes_to_ntp()
700 static int dhcp4_request_routes(Link *link) { in dhcp4_request_routes() argument
704 assert(link); in dhcp4_request_routes()
705 assert(link->dhcp_lease); in dhcp4_request_routes()
707 r = dhcp4_request_prefix_route(link); in dhcp4_request_routes()
709 … return log_link_error_errno(link, r, "DHCP error: Could not request prefix route: %m"); in dhcp4_request_routes()
711 r = dhcp4_request_static_routes(link, &gw); in dhcp4_request_routes()
713 … return log_link_error_errno(link, r, "DHCP error: Could not request static routes: %m"); in dhcp4_request_routes()
717 r = dhcp4_request_gateway(link, &gw); in dhcp4_request_routes()
719 … return log_link_error_errno(link, r, "DHCP error: Could not request gateway: %m"); in dhcp4_request_routes()
722 r = dhcp4_request_semi_static_routes(link, &gw); in dhcp4_request_routes()
724 …return log_link_error_errno(link, r, "DHCP error: Could not request routes with Gateway=_dhcp4 set… in dhcp4_request_routes()
726 r = dhcp4_request_routes_to_dns(link, &gw); in dhcp4_request_routes()
728 … return log_link_error_errno(link, r, "DHCP error: Could not request routes to DNS servers: %m"); in dhcp4_request_routes()
730 r = dhcp4_request_routes_to_ntp(link, &gw); in dhcp4_request_routes()
732 … return log_link_error_errno(link, r, "DHCP error: Could not request routes to NTP servers: %m"); in dhcp4_request_routes()
737 static int dhcp_reset_mtu(Link *link) { in dhcp_reset_mtu() argument
740 assert(link); in dhcp_reset_mtu()
742 if (!link->network->dhcp_use_mtu) in dhcp_reset_mtu()
745 r = link_request_to_set_mtu(link, link->original_mtu); in dhcp_reset_mtu()
747 … return log_link_error_errno(link, r, "DHCP error: Could not queue request to reset MTU: %m"); in dhcp_reset_mtu()
752 static int dhcp_reset_hostname(Link *link) { in dhcp_reset_hostname() argument
756 assert(link); in dhcp_reset_hostname()
758 if (!link->network->dhcp_use_hostname) in dhcp_reset_hostname()
761 hostname = link->network->dhcp_hostname; in dhcp_reset_hostname()
763 (void) sd_dhcp_lease_get_hostname(link->dhcp_lease, &hostname); in dhcp_reset_hostname()
769 r = manager_set_hostname(link->manager, NULL); in dhcp_reset_hostname()
771 … return log_link_error_errno(link, r, "DHCP error: Failed to reset transient hostname: %m"); in dhcp_reset_hostname()
776 int dhcp4_lease_lost(Link *link) { in dhcp4_lease_lost() argument
779 assert(link); in dhcp4_lease_lost()
780 assert(link->dhcp_lease); in dhcp4_lease_lost()
781 assert(link->network); in dhcp4_lease_lost()
783 log_link_info(link, "DHCP lease lost"); in dhcp4_lease_lost()
785 link->dhcp4_configured = false; in dhcp4_lease_lost()
787 if (link->network->dhcp_use_6rd && in dhcp4_lease_lost()
788 dhcp4_lease_has_pd_prefix(link->dhcp_lease)) in dhcp4_lease_lost()
789 dhcp4_pd_prefix_lost(link); in dhcp4_lease_lost()
791 k = dhcp4_remove_address_and_routes(link, /* only_marked = */ false); in dhcp4_lease_lost()
795 k = dhcp_reset_mtu(link); in dhcp4_lease_lost()
799 k = dhcp_reset_hostname(link); in dhcp4_lease_lost()
803 link->dhcp_lease = sd_dhcp_lease_unref(link->dhcp_lease); in dhcp4_lease_lost()
804 link_dirty(link); in dhcp4_lease_lost()
810 r = link_request_static_nexthops(link, true); in dhcp4_lease_lost()
814 return link_request_static_routes(link, true); in dhcp4_lease_lost()
817 static int dhcp4_address_handler(sd_netlink *rtnl, sd_netlink_message *m, Request *req, Link *link,… in dhcp4_address_handler() argument
820 assert(link); in dhcp4_address_handler()
822 r = address_configure_handler_internal(rtnl, m, link, "Could not set DHCPv4 address"); in dhcp4_address_handler()
826 r = dhcp4_check_ready(link); in dhcp4_address_handler()
828 link_enter_failed(link); in dhcp4_address_handler()
833 static int dhcp4_request_address(Link *link, bool announce) { in dhcp4_request_address() argument
841 assert(link); in dhcp4_request_address()
842 assert(link->network); in dhcp4_request_address()
843 assert(link->dhcp_lease); in dhcp4_request_address()
845 r = sd_dhcp_lease_get_address(link->dhcp_lease, &address); in dhcp4_request_address()
847 return log_link_warning_errno(link, r, "DHCP error: no address: %m"); in dhcp4_request_address()
849 r = sd_dhcp_lease_get_netmask(link->dhcp_lease, &netmask); in dhcp4_request_address()
851 return log_link_warning_errno(link, r, "DHCP error: no netmask: %m"); in dhcp4_request_address()
853 r = sd_dhcp_lease_get_server_identifier(link->dhcp_lease, &server); in dhcp4_request_address()
855 … return log_link_debug_errno(link, r, "DHCP error: failed to get DHCP server IP address: %m"); in dhcp4_request_address()
857 if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) { in dhcp4_request_address()
860 r = sd_dhcp_lease_get_lifetime(link->dhcp_lease, &lifetime_sec); in dhcp4_request_address()
862 return log_link_warning_errno(link, r, "DHCP error: no lifetime: %m"); in dhcp4_request_address()
873 r = sd_dhcp_lease_get_router(link->dhcp_lease, &router); in dhcp4_request_address()
875 … return log_link_error_errno(link, r, "DHCP error: Could not get gateway: %m"); in dhcp4_request_address()
879 LOG_LINK_INTERFACE(link), in dhcp4_request_address()
880 …LOG_LINK_MESSAGE(link, "DHCPv4 address "IPV4_ADDRESS_FMT_STR"/%u, gateway "IPV4_ADDRESS_FMT_STR" a… in dhcp4_request_address()
890 LOG_LINK_INTERFACE(link), in dhcp4_request_address()
891 …LOG_LINK_MESSAGE(link, "DHCPv4 address "IPV4_ADDRESS_FMT_STR"/%u acquired from "IPV4_ADDRESS_FMT_S… in dhcp4_request_address()
910 address_set_broadcast(addr, link); in dhcp4_request_address()
911 SET_FLAG(addr->flags, IFA_F_NOPREFIXROUTE, !link_prefixroute(link)); in dhcp4_request_address()
912 addr->route_metric = link->network->dhcp_route_metric; in dhcp4_request_address()
913 …addr->duplicate_address_detection = link->network->dhcp_send_decline ? ADDRESS_FAMILY_IPV4 : ADDRE… in dhcp4_request_address()
915 r = free_and_strdup_warn(&addr->label, link->network->dhcp_label); in dhcp4_request_address()
919 if (address_get(link, addr, &existing) < 0) /* The address is new. */ in dhcp4_request_address()
920 link->dhcp4_configured = false; in dhcp4_request_address()
924 r = link_request_address(link, TAKE_PTR(addr), true, &link->dhcp4_messages, in dhcp4_request_address()
927 return log_link_error_errno(link, r, "Failed to request DHCPv4 address: %m"); in dhcp4_request_address()
932 static int dhcp4_request_address_and_routes(Link *link, bool announce) { in dhcp4_request_address_and_routes() argument
935 assert(link); in dhcp4_request_address_and_routes()
937 link_mark_addresses(link, NETWORK_CONFIG_SOURCE_DHCP4, NULL); in dhcp4_request_address_and_routes()
938 link_mark_routes(link, NETWORK_CONFIG_SOURCE_DHCP4, NULL); in dhcp4_request_address_and_routes()
940 r = dhcp4_request_address(link, announce); in dhcp4_request_address_and_routes()
944 r = dhcp4_request_routes(link); in dhcp4_request_address_and_routes()
948 if (!link->dhcp4_configured) { in dhcp4_request_address_and_routes()
949 link_set_state(link, LINK_STATE_CONFIGURING); in dhcp4_request_address_and_routes()
950 link_check_ready(link); in dhcp4_request_address_and_routes()
956 static int dhcp_lease_renew(sd_dhcp_client *client, Link *link) { in dhcp_lease_renew() argument
961 assert(link); in dhcp_lease_renew()
962 assert(link->network); in dhcp_lease_renew()
967 return log_link_warning_errno(link, r, "DHCP error: no lease: %m"); in dhcp_lease_renew()
969 old_lease = TAKE_PTR(link->dhcp_lease); in dhcp_lease_renew()
970 link->dhcp_lease = sd_dhcp_lease_ref(lease); in dhcp_lease_renew()
971 link_dirty(link); in dhcp_lease_renew()
973 if (link->network->dhcp_use_6rd) { in dhcp_lease_renew()
974 if (dhcp4_lease_has_pd_prefix(link->dhcp_lease)) { in dhcp_lease_renew()
975 r = dhcp4_pd_prefix_acquired(link); in dhcp_lease_renew()
977 … return log_link_warning_errno(link, r, "Failed to process 6rd option: %m"); in dhcp_lease_renew()
979 dhcp4_pd_prefix_lost(link); in dhcp_lease_renew()
982 return dhcp4_request_address_and_routes(link, false); in dhcp_lease_renew()
985 static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) { in dhcp_lease_acquired() argument
990 assert(link); in dhcp_lease_acquired()
994 return log_link_error_errno(link, r, "DHCP error: No lease: %m"); in dhcp_lease_acquired()
996 sd_dhcp_lease_unref(link->dhcp_lease); in dhcp_lease_acquired()
997 link->dhcp_lease = sd_dhcp_lease_ref(lease); in dhcp_lease_acquired()
998 link_dirty(link); in dhcp_lease_acquired()
1000 if (link->network->dhcp_use_mtu) { in dhcp_lease_acquired()
1005 r = link_request_to_set_mtu(link, mtu); in dhcp_lease_acquired()
1007 … log_link_error_errno(link, r, "Failed to set MTU to %" PRIu16 ": %m", mtu); in dhcp_lease_acquired()
1011 if (link->network->dhcp_use_hostname) { in dhcp_lease_acquired()
1015 if (link->network->dhcp_hostname) in dhcp_lease_acquired()
1016 dhcpname = link->network->dhcp_hostname; in dhcp_lease_acquired()
1023 …log_link_warning_errno(link, r, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhc… in dhcp_lease_acquired()
1025 …log_link_notice(link, "Overlong DHCP hostname received, shortened from '%s' to '%s'", dhcpname, ho… in dhcp_lease_acquired()
1029 r = manager_set_hostname(link->manager, hostname); in dhcp_lease_acquired()
1031 … log_link_error_errno(link, r, "Failed to set transient hostname to '%s': %m", hostname); in dhcp_lease_acquired()
1035 if (link->network->dhcp_use_timezone) { in dhcp_lease_acquired()
1038 (void) sd_dhcp_lease_get_timezone(link->dhcp_lease, &tz); in dhcp_lease_acquired()
1041 r = manager_set_timezone(link->manager, tz); in dhcp_lease_acquired()
1043 … log_link_error_errno(link, r, "Failed to set timezone to '%s': %m", tz); in dhcp_lease_acquired()
1047 if (link->network->dhcp_use_6rd && in dhcp_lease_acquired()
1048 dhcp4_lease_has_pd_prefix(link->dhcp_lease)) { in dhcp_lease_acquired()
1049 r = dhcp4_pd_prefix_acquired(link); in dhcp_lease_acquired()
1051 return log_link_warning_errno(link, r, "Failed to process 6rd option: %m"); in dhcp_lease_acquired()
1054 return dhcp4_request_address_and_routes(link, true); in dhcp_lease_acquired()
1057 static int dhcp_lease_ip_change(sd_dhcp_client *client, Link *link) { in dhcp_lease_ip_change() argument
1060 r = dhcp_lease_acquired(client, link); in dhcp_lease_ip_change()
1062 (void) dhcp4_lease_lost(link); in dhcp_lease_ip_change()
1067 static int dhcp_server_is_filtered(Link *link, sd_dhcp_client *client) { in dhcp_server_is_filtered() argument
1072 assert(link); in dhcp_server_is_filtered()
1073 assert(link->network); in dhcp_server_is_filtered()
1078 return log_link_error_errno(link, r, "Failed to get DHCP lease: %m"); in dhcp_server_is_filtered()
1082 return log_link_debug_errno(link, r, "Failed to get DHCP server IP address: %m"); in dhcp_server_is_filtered()
1084 …if (in4_address_is_filtered(&addr, link->network->dhcp_allow_listed_ip, link->network->dhcp_deny_l… in dhcp_server_is_filtered()
1086 if (link->network->dhcp_allow_listed_ip) in dhcp_server_is_filtered()
1087 …log_link_debug(link, "DHCPv4 server IP address "IPV4_ADDRESS_FMT_STR" not found in allow-list, ign… in dhcp_server_is_filtered()
1090 …log_link_debug(link, "DHCPv4 server IP address "IPV4_ADDRESS_FMT_STR" found in deny-list, ignoring… in dhcp_server_is_filtered()
1101 Link *link = userdata; in dhcp4_handler() local
1104 assert(link); in dhcp4_handler()
1105 assert(link->network); in dhcp4_handler()
1106 assert(link->manager); in dhcp4_handler()
1108 if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) in dhcp4_handler()
1113 if (link->ipv4ll) { in dhcp4_handler()
1114 … log_link_debug(link, "DHCP client is stopped. Acquiring IPv4 link-local address"); in dhcp4_handler()
1116 r = sd_ipv4ll_start(link->ipv4ll); in dhcp4_handler()
1118 … return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m"); in dhcp4_handler()
1121 if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) { in dhcp4_handler()
1122 …log_link_notice(link, "DHCPv4 connection considered critical, ignoring request to reconfigure it."… in dhcp4_handler()
1126 if (link->dhcp_lease) { in dhcp4_handler()
1127 if (link->network->dhcp_send_release) { in dhcp4_handler()
1130 log_link_full_errno(link, in dhcp4_handler()
1135 r = dhcp4_lease_lost(link); in dhcp4_handler()
1137 link_enter_failed(link); in dhcp4_handler()
1144 if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) { in dhcp4_handler()
1145 …log_link_notice(link, "DHCPv4 connection considered critical, ignoring request to reconfigure it."… in dhcp4_handler()
1149 if (link->dhcp_lease) { in dhcp4_handler()
1150 r = dhcp4_lease_lost(link); in dhcp4_handler()
1152 link_enter_failed(link); in dhcp4_handler()
1159 if (FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) { in dhcp4_handler()
1160 …log_link_notice(link, "DHCPv4 connection considered critical, ignoring request to reconfigure it."… in dhcp4_handler()
1164 r = dhcp_lease_ip_change(client, link); in dhcp4_handler()
1166 link_enter_failed(link); in dhcp4_handler()
1172 r = dhcp_lease_renew(client, link); in dhcp4_handler()
1174 link_enter_failed(link); in dhcp4_handler()
1179 r = dhcp_lease_acquired(client, link); in dhcp4_handler()
1181 link_enter_failed(link); in dhcp4_handler()
1186 r = dhcp_server_is_filtered(link, client); in dhcp4_handler()
1188 link_enter_failed(link); in dhcp4_handler()
1196 if (link->ipv4ll && !sd_ipv4ll_is_running(link->ipv4ll)) { in dhcp4_handler()
1197 … log_link_debug(link, "Problems acquiring DHCP lease, acquiring IPv4 link-local address"); in dhcp4_handler()
1199 r = sd_ipv4ll_start(link->ipv4ll); in dhcp4_handler()
1201 … return log_link_warning_errno(link, r, "Could not acquire IPv4 link-local address: %m"); in dhcp4_handler()
1207 … log_link_warning_errno(link, event, "DHCP error: Client failed: %m"); in dhcp4_handler()
1209 log_link_warning(link, "DHCP unknown event: %i", event); in dhcp4_handler()
1216 static int dhcp4_set_hostname(Link *link) { in dhcp4_set_hostname() argument
1221 assert(link); in dhcp4_set_hostname()
1223 if (!link->network->dhcp_send_hostname) in dhcp4_set_hostname()
1225 else if (link->network->dhcp_hostname) in dhcp4_set_hostname()
1226 hn = link->network->dhcp_hostname; in dhcp4_set_hostname()
1230 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to get hostname: %m"); in dhcp4_set_hostname()
1235 r = sd_dhcp_client_set_hostname(link->dhcp_client, hn); in dhcp4_set_hostname()
1238 …log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set hostname from kernel hostname, ignorin… in dhcp4_set_hostname()
1240 return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set hostname: %m"); in dhcp4_set_hostname()
1245 static int dhcp4_set_client_identifier(Link *link) { in dhcp4_set_client_identifier() argument
1248 assert(link); in dhcp4_set_client_identifier()
1249 assert(link->network); in dhcp4_set_client_identifier()
1250 assert(link->dhcp_client); in dhcp4_set_client_identifier()
1252 switch (link->network->dhcp_client_identifier) { in dhcp4_set_client_identifier()
1255 const DUID *duid = link_get_dhcp4_duid(link); in dhcp4_set_client_identifier()
1258 r = sd_dhcp_client_set_iaid_duid_llt(link->dhcp_client, in dhcp4_set_client_identifier()
1259 link->network->dhcp_iaid_set, in dhcp4_set_client_identifier()
1260 link->network->dhcp_iaid, in dhcp4_set_client_identifier()
1263 r = sd_dhcp_client_set_iaid_duid(link->dhcp_client, in dhcp4_set_client_identifier()
1264 link->network->dhcp_iaid_set, in dhcp4_set_client_identifier()
1265 link->network->dhcp_iaid, in dhcp4_set_client_identifier()
1270 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set IAID+DUID: %m"); in dhcp4_set_client_identifier()
1275 const DUID *duid = link_get_dhcp4_duid(link); in dhcp4_set_client_identifier()
1278 r = sd_dhcp_client_set_duid_llt(link->dhcp_client, in dhcp4_set_client_identifier()
1281 r = sd_dhcp_client_set_duid(link->dhcp_client, in dhcp4_set_client_identifier()
1286 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set DUID: %m"); in dhcp4_set_client_identifier()
1290 const uint8_t *hw_addr = link->hw_addr.bytes; in dhcp4_set_client_identifier()
1291 size_t hw_addr_len = link->hw_addr.length; in dhcp4_set_client_identifier()
1293 if (link->iftype == ARPHRD_INFINIBAND && hw_addr_len == INFINIBAND_ALEN) { in dhcp4_set_client_identifier()
1299 r = sd_dhcp_client_set_client_id(link->dhcp_client, in dhcp4_set_client_identifier()
1300 link->iftype, in dhcp4_set_client_identifier()
1304 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set client ID: %m"); in dhcp4_set_client_identifier()
1314 static int dhcp4_set_request_address(Link *link) { in dhcp4_set_request_address() argument
1317 assert(link); in dhcp4_set_request_address()
1318 assert(link->network); in dhcp4_set_request_address()
1319 assert(link->dhcp_client); in dhcp4_set_request_address()
1321 if (!FLAGS_SET(link->network->keep_configuration, KEEP_CONFIGURATION_DHCP)) in dhcp4_set_request_address()
1324 SET_FOREACH(a, link->addresses) { in dhcp4_set_request_address()
1329 if (link_address_is_dynamic(link, a)) in dhcp4_set_request_address()
1336 …log_link_debug(link, "DHCPv4 CLIENT: requesting " IPV4_ADDRESS_FMT_STR, IPV4_ADDRESS_FMT_VAL(a->in… in dhcp4_set_request_address()
1338 return sd_dhcp_client_set_request_address(link->dhcp_client, &a->in_addr.in); in dhcp4_set_request_address()
1341 static bool link_needs_dhcp_broadcast(Link *link) { in link_needs_dhcp_broadcast() argument
1345 assert(link); in link_needs_dhcp_broadcast()
1346 assert(link->network); in link_needs_dhcp_broadcast()
1353 r = link->network->dhcp_broadcast; in link_needs_dhcp_broadcast()
1354 …if (r < 0 && link->sd_device && sd_device_get_property_value(link->sd_device, "ID_NET_DHCP_BROADCA… in link_needs_dhcp_broadcast()
1357 …log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to parse ID_NET_DHCP_BROADCAST, ignoring: %m"… in link_needs_dhcp_broadcast()
1359 … log_link_debug(link, "DHCPv4 CLIENT: Detected ID_NET_DHCP_BROADCAST='%d'.", r); in link_needs_dhcp_broadcast()
1365 static int dhcp4_configure(Link *link) { in dhcp4_configure() argument
1370 assert(link); in dhcp4_configure()
1371 assert(link->network); in dhcp4_configure()
1373 if (link->dhcp_client) in dhcp4_configure()
1374 … return log_link_debug_errno(link, SYNTHETIC_ERRNO(EBUSY), "DHCPv4 client is already configured."); in dhcp4_configure()
1376 r = sd_dhcp_client_new(&link->dhcp_client, link->network->dhcp_anonymize); in dhcp4_configure()
1378 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to allocate DHCPv4 client: %m"); in dhcp4_configure()
1380 r = sd_dhcp_client_attach_event(link->dhcp_client, link->manager->event, 0); in dhcp4_configure()
1382 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to attach event to DHCPv4 client: %m"); in dhcp4_configure()
1384 r = sd_dhcp_client_set_mac(link->dhcp_client, in dhcp4_configure()
1385 link->hw_addr.bytes, in dhcp4_configure()
1386 link->bcast_addr.length > 0 ? link->bcast_addr.bytes : NULL, in dhcp4_configure()
1387 link->hw_addr.length, link->iftype); in dhcp4_configure()
1389 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set MAC address: %m"); in dhcp4_configure()
1391 r = sd_dhcp_client_set_ifindex(link->dhcp_client, link->ifindex); in dhcp4_configure()
1393 return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set ifindex: %m"); in dhcp4_configure()
1395 r = sd_dhcp_client_set_callback(link->dhcp_client, dhcp4_handler, link); in dhcp4_configure()
1397 return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set callback: %m"); in dhcp4_configure()
1399 … r = sd_dhcp_client_set_request_broadcast(link->dhcp_client, link_needs_dhcp_broadcast(link)); in dhcp4_configure()
1401 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for broadcast: %m"… in dhcp4_configure()
1403 if (link->mtu > 0) { in dhcp4_configure()
1404 r = sd_dhcp_client_set_mtu(link->dhcp_client, link->mtu); in dhcp4_configure()
1406 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set MTU: %m"); in dhcp4_configure()
1409 if (!link->network->dhcp_anonymize) { in dhcp4_configure()
1410 if (link->network->dhcp_use_mtu) { in dhcp4_configure()
1411 … r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_MTU_INTERFACE); in dhcp4_configure()
1413 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for MTU: %m"); in dhcp4_configure()
1416 if (link->network->dhcp_use_routes) { in dhcp4_configure()
1417 … r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_STATIC_ROUTE); in dhcp4_configure()
1419 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for static route: … in dhcp4_configure()
1421 … r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE); in dhcp4_configure()
1423 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for classless stat… in dhcp4_configure()
1426 if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO) { in dhcp4_configure()
1427 … r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_DOMAIN_SEARCH); in dhcp4_configure()
1429 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for domain search … in dhcp4_configure()
1432 if (link->network->dhcp_use_ntp) { in dhcp4_configure()
1433 … r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_NTP_SERVER); in dhcp4_configure()
1435 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for NTP server: %m… in dhcp4_configure()
1438 if (link->network->dhcp_use_sip) { in dhcp4_configure()
1439 … r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_SIP_SERVER); in dhcp4_configure()
1441 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for SIP server: %m… in dhcp4_configure()
1444 if (link->network->dhcp_use_timezone) { in dhcp4_configure()
1445 … r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_TZDB_TIMEZONE); in dhcp4_configure()
1447 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for timezone: %m"); in dhcp4_configure()
1450 if (link->network->dhcp_use_6rd) { in dhcp4_configure()
1451 … r = sd_dhcp_client_set_request_option(link->dhcp_client, SD_DHCP_OPTION_6RD); in dhcp4_configure()
1453 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for 6rd: %m"); in dhcp4_configure()
1456 SET_FOREACH(request_options, link->network->dhcp_request_options) { in dhcp4_configure()
1459 r = sd_dhcp_client_set_request_option(link->dhcp_client, option); in dhcp4_configure()
1461 …return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set request flag for '%u': %m", opt… in dhcp4_configure()
1464 ORDERED_HASHMAP_FOREACH(send_option, link->network->dhcp_client_send_options) { in dhcp4_configure()
1465 r = sd_dhcp_client_add_option(link->dhcp_client, send_option); in dhcp4_configure()
1469 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set send option: %m"); in dhcp4_configure()
1472 … ORDERED_HASHMAP_FOREACH(send_option, link->network->dhcp_client_send_vendor_options) { in dhcp4_configure()
1473 r = sd_dhcp_client_add_vendor_option(link->dhcp_client, send_option); in dhcp4_configure()
1477 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set send option: %m"); in dhcp4_configure()
1480 r = dhcp4_set_hostname(link); in dhcp4_configure()
1484 if (link->network->dhcp_vendor_class_identifier) { in dhcp4_configure()
1485 r = sd_dhcp_client_set_vendor_class_identifier(link->dhcp_client, in dhcp4_configure()
1486 … link->network->dhcp_vendor_class_identifier); in dhcp4_configure()
1488 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set vendor class identifier: %m"); in dhcp4_configure()
1491 if (link->network->dhcp_mudurl) { in dhcp4_configure()
1492 … r = sd_dhcp_client_set_mud_url(link->dhcp_client, link->network->dhcp_mudurl); in dhcp4_configure()
1494 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set MUD URL: %m"); in dhcp4_configure()
1497 if (link->network->dhcp_user_class) { in dhcp4_configure()
1498 … r = sd_dhcp_client_set_user_class(link->dhcp_client, link->network->dhcp_user_class); in dhcp4_configure()
1500 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set user class: %m"); in dhcp4_configure()
1504 if (link->network->dhcp_client_port > 0) { in dhcp4_configure()
1505 … r = sd_dhcp_client_set_client_port(link->dhcp_client, link->network->dhcp_client_port); in dhcp4_configure()
1507 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set listen port: %m"); in dhcp4_configure()
1510 if (link->network->dhcp_max_attempts > 0) { in dhcp4_configure()
1511 … r = sd_dhcp_client_set_max_attempts(link->dhcp_client, link->network->dhcp_max_attempts); in dhcp4_configure()
1513 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set max attempts: %m"); in dhcp4_configure()
1516 if (link->network->dhcp_ip_service_type >= 0) { in dhcp4_configure()
1517 … r = sd_dhcp_client_set_service_type(link->dhcp_client, link->network->dhcp_ip_service_type); in dhcp4_configure()
1519 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set IP service type: %m"); in dhcp4_configure()
1522 if (link->network->dhcp_fallback_lease_lifetime > 0) { in dhcp4_configure()
1523 …r = sd_dhcp_client_set_fallback_lease_lifetime(link->dhcp_client, link->network->dhcp_fallback_lea… in dhcp4_configure()
1525 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed set to lease lifetime: %m"); in dhcp4_configure()
1528 r = dhcp4_set_request_address(link); in dhcp4_configure()
1530 … return log_link_debug_errno(link, r, "DHCPv4 CLIENT: Failed to set initial DHCPv4 address: %m"); in dhcp4_configure()
1532 return dhcp4_set_client_identifier(link); in dhcp4_configure()
1535 int dhcp4_update_mac(Link *link) { in dhcp4_update_mac() argument
1538 assert(link); in dhcp4_update_mac()
1540 if (!link->dhcp_client) in dhcp4_update_mac()
1543 r = sd_dhcp_client_set_mac(link->dhcp_client, link->hw_addr.bytes, in dhcp4_update_mac()
1544 link->bcast_addr.length > 0 ? link->bcast_addr.bytes : NULL, in dhcp4_update_mac()
1545 link->hw_addr.length, link->iftype); in dhcp4_update_mac()
1549 return dhcp4_set_client_identifier(link); in dhcp4_update_mac()
1552 int dhcp4_start(Link *link) { in dhcp4_start() argument
1555 assert(link); in dhcp4_start()
1557 if (!link->dhcp_client) in dhcp4_start()
1560 if (!link_has_carrier(link)) in dhcp4_start()
1563 if (sd_dhcp_client_is_running(link->dhcp_client) > 0) in dhcp4_start()
1566 r = sd_dhcp_client_start(link->dhcp_client); in dhcp4_start()
1573 static int dhcp4_configure_duid(Link *link) { in dhcp4_configure_duid() argument
1574 assert(link); in dhcp4_configure_duid()
1576 … if (!IN_SET(link->network->dhcp_client_identifier, DHCP_CLIENT_ID_DUID, DHCP_CLIENT_ID_DUID_ONLY)) in dhcp4_configure_duid()
1579 return dhcp_configure_duid(link, link_get_dhcp4_duid(link)); in dhcp4_configure_duid()
1582 static int dhcp4_process_request(Request *req, Link *link, void *userdata) { in dhcp4_process_request() argument
1585 assert(link); in dhcp4_process_request()
1587 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in dhcp4_process_request()
1590 if (!IN_SET(link->hw_addr.length, ETH_ALEN, INFINIBAND_ALEN) || in dhcp4_process_request()
1591 hw_addr_is_null(&link->hw_addr)) in dhcp4_process_request()
1595 r = dhcp4_configure_duid(link); in dhcp4_process_request()
1599 r = dhcp4_configure(link); in dhcp4_process_request()
1601 return log_link_warning_errno(link, r, "Failed to configure DHCPv4 client: %m"); in dhcp4_process_request()
1603 r = dhcp4_start(link); in dhcp4_process_request()
1605 return log_link_warning_errno(link, r, "Failed to start DHCPv4 client: %m"); in dhcp4_process_request()
1607 log_link_debug(link, "DHCPv4 client is configured%s.", in dhcp4_process_request()
1612 int link_request_dhcp4_client(Link *link) { in link_request_dhcp4_client() argument
1615 assert(link); in link_request_dhcp4_client()
1617 if (!link_dhcp4_enabled(link)) in link_request_dhcp4_client()
1620 if (link->dhcp_client) in link_request_dhcp4_client()
1623 r = link_queue_request(link, REQUEST_TYPE_DHCP4_CLIENT, dhcp4_process_request, NULL); in link_request_dhcp4_client()
1625 … return log_link_warning_errno(link, r, "Failed to request configuring of the DHCPv4 client: %m"); in link_request_dhcp4_client()
1627 log_link_debug(link, "Requested configuring of the DHCPv4 client."); in link_request_dhcp4_client()