summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2023-07-26 23:14:19 +0200
committerChristian Breunig <christian@breunig.cc>2023-07-26 23:14:19 +0200
commitfa07179ae7f1dc07e6ccc1b20d2b81384b6efe07 (patch)
tree3dcfa310f073d902133412bfb177ce88a5bdf1b7 /python
parent9e0a9b7df3d7187173feaf922fedbac8f0f0b674 (diff)
downloadvyos-1x-fa07179ae7f1dc07e6ccc1b20d2b81384b6efe07.tar.gz
vyos-1x-fa07179ae7f1dc07e6ccc1b20d2b81384b6efe07.zip
openvpn: T4974: dynamically load/unload kernel module
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/kernel.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/python/vyos/utils/kernel.py b/python/vyos/utils/kernel.py
index 0eb113174..1f3bbdffe 100644
--- a/python/vyos/utils/kernel.py
+++ b/python/vyos/utils/kernel.py
@@ -25,3 +25,14 @@ def check_kmod(k_mod):
if not os.path.exists(f'/sys/module/{module}'):
if call(f'modprobe {module}') != 0:
raise ConfigError(f'Loading Kernel module {module} failed')
+
+def unload_kmod(k_mod):
+ """ Common utility function to unload required kernel modules on demand """
+ from vyos import ConfigError
+ from vyos.utils.process import call
+ if isinstance(k_mod, str):
+ k_mod = k_mod.split()
+ for module in k_mod:
+ if os.path.exists(f'/sys/module/{module}'):
+ if call(f'rmmod {module}') != 0:
+ raise ConfigError(f'Unloading Kernel module {module} failed')