1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include <netinet/ether.h>
6 #include "alloc-util.h"
7 #include "hostname-util.h"
8 #include "parse-util.h"
9 #include "netdev/vrf.h"
10 #include "network-internal.h"
11 #include "networkd-link.h"
12 #include "networkd-manager.h"
13 #include "networkd-network.h"
14 #include "string-util.h"
15 #include "sysctl-util.h"
17 static int dhcp4_route_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
21 assert(link
->dhcp4_messages
> 0);
23 link
->dhcp4_messages
--;
25 r
= sd_netlink_message_get_errno(m
);
26 if (r
< 0 && r
!= -EEXIST
) {
27 log_link_error_errno(link
, r
, "Could not set DHCPv4 route: %m");
28 link_enter_failed(link
);
31 if (link
->dhcp4_messages
== 0) {
32 link
->dhcp4_configured
= true;
33 link_check_ready(link
);
39 static int route_scope_from_address(const Route
*route
, const struct in_addr
*self_addr
) {
43 if (in_addr_is_localhost(AF_INET
, &route
->dst
) ||
44 (self_addr
->s_addr
&& route
->dst
.in
.s_addr
== self_addr
->s_addr
))
46 else if (in4_addr_is_null(&route
->gw
.in
))
49 return RT_SCOPE_UNIVERSE
;
52 static int link_set_dhcp_routes(Link
*link
) {
53 _cleanup_free_ sd_dhcp_route
**static_routes
= NULL
;
54 bool classless_route
= false, static_route
= false;
55 struct in_addr gateway
, address
;
61 if (!link
->dhcp_lease
) /* link went down while we configured the IP addresses? */
64 if (!link
->network
) /* link went down while we configured the IP addresses? */
67 if (!link
->network
->dhcp_use_routes
)
70 /* When the interface is part of an VRF use the VRFs routing table, unless
71 * there is a another table specified. */
72 table
= link
->network
->dhcp_route_table
;
73 if (!link
->network
->dhcp_route_table_set
&& link
->network
->vrf
!= NULL
)
74 table
= VRF(link
->network
->vrf
)->table
;
76 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &address
);
78 return log_link_warning_errno(link
, r
, "DHCP error: could not get address: %m");
80 n
= sd_dhcp_lease_get_routes(link
->dhcp_lease
, &static_routes
);
82 log_link_debug_errno(link
, n
, "DHCP: No routes received from DHCP server: %m");
84 log_link_debug_errno(link
, n
, "DHCP error: could not get routes: %m");
86 for (i
= 0; i
< n
; i
++) {
87 switch (sd_dhcp_route_get_option(static_routes
[i
])) {
88 case SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
:
89 classless_route
= true;
91 case 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
&&
103 sd_dhcp_route_get_option(static_routes
[i
]) != SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
)
106 r
= route_new(&route
);
108 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
110 route
->family
= AF_INET
;
111 route
->protocol
= RTPROT_DHCP
;
112 assert_se(sd_dhcp_route_get_gateway(static_routes
[i
], &route
->gw
.in
) >= 0);
113 assert_se(sd_dhcp_route_get_destination(static_routes
[i
], &route
->dst
.in
) >= 0);
114 assert_se(sd_dhcp_route_get_destination_prefix_length(static_routes
[i
], &route
->dst_prefixlen
) >= 0);
115 route
->priority
= link
->network
->dhcp_route_metric
;
116 route
->table
= table
;
117 route
->scope
= route_scope_from_address(route
, &address
);
119 r
= route_configure(route
, link
, dhcp4_route_handler
);
121 return log_link_warning_errno(link
, r
, "Could not set host route: %m");
123 link
->dhcp4_messages
++;
126 r
= sd_dhcp_lease_get_router(link
->dhcp_lease
, &gateway
);
128 log_link_info_errno(link
, r
, "DHCP: No gateway received from DHCP server: %m");
130 log_link_warning_errno(link
, r
, "DHCP error: could not get gateway: %m");
132 /* According to RFC 3442: If the DHCP server returns both a Classless Static Routes option and
133 a Router option, the DHCP client MUST ignore the Router option. */
134 if (classless_route
&& static_route
)
135 log_link_warning(link
, "Classless static routes received from DHCP server: ignoring static-route option and router option");
137 if (r
>= 0 && !classless_route
) {
138 _cleanup_(route_freep
) Route
*route
= NULL
;
139 _cleanup_(route_freep
) Route
*route_gw
= NULL
;
141 r
= route_new(&route
);
143 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
145 route
->protocol
= RTPROT_DHCP
;
147 r
= route_new(&route_gw
);
149 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
151 /* The dhcp netmask may mask out the gateway. Add an explicit
152 * route for the gw host so that we can route no matter the
153 * netmask or existing kernel route tables. */
154 route_gw
->family
= AF_INET
;
155 route_gw
->dst
.in
= gateway
;
156 route_gw
->dst_prefixlen
= 32;
157 route_gw
->prefsrc
.in
= address
;
158 route_gw
->scope
= RT_SCOPE_LINK
;
159 route_gw
->protocol
= RTPROT_DHCP
;
160 route_gw
->priority
= link
->network
->dhcp_route_metric
;
161 route_gw
->table
= table
;
163 r
= route_configure(route_gw
, link
, dhcp4_route_handler
);
165 return log_link_warning_errno(link
, r
, "Could not set host route: %m");
167 link
->dhcp4_messages
++;
169 route
->family
= AF_INET
;
170 route
->gw
.in
= gateway
;
171 route
->prefsrc
.in
= address
;
172 route
->priority
= link
->network
->dhcp_route_metric
;
173 route
->table
= table
;
175 r
= route_configure(route
, link
, dhcp4_route_handler
);
177 log_link_warning_errno(link
, r
, "Could not set routes: %m");
178 link_enter_failed(link
);
182 link
->dhcp4_messages
++;
188 static int dhcp_lease_lost(Link
*link
) {
189 _cleanup_(address_freep
) Address
*address
= NULL
;
191 struct in_addr netmask
;
192 struct in_addr gateway
;
193 unsigned prefixlen
= 0;
197 assert(link
->dhcp_lease
);
199 log_link_warning(link
, "DHCP lease lost");
201 if (link
->network
->dhcp_use_routes
) {
202 _cleanup_free_ sd_dhcp_route
**routes
= NULL
;
205 n
= sd_dhcp_lease_get_routes(link
->dhcp_lease
, &routes
);
207 for (i
= 0; i
< n
; i
++) {
208 _cleanup_(route_freep
) Route
*route
= NULL
;
210 r
= route_new(&route
);
212 route
->family
= AF_INET
;
213 assert_se(sd_dhcp_route_get_gateway(routes
[i
], &route
->gw
.in
) >= 0);
214 assert_se(sd_dhcp_route_get_destination(routes
[i
], &route
->dst
.in
) >= 0);
215 assert_se(sd_dhcp_route_get_destination_prefix_length(routes
[i
], &route
->dst_prefixlen
) >= 0);
217 route_remove(route
, link
, NULL
);
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
, NULL
);
240 r
= route_new(&route
);
242 route
->family
= AF_INET
;
243 route
->gw
.in
= gateway
;
245 route_remove(route
, link
, NULL
);
249 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &addr
);
251 r
= sd_dhcp_lease_get_netmask(link
->dhcp_lease
, &netmask
);
253 prefixlen
= in4_addr_netmask_to_prefixlen(&netmask
);
255 address
->family
= AF_INET
;
256 address
->in_addr
.in
= addr
;
257 address
->prefixlen
= prefixlen
;
259 address_remove(address
, link
, NULL
);
263 if (link
->network
->dhcp_use_mtu
) {
266 r
= sd_dhcp_lease_get_mtu(link
->dhcp_lease
, &mtu
);
267 if (r
>= 0 && link
->original_mtu
!= mtu
) {
268 r
= link_set_mtu(link
, link
->original_mtu
);
270 log_link_warning(link
,
271 "DHCP error: could not reset MTU");
272 link_enter_failed(link
);
278 if (link
->network
->dhcp_use_hostname
) {
279 const char *hostname
= NULL
;
281 if (link
->network
->dhcp_hostname
)
282 hostname
= link
->network
->dhcp_hostname
;
284 (void) sd_dhcp_lease_get_hostname(link
->dhcp_lease
, &hostname
);
287 /* If a hostname was set due to the lease, then unset it now. */
288 r
= manager_set_hostname(link
->manager
, NULL
);
290 log_link_warning_errno(link
, r
, "Failed to reset transient hostname: %m");
294 link
->dhcp_lease
= sd_dhcp_lease_unref(link
->dhcp_lease
);
296 link
->dhcp4_configured
= false;
301 static int dhcp4_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
306 r
= sd_netlink_message_get_errno(m
);
307 if (r
< 0 && r
!= -EEXIST
) {
308 log_link_error_errno(link
, r
, "Could not set DHCPv4 address: %m");
309 link_enter_failed(link
);
311 manager_rtnl_process_address(rtnl
, m
, link
->manager
);
313 link_set_dhcp_routes(link
);
315 if (link
->dhcp4_messages
== 0) {
316 link
->dhcp4_configured
= true;
317 link_check_ready(link
);
323 static int dhcp4_update_address(Link
*link
,
324 struct in_addr
*address
,
325 struct in_addr
*netmask
,
327 _cleanup_(address_freep
) Address
*addr
= NULL
;
335 prefixlen
= in4_addr_netmask_to_prefixlen(netmask
);
337 r
= address_new(&addr
);
341 addr
->family
= AF_INET
;
342 addr
->in_addr
.in
.s_addr
= address
->s_addr
;
343 addr
->cinfo
.ifa_prefered
= lifetime
;
344 addr
->cinfo
.ifa_valid
= lifetime
;
345 addr
->prefixlen
= prefixlen
;
346 addr
->broadcast
.s_addr
= address
->s_addr
| ~netmask
->s_addr
;
348 /* allow reusing an existing address and simply update its lifetime
349 * in case it already exists */
350 r
= address_configure(addr
, link
, dhcp4_address_handler
, true);
357 static int dhcp_lease_renew(sd_dhcp_client
*client
, Link
*link
) {
358 sd_dhcp_lease
*lease
;
359 struct in_addr address
;
360 struct in_addr netmask
;
361 uint32_t lifetime
= CACHE_INFO_INFINITY_LIFE_TIME
;
366 assert(link
->network
);
368 r
= sd_dhcp_client_get_lease(client
, &lease
);
370 return log_link_warning_errno(link
, r
, "DHCP error: no lease: %m");
372 sd_dhcp_lease_unref(link
->dhcp_lease
);
373 link
->dhcp4_configured
= false;
374 link
->dhcp_lease
= sd_dhcp_lease_ref(lease
);
377 r
= sd_dhcp_lease_get_address(lease
, &address
);
379 return log_link_warning_errno(link
, r
, "DHCP error: no address: %m");
381 r
= sd_dhcp_lease_get_netmask(lease
, &netmask
);
383 return log_link_warning_errno(link
, r
, "DHCP error: no netmask: %m");
385 if (!link
->network
->dhcp_critical
) {
386 r
= sd_dhcp_lease_get_lifetime(link
->dhcp_lease
, &lifetime
);
388 return log_link_warning_errno(link
, r
, "DHCP error: no lifetime: %m");
391 r
= dhcp4_update_address(link
, &address
, &netmask
, lifetime
);
393 log_link_warning_errno(link
, r
, "Could not update IP address: %m");
394 link_enter_failed(link
);
401 static int dhcp_lease_acquired(sd_dhcp_client
*client
, Link
*link
) {
402 sd_dhcp_lease
*lease
;
403 struct in_addr address
;
404 struct in_addr netmask
;
405 struct in_addr gateway
;
407 uint32_t lifetime
= CACHE_INFO_INFINITY_LIFE_TIME
;
413 r
= sd_dhcp_client_get_lease(client
, &lease
);
415 return log_link_error_errno(link
, r
, "DHCP error: No lease: %m");
417 r
= sd_dhcp_lease_get_address(lease
, &address
);
419 return log_link_error_errno(link
, r
, "DHCP error: No address: %m");
421 r
= sd_dhcp_lease_get_netmask(lease
, &netmask
);
423 return log_link_error_errno(link
, r
, "DHCP error: No netmask: %m");
425 prefixlen
= in4_addr_netmask_to_prefixlen(&netmask
);
427 r
= sd_dhcp_lease_get_router(lease
, &gateway
);
428 if (r
< 0 && r
!= -ENODATA
)
429 return log_link_error_errno(link
, r
, "DHCP error: Could not get gateway: %m");
433 LOG_LINK_INTERFACE(link
),
434 LOG_LINK_MESSAGE(link
, "DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
435 ADDRESS_FMT_VAL(address
),
437 ADDRESS_FMT_VAL(gateway
)),
438 "ADDRESS=%u.%u.%u.%u", ADDRESS_FMT_VAL(address
),
439 "PREFIXLEN=%u", prefixlen
,
440 "GATEWAY=%u.%u.%u.%u", ADDRESS_FMT_VAL(gateway
));
443 LOG_LINK_INTERFACE(link
),
444 LOG_LINK_MESSAGE(link
, "DHCPv4 address %u.%u.%u.%u/%u",
445 ADDRESS_FMT_VAL(address
),
447 "ADDRESS=%u.%u.%u.%u", ADDRESS_FMT_VAL(address
),
448 "PREFIXLEN=%u", prefixlen
);
450 link
->dhcp_lease
= sd_dhcp_lease_ref(lease
);
453 if (link
->network
->dhcp_use_mtu
) {
456 r
= sd_dhcp_lease_get_mtu(lease
, &mtu
);
458 r
= link_set_mtu(link
, mtu
);
460 log_link_error_errno(link
, r
, "Failed to set MTU to %" PRIu16
": %m", mtu
);
464 if (link
->network
->dhcp_use_hostname
) {
465 const char *dhcpname
= NULL
;
466 _cleanup_free_
char *hostname
= NULL
;
468 if (link
->network
->dhcp_hostname
)
469 dhcpname
= link
->network
->dhcp_hostname
;
471 (void) sd_dhcp_lease_get_hostname(lease
, &dhcpname
);
474 r
= shorten_overlong(dhcpname
, &hostname
);
476 log_link_warning_errno(link
, r
, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhcpname
);
478 log_link_notice(link
, "Overlong DCHP hostname received, shortened from '%s' to '%s'", dhcpname
, hostname
);
482 r
= manager_set_hostname(link
->manager
, hostname
);
484 log_link_error_errno(link
, r
, "Failed to set transient hostname to '%s': %m", hostname
);
488 if (link
->network
->dhcp_use_timezone
) {
489 const char *tz
= NULL
;
491 (void) sd_dhcp_lease_get_timezone(link
->dhcp_lease
, &tz
);
494 r
= manager_set_timezone(link
->manager
, tz
);
496 log_link_error_errno(link
, r
, "Failed to set timezone to '%s': %m", tz
);
500 if (!link
->network
->dhcp_critical
) {
501 r
= sd_dhcp_lease_get_lifetime(link
->dhcp_lease
, &lifetime
);
503 return log_link_warning_errno(link
, r
, "DHCP error: no lifetime: %m");
506 r
= dhcp4_update_address(link
, &address
, &netmask
, lifetime
);
508 log_link_warning_errno(link
, r
, "Could not update IP address: %m");
509 link_enter_failed(link
);
515 static void dhcp4_handler(sd_dhcp_client
*client
, int event
, void *userdata
) {
516 Link
*link
= userdata
;
520 assert(link
->network
);
521 assert(link
->manager
);
523 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
527 case SD_DHCP_CLIENT_EVENT_EXPIRED
:
528 case SD_DHCP_CLIENT_EVENT_STOP
:
529 case SD_DHCP_CLIENT_EVENT_IP_CHANGE
:
530 if (link
->network
->dhcp_critical
) {
531 log_link_error(link
, "DHCPv4 connection considered system critical, ignoring request to reconfigure it.");
535 if (link
->dhcp_lease
) {
536 r
= dhcp_lease_lost(link
);
538 link_enter_failed(link
);
543 if (event
== SD_DHCP_CLIENT_EVENT_IP_CHANGE
) {
544 r
= dhcp_lease_acquired(client
, link
);
546 link_enter_failed(link
);
552 case SD_DHCP_CLIENT_EVENT_RENEW
:
553 r
= dhcp_lease_renew(client
, link
);
555 link_enter_failed(link
);
559 case SD_DHCP_CLIENT_EVENT_IP_ACQUIRE
:
560 r
= dhcp_lease_acquired(client
, link
);
562 link_enter_failed(link
);
568 log_link_warning_errno(link
, event
, "DHCP error: Client failed: %m");
570 log_link_warning(link
, "DHCP unknown event: %i", event
);
577 static int dhcp4_set_hostname(Link
*link
) {
578 _cleanup_free_
char *hostname
= NULL
;
584 if (!link
->network
->dhcp_send_hostname
)
586 else if (link
->network
->dhcp_hostname
)
587 hn
= link
->network
->dhcp_hostname
;
589 r
= gethostname_strict(&hostname
);
590 if (r
< 0 && r
!= -ENXIO
) /* ENXIO: no hostname set or hostname is "localhost" */
596 r
= sd_dhcp_client_set_hostname(link
->dhcp_client
, hn
);
597 if (r
== -EINVAL
&& hostname
)
598 /* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
599 log_link_warning_errno(link
, r
, "DHCP4 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
601 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set hostname: %m");
606 static bool promote_secondaries_enabled(const char *ifname
) {
607 _cleanup_free_
char *promote_secondaries_sysctl
= NULL
;
608 char *promote_secondaries_path
;
611 promote_secondaries_path
= strjoina("net/ipv4/conf/", ifname
, "/promote_secondaries");
612 r
= sysctl_read(promote_secondaries_path
, &promote_secondaries_sysctl
);
614 log_debug_errno(r
, "Cannot read sysctl %s", promote_secondaries_path
);
618 truncate_nl(promote_secondaries_sysctl
);
619 r
= parse_boolean(promote_secondaries_sysctl
);
621 log_warning_errno(r
, "Cannot parse sysctl %s with content %s as boolean", promote_secondaries_path
, promote_secondaries_sysctl
);
625 /* dhcp4_set_promote_secondaries will ensure this interface has
626 * the "promote_secondaries" option in the kernel set. If this sysctl
627 * is not set DHCP will work only as long as the IP address does not
628 * changes between leases. The kernel will remove all secondary IP
629 * addresses of an interface otherwise. The way systemd-network works
630 * is that the new IP of a lease is added as a secondary IP and when
631 * the primary one expires it relies on the kernel to promote the
632 * secondary IP. See also https://github.com/systemd/systemd/issues/7163
634 int dhcp4_set_promote_secondaries(Link
*link
) {
638 assert(link
->network
);
639 assert(link
->network
->dhcp
& ADDRESS_FAMILY_IPV4
);
641 /* check if the kernel has promote_secondaries enabled for our
642 * interface. If it is not globally enabled or enabled for the
643 * specific interface we must either enable it.
645 if (!(promote_secondaries_enabled("all") || promote_secondaries_enabled(link
->ifname
))) {
646 char *promote_secondaries_path
= NULL
;
648 log_link_debug(link
, "promote_secondaries is unset, setting it");
649 promote_secondaries_path
= strjoina("net/ipv4/conf/", link
->ifname
, "/promote_secondaries");
650 r
= sysctl_write(promote_secondaries_path
, "1");
652 log_link_warning_errno(link
, r
, "cannot set sysctl %s to 1", promote_secondaries_path
);
659 int dhcp4_set_client_identifier(Link
*link
) {
663 assert(link
->network
);
664 assert(link
->dhcp_client
);
666 switch (link
->network
->dhcp_client_identifier
) {
667 case DHCP_CLIENT_ID_DUID
: {
668 /* If configured, apply user specified DUID and IAID */
669 const DUID
*duid
= link_get_duid(link
);
671 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
672 r
= sd_dhcp_client_set_iaid_duid_llt(link
->dhcp_client
,
673 link
->network
->iaid_set
,
677 r
= sd_dhcp_client_set_iaid_duid(link
->dhcp_client
,
678 link
->network
->iaid_set
,
681 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
684 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set IAID+DUID: %m");
687 case DHCP_CLIENT_ID_DUID_ONLY
: {
688 /* If configured, apply user specified DUID */
689 const DUID
*duid
= link_get_duid(link
);
691 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
692 r
= sd_dhcp_client_set_duid_llt(link
->dhcp_client
,
695 r
= sd_dhcp_client_set_duid(link
->dhcp_client
,
697 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
700 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set DUID: %m");
703 case DHCP_CLIENT_ID_MAC
:
704 r
= sd_dhcp_client_set_client_id(link
->dhcp_client
,
706 (const uint8_t *) &link
->mac
,
709 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set client ID: %m");
712 assert_not_reached("Unknown client identifier type.");
718 int dhcp4_configure(Link
*link
) {
722 assert(link
->network
);
723 assert(link
->network
->dhcp
& ADDRESS_FAMILY_IPV4
);
725 if (!link
->dhcp_client
) {
726 r
= sd_dhcp_client_new(&link
->dhcp_client
, link
->network
->dhcp_anonymize
);
730 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to create DHCP4 client: %m");
733 r
= sd_dhcp_client_attach_event(link
->dhcp_client
, NULL
, 0);
735 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to attach event: %m");
737 r
= sd_dhcp_client_set_mac(link
->dhcp_client
,
738 (const uint8_t *) &link
->mac
,
739 sizeof (link
->mac
), ARPHRD_ETHER
);
741 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MAC address: %m");
743 r
= sd_dhcp_client_set_ifindex(link
->dhcp_client
, link
->ifindex
);
745 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set ifindex: %m");
747 r
= sd_dhcp_client_set_callback(link
->dhcp_client
, dhcp4_handler
, link
);
749 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set callback: %m");
751 r
= sd_dhcp_client_set_request_broadcast(link
->dhcp_client
,
752 link
->network
->dhcp_broadcast
);
754 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for broadcast: %m");
757 r
= sd_dhcp_client_set_mtu(link
->dhcp_client
, link
->mtu
);
759 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MTU: %m");
762 if (link
->network
->dhcp_use_mtu
) {
763 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
764 SD_DHCP_OPTION_INTERFACE_MTU
);
766 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for MTU: %m");
769 /* NOTE: even if this variable is called "use", it also "sends" PRL
770 * options, maybe there should be a different configuration variable
771 * to send or not route options?. */
772 /* NOTE: when using Anonymize=yes, routes PRL options are sent
773 * by default, so they don't need to be added here. */
774 if (link
->network
->dhcp_use_routes
&& !link
->network
->dhcp_anonymize
) {
775 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
776 SD_DHCP_OPTION_STATIC_ROUTE
);
778 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for static route: %m");
780 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
781 SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
);
783 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for classless static route: %m");
786 if (link
->network
->dhcp_use_ntp
) {
787 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_NTP_SERVER
);
789 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for NTP server: %m");
792 if (link
->network
->dhcp_use_timezone
) {
793 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_NEW_TZDB_TIMEZONE
);
795 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for timezone: %m");
798 r
= dhcp4_set_hostname(link
);
802 if (link
->network
->dhcp_vendor_class_identifier
) {
803 r
= sd_dhcp_client_set_vendor_class_identifier(link
->dhcp_client
,
804 link
->network
->dhcp_vendor_class_identifier
);
806 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set vendor class identifier: %m");
809 if (link
->network
->dhcp_user_class
) {
810 r
= sd_dhcp_client_set_user_class(link
->dhcp_client
, (const char **) link
->network
->dhcp_user_class
);
812 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set user class: %m");
815 if (link
->network
->dhcp_client_port
) {
816 r
= sd_dhcp_client_set_client_port(link
->dhcp_client
, link
->network
->dhcp_client_port
);
818 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set listen port: %m");
821 return dhcp4_set_client_identifier(link
);