summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-18 16:37:58 +0100
committerChristian Poessinger <christian@poessinger.com>2020-03-18 16:38:10 +0100
commit57bd20e3f1bbf41724b9d743f27b82419d70886f (patch)
tree49c57c81d1f801a01ab2c22355ec485acfb77a8c /src
parentc7b9230c418662fb08d6b4557c9ba003dff50e08 (diff)
downloadvyos-1x-57bd20e3f1bbf41724b9d743f27b82419d70886f.tar.gz
vyos-1x-57bd20e3f1bbf41724b9d743f27b82419d70886f.zip
l2tpv3: T1923: move kernel module load to helper function
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/interfaces-l2tpv3.py35
1 files changed, 8 insertions, 27 deletions
diff --git a/src/conf_mode/interfaces-l2tpv3.py b/src/conf_mode/interfaces-l2tpv3.py
index 1b9425f64..3bc3faca8 100755
--- a/src/conf_mode/interfaces-l2tpv3.py
+++ b/src/conf_mode/interfaces-l2tpv3.py
@@ -42,6 +42,13 @@ default_config_data = {
'tunnel_id': ''
}
+def check_kmod():
+ modules = ['l2tp_eth', 'l2tp_netlink', 'l2tp_ip', 'l2tp_ip6']
+ for module in modules:
+ if not os.path.exists(f'/sys/module/{module}'):
+ if os.system(f'modprobe {module}') != 0:
+ raise ConfigError(f'Loading Kernel module {module} failed')
+
def get_config():
l2tpv3 = deepcopy(default_config_data)
conf = Config()
@@ -152,35 +159,8 @@ def verify(l2tpv3):
def generate(l2tpv3):
- if l2tpv3['deleted']:
- # bail out early
- return None
-
- # initialize kernel module if not loaded
- if not os.path.isdir('/sys/module/l2tp_eth'):
- if os.system('modprobe l2tp_eth') != 0:
- raise ConfigError("failed loading l2tp_eth kernel module")
-
- if not os.path.isdir('/sys/module/l2tp_netlink'):
- if os.system('modprobe l2tp_netlink') != 0:
- raise ConfigError("failed loading l2tp_netlink kernel module")
-
- if not os.path.isdir('/sys/module/l2tp_ip'):
- if os.system('modprobe l2tp_ip') != 0:
- raise ConfigError("failed loading l2tp_ip kernel module")
-
- if l2tpv3['encapsulation'] == 'ip':
- if not os.path.isdir('/sys/module/l2tp_ip'):
- if os.system('modprobe l2tp_ip') != 0:
- raise ConfigError("failed loading l2tp_ip kernel module")
-
- if not os.path.isdir('/sys/module/l2tp_ip6 '):
- if os.system('modprobe l2tp_ip6 ') != 0:
- raise ConfigError("failed loading l2tp_ip6 kernel module")
-
return None
-
def apply(l2tpv3):
# L2TPv3 interface needs to be created/deleted on-block, instead of
# passing a ton of arguments, I just use a dict that is managed by
@@ -230,6 +210,7 @@ def apply(l2tpv3):
if __name__ == '__main__':
try:
+ check_kmod()
c = get_config()
verify(c)
generate(c)