diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-05-24 19:18:04 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2017-05-30 18:07:28 +0200 |
commit | 672b76a098b99102a46712b1d982f550f97806f2 (patch) | |
tree | 98ac9dc6bf827df3a5d19086818264b4b6c8b181 /src/config.c | |
parent | fd1e80d9f4bad1805d801fc4501d86807c93a9ec (diff) |
peer: use iterator macro instead of callback
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/config.c b/src/config.c index c3fe154..48afae1 100644 --- a/src/config.c +++ b/src/config.c @@ -8,20 +8,15 @@ #include "hashtables.h" #include "peer.h" #include "uapi.h" - -static int clear_peer_endpoint_src(struct wireguard_peer *peer, void *data) -{ - socket_clear_peer_endpoint_src(peer); - return 0; -} - static int set_device_port(struct wireguard_device *wg, u16 port) { + struct wireguard_peer *peer, *temp; socket_uninit(wg); wg->incoming_port = port; if (!(netdev_pub(wg)->flags & IFF_UP)) return 0; - peer_for_each_unlocked(wg, clear_peer_endpoint_src, NULL); + peer_for_each (wg, peer, temp, false) + socket_clear_peer_endpoint_src(peer); return socket_init(wg); } @@ -133,6 +128,7 @@ int config_set_device(struct wireguard_device *wg, void __user *user_device) { int ret; size_t i, offset; + struct wireguard_peer *peer, *temp; struct wgdevice in_device; void __user *user_peer; bool modified_static_identity = false; @@ -152,7 +148,8 @@ int config_set_device(struct wireguard_device *wg, void __user *user_device) if (in_device.fwmark || (!in_device.fwmark && (in_device.flags & WGDEVICE_REMOVE_FWMARK))) { wg->fwmark = in_device.fwmark; - peer_for_each_unlocked(wg, clear_peer_endpoint_src, NULL); + peer_for_each (wg, peer, temp, false) + socket_clear_peer_endpoint_src(peer); } if (in_device.port) { @@ -183,8 +180,10 @@ int config_set_device(struct wireguard_device *wg, void __user *user_device) } if (modified_static_identity) { - if (peer_for_each_unlocked(wg, noise_precompute_static_static, NULL) < 0) - noise_set_static_identity_private_key(&wg->static_identity, NULL); + peer_for_each (wg, peer, temp, false) { + if (!noise_precompute_static_static(peer)) + peer_remove(peer); + } cookie_checker_precompute_device_keys(&wg->cookie_checker); } @@ -242,10 +241,9 @@ static int populate_ipmask(void *ctx, union nf_inet_addr ip, u8 cidr, int family return ret; } -static int populate_peer(struct wireguard_peer *peer, void *ctx) +static int populate_peer(struct wireguard_peer *peer, struct data_remaining *data) { int ret = 0; - struct data_remaining *data = ctx; void __user *upeer = data->data; struct wgpeer out_peer; struct data_remaining ipmasks_data = { NULL }; @@ -289,6 +287,7 @@ static int populate_peer(struct wireguard_peer *peer, void *ctx) int config_get_device(struct wireguard_device *wg, void __user *user_device) { int ret; + struct wireguard_peer *peer, *temp; struct net_device *dev = netdev_pub(wg); struct data_remaining peer_data = { NULL }; struct wgdevice out_device; @@ -330,7 +329,12 @@ int config_get_device(struct wireguard_device *wg, void __user *user_device) peer_data.out_len = in_device.peers_size; peer_data.data = user_device + sizeof(struct wgdevice); - ret = peer_for_each_unlocked(wg, populate_peer, &peer_data); + + peer_for_each (wg, peer, temp, false) { + ret = populate_peer(peer, &peer_data); + if (ret) + break; + } if (ret) goto out; out_device.num_peers = peer_data.count; |