Skip to content

Commit

Permalink
Fix #64, bring back server side keepalive (renamed for clarity)
Browse files Browse the repository at this point in the history
  • Loading branch information
NHAS committed Nov 30, 2023
1 parent 276b743 commit 78df023
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ type Config struct {
MTU int

//Not externally configurable
External bool `json:"-"`
Range *net.IPNet `json:"-"`
ServerAddress net.IP `json:"-"`
External bool `json:"-"`
Range *net.IPNet `json:"-"`
ServerAddress net.IP `json:"-"`
ServerPersistentKeepAlive int

DNS []string `json:",omitempty"`
}
Expand Down
11 changes: 9 additions & 2 deletions internal/router/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net"
"sort"
"time"
"unsafe"

"github.com/NHAS/wag/internal/config"
Expand Down Expand Up @@ -98,13 +99,19 @@ func setupWireguard() error {

_, network, _ := net.ParseCIDR(device.Address + "/32")

c.Peers = append(c.Peers, wgtypes.PeerConfig{
pc := wgtypes.PeerConfig{
PublicKey: pk,
ReplaceAllowedIPs: true,
AllowedIPs: []net.IPNet{*network},
Endpoint: device.Endpoint,
PresharedKey: psk,
})
}

if config.Values().Wireguard.ServerPersistentKeepAlive > 0 {
d := time.Duration(config.Values().Wireguard.ServerPersistentKeepAlive) * time.Second
pc.PersistentKeepaliveInterval = &d
}
c.Peers = append(c.Peers, pc)
}

ctrl, err = wgctrl.New()
Expand Down

0 comments on commit 78df023

Please sign in to comment.