diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2024-10-30 10:27:24 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-30 10:27:24 +0100 |
commit | 0a1b553e2a38ada5c57527cab3700853846fb079 (patch) | |
tree | 391c4f2737abbc0067973037404894f9161651d5 | |
parent | pretty-print: add format-string version of draw_progress_bar() (#34939) (diff) | |
parent | network/netdev: skip processing netdev if it is already detached (diff) | |
download | systemd-0a1b553e2a38ada5c57527cab3700853846fb079.tar.xz systemd-0a1b553e2a38ada5c57527cab3700853846fb079.zip |
network: skip processing netdev if it is already detached (#34935)
split-out of #34909.
-rw-r--r-- | src/network/netdev/batadv.c | 3 | ||||
-rw-r--r-- | src/network/netdev/bridge.c | 3 | ||||
-rw-r--r-- | src/network/netdev/fou-tunnel.c | 4 | ||||
-rw-r--r-- | src/network/netdev/l2tp-tunnel.c | 11 | ||||
-rw-r--r-- | src/network/netdev/macsec.c | 10 | ||||
-rw-r--r-- | src/network/netdev/netdev.c | 27 | ||||
-rw-r--r-- | src/network/netdev/tuntap.c | 1 | ||||
-rw-r--r-- | src/network/netdev/wireguard.c | 6 | ||||
-rw-r--r-- | src/network/netdev/wlan.c | 3 | ||||
-rw-r--r-- | src/network/networkd-queue.c | 1 |
10 files changed, 65 insertions, 4 deletions
diff --git a/src/network/netdev/batadv.c b/src/network/netdev/batadv.c index e600727c20..9806d8eb7c 100644 --- a/src/network/netdev/batadv.c +++ b/src/network/netdev/batadv.c @@ -163,6 +163,9 @@ static int netdev_batadv_post_create(NetDev *netdev, Link *link) { assert(netdev); + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = sd_genl_message_new(netdev->manager->genl, BATADV_NL_NAME, BATADV_CMD_SET_MESH, &message); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not allocate netlink message: %m"); diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c index 25b0f81aa0..4dfc393830 100644 --- a/src/network/netdev/bridge.c +++ b/src/network/netdev/bridge.c @@ -159,6 +159,9 @@ static int netdev_bridge_post_create(NetDev *netdev, Link *link) { assert(netdev); + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = sd_rtnl_message_new_link(netdev->manager->rtnl, &req, RTM_NEWLINK, netdev->ifindex); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not allocate netlink message: %m"); diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index e962c6c64b..a85aff2e6d 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -89,6 +89,7 @@ static int netdev_create_fou_tunnel_message(NetDev *netdev, sd_netlink_message * int r; assert(netdev); + assert(netdev->manager); r = sd_genl_message_new(netdev->manager->genl, FOU_GENL_NAME, FOU_CMD_ADD, &m); if (r < 0) @@ -128,6 +129,9 @@ static int netdev_fou_tunnel_create(NetDev *netdev) { assert(FOU(netdev)); + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = netdev_create_fou_tunnel_message(netdev, &m); if (r < 0) return r; diff --git a/src/network/netdev/l2tp-tunnel.c b/src/network/netdev/l2tp-tunnel.c index c1372bb1e0..c87e44797b 100644 --- a/src/network/netdev/l2tp-tunnel.c +++ b/src/network/netdev/l2tp-tunnel.c @@ -94,6 +94,8 @@ static int l2tp_session_new_static(L2tpTunnel *t, const char *filename, unsigned static int netdev_l2tp_create_message_tunnel(NetDev *netdev, union in_addr_union *local_address, sd_netlink_message **ret) { assert(local_address); + assert(netdev); + assert(netdev->manager); _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *m = NULL; uint16_t encap_type; @@ -188,6 +190,7 @@ static int netdev_l2tp_create_message_session(NetDev *netdev, L2tpSession *sessi int r; assert(netdev); + assert(netdev->manager); assert(session); assert(session->tunnel); @@ -385,6 +388,11 @@ static int l2tp_create_session(NetDev *netdev, L2tpSession *session) { _cleanup_(sd_netlink_message_unrefp) sd_netlink_message *n = NULL; int r; + assert(netdev); + + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = netdev_l2tp_create_message_session(netdev, session, &n); if (r < 0) return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); @@ -429,6 +437,9 @@ static int l2tp_create_tunnel(NetDev *netdev) { L2tpTunnel *t = L2TP(netdev); int r; + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = l2tp_get_local_address(netdev, &local_address); if (r < 0) return log_netdev_error_errno(netdev, r, "Could not find local address."); diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c index 187da41344..15d79906f7 100644 --- a/src/network/netdev/macsec.c +++ b/src/network/netdev/macsec.c @@ -224,6 +224,7 @@ static int netdev_macsec_create_message(NetDev *netdev, int command, sd_netlink_ assert(netdev); assert(netdev->ifindex > 0); + assert(netdev->manager); r = sd_genl_message_new(netdev->manager->genl, MACSEC_GENL_NAME, command, &m); if (r < 0) @@ -334,6 +335,9 @@ static int netdev_macsec_configure_receive_association(NetDev *netdev, ReceiveAs assert(netdev); assert(a); + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = netdev_macsec_create_message(netdev, MACSEC_CMD_ADD_RXSA, &m); if (r < 0) return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); @@ -406,6 +410,9 @@ static int netdev_macsec_configure_receive_channel(NetDev *netdev, ReceiveChanne assert(netdev); assert(c); + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = netdev_macsec_create_message(netdev, MACSEC_CMD_ADD_RXSC, &m); if (r < 0) return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); @@ -454,6 +461,9 @@ static int netdev_macsec_configure_transmit_association(NetDev *netdev, Transmit assert(netdev); assert(a); + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = netdev_macsec_create_message(netdev, MACSEC_CMD_ADD_TXSA, &m); if (r < 0) return log_netdev_error_errno(netdev, r, "Failed to create netlink message: %m"); diff --git a/src/network/netdev/netdev.c b/src/network/netdev/netdev.c index 8e58a1ae12..f7598dc7ea 100644 --- a/src/network/netdev/netdev.c +++ b/src/network/netdev/netdev.c @@ -273,18 +273,17 @@ void netdev_drop(NetDev *netdev) { netdev_detach(netdev); } -int netdev_attach_name(NetDev *netdev, const char *name) { +static int netdev_attach_name_full(NetDev *netdev, const char *name, Hashmap **netdevs) { int r; assert(netdev); - assert(netdev->manager); assert(name); - r = hashmap_ensure_put(&netdev->manager->netdevs, &string_hash_ops, name, netdev); + r = hashmap_ensure_put(netdevs, &string_hash_ops, name, netdev); if (r == -ENOMEM) return log_oom(); if (r == -EEXIST) { - NetDev *n = hashmap_get(netdev->manager->netdevs, name); + NetDev *n = hashmap_get(*netdevs, name); assert(n); if (!streq(netdev->filename, n->filename)) @@ -299,6 +298,13 @@ int netdev_attach_name(NetDev *netdev, const char *name) { return 0; } +int netdev_attach_name(NetDev *netdev, const char *name) { + assert(netdev); + assert(netdev->manager); + + return netdev_attach_name_full(netdev, name, &netdev->manager->netdevs); +} + static int netdev_attach(NetDev *netdev) { int r; @@ -670,6 +676,7 @@ static int independent_netdev_create(NetDev *netdev) { int r; assert(netdev); + assert(netdev->manager); /* create netdev */ if (NETDEV_VTABLE(netdev)->create) { @@ -774,6 +781,9 @@ static int stacked_netdev_process_request(Request *req, Link *link, void *userda assert(req); assert(link); + if (!netdev_is_managed(netdev)) + return 1; /* Already detached, due to e.g. reloading .netdev files, cancelling the request. */ + r = netdev_is_ready_to_create(netdev, link); if (r <= 0) return r; @@ -819,6 +829,9 @@ int link_request_stacked_netdev(Link *link, NetDev *netdev) { if (!IN_SET(netdev->state, NETDEV_STATE_LOADING, NETDEV_STATE_FAILED) || netdev->ifindex > 0) return 0; /* Already created. */ + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + link->stacked_netdevs_created = false; r = link_queue_request_full(link, REQUEST_TYPE_NETDEV_STACKED, netdev, (mfree_func_t) netdev_unref, @@ -843,6 +856,9 @@ static int independent_netdev_process_request(Request *req, Link *link, void *us assert(!link); + if (!netdev_is_managed(netdev)) + return 1; /* Already detached, due to e.g. reloading .netdev files, cancelling the request. */ + r = netdev_is_ready_to_create(netdev, NULL); if (r <= 0) return r; @@ -866,6 +882,9 @@ static int netdev_request_to_create(NetDev *netdev) { if (netdev_is_stacked(netdev)) return 0; + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + r = netdev_is_ready_to_create(netdev, NULL); if (r < 0) return r; diff --git a/src/network/netdev/tuntap.c b/src/network/netdev/tuntap.c index f5be31ed94..c012bc1591 100644 --- a/src/network/netdev/tuntap.c +++ b/src/network/netdev/tuntap.c @@ -103,6 +103,7 @@ static int netdev_create_tuntap(NetDev *netdev) { int r; assert(netdev); + assert(netdev->manager); t = TUNTAP(netdev); assert(t); diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index 9715cf4034..9e8dfb259a 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -234,6 +234,9 @@ static int wireguard_set_interface(NetDev *netdev) { Wireguard *w = WIREGUARD(netdev); int r; + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + for (WireguardPeer *peer_start = w->peers; peer_start || !sent_once; ) { uint16_t i = 0; @@ -399,6 +402,9 @@ static int peer_resolve_endpoint(WireguardPeer *peer) { netdev = NETDEV(peer->wireguard); + if (!netdev_is_managed(netdev)) + return 0; /* Already detached, due to e.g. reloading .netdev files. */ + if (!peer->endpoint_host || !peer->endpoint_port) /* Not necessary to resolve the endpoint. */ return 0; diff --git a/src/network/netdev/wlan.c b/src/network/netdev/wlan.c index 904e40fe81..5b9db8b219 100644 --- a/src/network/netdev/wlan.c +++ b/src/network/netdev/wlan.c @@ -27,6 +27,9 @@ static void wlan_init(NetDev *netdev) { static int wlan_get_wiphy(NetDev *netdev, Wiphy **ret) { WLan *w = WLAN(netdev); + if (!netdev_is_managed(netdev)) + return -ENOENT; /* Already detached, due to e.g. reloading .netdev files. */ + if (w->wiphy_name) return wiphy_get_by_name(netdev->manager, w->wiphy_name, ret); diff --git a/src/network/networkd-queue.c b/src/network/networkd-queue.c index dcb9bd0549..e898ea6e85 100644 --- a/src/network/networkd-queue.c +++ b/src/network/networkd-queue.c @@ -193,6 +193,7 @@ int netdev_queue_request( int r; assert(netdev); + assert(netdev->manager); r = request_new(netdev->manager, NULL, REQUEST_TYPE_NETDEV_INDEPENDENT, netdev, (mfree_func_t) netdev_unref, |