summaryrefslogtreecommitdiff
path: root/proto
diff options
context:
space:
mode:
authorMikael Magnusson <mikma@users.sourceforge.net>2019-04-02 14:24:26 +0200
committerMikael Magnusson <mikma@users.sourceforge.net>2020-09-13 18:05:34 +0200
commit629afa8a735011534458473ebaa38a9a805b216e (patch)
treeb93e99f2e0506c78c74b26460359c1454eaf305c /proto
parent3a1fa0ab98bbb6cdd734dc1cb2897cd7875c06f4 (diff)
Wireguard: Reinit wg device at shutdown
Diffstat (limited to 'proto')
-rw-r--r--proto/wireguard/wireguard.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/proto/wireguard/wireguard.c b/proto/wireguard/wireguard.c
index 261c0e6e..20a42b5a 100644
--- a/proto/wireguard/wireguard.c
+++ b/proto/wireguard/wireguard.c
@@ -265,8 +265,15 @@ int get_device(struct wg_proto *p, wg_device **pdev, const char *device_name)
/* else */
/* return wg_get_device(dev, device_name); */
+ if (p->dev)
+ {
+ wg_free_device(p->dev);
+ p->dev = NULL;
+ }
+
wg_device *dev = calloc(1, sizeof(wg_device));
strncpy(dev->name, device_name, sizeof(dev->name));
+ dev->flags = WGDEVICE_REPLACE_PEERS;
if (c->private_key)
{
dev->flags |= WGDEVICE_HAS_PRIVATE_KEY | WGDEVICE_HAS_PUBLIC_KEY;
@@ -288,6 +295,8 @@ int get_device(struct wg_proto *p, wg_device **pdev, const char *device_name)
dev->last_peer->next_peer = peer;
dev->last_peer = peer;
+ peer->flags = WGPEER_REPLACE_ALLOWEDIPS;
+
if (pc->public_key)
{
peer->flags = WGPEER_HAS_PUBLIC_KEY;
@@ -935,6 +944,20 @@ wg_start(struct proto *P)
return PS_UP;
}
+static int
+wg_shutdown(struct proto *P)
+{
+ struct wg_config *cf = (struct wg_config*)P->cf;
+ struct wg_proto *p = (struct wg_proto*)P;
+
+ log(L_TRACE "WG: wg_shutdown");
+ if (get_device(p, &p->dev, cf->ifname) >= 0)
+ {
+ int res = set_device(p);
+ log(L_TRACE "WG: flush wg_set_device %d", res);
+ }
+}
+
static void
wg_dump(struct proto *P)
{
@@ -983,6 +1006,7 @@ struct protocol proto_wireguard = {
.postconfig = wg_postconfig,
.init = wg_init,
.start = wg_start,
+ .shutdown = wg_shutdown,
.dump = wg_dump,
/* .multitable = 1,
.preference = DEF_PREF_PIPE,