@@ -186,21 +186,10 @@ function create_wg_interface(nsid, ifname, ifcfg, netns) {
186
186
return false ;
187
187
}
188
188
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
-
203
189
// 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.
204
193
if (length (ifcfg .ipv4 ) > 0 ) {
205
194
rtnl_request (rtnl .const .RTM_NEWADDR ,
206
195
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) {
229
218
let srvcfg = cfg .wireguard_servers [next ];
230
219
let certopt = srvcfg .insecure_cert ? "--no-check-certificate" : "" ;
231
220
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.
233
223
if (0 != shell_command ("ip link set down " +ifname )) {
234
224
return false ;
235
225
}
@@ -355,6 +345,22 @@ function wg_replace_endpoint(ifname, cfg, next) {
355
345
return false ;
356
346
}
357
347
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
+
358
364
return true ;
359
365
}
360
366
0 commit comments