From 051f24f7c2b0a8210e5c866ea24e69c01edf5ee8 Mon Sep 17 00:00:00 2001 From: Mikael Magnusson Date: Fri, 1 Mar 2019 20:20:57 +0100 Subject: wireguard: Simplify allowedip deletion --- proto/wireguard/wireguard.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'proto/wireguard') diff --git a/proto/wireguard/wireguard.c b/proto/wireguard/wireguard.c index 3cb80ed6..e9cb9cf2 100644 --- a/proto/wireguard/wireguard.c +++ b/proto/wireguard/wireguard.c @@ -217,9 +217,7 @@ wg_rt_notify(struct proto *P, struct channel *ch UNUSED, struct network *n, debug("WG: found ip\n"); - struct wg_allowedip *next = ip->next_allowedip; - - if (peer->first_allowedip == ip) { + if (!previp) { debug("WG: remove first\n"); peer->first_allowedip = ip->next_allowedip; if (peer->last_allowedip == ip) @@ -227,23 +225,14 @@ wg_rt_notify(struct proto *P, struct channel *ch UNUSED, struct network *n, } else { debug("WG: remove middle\n"); // Remove - struct wg_allowedip *cur = NULL; - wg_for_each_allowedip(peer, cur) { - if (cur->next_allowedip != ip) - continue; - - debug("WG: remove next\n"); - if (peer->last_allowedip == ip) - peer->last_allowedip = cur; - - cur->next_allowedip = ip->next_allowedip; - break; - } + if (peer->last_allowedip == ip) + peer->last_allowedip = previp; + + previp->next_allowedip = ip->next_allowedip; } free(ip); break; - /* ip = next; */ } peer->flags |= WGPEER_REPLACE_ALLOWEDIPS; -- cgit v1.2.3