/* SPDX-License-Identifier: LGPL-2.1+ */
-#include "libudev.h"
+#include "sd-device.h"
#include "sd-id128.h"
#include "dhcp-identifier.h"
#include "network-internal.h"
#include "siphash24.h"
#include "sparse-endian.h"
-#include "udev-util.h"
#include "virt.h"
#define SYSTEMD_PEN 43793
}
int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_id) {
- /* name is a pointer to memory in the udev_device struct, so must
- have the same scope */
- _cleanup_(udev_device_unrefp) struct udev_device *device = NULL;
+ /* name is a pointer to memory in the sd_device struct, so must
+ * have the same scope */
+ _cleanup_(sd_device_unrefp) sd_device *device = NULL;
const char *name = NULL;
uint64_t id;
if (detect_container() <= 0) {
/* not in a container, udev will be around */
- _cleanup_(udev_unrefp) struct udev *udev;
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
-
- udev = udev_new();
- if (!udev)
- return -ENOMEM;
+ int initialized, r;
sprintf(ifindex_str, "n%d", ifindex);
- device = udev_device_new_from_device_id(udev, ifindex_str);
- if (device) {
- if (udev_device_get_is_initialized(device) <= 0)
+ if (sd_device_new_from_device_id(&device, ifindex_str) >= 0) {
+ r = sd_device_get_is_initialized(device, &initialized);
+ if (r < 0)
+ return r;
+ if (!initialized)
/* not yet ready */
return -EBUSY;
#include "utf8.h"
#include "util.h"
-const char *net_get_name(struct udev_device *device) {
+const char *net_get_name(sd_device *device) {
const char *name, *field;
assert(device);
/* fetch some persistent data unique (on this machine) to this device */
- FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC") {
- name = udev_device_get_property_value(device, field);
- if (name)
+ FOREACH_STRING(field, "ID_NET_NAME_ONBOARD", "ID_NET_NAME_SLOT", "ID_NET_NAME_PATH", "ID_NET_NAME_MAC")
+ if (sd_device_get_property_value(device, field, &name) >= 0)
return name;
- }
return NULL;
}
#define HASH_KEY SD_ID128_MAKE(d3,1e,48,fa,90,fe,4b,4c,9d,af,d5,d7,a1,b1,2e,8a)
-int net_get_unique_predictable_data(struct udev_device *device, uint64_t *result) {
+int net_get_unique_predictable_data(sd_device *device, uint64_t *result) {
size_t l, sz = 0;
const char *name = NULL;
int r;
#include <stdbool.h>
+#include "sd-device.h"
#include "sd-dhcp-lease.h"
#include "condition.h"
#include "conf-parser.h"
#include "set.h"
-#include "udev.h"
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
#define LINK_BRIDGE_PORT_PRIORITY_MAX 63
CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
CONFIG_PARSER_PROTOTYPE(config_parse_bridge_port_priority);
-int net_get_unique_predictable_data(struct udev_device *device, uint64_t *result);
-const char *net_get_name(struct udev_device *device);
+int net_get_unique_predictable_data(sd_device *device, uint64_t *result);
+const char *net_get_name(sd_device *device);
void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size);
int deserialize_in_addrs(struct in_addr **addresses, const char *string);
#include "parse-util.h"
#include "stdio-util.h"
#include "string-util.h"
+#include "strv.h"
#include "unaligned.h"
int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr) {
#include "stat-util.h"
#include "string-table.h"
#include "string-util.h"
+#include "strv.h"
#include "netdev/bridge.h"
#include "netdev/bond.h"
#include "set.h"
#include "socket-util.h"
#include "string-util.h"
+#include "strv.h"
#include "utf8.h"
#include "util.h"
return r;
}
- if (link->udev_device) {
- r = net_get_unique_predictable_data(link->udev_device, &seed);
- if (r >= 0) {
- r = sd_ipv4ll_set_address_seed(link->ipv4ll, seed);
- if (r < 0)
- return r;
- }
+ if (link->sd_device &&
+ net_get_unique_predictable_data(link->sd_device, &seed) >= 0) {
+ r = sd_ipv4ll_set_address_seed(link->ipv4ll, seed);
+ if (r < 0)
+ return r;
}
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
#include "socket-util.h"
#include "stdio-util.h"
#include "string-table.h"
-#include "udev-util.h"
+#include "strv.h"
#include "util.h"
#include "virt.h"
(void) unlink(link->state_file);
free(link->state_file);
- udev_device_unref(link->udev_device);
+ sd_device_unref(link->sd_device);
HASHMAP_FOREACH (carrier, link->bound_to_links, i)
hashmap_remove(link->bound_to_links, INT_TO_PTR(carrier->ifindex));
return r;
if (!link->network) {
- r = network_get(link->manager, link->udev_device, link->ifname,
+ r = network_get(link->manager, link->sd_device, link->ifname,
&link->mac, &network);
if (r == -ENOENT) {
link_enter_unmanaged(link);
return 1;
}
-int link_initialized(Link *link, struct udev_device *device) {
+int link_initialized(Link *link, sd_device *device) {
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
int r;
if (link->state != LINK_STATE_PENDING)
return 0;
- if (link->udev_device)
+ if (link->sd_device)
return 0;
log_link_debug(link, "udev initialized link");
- link->udev_device = udev_device_ref(device);
+ link->sd_device = sd_device_ref(device);
/* udev has initialized the link, but we don't know if we have yet
* processed the NEWLINK messages with the latest state. Do a GETLINK,
}
int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
- Link *link;
- _cleanup_(udev_device_unrefp) struct udev_device *device = NULL;
+ _cleanup_(sd_device_unrefp) sd_device *device = NULL;
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
- int r;
+ int initialized, r;
+ Link *link;
assert(m);
assert(m->rtnl);
if (detect_container() <= 0) {
/* not in a container, udev will be around */
sprintf(ifindex_str, "n%d", link->ifindex);
- device = udev_device_new_from_device_id(m->udev, ifindex_str);
- if (!device) {
- r = log_link_warning_errno(link, errno, "Could not find udev device: %m");
+ r = sd_device_new_from_device_id(&device, ifindex_str);
+ if (r < 0) {
+ log_link_warning_errno(link, r, "Could not find device: %m");
goto failed;
}
- if (udev_device_get_is_initialized(device) <= 0) {
+ r = sd_device_get_is_initialized(device, &initialized);
+ if (r < 0) {
+ log_link_warning_errno(link, r, "Could not determine whether the device is initialized or not: %m");
+ goto failed;
+ }
+ if (!initialized) {
/* not yet ready */
log_link_debug(link, "link pending udev initialization...");
return 0;
#include <endian.h>
#include "sd-bus.h"
+#include "sd-device.h"
#include "sd-dhcp-client.h"
#include "sd-dhcp-server.h"
#include "sd-dhcp6-client.h"
struct ether_addr mac;
struct in6_addr ipv6ll_address;
uint32_t mtu;
- struct udev_device *udev_device;
+ sd_device *sd_device;
unsigned flags;
uint8_t kernel_operstate;
int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
void link_enter_failed(Link *link);
-int link_initialized(Link *link, struct udev_device *device);
+int link_initialized(Link *link, sd_device *device);
void link_check_ready(Link *link);
#include "alloc-util.h"
#include "bus-util.h"
#include "networkd-manager.h"
+#include "strv.h"
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState);
#include "ordered-set.h"
#include "path-util.h"
#include "set.h"
-#include "udev-util.h"
#include "virt.h"
/* use 8 MB for receive socket kernel queue. */
return 0;
}
-static int manager_udev_process_link(Manager *m, struct udev_device *device) {
+static int manager_udev_process_link(Manager *m, sd_device *device) {
+ const char *action;
Link *link = NULL;
int r, ifindex;
assert(m);
assert(device);
- if (!streq_ptr(udev_device_get_action(device), "add"))
+ r = sd_device_get_property_value(device, "ACTION", &action);
+ if (r < 0 || !streq_ptr(action, "add"))
return 0;
- ifindex = udev_device_get_ifindex(device);
- if (ifindex <= 0) {
+ r = sd_device_get_ifindex(device, &ifindex);
+ if (r < 0 || ifindex <= 0) {
log_debug("Ignoring udev ADD event for device with invalid ifindex");
return 0;
}
static int manager_dispatch_link_udev(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
Manager *m = userdata;
struct udev_monitor *monitor = m->udev_monitor;
- _cleanup_(udev_device_unrefp) struct udev_device *device = NULL;
+ _cleanup_(sd_device_unrefp) sd_device *device = NULL;
+ int r;
- device = udev_monitor_receive_device(monitor);
- if (!device)
- return -ENOMEM;
+ r = udev_monitor_receive_sd_device(monitor, &device);
+ if (r < 0)
+ return r;
(void) manager_udev_process_link(m, device);
if (detect_container() > 0)
return 0;
- m->udev = udev_new();
- if (!m->udev)
- return -ENOMEM;
-
- m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
+ m->udev_monitor = udev_monitor_new_from_netlink(NULL, "udev");
if (!m->udev_monitor)
return -ENOMEM;
sd_event_source_unref(m->udev_event_source);
udev_monitor_unref(m->udev_monitor);
- udev_unref(m->udev);
sd_bus_unref(m->bus);
#include "sd-event.h"
#include "sd-netlink.h"
#include "sd-resolve.h"
-#include "udev.h"
+#include "libudev.h"
#include "dhcp-identifier.h"
#include "hashmap.h"
sd_event *event;
sd_resolve *resolve;
sd_bus *bus;
- struct udev *udev;
struct udev_monitor *udev_monitor;
sd_event_source *udev_event_source;
#include "networkd-ndisc.h"
#include "networkd-route.h"
+#include "strv.h"
#define NDISC_DNSSL_MAX 64U
#define NDISC_RDNSS_MAX 64U
return 0;
}
-int network_get(Manager *manager, struct udev_device *device,
+int network_get(Manager *manager, sd_device *device,
const char *ifname, const struct ether_addr *address,
Network **ret) {
- Network *network;
- struct udev_device *parent;
const char *path = NULL, *parent_driver = NULL, *driver = NULL, *devtype = NULL;
+ sd_device *parent;
+ Network *network;
assert(manager);
assert(ret);
if (device) {
- path = udev_device_get_property_value(device, "ID_PATH");
+ (void) sd_device_get_property_value(device, "ID_PATH", &path);
- parent = udev_device_get_parent(device);
- if (parent)
- parent_driver = udev_device_get_driver(parent);
+ if (sd_device_get_parent(device, &parent) >= 0)
+ (void) sd_device_get_driver(parent, &parent_driver);
- driver = udev_device_get_property_value(device, "ID_NET_DRIVER");
+ (void) sd_device_get_property_value(device, "ID_NET_DRIVER", &driver);
- devtype = udev_device_get_devtype(device);
+ (void) sd_device_get_devtype(device, &devtype);
}
LIST_FOREACH(networks, network, manager->networks) {
const char *attr;
uint8_t name_assign_type = NET_NAME_UNKNOWN;
- attr = udev_device_get_sysattr_value(device, "name_assign_type");
- if (attr)
+ if (sd_device_get_sysattr_value(device, "name_assign_type", &attr) >= 0)
(void) safe_atou8(attr, &name_assign_type);
if (name_assign_type == NET_NAME_ENUM)
#pragma once
#include "sd-bus.h"
-#include "udev.h"
+#include "sd-device.h"
#include "condition.h"
#include "conf-parser.h"
int network_load(Manager *manager);
int network_get_by_name(Manager *manager, const char *name, Network **ret);
-int network_get(Manager *manager, struct udev_device *device, const char *ifname, const struct ether_addr *mac, Network **ret);
+int network_get(Manager *manager, sd_device *device, const char *ifname, const struct ether_addr *mac, Network **ret);
int network_apply(Network *network, Link *link);
void network_apply_anonymize_if_set(Network *network);
#include "parse-util.h"
#include "sd-radv.h"
#include "string-util.h"
+#include "strv.h"
int config_parse_router_prefix_delegation(
const char *unit,
#include "parse-util.h"
#include "socket-util.h"
#include "string-util.h"
+#include "strv.h"
int routing_policy_rule_new(RoutingPolicyRule **ret) {
RoutingPolicyRule *rule;
#include "sd-event.h"
#include "capability-util.h"
+#include "mkdir.h"
#include "networkd-conf.h"
#include "networkd-manager.h"
#include "signal-util.h"
#include <sys/param.h>
+#include "sd-device.h"
+
#include "alloc-util.h"
#include "dhcp-lease-internal.h"
#include "hostname-util.h"
#include "network-internal.h"
#include "networkd-manager.h"
#include "string-util.h"
-#include "udev-util.h"
static void test_deserialize_in_addr(void) {
_cleanup_free_ struct in_addr *addresses = NULL;
return 0;
}
-static void test_network_get(Manager *manager, struct udev_device *loopback) {
+static void test_network_get(Manager *manager, sd_device *loopback) {
Network *network;
const struct ether_addr mac = {};
int main(void) {
_cleanup_(manager_freep) Manager *manager = NULL;
- _cleanup_(udev_unrefp) struct udev *udev = NULL;
- _cleanup_(udev_device_unrefp) struct udev_device *loopback = NULL;
- int r;
+ _cleanup_(sd_device_unrefp) sd_device *loopback = NULL;
+ int ifindex, r;
test_deserialize_in_addr();
test_deserialize_dhcp_routes();
if (r == -EPERM)
return EXIT_TEST_SKIP;
- udev = udev_new();
- assert_se(udev);
-
- loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
+ assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
assert_se(loopback);
- assert_se(udev_device_get_ifindex(loopback) == 1);
+ assert_se(sd_device_get_ifindex(loopback, &ifindex) >= 0);
+ assert_se(ifindex == 1);
test_network_get(manager, loopback);
#include "manager.h"
#include "netlink-util.h"
#include "network-internal.h"
+#include "strv.h"
#include "time-util.h"
#include "util.h"
#include "conf-parser.h"
#include "ethtool-util.h"
#include "fd-util.h"
+#include "libudev-device-internal.h"
#include "libudev-private.h"
#include "link-config.h"
#include "log.h"
else {
uint64_t result;
- r = net_get_unique_predictable_data(device, &result);
+ r = net_get_unique_predictable_data(device->device, &result);
if (r < 0)
return r;