1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include <netinet/ether.h>
6 #include "alloc-util.h"
7 #include "dhcp-lease-internal.h"
8 #include "hostname-util.h"
9 #include "parse-util.h"
10 #include "netdev/vrf.h"
11 #include "network-internal.h"
12 #include "networkd-link.h"
13 #include "networkd-manager.h"
14 #include "networkd-network.h"
15 #include "string-util.h"
16 #include "sysctl-util.h"
18 static int dhcp4_route_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
,
20 Link
*link
= userdata
;
24 assert(link
->dhcp4_messages
> 0);
26 link
->dhcp4_messages
--;
28 r
= sd_netlink_message_get_errno(m
);
29 if (r
< 0 && r
!= -EEXIST
) {
30 log_link_error_errno(link
, r
, "Could not set DHCPv4 route: %m");
31 link_enter_failed(link
);
34 if (link
->dhcp4_messages
== 0) {
35 link
->dhcp4_configured
= true;
36 link_check_ready(link
);
42 static int route_scope_from_address(const Route
*route
, const struct in_addr
*self_addr
) {
46 if (in_addr_is_localhost(AF_INET
, &route
->dst
) ||
47 (self_addr
->s_addr
&& route
->dst
.in
.s_addr
== self_addr
->s_addr
))
49 else if (in4_addr_is_null(&route
->gw
.in
))
52 return RT_SCOPE_UNIVERSE
;
55 static int link_set_dhcp_routes(Link
*link
) {
56 _cleanup_free_ sd_dhcp_route
**static_routes
= NULL
;
57 bool classless_route
= false, static_route
= false;
58 struct in_addr gateway
, address
;
64 if (!link
->dhcp_lease
) /* link went down while we configured the IP addresses? */
67 if (!link
->network
) /* link went down while we configured the IP addresses? */
70 if (!link
->network
->dhcp_use_routes
)
73 /* When the interface is part of an VRF use the VRFs routing table, unless
74 * there is a another table specified. */
75 table
= link
->network
->dhcp_route_table
;
76 if (!link
->network
->dhcp_route_table_set
&& link
->network
->vrf
!= NULL
)
77 table
= VRF(link
->network
->vrf
)->table
;
79 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &address
);
81 return log_link_warning_errno(link
, r
, "DHCP error: could not get address: %m");
83 n
= sd_dhcp_lease_get_routes(link
->dhcp_lease
, &static_routes
);
85 log_link_debug_errno(link
, n
, "DHCP: No routes received from DHCP server: %m");
87 log_link_debug_errno(link
, n
, "DHCP error: could not get routes: %m");
89 for (i
= 0; i
< n
; i
++) {
90 if (static_routes
[i
]->option
== SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
)
91 classless_route
= true;
93 if (static_routes
[i
]->option
== SD_DHCP_OPTION_STATIC_ROUTE
)
97 for (i
= 0; i
< n
; i
++) {
98 _cleanup_(route_freep
) Route
*route
= NULL
;
100 /* if the DHCP server returns both a Classless Static Routes option and a Static Routes option,
101 the DHCP client MUST ignore the Static Routes option. */
102 if (classless_route
&& static_routes
[i
]->option
== SD_DHCP_OPTION_STATIC_ROUTE
)
105 r
= route_new(&route
);
107 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
109 route
->family
= AF_INET
;
110 route
->protocol
= RTPROT_DHCP
;
111 assert_se(sd_dhcp_route_get_gateway(static_routes
[i
], &route
->gw
.in
) >= 0);
112 assert_se(sd_dhcp_route_get_destination(static_routes
[i
], &route
->dst
.in
) >= 0);
113 assert_se(sd_dhcp_route_get_destination_prefix_length(static_routes
[i
], &route
->dst_prefixlen
) >= 0);
114 route
->priority
= link
->network
->dhcp_route_metric
;
115 route
->table
= table
;
116 route
->scope
= route_scope_from_address(route
, &address
);
118 r
= route_configure(route
, link
, dhcp4_route_handler
);
120 return log_link_warning_errno(link
, r
, "Could not set host route: %m");
122 link
->dhcp4_messages
++;
125 r
= sd_dhcp_lease_get_router(link
->dhcp_lease
, &gateway
);
127 log_link_info_errno(link
, r
, "DHCP: No gateway received from DHCP server: %m");
129 log_link_warning_errno(link
, r
, "DHCP error: could not get gateway: %m");
131 /* According to RFC 3442: If the DHCP server returns both a Classless Static Routes option and
132 a Router option, the DHCP client MUST ignore the Router option. */
133 if (classless_route
&& static_route
)
134 log_link_warning(link
, "Classless static routes received from DHCP server: ignoring static-route option and router option");
136 if (r
>= 0 && !classless_route
) {
137 _cleanup_(route_freep
) Route
*route
= NULL
;
138 _cleanup_(route_freep
) Route
*route_gw
= NULL
;
140 r
= route_new(&route
);
142 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
144 route
->protocol
= RTPROT_DHCP
;
146 r
= route_new(&route_gw
);
148 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
150 /* The dhcp netmask may mask out the gateway. Add an explicit
151 * route for the gw host so that we can route no matter the
152 * netmask or existing kernel route tables. */
153 route_gw
->family
= AF_INET
;
154 route_gw
->dst
.in
= gateway
;
155 route_gw
->dst_prefixlen
= 32;
156 route_gw
->prefsrc
.in
= address
;
157 route_gw
->scope
= RT_SCOPE_LINK
;
158 route_gw
->protocol
= RTPROT_DHCP
;
159 route_gw
->priority
= link
->network
->dhcp_route_metric
;
160 route_gw
->table
= table
;
162 r
= route_configure(route_gw
, link
, dhcp4_route_handler
);
164 return log_link_warning_errno(link
, r
, "Could not set host route: %m");
166 link
->dhcp4_messages
++;
168 route
->family
= AF_INET
;
169 route
->gw
.in
= gateway
;
170 route
->prefsrc
.in
= address
;
171 route
->priority
= link
->network
->dhcp_route_metric
;
172 route
->table
= table
;
174 r
= route_configure(route
, link
, dhcp4_route_handler
);
176 log_link_warning_errno(link
, r
, "Could not set routes: %m");
177 link_enter_failed(link
);
181 link
->dhcp4_messages
++;
187 static int dhcp_lease_lost(Link
*link
) {
188 _cleanup_(address_freep
) Address
*address
= NULL
;
190 struct in_addr netmask
;
191 struct in_addr gateway
;
192 unsigned prefixlen
= 0;
196 assert(link
->dhcp_lease
);
198 log_link_warning(link
, "DHCP lease lost");
200 if (link
->network
->dhcp_use_routes
) {
201 _cleanup_free_ sd_dhcp_route
**routes
= NULL
;
204 n
= sd_dhcp_lease_get_routes(link
->dhcp_lease
, &routes
);
206 for (i
= 0; i
< n
; i
++) {
207 _cleanup_(route_freep
) Route
*route
= NULL
;
209 r
= route_new(&route
);
211 route
->family
= AF_INET
;
212 assert_se(sd_dhcp_route_get_gateway(routes
[i
], &route
->gw
.in
) >= 0);
213 assert_se(sd_dhcp_route_get_destination(routes
[i
], &route
->dst
.in
) >= 0);
214 assert_se(sd_dhcp_route_get_destination_prefix_length(routes
[i
], &route
->dst_prefixlen
) >= 0);
216 route_remove(route
, link
,
217 link_route_remove_handler
);
223 r
= address_new(&address
);
225 r
= sd_dhcp_lease_get_router(link
->dhcp_lease
, &gateway
);
227 _cleanup_(route_freep
) Route
*route_gw
= NULL
;
228 _cleanup_(route_freep
) Route
*route
= NULL
;
230 r
= route_new(&route_gw
);
232 route_gw
->family
= AF_INET
;
233 route_gw
->dst
.in
= gateway
;
234 route_gw
->dst_prefixlen
= 32;
235 route_gw
->scope
= RT_SCOPE_LINK
;
237 route_remove(route_gw
, link
,
238 link_route_remove_handler
);
241 r
= route_new(&route
);
243 route
->family
= AF_INET
;
244 route
->gw
.in
= gateway
;
246 route_remove(route
, link
,
247 link_route_remove_handler
);
251 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &addr
);
253 r
= sd_dhcp_lease_get_netmask(link
->dhcp_lease
, &netmask
);
255 prefixlen
= in4_addr_netmask_to_prefixlen(&netmask
);
257 address
->family
= AF_INET
;
258 address
->in_addr
.in
= addr
;
259 address
->prefixlen
= prefixlen
;
261 address_remove(address
, link
, link_address_remove_handler
);
265 if (link
->network
->dhcp_use_mtu
) {
268 r
= sd_dhcp_lease_get_mtu(link
->dhcp_lease
, &mtu
);
269 if (r
>= 0 && link
->original_mtu
!= mtu
) {
270 r
= link_set_mtu(link
, link
->original_mtu
);
272 log_link_warning(link
,
273 "DHCP error: could not reset MTU");
274 link_enter_failed(link
);
280 if (link
->network
->dhcp_use_hostname
) {
281 const char *hostname
= NULL
;
283 if (link
->network
->dhcp_hostname
)
284 hostname
= link
->network
->dhcp_hostname
;
286 (void) sd_dhcp_lease_get_hostname(link
->dhcp_lease
, &hostname
);
289 /* If a hostname was set due to the lease, then unset it now. */
290 r
= manager_set_hostname(link
->manager
, NULL
);
292 log_link_warning_errno(link
, r
, "Failed to reset transient hostname: %m");
296 link
->dhcp_lease
= sd_dhcp_lease_unref(link
->dhcp_lease
);
298 link
->dhcp4_configured
= false;
303 static int dhcp4_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
,
305 Link
*link
= userdata
;
310 r
= sd_netlink_message_get_errno(m
);
311 if (r
< 0 && r
!= -EEXIST
) {
312 log_link_error_errno(link
, r
, "Could not set DHCPv4 address: %m");
313 link_enter_failed(link
);
315 manager_rtnl_process_address(rtnl
, m
, link
->manager
);
317 link_set_dhcp_routes(link
);
319 if (link
->dhcp4_messages
== 0) {
320 link
->dhcp4_configured
= true;
321 link_check_ready(link
);
327 static int dhcp4_update_address(Link
*link
,
328 struct in_addr
*address
,
329 struct in_addr
*netmask
,
331 _cleanup_(address_freep
) Address
*addr
= NULL
;
339 prefixlen
= in4_addr_netmask_to_prefixlen(netmask
);
341 r
= address_new(&addr
);
345 addr
->family
= AF_INET
;
346 addr
->in_addr
.in
.s_addr
= address
->s_addr
;
347 addr
->cinfo
.ifa_prefered
= lifetime
;
348 addr
->cinfo
.ifa_valid
= lifetime
;
349 addr
->prefixlen
= prefixlen
;
350 addr
->broadcast
.s_addr
= address
->s_addr
| ~netmask
->s_addr
;
352 /* allow reusing an existing address and simply update its lifetime
353 * in case it already exists */
354 r
= address_configure(addr
, link
, dhcp4_address_handler
, true);
361 static int dhcp_lease_renew(sd_dhcp_client
*client
, Link
*link
) {
362 sd_dhcp_lease
*lease
;
363 struct in_addr address
;
364 struct in_addr netmask
;
365 uint32_t lifetime
= CACHE_INFO_INFINITY_LIFE_TIME
;
370 assert(link
->network
);
372 r
= sd_dhcp_client_get_lease(client
, &lease
);
374 return log_link_warning_errno(link
, r
, "DHCP error: no lease: %m");
376 sd_dhcp_lease_unref(link
->dhcp_lease
);
377 link
->dhcp4_configured
= false;
378 link
->dhcp_lease
= sd_dhcp_lease_ref(lease
);
381 r
= sd_dhcp_lease_get_address(lease
, &address
);
383 return log_link_warning_errno(link
, r
, "DHCP error: no address: %m");
385 r
= sd_dhcp_lease_get_netmask(lease
, &netmask
);
387 return log_link_warning_errno(link
, r
, "DHCP error: no netmask: %m");
389 if (!link
->network
->dhcp_critical
) {
390 r
= sd_dhcp_lease_get_lifetime(link
->dhcp_lease
, &lifetime
);
392 return log_link_warning_errno(link
, r
, "DHCP error: no lifetime: %m");
395 r
= dhcp4_update_address(link
, &address
, &netmask
, lifetime
);
397 log_link_warning_errno(link
, r
, "Could not update IP address: %m");
398 link_enter_failed(link
);
405 static int dhcp_lease_acquired(sd_dhcp_client
*client
, Link
*link
) {
406 sd_dhcp_lease
*lease
;
407 struct in_addr address
;
408 struct in_addr netmask
;
409 struct in_addr gateway
;
411 uint32_t lifetime
= CACHE_INFO_INFINITY_LIFE_TIME
;
417 r
= sd_dhcp_client_get_lease(client
, &lease
);
419 return log_link_error_errno(link
, r
, "DHCP error: No lease: %m");
421 r
= sd_dhcp_lease_get_address(lease
, &address
);
423 return log_link_error_errno(link
, r
, "DHCP error: No address: %m");
425 r
= sd_dhcp_lease_get_netmask(lease
, &netmask
);
427 return log_link_error_errno(link
, r
, "DHCP error: No netmask: %m");
429 prefixlen
= in4_addr_netmask_to_prefixlen(&netmask
);
431 r
= sd_dhcp_lease_get_router(lease
, &gateway
);
432 if (r
< 0 && r
!= -ENODATA
)
433 return log_link_error_errno(link
, r
, "DHCP error: Could not get gateway: %m");
437 LOG_LINK_INTERFACE(link
),
438 LOG_LINK_MESSAGE(link
, "DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
439 ADDRESS_FMT_VAL(address
),
441 ADDRESS_FMT_VAL(gateway
)),
442 "ADDRESS=%u.%u.%u.%u", ADDRESS_FMT_VAL(address
),
443 "PREFIXLEN=%u", prefixlen
,
444 "GATEWAY=%u.%u.%u.%u", ADDRESS_FMT_VAL(gateway
));
447 LOG_LINK_INTERFACE(link
),
448 LOG_LINK_MESSAGE(link
, "DHCPv4 address %u.%u.%u.%u/%u",
449 ADDRESS_FMT_VAL(address
),
451 "ADDRESS=%u.%u.%u.%u", ADDRESS_FMT_VAL(address
),
452 "PREFIXLEN=%u", prefixlen
);
454 link
->dhcp_lease
= sd_dhcp_lease_ref(lease
);
457 if (link
->network
->dhcp_use_mtu
) {
460 r
= sd_dhcp_lease_get_mtu(lease
, &mtu
);
462 r
= link_set_mtu(link
, mtu
);
464 log_link_error_errno(link
, r
, "Failed to set MTU to %" PRIu16
": %m", mtu
);
468 if (link
->network
->dhcp_use_hostname
) {
469 const char *dhcpname
= NULL
;
470 _cleanup_free_
char *hostname
= NULL
;
472 if (link
->network
->dhcp_hostname
)
473 dhcpname
= link
->network
->dhcp_hostname
;
475 (void) sd_dhcp_lease_get_hostname(lease
, &dhcpname
);
478 r
= shorten_overlong(dhcpname
, &hostname
);
480 log_link_warning_errno(link
, r
, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhcpname
);
482 log_link_notice(link
, "Overlong DCHP hostname received, shortened from '%s' to '%s'", dhcpname
, hostname
);
486 r
= manager_set_hostname(link
->manager
, hostname
);
488 log_link_error_errno(link
, r
, "Failed to set transient hostname to '%s': %m", hostname
);
492 if (link
->network
->dhcp_use_timezone
) {
493 const char *tz
= NULL
;
495 (void) sd_dhcp_lease_get_timezone(link
->dhcp_lease
, &tz
);
498 r
= manager_set_timezone(link
->manager
, tz
);
500 log_link_error_errno(link
, r
, "Failed to set timezone to '%s': %m", tz
);
504 if (!link
->network
->dhcp_critical
) {
505 r
= sd_dhcp_lease_get_lifetime(link
->dhcp_lease
, &lifetime
);
507 return log_link_warning_errno(link
, r
, "DHCP error: no lifetime: %m");
510 r
= dhcp4_update_address(link
, &address
, &netmask
, lifetime
);
512 log_link_warning_errno(link
, r
, "Could not update IP address: %m");
513 link_enter_failed(link
);
519 static void dhcp4_handler(sd_dhcp_client
*client
, int event
, void *userdata
) {
520 Link
*link
= userdata
;
524 assert(link
->network
);
525 assert(link
->manager
);
527 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
531 case SD_DHCP_CLIENT_EVENT_EXPIRED
:
532 case SD_DHCP_CLIENT_EVENT_STOP
:
533 case SD_DHCP_CLIENT_EVENT_IP_CHANGE
:
534 if (link
->network
->dhcp_critical
) {
535 log_link_error(link
, "DHCPv4 connection considered system critical, ignoring request to reconfigure it.");
539 if (link
->dhcp_lease
) {
540 r
= dhcp_lease_lost(link
);
542 link_enter_failed(link
);
547 if (event
== SD_DHCP_CLIENT_EVENT_IP_CHANGE
) {
548 r
= dhcp_lease_acquired(client
, link
);
550 link_enter_failed(link
);
556 case SD_DHCP_CLIENT_EVENT_RENEW
:
557 r
= dhcp_lease_renew(client
, link
);
559 link_enter_failed(link
);
563 case SD_DHCP_CLIENT_EVENT_IP_ACQUIRE
:
564 r
= dhcp_lease_acquired(client
, link
);
566 link_enter_failed(link
);
572 log_link_warning_errno(link
, event
, "DHCP error: Client failed: %m");
574 log_link_warning(link
, "DHCP unknown event: %i", event
);
581 static int dhcp4_set_hostname(Link
*link
) {
582 _cleanup_free_
char *hostname
= NULL
;
588 if (!link
->network
->dhcp_send_hostname
)
590 else if (link
->network
->dhcp_hostname
)
591 hn
= link
->network
->dhcp_hostname
;
593 r
= gethostname_strict(&hostname
);
594 if (r
< 0 && r
!= -ENXIO
) /* ENXIO: no hostname set or hostname is "localhost" */
600 r
= sd_dhcp_client_set_hostname(link
->dhcp_client
, hn
);
601 if (r
== -EINVAL
&& hostname
)
602 /* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
603 log_link_warning_errno(link
, r
, "DHCP4 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
605 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set hostname: %m");
610 static bool promote_secondaries_enabled(const char *ifname
) {
611 _cleanup_free_
char *promote_secondaries_sysctl
= NULL
;
612 char *promote_secondaries_path
;
615 promote_secondaries_path
= strjoina("net/ipv4/conf/", ifname
, "/promote_secondaries");
616 r
= sysctl_read(promote_secondaries_path
, &promote_secondaries_sysctl
);
618 log_debug_errno(r
, "Cannot read sysctl %s", promote_secondaries_path
);
622 truncate_nl(promote_secondaries_sysctl
);
623 r
= parse_boolean(promote_secondaries_sysctl
);
625 log_warning_errno(r
, "Cannot parse sysctl %s with content %s as boolean", promote_secondaries_path
, promote_secondaries_sysctl
);
629 /* dhcp4_set_promote_secondaries will ensure this interface has
630 * the "promote_secondaries" option in the kernel set. If this sysctl
631 * is not set DHCP will work only as long as the IP address does not
632 * changes between leases. The kernel will remove all secondary IP
633 * addresses of an interface otherwise. The way systemd-network works
634 * is that the new IP of a lease is added as a secondary IP and when
635 * the primary one expires it relies on the kernel to promote the
636 * secondary IP. See also https://github.com/systemd/systemd/issues/7163
638 int dhcp4_set_promote_secondaries(Link
*link
) {
642 assert(link
->network
);
643 assert(link
->network
->dhcp
& ADDRESS_FAMILY_IPV4
);
645 /* check if the kernel has promote_secondaries enabled for our
646 * interface. If it is not globally enabled or enabled for the
647 * specific interface we must either enable it.
649 if (!(promote_secondaries_enabled("all") || promote_secondaries_enabled(link
->ifname
))) {
650 char *promote_secondaries_path
= NULL
;
652 log_link_debug(link
, "promote_secondaries is unset, setting it");
653 promote_secondaries_path
= strjoina("net/ipv4/conf/", link
->ifname
, "/promote_secondaries");
654 r
= sysctl_write(promote_secondaries_path
, "1");
656 log_link_warning_errno(link
, r
, "cannot set sysctl %s to 1", promote_secondaries_path
);
663 int dhcp4_set_client_identifier(Link
*link
) {
667 assert(link
->network
);
668 assert(link
->dhcp_client
);
670 switch (link
->network
->dhcp_client_identifier
) {
671 case DHCP_CLIENT_ID_DUID
: {
672 /* If configured, apply user specified DUID and IAID */
673 const DUID
*duid
= link_get_duid(link
);
675 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
676 r
= sd_dhcp_client_set_iaid_duid_llt(link
->dhcp_client
,
680 r
= sd_dhcp_client_set_iaid_duid(link
->dhcp_client
,
683 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
686 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set IAID+DUID: %m");
689 case DHCP_CLIENT_ID_DUID_ONLY
: {
690 /* If configured, apply user specified DUID */
691 const DUID
*duid
= link_get_duid(link
);
693 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
694 r
= sd_dhcp_client_set_duid_llt(link
->dhcp_client
,
697 r
= sd_dhcp_client_set_duid(link
->dhcp_client
,
699 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
702 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set DUID: %m");
705 case DHCP_CLIENT_ID_MAC
:
706 r
= sd_dhcp_client_set_client_id(link
->dhcp_client
,
708 (const uint8_t *) &link
->mac
,
711 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set client ID: %m");
714 assert_not_reached("Unknown client identifier type.");
720 int dhcp4_configure(Link
*link
) {
724 assert(link
->network
);
725 assert(link
->network
->dhcp
& ADDRESS_FAMILY_IPV4
);
727 if (!link
->dhcp_client
) {
728 r
= sd_dhcp_client_new(&link
->dhcp_client
, link
->network
->dhcp_anonymize
);
732 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to create DHCP4 client: %m");
735 r
= sd_dhcp_client_attach_event(link
->dhcp_client
, NULL
, 0);
737 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to attach event: %m");
739 r
= sd_dhcp_client_set_mac(link
->dhcp_client
,
740 (const uint8_t *) &link
->mac
,
741 sizeof (link
->mac
), ARPHRD_ETHER
);
743 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MAC address: %m");
745 r
= sd_dhcp_client_set_ifindex(link
->dhcp_client
, link
->ifindex
);
747 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set ifindex: %m");
749 r
= sd_dhcp_client_set_callback(link
->dhcp_client
, dhcp4_handler
, link
);
751 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set callback: %m");
753 r
= sd_dhcp_client_set_request_broadcast(link
->dhcp_client
,
754 link
->network
->dhcp_broadcast
);
756 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for broadcast: %m");
759 r
= sd_dhcp_client_set_mtu(link
->dhcp_client
, link
->mtu
);
761 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MTU: %m");
764 if (link
->network
->dhcp_use_mtu
) {
765 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
766 SD_DHCP_OPTION_INTERFACE_MTU
);
768 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for MTU: %m");
771 /* NOTE: even if this variable is called "use", it also "sends" PRL
772 * options, maybe there should be a different configuration variable
773 * to send or not route options?. */
774 /* NOTE: when using Anonymize=yes, routes PRL options are sent
775 * by default, so they don't need to be added here. */
776 if (link
->network
->dhcp_use_routes
&& !link
->network
->dhcp_anonymize
) {
777 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
778 SD_DHCP_OPTION_STATIC_ROUTE
);
780 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for static route: %m");
782 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
783 SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
);
785 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for classless static route: %m");
788 if (link
->network
->dhcp_use_ntp
) {
789 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_NTP_SERVER
);
791 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for NTP server: %m");
794 if (link
->network
->dhcp_use_timezone
) {
795 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_NEW_TZDB_TIMEZONE
);
797 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for timezone: %m");
800 r
= dhcp4_set_hostname(link
);
804 if (link
->network
->dhcp_vendor_class_identifier
) {
805 r
= sd_dhcp_client_set_vendor_class_identifier(link
->dhcp_client
,
806 link
->network
->dhcp_vendor_class_identifier
);
808 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set vendor class identifier: %m");
811 if (link
->network
->dhcp_user_class
) {
812 r
= sd_dhcp_client_set_user_class(link
->dhcp_client
, (const char **) link
->network
->dhcp_user_class
);
814 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set user class: %m");
817 if (link
->network
->dhcp_client_port
) {
818 r
= sd_dhcp_client_set_client_port(link
->dhcp_client
, link
->network
->dhcp_client_port
);
820 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set listen port: %m");
823 return dhcp4_set_client_identifier(link
);