And make net_match_config() propagate the error.
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) {
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);
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,
(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);
static int link_get_network(Link *link, Network **ret) {
Network *network;
+ int r;
assert(link);
assert(link->manager);
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,
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) {
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,
_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;
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,
(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);
-
- *ret = link;
- return 0;
- }
+ 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;
+
+ 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;