diff options
-rw-r--r-- | python/vyos/util.py | 9 | ||||
-rwxr-xr-x | src/conf_mode/igmp_proxy.py | 11 | ||||
-rwxr-xr-x | src/conf_mode/protocols_igmp.py | 34 | ||||
-rwxr-xr-x | src/conf_mode/protocols_pim.py | 34 |
4 files changed, 76 insertions, 12 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py index d2e58bef2..cc7ce5b40 100644 --- a/python/vyos/util.py +++ b/python/vyos/util.py @@ -191,3 +191,12 @@ def ask_yes_no(question, default=False) -> bool: return False else: sys.stdout.write("Please respond with yes/y or no/n\n") + +def process_named_running(name): + """ Checks if process with given name is running and returns its PID. + If Process is not running, return None + """ + for p in psutil.process_iter(): + if name in p.name(): + return p.pid + return None diff --git a/src/conf_mode/igmp_proxy.py b/src/conf_mode/igmp_proxy.py index cd0704124..0e1c2c569 100755 --- a/src/conf_mode/igmp_proxy.py +++ b/src/conf_mode/igmp_proxy.py @@ -76,6 +76,13 @@ default_config_data = { def get_config(): igmp_proxy = default_config_data conf = Config() + + if conf.exists('protocols igmp'): + igmp_proxy['igmp_configured'] = True + + if conf.exists('protocols pim'): + igmp_proxy['pim_configured'] = True + if not conf.exists('protocols igmp-proxy'): return None else: @@ -125,6 +132,10 @@ def verify(igmp_proxy): if igmp_proxy['disable']: return None + if 'igmp_configured' in igmp_proxy or 'pim_configured' in igmp_proxy: + raise ConfigError('Can not configure both IGMP proxy and PIM '\ + 'at the same time') + # at least two interfaces are required, one upstream and one downstream if len(igmp_proxy['interfaces']) < 2: raise ConfigError('Must define an upstream and at least 1 downstream interface!') diff --git a/src/conf_mode/protocols_igmp.py b/src/conf_mode/protocols_igmp.py index 983ca4c3a..45ab78419 100755 --- a/src/conf_mode/protocols_igmp.py +++ b/src/conf_mode/protocols_igmp.py @@ -23,6 +23,11 @@ from sys import exit from vyos import ConfigError from vyos.config import Config +from vyos.util import process_named_running +from signal import SIGTERM + +# Required to use the full path to pimd, in another case daemon will not be started +pimd_cmd = 'sudo /usr/lib/frr/pimd -d -F traditional --daemon -A 127.0.0.1' config_file = r'/tmp/igmp.frr' @@ -73,15 +78,22 @@ ip igmp join {{ group }} def get_config(): conf = Config() igmp_conf = { - 'igmp_conf' : False, + 'igmp_configured' : False, + 'pim_configured' : False, 'old_ifaces' : {}, 'ifaces' : {} } if not (conf.exists('protocols igmp') or conf.exists_effective('protocols igmp')): return None + if conf.exists('protocols igmp-proxy'): + igmp_conf['igmp_proxy_configured'] = True + + if conf.exists('protocols pim'): + igmp_conf['pim_configured'] = True + if conf.exists('protocols igmp'): - igmp_conf['igmp_conf'] = True + igmp_conf['igmp_configured'] = True conf.set_level('protocols igmp') @@ -116,7 +128,10 @@ def verify(igmp): if igmp is None: return None - if igmp['igmp_conf']: + if 'igmp_proxy_configured' in igmp: + raise ConfigError('Can not configure both IGMP proxy and PIM at the same time') + + if igmp['igmp_configured']: # Check interfaces if not igmp['ifaces']: raise ConfigError("IGMP require defined interfaces!") @@ -141,9 +156,16 @@ def apply(igmp): if igmp is None: return None - if os.path.exists(config_file): - os.system("sudo vtysh -d pimd -f " + config_file) - os.remove(config_file) + pim_pid = process_named_running('pimd') + if igmp['igmp_configured'] or igmp['pim_configured']: + if not pim_pid: + os.system(pimd_cmd) + + if os.path.exists(config_file): + os.system('vtysh -d pimd -f ' + config_file) + os.remove(config_file) + elif pim_pid: + os.kill(int(pim_pid), SIGTERM) return None diff --git a/src/conf_mode/protocols_pim.py b/src/conf_mode/protocols_pim.py index ee5cc035f..1428c449b 100755 --- a/src/conf_mode/protocols_pim.py +++ b/src/conf_mode/protocols_pim.py @@ -23,6 +23,11 @@ from sys import exit from vyos import ConfigError from vyos.config import Config +from vyos.util import process_named_running +from signal import SIGTERM + +# Required to use the full path to pimd, in another case daemon will not be started +pimd_cmd = 'sudo /usr/lib/frr/pimd -d -F traditional --daemon -A 127.0.0.1' config_file = r'/tmp/pimd.frr' @@ -66,7 +71,8 @@ ip pim rp keep-alive-timer {{ pim.rp_keep_alive }} def get_config(): conf = Config() pim_conf = { - 'pim_conf' : False, + 'pim_configured' : False, + 'igmp_configured' : False, 'old_pim' : { 'ifaces' : {}, 'rp' : {} @@ -80,7 +86,13 @@ def get_config(): return None if conf.exists('protocols pim'): - pim_conf['pim_conf'] = True + pim_conf['pim_configured'] = True + + if conf.exists('protocols igmp-proxy'): + pim_conf['igmp_proxy_configured'] = True + + if conf.exists('protocols igmp'): + pim_conf['igmp_configured'] = True conf.set_level('protocols pim') @@ -122,7 +134,10 @@ def verify(pim): if pim is None: return None - if pim['pim_conf']: + if 'igmp_proxy_configured' in pim: + raise ConfigError('Can not configure both IGMP proxy and PIM at the same time') + + if pim['pim_configured']: # Check interfaces if not pim['pim']['ifaces']: raise ConfigError("PIM require defined interfaces!") @@ -161,9 +176,16 @@ def apply(pim): if pim is None: return None - if os.path.exists(config_file): - os.system("sudo vtysh -d pimd -f " + config_file) - os.remove(config_file) + pim_pid = process_named_running('pimd') + if pim['igmp_configured'] or pim['pim_configured']: + if not pim_pid: + os.system(pimd_cmd) + + if os.path.exists(config_file): + os.system('vtysh -d pimd -f ' + config_file) + os.remove(config_file) + elif pim_pid: + os.kill(int(pim_pid), SIGTERM) return None |