summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-11-30 18:49:43 +0100
committerGitHub <noreply@github.com>2020-11-30 18:49:43 +0100
commit669969f3f48a680296bb996829f17a3a4676c914 (patch)
treed2d5151fff68e05e107ffb082d9f48e5fa75e641 /src
parent9dab6e725568e8bcc46c265a0da90c09a651d83c (diff)
parent144baef71a64d21ac32ebbcf523ba10bf020a332 (diff)
downloadvyos-1x-669969f3f48a680296bb996829f17a3a4676c914.tar.gz
vyos-1x-669969f3f48a680296bb996829f17a3a4676c914.zip
Merge pull request #624 from Cheeze-It/current
mpls-conf: T915: Add ethernet vif sub interface MPLS enable
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/protocols_mpls.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/conf_mode/protocols_mpls.py b/src/conf_mode/protocols_mpls.py
index 791b18110..3b27608da 100755
--- a/src/conf_mode/protocols_mpls.py
+++ b/src/conf_mode/protocols_mpls.py
@@ -18,11 +18,13 @@ import os
from sys import exit
+from glob import glob
from vyos.config import Config
from vyos.configdict import node_changed
from vyos.template import render_to_string
from vyos.util import call
from vyos.util import dict_search
+from vyos.util import read_file
from vyos import ConfigError
from vyos import frr
from vyos import airbag
@@ -118,22 +120,28 @@ def apply(mpls):
# Enable and disable MPLS processing on interfaces per configuration
if 'interface' in mpls:
system_interfaces = []
- system_interfaces.append(((os.popen('sysctl net.mpls.conf').read()).split('\n')))
- del system_interfaces[0][-1]
- for configured_interface in mpls['interface']:
- for system_interface in system_interfaces[0]:
- if configured_interface in system_interface:
- call(f'sysctl -wq net.mpls.conf.{configured_interface}.input=1')
- elif system_interface.endswith(' = 1'):
- system_interface = system_interface.replace(' = 1', '=0')
- call(f'sysctl -wq {system_interface}')
+ # Populate system interfaces list with local MPLS capable interfaces
+ for interface in glob('/proc/sys/net/mpls/conf/*'):
+ system_interfaces.append(os.path.basename(interface))
+ # This is where the comparison is done on if an interface needs to be enabled/disabled.
+ for system_interface in system_interfaces:
+ interface_state = read_file(f'/proc/sys/net/mpls/conf/{system_interface}/input')
+ if '1' in interface_state:
+ if system_interface not in mpls['interface']:
+ system_interface = system_interface.replace('.', '/')
+ call(f'sysctl -wq net.mpls.conf.{system_interface}.input=0')
+ elif '0' in interface_state:
+ if system_interface in mpls['interface']:
+ system_interface = system_interface.replace('.', '/')
+ call(f'sysctl -wq net.mpls.conf.{system_interface}.input=1')
else:
- # If MPLS interfaces are not configured, set MPLS processing disabled
system_interfaces = []
- system_interfaces.append(((os.popen('sysctl net.mpls.conf').read()).replace(" = 1", "=0")).split('\n'))
- del system_interfaces[0][-1]
- for interface in (system_interfaces[0]):
- call(f'sysctl -wq {interface}')
+ # If MPLS interfaces are not configured, set MPLS processing disabled
+ for interface in glob('/proc/sys/net/mpls/conf/*'):
+ system_interfaces.append(os.path.basename(interface))
+ for system_interface in system_interfaces:
+ system_interface = system_interface.replace('.', '/')
+ call(f'sysctl -wq net.mpls.conf.{system_interface}.input=0')
return None