History

wireguard: 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.

Jason A. Donenfeld committed 4 years ago

Commit 20ae1d61 parent 7e938be5 files · +57 −2Browse files

Showing the changes to include (1 of 5 files). Show all

Unified · Split

include/net/dst_cache.h+11−0
@@ -79,6 +79,17 @@ static inline void dst_cache_reset(struct dst_cache *dst_cache) · 78 unmodified lines
79 dst_cache->reset_ts = jiffies;79 dst_cache->reset_ts = jiffies;
80}80}
81 81
82/**
83 * dst_cache_reset_now - invalidate the cache contents immediately
84 * @dst_cache: the cache
85 *
86 * The caller must be sure there are no concurrent users, as this frees
87 * all dst_cache users immediately, rather than waiting for the next
88 * per-cpu usage like dst_cache_reset does. Most callers should use the
89 * higher speed lazily-freed dst_cache_reset function instead.
90 */
91void dst_cache_reset_now(struct dst_cache *dst_cache);
92
82/**93/**
83 * dst_cache_init - initialize the cache, allocating the required storage94 * dst_cache_init - initialize the cache, allocating the required storage
84 * @dst_cache: the cache95 * @dst_cache: the cache

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t