Skip to content

Commit

Permalink
feat: allow setting peer endpoint using peer event
Browse files Browse the repository at this point in the history
With this change it will be possible to recover wireguard connection
immediately after the siderolink server is restarted, instead of waiting
for the client to send keep alive packet.

Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
  • Loading branch information
Unix4ever committed May 26, 2022
1 parent 5d085d6 commit 1d2b7e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/wireguard/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type PeerSource interface {
type PeerEvent struct {
PubKey wgtypes.Key

Remove bool
Remove bool
Endpoint string

Address netaddr.IP
}
9 changes: 9 additions & 0 deletions pkg/wireguard/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,15 @@ func (dev *Device) handlePeerEvent(logger *zap.Logger, peerEvent PeerEvent) erro
*netaddr.IPPrefixFrom(peerEvent.Address, peerEvent.Address.BitLen()).IPNet(),
}

if peerEvent.Endpoint != "" {
ip, err := netaddr.ParseIPPort(peerEvent.Endpoint)
if err != nil {
return fmt.Errorf("failed to parse last endpoint: %w", err)
}

cfg.Peers[0].Endpoint = ip.UDPAddr()
}

logger.Info("updating peer", zap.Stringer("public_key", peerEvent.PubKey), zap.Stringer("address", peerEvent.Address))
} else {
logger.Info("removing peer", zap.Stringer("public_key", peerEvent.PubKey))
Expand Down

0 comments on commit 1d2b7e1

Please sign in to comment.