From 9b6a3695ea2cc2884943edc8d752ea639735bbb5 Mon Sep 17 00:00:00 2001 From: Jernej Jakob Date: Tue, 14 Apr 2020 21:58:53 +0200 Subject: openvpn: T2293: fix UnboundLocalError if server subnet is unset Commit bb36bde introduced a bug when server subnet is unset, this fixes it. --- src/conf_mode/interfaces-openvpn.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/conf_mode/interfaces-openvpn.py b/src/conf_mode/interfaces-openvpn.py index b42765586..79def4e45 100755 --- a/src/conf_mode/interfaces-openvpn.py +++ b/src/conf_mode/interfaces-openvpn.py @@ -124,13 +124,10 @@ def getDefaultServer(network, topology, devtype): Logic from openvpn's src/openvpn/helper.c. Returns a dict with addresses or False if the input parameters were incorrect. """ - if not (topology and devtype): - return False - if not (devtype == 'tun' or devtype == 'tap'): return False - if not network.prefixlen: + if not network.version == 4: return False elif (devtype == 'tun' and network.prefixlen > 29) or (devtype == 'tap' and network.prefixlen > 30): return False @@ -477,9 +474,10 @@ def get_config(): openvpn['tls_dh'] = 'none' # Set defaults where necessary. - # If any of the input parameters are missing or wrong, + # If any of the input parameters are wrong, # this will return False and no defaults will be set. - default_server = getDefaultServer(server_network, openvpn['server_topology'], openvpn['type']) + if server_network and openvpn['server_topology'] and openvpn['type']: + default_server = getDefaultServer(server_network, openvpn['server_topology'], openvpn['type']) if default_server: # server-bridge doesn't require a pool so don't set defaults for it if not openvpn['bridge_member']: -- cgit v1.2.3