aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/peer.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-09-28 03:05:22 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-02 03:41:49 +0200
commit45a53bbaafbca0af90f0fb097b1ff6c151b5d8f0 (patch)
tree9409e8289e08211e35e8cdeef0e509e1e254acc0 /src/peer.c
parentpoly1305-mips64: use compiler-defined macros in assembly (diff)
downloadwireguard-monolithic-historical-45a53bbaafbca0af90f0fb097b1ff6c151b5d8f0.tar.xz
wireguard-monolithic-historical-45a53bbaafbca0af90f0fb097b1ff6c151b5d8f0.zip
global: prefix all functions with wg_
I understand why this must be done, though I'm not so happy about having to do it. In some places, it puts us over 80 chars and we have to break lines up in further ugly ways. And in general, I think this makes things harder to read. Yet another thing we must do to please upstream. Maybe this can be replaced in the future by some kind of automatic module namespacing logic in the linker, or even combined with LTO and aggressive symbol stripping. Suggested-by: Andrew Lunn <andrew@lunn.ch>
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c63
1 files changed, 33 insertions, 30 deletions
diff --git a/src/peer.c b/src/peer.c
index d9ac366..c4737ae 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -18,9 +18,9 @@
static atomic64_t peer_counter = ATOMIC64_INIT(0);
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])
+wg_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;
@@ -34,24 +34,26 @@ peer_create(struct wireguard_device *wg,
return NULL;
peer->device = wg;
- if (!noise_handshake_init(&peer->handshake, &wg->static_identity,
- public_key, preshared_key, peer))
+ if (!wg_noise_handshake_init(&peer->handshake, &wg->static_identity,
+ public_key, preshared_key, peer))
goto err_1;
if (dst_cache_init(&peer->endpoint_cache, GFP_KERNEL))
goto err_1;
- if (packet_queue_init(&peer->tx_queue, packet_tx_worker, false,
- MAX_QUEUED_PACKETS))
+ if (wg_packet_queue_init(&peer->tx_queue, wg_packet_tx_worker, false,
+ MAX_QUEUED_PACKETS))
goto err_2;
- if (packet_queue_init(&peer->rx_queue, NULL, false, MAX_QUEUED_PACKETS))
+ if (wg_packet_queue_init(&peer->rx_queue, NULL, false,
+ MAX_QUEUED_PACKETS))
goto err_3;
peer->internal_id = atomic64_inc_return(&peer_counter);
peer->serial_work_cpu = nr_cpumask_bits;
- cookie_init(&peer->latest_cookie);
- timers_init(peer);
- cookie_checker_precompute_peer_keys(peer);
+ wg_cookie_init(&peer->latest_cookie);
+ wg_timers_init(peer);
+ wg_cookie_checker_precompute_peer_keys(peer);
spin_lock_init(&peer->keypairs.keypair_update_lock);
- INIT_WORK(&peer->transmit_handshake_work, packet_handshake_send_worker);
+ INIT_WORK(&peer->transmit_handshake_work,
+ wg_packet_handshake_send_worker);
rwlock_init(&peer->endpoint_lock);
kref_init(&peer->refcount);
skb_queue_head_init(&peer->staged_packet_queue);
@@ -59,16 +61,17 @@ peer_create(struct wireguard_device *wg,
ktime_get_boot_fast_ns() -
(u64)(REKEY_TIMEOUT + 1) * NSEC_PER_SEC);
set_bit(NAPI_STATE_NO_BUSY_POLL, &peer->napi.state);
- netif_napi_add(wg->dev, &peer->napi, packet_rx_poll, NAPI_POLL_WEIGHT);
+ netif_napi_add(wg->dev, &peer->napi, wg_packet_rx_poll,
+ NAPI_POLL_WEIGHT);
napi_enable(&peer->napi);
list_add_tail(&peer->peer_list, &wg->peer_list);
- pubkey_hashtable_add(&wg->peer_hashtable, peer);
+ wg_pubkey_hashtable_add(&wg->peer_hashtable, peer);
++wg->num_peers;
pr_debug("%s: Peer %llu created\n", wg->dev->name, peer->internal_id);
return peer;
err_3:
- packet_queue_free(&peer->tx_queue, false);
+ wg_packet_queue_free(&peer->tx_queue, false);
err_2:
dst_cache_destroy(&peer->endpoint_cache);
err_1:
@@ -76,7 +79,7 @@ err_1:
return NULL;
}
-struct wireguard_peer *peer_get_maybe_zero(struct wireguard_peer *peer)
+struct wireguard_peer *wg_peer_get_maybe_zero(struct wireguard_peer *peer)
{
RCU_LOCKDEP_WARN(!rcu_read_lock_bh_held(),
"Taking peer reference without holding the RCU read lock");
@@ -89,7 +92,7 @@ struct wireguard_peer *peer_get_maybe_zero(struct wireguard_peer *peer)
* because peer_list, clearing handshakes, and flushing all require mutexes
* which requires sleeping, which must only be done from certain contexts.
*/
-void peer_remove(struct wireguard_peer *peer)
+void wg_peer_remove(struct wireguard_peer *peer)
{
if (unlikely(!peer))
return;
@@ -99,9 +102,9 @@ void peer_remove(struct wireguard_peer *peer)
* can't enter.
*/
list_del_init(&peer->peer_list);
- allowedips_remove_by_peer(&peer->device->peer_allowedips, peer,
- &peer->device->device_update_lock);
- pubkey_hashtable_remove(&peer->device->peer_hashtable, peer);
+ wg_allowedips_remove_by_peer(&peer->device->peer_allowedips, peer,
+ &peer->device->device_update_lock);
+ wg_pubkey_hashtable_remove(&peer->device->peer_hashtable, peer);
/* Mark as dead, so that we don't allow jumping contexts after. */
WRITE_ONCE(peer->is_dead, true);
@@ -110,12 +113,12 @@ void peer_remove(struct wireguard_peer *peer)
/* Now that no more keypairs can be created for this peer, we destroy
* existing ones.
*/
- noise_keypairs_clear(&peer->keypairs);
+ wg_noise_keypairs_clear(&peer->keypairs);
/* Destroy all ongoing timers that were in-flight at the beginning of
* this function.
*/
- timers_stop(peer);
+ wg_timers_stop(peer);
/* The transition between packet encryption/decryption queues isn't
* guarded by is_dead, but each reference's life is strictly bounded by
@@ -141,7 +144,7 @@ void peer_remove(struct wireguard_peer *peer)
flush_workqueue(peer->device->handshake_send_wq);
--peer->device->num_peers;
- peer_put(peer);
+ wg_peer_put(peer);
}
static void rcu_release(struct rcu_head *rcu)
@@ -149,8 +152,8 @@ static void rcu_release(struct rcu_head *rcu)
struct wireguard_peer *peer =
container_of(rcu, struct wireguard_peer, rcu);
dst_cache_destroy(&peer->endpoint_cache);
- packet_queue_free(&peer->rx_queue, false);
- packet_queue_free(&peer->tx_queue, false);
+ wg_packet_queue_free(&peer->rx_queue, false);
+ wg_packet_queue_free(&peer->tx_queue, false);
kzfree(peer);
}
@@ -164,8 +167,8 @@ static void kref_release(struct kref *refcount)
/* Remove ourself from dynamic runtime lookup structures, now that the
* last reference is gone.
*/
- index_hashtable_remove(&peer->device->index_hashtable,
- &peer->handshake.entry);
+ wg_index_hashtable_remove(&peer->device->index_hashtable,
+ &peer->handshake.entry);
/* Remove any lingering packets that didn't have a chance to be
* transmitted.
*/
@@ -174,18 +177,18 @@ static void kref_release(struct kref *refcount)
call_rcu_bh(&peer->rcu, rcu_release);
}
-void peer_put(struct wireguard_peer *peer)
+void wg_peer_put(struct wireguard_peer *peer)
{
if (unlikely(!peer))
return;
kref_put(&peer->refcount, kref_release);
}
-void peer_remove_all(struct wireguard_device *wg)
+void wg_peer_remove_all(struct wireguard_device *wg)
{
struct wireguard_peer *peer, *temp;
lockdep_assert_held(&wg->device_update_lock);
list_for_each_entry_safe (peer, temp, &wg->peer_list, peer_list)
- peer_remove(peer);
+ wg_peer_remove(peer);
}