diff options
| author | aapostoliuk <aapostoliuk@vyos.io> | 2025-07-09 18:06:13 +0300 |
|---|---|---|
| committer | aapostoliuk <a.apostoliuk@vyos.io> | 2025-07-18 13:08:10 +0300 |
| commit | f0ac13f3683d593e7700c46fc227cf223e0c79d5 (patch) | |
| tree | 9491a031b7d654610894832ef2f988bdace958cb | |
| parent | 4b34c65d4129eede784d5747653bd81f8d40f299 (diff) | |
| download | vyos-1x-f0ac13f3683d593e7700c46fc227cf223e0c79d5.tar.gz vyos-1x-f0ac13f3683d593e7700c46fc227cf223e0c79d5.zip | |
ipsec: T7504: Added IKEv2 retransmission options
Added IKEv2 retransmission options (base, tries, timeout).
| -rw-r--r-- | data/templates/ipsec/charon.j2 | 19 | ||||
| -rw-r--r-- | interface-definitions/vpn_ipsec.xml.in | 46 | ||||
| -rwxr-xr-x | smoketest/scripts/cli/test_vpn_ipsec.py | 54 |
3 files changed, 110 insertions, 9 deletions
diff --git a/data/templates/ipsec/charon.j2 b/data/templates/ipsec/charon.j2 index 388559af8..a9108eeda 100644 --- a/data/templates/ipsec/charon.j2 +++ b/data/templates/ipsec/charon.j2 @@ -202,15 +202,16 @@ charon { # Size of the AH/ESP replay window, in packets. # replay_window = 32 - # Base to use for calculating exponential back off, see IKEv2 RETRANSMISSION - # in strongswan.conf(5). - # retransmit_base = 1.8 - - # Timeout in seconds before sending first retransmit. - # retransmit_timeout = 4.0 - - # Number of times to retransmit a packet before giving up. - # retransmit_tries = 5 + # IKEv2 RETRANSMISSION +{% if options.retransmission.attempts is vyos_defined %} + retransmit_tries = {{ options.retransmission.attempts }} +{% endif %} +{% if options.retransmission.base is vyos_defined %} + retransmit_base = {{ options.retransmission.base }} +{% endif %} +{% if options.retransmission.timeout is vyos_defined %} + retransmit_timeout = {{ options.retransmission.timeout }} +{% endif %} # Interval in seconds to use when retrying to initiate an IKE_SA (e.g. if # DNS resolution failed), 0 to disable retries. diff --git a/interface-definitions/vpn_ipsec.xml.in b/interface-definitions/vpn_ipsec.xml.in index 873a4f882..a54b16736 100644 --- a/interface-definitions/vpn_ipsec.xml.in +++ b/interface-definitions/vpn_ipsec.xml.in @@ -701,6 +701,52 @@ <valueless/> </properties> </leafNode> + <node name="retransmission"> + <properties> + <help>IPsec retransmission settings</help> + </properties> + <children> + <leafNode name="attempts"> + <properties> + <help>Maximum number of retransmissions</help> + <valueHelp> + <format>u32:1-65535</format> + <description>Maximum number of retransmissions</description> + </valueHelp> + <constraint> + <validator name="numeric" argument="--range 1-65535"/> + </constraint> + </properties> + <defaultValue>5</defaultValue> + </leafNode> + <leafNode name="base"> + <properties> + <help>Base of exponential backoff</help> + <valueHelp> + <format><1.0-5.0></format> + <description>Base of exponential backoff</description> + </valueHelp> + <constraint> + <validator name="numeric" argument="--range 1-5 --float"/> + </constraint> + </properties> + <defaultValue>1.8</defaultValue> + </leafNode> + <leafNode name="timeout"> + <properties> + <help>Timeout in seconds before the first retransmission</help> + <valueHelp> + <format>u32:1-1000</format> + <description>Timeout in seconds before the first retransmission</description> + </valueHelp> + <constraint> + <validator name="numeric" argument="--range 1-1000"/> + </constraint> + </properties> + <defaultValue>4</defaultValue> + </leafNode> + </children> + </node> </children> </node> <tagNode name="profile"> diff --git a/smoketest/scripts/cli/test_vpn_ipsec.py b/smoketest/scripts/cli/test_vpn_ipsec.py index a0bf30953..f9f0bd669 100755 --- a/smoketest/scripts/cli/test_vpn_ipsec.py +++ b/smoketest/scripts/cli/test_vpn_ipsec.py @@ -16,6 +16,7 @@ import os import unittest +import re from base_vyostest_shim import VyOSUnitTestSHIM @@ -24,6 +25,8 @@ from vyos.ifconfig import Interface from vyos.utils.convert import encode_to_base64 from vyos.utils.process import process_named_running from vyos.utils.file import read_file +from vyos.xml_ref import default_value + ethernet_path = ['interfaces', 'ethernet'] tunnel_path = ['interfaces', 'tunnel'] @@ -107,6 +110,11 @@ swanctl_dir = '/etc/swanctl' CERT_PATH = f'{swanctl_dir}/x509/' CA_PATH = f'{swanctl_dir}/x509ca/' +def get_config_value(file, key): + tmp = read_file(file) + tmp = re.findall(f'\n?{key}\s+(.*)', tmp) + return tmp + class TestVPNIPsec(VyOSUnitTestSHIM.TestCase): skip_process_check = False @@ -1468,5 +1476,51 @@ class TestVPNIPsec(VyOSUnitTestSHIM.TestCase): self.tearDownPKI() + def test_retransmission_settings(self): + retransmit_base = '2.2' + retransmit_timeout = '10' + retransmit_attempts = '8' + self.cli_set(base_path + ['options', 'retransmission', 'base', retransmit_base]) + self.cli_set(base_path + ['options', 'retransmission', 'timeout', retransmit_timeout]) + self.cli_set(base_path + ['options', 'retransmission', 'attempts', retransmit_attempts]) + + self.cli_commit() + + # Verify charon configuration + charon_conf = read_file(charon_file) + charon_conf_lines = [ + f'# IKEv2 RETRANSMISSION', + f'retransmit_tries = {retransmit_attempts}', + f'retransmit_base = {retransmit_base}', + f'retransmit_timeout = {retransmit_timeout}', + ] + + for line in charon_conf_lines: + self.assertIn(line, charon_conf) + + def test_retransmission_default_settings(self): + # config file to cli options correspondence + retransmission_options = { + 'retransmit_base' : 'base', + 'retransmit_timeout': 'timeout', + 'retransmit_tries': 'attempts', + } + + # commit changes + self.cli_commit() + + for config_option, cli_option in retransmission_options.items(): + # Check configured value agains CLI default value + config_values_list = get_config_value(charon_file,config_option + ' =') + + if config_values_list: + config_value = config_values_list[0] + else: + config_value = None + cli_value = default_value(base_path + ['options', 'retransmission', cli_option]) + self.assertEqual(config_value, cli_value) + + + if __name__ == '__main__': unittest.main(verbosity=2) |
