summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2019-03-01 20:20:57 +0100
committerMikael Magnusson <mikma@users.sourceforge.net>2019-03-08 00:11:47 +0100
commit051f24f7c2b0a8210e5c866ea24e69c01edf5ee8 (patch)
tree056e4b9a023c5f481bc94a24b50be5e9c702ddb7
parentc6b6284560f65442f3d6c3accae583b7426b519d (diff)
wireguard: Simplify allowedip deletion
-rw-r--r--proto/wireguard/wireguard.c21
1 files changed, 5 insertions, 16 deletions
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;