1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include <netinet/in.h>
4 #include <netinet/ip.h>
6 #include <linux/if_arp.h>
9 #include "alloc-util.h"
10 #include "dhcp-client-internal.h"
11 #include "hostname-util.h"
12 #include "parse-util.h"
13 #include "network-internal.h"
14 #include "networkd-dhcp4.h"
15 #include "networkd-link.h"
16 #include "networkd-manager.h"
17 #include "networkd-network.h"
18 #include "string-table.h"
19 #include "string-util.h"
20 #include "sysctl-util.h"
23 static int dhcp4_update_address(Link
*link
, bool announce
);
24 static int dhcp4_remove_all(Link
*link
);
25 static int dhcp4_release_old_lease(Link
*link
, bool force
);
27 static int dhcp4_address_callback(Address
*address
) {
29 assert(address
->link
);
31 /* Do not call this callback again. */
32 address
->callback
= NULL
;
34 return dhcp4_release_old_lease(address
->link
, true);
37 static int dhcp4_release_old_lease(Link
*link
, bool force
) {
44 if (!link
->dhcp_address_old
&& set_isempty(link
->dhcp_routes_old
))
47 if (!force
&& (link
->dhcp_address
&& !address_is_ready(link
->dhcp_address
))) {
48 log_link_debug(link
, "New DHCPv4 address is not ready. The old lease will be removed later.");
49 link
->dhcp_address
->callback
= dhcp4_address_callback
;
53 log_link_debug(link
, "Removing old DHCPv4 address and routes.");
57 SET_FOREACH(route
, link
->dhcp_routes_old
, i
) {
58 k
= route_remove(route
, link
, NULL
);
63 if (link
->dhcp_address_old
) {
64 k
= address_remove(link
->dhcp_address_old
, link
, NULL
);
72 static void dhcp4_check_ready(Link
*link
) {
75 if (link
->network
->dhcp_send_decline
&& !link
->dhcp4_address_bind
)
78 if (link
->dhcp4_messages
> 0)
81 link
->dhcp4_configured
= true;
83 /* New address and routes are configured now. Let's release old lease. */
84 r
= dhcp4_release_old_lease(link
, false);
86 link_enter_failed(link
);
90 link_check_ready(link
);
93 static int dhcp4_route_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
97 assert(link
->dhcp4_messages
> 0);
99 link
->dhcp4_messages
--;
101 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
104 r
= sd_netlink_message_get_errno(m
);
105 if (r
== -ENETUNREACH
&& !link
->dhcp4_route_retrying
) {
107 /* It seems kernel does not support that the prefix route cannot be configured with
108 * route table. Let's once drop the config and reconfigure them later. */
110 log_link_message_debug_errno(link
, m
, r
, "Could not set DHCPv4 route, retrying later");
111 link
->dhcp4_route_failed
= true;
112 link
->manager
->dhcp4_prefix_root_cannot_set_table
= true;
113 } else if (r
< 0 && r
!= -EEXIST
) {
114 log_link_message_warning_errno(link
, m
, r
, "Could not set DHCPv4 route");
115 link_enter_failed(link
);
119 if (link
->dhcp4_messages
== 0 && link
->dhcp4_route_failed
) {
120 link
->dhcp4_route_failed
= false;
121 link
->dhcp4_route_retrying
= true;
123 r
= dhcp4_remove_all(link
);
125 link_enter_failed(link
);
129 dhcp4_check_ready(link
);
134 static int route_scope_from_address(const Route
*route
, const struct in_addr
*self_addr
) {
138 if (in4_addr_is_localhost(&route
->dst
.in
) ||
139 (!in4_addr_is_null(self_addr
) && in4_addr_equal(&route
->dst
.in
, self_addr
)))
140 return RT_SCOPE_HOST
;
141 else if (in4_addr_is_null(&route
->gw
.in
))
142 return RT_SCOPE_LINK
;
144 return RT_SCOPE_UNIVERSE
;
147 static bool link_prefixroute(Link
*link
) {
148 return !link
->network
->dhcp_route_table_set
||
149 link
->network
->dhcp_route_table
== RT_TABLE_MAIN
||
150 link
->manager
->dhcp4_prefix_root_cannot_set_table
;
153 static int dhcp_route_configure(Route
*route
, Link
*link
) {
160 r
= route_configure(route
, link
, dhcp4_route_handler
, &ret
);
162 return log_link_error_errno(link
, r
, "Failed to set DHCPv4 route: %m");
164 link
->dhcp4_messages
++;
166 r
= set_ensure_put(&link
->dhcp_routes
, &route_hash_ops
, ret
);
168 return log_link_error_errno(link
, r
, "Failed to store DHCPv4 route: %m");
170 (void) set_remove(link
->dhcp_routes_old
, ret
);
175 static int link_set_dns_routes(Link
*link
, const struct in_addr
*address
) {
176 const struct in_addr
*dns
;
181 assert(link
->dhcp_lease
);
182 assert(link
->network
);
184 if (!link
->network
->dhcp_use_dns
||
185 !link
->network
->dhcp_routes_to_dns
)
188 n
= sd_dhcp_lease_get_dns(link
->dhcp_lease
, &dns
);
189 if (IN_SET(n
, 0, -ENODATA
))
192 return log_link_warning_errno(link
, n
, "DHCP error: could not get DNS servers: %m");
194 table
= link_get_dhcp_route_table(link
);
196 for (i
= 0; i
< n
; i
++) {
197 _cleanup_(route_freep
) Route
*route
= NULL
;
199 r
= route_new(&route
);
201 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
203 /* Set routes to DNS servers. */
205 route
->family
= AF_INET
;
206 route
->dst
.in
= dns
[i
];
207 route
->dst_prefixlen
= 32;
208 route
->prefsrc
.in
= *address
;
209 route
->scope
= RT_SCOPE_LINK
;
210 route
->protocol
= RTPROT_DHCP
;
211 route
->priority
= link
->network
->dhcp_route_metric
;
212 route
->table
= table
;
214 r
= dhcp_route_configure(route
, link
);
216 return log_link_error_errno(link
, r
, "Could not set route to DNS server: %m");
222 static int dhcp_prefix_route_from_lease(
223 const sd_dhcp_lease
*lease
,
225 const struct in_addr
*address
,
229 struct in_addr netmask
;
232 r
= sd_dhcp_lease_get_netmask((sd_dhcp_lease
*) lease
, &netmask
);
236 r
= route_new(&route
);
240 route
->family
= AF_INET
;
241 route
->dst
.in
.s_addr
= address
->s_addr
& netmask
.s_addr
;
242 route
->dst_prefixlen
= in4_addr_netmask_to_prefixlen(&netmask
);
243 route
->prefsrc
.in
= *address
;
244 route
->scope
= RT_SCOPE_LINK
;
245 route
->protocol
= RTPROT_DHCP
;
246 route
->table
= table
;
251 static int link_set_dhcp_routes(Link
*link
) {
252 _cleanup_free_ sd_dhcp_route
**static_routes
= NULL
;
253 bool classless_route
= false, static_route
= false;
254 const struct in_addr
*router
;
255 struct in_addr address
;
262 if (!link
->dhcp_lease
) /* link went down while we configured the IP addresses? */
265 if (!link
->network
) /* link went down while we configured the IP addresses? */
268 if (!link_has_carrier(link
) && !link
->network
->configure_without_carrier
)
269 /* During configuring addresses, the link lost its carrier. As networkd is dropping
270 * the addresses now, let's not configure the routes either. */
273 while ((rt
= set_steal_first(link
->dhcp_routes
))) {
274 r
= set_ensure_put(&link
->dhcp_routes_old
, &route_hash_ops
, rt
);
276 return log_link_error_errno(link
, r
, "Failed to store old DHCPv4 route: %m");
279 table
= link_get_dhcp_route_table(link
);
281 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &address
);
283 return log_link_warning_errno(link
, r
, "DHCP error: could not get address: %m");
285 if (!link_prefixroute(link
)) {
286 _cleanup_(route_freep
) Route
*prefix_route
= NULL
;
288 r
= dhcp_prefix_route_from_lease(link
->dhcp_lease
, table
, &address
, &prefix_route
);
290 return log_link_error_errno(link
, r
, "Could not create prefix route: %m");
292 r
= dhcp_route_configure(prefix_route
, link
);
294 return log_link_error_errno(link
, r
, "Could not set prefix route: %m");
297 n
= sd_dhcp_lease_get_routes(link
->dhcp_lease
, &static_routes
);
299 log_link_debug_errno(link
, n
, "DHCP: No routes received from DHCP server: %m");
301 log_link_debug_errno(link
, n
, "DHCP: could not get routes: %m");
303 for (i
= 0; i
< n
; i
++) {
304 switch (sd_dhcp_route_get_option(static_routes
[i
])) {
305 case SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
:
306 classless_route
= true;
308 case SD_DHCP_OPTION_STATIC_ROUTE
:
314 if (link
->network
->dhcp_use_routes
) {
315 for (i
= 0; i
< n
; i
++) {
316 _cleanup_(route_freep
) Route
*route
= NULL
;
318 /* if the DHCP server returns both a Classless Static Routes option and a Static Routes option,
319 the DHCP client MUST ignore the Static Routes option. */
320 if (classless_route
&&
321 sd_dhcp_route_get_option(static_routes
[i
]) != SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
)
324 r
= route_new(&route
);
326 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
328 route
->family
= AF_INET
;
329 route
->protocol
= RTPROT_DHCP
;
330 assert_se(sd_dhcp_route_get_gateway(static_routes
[i
], &route
->gw
.in
) >= 0);
331 assert_se(sd_dhcp_route_get_destination(static_routes
[i
], &route
->dst
.in
) >= 0);
332 assert_se(sd_dhcp_route_get_destination_prefix_length(static_routes
[i
], &route
->dst_prefixlen
) >= 0);
333 route
->priority
= link
->network
->dhcp_route_metric
;
334 route
->table
= table
;
335 route
->mtu
= link
->network
->dhcp_route_mtu
;
336 route
->scope
= route_scope_from_address(route
, &address
);
337 if (IN_SET(route
->scope
, RT_SCOPE_LINK
, RT_SCOPE_UNIVERSE
))
338 route
->prefsrc
.in
= address
;
340 if (set_contains(link
->dhcp_routes
, route
))
343 r
= dhcp_route_configure(route
, link
);
345 return log_link_error_errno(link
, r
, "Could not set route: %m");
349 if (link
->network
->dhcp_use_gateway
) {
350 r
= sd_dhcp_lease_get_router(link
->dhcp_lease
, &router
);
351 if (IN_SET(r
, 0, -ENODATA
))
352 log_link_info(link
, "DHCP: No gateway received from DHCP server.");
354 log_link_warning_errno(link
, r
, "DHCP error: could not get gateway: %m");
355 else if (in4_addr_is_null(&router
[0]))
356 log_link_info(link
, "DHCP: Received gateway is null.");
358 /* According to RFC 3442: If the DHCP server returns both a Classless Static Routes option and
359 a Router option, the DHCP client MUST ignore the Router option. */
360 if (classless_route
&& static_route
)
361 log_link_warning(link
, "Classless static routes received from DHCP server: ignoring static-route option and router option");
363 if (r
> 0 && !classless_route
&& !in4_addr_is_null(&router
[0])) {
364 _cleanup_(route_freep
) Route
*route
= NULL
, *route_gw
= NULL
;
366 r
= route_new(&route_gw
);
368 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
370 /* The dhcp netmask may mask out the gateway. Add an explicit
371 * route for the gw host so that we can route no matter the
372 * netmask or existing kernel route tables. */
373 route_gw
->family
= AF_INET
;
374 route_gw
->dst
.in
= router
[0];
375 route_gw
->dst_prefixlen
= 32;
376 route_gw
->prefsrc
.in
= address
;
377 route_gw
->scope
= RT_SCOPE_LINK
;
378 route_gw
->protocol
= RTPROT_DHCP
;
379 route_gw
->priority
= link
->network
->dhcp_route_metric
;
380 route_gw
->table
= table
;
381 route_gw
->mtu
= link
->network
->dhcp_route_mtu
;
383 r
= dhcp_route_configure(route_gw
, link
);
385 return log_link_error_errno(link
, r
, "Could not set host route: %m");
387 r
= route_new(&route
);
389 return log_link_error_errno(link
, r
, "Could not allocate route: %m");
391 route
->family
= AF_INET
;
392 route
->gw
.in
= router
[0];
393 route
->prefsrc
.in
= address
;
394 route
->protocol
= RTPROT_DHCP
;
395 route
->priority
= link
->network
->dhcp_route_metric
;
396 route
->table
= table
;
397 route
->mtu
= link
->network
->dhcp_route_mtu
;
399 r
= dhcp_route_configure(route
, link
);
401 return log_link_error_errno(link
, r
, "Could not set router: %m");
404 LIST_FOREACH(routes
, rt
, link
->network
->static_routes
) {
405 if (!rt
->gateway_from_dhcp
)
408 if (rt
->family
!= AF_INET
)
411 rt
->gw
.in
= router
[0];
413 r
= dhcp_route_configure(rt
, link
);
415 return log_link_error_errno(link
, r
, "Could not set gateway: %m");
419 return link_set_dns_routes(link
, &address
);
422 static int dhcp_reset_mtu(Link
*link
) {
428 if (!link
->network
->dhcp_use_mtu
)
431 r
= sd_dhcp_lease_get_mtu(link
->dhcp_lease
, &mtu
);
435 if (link
->original_mtu
== mtu
)
438 r
= link_set_mtu(link
, link
->original_mtu
);
440 log_link_error_errno(link
, r
, "DHCP error: could not reset MTU: %m");
441 link_enter_failed(link
);
448 static int dhcp_reset_hostname(Link
*link
) {
449 const char *hostname
;
454 if (!link
->network
->dhcp_use_hostname
)
457 hostname
= link
->network
->dhcp_hostname
;
459 (void) sd_dhcp_lease_get_hostname(link
->dhcp_lease
, &hostname
);
464 /* If a hostname was set due to the lease, then unset it now. */
465 r
= manager_set_hostname(link
->manager
, NULL
);
467 return log_link_error_errno(link
, r
, "DHCP error: Failed to reset transient hostname: %m");
472 static int dhcp4_remove_route_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
477 assert(link
->dhcp4_remove_messages
> 0);
479 link
->dhcp4_remove_messages
--;
481 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
484 r
= sd_netlink_message_get_errno(m
);
485 if (r
< 0 && r
!= -ESRCH
)
486 log_link_message_warning_errno(link
, m
, r
, "Failed to remove DHCPv4 route, ignoring");
488 if (link
->dhcp4_remove_messages
== 0) {
489 r
= dhcp4_update_address(link
, false);
491 link_enter_failed(link
);
497 static int dhcp4_remove_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
502 assert(link
->dhcp4_remove_messages
> 0);
504 link
->dhcp4_remove_messages
--;
506 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
509 r
= sd_netlink_message_get_errno(m
);
510 if (r
< 0 && r
!= -EADDRNOTAVAIL
)
511 log_link_message_warning_errno(link
, m
, r
, "Failed to remove DHCPv4 address, ignoring");
513 (void) manager_rtnl_process_address(rtnl
, m
, link
->manager
);
515 if (link
->dhcp4_remove_messages
== 0) {
516 r
= dhcp4_update_address(link
, false);
518 link_enter_failed(link
);
524 static int dhcp4_remove_all(Link
*link
) {
531 SET_FOREACH(route
, link
->dhcp_routes
, i
) {
532 k
= route_remove(route
, link
, dhcp4_remove_route_handler
);
536 link
->dhcp4_remove_messages
++;
539 if (link
->dhcp_address
) {
540 k
= address_remove(link
->dhcp_address
, link
, dhcp4_remove_address_handler
);
544 link
->dhcp4_remove_messages
++;
550 static int dhcp_lease_lost(Link
*link
) {
554 assert(link
->dhcp_lease
);
556 log_link_info(link
, "DHCP lease lost");
558 link
->dhcp4_configured
= false;
560 /* dhcp_lease_lost() may be called during renewing IP address. */
561 k
= dhcp4_release_old_lease(link
, true);
565 k
= dhcp4_remove_all(link
);
569 k
= dhcp_reset_mtu(link
);
573 k
= dhcp_reset_hostname(link
);
577 link
->dhcp_lease
= sd_dhcp_lease_unref(link
->dhcp_lease
);
583 static void dhcp_address_on_acd(sd_ipv4acd
*acd
, int event
, void *userdata
) {
584 _cleanup_free_
char *pretty
= NULL
;
585 union in_addr_union address
= {};
595 case SD_IPV4ACD_EVENT_STOP
:
596 log_link_debug(link
, "Stopping ACD client for DHCP4...");
599 case SD_IPV4ACD_EVENT_BIND
:
601 (void) sd_dhcp_lease_get_address(link
->dhcp_lease
, &address
.in
);
602 (void) in_addr_to_string(AF_INET
, &address
, &pretty
);
603 log_link_debug(link
, "Successfully claimed DHCP4 address %s", strna(pretty
));
605 link
->dhcp4_address_bind
= true;
606 dhcp4_check_ready(link
);
609 case SD_IPV4ACD_EVENT_CONFLICT
:
610 (void) sd_dhcp_lease_get_address(link
->dhcp_lease
, &address
.in
);
611 (void) in_addr_to_string(AF_INET
, &address
, &pretty
);
612 log_link_warning(link
, "DAD conflict. Dropping DHCP4 address %s", strna(pretty
));
614 r
= sd_dhcp_client_send_decline(link
->dhcp_client
);
616 log_link_warning_errno(link
, r
, "Failed to send DHCP DECLINE, ignoring: %m");
618 if (link
->dhcp_lease
) {
619 r
= dhcp_lease_lost(link
);
621 link_enter_failed(link
);
626 assert_not_reached("Invalid IPv4ACD event.");
629 sd_ipv4acd_stop(acd
);
634 static int configure_dhcpv4_duplicate_address_detection(Link
*link
) {
639 r
= sd_ipv4acd_new(&link
->network
->dhcp_acd
);
643 r
= sd_ipv4acd_attach_event(link
->network
->dhcp_acd
, NULL
, 0);
647 r
= sd_ipv4acd_set_ifindex(link
->network
->dhcp_acd
, link
->ifindex
);
651 r
= sd_ipv4acd_set_mac(link
->network
->dhcp_acd
, &link
->mac
);
658 static int dhcp4_start_acd(Link
*link
) {
659 union in_addr_union addr
;
662 if (!link
->network
->dhcp_send_decline
)
665 if (!link
->dhcp_lease
)
668 link
->dhcp4_address_bind
= false;
670 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &addr
.in
);
674 r
= sd_ipv4acd_set_address(link
->network
->dhcp_acd
, &addr
.in
);
678 r
= sd_ipv4acd_set_callback(link
->network
->dhcp_acd
, dhcp_address_on_acd
, link
);
683 _cleanup_free_
char *pretty
= NULL
;
685 (void) in_addr_to_string(AF_INET
, &addr
, &pretty
);
686 log_link_debug(link
, "Starting IPv4ACD client. Probing DHCPv4 address %s", strna(pretty
));
689 r
= sd_ipv4acd_start(link
->network
->dhcp_acd
, true);
696 static int dhcp4_address_handler(sd_netlink
*rtnl
, sd_netlink_message
*m
, Link
*link
) {
701 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
704 r
= sd_netlink_message_get_errno(m
);
705 if (r
< 0 && r
!= -EEXIST
) {
706 log_link_message_warning_errno(link
, m
, r
, "Could not set DHCPv4 address");
707 link_enter_failed(link
);
710 (void) manager_rtnl_process_address(rtnl
, m
, link
->manager
);
712 r
= link_set_dhcp_routes(link
);
714 link_enter_failed(link
);
718 /* Add back static routes since kernel removes while DHCPv4 address is removed from when lease expires */
719 r
= link_request_set_routes(link
);
721 link_enter_failed(link
);
725 r
= dhcp4_start_acd(link
);
727 log_link_error_errno(link
, r
, "Failed to start IPv4ACD for DHCP4 adddress: %m");
728 link_enter_failed(link
);
732 dhcp4_check_ready(link
);
737 static int dhcp4_update_address(Link
*link
, bool announce
) {
738 _cleanup_(address_freep
) Address
*addr
= NULL
;
739 uint32_t lifetime
= CACHE_INFO_INFINITY_LIFE_TIME
;
740 struct in_addr address
, netmask
;
746 assert(link
->network
);
748 if (!link
->dhcp_lease
)
751 link_set_state(link
, LINK_STATE_CONFIGURING
);
752 link
->dhcp4_configured
= false;
754 /* address_handler calls link_request_set_routes() and link_request_set_nexthop(). Before they
755 * are called, the related flags must be cleared. Otherwise, the link becomes configured state
756 * before routes are configured. */
757 link
->static_routes_configured
= false;
758 link
->static_nexthops_configured
= false;
760 r
= sd_dhcp_lease_get_address(link
->dhcp_lease
, &address
);
762 return log_link_warning_errno(link
, r
, "DHCP error: no address: %m");
764 r
= sd_dhcp_lease_get_netmask(link
->dhcp_lease
, &netmask
);
766 return log_link_warning_errno(link
, r
, "DHCP error: no netmask: %m");
768 if (!FLAGS_SET(link
->network
->keep_configuration
, KEEP_CONFIGURATION_DHCP
)) {
769 r
= sd_dhcp_lease_get_lifetime(link
->dhcp_lease
, &lifetime
);
771 return log_link_warning_errno(link
, r
, "DHCP error: no lifetime: %m");
774 prefixlen
= in4_addr_netmask_to_prefixlen(&netmask
);
777 const struct in_addr
*router
;
779 r
= sd_dhcp_lease_get_router(link
->dhcp_lease
, &router
);
780 if (r
< 0 && r
!= -ENODATA
)
781 return log_link_error_errno(link
, r
, "DHCP error: Could not get gateway: %m");
783 if (r
> 0 && !in4_addr_is_null(&router
[0]))
785 LOG_LINK_INTERFACE(link
),
786 LOG_LINK_MESSAGE(link
, "DHCPv4 address %u.%u.%u.%u/%u via %u.%u.%u.%u",
787 ADDRESS_FMT_VAL(address
),
789 ADDRESS_FMT_VAL(router
[0])),
790 "ADDRESS=%u.%u.%u.%u", ADDRESS_FMT_VAL(address
),
791 "PREFIXLEN=%u", prefixlen
,
792 "GATEWAY=%u.%u.%u.%u", ADDRESS_FMT_VAL(router
[0]));
795 LOG_LINK_INTERFACE(link
),
796 LOG_LINK_MESSAGE(link
, "DHCPv4 address %u.%u.%u.%u/%u",
797 ADDRESS_FMT_VAL(address
),
799 "ADDRESS=%u.%u.%u.%u", ADDRESS_FMT_VAL(address
),
800 "PREFIXLEN=%u", prefixlen
);
803 r
= address_new(&addr
);
807 addr
->family
= AF_INET
;
808 addr
->in_addr
.in
.s_addr
= address
.s_addr
;
809 addr
->cinfo
.ifa_prefered
= lifetime
;
810 addr
->cinfo
.ifa_valid
= lifetime
;
811 addr
->prefixlen
= prefixlen
;
812 addr
->broadcast
.s_addr
= address
.s_addr
| ~netmask
.s_addr
;
813 addr
->prefix_route
= link_prefixroute(link
);
815 /* allow reusing an existing address and simply update its lifetime
816 * in case it already exists */
817 r
= address_configure(addr
, link
, dhcp4_address_handler
, true, &ret
);
819 return log_link_error_errno(link
, r
, "Failed to set DHCPv4 address: %m");
821 if (!address_equal(link
->dhcp_address
, ret
))
822 link
->dhcp_address_old
= link
->dhcp_address
;
823 link
->dhcp_address
= ret
;
828 static int dhcp_lease_renew(sd_dhcp_client
*client
, Link
*link
) {
829 sd_dhcp_lease
*lease
;
835 r
= sd_dhcp_client_get_lease(client
, &lease
);
837 return log_link_warning_errno(link
, r
, "DHCP error: no lease: %m");
839 sd_dhcp_lease_unref(link
->dhcp_lease
);
840 link
->dhcp_lease
= sd_dhcp_lease_ref(lease
);
843 return dhcp4_update_address(link
, false);
846 static int dhcp_lease_acquired(sd_dhcp_client
*client
, Link
*link
) {
847 sd_dhcp_lease
*lease
;
853 r
= sd_dhcp_client_get_lease(client
, &lease
);
855 return log_link_error_errno(link
, r
, "DHCP error: No lease: %m");
857 sd_dhcp_lease_unref(link
->dhcp_lease
);
858 link
->dhcp_lease
= sd_dhcp_lease_ref(lease
);
861 if (link
->network
->dhcp_use_mtu
) {
864 r
= sd_dhcp_lease_get_mtu(lease
, &mtu
);
866 r
= link_set_mtu(link
, mtu
);
868 log_link_error_errno(link
, r
, "Failed to set MTU to %" PRIu16
": %m", mtu
);
872 if (link
->network
->dhcp_use_hostname
) {
873 const char *dhcpname
= NULL
;
874 _cleanup_free_
char *hostname
= NULL
;
876 if (link
->network
->dhcp_hostname
)
877 dhcpname
= link
->network
->dhcp_hostname
;
879 (void) sd_dhcp_lease_get_hostname(lease
, &dhcpname
);
882 r
= shorten_overlong(dhcpname
, &hostname
);
884 log_link_warning_errno(link
, r
, "Unable to shorten overlong DHCP hostname '%s', ignoring: %m", dhcpname
);
886 log_link_notice(link
, "Overlong DHCP hostname received, shortened from '%s' to '%s'", dhcpname
, hostname
);
890 r
= manager_set_hostname(link
->manager
, hostname
);
892 log_link_error_errno(link
, r
, "Failed to set transient hostname to '%s': %m", hostname
);
896 if (link
->network
->dhcp_use_timezone
) {
897 const char *tz
= NULL
;
899 (void) sd_dhcp_lease_get_timezone(link
->dhcp_lease
, &tz
);
902 r
= manager_set_timezone(link
->manager
, tz
);
904 log_link_error_errno(link
, r
, "Failed to set timezone to '%s': %m", tz
);
908 if (link
->dhcp4_remove_messages
== 0) {
909 r
= dhcp4_update_address(link
, true);
914 "The link has previously assigned DHCPv4 address or routes. "
915 "The newly assigned address and routes will set up after old ones are removed.");
920 static int dhcp_lease_ip_change(sd_dhcp_client
*client
, Link
*link
) {
923 r
= dhcp_lease_acquired(client
, link
);
925 (void) dhcp_lease_lost(link
);
930 static int dhcp_server_is_deny_listed(Link
*link
, sd_dhcp_client
*client
) {
931 sd_dhcp_lease
*lease
;
936 assert(link
->network
);
939 r
= sd_dhcp_client_get_lease(client
, &lease
);
941 return log_link_error_errno(link
, r
, "Failed to get DHCP lease: %m");
943 r
= sd_dhcp_lease_get_server_identifier(lease
, &addr
);
945 return log_link_debug_errno(link
, r
, "Failed to get DHCP server IP address: %m");
947 if (set_contains(link
->network
->dhcp_deny_listed_ip
, UINT32_TO_PTR(addr
.s_addr
))) {
948 log_struct(LOG_DEBUG
,
949 LOG_LINK_INTERFACE(link
),
950 LOG_LINK_MESSAGE(link
, "DHCPv4 IP '%u.%u.%u.%u' found in deny-listed IP addresses, ignoring offer",
951 ADDRESS_FMT_VAL(addr
)));
958 static int dhcp_server_is_allow_listed(Link
*link
, sd_dhcp_client
*client
) {
959 sd_dhcp_lease
*lease
;
964 assert(link
->network
);
967 r
= sd_dhcp_client_get_lease(client
, &lease
);
969 return log_link_error_errno(link
, r
, "Failed to get DHCP lease: %m");
971 r
= sd_dhcp_lease_get_server_identifier(lease
, &addr
);
973 return log_link_debug_errno(link
, r
, "Failed to get DHCP server IP address: %m");
975 if (set_contains(link
->network
->dhcp_allow_listed_ip
, UINT32_TO_PTR(addr
.s_addr
))) {
976 log_struct(LOG_DEBUG
,
977 LOG_LINK_INTERFACE(link
),
978 LOG_LINK_MESSAGE(link
, "DHCPv4 IP '%u.%u.%u.%u' found in allow-listed IP addresses, accepting offer",
979 ADDRESS_FMT_VAL(addr
)));
986 static int dhcp4_handler(sd_dhcp_client
*client
, int event
, void *userdata
) {
987 Link
*link
= userdata
;
991 assert(link
->network
);
992 assert(link
->manager
);
994 if (IN_SET(link
->state
, LINK_STATE_FAILED
, LINK_STATE_LINGER
))
998 case SD_DHCP_CLIENT_EVENT_STOP
:
1000 if (link_ipv4ll_enabled(link
, ADDRESS_FAMILY_FALLBACK_IPV4
)) {
1001 assert(link
->ipv4ll
);
1003 log_link_debug(link
, "DHCP client is stopped. Acquiring IPv4 link-local address");
1005 r
= sd_ipv4ll_start(link
->ipv4ll
);
1007 return log_link_warning_errno(link
, r
, "Could not acquire IPv4 link-local address: %m");
1010 if (FLAGS_SET(link
->network
->keep_configuration
, KEEP_CONFIGURATION_DHCP
)) {
1011 log_link_notice(link
, "DHCPv4 connection considered critical, ignoring request to reconfigure it.");
1015 if (link
->dhcp_lease
) {
1016 if (link
->network
->dhcp_send_release
) {
1017 r
= sd_dhcp_client_send_release(client
);
1019 log_link_warning_errno(link
, r
, "Failed to send DHCP RELEASE, ignoring: %m");
1022 r
= dhcp_lease_lost(link
);
1024 link_enter_failed(link
);
1030 case SD_DHCP_CLIENT_EVENT_EXPIRED
:
1031 if (FLAGS_SET(link
->network
->keep_configuration
, KEEP_CONFIGURATION_DHCP
)) {
1032 log_link_notice(link
, "DHCPv4 connection considered critical, ignoring request to reconfigure it.");
1036 if (link
->dhcp_lease
) {
1037 r
= dhcp_lease_lost(link
);
1039 link_enter_failed(link
);
1045 case SD_DHCP_CLIENT_EVENT_IP_CHANGE
:
1046 if (FLAGS_SET(link
->network
->keep_configuration
, KEEP_CONFIGURATION_DHCP
)) {
1047 log_link_notice(link
, "DHCPv4 connection considered critical, ignoring request to reconfigure it.");
1051 r
= dhcp_lease_ip_change(client
, link
);
1053 link_enter_failed(link
);
1058 case SD_DHCP_CLIENT_EVENT_RENEW
:
1059 r
= dhcp_lease_renew(client
, link
);
1061 link_enter_failed(link
);
1065 case SD_DHCP_CLIENT_EVENT_IP_ACQUIRE
:
1066 r
= dhcp_lease_acquired(client
, link
);
1068 link_enter_failed(link
);
1072 case SD_DHCP_CLIENT_EVENT_SELECTING
:
1073 if (!set_isempty(link
->network
->dhcp_allow_listed_ip
)) {
1074 r
= dhcp_server_is_allow_listed(link
, client
);
1080 r
= dhcp_server_is_deny_listed(link
, client
);
1089 log_link_warning_errno(link
, event
, "DHCP error: Client failed: %m");
1091 log_link_warning(link
, "DHCP unknown event: %i", event
);
1098 static int dhcp4_set_hostname(Link
*link
) {
1099 _cleanup_free_
char *hostname
= NULL
;
1105 if (!link
->network
->dhcp_send_hostname
)
1107 else if (link
->network
->dhcp_hostname
)
1108 hn
= link
->network
->dhcp_hostname
;
1110 r
= gethostname_strict(&hostname
);
1111 if (r
< 0 && r
!= -ENXIO
) /* ENXIO: no hostname set or hostname is "localhost" */
1117 r
= sd_dhcp_client_set_hostname(link
->dhcp_client
, hn
);
1118 if (r
== -EINVAL
&& hostname
)
1119 /* Ignore error when the machine's hostname is not suitable to send in DHCP packet. */
1120 log_link_warning_errno(link
, r
, "DHCP4 CLIENT: Failed to set hostname from kernel hostname, ignoring: %m");
1122 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set hostname: %m");
1127 static bool promote_secondaries_enabled(const char *ifname
) {
1128 _cleanup_free_
char *promote_secondaries_sysctl
= NULL
;
1129 char *promote_secondaries_path
;
1132 promote_secondaries_path
= strjoina("net/ipv4/conf/", ifname
, "/promote_secondaries");
1133 r
= sysctl_read(promote_secondaries_path
, &promote_secondaries_sysctl
);
1135 log_debug_errno(r
, "Cannot read sysctl %s", promote_secondaries_path
);
1139 truncate_nl(promote_secondaries_sysctl
);
1140 r
= parse_boolean(promote_secondaries_sysctl
);
1142 log_warning_errno(r
, "Cannot parse sysctl %s with content %s as boolean", promote_secondaries_path
, promote_secondaries_sysctl
);
1146 /* dhcp4_set_promote_secondaries will ensure this interface has
1147 * the "promote_secondaries" option in the kernel set. If this sysctl
1148 * is not set DHCP will work only as long as the IP address does not
1149 * changes between leases. The kernel will remove all secondary IP
1150 * addresses of an interface otherwise. The way systemd-network works
1151 * is that the new IP of a lease is added as a secondary IP and when
1152 * the primary one expires it relies on the kernel to promote the
1153 * secondary IP. See also https://github.com/systemd/systemd/issues/7163
1155 int dhcp4_set_promote_secondaries(Link
*link
) {
1159 assert(link
->network
);
1160 assert(link
->network
->dhcp
& ADDRESS_FAMILY_IPV4
);
1162 /* check if the kernel has promote_secondaries enabled for our
1163 * interface. If it is not globally enabled or enabled for the
1164 * specific interface we must either enable it.
1166 if (!(promote_secondaries_enabled("all") || promote_secondaries_enabled(link
->ifname
))) {
1167 char *promote_secondaries_path
= NULL
;
1169 log_link_debug(link
, "promote_secondaries is unset, setting it");
1170 promote_secondaries_path
= strjoina("net/ipv4/conf/", link
->ifname
, "/promote_secondaries");
1171 r
= sysctl_write(promote_secondaries_path
, "1");
1173 log_link_warning_errno(link
, r
, "cannot set sysctl %s to 1", promote_secondaries_path
);
1180 int dhcp4_set_client_identifier(Link
*link
) {
1184 assert(link
->network
);
1185 assert(link
->dhcp_client
);
1187 switch (link
->network
->dhcp_client_identifier
) {
1188 case DHCP_CLIENT_ID_DUID
: {
1189 /* If configured, apply user specified DUID and IAID */
1190 const DUID
*duid
= link_get_duid(link
);
1192 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
1193 r
= sd_dhcp_client_set_iaid_duid_llt(link
->dhcp_client
,
1194 link
->network
->iaid_set
,
1195 link
->network
->iaid
,
1198 r
= sd_dhcp_client_set_iaid_duid(link
->dhcp_client
,
1199 link
->network
->iaid_set
,
1200 link
->network
->iaid
,
1202 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
1203 duid
->raw_data_len
);
1205 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set IAID+DUID: %m");
1208 case DHCP_CLIENT_ID_DUID_ONLY
: {
1209 /* If configured, apply user specified DUID */
1210 const DUID
*duid
= link_get_duid(link
);
1212 if (duid
->type
== DUID_TYPE_LLT
&& duid
->raw_data_len
== 0)
1213 r
= sd_dhcp_client_set_duid_llt(link
->dhcp_client
,
1216 r
= sd_dhcp_client_set_duid(link
->dhcp_client
,
1218 duid
->raw_data_len
> 0 ? duid
->raw_data
: NULL
,
1219 duid
->raw_data_len
);
1221 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set DUID: %m");
1224 case DHCP_CLIENT_ID_MAC
:
1225 r
= sd_dhcp_client_set_client_id(link
->dhcp_client
,
1227 (const uint8_t *) &link
->mac
,
1230 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set client ID: %m");
1233 assert_not_reached("Unknown client identifier type.");
1239 int dhcp4_configure(Link
*link
) {
1240 sd_dhcp_option
*send_option
;
1241 void *request_options
;
1246 assert(link
->network
);
1247 assert(link
->network
->dhcp
& ADDRESS_FAMILY_IPV4
);
1249 if (!link
->dhcp_client
) {
1250 r
= sd_dhcp_client_new(&link
->dhcp_client
, link
->network
->dhcp_anonymize
);
1254 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to create DHCP4 client: %m");
1256 r
= sd_dhcp_client_attach_event(link
->dhcp_client
, NULL
, 0);
1258 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to attach event: %m");
1261 r
= sd_dhcp_client_set_mac(link
->dhcp_client
,
1262 (const uint8_t *) &link
->mac
,
1263 sizeof (link
->mac
), ARPHRD_ETHER
);
1265 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MAC address: %m");
1267 r
= sd_dhcp_client_set_ifindex(link
->dhcp_client
, link
->ifindex
);
1269 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set ifindex: %m");
1271 r
= sd_dhcp_client_set_callback(link
->dhcp_client
, dhcp4_handler
, link
);
1273 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set callback: %m");
1275 r
= sd_dhcp_client_set_request_broadcast(link
->dhcp_client
,
1276 link
->network
->dhcp_broadcast
);
1278 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for broadcast: %m");
1281 r
= sd_dhcp_client_set_mtu(link
->dhcp_client
, link
->mtu
);
1283 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MTU: %m");
1286 if (link
->network
->dhcp_use_mtu
) {
1287 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
1288 SD_DHCP_OPTION_INTERFACE_MTU
);
1290 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for MTU: %m");
1293 /* NOTE: even if this variable is called "use", it also "sends" PRL
1294 * options, maybe there should be a different configuration variable
1295 * to send or not route options?. */
1296 /* NOTE: when using Anonymize=yes, routes PRL options are sent
1297 * by default, so they don't need to be added here. */
1298 if (link
->network
->dhcp_use_routes
&& !link
->network
->dhcp_anonymize
) {
1299 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
1300 SD_DHCP_OPTION_STATIC_ROUTE
);
1302 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for static route: %m");
1304 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
,
1305 SD_DHCP_OPTION_CLASSLESS_STATIC_ROUTE
);
1307 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for classless static route: %m");
1310 if (link
->network
->dhcp_use_domains
!= DHCP_USE_DOMAINS_NO
&& !link
->network
->dhcp_anonymize
) {
1311 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_DOMAIN_SEARCH_LIST
);
1313 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for domain search list: %m");
1316 if (link
->network
->dhcp_use_ntp
) {
1317 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_NTP_SERVER
);
1319 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for NTP server: %m");
1322 if (link
->network
->dhcp_use_sip
) {
1323 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_SIP_SERVER
);
1325 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for SIP server: %m");
1328 if (link
->network
->dhcp_use_timezone
) {
1329 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, SD_DHCP_OPTION_NEW_TZDB_TIMEZONE
);
1331 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for timezone: %m");
1334 SET_FOREACH(request_options
, link
->network
->dhcp_request_options
, i
) {
1335 uint32_t option
= PTR_TO_UINT32(request_options
);
1337 r
= sd_dhcp_client_set_request_option(link
->dhcp_client
, option
);
1339 log_link_debug(link
, "DHCP4 CLIENT: Failed to set request flag for '%u' already exists, ignoring.", option
);
1343 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set request flag for '%u': %m", option
);
1346 ORDERED_HASHMAP_FOREACH(send_option
, link
->network
->dhcp_client_send_options
, i
) {
1347 r
= sd_dhcp_client_add_option(link
->dhcp_client
, send_option
);
1351 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set send option: %m");
1354 ORDERED_HASHMAP_FOREACH(send_option
, link
->network
->dhcp_client_send_vendor_options
, i
) {
1355 r
= sd_dhcp_client_add_vendor_option(link
->dhcp_client
, send_option
);
1359 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set send option: %m");
1362 r
= dhcp4_set_hostname(link
);
1366 if (link
->network
->dhcp_vendor_class_identifier
) {
1367 r
= sd_dhcp_client_set_vendor_class_identifier(link
->dhcp_client
,
1368 link
->network
->dhcp_vendor_class_identifier
);
1370 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set vendor class identifier: %m");
1373 if (link
->network
->dhcp_mudurl
) {
1374 r
= sd_dhcp_client_set_mud_url(link
->dhcp_client
,
1375 link
->network
->dhcp_mudurl
);
1377 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set MUD URL: %m");
1380 if (link
->network
->dhcp_user_class
) {
1381 r
= sd_dhcp_client_set_user_class(link
->dhcp_client
, (const char **) link
->network
->dhcp_user_class
);
1383 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set user class: %m");
1386 if (link
->network
->dhcp_client_port
) {
1387 r
= sd_dhcp_client_set_client_port(link
->dhcp_client
, link
->network
->dhcp_client_port
);
1389 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set listen port: %m");
1392 if (link
->network
->dhcp_max_attempts
> 0) {
1393 r
= sd_dhcp_client_set_max_attempts(link
->dhcp_client
, link
->network
->dhcp_max_attempts
);
1395 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set max attempts: %m");
1398 if (link
->network
->ip_service_type
> 0) {
1399 r
= sd_dhcp_client_set_service_type(link
->dhcp_client
, link
->network
->ip_service_type
);
1401 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to set IP service type: %m");
1404 if (link
->network
->dhcp_fallback_lease_lifetime
> 0) {
1405 r
= sd_dhcp_client_set_fallback_lease_lifetime(link
->dhcp_client
, link
->network
->dhcp_fallback_lease_lifetime
);
1407 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed set to lease lifetime: %m");
1410 if (link
->network
->dhcp_send_decline
) {
1411 r
= configure_dhcpv4_duplicate_address_detection(link
);
1413 return log_link_error_errno(link
, r
, "DHCP4 CLIENT: Failed to configure service type: %m");
1416 return dhcp4_set_client_identifier(link
);
1419 int config_parse_dhcp_max_attempts(
1421 const char *filename
,
1423 const char *section
,
1424 unsigned section_line
,
1431 Network
*network
= data
;
1439 if (isempty(rvalue
)) {
1440 network
->dhcp_max_attempts
= 0;
1444 if (streq(rvalue
, "infinity")) {
1445 network
->dhcp_max_attempts
= (uint64_t) -1;
1449 r
= safe_atou64(rvalue
, &a
);
1451 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1452 "Failed to parse DHCP maximum attempts, ignoring: %s", rvalue
);
1457 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1458 "%s= must be positive integer or 'infinity', ignoring: %s", lvalue
, rvalue
);
1462 network
->dhcp_max_attempts
= a
;
1467 int config_parse_dhcp_acl_ip_address(
1469 const char *filename
,
1471 const char *section
,
1472 unsigned section_line
,
1479 Network
*network
= data
;
1488 acl
= STR_IN_SET(lvalue
, "DenyList", "BlackList") ? &network
->dhcp_deny_listed_ip
: &network
->dhcp_allow_listed_ip
;
1490 if (isempty(rvalue
)) {
1491 *acl
= set_free(*acl
);
1495 for (const char *p
= rvalue
;;) {
1496 _cleanup_free_
char *n
= NULL
;
1497 union in_addr_union ip
;
1499 r
= extract_first_word(&p
, &n
, NULL
, 0);
1503 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1504 "Failed to parse DHCP '%s=' IP address, ignoring assignment: %s",
1511 r
= in_addr_from_string(AF_INET
, n
, &ip
);
1513 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1514 "DHCP '%s=' IP address is invalid, ignoring assignment: %s", lvalue
, n
);
1518 r
= set_ensure_put(acl
, NULL
, UINT32_TO_PTR(ip
.in
.s_addr
));
1520 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1521 "Failed to store DHCP '%s=' IP address '%s', ignoring assignment: %m", lvalue
, n
);
1525 int config_parse_dhcp_ip_service_type(
1527 const char *filename
,
1529 const char *section
,
1530 unsigned section_line
,
1541 if (streq(rvalue
, "CS4"))
1542 *((int *)data
) = IPTOS_CLASS_CS4
;
1543 else if (streq(rvalue
, "CS6"))
1544 *((int *)data
) = IPTOS_CLASS_CS6
;
1546 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1547 "Failed to parse IPServiceType type '%s', ignoring.", rvalue
);
1552 int config_parse_dhcp_mud_url(
1554 const char *filename
,
1556 const char *section
,
1557 unsigned section_line
,
1564 _cleanup_free_
char *unescaped
= NULL
;
1565 Network
*network
= data
;
1572 if (isempty(rvalue
)) {
1573 network
->dhcp_mudurl
= mfree(network
->dhcp_mudurl
);
1577 r
= cunescape(rvalue
, 0, &unescaped
);
1579 log_syntax(unit
, LOG_WARNING
, filename
, line
, r
,
1580 "Failed to Failed to unescape MUD URL, ignoring: %s", rvalue
);
1584 if (!http_url_is_valid(unescaped
) || strlen(unescaped
) > 255) {
1585 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1586 "Failed to parse MUD URL '%s', ignoring: %m", rvalue
);
1591 return free_and_strdup_warn(&network
->dhcp_mudurl
, unescaped
);
1594 int config_parse_dhcp_fallback_lease_lifetime(const char *unit
,
1595 const char *filename
,
1597 const char *section
,
1598 unsigned section_line
,
1604 Network
*network
= userdata
;
1613 if (isempty(rvalue
)) {
1614 network
->dhcp_fallback_lease_lifetime
= 0;
1618 /* We accept only "forever" or "infinity". */
1619 if (STR_IN_SET(rvalue
, "forever", "infinity"))
1620 k
= CACHE_INFO_INFINITY_LIFE_TIME
;
1622 log_syntax(unit
, LOG_WARNING
, filename
, line
, 0,
1623 "Invalid LeaseLifetime= value, ignoring: %s", rvalue
);
1627 network
->dhcp_fallback_lease_lifetime
= k
;
1632 static const char* const dhcp_client_identifier_table
[_DHCP_CLIENT_ID_MAX
] = {
1633 [DHCP_CLIENT_ID_MAC
] = "mac",
1634 [DHCP_CLIENT_ID_DUID
] = "duid",
1635 [DHCP_CLIENT_ID_DUID_ONLY
] = "duid-only",
1638 DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_client_identifier
, DHCPClientIdentifier
);
1639 DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier
, dhcp_client_identifier
, DHCPClientIdentifier
,
1640 "Failed to parse client identifier type");