diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-10-18 20:46:14 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2020-10-18 20:46:14 +0200 |
commit | b67bf3f77d1eee7f6075ad1a5daf67ecd5755f0b (patch) | |
tree | 93a848bb9c170adaa1f51fbbb382ed8aecfde4bc | |
parent | 029f9839c21317ec5959b331eee25da472d08dc1 (diff) | |
download | vyos-1x-b67bf3f77d1eee7f6075ad1a5daf67ecd5755f0b.tar.gz vyos-1x-b67bf3f77d1eee7f6075ad1a5daf67ecd5755f0b.zip |
openvpn: T2969: ensure interface is always removed
-rwxr-xr-x | src/conf_mode/interfaces-openvpn.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/conf_mode/interfaces-openvpn.py b/src/conf_mode/interfaces-openvpn.py index 9cd72f691..3f4965029 100755 --- a/src/conf_mode/interfaces-openvpn.py +++ b/src/conf_mode/interfaces-openvpn.py @@ -21,7 +21,6 @@ from copy import deepcopy from sys import exit,stderr from ipaddress import ip_address,ip_network,IPv4Address,IPv4Network,IPv6Address,IPv6Network,summarize_address_range from netifaces import interfaces -from time import sleep from shutil import rmtree from vyos.config import Config @@ -1035,6 +1034,12 @@ def apply(openvpn): interface = openvpn['intf'] call(f'systemctl stop openvpn@{interface}.service') + # On configuration change we need to wait for the 'old' interface to + # vanish from the Kernel, if it is not gone, OpenVPN will report: + # ERROR: Cannot ioctl TUNSETIFF vtun10: Device or resource busy (errno=16) + if interface in interfaces(): + cmd(f'sudo ip link del {interface}') + # Do some cleanup when OpenVPN is disabled/deleted if openvpn['deleted'] or openvpn['disable']: # cleanup old configuration files @@ -1048,19 +1053,16 @@ def apply(openvpn): return None - # On configuration change we need to wait for the 'old' interface to - # vanish from the Kernel, if it is not gone, OpenVPN will report: - # ERROR: Cannot ioctl TUNSETIFF vtun10: Device or resource busy (errno=16) - while interface in interfaces(): - sleep(0.250) # 250ms - # No matching OpenVPN process running - maybe it got killed or none # existed - nevertheless, spawn new OpenVPN process call(f'systemctl start openvpn@{interface}.service') if interface not in interfaces(): - dev_type = openvpn['type'] - cmd(f'sudo openvpn --mktun --dev-type {dev_type} --dev {interface}') + try: + dev_type = openvpn['type'] + cmd(f'sudo openvpn --mktun --dev-type {dev_type} --dev {interface}') + except: + pass # we need to catch the exception if the interface is not up due to # reason stated above |