summaryrefslogtreecommitdiffhomepage
path: root/src/device.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-05-24 19:18:04 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-05-30 18:07:28 +0200
commit672b76a098b99102a46712b1d982f550f97806f2 (patch)
tree98ac9dc6bf827df3a5d19086818264b4b6c8b181 /src/device.c
parentfd1e80d9f4bad1805d801fc4501d86807c93a9ec (diff)
peer: use iterator macro instead of callback
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c50
1 files changed, 22 insertions, 28 deletions
diff --git a/src/device.c b/src/device.c
index e10aeed..a06750a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -26,18 +26,10 @@
#include <net/netfilter/nf_nat_core.h>
#endif
-static int open_peer(struct wireguard_peer *peer, void *data)
-{
- timers_init_peer(peer);
- packet_send_queue(peer);
- if (peer->persistent_keepalive_interval)
- packet_send_keepalive(peer);
- return 0;
-}
-
static int open(struct net_device *dev)
{
int ret;
+ struct wireguard_peer *peer, *temp;
struct wireguard_device *wg = netdev_priv(dev);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 17, 0)
struct inet6_dev *dev_v6 = __in6_dev_get(dev);
@@ -64,16 +56,12 @@ static int open(struct net_device *dev)
ret = socket_init(wg);
if (ret < 0)
return ret;
- peer_for_each(wg, open_peer, NULL);
- return 0;
-}
-
-static int clear_noise_peer(struct wireguard_peer *peer, void *data)
-{
- noise_handshake_clear(&peer->handshake);
- noise_keypairs_clear(&peer->keypairs);
- if (peer->timers_enabled)
- del_timer(&peer->timer_kill_ephemerals);
+ peer_for_each (wg, peer, temp, true) {
+ timers_init_peer(peer);
+ packet_send_queue(peer);
+ if (peer->persistent_keepalive_interval)
+ packet_send_keepalive(peer);
+ }
return 0;
}
@@ -81,25 +69,31 @@ static int clear_noise_peer(struct wireguard_peer *peer, void *data)
static int suspending_clear_noise_peers(struct notifier_block *nb, unsigned long action, void *data)
{
struct wireguard_device *wg = container_of(nb, struct wireguard_device, clear_peers_on_suspend);
+ struct wireguard_peer *peer, *temp;
if (action == PM_HIBERNATION_PREPARE || action == PM_SUSPEND_PREPARE) {
- peer_for_each(wg, clear_noise_peer, NULL);
+ peer_for_each (wg, peer, temp, true) {
+ noise_handshake_clear(&peer->handshake);
+ noise_keypairs_clear(&peer->keypairs);
+ if (peer->timers_enabled)
+ del_timer(&peer->timer_kill_ephemerals);
+ }
rcu_barrier_bh();
}
return 0;
}
#endif
-static int stop_peer(struct wireguard_peer *peer, void *data)
-{
- timers_uninit_peer(peer);
- clear_noise_peer(peer, data);
- return 0;
-}
-
static int stop(struct net_device *dev)
{
struct wireguard_device *wg = netdev_priv(dev);
- peer_for_each(wg, stop_peer, NULL);
+ struct wireguard_peer *peer, *temp;
+ peer_for_each (wg, peer, temp, true) {
+ timers_uninit_peer(peer);
+ noise_handshake_clear(&peer->handshake);
+ noise_keypairs_clear(&peer->keypairs);
+ if (peer->timers_enabled)
+ del_timer(&peer->timer_kill_ephemerals);
+ }
skb_queue_purge(&wg->incoming_handshakes);
socket_uninit(wg);
return 0;