From fe8d884b564e1758216b6a2db025bf1b22e56fa7 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Fri, 20 Nov 2020 14:05:39 +0100 Subject: tunnel: T3072: support changing tunnel encapsulation on-the-fly --- src/conf_mode/interfaces-tunnel.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/conf_mode/interfaces-tunnel.py b/src/conf_mode/interfaces-tunnel.py index 78fc9667c..bf643f3d1 100755 --- a/src/conf_mode/interfaces-tunnel.py +++ b/src/conf_mode/interfaces-tunnel.py @@ -17,7 +17,7 @@ import os from sys import exit -from copy import deepcopy +from netifaces import interfaces from vyos.config import Config from vyos.configdict import dict_merge @@ -46,8 +46,8 @@ airbag.enable() def get_config(config=None): """ - Retrive CLI config as dictionary. Dictionary can never be empty, as at least the - interface name will be added or a deleted flag + Retrive CLI config as dictionary. Dictionary can never be empty, as at least + the interface name will be added or a deleted flag """ if config: conf = config @@ -62,6 +62,9 @@ def get_config(config=None): if 'mtu' not in tmp: tunnel['mtu'] = '1476' + tmp = leaf_node_changed(conf, ['encapsulation']) + if tmp: tunnel.update({'encapsulation_changed': {}}) + # We must check if our interface is configured to be a DMVPN member nhrp_base = ['protocols', 'nhrp', 'tunnel'] conf.set_level(nhrp_base) @@ -123,10 +126,12 @@ def generate(tunnel): return None def apply(tunnel): - if 'deleted' in tunnel: - tmp = Interface(tunnel['ifname']) - tmp.remove() - return None + if 'deleted' in tunnel or 'encapsulation_changed' in tunnel: + if tunnel['ifname'] in interfaces(): + tmp = Interface(tunnel['ifname']) + tmp.remove() + if 'deleted' in tunnel: + return None dispatch = { 'gre': GREIf, @@ -173,10 +178,10 @@ def apply(tunnel): if dict_search(our_key, tunnel) and their_key in conf: conf[their_key] = dict_search(our_key, tunnel) - # TODO: support encapsulation change per tunnel - tun = klass(tunnel['ifname'], **conf) + tun.change_options() tun.update(tunnel) + return None if __name__ == '__main__': -- cgit v1.2.3