diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-11-17 11:33:24 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-11-17 11:33:24 +0100 |
commit | 82e6e3b2588939b03d0a534b85f446183a13ceda (patch) | |
tree | 3dab6c0d4d9e000d214251714ff8238a10c2b4a1 /src/device.c | |
parent | compat: fix compilation with PaX (diff) | |
download | wireguard-monolithic-historical-82e6e3b2588939b03d0a534b85f446183a13ceda.tar.xz wireguard-monolithic-historical-82e6e3b2588939b03d0a534b85f446183a13ceda.zip |
socket: only free socket after successful creation of new
When an interface is down, the socket port can change freely. A socket
will be allocated when the interface comes up, and if a socket can't be
allocated, the interface doesn't come up.
However, a socket port can change while the interface is up. In this
case, if a new socket with a new port cannot be allocated, it's
important to keep the interface in a consistent state. The choices are
either to bring down the interface or to preserve the old socket. This
patch implements the latter.
Reported-by: Marc-Antoine Perennou <keruspe@exherbo.org>
Diffstat (limited to 'src/device.c')
-rw-r--r-- | src/device.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/device.c b/src/device.c index ffc36b4..12c11fb 100644 --- a/src/device.c +++ b/src/device.c @@ -51,7 +51,7 @@ static int open(struct net_device *dev) #endif #endif - ret = socket_init(wg); + ret = socket_init(wg, wg->incoming_port); if (ret < 0) return ret; mutex_lock(&wg->device_update_lock); @@ -105,7 +105,7 @@ static int stop(struct net_device *dev) } mutex_unlock(&wg->device_update_lock); skb_queue_purge(&wg->incoming_handshakes); - socket_uninit(wg); + socket_reinit(wg, NULL, NULL); return 0; } @@ -220,7 +220,7 @@ static void destruct(struct net_device *dev) ratelimiter_uninit(); memzero_explicit(&wg->static_identity, sizeof(struct noise_static_identity)); skb_queue_purge(&wg->incoming_handshakes); - socket_uninit(wg); + socket_reinit(wg, NULL, NULL); free_percpu(dev->tstats); free_percpu(wg->incoming_handshakes_worker); if (wg->have_creating_net_ref) |