aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/compat/dst_cache/dst_cache.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-11-29 13:52:14 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2021-12-03 23:24:03 +0100
commit68abb1b9ba6c9726ea108f796ae7d84f8553d620 (patch)
treeeb3eb842a79c65b60f77f43f606a0b06161288d3 /src/compat/dst_cache/dst_cache.c
parentmain: rename 'mod_init' & 'mod_exit' functions to be module-specific (diff)
downloadwireguard-linux-compat-68abb1b9ba6c9726ea108f796ae7d84f8553d620.tar.xz
wireguard-linux-compat-68abb1b9ba6c9726ea108f796ae7d84f8553d620.zip
device: reset peer src endpoint when netns exits
Each peer's endpoint contains a dst_cache entry that takes a reference to another netdev. When the containing namespace exits, we take down the socket and prevent future sockets from being created (by setting creating_net to NULL), which removes that potential reference on the netns. However, it doesn't release references to the netns that a netdev cached in dst_cache might be taking, so the netns still might fail to exit. Since the socket is gimped anyway, we can simply clear all the dst_caches (by way of clearing the endpoint src), which will release all references. However, the current dst_cache_reset function only releases those references lazily. But it turns out that all of our usages of wg_socket_clear_peer_endpoint_src are called from contexts that are not exactly high-speed or bottle-necked. For example, when there's connection difficulty, or when userspace is reconfiguring the interface. And in particular for this patch, when the netns is exiting. So for those cases, it makes more sense to call dst_release immediately. For that, we add a small helper function to dst_cache. This patch also adds a test to netns.sh from Hangbin Liu to ensure this doesn't regress. Test-by: Hangbin Liu <liuhangbin@gmail.com> Reported-by: Xiumei Mu <xmu@redhat.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/compat/dst_cache/dst_cache.c')
-rw-r--r--src/compat/dst_cache/dst_cache.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/compat/dst_cache/dst_cache.c b/src/compat/dst_cache/dst_cache.c
index 7ec22f7..f74c43c 100644
--- a/src/compat/dst_cache/dst_cache.c
+++ b/src/compat/dst_cache/dst_cache.c
@@ -27,6 +27,7 @@ static inline u32 rt6_get_cookie(const struct rt6_info *rt)
#endif
#include <uapi/linux/in.h>
+#ifndef COMPAT_HAS_DEFINED_DST_CACHE_PCPU
struct dst_cache_pcpu {
unsigned long refresh_ts;
struct dst_entry *dst;
@@ -36,6 +37,7 @@ struct dst_cache_pcpu {
struct in6_addr in6_saddr;
};
};
+#endif
static void dst_cache_per_cpu_dst_set(struct dst_cache_pcpu *dst_cache,
struct dst_entry *dst, u32 cookie)