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 "network-internal.h"
10 #include "networkd-link.h"
11 #include "networkd-manager.h"
12 #include "networkd-network.h"
13 #include "string-util.h"
14 #include "sysctl-util.h"
16 static int dhcp4_route_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
20 assert(link
->dhcp4_messages
> 0);
22 link
->dhcp4_messages
--;
24 r
= sd_netlink_message_get_errno(m
);
25 if (r
< 0 && r
!= -EEXIST
) {
26 log_link_error_errno(link
, r
, "Could not set DHCPv4 route: %m");
27 link_enter_failed(link
);
30 if (link
->dhcp4_messages
== 0) {
31 link
->dhcp4_configured
= true;
32 link_check_ready(link
);
38 static int route_scope_from_address(const Route
*route
, const struct in_addr
*self_addr
) {
42 if (in_addr_is_localhost(AF_INET
, &route
->dst
) ||
43 (self_addr
->s_addr
&& route
->dst
.in
.s_addr
== self_addr
->s_addr
))
45 else if (in4_addr_is_null(&route
->gw
.in
))
48 return RT_SCOPE_UNIVERSE
;
51 static int link_set_dhcp_routes(Link
*link
) {
52 _cleanup_free_ sd_dhcp_route
**static_routes
= NULL
;
53 bool classless_route
= false, static_route
= false;
54 const struct in_addr
*router
;
55 struct in_addr 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 table
= link_get_dhcp_route_table(link
);
72 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &address
);
74 return log_link_warning_errno(link
, r
, "DHCP error: could not get address: %m");
76 n
= sd_dhcp_lease_get_routes(link
->dhcp_lease
, &static_routes
);
78 log_link_debug_errno(link
, n
, "DHCP: No routes received from DHCP server: %m");
80 log_link_debug_errno(link
, n
, "DHCP error: could not get routes: %m");
82 for (i
= 0; i
< n
; i
++) {
83 switch (sd_dhcp_route_get_option(static_routes
[i
])) {
84 case SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
:
85 classless_route
= true;
87 case SD_DHCP_OPTION_STATIC_ROUTE
:
93 for (i
= 0; i
< n
; i
++) {
94 _cleanup_(route_freep
) Route
*route
= NULL
;
96 /* if the DHCP server returns both a Classless Static Routes option and a Static Routes option,
97 the DHCP client MUST ignore the Static Routes option. */
98 if (classless_route
&&
99 sd_dhcp_route_get_option(static_routes
[i
]) != SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
)
102 r
= route_new(&route
);
104 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
106 route
->family
= AF_INET
;
107 route
->protocol
= RTPROT_DHCP
;
108 assert_se(sd_dhcp_route_get_gateway(static_routes
[i
], &route
->gw
.in
) >= 0);
109 assert_se(sd_dhcp_route_get_destination(static_routes
[i
], &route
->dst
.in
) >= 0);
110 assert_se(sd_dhcp_route_get_destination_prefix_length(static_routes
[i
], &route
->dst_prefixlen
) >= 0);
111 route
->priority
= link
->network
->dhcp_route_metric
;
112 route
->table
= table
;
113 route
->scope
= route_scope_from_address(route
, &address
);
115 r
= route_configure(route
, link
, dhcp4_route_handler
);
117 return log_link_warning_errno(link
, r
, "Could not set host route: %m");
119 link
->dhcp4_messages
++;
122 r
= sd_dhcp_lease_get_router(link
->dhcp_lease
, &router
);
123 if (IN_SET(r
, 0, -ENODATA
))
124 log_link_info(link
, "DHCP: No gateway received from DHCP server.");
126 log_link_warning_errno(link
, r
, "DHCP error: could not get gateway: %m");
127 else if (in4_addr_is_null(&router
[0]))
128 log_link_info(link
, "DHCP: Received gateway is null.");
130 /* According to RFC 3442: If the DHCP server returns both a Classless Static Routes option and
131 a Router option, the DHCP client MUST ignore the Router option. */
132 if (classless_route
&& static_route
)
133 log_link_warning(link
, "Classless static routes received from DHCP server: ignoring static-route option and router option");
135 if (r
> 0 && !classless_route
&& !in4_addr_is_null(&router
[0])) {
136 _cleanup_(route_freep
) Route
*route
= NULL
, *route_gw
= NULL
;
138 r
= route_new(&route_gw
);
140 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
142 /* The dhcp netmask may mask out the gateway. Add an explicit
143 * route for the gw host so that we can route no matter the
144 * netmask or existing kernel route tables. */
145 route_gw
->family
= AF_INET
;
146 route_gw
->dst
.in
= router
[0];
147 route_gw
->dst_prefixlen
= 32;
148 route_gw
->prefsrc
.in
= address
;
149 route_gw
->scope
= RT_SCOPE_LINK
;
150 route_gw
->protocol
= RTPROT_DHCP
;
151 route_gw
->priority
= link
->network
->dhcp_route_metric
;
152 route_gw
->table
= table
;
154 r
= route_configure(route_gw
, link
, dhcp4_route_handler
);
156 return log_link_warning_errno(link
, r
, "Could not set host route: %m");
158 link
->dhcp4_messages
++;
160 r
= route_new(&route
);
162 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
164 route
->family
= AF_INET
;
165 route
->gw
.in
= router
[0];
166 route
->prefsrc
.in
= address
;
167 route
->protocol
= RTPROT_DHCP
;
168 route
->priority
= link
->network
->dhcp_route_metric
;
169 route
->table
= table
;
171 r
= route_configure(route
, link
, dhcp4_route_handler
);
173 log_link_warning_errno(link
, r
, "Could not set routes: %m");
174 link_enter_failed(link
);
178 link
->dhcp4_messages
++;
184 static int dhcp_lease_lost(Link
*link
) {
185 _cleanup_(address_freep
) Address
*address
= NULL
;
186 const struct in_addr
*router
;
188 struct in_addr netmask
;
189 unsigned prefixlen
= 0;
193 assert(link
->dhcp_lease
);
195 log_link_warning(link
, "DHCP lease lost");
197 if (link
->network
->dhcp_use_routes
) {
198 _cleanup_free_ sd_dhcp_route
**routes
= NULL
;
201 n
= sd_dhcp_lease_get_routes(link
->dhcp_lease
, &routes
);
203 for (i
= 0; i
< n
; i
++) {
204 _cleanup_(route_freep
) Route
*route
= NULL
;
206 r
= route_new(&route
);
208 route
->family
= AF_INET
;
209 assert_se(sd_dhcp_route_get_gateway(routes
[i
], &route
->gw
.in
) >= 0);
210 assert_se(sd_dhcp_route_get_destination(routes
[i
], &route
->dst
.in
) >= 0);
211 assert_se(sd_dhcp_route_get_destination_prefix_length(routes
[i
], &route
->dst_prefixlen
) >= 0);
213 route_remove(route
, link
, NULL
);
219 r
= address_new(&address
);
221 r
= sd_dhcp_lease_get_router(link
->dhcp_lease
, &router
);
222 if (r
> 0 && !in4_addr_is_null(&router
[0])) {
223 _cleanup_(route_freep
) Route
*route_gw
= NULL
;
224 _cleanup_(route_freep
) Route
*route
= NULL
;
226 r
= route_new(&route_gw
);
228 route_gw
->family
= AF_INET
;
229 route_gw
->dst
.in
= router
[0];
230 route_gw
->dst_prefixlen
= 32;
231 route_gw
->scope
= RT_SCOPE_LINK
;
233 route_remove(route_gw
, link
, NULL
);
236 r
= route_new(&route
);
238 route
->family
= AF_INET
;
239 route
->gw
.in
= router
[0];
241 route_remove(route
, link
, NULL
);
245 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &addr
);
247 r
= sd_dhcp_lease_get_netmask(link
->dhcp_lease
, &netmask
);
249 prefixlen
= in4_addr_netmask_to_prefixlen(&netmask
);
251 address
->family
= AF_INET
;
252 address
->in_addr
.in
= addr
;
253 address
->prefixlen
= prefixlen
;
255 address_remove(address
, link
, NULL
);
259 if (link
->network
->dhcp_use_mtu
) {
262 r
= sd_dhcp_lease_get_mtu(link
->dhcp_lease
, &mtu
);
263 if (r
>= 0 && link
->original_mtu
!= mtu
) {
264 r
= link_set_mtu(link
, link
->original_mtu
);
266 log_link_warning(link
,
267 "DHCP error: could not reset MTU");
268 link_enter_failed(link
);
274 if (link
->network
->dhcp_use_hostname
) {
275 const char *hostname
= NULL
;
277 if (link
->network
->dhcp_hostname
)
278 hostname
= link
->network
->dhcp_hostname
;
280 (void) sd_dhcp_lease_get_hostname(link
->dhcp_lease
, &hostname
);
283 /* If a hostname was set due to the lease, then unset it now. */
284 r
= manager_set_hostname(link
->manager
, NULL
);
286 log_link_warning_errno(link
, r
, "Failed to reset transient hostname: %m");
290 link
->dhcp_lease
= sd_dhcp_lease_unref(link
->dhcp_lease
);
292 link
->dhcp4_configured
= false;
297 static int dhcp4_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
302 r
= sd_netlink_message_get_errno(m
);
303 if (r
< 0 && r
!= -EEXIST
) {
304 log_link_error_errno(link
, r
, "Could not set DHCPv4 address: %m");
305 link_enter_failed(link
);
307 manager_rtnl_process_address(rtnl
, m
, link
->manager
);
309 link_set_dhcp_routes(link
);
311 if (link
->dhcp4_messages
== 0) {
312 link
->dhcp4_configured
= true;
313 link_check_ready(link
);
319 static int dhcp4_update_address(Link
*link
,
320 struct in_addr
*address
,
321 struct in_addr
*netmask
,
323 _cleanup_(address_freep
) Address
*addr
= NULL
;
331 prefixlen
= in4_addr_netmask_to_prefixlen(netmask
);
333 r
= address_new(&addr
);
337 addr
->family
= AF_INET
;
338 addr
->in_addr
.in
.s_addr
= address
->s_addr
;
339 addr
->cinfo
.ifa_prefered
= lifetime
;
340 addr
->cinfo
.ifa_valid
= lifetime
;
341 addr
->prefixlen
= prefixlen
;
342 addr
->broadcast
.s_addr
= address
->s_addr
| ~netmask
->s_addr
;
344 /* allow reusing an existing address and simply update its lifetime
345 * in case it already exists */
346 r
= address_configure(addr
, link
, dhcp4_address_handler
, true);
353 static int dhcp_lease_renew(sd_dhcp_client
*client
, Link
*link
) {
354 sd_dhcp_lease
*lease
;
355 struct in_addr address
;
356 struct in_addr netmask
;
357 uint32_t lifetime
= CACHE_INFO_INFINITY_LIFE_TIME
;
362 assert(link
->network
);
364 r
= sd_dhcp_client_get_lease(client
, &lease
);
366 return log_link_warning_errno(link
, r
, "DHCP error: no lease: %m");
368 sd_dhcp_lease_unref(link
->dhcp_lease
);
369 link
->dhcp4_configured
= false;
370 link
->dhcp_lease
= sd_dhcp_lease_ref(lease
);
373 r
= sd_dhcp_lease_get_address(lease
, &address
);
375 return log_link_warning_errno(link
, r
, "DHCP error: no address: %m");
377 r
= sd_dhcp_lease_get_netmask(lease
, &netmask
);
379 return log_link_warning_errno(link
, r
, "DHCP error: no netmask: %m");
381 if (!link
->network
->dhcp_critical
) {
382 r
= sd_dhcp_lease_get_lifetime(link
->dhcp_lease
, &lifetime
);
384 return log_link_warning_errno(link
, r
, "DHCP error: no lifetime: %m");
387 r
= dhcp4_update_address(link
, &address
, &netmask
, lifetime
);
389 log_link_warning_errno(link
, r
, "Could not update IP address: %m");
390 link_enter_failed(link
);
397 static int dhcp_lease_acquired(sd_dhcp_client
*client
, Link
*link
) {
398 const struct in_addr
*router
;
399 sd_dhcp_lease
*lease
;
400 struct in_addr address
;
401 struct in_addr netmask
;
403 uint32_t lifetime
= CACHE_INFO_INFINITY_LIFE_TIME
;
409 r
= sd_dhcp_client_get_lease(client
, &lease
);
411 return log_link_error_errno(link
, r
, "DHCP error: No lease: %m");
413 r
= sd_dhcp_lease_get_address(lease
, &address
);
415 return log_link_error_errno(link
, r
, "DHCP error: No address: %m");
417 r
= sd_dhcp_lease_get_netmask(lease
, &netmask
);
419 return log_link_error_errno(link
, r
, "DHCP error: No netmask: %m");
421 prefixlen
= in4_addr_netmask_to_prefixlen(&netmask
);
423 r
= sd_dhcp_lease_get_router(lease
, &router
);
424 if (r
< 0 && r
!= -ENODATA
)
425 return log_link_error_errno(link
, r
, "DHCP error: Could not get gateway: %m");
427 if (r
> 0 && !in4_addr_is_null(&router
[0]))
429 LOG_LINK_INTERFACE(link
),
430 LOG_LINK_MESSAGE(link
, "DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
431 ADDRESS_FMT_VAL(address
),
433 ADDRESS_FMT_VAL(router
[0])),
434 "ADDRESS=%u.%u.%u.%u", ADDRESS_FMT_VAL(address
),
435 "PREFIXLEN=%u", prefixlen
,
436 "GATEWAY=%u.%u.%u.%u", ADDRESS_FMT_VAL(router
[0]));
439 LOG_LINK_INTERFACE(link
),
440 LOG_LINK_MESSAGE(link
, "DHCPv4 address %u.%u.%u.%u/%u",
441 ADDRESS_FMT_VAL(address
),
443 "ADDRESS=%u.%u.%u.%u", ADDRESS_FMT_VAL(address
),
444 "PREFIXLEN=%u", prefixlen
);
446 link
->dhcp_lease
= sd_dhcp_lease_ref(lease
);
449 if (link
->network
->dhcp_use_mtu
) {
452 r
= sd_dhcp_lease_get_mtu(lease
, &mtu
);
454 r
= link_set_mtu(link
, mtu
);
456 log_link_error_errno(link
, r
, "Failed to set MTU to %" PRIu16
": %m", mtu
);
460 if (link
->network
->dhcp_use_hostname
) {
461 const char *dhcpname
= NULL
;
462 _cleanup_free_
char *hostname
= NULL
;
464 if (link
->network
->dhcp_hostname
)
465 dhcpname
= link
->network
->dhcp_hostname
;
467 (void) sd_dhcp_lease_get_hostname(lease
, &dhcpname
);
470 r
= shorten_overlong(dhcpname
, &hostname
);
472 log_link_warning_errno(link
, r
, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhcpname
);
474 log_link_notice(link
, "Overlong DCHP hostname received, shortened from '%s' to '%s'", dhcpname
, hostname
);
478 r
= manager_set_hostname(link
->manager
, hostname
);
480 log_link_error_errno(link
, r
, "Failed to set transient hostname to '%s': %m", hostname
);
484 if (link
->network
->dhcp_use_timezone
) {
485 const char *tz
= NULL
;
487 (void) sd_dhcp_lease_get_timezone(link
->dhcp_lease
, &tz
);
490 r
= manager_set_timezone(link
->manager
, tz
);
492 log_link_error_errno(link
, r
, "Failed to set timezone to '%s': %m", tz
);
496 if (!link
->network
->dhcp_critical
) {
497 r
= sd_dhcp_lease_get_lifetime(link
->dhcp_lease
, &lifetime
);
499 return log_link_warning_errno(link
, r
, "DHCP error: no lifetime: %m");
502 r
= dhcp4_update_address(link
, &address
, &netmask
, lifetime
);
504 log_link_warning_errno(link
, r
, "Could not update IP address: %m");
505 link_enter_failed(link
);
511 static void dhcp4_handler(sd_dhcp_client
*client
, int event
, void *userdata
) {
512 Link
*link
= userdata
;
516 assert(link
->network
);
517 assert(link
->manager
);
519 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
523 case SD_DHCP_CLIENT_EVENT_EXPIRED
:
524 case SD_DHCP_CLIENT_EVENT_STOP
:
525 case SD_DHCP_CLIENT_EVENT_IP_CHANGE
:
526 if (link
->network
->dhcp_critical
) {
527 log_link_error(link
, "DHCPv4 connection considered system critical, ignoring request to reconfigure it.");
531 if (link
->dhcp_lease
) {
532 r
= dhcp_lease_lost(link
);
534 link_enter_failed(link
);
539 if (event
== SD_DHCP_CLIENT_EVENT_IP_CHANGE
) {
540 r
= dhcp_lease_acquired(client
, link
);
542 link_enter_failed(link
);
548 case SD_DHCP_CLIENT_EVENT_RENEW
:
549 r
= dhcp_lease_renew(client
, link
);
551 link_enter_failed(link
);
555 case SD_DHCP_CLIENT_EVENT_IP_ACQUIRE
:
556 r
= dhcp_lease_acquired(client
, link
);
558 link_enter_failed(link
);
564 log_link_warning_errno(link
, event
, "DHCP error: Client failed: %m");
566 log_link_warning(link
, "DHCP unknown event: %i", event
);
573 static int dhcp4_set_hostname(Link
*link
) {
574 _cleanup_free_
char *hostname
= NULL
;
580 if (!link
->network
->dhcp_send_hostname
)
582 else if (link
->network
->dhcp_hostname
)
583 hn
= link
->network
->dhcp_hostname
;
585 r
= gethostname_strict(&hostname
);
586 if (r
< 0 && r
!= -ENXIO
) /* ENXIO: no hostname set or hostname is "localhost" */
592 r
= sd_dhcp_client_set_hostname(link
->dhcp_client
, hn
);
593 if (r
== -EINVAL
&& hostname
)
594 /* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
595 log_link_warning_errno(link
, r
, "DHCP4 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
597 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set hostname: %m");
602 static bool promote_secondaries_enabled(const char *ifname
) {
603 _cleanup_free_
char *promote_secondaries_sysctl
= NULL
;
604 char *promote_secondaries_path
;
607 promote_secondaries_path
= strjoina("net/ipv4/conf/", ifname
, "/promote_secondaries");
608 r
= sysctl_read(promote_secondaries_path
, &promote_secondaries_sysctl
);
610 log_debug_errno(r
, "Cannot read sysctl %s", promote_secondaries_path
);
614 truncate_nl(promote_secondaries_sysctl
);
615 r
= parse_boolean(promote_secondaries_sysctl
);
617 log_warning_errno(r
, "Cannot parse sysctl %s with content %s as boolean", promote_secondaries_path
, promote_secondaries_sysctl
);
621 /* dhcp4_set_promote_secondaries will ensure this interface has
622 * the "promote_secondaries" option in the kernel set. If this sysctl
623 * is not set DHCP will work only as long as the IP address does not
624 * changes between leases. The kernel will remove all secondary IP
625 * addresses of an interface otherwise. The way systemd-network works
626 * is that the new IP of a lease is added as a secondary IP and when
627 * the primary one expires it relies on the kernel to promote the
628 * secondary IP. See also https://github.com/systemd/systemd/issues/7163
630 int dhcp4_set_promote_secondaries(Link
*link
) {
634 assert(link
->network
);
635 assert(link
->network
->dhcp
& ADDRESS_FAMILY_IPV4
);
637 /* check if the kernel has promote_secondaries enabled for our
638 * interface. If it is not globally enabled or enabled for the
639 * specific interface we must either enable it.
641 if (!(promote_secondaries_enabled("all") || promote_secondaries_enabled(link
->ifname
))) {
642 char *promote_secondaries_path
= NULL
;
644 log_link_debug(link
, "promote_secondaries is unset, setting it");
645 promote_secondaries_path
= strjoina("net/ipv4/conf/", link
->ifname
, "/promote_secondaries");
646 r
= sysctl_write(promote_secondaries_path
, "1");
648 log_link_warning_errno(link
, r
, "cannot set sysctl %s to 1", promote_secondaries_path
);
655 int dhcp4_set_client_identifier(Link
*link
) {
659 assert(link
->network
);
660 assert(link
->dhcp_client
);
662 switch (link
->network
->dhcp_client_identifier
) {
663 case DHCP_CLIENT_ID_DUID
: {
664 /* If configured, apply user specified DUID and IAID */
665 const DUID
*duid
= link_get_duid(link
);
667 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
668 r
= sd_dhcp_client_set_iaid_duid_llt(link
->dhcp_client
,
669 link
->network
->iaid_set
,
673 r
= sd_dhcp_client_set_iaid_duid(link
->dhcp_client
,
674 link
->network
->iaid_set
,
677 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
680 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set IAID+DUID: %m");
683 case DHCP_CLIENT_ID_DUID_ONLY
: {
684 /* If configured, apply user specified DUID */
685 const DUID
*duid
= link_get_duid(link
);
687 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
688 r
= sd_dhcp_client_set_duid_llt(link
->dhcp_client
,
691 r
= sd_dhcp_client_set_duid(link
->dhcp_client
,
693 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
696 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set DUID: %m");
699 case DHCP_CLIENT_ID_MAC
:
700 r
= sd_dhcp_client_set_client_id(link
->dhcp_client
,
702 (const uint8_t *) &link
->mac
,
705 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set client ID: %m");
708 assert_not_reached("Unknown client identifier type.");
714 int dhcp4_configure(Link
*link
) {
718 assert(link
->network
);
719 assert(link
->network
->dhcp
& ADDRESS_FAMILY_IPV4
);
721 if (!link
->dhcp_client
) {
722 r
= sd_dhcp_client_new(&link
->dhcp_client
, link
->network
->dhcp_anonymize
);
726 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to create DHCP4 client: %m");
729 r
= sd_dhcp_client_attach_event(link
->dhcp_client
, NULL
, 0);
731 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to attach event: %m");
733 r
= sd_dhcp_client_set_mac(link
->dhcp_client
,
734 (const uint8_t *) &link
->mac
,
735 sizeof (link
->mac
), ARPHRD_ETHER
);
737 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MAC address: %m");
739 r
= sd_dhcp_client_set_ifindex(link
->dhcp_client
, link
->ifindex
);
741 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set ifindex: %m");
743 r
= sd_dhcp_client_set_callback(link
->dhcp_client
, dhcp4_handler
, link
);
745 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set callback: %m");
747 r
= sd_dhcp_client_set_request_broadcast(link
->dhcp_client
,
748 link
->network
->dhcp_broadcast
);
750 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for broadcast: %m");
753 r
= sd_dhcp_client_set_mtu(link
->dhcp_client
, link
->mtu
);
755 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MTU: %m");
758 if (link
->network
->dhcp_use_mtu
) {
759 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
760 SD_DHCP_OPTION_INTERFACE_MTU
);
762 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for MTU: %m");
765 /* NOTE: even if this variable is called "use", it also "sends" PRL
766 * options, maybe there should be a different configuration variable
767 * to send or not route options?. */
768 /* NOTE: when using Anonymize=yes, routes PRL options are sent
769 * by default, so they don't need to be added here. */
770 if (link
->network
->dhcp_use_routes
&& !link
->network
->dhcp_anonymize
) {
771 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
772 SD_DHCP_OPTION_STATIC_ROUTE
);
774 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for static route: %m");
776 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
777 SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
);
779 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for classless static route: %m");
782 if (link
->network
->dhcp_use_ntp
) {
783 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_NTP_SERVER
);
785 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for NTP server: %m");
788 if (link
->network
->dhcp_use_timezone
) {
789 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_NEW_TZDB_TIMEZONE
);
791 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for timezone: %m");
794 r
= dhcp4_set_hostname(link
);
798 if (link
->network
->dhcp_vendor_class_identifier
) {
799 r
= sd_dhcp_client_set_vendor_class_identifier(link
->dhcp_client
,
800 link
->network
->dhcp_vendor_class_identifier
);
802 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set vendor class identifier: %m");
805 if (link
->network
->dhcp_user_class
) {
806 r
= sd_dhcp_client_set_user_class(link
->dhcp_client
, (const char **) link
->network
->dhcp_user_class
);
808 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set user class: %m");
811 if (link
->network
->dhcp_client_port
) {
812 r
= sd_dhcp_client_set_client_port(link
->dhcp_client
, link
->network
->dhcp_client_port
);
814 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set listen port: %m");
817 return dhcp4_set_client_identifier(link
);