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 | 6ed6b2e1c4bbf6f5ce234eb10d16f25923351571 (patch) | |
tree | 16a88ef822f0e7d819a54e75d3adbe32284e25d7 /src/netlink.c | |
parent | 75b8cad99bdca07d0098daf21792dd2ce507d73d (diff) |
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>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/netlink.c')
-rw-r--r-- | src/netlink.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/netlink.c b/src/netlink.c index f2e724a..9297e60 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -260,13 +260,13 @@ static int set_port(struct wireguard_device *wg, u16 port) if (wg->incoming_port == port) return 0; - socket_uninit(wg); - wg->incoming_port = port; list_for_each_entry(peer, &wg->peer_list, peer_list) socket_clear_peer_endpoint_src(peer); - if (!netif_running(wg->dev)) + if (!netif_running(wg->dev)) { + wg->incoming_port = port; return 0; - return socket_init(wg); + } + return socket_init(wg, port); } static int set_allowedip(struct wireguard_peer *peer, struct nlattr **attrs) |