summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-10-08 18:27:12 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-08 18:51:34 +0200
commitb3e330d12b0778cb0dc28b7d646c038d8e0b5613 (patch)
tree65cfc7a4297337a740bc21d6c7e8809b42fd2194
parent6769955cdfd509b446d18ec989275bc18ec29236 (diff)
timers: avoid using control statements in macro
Suggested-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r--src/timers.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/timers.c b/src/timers.c
index e6aacc5..0312bd8 100644
--- a/src/timers.c
+++ b/src/timers.c
@@ -26,13 +26,13 @@
* specified seconds.
*/
-#define peer_get_from_timer(timer_name) \
+#define peer_get_from_timer(timer_name) ({ \
struct wg_peer *peer; \
rcu_read_lock_bh(); \
peer = wg_peer_get_maybe_zero(from_timer(peer, timer, timer_name)); \
rcu_read_unlock_bh(); \
- if (unlikely(!peer)) \
- return;
+ peer; \
+})
static inline void mod_peer_timer(struct wg_peer *peer,
struct timer_list *timer,
@@ -55,7 +55,10 @@ static inline void del_peer_timer(struct wg_peer *peer,
static void wg_expired_retransmit_handshake(struct timer_list *timer)
{
- peer_get_from_timer(timer_retransmit_handshake);
+ struct wg_peer *peer = peer_get_from_timer(timer_retransmit_handshake);
+
+ if (unlikely(!peer))
+ return;
if (peer->timer_handshake_attempts > MAX_TIMER_HANDSHAKES) {
pr_debug("%s: Handshake for peer %llu (%pISpfsc) did not complete after %d attempts, giving up\n",
@@ -93,7 +96,10 @@ static void wg_expired_retransmit_handshake(struct timer_list *timer)
static void wg_expired_send_keepalive(struct timer_list *timer)
{
- peer_get_from_timer(timer_send_keepalive);
+ struct wg_peer *peer = peer_get_from_timer(timer_send_keepalive);
+
+ if (unlikely(!peer))
+ return;
wg_packet_send_keepalive(peer);
if (peer->timer_need_another_keepalive) {
@@ -106,7 +112,10 @@ static void wg_expired_send_keepalive(struct timer_list *timer)
static void wg_expired_new_handshake(struct timer_list *timer)
{
- peer_get_from_timer(timer_new_handshake);
+ struct wg_peer *peer = peer_get_from_timer(timer_new_handshake);
+
+ if (unlikely(!peer))
+ return;
pr_debug("%s: Retrying handshake with peer %llu (%pISpfsc) because we stopped hearing back after %d seconds\n",
peer->device->dev->name, peer->internal_id,
@@ -121,7 +130,10 @@ static void wg_expired_new_handshake(struct timer_list *timer)
static void wg_expired_zero_key_material(struct timer_list *timer)
{
- peer_get_from_timer(timer_zero_key_material);
+ struct wg_peer *peer = peer_get_from_timer(timer_zero_key_material);
+
+ if (unlikely(!peer))
+ return;
rcu_read_lock_bh();
if (!peer->is_dead) {
@@ -149,7 +161,10 @@ static void wg_queued_expired_zero_key_material(struct work_struct *work)
static void wg_expired_send_persistent_keepalive(struct timer_list *timer)
{
- peer_get_from_timer(timer_persistent_keepalive);
+ struct wg_peer *peer = peer_get_from_timer(timer_persistent_keepalive);
+
+ if (unlikely(!peer))
+ return;
if (likely(peer->persistent_keepalive_interval))
wg_packet_send_keepalive(peer);