mirror of
https://github.com/systemd/systemd.git
synced 2024-11-06 08:26:52 +03:00
network: replace udev_device by sd_device
This commit is contained in:
parent
f55b0d3fd6
commit
51517f9e09
@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||||
|
|
||||||
#include "libudev.h"
|
#include "sd-device.h"
|
||||||
#include "sd-id128.h"
|
#include "sd-id128.h"
|
||||||
|
|
||||||
#include "dhcp-identifier.h"
|
#include "dhcp-identifier.h"
|
||||||
@ -8,7 +8,6 @@
|
|||||||
#include "network-internal.h"
|
#include "network-internal.h"
|
||||||
#include "siphash24.h"
|
#include "siphash24.h"
|
||||||
#include "sparse-endian.h"
|
#include "sparse-endian.h"
|
||||||
#include "udev-util.h"
|
|
||||||
#include "virt.h"
|
#include "virt.h"
|
||||||
|
|
||||||
#define SYSTEMD_PEN 43793
|
#define SYSTEMD_PEN 43793
|
||||||
@ -71,25 +70,23 @@ int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, void *_id) {
|
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
|
/* name is a pointer to memory in the sd_device struct, so must
|
||||||
have the same scope */
|
* have the same scope */
|
||||||
_cleanup_(udev_device_unrefp) struct udev_device *device = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
uint64_t id;
|
uint64_t id;
|
||||||
|
|
||||||
if (detect_container() <= 0) {
|
if (detect_container() <= 0) {
|
||||||
/* not in a container, udev will be around */
|
/* not in a container, udev will be around */
|
||||||
_cleanup_(udev_unrefp) struct udev *udev;
|
|
||||||
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
||||||
|
int initialized, r;
|
||||||
udev = udev_new();
|
|
||||||
if (!udev)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
sprintf(ifindex_str, "n%d", ifindex);
|
sprintf(ifindex_str, "n%d", ifindex);
|
||||||
device = udev_device_new_from_device_id(udev, ifindex_str);
|
if (sd_device_new_from_device_id(&device, ifindex_str) >= 0) {
|
||||||
if (device) {
|
r = sd_device_get_is_initialized(device, &initialized);
|
||||||
if (udev_device_get_is_initialized(device) <= 0)
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
if (!initialized)
|
||||||
/* not yet ready */
|
/* not yet ready */
|
||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
|
|
||||||
|
@ -23,24 +23,22 @@
|
|||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
#include "util.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;
|
const char *name, *field;
|
||||||
|
|
||||||
assert(device);
|
assert(device);
|
||||||
|
|
||||||
/* fetch some persistent data unique (on this machine) to this 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") {
|
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 (sd_device_get_property_value(device, field, &name) >= 0)
|
||||||
if (name)
|
|
||||||
return name;
|
return name;
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define HASH_KEY SD_ID128_MAKE(d3,1e,48,fa,90,fe,4b,4c,9d,af,d5,d7,a1,b1,2e,8a)
|
#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;
|
size_t l, sz = 0;
|
||||||
const char *name = NULL;
|
const char *name = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
@ -3,12 +3,12 @@
|
|||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "sd-device.h"
|
||||||
#include "sd-dhcp-lease.h"
|
#include "sd-dhcp-lease.h"
|
||||||
|
|
||||||
#include "condition.h"
|
#include "condition.h"
|
||||||
#include "conf-parser.h"
|
#include "conf-parser.h"
|
||||||
#include "set.h"
|
#include "set.h"
|
||||||
#include "udev.h"
|
|
||||||
|
|
||||||
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
|
#define LINK_BRIDGE_PORT_PRIORITY_INVALID 128
|
||||||
#define LINK_BRIDGE_PORT_PRIORITY_MAX 63
|
#define LINK_BRIDGE_PORT_PRIORITY_MAX 63
|
||||||
@ -38,8 +38,8 @@ CONFIG_PARSER_PROTOTYPE(config_parse_ifalias);
|
|||||||
CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
|
CONFIG_PARSER_PROTOTYPE(config_parse_iaid);
|
||||||
CONFIG_PARSER_PROTOTYPE(config_parse_bridge_port_priority);
|
CONFIG_PARSER_PROTOTYPE(config_parse_bridge_port_priority);
|
||||||
|
|
||||||
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);
|
||||||
const char *net_get_name(struct udev_device *device);
|
const char *net_get_name(sd_device *device);
|
||||||
|
|
||||||
void serialize_in_addrs(FILE *f, const struct in_addr *addresses, size_t size);
|
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);
|
int deserialize_in_addrs(struct in_addr **addresses, const char *string);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "stdio-util.h"
|
#include "stdio-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
|
#include "strv.h"
|
||||||
#include "unaligned.h"
|
#include "unaligned.h"
|
||||||
|
|
||||||
int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr) {
|
int sd_dhcp_lease_get_address(sd_dhcp_lease *lease, struct in_addr *addr) {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "stat-util.h"
|
#include "stat-util.h"
|
||||||
#include "string-table.h"
|
#include "string-table.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
|
#include "strv.h"
|
||||||
|
|
||||||
#include "netdev/bridge.h"
|
#include "netdev/bridge.h"
|
||||||
#include "netdev/bond.h"
|
#include "netdev/bond.h"
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "set.h"
|
#include "set.h"
|
||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
|
#include "strv.h"
|
||||||
#include "utf8.h"
|
#include "utf8.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
@ -202,14 +202,12 @@ int ipv4ll_configure(Link *link) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (link->udev_device) {
|
if (link->sd_device &&
|
||||||
r = net_get_unique_predictable_data(link->udev_device, &seed);
|
net_get_unique_predictable_data(link->sd_device, &seed) >= 0) {
|
||||||
if (r >= 0) {
|
|
||||||
r = sd_ipv4ll_set_address_seed(link->ipv4ll, seed);
|
r = sd_ipv4ll_set_address_seed(link->ipv4ll, seed);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
|
r = sd_ipv4ll_attach_event(link->ipv4ll, NULL, 0);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
#include "stdio-util.h"
|
#include "stdio-util.h"
|
||||||
#include "string-table.h"
|
#include "string-table.h"
|
||||||
#include "udev-util.h"
|
#include "strv.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "virt.h"
|
#include "virt.h"
|
||||||
|
|
||||||
@ -549,7 +549,7 @@ static void link_free(Link *link) {
|
|||||||
(void) unlink(link->state_file);
|
(void) unlink(link->state_file);
|
||||||
free(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_FOREACH (carrier, link->bound_to_links, i)
|
||||||
hashmap_remove(link->bound_to_links, INT_TO_PTR(carrier->ifindex));
|
hashmap_remove(link->bound_to_links, INT_TO_PTR(carrier->ifindex));
|
||||||
@ -2908,7 +2908,7 @@ static int link_initialized_and_synced(sd_netlink *rtnl, sd_netlink_message *m,
|
|||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (!link->network) {
|
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);
|
&link->mac, &network);
|
||||||
if (r == -ENOENT) {
|
if (r == -ENOENT) {
|
||||||
link_enter_unmanaged(link);
|
link_enter_unmanaged(link);
|
||||||
@ -2946,7 +2946,7 @@ static int link_initialized_and_synced(sd_netlink *rtnl, sd_netlink_message *m,
|
|||||||
return 1;
|
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;
|
_cleanup_(sd_netlink_message_unrefp) sd_netlink_message *req = NULL;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -2958,12 +2958,12 @@ int link_initialized(Link *link, struct udev_device *device) {
|
|||||||
if (link->state != LINK_STATE_PENDING)
|
if (link->state != LINK_STATE_PENDING)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (link->udev_device)
|
if (link->sd_device)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
log_link_debug(link, "udev initialized link");
|
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
|
/* 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,
|
* processed the NEWLINK messages with the latest state. Do a GETLINK,
|
||||||
@ -3176,10 +3176,10 @@ ipv4ll_address_fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
|
int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
|
||||||
Link *link;
|
_cleanup_(sd_device_unrefp) sd_device *device = NULL;
|
||||||
_cleanup_(udev_device_unrefp) struct udev_device *device = NULL;
|
|
||||||
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
char ifindex_str[2 + DECIMAL_STR_MAX(int)];
|
||||||
int r;
|
int initialized, r;
|
||||||
|
Link *link;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(m->rtnl);
|
assert(m->rtnl);
|
||||||
@ -3201,13 +3201,18 @@ int link_add(Manager *m, sd_netlink_message *message, Link **ret) {
|
|||||||
if (detect_container() <= 0) {
|
if (detect_container() <= 0) {
|
||||||
/* not in a container, udev will be around */
|
/* not in a container, udev will be around */
|
||||||
sprintf(ifindex_str, "n%d", link->ifindex);
|
sprintf(ifindex_str, "n%d", link->ifindex);
|
||||||
device = udev_device_new_from_device_id(m->udev, ifindex_str);
|
r = sd_device_new_from_device_id(&device, ifindex_str);
|
||||||
if (!device) {
|
if (r < 0) {
|
||||||
r = log_link_warning_errno(link, errno, "Could not find udev device: %m");
|
log_link_warning_errno(link, r, "Could not find device: %m");
|
||||||
goto failed;
|
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 */
|
/* not yet ready */
|
||||||
log_link_debug(link, "link pending udev initialization...");
|
log_link_debug(link, "link pending udev initialization...");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <endian.h>
|
#include <endian.h>
|
||||||
|
|
||||||
#include "sd-bus.h"
|
#include "sd-bus.h"
|
||||||
|
#include "sd-device.h"
|
||||||
#include "sd-dhcp-client.h"
|
#include "sd-dhcp-client.h"
|
||||||
#include "sd-dhcp-server.h"
|
#include "sd-dhcp-server.h"
|
||||||
#include "sd-dhcp6-client.h"
|
#include "sd-dhcp6-client.h"
|
||||||
@ -57,7 +58,7 @@ typedef struct Link {
|
|||||||
struct ether_addr mac;
|
struct ether_addr mac;
|
||||||
struct in6_addr ipv6ll_address;
|
struct in6_addr ipv6ll_address;
|
||||||
uint32_t mtu;
|
uint32_t mtu;
|
||||||
struct udev_device *udev_device;
|
sd_device *sd_device;
|
||||||
|
|
||||||
unsigned flags;
|
unsigned flags;
|
||||||
uint8_t kernel_operstate;
|
uint8_t kernel_operstate;
|
||||||
@ -136,7 +137,7 @@ int link_address_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *u
|
|||||||
int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
|
int link_route_remove_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata);
|
||||||
|
|
||||||
void link_enter_failed(Link *link);
|
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);
|
void link_check_ready(Link *link);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "bus-util.h"
|
#include "bus-util.h"
|
||||||
#include "networkd-manager.h"
|
#include "networkd-manager.h"
|
||||||
|
#include "strv.h"
|
||||||
|
|
||||||
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState);
|
static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState);
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@
|
|||||||
#include "ordered-set.h"
|
#include "ordered-set.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
#include "set.h"
|
#include "set.h"
|
||||||
#include "udev-util.h"
|
|
||||||
#include "virt.h"
|
#include "virt.h"
|
||||||
|
|
||||||
/* use 8 MB for receive socket kernel queue. */
|
/* use 8 MB for receive socket kernel queue. */
|
||||||
@ -183,18 +182,20 @@ int manager_connect_bus(Manager *m) {
|
|||||||
return 0;
|
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;
|
Link *link = NULL;
|
||||||
int r, ifindex;
|
int r, ifindex;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(device);
|
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;
|
return 0;
|
||||||
|
|
||||||
ifindex = udev_device_get_ifindex(device);
|
r = sd_device_get_ifindex(device, &ifindex);
|
||||||
if (ifindex <= 0) {
|
if (r < 0 || ifindex <= 0) {
|
||||||
log_debug("Ignoring udev ADD event for device with invalid ifindex");
|
log_debug("Ignoring udev ADD event for device with invalid ifindex");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -215,11 +216,12 @@ static int manager_udev_process_link(Manager *m, struct udev_device *device) {
|
|||||||
static int manager_dispatch_link_udev(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
|
static int manager_dispatch_link_udev(sd_event_source *source, int fd, uint32_t revents, void *userdata) {
|
||||||
Manager *m = userdata;
|
Manager *m = userdata;
|
||||||
struct udev_monitor *monitor = m->udev_monitor;
|
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);
|
r = udev_monitor_receive_sd_device(monitor, &device);
|
||||||
if (!device)
|
if (r < 0)
|
||||||
return -ENOMEM;
|
return r;
|
||||||
|
|
||||||
(void) manager_udev_process_link(m, device);
|
(void) manager_udev_process_link(m, device);
|
||||||
|
|
||||||
@ -235,11 +237,7 @@ static int manager_connect_udev(Manager *m) {
|
|||||||
if (detect_container() > 0)
|
if (detect_container() > 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
m->udev = udev_new();
|
m->udev_monitor = udev_monitor_new_from_netlink(NULL, "udev");
|
||||||
if (!m->udev)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
m->udev_monitor = udev_monitor_new_from_netlink(m->udev, "udev");
|
|
||||||
if (!m->udev_monitor)
|
if (!m->udev_monitor)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
@ -1481,7 +1479,6 @@ void manager_free(Manager *m) {
|
|||||||
|
|
||||||
sd_event_source_unref(m->udev_event_source);
|
sd_event_source_unref(m->udev_event_source);
|
||||||
udev_monitor_unref(m->udev_monitor);
|
udev_monitor_unref(m->udev_monitor);
|
||||||
udev_unref(m->udev);
|
|
||||||
|
|
||||||
sd_bus_unref(m->bus);
|
sd_bus_unref(m->bus);
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
#include "sd-event.h"
|
#include "sd-event.h"
|
||||||
#include "sd-netlink.h"
|
#include "sd-netlink.h"
|
||||||
#include "sd-resolve.h"
|
#include "sd-resolve.h"
|
||||||
#include "udev.h"
|
#include "libudev.h"
|
||||||
|
|
||||||
#include "dhcp-identifier.h"
|
#include "dhcp-identifier.h"
|
||||||
#include "hashmap.h"
|
#include "hashmap.h"
|
||||||
@ -26,7 +26,6 @@ struct Manager {
|
|||||||
sd_event *event;
|
sd_event *event;
|
||||||
sd_resolve *resolve;
|
sd_resolve *resolve;
|
||||||
sd_bus *bus;
|
sd_bus *bus;
|
||||||
struct udev *udev;
|
|
||||||
struct udev_monitor *udev_monitor;
|
struct udev_monitor *udev_monitor;
|
||||||
sd_event_source *udev_event_source;
|
sd_event_source *udev_event_source;
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
#include "networkd-ndisc.h"
|
#include "networkd-ndisc.h"
|
||||||
#include "networkd-route.h"
|
#include "networkd-route.h"
|
||||||
|
#include "strv.h"
|
||||||
|
|
||||||
#define NDISC_DNSSL_MAX 64U
|
#define NDISC_DNSSL_MAX 64U
|
||||||
#define NDISC_RDNSS_MAX 64U
|
#define NDISC_RDNSS_MAX 64U
|
||||||
|
@ -450,26 +450,25 @@ int network_get_by_name(Manager *manager, const char *name, Network **ret) {
|
|||||||
return 0;
|
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,
|
const char *ifname, const struct ether_addr *address,
|
||||||
Network **ret) {
|
Network **ret) {
|
||||||
Network *network;
|
|
||||||
struct udev_device *parent;
|
|
||||||
const char *path = NULL, *parent_driver = NULL, *driver = NULL, *devtype = NULL;
|
const char *path = NULL, *parent_driver = NULL, *driver = NULL, *devtype = NULL;
|
||||||
|
sd_device *parent;
|
||||||
|
Network *network;
|
||||||
|
|
||||||
assert(manager);
|
assert(manager);
|
||||||
assert(ret);
|
assert(ret);
|
||||||
|
|
||||||
if (device) {
|
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 (sd_device_get_parent(device, &parent) >= 0)
|
||||||
if (parent)
|
(void) sd_device_get_driver(parent, &parent_driver);
|
||||||
parent_driver = udev_device_get_driver(parent);
|
|
||||||
|
|
||||||
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) {
|
LIST_FOREACH(networks, network, manager->networks) {
|
||||||
@ -484,8 +483,7 @@ int network_get(Manager *manager, struct udev_device *device,
|
|||||||
const char *attr;
|
const char *attr;
|
||||||
uint8_t name_assign_type = NET_NAME_UNKNOWN;
|
uint8_t name_assign_type = NET_NAME_UNKNOWN;
|
||||||
|
|
||||||
attr = udev_device_get_sysattr_value(device, "name_assign_type");
|
if (sd_device_get_sysattr_value(device, "name_assign_type", &attr) >= 0)
|
||||||
if (attr)
|
|
||||||
(void) safe_atou8(attr, &name_assign_type);
|
(void) safe_atou8(attr, &name_assign_type);
|
||||||
|
|
||||||
if (name_assign_type == NET_NAME_ENUM)
|
if (name_assign_type == NET_NAME_ENUM)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "sd-bus.h"
|
#include "sd-bus.h"
|
||||||
#include "udev.h"
|
#include "sd-device.h"
|
||||||
|
|
||||||
#include "condition.h"
|
#include "condition.h"
|
||||||
#include "conf-parser.h"
|
#include "conf-parser.h"
|
||||||
@ -268,7 +268,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Network*, network_free);
|
|||||||
int network_load(Manager *manager);
|
int network_load(Manager *manager);
|
||||||
|
|
||||||
int network_get_by_name(Manager *manager, const char *name, Network **ret);
|
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);
|
int network_apply(Network *network, Link *link);
|
||||||
void network_apply_anonymize_if_set(Network *network);
|
void network_apply_anonymize_if_set(Network *network);
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "sd-radv.h"
|
#include "sd-radv.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
|
#include "strv.h"
|
||||||
|
|
||||||
int config_parse_router_prefix_delegation(
|
int config_parse_router_prefix_delegation(
|
||||||
const char *unit,
|
const char *unit,
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "parse-util.h"
|
#include "parse-util.h"
|
||||||
#include "socket-util.h"
|
#include "socket-util.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
|
#include "strv.h"
|
||||||
|
|
||||||
int routing_policy_rule_new(RoutingPolicyRule **ret) {
|
int routing_policy_rule_new(RoutingPolicyRule **ret) {
|
||||||
RoutingPolicyRule *rule;
|
RoutingPolicyRule *rule;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "sd-event.h"
|
#include "sd-event.h"
|
||||||
|
|
||||||
#include "capability-util.h"
|
#include "capability-util.h"
|
||||||
|
#include "mkdir.h"
|
||||||
#include "networkd-conf.h"
|
#include "networkd-conf.h"
|
||||||
#include "networkd-manager.h"
|
#include "networkd-manager.h"
|
||||||
#include "signal-util.h"
|
#include "signal-util.h"
|
||||||
|
@ -2,13 +2,14 @@
|
|||||||
|
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
|
|
||||||
|
#include "sd-device.h"
|
||||||
|
|
||||||
#include "alloc-util.h"
|
#include "alloc-util.h"
|
||||||
#include "dhcp-lease-internal.h"
|
#include "dhcp-lease-internal.h"
|
||||||
#include "hostname-util.h"
|
#include "hostname-util.h"
|
||||||
#include "network-internal.h"
|
#include "network-internal.h"
|
||||||
#include "networkd-manager.h"
|
#include "networkd-manager.h"
|
||||||
#include "string-util.h"
|
#include "string-util.h"
|
||||||
#include "udev-util.h"
|
|
||||||
|
|
||||||
static void test_deserialize_in_addr(void) {
|
static void test_deserialize_in_addr(void) {
|
||||||
_cleanup_free_ struct in_addr *addresses = NULL;
|
_cleanup_free_ struct in_addr *addresses = NULL;
|
||||||
@ -117,7 +118,7 @@ static int test_load_config(Manager *manager) {
|
|||||||
return 0;
|
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;
|
Network *network;
|
||||||
const struct ether_addr mac = {};
|
const struct ether_addr mac = {};
|
||||||
|
|
||||||
@ -219,9 +220,8 @@ static void test_dhcp_hostname_shorten_overlong(void) {
|
|||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
_cleanup_(manager_freep) Manager *manager = NULL;
|
_cleanup_(manager_freep) Manager *manager = NULL;
|
||||||
_cleanup_(udev_unrefp) struct udev *udev = NULL;
|
_cleanup_(sd_device_unrefp) sd_device *loopback = NULL;
|
||||||
_cleanup_(udev_device_unrefp) struct udev_device *loopback = NULL;
|
int ifindex, r;
|
||||||
int r;
|
|
||||||
|
|
||||||
test_deserialize_in_addr();
|
test_deserialize_in_addr();
|
||||||
test_deserialize_dhcp_routes();
|
test_deserialize_dhcp_routes();
|
||||||
@ -234,12 +234,10 @@ int main(void) {
|
|||||||
if (r == -EPERM)
|
if (r == -EPERM)
|
||||||
return EXIT_TEST_SKIP;
|
return EXIT_TEST_SKIP;
|
||||||
|
|
||||||
udev = udev_new();
|
assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
|
||||||
assert_se(udev);
|
|
||||||
|
|
||||||
loopback = udev_device_new_from_syspath(udev, "/sys/class/net/lo");
|
|
||||||
assert_se(loopback);
|
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);
|
test_network_get(manager, loopback);
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "manager.h"
|
#include "manager.h"
|
||||||
#include "netlink-util.h"
|
#include "netlink-util.h"
|
||||||
#include "network-internal.h"
|
#include "network-internal.h"
|
||||||
|
#include "strv.h"
|
||||||
#include "time-util.h"
|
#include "time-util.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "conf-parser.h"
|
#include "conf-parser.h"
|
||||||
#include "ethtool-util.h"
|
#include "ethtool-util.h"
|
||||||
#include "fd-util.h"
|
#include "fd-util.h"
|
||||||
|
#include "libudev-device-internal.h"
|
||||||
#include "libudev-private.h"
|
#include "libudev-private.h"
|
||||||
#include "link-config.h"
|
#include "link-config.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
@ -332,7 +333,7 @@ static int get_mac(struct udev_device *device, bool want_random,
|
|||||||
else {
|
else {
|
||||||
uint64_t result;
|
uint64_t result;
|
||||||
|
|
||||||
r = net_get_unique_predictable_data(device, &result);
|
r = net_get_unique_predictable_data(device->device, &result);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user