summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/vyos/ifconfig.py14
-rwxr-xr-xsrc/conf_mode/interfaces-l2tpv3.py29
2 files changed, 30 insertions, 13 deletions
diff --git a/python/vyos/ifconfig.py b/python/vyos/ifconfig.py
index 1c5a7cd14..36bd8c57c 100644
--- a/python/vyos/ifconfig.py
+++ b/python/vyos/ifconfig.py
@@ -1714,8 +1714,10 @@ class L2TPv3If(Interface):
monitoring may be performed.
"""
def __init__(self, ifname, config=''):
+ self._config = {}
if config:
self._ifname = ifname
+ self._config = config
if not os.path.exists('/sys/class/net/{}'.format(self._ifname)):
# create tunnel interface
cmd = 'ip l2tp add tunnel tunnel_id {} '.format(config['tunnel_id'])
@@ -1729,7 +1731,7 @@ class L2TPv3If(Interface):
# setup session
cmd = 'ip l2tp add session name {} '.format(self._ifname)
- cmd += 'tunnel_id {} '.format(config['tunnel_id'])
+ cmd += 'tunnel_id {} '.format(config['tunnel_id'])
cmd += 'session_id {} '.format(config['session_id'])
cmd += 'peer_session_id {} '.format(config['peer_session_id'])
self._cmd(cmd)
@@ -1753,10 +1755,14 @@ class L2TPv3If(Interface):
# interface is always A/D down. It needs to be enabled explicitly
self.set_state('down')
- #cmd = 'ip l2tp add tunnel tunnel_id {} '.format(config['tunnel_id'])
+ if self._config['tunnel_id'] and self._config['session_id']:
+ cmd = 'ip l2tp del session tunnel_id {} '.format(self._config['tunnel_id'])
+ cmd += 'session_id {} '.format(self._config['session_id'])
+ self._cmd(cmd)
- # call remove of parent class
- super().remove()
+ if self._config['tunnel_id']:
+ cmd = 'ip l2tp del tunnel tunnel_id {} '.format(self._config['tunnel_id'])
+ self._cmd(cmd)
@staticmethod
def get_config():
diff --git a/src/conf_mode/interfaces-l2tpv3.py b/src/conf_mode/interfaces-l2tpv3.py
index 62d802b39..ae49dadad 100755
--- a/src/conf_mode/interfaces-l2tpv3.py
+++ b/src/conf_mode/interfaces-l2tpv3.py
@@ -55,6 +55,16 @@ def get_config():
# Check if interface has been removed
if not conf.exists('interfaces l2tpv3 ' + l2tpv3['intf']):
l2tpv3['deleted'] = True
+ # to delete the l2tpv3 interface we need to current
+ # tunnel_id and session_id
+ if conf.exists_effective('interfaces l2tpv3 {} tunnel-id'.format(l2tpv3['intf'])):
+ l2tpv3['tunnel_id'] = conf.return_effective_value(
+ 'interfaces l2tpv3 {} tunnel-id'.format(l2tpv3['intf']))
+
+ if conf.exists_effective('interfaces l2tpv3 {} session-id'.format(l2tpv3['intf'])):
+ l2tpv3['session_id'] = conf.return_effective_value(
+ 'interfaces l2tpv3 {} session-id'.format(l2tpv3['intf']))
+
return l2tpv3
# set new configuration level
@@ -172,20 +182,21 @@ def generate(l2tpv3):
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
+ # vyos.ifconfig
+ conf = deepcopy(L2TPv3If.get_config())
+
# Check if L2TPv3 interface already exists
if l2tpv3['intf'] in interfaces():
- l = L2TPv3If(l2tpv3['intf'])
- # L2TPv3 is super picky and the tunnel always needs to be recreated,
- # thus we can simply always delete it first.
+ # L2TPv3 is picky when changing tunnels/sessions, thus we can simply
+ # always delete it first.
+ conf['session_id'] = l2tpv3['session_id']
+ conf['tunnel_id'] = l2tpv3['tunnel_id']
+ l = L2TPv3If(l2tpv3['intf'], config=conf)
l.remove()
-
if not l2tpv3['deleted']:
- # L2TPv3 interface needs to be created on-block
- # instead of passing a ton of arguments, I just use a dict
- # that is managed by vyos.ifconfig
- conf = deepcopy(L2TPv3If.get_config())
-
conf['peer_tunnel_id'] = l2tpv3['peer_tunnel_id']
conf['local_port'] = l2tpv3['local_port']
conf['remote_port'] = l2tpv3['remote_port']