aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/peer.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-09-12 18:51:12 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-09-15 01:50:11 +0200
commitc2cb0a2013a338200b6aeda719bd01f1d89209e2 (patch)
treeda958ec8bd9083a455a467aeb8f287c80ff349db /src/peer.c
parentcompat: add READ_ONCE/WRITE_ONCE for old kernels (diff)
downloadwireguard-monolithic-historical-c2cb0a2013a338200b6aeda719bd01f1d89209e2.tar.xz
wireguard-monolithic-historical-c2cb0a2013a338200b6aeda719bd01f1d89209e2.zip
data: reorganize and edit new queuing code
This involves many changes of Samuel's new system, in addition to some TODOs for things that are not yet ideal.
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c23
1 files changed, 6 insertions, 17 deletions
diff --git a/src/peer.c b/src/peer.c
index 20fd6cb..62d3259 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -14,18 +14,6 @@
static atomic64_t peer_counter = ATOMIC64_INIT(0);
-static int choose_cpu(u64 id)
-{
- unsigned int cpu, cpu_index, i;
-
- cpu_index = id % cpumask_weight(cpu_online_mask);
- cpu = cpumask_first(cpu_online_mask);
- for (i = 0; i < cpu_index; i += 1)
- cpu = cpumask_next(cpu, cpu_online_mask);
-
- return cpu;
-}
-
struct wireguard_peer *peer_create(struct wireguard_device *wg, const u8 public_key[NOISE_PUBLIC_KEY_LEN], const u8 preshared_key[NOISE_SYMMETRIC_KEY_LEN])
{
struct wireguard_peer *peer;
@@ -44,6 +32,7 @@ struct wireguard_peer *peer_create(struct wireguard_device *wg, const u8 public_
}
peer->internal_id = atomic64_inc_return(&peer_counter);
+ peer->serial_work_cpu = nr_cpumask_bits;
peer->device = wg;
cookie_init(&peer->latest_cookie);
if (!noise_handshake_init(&peer->handshake, &wg->static_identity, public_key, preshared_key, peer)) {
@@ -57,7 +46,6 @@ struct wireguard_peer *peer_create(struct wireguard_device *wg, const u8 public_
kref_init(&peer->refcount);
pubkey_hashtable_add(&wg->peer_hashtable, peer);
list_add_tail(&peer->peer_list, &wg->peer_list);
- peer->work_cpu = choose_cpu(peer->internal_id);
INIT_LIST_HEAD(&peer->init_queue.list);
INIT_WORK(&peer->init_queue.work, packet_init_worker);
INIT_LIST_HEAD(&peer->send_queue.list);
@@ -99,10 +87,11 @@ void peer_remove(struct wireguard_peer *peer)
timers_uninit_peer(peer);
routing_table_remove_by_peer(&peer->device->peer_routing_table, peer);
pubkey_hashtable_remove(&peer->device->peer_hashtable, peer);
- flush_workqueue(peer->device->crypt_wq);
- if (peer->device->peer_wq)
- flush_workqueue(peer->device->peer_wq);
- peer_purge_queues(peer);
+ atomic_set(&peer->is_draining, true);
+ packet_purge_init_queue(peer);
+ flush_workqueue(peer->device->packet_crypt_wq); /* The first flush is for encrypt/decrypt step. */
+ flush_workqueue(peer->device->packet_crypt_wq); /* The second flush is for send/receive step. */
+ flush_workqueue(peer->device->handshake_send_wq);
peer_put(peer);
}