Skip to content

Commit 12caa70

Browse files
committed
tunspace: re-add IPv6 address after it gets flushed
IPv6 addresses get flushed when an interface is taken down. Now that we take the interface down for convenience reasons, we need to re-add the address when we bring it back up.
1 parent 53626e2 commit 12caa70

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

packages/tunspace/tunspace.uc

+21-15
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,10 @@ function create_wg_interface(nsid, ifname, ifcfg, netns) {
186186
return false;
187187
}
188188

189-
// add ipv6 address
190-
if (length(ifcfg.ipv6) > 0) {
191-
rtnl_request(rtnl.const.RTM_NEWADDR,
192-
rtnl.const.NLM_F_REQUEST|rtnl.const.NLM_F_CREATE|rtnl.const.NLM_F_EXCL, {
193-
"dev": ifname,
194-
"family": rtnl.const.AF_INET6,
195-
"address": ifcfg.ipv6,
196-
});
197-
if (err = rtnl.error()) {
198-
log("RTM_NEWADDR with AF_INET6 failed: "+err);
199-
return false;
200-
}
201-
}
202-
203189
// add ipv4 address
190+
// ipv4 addresses dont get flushed when the interface goes down, so we can
191+
// add it once at the beginning (here) and be done with it.
192+
// the ipv6 address will be added everytime we change the endpoint.
204193
if (length(ifcfg.ipv4) > 0) {
205194
rtnl_request(rtnl.const.RTM_NEWADDR,
206195
rtnl.const.NLM_F_REQUEST|rtnl.const.NLM_F_CREATE|rtnl.const.NLM_F_EXCL, {
@@ -229,7 +218,8 @@ function wg_replace_endpoint(ifname, cfg, next) {
229218
let srvcfg = cfg.wireguard_servers[next];
230219
let certopt = srvcfg.insecure_cert ? "--no-check-certificate" : "";
231220

232-
// bring interface down to prevent OLSR and Babel from spamming syslog.
221+
// bring interface down
222+
// it's not technically neccessary, just for aesthetics.
233223
if (0 != shell_command("ip link set down "+ifname)) {
234224
return false;
235225
}
@@ -355,6 +345,22 @@ function wg_replace_endpoint(ifname, cfg, next) {
355345
return false;
356346
}
357347

348+
// add ipv6 address
349+
// as ipv6 addresses get flushed when and interface is set down,
350+
// we need to re-add it everytime we bring it up.
351+
if (length(ifcfg.ipv6) > 0) {
352+
rtnl_request(rtnl.const.RTM_NEWADDR,
353+
rtnl.const.NLM_F_REQUEST|rtnl.const.NLM_F_CREATE|rtnl.const.NLM_F_EXCL, {
354+
"dev": ifname,
355+
"family": rtnl.const.AF_INET6,
356+
"address": ifcfg.ipv6,
357+
});
358+
if (err = rtnl.error()) {
359+
log("RTM_NEWADDR with AF_INET6 failed: "+err);
360+
return false;
361+
}
362+
}
363+
358364
return true;
359365
}
360366

0 commit comments

Comments
 (0)