diff options
author | Daniil Baturin <daniil@vyos.io> | 2021-07-23 23:43:03 -0500 |
---|---|---|
committer | Daniil Baturin <daniil@vyos.io> | 2021-07-23 23:44:00 -0500 |
commit | 483e0b3327918719fb38dbdd9b6fb755aecce2eb (patch) | |
tree | 5fb6b5fece8e40d032aa7341de521bb1b42a44b8 /src | |
parent | 7292631373ea50f9908796ef2eda32e672d1df2e (diff) | |
download | vyos-1x-483e0b3327918719fb38dbdd9b6fb755aecce2eb.tar.gz vyos-1x-483e0b3327918719fb38dbdd9b6fb755aecce2eb.zip |
T3697: return an empty dict when IPsec isn't fully configured
to avoid trying to wait for a daemon that shouldn't even be running.
Diffstat (limited to 'src')
-rwxr-xr-x | src/conf_mode/ipsec-settings.py | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/conf_mode/ipsec-settings.py b/src/conf_mode/ipsec-settings.py index b02f3bcb0..ce313d9a0 100755 --- a/src/conf_mode/ipsec-settings.py +++ b/src/conf_mode/ipsec-settings.py @@ -46,6 +46,14 @@ def get_config(config=None): config = config else: config = Config() + + # IPsec isn't configured enough to warrant starting StrongSWAN for it, + # it's just some incomplete or leftover options. + if config.exists("vpn ipsec site-to-site peer") or \ + config.exists("vpn ipsec profile") or \ + config.exists("vpn l2tp remote-access ipsec-settings"): + return {} + data = {"install_routes": "yes"} if config.exists("vpn ipsec options disable-route-autoinstall"): @@ -204,6 +212,10 @@ def generate(data): def restart_ipsec(): try: + # Restart the IPsec daemon when it's running. + # Since it's started by the legacy ipsec.pl in VyOS 1.3, + # there's a chance that this script will run before charon is up, + # so we can't assume it's running and have to check and wait if needed. wait_for_file_write_complete(charon_pidfile, pre_hook=(lambda: call('ipsec restart >&/dev/null')), timeout=10) @@ -214,22 +226,18 @@ def restart_ipsec(): except OSError: raise ConfigError('VPN configuration error: IPSec process did not start.') -def apply(data, config): - if config.exists("vpn ipsec site-to-site peer") or \ - config.exists("vpn ipsec profile") or \ - config.exists("vpn l2tp remote-access ipsec-settings"): - # Restart IPSec daemon +def apply(data): + if data: restart_ipsec() else: - print() + print("Note: the IPsec process will not start until you configure some tunnels, profiles, or L2TP/IPsec settings") if __name__ == '__main__': try: - vyos_config = Config() - c = get_config(vyos_config) + c = get_config() verify(c) generate(c) - apply(c, vyos_config) + apply(c) except ConfigError as e: print(e) exit(1) |