summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/network/networkd-link.c71
-rw-r--r--src/network/networkd-network.c37
-rw-r--r--src/network/networkd-network.h5
-rw-r--r--src/network/test-network.c32
4 files changed, 59 insertions, 86 deletions
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index 152ac05e7c..7c24138a4a 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2226,6 +2226,55 @@ static int link_configure_continue(Link *link) {
return link_enter_join_netdev(link);
}
+static int link_get_network(Link *link, Network **ret) {
+ Network *network;
+
+ assert(link);
+ assert(link->manager);
+ assert(ret);
+
+ ORDERED_HASHMAP_FOREACH(network, link->manager->networks) {
+ bool warn = false;
+
+ if (!net_match_config(
+ &network->match,
+ link->sd_device,
+ &link->hw_addr.addr.ether,
+ &link->permanent_mac,
+ link->driver,
+ link->iftype,
+ link->ifname,
+ link->alternative_names,
+ link->wlan_iftype,
+ link->ssid,
+ &link->bssid))
+ continue;
+
+ if (network->match.ifname && link->sd_device) {
+ uint8_t name_assign_type = NET_NAME_UNKNOWN;
+ const char *attr;
+
+ if (sd_device_get_sysattr_value(link->sd_device, "name_assign_type", &attr) >= 0)
+ (void) safe_atou8(attr, &name_assign_type);
+
+ warn = name_assign_type == NET_NAME_ENUM;
+ }
+
+ log_link_full(link, warn ? LOG_WARNING : LOG_DEBUG,
+ "found matching network '%s'%s.",
+ network->filename,
+ warn ? ", based on potentially unpredictable interface name" : "");
+
+ if (network->unmanaged)
+ return -ENOENT;
+
+ *ret = network;
+ return 0;
+ }
+
+ return -ENOENT;
+}
+
static int link_reconfigure_internal(Link *link, sd_netlink_message *m, bool force) {
_cleanup_strv_free_ char **s = NULL;
Network *network;
@@ -2243,17 +2292,12 @@ static int link_reconfigure_internal(Link *link, sd_netlink_message *m, bool for
strv_free_and_replace(link->alternative_names, s);
- r = network_get(link->manager, link->iftype, link->sd_device,
- link->ifname, link->alternative_names, link->driver,
- &link->hw_addr.addr.ether, &link->permanent_mac,
- link->wlan_iftype, link->ssid, &link->bssid, &network);
+ r = link_get_network(link, &network);
if (r == -ENOENT) {
link_enter_unmanaged(link);
return 0;
- } else if (r == 0 && network->unmanaged) {
- link_enter_unmanaged(link);
- return 0;
- } else if (r < 0)
+ }
+ if (r < 0)
return r;
if (link->network == network && !force)
@@ -2377,17 +2421,12 @@ static int link_initialized_and_synced(Link *link) {
if (r < 0)
return r;
- r = network_get(link->manager, link->iftype, link->sd_device,
- link->ifname, link->alternative_names, link->driver,
- &link->hw_addr.addr.ether, &link->permanent_mac,
- link->wlan_iftype, link->ssid, &link->bssid, &network);
+ r = link_get_network(link, &network);
if (r == -ENOENT) {
link_enter_unmanaged(link);
return 0;
- } else if (r == 0 && network->unmanaged) {
- link_enter_unmanaged(link);
- return 0;
- } else if (r < 0)
+ }
+ if (r < 0)
return r;
if (link->flags & IFF_LOOPBACK) {
diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
index 8b236342b5..482c31064f 100644
--- a/src/network/networkd-network.c
+++ b/src/network/networkd-network.c
@@ -646,43 +646,6 @@ int network_get_by_name(Manager *manager, const char *name, Network **ret) {
return 0;
}
-int network_get(Manager *manager, unsigned short iftype, sd_device *device,
- const char *ifname, char * const *alternative_names, const char *driver,
- const struct ether_addr *mac, const struct ether_addr *permanent_mac,
- enum nl80211_iftype wlan_iftype, const char *ssid, const struct ether_addr *bssid,
- Network **ret) {
- Network *network;
-
- assert(manager);
- assert(ret);
-
- ORDERED_HASHMAP_FOREACH(network, manager->networks)
- if (net_match_config(&network->match, device, mac, permanent_mac, driver, iftype,
- ifname, alternative_names, wlan_iftype, ssid, bssid)) {
- if (network->match.ifname && device) {
- const char *attr;
- uint8_t name_assign_type = NET_NAME_UNKNOWN;
-
- 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)
- log_warning("%s: found matching network '%s', based on potentially unpredictable ifname",
- ifname, network->filename);
- else
- log_debug("%s: found matching network '%s'", ifname, network->filename);
- } else
- log_debug("%s: found matching network '%s'", ifname, network->filename);
-
- *ret = network;
- return 0;
- }
-
- *ret = NULL;
-
- return -ENOENT;
-}
-
bool network_has_static_ipv6_configurations(Network *network) {
Address *address;
Route *route;
diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
index c094065a83..e27a27cd02 100644
--- a/src/network/networkd-network.h
+++ b/src/network/networkd-network.h
@@ -341,11 +341,6 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
int network_verify(Network *network);
int network_get_by_name(Manager *manager, const char *name, Network **ret);
-int network_get(Manager *manager, unsigned short iftype, sd_device *device,
- const char *ifname, char * const *alternative_names, const char *driver,
- const struct ether_addr *mac, const struct ether_addr *permanent_mac,
- enum nl80211_iftype wlan_iftype, const char *ssid, const struct ether_addr *bssid,
- Network **ret);
void network_apply_anonymize_if_set(Network *network);
bool network_has_static_ipv6_configurations(Network *network);
diff --git a/src/network/test-network.c b/src/network/test-network.c
index 25ff3a33a8..09e7b99d23 100644
--- a/src/network/test-network.c
+++ b/src/network/test-network.c
@@ -168,23 +168,6 @@ static int test_load_config(Manager *manager) {
return 0;
}
-static void test_network_get(Manager *manager, sd_device *loopback) {
- Network *network;
- const struct ether_addr mac = ETHER_ADDR_NULL;
- int r;
-
- /* Let's hope that the test machine does not have a .network file that applies to loopback deviceā€¦
- * But it is still possible, so let's allow that case too. */
- r = network_get(manager, 0, loopback, "lo", NULL, NULL, &mac, &mac, 0, NULL, NULL, &network);
- if (r == -ENOENT)
- /* The expected case */
- assert_se(!network);
- else if (r >= 0)
- assert_se(network);
- else
- assert_not_reached("bad error!");
-}
-
static void test_address_equality(void) {
_cleanup_(address_freep) Address *a1 = NULL, *a2 = NULL;
@@ -277,8 +260,7 @@ static void test_dhcp_hostname_shorten_overlong(void) {
int main(void) {
_cleanup_(manager_freep) Manager *manager = NULL;
- _cleanup_(sd_device_unrefp) sd_device *loopback = NULL;
- int ifindex, r;
+ int r;
test_setup_logging(LOG_INFO);
@@ -293,15 +275,9 @@ int main(void) {
r = test_load_config(manager);
if (r == -EPERM)
- return log_tests_skipped("Cannot load configuration");
- assert_se(r == 0);
-
- assert_se(sd_device_new_from_syspath(&loopback, "/sys/class/net/lo") >= 0);
- assert_se(loopback);
- assert_se(sd_device_get_ifindex(loopback, &ifindex) >= 0);
- assert_se(ifindex == 1);
-
- test_network_get(manager, loopback);
+ log_debug("Cannot load configuration, ignoring.");
+ else
+ assert_se(r == 0);
assert_se(manager_enumerate(manager) >= 0);
return 0;