1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

network,udev: make net_match_config() take sd_device

This commit is contained in:
Yu Watanabe 2019-06-23 01:08:51 +09:00
parent 54a8423788
commit b38de0e9cc
4 changed files with 23 additions and 35 deletions

View File

@ -106,12 +106,24 @@ bool net_match_config(Set *match_mac,
char * const *match_drivers,
char * const *match_types,
char * const *match_names,
sd_device *device,
const struct ether_addr *dev_mac,
const char *dev_path,
const char *dev_driver,
const char *dev_type,
const char *dev_name) {
const char *dev_path = NULL, *dev_driver = NULL, *dev_type = NULL, *mac_str;
if (device) {
(void) sd_device_get_property_value(device, "ID_PATH", &dev_path);
(void) sd_device_get_property_value(device, "ID_NET_DRIVER", &dev_driver);
(void) sd_device_get_devtype(device, &dev_type);
if (!dev_name)
(void) sd_device_get_sysname(device, &dev_name);
if (!dev_mac &&
sd_device_get_sysattr_value(device, "address", &mac_str) >= 0)
dev_mac = ether_aton(mac_str);
}
if (match_mac && (!dev_mac || !set_contains(match_mac, dev_mac)))
return false;

View File

@ -19,10 +19,8 @@ bool net_match_config(Set *match_mac,
char * const *match_driver,
char * const *match_type,
char * const *match_name,
sd_device *device,
const struct ether_addr *dev_mac,
const char *dev_path,
const char *dev_driver,
const char *dev_type,
const char *dev_name);
CONFIG_PARSER_PROTOTYPE(config_parse_net_condition);

View File

@ -607,26 +607,17 @@ int network_get_by_name(Manager *manager, const char *name, Network **ret) {
int network_get(Manager *manager, sd_device *device,
const char *ifname, const struct ether_addr *address,
Network **ret) {
const char *path = NULL, *driver = NULL, *devtype = NULL;
Network *network;
Iterator i;
assert(manager);
assert(ret);
if (device) {
(void) sd_device_get_property_value(device, "ID_PATH", &path);
(void) sd_device_get_property_value(device, "ID_NET_DRIVER", &driver);
(void) sd_device_get_devtype(device, &devtype);
}
ORDERED_HASHMAP_FOREACH(network, manager->networks, i)
if (net_match_config(network->match_mac, network->match_path,
network->match_driver, network->match_type,
network->match_name,
address, path, driver, devtype, ifname)) {
device, address, ifname)) {
if (network->match_name && device) {
const char *attr;
uint8_t name_assign_type = NET_NAME_UNKNOWN;

View File

@ -240,42 +240,29 @@ int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret)
assert(ret);
LIST_FOREACH(links, link, ctx->links) {
const char *address = NULL, *id_path = NULL, *id_net_driver = NULL, *devtype = NULL, *sysname = NULL;
(void) sd_device_get_sysattr_value(device, "address", &address);
(void) sd_device_get_property_value(device, "ID_PATH", &id_path);
(void) sd_device_get_property_value(device, "ID_NET_DRIVER", &id_net_driver);
(void) sd_device_get_devtype(device, &devtype);
(void) sd_device_get_sysname(device, &sysname);
if (net_match_config(link->match_mac, link->match_path, link->match_driver,
link->match_type, link->match_name,
address ? ether_aton(address) : NULL,
id_path,
id_net_driver,
devtype,
sysname)) {
device, NULL, NULL)) {
if (link->match_name) {
unsigned name_assign_type = NET_NAME_UNKNOWN;
(void) link_unsigned_attribute(device, "name_assign_type", &name_assign_type);
if (name_assign_type == NET_NAME_ENUM && !strv_contains(link->match_name, "*")) {
log_warning("Config file %s applies to device based on potentially unpredictable interface name '%s'",
link->filename, sysname);
log_device_warning(device, "Config file %s applies to device based on potentially unpredictable interface name",
link->filename);
*ret = link;
return 0;
} else if (name_assign_type == NET_NAME_RENAMED) {
log_warning("Config file %s matches device based on renamed interface name '%s', ignoring",
link->filename, sysname);
log_device_warning(device, "Config file %s matches device based on renamed interface name, ignoring",
link->filename);
continue;
}
}
log_debug("Config file %s applies to device %s",
link->filename, sysname);
log_device_debug(device, "Config file %s is applied", link->filename);
*ret = link;
return 0;