mirror of
https://github.com/systemd/systemd.git
synced 2024-12-25 01:34:28 +03:00
udev,network: make link_get_type_string() return negative errno on failure
And make net_match_config() propagate the error.
This commit is contained in:
parent
170e88c8e3
commit
1a3caa49d7
@ -119,24 +119,31 @@ int parse_operational_state_range(const char *str, LinkOperationalStateRange *ou
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *link_get_type_string(sd_device *device, unsigned short iftype) {
|
||||
int link_get_type_string(sd_device *device, unsigned short iftype, char **ret) {
|
||||
const char *t;
|
||||
char *p;
|
||||
|
||||
if (device &&
|
||||
sd_device_get_devtype(device, &t) >= 0 &&
|
||||
!isempty(t))
|
||||
return strdup(t);
|
||||
!isempty(t)) {
|
||||
p = strdup(t);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
*ret = p;
|
||||
return 0;
|
||||
}
|
||||
|
||||
t = arphrd_to_name(iftype);
|
||||
if (!t)
|
||||
return NULL;
|
||||
return -ENOENT;
|
||||
|
||||
p = strdup(t);
|
||||
if (!p)
|
||||
return NULL;
|
||||
return -ENOMEM;
|
||||
|
||||
return ascii_strlower(p);
|
||||
*ret = ascii_strlower(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *net_get_name_persistent(sd_device *device) {
|
||||
|
@ -76,6 +76,6 @@ typedef struct LinkOperationalStateRange {
|
||||
|
||||
int parse_operational_state_range(const char *str, LinkOperationalStateRange *out);
|
||||
|
||||
char *link_get_type_string(sd_device *device, unsigned short iftype);
|
||||
int link_get_type_string(sd_device *device, unsigned short iftype, char **ret);
|
||||
int net_get_unique_predictable_data(sd_device *device, bool use_sysname, uint64_t *result);
|
||||
const char *net_get_name_persistent(sd_device *device);
|
||||
|
@ -715,7 +715,9 @@ static int list_links(int argc, char *argv[], void *userdata) {
|
||||
setup_state = strdup("unmanaged");
|
||||
setup_state_to_color(setup_state, &on_color_setup, NULL);
|
||||
|
||||
t = link_get_type_string(links[i].sd_device, links[i].iftype);
|
||||
r = link_get_type_string(links[i].sd_device, links[i].iftype, &t);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
|
||||
r = table_add_many(table,
|
||||
TABLE_INT, links[i].ifindex,
|
||||
@ -1436,7 +1438,9 @@ static int link_status_one(
|
||||
(void) sd_device_get_property_value(info->sd_device, "ID_MODEL", &model);
|
||||
}
|
||||
|
||||
t = link_get_type_string(info->sd_device, info->iftype);
|
||||
r = link_get_type_string(info->sd_device, info->iftype, &t);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
|
||||
(void) sd_network_link_get_network_file(info->ifindex, &network);
|
||||
|
||||
|
@ -2228,6 +2228,7 @@ static int link_configure_continue(Link *link) {
|
||||
|
||||
static int link_get_network(Link *link, Network **ret) {
|
||||
Network *network;
|
||||
int r;
|
||||
|
||||
assert(link);
|
||||
assert(link->manager);
|
||||
@ -2236,7 +2237,7 @@ static int link_get_network(Link *link, Network **ret) {
|
||||
ORDERED_HASHMAP_FOREACH(network, link->manager->networks) {
|
||||
bool warn = false;
|
||||
|
||||
if (!net_match_config(
|
||||
r = net_match_config(
|
||||
&network->match,
|
||||
link->sd_device,
|
||||
&link->hw_addr.addr.ether,
|
||||
@ -2247,7 +2248,10 @@ static int link_get_network(Link *link, Network **ret) {
|
||||
link->alternative_names,
|
||||
link->wlan_iftype,
|
||||
link->ssid,
|
||||
&link->bssid))
|
||||
&link->bssid);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
continue;
|
||||
|
||||
if (network->match.ifname && link->sd_device) {
|
||||
|
@ -134,7 +134,7 @@ static const char *const wifi_iftype_table[NL80211_IFTYPE_MAX+1] = {
|
||||
|
||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(wifi_iftype, enum nl80211_iftype);
|
||||
|
||||
bool net_match_config(
|
||||
int net_match_config(
|
||||
const NetMatch *match,
|
||||
sd_device *device,
|
||||
const struct ether_addr *mac,
|
||||
@ -149,10 +149,13 @@ bool net_match_config(
|
||||
|
||||
_cleanup_free_ char *iftype_str = NULL;
|
||||
const char *path = NULL;
|
||||
int r;
|
||||
|
||||
assert(match);
|
||||
|
||||
iftype_str = link_get_type_string(device, iftype);
|
||||
r = link_get_type_string(device, iftype, &iftype_str);
|
||||
if (r == -ENOMEM)
|
||||
return r;
|
||||
|
||||
if (device) {
|
||||
const char *mac_str;
|
||||
|
@ -26,7 +26,7 @@ typedef struct NetMatch {
|
||||
void net_match_clear(NetMatch *match);
|
||||
bool net_match_is_empty(const NetMatch *match);
|
||||
|
||||
bool net_match_config(
|
||||
int net_match_config(
|
||||
const NetMatch *match,
|
||||
sd_device *device,
|
||||
const struct ether_addr *mac,
|
||||
|
@ -273,16 +273,20 @@ int link_config_get(link_config_ctx *ctx, sd_device *device, link_config **ret)
|
||||
(void) link_unsigned_attribute(device, "name_assign_type", &name_assign_type);
|
||||
|
||||
LIST_FOREACH(links, link, ctx->links) {
|
||||
if (net_match_config(&link->match, device, NULL, &permanent_mac, NULL, iftype, NULL, NULL, 0, NULL, NULL)) {
|
||||
if (link->match.ifname && !strv_contains(link->match.ifname, "*") && name_assign_type == NET_NAME_ENUM)
|
||||
log_device_warning(device, "Config file %s is applied to device based on potentially unpredictable interface name.",
|
||||
link->filename);
|
||||
else
|
||||
log_device_debug(device, "Config file %s is applied", link->filename);
|
||||
r = net_match_config(&link->match, device, NULL, &permanent_mac, NULL, iftype, NULL, NULL, 0, NULL, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
continue;
|
||||
|
||||
*ret = link;
|
||||
return 0;
|
||||
}
|
||||
if (link->match.ifname && !strv_contains(link->match.ifname, "*") && name_assign_type == NET_NAME_ENUM)
|
||||
log_device_warning(device, "Config file %s is applied to device based on potentially unpredictable interface name.",
|
||||
link->filename);
|
||||
else
|
||||
log_device_debug(device, "Config file %s is applied", link->filename);
|
||||
|
||||
*ret = link;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOENT;
|
||||
|
Loading…
Reference in New Issue
Block a user