From f87144f84b29017806bb9458a2af907010526d1a Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Tue, 13 Dec 2022 08:35:01 +0800 Subject: [PATCH] chore: add persistent-keepalive for wireguard --- adapter/outbound/wireguard.go | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/adapter/outbound/wireguard.go b/adapter/outbound/wireguard.go index 22eca388..75cb6f9f 100644 --- a/adapter/outbound/wireguard.go +++ b/adapter/outbound/wireguard.go @@ -41,18 +41,19 @@ type WireGuard struct { type WireGuardOption struct { BasicOption - Name string `proxy:"name"` - Server string `proxy:"server"` - Port int `proxy:"port"` - Ip string `proxy:"ip,omitempty"` - Ipv6 string `proxy:"ipv6,omitempty"` - PrivateKey string `proxy:"private-key"` - PublicKey string `proxy:"public-key"` - PreSharedKey string `proxy:"pre-shared-key,omitempty"` - Reserved []int `proxy:"reserved,omitempty"` - Workers int `proxy:"workers,omitempty"` - MTU int `proxy:"mtu,omitempty"` - UDP bool `proxy:"udp,omitempty"` + Name string `proxy:"name"` + Server string `proxy:"server"` + Port int `proxy:"port"` + Ip string `proxy:"ip,omitempty"` + Ipv6 string `proxy:"ipv6,omitempty"` + PrivateKey string `proxy:"private-key"` + PublicKey string `proxy:"public-key"` + PreSharedKey string `proxy:"pre-shared-key,omitempty"` + Reserved []int `proxy:"reserved,omitempty"` + Workers int `proxy:"workers,omitempty"` + MTU int `proxy:"mtu,omitempty"` + UDP bool `proxy:"udp,omitempty"` + PersistentKeepalive int `proxy:"persistent-keepalive,omitempty"` } type wgDialer struct { @@ -159,6 +160,9 @@ func NewWireGuard(option WireGuardOption) (*WireGuard, error) { if has6 { ipcConf += "\nallowed_ip=::/0" } + if option.PersistentKeepalive != 0 { + ipcConf += fmt.Sprintf("\npersistent_keepalive_interval=%d", option.PersistentKeepalive) + } mtu := option.MTU if mtu == 0 { mtu = 1408