1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include <sys/socket.h>
5 #include <linux/fib_rules.h>
9 #include "sd-netlink.h"
11 #include "alloc-util.h"
13 #include "conf-parser.h"
15 #include "device-util.h"
16 #include "dns-domain.h"
19 #include "local-addresses.h"
20 #include "netlink-util.h"
21 #include "networkd-manager.h"
22 #include "ordered-set.h"
23 #include "path-util.h"
28 /* use 8 MB for receive socket kernel queue. */
29 #define RCVBUF_SIZE (8*1024*1024)
31 const char* const network_dirs
[] = {
32 "/etc/systemd/network",
33 "/run/systemd/network",
34 "/usr/lib/systemd/network",
36 "/lib/systemd/network",
40 static int setup_default_address_pool(Manager
*m
) {
46 /* Add in the well-known private address ranges. */
48 r
= address_pool_new_from_string(m
, &p
, AF_INET6
, "fc00::", 7);
52 r
= address_pool_new_from_string(m
, &p
, AF_INET
, "192.168.0.0", 16);
56 r
= address_pool_new_from_string(m
, &p
, AF_INET
, "172.16.0.0", 12);
60 r
= address_pool_new_from_string(m
, &p
, AF_INET
, "10.0.0.0", 8);
67 static int manager_reset_all(Manager
*m
) {
74 HASHMAP_FOREACH(link
, m
->links
, i
) {
75 r
= link_carrier_reset(link
);
77 log_link_warning_errno(link
, r
, "Could not reset carrier: %m");
83 static int match_prepare_for_sleep(sd_bus_message
*message
, void *userdata
, sd_bus_error
*ret_error
) {
84 Manager
*m
= userdata
;
90 r
= sd_bus_message_read(message
, "b", &b
);
92 log_debug_errno(r
, "Failed to parse PrepareForSleep signal: %m");
99 log_debug("Coming back from suspend, resetting all connections...");
101 (void) manager_reset_all(m
);
106 static int on_connected(sd_bus_message
*message
, void *userdata
, sd_bus_error
*ret_error
) {
107 Manager
*m
= userdata
;
112 /* Did we get a timezone or transient hostname from DHCP while D-Bus wasn't up yet? */
113 if (m
->dynamic_hostname
)
114 (void) manager_set_hostname(m
, m
->dynamic_hostname
);
115 if (m
->dynamic_timezone
)
116 (void) manager_set_timezone(m
, m
->dynamic_timezone
);
117 if (m
->links_requesting_uuid
)
118 (void) manager_request_product_uuid(m
, NULL
);
123 int manager_connect_bus(Manager
*m
) {
131 r
= bus_open_system_watch_bind_with_description(&m
->bus
, "bus-api-network");
133 return log_error_errno(r
, "Failed to connect to bus: %m");
135 r
= sd_bus_add_object_vtable(m
->bus
, NULL
, "/org/freedesktop/network1", "org.freedesktop.network1.Manager", manager_vtable
, m
);
137 return log_error_errno(r
, "Failed to add manager object vtable: %m");
139 r
= sd_bus_add_fallback_vtable(m
->bus
, NULL
, "/org/freedesktop/network1/link", "org.freedesktop.network1.Link", link_vtable
, link_object_find
, m
);
141 return log_error_errno(r
, "Failed to add link object vtable: %m");
143 r
= sd_bus_add_node_enumerator(m
->bus
, NULL
, "/org/freedesktop/network1/link", link_node_enumerator
, m
);
145 return log_error_errno(r
, "Failed to add link enumerator: %m");
147 r
= sd_bus_add_fallback_vtable(m
->bus
, NULL
, "/org/freedesktop/network1/network", "org.freedesktop.network1.Network", network_vtable
, network_object_find
, m
);
149 return log_error_errno(r
, "Failed to add network object vtable: %m");
151 r
= sd_bus_add_node_enumerator(m
->bus
, NULL
, "/org/freedesktop/network1/network", network_node_enumerator
, m
);
153 return log_error_errno(r
, "Failed to add network enumerator: %m");
155 r
= sd_bus_request_name_async(m
->bus
, NULL
, "org.freedesktop.network1", 0, NULL
, NULL
);
157 return log_error_errno(r
, "Failed to request name: %m");
159 r
= sd_bus_attach_event(m
->bus
, m
->event
, 0);
161 return log_error_errno(r
, "Failed to attach bus to event loop: %m");
163 r
= sd_bus_match_signal_async(
166 "org.freedesktop.DBus.Local",
168 "org.freedesktop.DBus.Local",
170 on_connected
, NULL
, m
);
172 return log_error_errno(r
, "Failed to request match on Connected signal: %m");
174 r
= sd_bus_match_signal_async(
177 "org.freedesktop.login1",
178 "/org/freedesktop/login1",
179 "org.freedesktop.login1.Manager",
181 match_prepare_for_sleep
, NULL
, m
);
183 log_warning_errno(r
, "Failed to request match for PrepareForSleep, ignoring: %m");
188 static int manager_udev_process_link(sd_device_monitor
*monitor
, sd_device
*device
, void *userdata
) {
189 Manager
*m
= userdata
;
197 r
= sd_device_get_property_value(device
, "ACTION", &action
);
199 log_device_debug_errno(device
, r
, "Failed to get 'ACTION' property, ignoring device: %m");
203 if (!STR_IN_SET(action
, "add", "change")) {
204 log_device_debug(device
, "Ignoring udev %s event for device.", action
);
208 r
= sd_device_get_ifindex(device
, &ifindex
);
210 log_device_debug_errno(device
, r
, "Ignoring udev ADD event for device without ifindex or with invalid ifindex: %m");
214 r
= link_get(m
, ifindex
, &link
);
217 log_debug_errno(r
, "Failed to get link from ifindex %i, ignoring: %m", ifindex
);
221 (void) link_initialized(link
, device
);
226 static int manager_connect_udev(Manager
*m
) {
229 /* udev does not initialize devices inside containers,
230 * so we rely on them being already initialized before
231 * entering the container */
232 if (detect_container() > 0)
235 r
= sd_device_monitor_new(&m
->device_monitor
);
237 return log_error_errno(r
, "Failed to initialize device monitor: %m");
239 r
= sd_device_monitor_filter_add_match_subsystem_devtype(m
->device_monitor
, "net", NULL
);
241 return log_error_errno(r
, "Could not add device monitor filter: %m");
243 r
= sd_device_monitor_attach_event(m
->device_monitor
, m
->event
);
245 return log_error_errno(r
, "Failed to attach event to device monitor: %m");
247 r
= sd_device_monitor_start(m
->device_monitor
, manager_udev_process_link
, m
);
249 return log_error_errno(r
, "Failed to start device monitor: %m");
254 int manager_rtnl_process_route(sd_netlink
*rtnl
, sd_netlink_message
*message
, void *userdata
) {
255 Manager
*m
= userdata
;
258 uint32_t ifindex
, priority
= 0;
259 unsigned char protocol
, scope
, tos
, table
, rt_type
;
261 unsigned char dst_prefixlen
, src_prefixlen
;
262 union in_addr_union dst
= {}, gw
= {}, src
= {}, prefsrc
= {};
270 if (sd_netlink_message_is_error(message
)) {
271 r
= sd_netlink_message_get_errno(message
);
273 log_warning_errno(r
, "rtnl: failed to receive route, ignoring: %m");
278 r
= sd_netlink_message_get_type(message
, &type
);
280 log_warning_errno(r
, "rtnl: could not get message type, ignoring: %m");
282 } else if (!IN_SET(type
, RTM_NEWROUTE
, RTM_DELROUTE
)) {
283 log_warning("rtnl: received unexpected message type when processing route, ignoring");
287 r
= sd_netlink_message_read_u32(message
, RTA_OIF
, &ifindex
);
289 log_debug("rtnl: received route without ifindex, ignoring");
292 log_warning_errno(r
, "rtnl: could not get ifindex from route, ignoring: %m");
294 } else if (ifindex
<= 0) {
295 log_warning("rtnl: received route message with invalid ifindex, ignoring: %d", ifindex
);
298 r
= link_get(m
, ifindex
, &link
);
299 if (r
< 0 || !link
) {
300 /* when enumerating we might be out of sync, but we will
301 * get the route again, so just ignore it */
303 log_warning("rtnl: received route for nonexistent link (%d), ignoring", ifindex
);
308 r
= sd_rtnl_message_route_get_family(message
, &family
);
309 if (r
< 0 || !IN_SET(family
, AF_INET
, AF_INET6
)) {
310 log_link_warning(link
, "rtnl: received address with invalid family, ignoring");
314 r
= sd_rtnl_message_route_get_protocol(message
, &protocol
);
316 log_warning_errno(r
, "rtnl: could not get route protocol: %m");
322 r
= sd_netlink_message_read_in_addr(message
, RTA_DST
, &dst
.in
);
323 if (r
< 0 && r
!= -ENODATA
) {
324 log_link_warning_errno(link
, r
, "rtnl: received route without valid destination, ignoring: %m");
328 r
= sd_netlink_message_read_in_addr(message
, RTA_GATEWAY
, &gw
.in
);
329 if (r
< 0 && r
!= -ENODATA
) {
330 log_link_warning_errno(link
, r
, "rtnl: received route with invalid gateway, ignoring: %m");
334 r
= sd_netlink_message_read_in_addr(message
, RTA_SRC
, &src
.in
);
335 if (r
< 0 && r
!= -ENODATA
) {
336 log_link_warning_errno(link
, r
, "rtnl: received route with invalid source, ignoring: %m");
340 r
= sd_netlink_message_read_in_addr(message
, RTA_PREFSRC
, &prefsrc
.in
);
341 if (r
< 0 && r
!= -ENODATA
) {
342 log_link_warning_errno(link
, r
, "rtnl: received route with invalid preferred source, ignoring: %m");
349 r
= sd_netlink_message_read_in6_addr(message
, RTA_DST
, &dst
.in6
);
350 if (r
< 0 && r
!= -ENODATA
) {
351 log_link_warning_errno(link
, r
, "rtnl: received route without valid destination, ignoring: %m");
355 r
= sd_netlink_message_read_in6_addr(message
, RTA_GATEWAY
, &gw
.in6
);
356 if (r
< 0 && r
!= -ENODATA
) {
357 log_link_warning_errno(link
, r
, "rtnl: received route with invalid gateway, ignoring: %m");
361 r
= sd_netlink_message_read_in6_addr(message
, RTA_SRC
, &src
.in6
);
362 if (r
< 0 && r
!= -ENODATA
) {
363 log_link_warning_errno(link
, r
, "rtnl: received route with invalid source, ignoring: %m");
367 r
= sd_netlink_message_read_in6_addr(message
, RTA_PREFSRC
, &prefsrc
.in6
);
368 if (r
< 0 && r
!= -ENODATA
) {
369 log_link_warning_errno(link
, r
, "rtnl: received route with invalid preferred source, ignoring: %m");
376 assert_not_reached("Received unsupported address family");
380 r
= sd_rtnl_message_route_get_dst_prefixlen(message
, &dst_prefixlen
);
382 log_link_warning_errno(link
, r
, "rtnl: received route with invalid destination prefixlen, ignoring: %m");
386 r
= sd_rtnl_message_route_get_src_prefixlen(message
, &src_prefixlen
);
388 log_link_warning_errno(link
, r
, "rtnl: received route with invalid source prefixlen, ignoring: %m");
392 r
= sd_rtnl_message_route_get_scope(message
, &scope
);
394 log_link_warning_errno(link
, r
, "rtnl: received route with invalid scope, ignoring: %m");
398 r
= sd_rtnl_message_route_get_tos(message
, &tos
);
400 log_link_warning_errno(link
, r
, "rtnl: received route with invalid tos, ignoring: %m");
404 r
= sd_rtnl_message_route_get_type(message
, &rt_type
);
406 log_link_warning_errno(link
, r
, "rtnl: received route with invalid type, ignoring: %m");
410 r
= sd_rtnl_message_route_get_table(message
, &table
);
412 log_link_warning_errno(link
, r
, "rtnl: received route with invalid table, ignoring: %m");
416 r
= sd_netlink_message_read_u32(message
, RTA_PRIORITY
, &priority
);
417 if (r
< 0 && r
!= -ENODATA
) {
418 log_link_warning_errno(link
, r
, "rtnl: received route with invalid priority, ignoring: %m");
422 (void) route_get(link
, family
, &dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
427 /* A route appeared that we did not request */
428 r
= route_add_foreign(link
, family
, &dst
, dst_prefixlen
, tos
, priority
, table
, &route
);
430 log_link_warning_errno(link
, r
, "Failed to add route, ignoring: %m");
435 route_update(route
, &src
, src_prefixlen
, &gw
, &prefsrc
, scope
, protocol
, rt_type
);
444 assert_not_reached("Received invalid RTNL message type");
450 int manager_rtnl_process_address(sd_netlink
*rtnl
, sd_netlink_message
*message
, void *userdata
) {
451 Manager
*m
= userdata
;
456 unsigned char prefixlen
;
458 union in_addr_union in_addr
;
459 struct ifa_cacheinfo cinfo
;
460 Address
*address
= NULL
;
461 char buf
[INET6_ADDRSTRLEN
], valid_buf
[FORMAT_TIMESPAN_MAX
];
462 const char *valid_str
= NULL
;
469 if (sd_netlink_message_is_error(message
)) {
470 r
= sd_netlink_message_get_errno(message
);
472 log_warning_errno(r
, "rtnl: failed to receive address, ignoring: %m");
477 r
= sd_netlink_message_get_type(message
, &type
);
479 log_warning_errno(r
, "rtnl: could not get message type, ignoring: %m");
481 } else if (!IN_SET(type
, RTM_NEWADDR
, RTM_DELADDR
)) {
482 log_warning("rtnl: received unexpected message type when processing address, ignoring");
486 r
= sd_rtnl_message_addr_get_ifindex(message
, &ifindex
);
488 log_warning_errno(r
, "rtnl: could not get ifindex from address, ignoring: %m");
490 } else if (ifindex
<= 0) {
491 log_warning("rtnl: received address message with invalid ifindex, ignoring: %d", ifindex
);
494 r
= link_get(m
, ifindex
, &link
);
495 if (r
< 0 || !link
) {
496 /* when enumerating we might be out of sync, but we will
497 * get the address again, so just ignore it */
499 log_warning("rtnl: received address for nonexistent link (%d), ignoring", ifindex
);
504 r
= sd_rtnl_message_addr_get_family(message
, &family
);
505 if (r
< 0 || !IN_SET(family
, AF_INET
, AF_INET6
)) {
506 log_link_warning(link
, "rtnl: received address with invalid family, ignoring");
510 r
= sd_rtnl_message_addr_get_prefixlen(message
, &prefixlen
);
512 log_link_warning_errno(link
, r
, "rtnl: received address with invalid prefixlen, ignoring: %m");
516 r
= sd_rtnl_message_addr_get_scope(message
, &scope
);
518 log_link_warning_errno(link
, r
, "rtnl: received address with invalid scope, ignoring: %m");
522 r
= sd_rtnl_message_addr_get_flags(message
, &flags
);
524 log_link_warning_errno(link
, r
, "rtnl: received address with invalid flags, ignoring: %m");
530 r
= sd_netlink_message_read_in_addr(message
, IFA_LOCAL
, &in_addr
.in
);
532 log_link_warning_errno(link
, r
, "rtnl: received address without valid address, ignoring: %m");
539 r
= sd_netlink_message_read_in6_addr(message
, IFA_ADDRESS
, &in_addr
.in6
);
541 log_link_warning_errno(link
, r
, "rtnl: received address without valid address, ignoring: %m");
548 assert_not_reached("Received unsupported address family");
551 if (!inet_ntop(family
, &in_addr
, buf
, INET6_ADDRSTRLEN
)) {
552 log_link_warning(link
, "Could not print address, ignoring");
556 r
= sd_netlink_message_read_cache_info(message
, IFA_CACHEINFO
, &cinfo
);
557 if (r
< 0 && r
!= -ENODATA
) {
558 log_link_warning_errno(link
, r
, "rtnl: cannot get IFA_CACHEINFO attribute, ignoring: %m");
561 if (cinfo
.ifa_valid
!= CACHE_INFO_INFINITY_LIFE_TIME
)
562 valid_str
= format_timespan(valid_buf
, FORMAT_TIMESPAN_MAX
,
563 cinfo
.ifa_valid
* USEC_PER_SEC
,
567 (void) address_get(link
, family
, &in_addr
, prefixlen
, &address
);
572 log_link_debug(link
, "Updating address: %s/%u (valid %s%s)", buf
, prefixlen
,
573 valid_str
? "for " : "forever", strempty(valid_str
));
575 /* An address appeared that we did not request */
576 r
= address_add_foreign(link
, family
, &in_addr
, prefixlen
, &address
);
578 log_link_warning_errno(link
, r
, "Failed to add address %s/%u, ignoring: %m", buf
, prefixlen
);
581 log_link_debug(link
, "Adding address: %s/%u (valid %s%s)", buf
, prefixlen
,
582 valid_str
? "for " : "forever", strempty(valid_str
));
585 r
= address_update(address
, flags
, scope
, &cinfo
);
587 log_link_warning_errno(link
, r
, "Failed to update address %s/%u, ignoring: %m", buf
, prefixlen
);
596 log_link_debug(link
, "Removing address: %s/%u (valid %s%s)", buf
, prefixlen
,
597 valid_str
? "for " : "forever", strempty(valid_str
));
598 (void) address_drop(address
);
600 log_link_warning(link
, "Removing non-existent address: %s/%u (valid %s%s), ignoring", buf
, prefixlen
,
601 valid_str
? "for " : "forever", strempty(valid_str
));
605 assert_not_reached("Received invalid RTNL message type");
611 static int manager_rtnl_process_link(sd_netlink
*rtnl
, sd_netlink_message
*message
, void *userdata
) {
612 Manager
*m
= userdata
;
614 NetDev
*netdev
= NULL
;
623 if (sd_netlink_message_is_error(message
)) {
624 r
= sd_netlink_message_get_errno(message
);
626 log_warning_errno(r
, "rtnl: Could not receive link, ignoring: %m");
631 r
= sd_netlink_message_get_type(message
, &type
);
633 log_warning_errno(r
, "rtnl: Could not get message type, ignoring: %m");
635 } else if (!IN_SET(type
, RTM_NEWLINK
, RTM_DELLINK
)) {
636 log_warning("rtnl: Received unexpected message type when processing link, ignoring");
640 r
= sd_rtnl_message_link_get_ifindex(message
, &ifindex
);
642 log_warning_errno(r
, "rtnl: Could not get ifindex from link, ignoring: %m");
644 } else if (ifindex
<= 0) {
645 log_warning("rtnl: received link message with invalid ifindex %d, ignoring", ifindex
);
649 r
= sd_netlink_message_read_string(message
, IFLA_IFNAME
, &name
);
651 log_warning_errno(r
, "rtnl: Received link message without ifname, ignoring: %m");
655 (void) link_get(m
, ifindex
, &link
);
656 (void) netdev_get(m
, name
, &netdev
);
661 /* link is new, so add it */
662 r
= link_add(m
, message
, &link
);
664 log_warning_errno(r
, "Could not add new link, ignoring: %m");
670 /* netdev exists, so make sure the ifindex matches */
671 r
= netdev_set_ifindex(netdev
, message
);
673 log_warning_errno(r
, "Could not set ifindex on netdev, ignoring: %m");
678 r
= link_update(link
, message
);
680 log_warning_errno(r
, "Could not update link, ignoring: %m");
693 assert_not_reached("Received invalid RTNL message type.");
699 int manager_rtnl_process_rule(sd_netlink
*rtnl
, sd_netlink_message
*message
, void *userdata
) {
700 uint8_t tos
= 0, to_prefixlen
= 0, from_prefixlen
= 0, protocol
= 0;
701 struct fib_rule_port_range sport
= {}, dport
= {};
702 union in_addr_union to
= {}, from
= {};
703 RoutingPolicyRule
*rule
= NULL
;
704 uint32_t fwmark
= 0, table
= 0;
705 const char *iif
= NULL
, *oif
= NULL
;
706 Manager
*m
= userdata
;
715 if (sd_netlink_message_is_error(message
)) {
716 r
= sd_netlink_message_get_errno(message
);
718 log_warning_errno(r
, "rtnl: failed to receive rule, ignoring: %m");
723 r
= sd_netlink_message_get_type(message
, &type
);
725 log_warning_errno(r
, "rtnl: could not get message type, ignoring: %m");
727 } else if (!IN_SET(type
, RTM_NEWRULE
, RTM_DELRULE
)) {
728 log_warning("rtnl: received unexpected message type '%u' when processing rule, ignoring", type
);
732 r
= sd_rtnl_message_get_family(message
, &family
);
734 log_warning_errno(r
, "rtnl: could not get rule family, ignoring: %m");
736 } else if (!IN_SET(family
, AF_INET
, AF_INET6
)) {
737 log_debug("rtnl: received address with invalid family %u, ignoring", family
);
743 r
= sd_netlink_message_read_in_addr(message
, FRA_SRC
, &from
.in
);
744 if (r
< 0 && r
!= -ENODATA
) {
745 log_warning_errno(r
, "rtnl: could not get FRA_SRC attribute, ignoring: %m");
748 r
= sd_rtnl_message_routing_policy_rule_get_rtm_src_prefixlen(message
, &from_prefixlen
);
750 log_warning_errno(r
, "rtnl: failed to retrieve rule from prefix length, ignoring: %m");
755 r
= sd_netlink_message_read_in_addr(message
, FRA_DST
, &to
.in
);
756 if (r
< 0 && r
!= -ENODATA
) {
757 log_warning_errno(r
, "rtnl: could not get FRA_DST attribute, ignoring: %m");
760 r
= sd_rtnl_message_routing_policy_rule_get_rtm_dst_prefixlen(message
, &to_prefixlen
);
762 log_warning_errno(r
, "rtnl: failed to retrieve rule to prefix length, ignoring: %m");
770 r
= sd_netlink_message_read_in6_addr(message
, FRA_SRC
, &from
.in6
);
771 if (r
< 0 && r
!= -ENODATA
) {
772 log_warning_errno(r
, "rtnl: could not get FRA_SRC attribute, ignoring: %m");
775 r
= sd_rtnl_message_routing_policy_rule_get_rtm_src_prefixlen(message
, &from_prefixlen
);
777 log_warning_errno(r
, "rtnl: failed to retrieve rule from prefix length, ignoring: %m");
782 r
= sd_netlink_message_read_in6_addr(message
, FRA_DST
, &to
.in6
);
783 if (r
< 0 && r
!= -ENODATA
) {
784 log_warning_errno(r
, "rtnl: could not get FRA_DST attribute, ignoring: %m");
787 r
= sd_rtnl_message_routing_policy_rule_get_rtm_dst_prefixlen(message
, &to_prefixlen
);
789 log_warning_errno(r
, "rtnl: failed to retrieve rule to prefix length, ignoring: %m");
797 assert_not_reached("Received unsupported address family");
800 if (from_prefixlen
== 0 && to_prefixlen
== 0)
803 r
= sd_netlink_message_read_u32(message
, FRA_FWMARK
, &fwmark
);
804 if (r
< 0 && r
!= -ENODATA
) {
805 log_warning_errno(r
, "rtnl: could not get FRA_FWMARK attribute, ignoring: %m");
809 r
= sd_netlink_message_read_u32(message
, FRA_TABLE
, &table
);
810 if (r
< 0 && r
!= -ENODATA
) {
811 log_warning_errno(r
, "rtnl: could not get FRA_TABLE attribute, ignoring: %m");
815 r
= sd_rtnl_message_routing_policy_rule_get_tos(message
, &tos
);
816 if (r
< 0 && r
!= -ENODATA
) {
817 log_warning_errno(r
, "rtnl: could not get ip rule TOS, ignoring: %m");
821 r
= sd_netlink_message_read_string(message
, FRA_IIFNAME
, &iif
);
822 if (r
< 0 && r
!= -ENODATA
) {
823 log_warning_errno(r
, "rtnl: could not get FRA_IIFNAME attribute, ignoring: %m");
827 r
= sd_netlink_message_read_string(message
, FRA_OIFNAME
, &oif
);
828 if (r
< 0 && r
!= -ENODATA
) {
829 log_warning_errno(r
, "rtnl: could not get FRA_OIFNAME attribute, ignoring: %m");
833 r
= sd_netlink_message_read_u8(message
, FRA_IP_PROTO
, &protocol
);
834 if (r
< 0 && r
!= -ENODATA
) {
835 log_warning_errno(r
, "rtnl: could not get FRA_IP_PROTO attribute, ignoring: %m");
839 r
= sd_netlink_message_read(message
, FRA_SPORT_RANGE
, sizeof(sport
), (void *) &sport
);
840 if (r
< 0 && r
!= -ENODATA
) {
841 log_warning_errno(r
, "rtnl: could not get FRA_SPORT_RANGE attribute, ignoring: %m");
845 r
= sd_netlink_message_read(message
, FRA_DPORT_RANGE
, sizeof(dport
), (void *) &dport
);
846 if (r
< 0 && r
!= -ENODATA
) {
847 log_warning_errno(r
, "rtnl: could not get FRA_DPORT_RANGE attribute, ignoring: %m");
851 (void) routing_policy_rule_get(m
, family
, &from
, from_prefixlen
, &to
, to_prefixlen
, tos
, fwmark
, table
, iif
, oif
, protocol
, &sport
, &dport
, &rule
);
856 r
= routing_policy_rule_add_foreign(m
, family
, &from
, from_prefixlen
, &to
, to_prefixlen
, tos
, fwmark
, table
, iif
, oif
, protocol
, &sport
, &dport
, &rule
);
858 log_warning_errno(r
, "Could not add rule, ignoring: %m");
864 routing_policy_rule_free(rule
);
869 assert_not_reached("Received invalid RTNL message type");
875 static int systemd_netlink_fd(void) {
876 int n
, fd
, rtnl_fd
= -EINVAL
;
878 n
= sd_listen_fds(true);
882 for (fd
= SD_LISTEN_FDS_START
; fd
< SD_LISTEN_FDS_START
+ n
; fd
++) {
883 if (sd_is_socket(fd
, AF_NETLINK
, SOCK_RAW
, -1) > 0) {
894 static int manager_connect_genl(Manager
*m
) {
899 r
= sd_genl_socket_open(&m
->genl
);
903 r
= sd_netlink_inc_rcvbuf(m
->genl
, RCVBUF_SIZE
);
907 r
= sd_netlink_attach_event(m
->genl
, m
->event
, 0);
914 static int manager_connect_rtnl(Manager
*m
) {
919 fd
= systemd_netlink_fd();
921 r
= sd_netlink_open(&m
->rtnl
);
923 r
= sd_netlink_open_fd(&m
->rtnl
, fd
);
927 r
= sd_netlink_inc_rcvbuf(m
->rtnl
, RCVBUF_SIZE
);
931 r
= sd_netlink_attach_event(m
->rtnl
, m
->event
, 0);
935 r
= sd_netlink_add_match(m
->rtnl
, NULL
, RTM_NEWLINK
, &manager_rtnl_process_link
, NULL
, m
, "network-rtnl_process_link");
939 r
= sd_netlink_add_match(m
->rtnl
, NULL
, RTM_DELLINK
, &manager_rtnl_process_link
, NULL
, m
, "network-rtnl_process_link");
943 r
= sd_netlink_add_match(m
->rtnl
, NULL
, RTM_NEWADDR
, &manager_rtnl_process_address
, NULL
, m
, "network-rtnl_process_address");
947 r
= sd_netlink_add_match(m
->rtnl
, NULL
, RTM_DELADDR
, &manager_rtnl_process_address
, NULL
, m
, "network-rtnl_process_address");
951 r
= sd_netlink_add_match(m
->rtnl
, NULL
, RTM_NEWROUTE
, &manager_rtnl_process_route
, NULL
, m
, "network-rtnl_process_route");
955 r
= sd_netlink_add_match(m
->rtnl
, NULL
, RTM_DELROUTE
, &manager_rtnl_process_route
, NULL
, m
, "network-rtnl_process_route");
959 r
= sd_netlink_add_match(m
->rtnl
, NULL
, RTM_NEWRULE
, &manager_rtnl_process_rule
, NULL
, m
, "network-rtnl_process_rule");
963 r
= sd_netlink_add_match(m
->rtnl
, NULL
, RTM_DELRULE
, &manager_rtnl_process_rule
, NULL
, m
, "network-rtnl_process_rule");
970 static int ordered_set_put_in_addr_data(OrderedSet
*s
, const struct in_addr_data
*address
) {
977 r
= in_addr_to_string(address
->family
, &address
->address
, &p
);
981 r
= ordered_set_consume(s
, p
);
988 static int ordered_set_put_in_addr_datav(OrderedSet
*s
, const struct in_addr_data
*addresses
, unsigned n
) {
993 assert(addresses
|| n
== 0);
995 for (i
= 0; i
< n
; i
++) {
996 r
= ordered_set_put_in_addr_data(s
, addresses
+i
);
1006 static int ordered_set_put_in4_addr(OrderedSet
*s
, const struct in_addr
*address
) {
1013 r
= in_addr_to_string(AF_INET
, (const union in_addr_union
*) address
, &p
);
1017 r
= ordered_set_consume(s
, p
);
1024 static int ordered_set_put_in4_addrv(OrderedSet
*s
, const struct in_addr
*addresses
, unsigned n
) {
1029 assert(n
== 0 || addresses
);
1031 for (i
= 0; i
< n
; i
++) {
1032 r
= ordered_set_put_in4_addr(s
, addresses
+i
);
1042 static void print_string_set(FILE *f
, const char *field
, OrderedSet
*s
) {
1047 if (ordered_set_isempty(s
))
1052 ORDERED_SET_FOREACH(p
, s
, i
)
1053 fputs_with_space(f
, p
, NULL
, &space
);
1058 static int manager_save(Manager
*m
) {
1059 _cleanup_ordered_set_free_free_ OrderedSet
*dns
= NULL
, *ntp
= NULL
, *search_domains
= NULL
, *route_domains
= NULL
;
1062 _cleanup_free_
char *temp_path
= NULL
;
1063 _cleanup_fclose_
FILE *f
= NULL
;
1064 LinkOperationalState operstate
= LINK_OPERSTATE_OFF
;
1065 const char *operstate_str
;
1069 assert(m
->state_file
);
1071 /* We add all NTP and DNS server to a set, to filter out duplicates */
1072 dns
= ordered_set_new(&string_hash_ops
);
1076 ntp
= ordered_set_new(&string_hash_ops
);
1080 search_domains
= ordered_set_new(&dns_name_hash_ops
);
1081 if (!search_domains
)
1084 route_domains
= ordered_set_new(&dns_name_hash_ops
);
1088 HASHMAP_FOREACH(link
, m
->links
, i
) {
1089 if (link
->flags
& IFF_LOOPBACK
)
1092 if (link
->operstate
> operstate
)
1093 operstate
= link
->operstate
;
1098 /* First add the static configured entries */
1099 r
= ordered_set_put_in_addr_datav(dns
, link
->network
->dns
, link
->network
->n_dns
);
1103 r
= ordered_set_put_strdupv(ntp
, link
->network
->ntp
);
1107 r
= ordered_set_put_strdupv(search_domains
, link
->network
->search_domains
);
1111 r
= ordered_set_put_strdupv(route_domains
, link
->network
->route_domains
);
1115 if (!link
->dhcp_lease
)
1118 /* Secondly, add the entries acquired via DHCP */
1119 if (link
->network
->dhcp_use_dns
) {
1120 const struct in_addr
*addresses
;
1122 r
= sd_dhcp_lease_get_dns(link
->dhcp_lease
, &addresses
);
1124 r
= ordered_set_put_in4_addrv(dns
, addresses
, r
);
1127 } else if (r
< 0 && r
!= -ENODATA
)
1131 if (link
->network
->dhcp_use_ntp
) {
1132 const struct in_addr
*addresses
;
1134 r
= sd_dhcp_lease_get_ntp(link
->dhcp_lease
, &addresses
);
1136 r
= ordered_set_put_in4_addrv(ntp
, addresses
, r
);
1139 } else if (r
< 0 && r
!= -ENODATA
)
1143 if (link
->network
->dhcp_use_domains
!= DHCP_USE_DOMAINS_NO
) {
1144 const char *domainname
;
1145 char **domains
= NULL
;
1147 OrderedSet
*target_domains
= (link
->network
->dhcp_use_domains
== DHCP_USE_DOMAINS_YES
) ? search_domains
: route_domains
;
1148 r
= sd_dhcp_lease_get_domainname(link
->dhcp_lease
, &domainname
);
1150 r
= ordered_set_put_strdup(target_domains
, domainname
);
1153 } else if (r
!= -ENODATA
)
1156 r
= sd_dhcp_lease_get_search_domains(link
->dhcp_lease
, &domains
);
1158 r
= ordered_set_put_strdupv(target_domains
, domains
);
1161 } else if (r
!= -ENODATA
)
1166 operstate_str
= link_operstate_to_string(operstate
);
1167 assert(operstate_str
);
1169 r
= fopen_temporary(m
->state_file
, &f
, &temp_path
);
1173 (void) __fsetlocking(f
, FSETLOCKING_BYCALLER
);
1174 (void) fchmod(fileno(f
), 0644);
1177 "# This is private data. Do not parse.\n"
1178 "OPER_STATE=%s\n", operstate_str
);
1180 print_string_set(f
, "DNS=", dns
);
1181 print_string_set(f
, "NTP=", ntp
);
1182 print_string_set(f
, "DOMAINS=", search_domains
);
1183 print_string_set(f
, "ROUTE_DOMAINS=", route_domains
);
1185 r
= routing_policy_serialize_rules(m
->rules
, f
);
1189 r
= fflush_and_check(f
);
1193 if (rename(temp_path
, m
->state_file
) < 0) {
1198 if (m
->operational_state
!= operstate
) {
1199 m
->operational_state
= operstate
;
1200 r
= manager_send_changed(m
, "OperationalState", NULL
);
1202 log_error_errno(r
, "Could not emit changed OperationalState: %m");
1210 (void) unlink(m
->state_file
);
1211 (void) unlink(temp_path
);
1213 return log_error_errno(r
, "Failed to save network state to %s: %m", m
->state_file
);
1216 static int manager_dirty_handler(sd_event_source
*s
, void *userdata
) {
1217 Manager
*m
= userdata
;
1226 SET_FOREACH(link
, m
->dirty_links
, i
)
1227 if (link_save(link
) >= 0)
1233 Link
*manager_dhcp6_prefix_get(Manager
*m
, struct in6_addr
*addr
) {
1234 assert_return(m
, NULL
);
1235 assert_return(addr
, NULL
);
1237 return hashmap_get(m
->dhcp6_prefixes
, addr
);
1240 static int dhcp6_route_add_handler(sd_netlink
*nl
, sd_netlink_message
*m
, void *userdata
) {
1241 Link
*link
= userdata
;
1246 r
= sd_netlink_message_get_errno(m
);
1247 if (r
< 0 && r
!= -EEXIST
)
1248 log_link_debug_errno(link
, r
, "Received error adding DHCPv6 Prefix Delegation route: %m");
1253 static void dhcp6_prefixes_hash_func(const void *p
, struct siphash
*state
) {
1254 const struct in6_addr
*addr
= p
;
1258 siphash24_compress(addr
, sizeof(*addr
), state
);
1261 static int dhcp6_prefixes_compare_func(const void *_a
, const void *_b
) {
1262 const struct in6_addr
*a
= _a
, *b
= _b
;
1264 return memcmp(a
, b
, sizeof(*a
));
1267 static const struct hash_ops dhcp6_prefixes_hash_ops
= {
1268 .hash
= dhcp6_prefixes_hash_func
,
1269 .compare
= dhcp6_prefixes_compare_func
,
1272 int manager_dhcp6_prefix_add(Manager
*m
, struct in6_addr
*addr
, Link
*link
) {
1273 _cleanup_free_
char *buf
= NULL
;
1277 assert_return(m
, -EINVAL
);
1278 assert_return(addr
, -EINVAL
);
1280 r
= route_add(link
, AF_INET6
, (union in_addr_union
*) addr
, 64,
1285 r
= route_configure(route
, link
, dhcp6_route_add_handler
);
1289 (void) in_addr_to_string(AF_INET6
, (union in_addr_union
*) addr
, &buf
);
1290 log_link_debug(link
, "Adding prefix route %s/64", strnull(buf
));
1292 r
= hashmap_ensure_allocated(&m
->dhcp6_prefixes
, &dhcp6_prefixes_hash_ops
);
1296 return hashmap_put(m
->dhcp6_prefixes
, addr
, link
);
1299 static int dhcp6_route_remove_handler(sd_netlink
*nl
, sd_netlink_message
*m
, void *userdata
) {
1300 Link
*link
= userdata
;
1305 r
= sd_netlink_message_get_errno(m
);
1307 log_link_debug_errno(link
, r
, "Received error on DHCPv6 Prefix Delegation route removal: %m");
1312 static int manager_dhcp6_prefix_remove(Manager
*m
, struct in6_addr
*addr
) {
1313 _cleanup_free_
char *buf
= NULL
;
1318 assert_return(m
, -EINVAL
);
1319 assert_return(addr
, -EINVAL
);
1321 l
= hashmap_remove(m
->dhcp6_prefixes
, addr
);
1325 (void) sd_radv_remove_prefix(l
->radv
, addr
, 64);
1326 r
= route_get(l
, AF_INET6
, (union in_addr_union
*) addr
, 64,
1331 r
= route_remove(route
, l
, dhcp6_route_remove_handler
);
1335 (void) in_addr_to_string(AF_INET6
, (union in_addr_union
*) addr
, &buf
);
1336 log_link_debug(l
, "Removing prefix route %s/64", strnull(buf
));
1341 int manager_dhcp6_prefix_remove_all(Manager
*m
, Link
*link
) {
1342 struct in6_addr
*addr
;
1346 assert_return(m
, -EINVAL
);
1347 assert_return(link
, -EINVAL
);
1349 HASHMAP_FOREACH_KEY(l
, addr
, m
->dhcp6_prefixes
, i
) {
1353 (void) manager_dhcp6_prefix_remove(m
, addr
);
1359 int manager_new(Manager
**ret
) {
1360 _cleanup_(manager_freep
) Manager
*m
= NULL
;
1363 m
= new0(Manager
, 1);
1367 m
->state_file
= strdup("/run/systemd/netif/state");
1371 r
= sd_event_default(&m
->event
);
1375 (void) sd_event_set_watchdog(m
->event
, true);
1376 (void) sd_event_add_signal(m
->event
, NULL
, SIGTERM
, NULL
, NULL
);
1377 (void) sd_event_add_signal(m
->event
, NULL
, SIGINT
, NULL
, NULL
);
1379 r
= sd_event_add_post(m
->event
, NULL
, manager_dirty_handler
, m
);
1383 r
= manager_connect_rtnl(m
);
1387 r
= manager_connect_genl(m
);
1391 r
= manager_connect_udev(m
);
1395 LIST_HEAD_INIT(m
->networks
);
1397 r
= sd_resolve_default(&m
->resolve
);
1401 r
= sd_resolve_attach_event(m
->resolve
, m
->event
, 0);
1405 r
= setup_default_address_pool(m
);
1409 m
->duid
.type
= DUID_TYPE_EN
;
1411 (void) routing_policy_load_rules(m
->state_file
, &m
->rules_saved
);
1418 void manager_free(Manager
*m
) {
1426 free(m
->state_file
);
1428 sd_netlink_unref(m
->rtnl
);
1429 sd_netlink_unref(m
->genl
);
1430 sd_resolve_unref(m
->resolve
);
1432 while ((network
= m
->networks
))
1433 network_free(network
);
1435 while ((link
= hashmap_first(m
->dhcp6_prefixes
)))
1436 manager_dhcp6_prefix_remove_all(m
, link
);
1437 hashmap_free(m
->dhcp6_prefixes
);
1439 while ((link
= hashmap_steal_first(m
->links
))) {
1440 if (link
->dhcp6_client
)
1441 (void) dhcp6_lease_pd_prefix_lost(link
->dhcp6_client
, link
);
1445 m
->dirty_links
= set_free_with_destructor(m
->dirty_links
, link_unref
);
1446 m
->links
= hashmap_free(m
->links
);
1447 m
->links_requesting_uuid
= set_free(m
->links_requesting_uuid
);
1448 set_free(m
->duids_requesting_uuid
);
1450 hashmap_free(m
->networks_by_name
);
1452 m
->netdevs
= hashmap_free_with_destructor(m
->netdevs
, netdev_unref
);
1454 while ((pool
= m
->address_pools
))
1455 address_pool_free(pool
);
1457 /* routing_policy_rule_free() access m->rules and m->rules_foreign.
1458 * So, it is necessary to set NULL after the sets are freed. */
1459 m
->rules
= set_free_with_destructor(m
->rules
, routing_policy_rule_free
);
1460 m
->rules_foreign
= set_free_with_destructor(m
->rules_foreign
, routing_policy_rule_free
);
1461 set_free_with_destructor(m
->rules_saved
, routing_policy_rule_free
);
1463 sd_event_unref(m
->event
);
1465 sd_device_monitor_unref(m
->device_monitor
);
1467 sd_bus_unref(m
->bus
);
1469 free(m
->dynamic_timezone
);
1470 free(m
->dynamic_hostname
);
1475 int manager_start(Manager
*m
) {
1481 /* The dirty handler will deal with future serialization, but the first one
1482 must be done explicitly. */
1486 HASHMAP_FOREACH(link
, m
->links
, i
)
1492 int manager_load_config(Manager
*m
) {
1495 /* update timestamp */
1496 paths_check_timestamp(network_dirs
, &m
->network_dirs_ts_usec
, true);
1502 r
= network_load(m
);
1509 bool manager_should_reload(Manager
*m
) {
1510 return paths_check_timestamp(network_dirs
, &m
->network_dirs_ts_usec
, false);
1513 int manager_rtnl_enumerate_links(Manager
*m
) {
1514 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
, *reply
= NULL
;
1515 sd_netlink_message
*link
;
1521 r
= sd_rtnl_message_new_link(m
->rtnl
, &req
, RTM_GETLINK
, 0);
1525 r
= sd_netlink_message_request_dump(req
, true);
1529 r
= sd_netlink_call(m
->rtnl
, req
, 0, &reply
);
1533 for (link
= reply
; link
; link
= sd_netlink_message_next(link
)) {
1536 m
->enumerating
= true;
1538 k
= manager_rtnl_process_link(m
->rtnl
, link
, m
);
1542 m
->enumerating
= false;
1548 int manager_rtnl_enumerate_addresses(Manager
*m
) {
1549 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
, *reply
= NULL
;
1550 sd_netlink_message
*addr
;
1556 r
= sd_rtnl_message_new_addr(m
->rtnl
, &req
, RTM_GETADDR
, 0, 0);
1560 r
= sd_netlink_message_request_dump(req
, true);
1564 r
= sd_netlink_call(m
->rtnl
, req
, 0, &reply
);
1568 for (addr
= reply
; addr
; addr
= sd_netlink_message_next(addr
)) {
1571 m
->enumerating
= true;
1573 k
= manager_rtnl_process_address(m
->rtnl
, addr
, m
);
1577 m
->enumerating
= false;
1583 int manager_rtnl_enumerate_routes(Manager
*m
) {
1584 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
, *reply
= NULL
;
1585 sd_netlink_message
*route
;
1591 r
= sd_rtnl_message_new_route(m
->rtnl
, &req
, RTM_GETROUTE
, 0, 0);
1595 r
= sd_netlink_message_request_dump(req
, true);
1599 r
= sd_netlink_call(m
->rtnl
, req
, 0, &reply
);
1603 for (route
= reply
; route
; route
= sd_netlink_message_next(route
)) {
1606 m
->enumerating
= true;
1608 k
= manager_rtnl_process_route(m
->rtnl
, route
, m
);
1612 m
->enumerating
= false;
1618 int manager_rtnl_enumerate_rules(Manager
*m
) {
1619 _cleanup_(sd_netlink_message_unrefp
) sd_netlink_message
*req
= NULL
, *reply
= NULL
;
1620 sd_netlink_message
*rule
;
1626 r
= sd_rtnl_message_new_routing_policy_rule(m
->rtnl
, &req
, RTM_GETRULE
, 0);
1630 r
= sd_netlink_message_request_dump(req
, true);
1634 r
= sd_netlink_call(m
->rtnl
, req
, 0, &reply
);
1636 if (r
== -EOPNOTSUPP
) {
1637 log_debug("FIB Rules are not supported by the kernel. Ignoring.");
1644 for (rule
= reply
; rule
; rule
= sd_netlink_message_next(rule
)) {
1647 m
->enumerating
= true;
1649 k
= manager_rtnl_process_rule(m
->rtnl
, rule
, m
);
1653 m
->enumerating
= false;
1659 int manager_address_pool_acquire(Manager
*m
, int family
, unsigned prefixlen
, union in_addr_union
*found
) {
1664 assert(prefixlen
> 0);
1667 LIST_FOREACH(address_pools
, p
, m
->address_pools
) {
1668 if (p
->family
!= family
)
1671 r
= address_pool_acquire(p
, prefixlen
, found
);
1679 Link
* manager_find_uplink(Manager
*m
, Link
*exclude
) {
1680 _cleanup_free_
struct local_address
*gateways
= NULL
;
1685 /* Looks for a suitable "uplink", via black magic: an
1686 * interface that is up and where the default route with the
1687 * highest priority points to. */
1689 n
= local_gateways(m
->rtnl
, 0, AF_UNSPEC
, &gateways
);
1691 log_warning_errno(n
, "Failed to determine list of default gateways: %m");
1695 for (i
= 0; i
< n
; i
++) {
1698 link
= hashmap_get(m
->links
, INT_TO_PTR(gateways
[i
].ifindex
));
1700 log_debug("Weird, found a gateway for a link we don't know. Ignoring.");
1704 if (link
== exclude
)
1707 if (link
->operstate
< LINK_OPERSTATE_ROUTABLE
)
1716 void manager_dirty(Manager
*manager
) {
1719 /* the serialized state in /run is no longer up-to-date */
1720 manager
->dirty
= true;
1723 static int set_hostname_handler(sd_bus_message
*m
, void *userdata
, sd_bus_error
*ret_error
) {
1724 Manager
*manager
= userdata
;
1725 const sd_bus_error
*e
;
1730 e
= sd_bus_message_get_error(m
);
1732 log_warning_errno(sd_bus_error_get_errno(e
), "Could not set hostname: %s", e
->message
);
1737 int manager_set_hostname(Manager
*m
, const char *hostname
) {
1740 log_debug("Setting transient hostname: '%s'", strna(hostname
));
1742 if (free_and_strdup(&m
->dynamic_hostname
, hostname
) < 0)
1745 if (!m
->bus
|| sd_bus_is_ready(m
->bus
) <= 0) {
1746 log_debug("Not connected to system bus, setting hostname later.");
1750 r
= sd_bus_call_method_async(
1753 "org.freedesktop.hostname1",
1754 "/org/freedesktop/hostname1",
1755 "org.freedesktop.hostname1",
1757 set_hostname_handler
,
1764 return log_error_errno(r
, "Could not set transient hostname: %m");
1769 static int set_timezone_handler(sd_bus_message
*m
, void *userdata
, sd_bus_error
*ret_error
) {
1770 Manager
*manager
= userdata
;
1771 const sd_bus_error
*e
;
1776 e
= sd_bus_message_get_error(m
);
1778 log_warning_errno(sd_bus_error_get_errno(e
), "Could not set timezone: %s", e
->message
);
1783 int manager_set_timezone(Manager
*m
, const char *tz
) {
1789 log_debug("Setting system timezone: '%s'", tz
);
1790 if (free_and_strdup(&m
->dynamic_timezone
, tz
) < 0)
1793 if (!m
->bus
|| sd_bus_is_ready(m
->bus
) <= 0) {
1794 log_debug("Not connected to system bus, setting timezone later.");
1798 r
= sd_bus_call_method_async(
1801 "org.freedesktop.timedate1",
1802 "/org/freedesktop/timedate1",
1803 "org.freedesktop.timedate1",
1805 set_timezone_handler
,
1811 return log_error_errno(r
, "Could not set timezone: %m");
1816 int manager_request_product_uuid(Manager
*m
, Link
*link
) {
1821 if (m
->has_product_uuid
)
1824 log_debug("Requesting product UUID");
1829 assert_se(duid
= link_get_duid(link
));
1831 r
= set_ensure_allocated(&m
->links_requesting_uuid
, NULL
);
1835 r
= set_ensure_allocated(&m
->duids_requesting_uuid
, NULL
);
1839 r
= set_put(m
->links_requesting_uuid
, link
);
1843 r
= set_put(m
->duids_requesting_uuid
, duid
);
1848 if (!m
->bus
|| sd_bus_is_ready(m
->bus
) <= 0) {
1849 log_debug("Not connected to system bus, requesting product UUID later.");
1853 r
= sd_bus_call_method_async(
1856 "org.freedesktop.hostname1",
1857 "/org/freedesktop/hostname1",
1858 "org.freedesktop.hostname1",
1860 get_product_uuid_handler
,
1865 return log_warning_errno(r
, "Failed to get product UUID: %m");