From fbea8fe2e0ac0f46d5a64a2291a2926109163001 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 18 May 2018 13:38:16 +0200 Subject: device: remove allowedips before individual peers This avoids an O(n^2) traversal in favor of an O(n) one. --- src/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/device.c b/src/device.c index d64653d..88790d6 100644 --- a/src/device.c +++ b/src/device.c @@ -219,6 +219,7 @@ static void destruct(struct net_device *dev) mutex_lock(&wg->device_update_lock); wg->incoming_port = 0; socket_reinit(wg, NULL, NULL); + allowedips_free(&wg->peer_allowedips, &wg->device_update_lock); peer_remove_all(wg); /* The final references are cleared in the below calls to destroy_workqueue. */ destroy_workqueue(wg->handshake_receive_wq); destroy_workqueue(wg->handshake_send_wq); @@ -226,7 +227,6 @@ static void destruct(struct net_device *dev) packet_queue_free(&wg->encrypt_queue, true); destroy_workqueue(wg->packet_crypt_wq); rcu_barrier_bh(); /* Wait for all the peers to be actually freed. */ - allowedips_free(&wg->peer_allowedips, &wg->device_update_lock); ratelimiter_uninit(); memzero_explicit(&wg->static_identity, sizeof(struct noise_static_identity)); skb_queue_purge(&wg->incoming_handshakes); -- cgit v1.2.3-59-g8ed1b