Skip to content

Commit

Permalink
T4930: resolve code change requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sskaje committed Dec 27, 2024
1 parent 6c2c881 commit 2600895
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
23 changes: 11 additions & 12 deletions python/vyos/ifconfig/wireguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,11 @@ def show_interface(self):
return answer

def get_latest_handshakes(self):

"""Get latest handshake time for each peer"""
output = {}

# Dump wireguard last handshake
_f = self._cmd(f'wg show {self.config["ifname"]} latest-handshakes')
_f = self._cmd(f'wg show {self.ifname} latest-handshakes')
# Output:
# xxxw= 1732812147
# xxx= 0
Expand All @@ -180,17 +179,17 @@ def get_latest_handshakes(self):
return output

def reset_peer(self, peer_name=None, public_key=None):
from vyos.config import Config
from vyos.configquery import ConfigTreeQuery
c = ConfigTreeQuery()

c = Config()
c.set_level(['interfaces', 'wireguard', self.config['ifname']])
max_dns_retry = c.return_effective_value(['max-dns-retry'], 3)
c.set_level(['interfaces', 'wireguard', self.ifname])
max_dns_retry = c.value(['max-dns-retry'], 3)

for peer in c.list_effective_nodes(['peer']):
peer_public_key = c.return_effective_value(['peer', peer, 'public-key'])
for peer in c.list_nodes(['peer']):
peer_public_key = c.value(['peer', peer, 'public-key'])
if peer_name is None or peer == peer_name or public_key == peer_public_key:
address = c.return_effective_value(['peer', peer, 'address'])
port = c.return_effective_value(['peer', peer, 'port'])
address = c.value(['peer', peer, 'address'])
port = c.value(['peer', peer, 'port'])

if not address or not port:
if peer_name is not None:
Expand All @@ -200,10 +199,10 @@ def reset_peer(self, peer_name=None, public_key=None):
if c.exists_effective(['peer', peer, 'disable']):
continue

cmd = f"wg set {self.config['ifname']} peer {peer_public_key} endpoint {address}:{port}"
cmd = f"wg set {self.ifname} peer {peer_public_key} endpoint {address}:{port}"
try:
print(
f'Resetting {self.config["ifname"]} peer {peer_public_key} endpoint to {address}:{port} ... ',
f'Resetting {self.ifname} peer {peer_public_key} endpoint to {address}:{port} ... ',
end='',
)
self._cmd(
Expand Down
3 changes: 3 additions & 0 deletions src/helpers/vyos-domain-resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ def update_interfaces(config, node):
if node == 'interfaces':
wireguard_interfaces = dict_search_args(config, 'wireguard')

# WireGuard redo handshake usually every 180 seconds, but not documented officially.
# If peer with domain name in its endpoint didn't get handshake for over 300 seconds,
# we do re-resolv and reset its endpoint from config tree.
handshake_threshold = 300

from vyos.ifconfig import WireGuardIf
Expand Down

0 comments on commit 2600895

Please sign in to comment.