feat(wireguard): WIREGUARD_PERSISTENT_KEEPALIVE_INTERVAL option

This commit is contained in:
Quentin McGaw
2024-04-25 10:42:09 +00:00
parent 7b4befce61
commit c87c0e12fe
7 changed files with 65 additions and 15 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net"
"net/netip"
"time"
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
@@ -43,6 +44,12 @@ func makeDeviceConfig(settings Settings) (config wgtypes.Config, err error) {
preSharedKey = &preSharedKeyValue
}
var persistentKeepaliveInterval *time.Duration
if settings.PersistentKeepaliveInterval > 0 {
persistentKeepaliveInterval = new(time.Duration)
*persistentKeepaliveInterval = settings.PersistentKeepaliveInterval
}
firewallMark := settings.FirewallMark
config = wgtypes.Config{
@@ -63,7 +70,8 @@ func makeDeviceConfig(settings Settings) (config wgtypes.Config, err error) {
Mask: []byte(net.IPv6zero),
},
},
ReplaceAllowedIPs: true,
PersistentKeepaliveInterval: persistentKeepaliveInterval,
ReplaceAllowedIPs: true,
Endpoint: &net.UDPAddr{
IP: settings.Endpoint.Addr().AsSlice(),
Port: int(settings.Endpoint.Port()),