Lines Matching refs:link

26 static bool link_dhcp4_server_enabled(Link *link) {  in link_dhcp4_server_enabled()  argument
27 assert(link); in link_dhcp4_server_enabled()
29 if (link->flags & IFF_LOOPBACK) in link_dhcp4_server_enabled()
32 if (!link->network) in link_dhcp4_server_enabled()
35 if (link->iftype == ARPHRD_CAN) in link_dhcp4_server_enabled()
38 return link->network->dhcp_server; in link_dhcp4_server_enabled()
87 int link_request_dhcp_server_address(Link *link) { in link_request_dhcp_server_address() argument
92 assert(link); in link_request_dhcp_server_address()
93 assert(link->network); in link_request_dhcp_server_address()
95 if (!link_dhcp4_server_enabled(link)) in link_request_dhcp_server_address()
98 if (!in4_addr_is_set(&link->network->dhcp_server_address)) in link_request_dhcp_server_address()
107 address->in_addr.in = link->network->dhcp_server_address; in link_request_dhcp_server_address()
108 address->prefixlen = link->network->dhcp_server_address_prefixlen; in link_request_dhcp_server_address()
109 address_set_broadcast(address, link); in link_request_dhcp_server_address()
111 if (address_get(link, address, &existing) >= 0 && in link_request_dhcp_server_address()
118 return link_request_static_address(link, TAKE_PTR(address), true); in link_request_dhcp_server_address()
121 static int link_find_dhcp_server_address(Link *link, Address **ret) { in link_find_dhcp_server_address() argument
124 assert(link); in link_find_dhcp_server_address()
125 assert(link->network); in link_find_dhcp_server_address()
128 if (in4_addr_is_set(&link->network->dhcp_server_address)) in link_find_dhcp_server_address()
129 return link_get_ipv4_address(link, &link->network->dhcp_server_address, in link_find_dhcp_server_address()
130 link->network->dhcp_server_address_prefixlen, ret); in link_find_dhcp_server_address()
133 SET_FOREACH(address, link->addresses) { in link_find_dhcp_server_address()
154 static int dhcp_server_find_uplink(Link *link, Link **ret) { in dhcp_server_find_uplink() argument
155 assert(link); in dhcp_server_find_uplink()
157 if (link->network->dhcp_server_uplink_name) in dhcp_server_find_uplink()
158 return link_get_by_name(link->manager, link->network->dhcp_server_uplink_name, ret); in dhcp_server_find_uplink()
160 if (link->network->dhcp_server_uplink_index > 0) in dhcp_server_find_uplink()
161 … return link_get_by_index(link->manager, link->network->dhcp_server_uplink_index, ret); in dhcp_server_find_uplink()
163 if (link->network->dhcp_server_uplink_index == UPLINK_INDEX_AUTO) { in dhcp_server_find_uplink()
165 if (manager_find_uplink(link->manager, AF_INET, link, ret) < 0) in dhcp_server_find_uplink()
175 Link *link, in link_push_uplink_to_dhcp_server() argument
183 assert(link); in link_push_uplink_to_dhcp_server()
185 if (!link->network) in link_push_uplink_to_dhcp_server()
187 assert(link->network); in link_push_uplink_to_dhcp_server()
189 log_link_debug(link, "Copying %s from link", dhcp_lease_server_type_to_string(what)); in link_push_uplink_to_dhcp_server()
197 for (unsigned i = 0; i < link->network->n_dns; i++) { in link_push_uplink_to_dhcp_server()
201 if (link->network->dns[i]->family != AF_INET) in link_push_uplink_to_dhcp_server()
204 ia = link->network->dns[i]->address.in; in link_push_uplink_to_dhcp_server()
216 use_dhcp_lease_data = link->network->dhcp_use_dns; in link_push_uplink_to_dhcp_server()
223 STRV_FOREACH(i, link->network->ntp) { in link_push_uplink_to_dhcp_server()
239 use_dhcp_lease_data = link->network->dhcp_use_ntp; in link_push_uplink_to_dhcp_server()
246 use_dhcp_lease_data = link->network->dhcp_use_sip; in link_push_uplink_to_dhcp_server()
260 if (use_dhcp_lease_data && link->dhcp_lease) { in link_push_uplink_to_dhcp_server()
263 int n = sd_dhcp_lease_get_servers(link->dhcp_lease, what, &da); in link_push_uplink_to_dhcp_server()
319 static int dhcp4_server_set_dns_from_resolve_conf(Link *link) { in dhcp4_server_set_dns_from_resolve_conf() argument
362 return sd_dhcp_server_set_dns(link->dhcp_server, addresses, n_addresses); in dhcp4_server_set_dns_from_resolve_conf()
365 static int dhcp4_server_configure(Link *link) { in dhcp4_server_configure() argument
374 assert(link); in dhcp4_server_configure()
376 log_link_debug(link, "Configuring DHCP Server."); in dhcp4_server_configure()
378 if (link->dhcp_server) in dhcp4_server_configure()
381 r = sd_dhcp_server_new(&link->dhcp_server, link->ifindex); in dhcp4_server_configure()
385 r = sd_dhcp_server_attach_event(link->dhcp_server, link->manager->event, 0); in dhcp4_server_configure()
389 r = sd_dhcp_server_set_callback(link->dhcp_server, dhcp_server_callback, link); in dhcp4_server_configure()
391 … return log_link_warning_errno(link, r, "Failed to set callback for DHCPv4 server instance: %m"); in dhcp4_server_configure()
393 r = link_find_dhcp_server_address(link, &address); in dhcp4_server_configure()
395 …return log_link_error_errno(link, r, "Failed to find suitable address for DHCPv4 server instance: … in dhcp4_server_configure()
398 … r = sd_dhcp_server_configure_pool(link->dhcp_server, &address->in_addr.in, address->prefixlen, in dhcp4_server_configure()
399link->network->dhcp_server_pool_offset, link->network->dhcp_server_pool_size); in dhcp4_server_configure()
401 …return log_link_error_errno(link, r, "Failed to configure address pool for DHCPv4 server instance:… in dhcp4_server_configure()
403 if (link->network->dhcp_server_max_lease_time_usec > 0) { in dhcp4_server_configure()
404 r = sd_dhcp_server_set_max_lease_time(link->dhcp_server, in dhcp4_server_configure()
405 … DIV_ROUND_UP(link->network->dhcp_server_max_lease_time_usec, USEC_PER_SEC)); in dhcp4_server_configure()
407 …return log_link_error_errno(link, r, "Failed to set maximum lease time for DHCPv4 server instance:… in dhcp4_server_configure()
410 if (link->network->dhcp_server_default_lease_time_usec > 0) { in dhcp4_server_configure()
411 r = sd_dhcp_server_set_default_lease_time(link->dhcp_server, in dhcp4_server_configure()
412 … DIV_ROUND_UP(link->network->dhcp_server_default_lease_time_usec, USEC_PER_SEC)); in dhcp4_server_configure()
414 …return log_link_error_errno(link, r, "Failed to set default lease time for DHCPv4 server instance:… in dhcp4_server_configure()
417 …r = sd_dhcp_server_set_boot_server_address(link->dhcp_server, &link->network->dhcp_server_boot_ser… in dhcp4_server_configure()
419 …return log_link_warning_errno(link, r, "Failed to set boot server address for DHCPv4 server instan… in dhcp4_server_configure()
421 …r = sd_dhcp_server_set_boot_server_name(link->dhcp_server, link->network->dhcp_server_boot_server_… in dhcp4_server_configure()
423 …return log_link_warning_errno(link, r, "Failed to set boot server name for DHCPv4 server instance:… in dhcp4_server_configure()
425 … r = sd_dhcp_server_set_boot_filename(link->dhcp_server, link->network->dhcp_server_boot_filename); in dhcp4_server_configure()
427 …return log_link_warning_errno(link, r, "Failed to set boot filename for DHCPv4 server instance: %m… in dhcp4_server_configure()
431 if (!link->network->dhcp_server_emit[type].emit) in dhcp4_server_configure()
434 if (link->network->dhcp_server_emit[type].n_addresses > 0) in dhcp4_server_configure()
437 link->dhcp_server, in dhcp4_server_configure()
439 link->network->dhcp_server_emit[type].addresses, in dhcp4_server_configure()
440 link->network->dhcp_server_emit[type].n_addresses); in dhcp4_server_configure()
444 (void) dhcp_server_find_uplink(link, &uplink); in dhcp4_server_configure()
449 … r = link_push_uplink_to_dhcp_server(uplink, type, link->dhcp_server); in dhcp4_server_configure()
451 r = dhcp4_server_set_dns_from_resolve_conf(link); in dhcp4_server_configure()
453 log_link_debug(link, in dhcp4_server_configure()
461 log_link_warning_errno(link, r, in dhcp4_server_configure()
466 if (link->network->dhcp_server_emit_router) { in dhcp4_server_configure()
467 … r = sd_dhcp_server_set_router(link->dhcp_server, &link->network->dhcp_server_router); in dhcp4_server_configure()
469 … return log_link_error_errno(link, r, "Failed to set router address for DHCP server: %m"); in dhcp4_server_configure()
472 … r = sd_dhcp_server_set_relay_target(link->dhcp_server, &link->network->dhcp_server_relay_target); in dhcp4_server_configure()
474 … return log_link_error_errno(link, r, "Failed to set relay target for DHCP server: %m"); in dhcp4_server_configure()
476 …bind_to_interface = sd_dhcp_server_is_in_relay_mode(link->dhcp_server) ? false : link->network->dh… in dhcp4_server_configure()
477 r = sd_dhcp_server_set_bind_to_interface(link->dhcp_server, bind_to_interface); in dhcp4_server_configure()
479 … return log_link_error_errno(link, r, "Failed to set interface binding for DHCP server: %m"); in dhcp4_server_configure()
481 …hcp_server_set_relay_agent_information(link->dhcp_server, link->network->dhcp_server_relay_agent_c… in dhcp4_server_configure()
483 … return log_link_error_errno(link, r, "Failed to set agent circuit/remote id for DHCP server: %m"); in dhcp4_server_configure()
485 if (link->network->dhcp_server_emit_timezone) { in dhcp4_server_configure()
489 if (link->network->dhcp_server_timezone) in dhcp4_server_configure()
490 tz = link->network->dhcp_server_timezone; in dhcp4_server_configure()
494 … log_link_warning_errno(link, r, "Failed to determine timezone, not sending timezone: %m"); in dhcp4_server_configure()
500 r = sd_dhcp_server_set_timezone(link->dhcp_server, tz); in dhcp4_server_configure()
502 … return log_link_error_errno(link, r, "Failed to set timezone for DHCP server: %m"); in dhcp4_server_configure()
506 ORDERED_HASHMAP_FOREACH(p, link->network->dhcp_server_send_options) { in dhcp4_server_configure()
507 r = sd_dhcp_server_add_option(link->dhcp_server, p); in dhcp4_server_configure()
511 return log_link_error_errno(link, r, "Failed to set DHCPv4 option: %m"); in dhcp4_server_configure()
514 ORDERED_HASHMAP_FOREACH(p, link->network->dhcp_server_send_vendor_options) { in dhcp4_server_configure()
515 r = sd_dhcp_server_add_vendor_option(link->dhcp_server, p); in dhcp4_server_configure()
519 return log_link_error_errno(link, r, "Failed to set DHCPv4 option: %m"); in dhcp4_server_configure()
522 HASHMAP_FOREACH(static_lease, link->network->dhcp_static_leases_by_section) { in dhcp4_server_configure()
523 …r = sd_dhcp_server_set_static_lease(link->dhcp_server, &static_lease->address, static_lease->clien… in dhcp4_server_configure()
525 … return log_link_error_errno(link, r, "Failed to set DHCPv4 static lease for DHCP server: %m"); in dhcp4_server_configure()
528 r = sd_dhcp_server_start(link->dhcp_server); in dhcp4_server_configure()
530 return log_link_error_errno(link, r, "Could not start DHCPv4 server instance: %m"); in dhcp4_server_configure()
532 log_link_debug(link, "Offering DHCPv4 leases"); in dhcp4_server_configure()
536 static bool dhcp_server_is_ready_to_configure(Link *link) { in dhcp_server_is_ready_to_configure() argument
540 assert(link); in dhcp_server_is_ready_to_configure()
542 if (!link->network) in dhcp_server_is_ready_to_configure()
545 if (!IN_SET(link->state, LINK_STATE_CONFIGURING, LINK_STATE_CONFIGURED)) in dhcp_server_is_ready_to_configure()
548 if (link->set_flags_messages > 0) in dhcp_server_is_ready_to_configure()
551 if (!link_has_carrier(link)) in dhcp_server_is_ready_to_configure()
554 if (!link->static_addresses_configured) in dhcp_server_is_ready_to_configure()
557 if (link_find_dhcp_server_address(link, &a) < 0) in dhcp_server_is_ready_to_configure()
563 if (dhcp_server_find_uplink(link, &uplink) < 0) in dhcp_server_is_ready_to_configure()
572 static int dhcp_server_process_request(Request *req, Link *link, void *userdata) { in dhcp_server_process_request() argument
575 assert(link); in dhcp_server_process_request()
577 if (!dhcp_server_is_ready_to_configure(link)) in dhcp_server_process_request()
580 r = dhcp4_server_configure(link); in dhcp_server_process_request()
582 return log_link_warning_errno(link, r, "Failed to configure DHCP server: %m"); in dhcp_server_process_request()
587 int link_request_dhcp_server(Link *link) { in link_request_dhcp_server() argument
590 assert(link); in link_request_dhcp_server()
592 if (!link_dhcp4_server_enabled(link)) in link_request_dhcp_server()
595 if (link->dhcp_server) in link_request_dhcp_server()
598 log_link_debug(link, "Requesting DHCP server."); in link_request_dhcp_server()
599 r = link_queue_request(link, REQUEST_TYPE_DHCP_SERVER, dhcp_server_process_request, NULL); in link_request_dhcp_server()
601 … return log_link_warning_errno(link, r, "Failed to request configuration of DHCP server: %m"); in link_request_dhcp_server()