summaryrefslogtreecommitdiff
path: root/src/conf_mode/interfaces-l2tpv3.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-07-21 15:59:06 +0200
committerChristian Poessinger <christian@poessinger.com>2020-07-25 15:35:06 +0200
commit1a85e758b105d493bb9d95916816bd206345bc5d (patch)
treed8b3e5aa12a539e84f5dc1554adb76811513257c /src/conf_mode/interfaces-l2tpv3.py
parent61dccd81a1037c06ae883020db51409dda3e41f9 (diff)
downloadvyos-1x-1a85e758b105d493bb9d95916816bd206345bc5d.tar.gz
vyos-1x-1a85e758b105d493bb9d95916816bd206345bc5d.zip
vyos.util: add common helper to load kernel modules
l2tpv3, wireguard, wirelessmodem, nat all require additional Kernel modules to be present on the system. Each and every interface implemented their own way of loading a module - by copying code. Use a generic function, vyos.util.check_kmod() to load any arbitrary kernel module passed as string or list.
Diffstat (limited to 'src/conf_mode/interfaces-l2tpv3.py')
-rwxr-xr-xsrc/conf_mode/interfaces-l2tpv3.py12
1 files changed, 4 insertions, 8 deletions
diff --git a/src/conf_mode/interfaces-l2tpv3.py b/src/conf_mode/interfaces-l2tpv3.py
index 4ff0bcb57..866419f2c 100755
--- a/src/conf_mode/interfaces-l2tpv3.py
+++ b/src/conf_mode/interfaces-l2tpv3.py
@@ -24,11 +24,14 @@ from vyos.config import Config
from vyos.ifconfig import L2TPv3If, Interface
from vyos import ConfigError
from vyos.util import call
+from vyos.util import check_kmod
from vyos.validate import is_member, is_addr_assigned
from vyos import airbag
airbag.enable()
+k_mod = ['l2tp_eth', 'l2tp_netlink', 'l2tp_ip', 'l2tp_ip6']
+
default_config_data = {
'address': [],
'deleted': False,
@@ -53,13 +56,6 @@ 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 call(f'modprobe {module}') != 0:
- raise ConfigError(f'Loading Kernel module {module} failed')
-
def get_config():
l2tpv3 = deepcopy(default_config_data)
conf = Config()
@@ -283,7 +279,7 @@ def apply(l2tpv3):
if __name__ == '__main__':
try:
- check_kmod()
+ check_kmod(k_mod)
c = get_config()
verify(c)
generate(c)