Skip to content

Commit a6bd1c3

Browse files
committed
T4930: make wg dns retry configurable through interfaces wireguard wgX max-dns-retry
1 parent fe4fcab commit a6bd1c3

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

interface-definitions/interfaces_wireguard.xml.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@
4040
</properties>
4141
<defaultValue>0</defaultValue>
4242
</leafNode>
43+
<leafNode name="max-dns-retry">
44+
<properties>
45+
<help>Max retry when DNS resolves failed.</help>
46+
<valueHelp>
47+
<format>u32:1-15</format>
48+
<description>Max retry times</description>
49+
</valueHelp>
50+
<constraint>
51+
<validator name="numeric" argument="--range 1-15"/>
52+
</constraint>
53+
</properties>
54+
<defaultValue>3</defaultValue>
55+
</leafNode>
4356
<leafNode name="private-key">
4457
<properties>
4558
<help>Base64 encoded private key</help>

python/vyos/ifconfig/wireguard.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ def reset_peer(self, interface, peer_name=None):
161161

162162
c = Config()
163163
c.set_level(['interfaces', 'wireguard', self.config['ifname']])
164+
max_dns_retry = c.return_effective_value(['max-dns-retry'], 3)
164165

165166
for peer in c.list_effective_nodes(['peer']):
166167
if peer_name is None or peer == peer_name:
@@ -179,7 +180,7 @@ def reset_peer(self, interface, peer_name=None):
179180
f'Resetting {self.config["ifname"]} peer {public_key} endpoint to {address}:{port} ... ',
180181
end='',
181182
)
182-
self._cmd(cmd, env={'WG_ENDPOINT_RESOLUTION_RETRIES': '5'})
183+
self._cmd(cmd, env={'WG_ENDPOINT_RESOLUTION_RETRIES': str(max_dns_retry)})
183184
print('done')
184185
except:
185186
print(f'Error\nPlease try to run command manually:\n{cmd}')
@@ -216,6 +217,7 @@ def update(self, config):
216217

217218
# Wireguard base command is identical for every peer
218219
base_cmd = 'wg set ' + config['ifname']
220+
max_dns_retry = config['max_dns_retry']
219221

220222
interface_cmd = base_cmd
221223
if 'port' in config:
@@ -277,7 +279,7 @@ def update(self, config):
277279

278280
self._cmd(
279281
cmd.format(**peer_config),
280-
env={'WG_ENDPOINT_RESOLUTION_RETRIES': '5'},
282+
env={'WG_ENDPOINT_RESOLUTION_RETRIES': str(max_dns_retry)},
281283
)
282284
except:
283285
# todo: logging

0 commit comments

Comments
 (0)