Skip to content

Commit ade8e45

Browse files
authored
Merge pull request #4601 from aapostoliuk/T7504-current
ipsec: T7504: Added IKEv2 retransmission options
2 parents 7a88b0b + f0ac13f commit ade8e45

File tree

3 files changed

+110
-9
lines changed

3 files changed

+110
-9
lines changed

data/templates/ipsec/charon.j2

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,16 @@ charon {
202202
# Size of the AH/ESP replay window, in packets.
203203
# replay_window = 32
204204

205-
# Base to use for calculating exponential back off, see IKEv2 RETRANSMISSION
206-
# in strongswan.conf(5).
207-
# retransmit_base = 1.8
208-
209-
# Timeout in seconds before sending first retransmit.
210-
# retransmit_timeout = 4.0
211-
212-
# Number of times to retransmit a packet before giving up.
213-
# retransmit_tries = 5
205+
# IKEv2 RETRANSMISSION
206+
{% if options.retransmission.attempts is vyos_defined %}
207+
retransmit_tries = {{ options.retransmission.attempts }}
208+
{% endif %}
209+
{% if options.retransmission.base is vyos_defined %}
210+
retransmit_base = {{ options.retransmission.base }}
211+
{% endif %}
212+
{% if options.retransmission.timeout is vyos_defined %}
213+
retransmit_timeout = {{ options.retransmission.timeout }}
214+
{% endif %}
214215

215216
# Interval in seconds to use when retrying to initiate an IKE_SA (e.g. if
216217
# DNS resolution failed), 0 to disable retries.

interface-definitions/vpn_ipsec.xml.in

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,52 @@
701701
<valueless/>
702702
</properties>
703703
</leafNode>
704+
<node name="retransmission">
705+
<properties>
706+
<help>IPsec retransmission settings</help>
707+
</properties>
708+
<children>
709+
<leafNode name="attempts">
710+
<properties>
711+
<help>Maximum number of retransmissions</help>
712+
<valueHelp>
713+
<format>u32:1-65535</format>
714+
<description>Maximum number of retransmissions</description>
715+
</valueHelp>
716+
<constraint>
717+
<validator name="numeric" argument="--range 1-65535"/>
718+
</constraint>
719+
</properties>
720+
<defaultValue>5</defaultValue>
721+
</leafNode>
722+
<leafNode name="base">
723+
<properties>
724+
<help>Base of exponential backoff</help>
725+
<valueHelp>
726+
<format>&lt;1.0-5.0&gt;</format>
727+
<description>Base of exponential backoff</description>
728+
</valueHelp>
729+
<constraint>
730+
<validator name="numeric" argument="--range 1-5 --float"/>
731+
</constraint>
732+
</properties>
733+
<defaultValue>1.8</defaultValue>
734+
</leafNode>
735+
<leafNode name="timeout">
736+
<properties>
737+
<help>Timeout in seconds before the first retransmission</help>
738+
<valueHelp>
739+
<format>u32:1-1000</format>
740+
<description>Timeout in seconds before the first retransmission</description>
741+
</valueHelp>
742+
<constraint>
743+
<validator name="numeric" argument="--range 1-1000"/>
744+
</constraint>
745+
</properties>
746+
<defaultValue>4</defaultValue>
747+
</leafNode>
748+
</children>
749+
</node>
704750
</children>
705751
</node>
706752
<tagNode name="profile">

smoketest/scripts/cli/test_vpn_ipsec.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import os
1818
import unittest
19+
import re
1920

2021
from base_vyostest_shim import VyOSUnitTestSHIM
2122

@@ -24,6 +25,8 @@
2425
from vyos.utils.convert import encode_to_base64
2526
from vyos.utils.process import process_named_running
2627
from vyos.utils.file import read_file
28+
from vyos.xml_ref import default_value
29+
2730

2831
ethernet_path = ['interfaces', 'ethernet']
2932
tunnel_path = ['interfaces', 'tunnel']
@@ -107,6 +110,11 @@
107110
CERT_PATH = f'{swanctl_dir}/x509/'
108111
CA_PATH = f'{swanctl_dir}/x509ca/'
109112

113+
def get_config_value(file, key):
114+
tmp = read_file(file)
115+
tmp = re.findall(f'\n?{key}\s+(.*)', tmp)
116+
return tmp
117+
110118
class TestVPNIPsec(VyOSUnitTestSHIM.TestCase):
111119
skip_process_check = False
112120

@@ -1468,5 +1476,51 @@ def test_remote_access_vti(self):
14681476

14691477
self.tearDownPKI()
14701478

1479+
def test_retransmission_settings(self):
1480+
retransmit_base = '2.2'
1481+
retransmit_timeout = '10'
1482+
retransmit_attempts = '8'
1483+
self.cli_set(base_path + ['options', 'retransmission', 'base', retransmit_base])
1484+
self.cli_set(base_path + ['options', 'retransmission', 'timeout', retransmit_timeout])
1485+
self.cli_set(base_path + ['options', 'retransmission', 'attempts', retransmit_attempts])
1486+
1487+
self.cli_commit()
1488+
1489+
# Verify charon configuration
1490+
charon_conf = read_file(charon_file)
1491+
charon_conf_lines = [
1492+
f'# IKEv2 RETRANSMISSION',
1493+
f'retransmit_tries = {retransmit_attempts}',
1494+
f'retransmit_base = {retransmit_base}',
1495+
f'retransmit_timeout = {retransmit_timeout}',
1496+
]
1497+
1498+
for line in charon_conf_lines:
1499+
self.assertIn(line, charon_conf)
1500+
1501+
def test_retransmission_default_settings(self):
1502+
# config file to cli options correspondence
1503+
retransmission_options = {
1504+
'retransmit_base' : 'base',
1505+
'retransmit_timeout': 'timeout',
1506+
'retransmit_tries': 'attempts',
1507+
}
1508+
1509+
# commit changes
1510+
self.cli_commit()
1511+
1512+
for config_option, cli_option in retransmission_options.items():
1513+
# Check configured value agains CLI default value
1514+
config_values_list = get_config_value(charon_file,config_option + ' =')
1515+
1516+
if config_values_list:
1517+
config_value = config_values_list[0]
1518+
else:
1519+
config_value = None
1520+
cli_value = default_value(base_path + ['options', 'retransmission', cli_option])
1521+
self.assertEqual(config_value, cli_value)
1522+
1523+
1524+
14711525
if __name__ == '__main__':
14721526
unittest.main(verbosity=2)

0 commit comments

Comments
 (0)