diff options
author | Christian Breunig <christian@breunig.cc> | 2023-06-30 21:49:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-30 21:49:53 +0200 |
commit | 64cc7d7e3b9e2f0f8e16cb95272336062700b91f (patch) | |
tree | 8f8e16c4fe6e2b443dda0de28eaf3b608a65891e /src | |
parent | 6efdecdaa20359b56d1ff856c9f6f1f736f77a7f (diff) | |
parent | 77bce8f54bad791ea7ab6e6100ee11c97ec3dfb4 (diff) | |
download | vyos-1x-64cc7d7e3b9e2f0f8e16cb95272336062700b91f.tar.gz vyos-1x-64cc7d7e3b9e2f0f8e16cb95272336062700b91f.zip |
Merge pull request #2057 from c-po/t5313-backport
bcast-relay: T5313: verify() relay interfaces have IPv4 address configured
Diffstat (limited to 'src')
-rwxr-xr-x | src/conf_mode/bcast_relay.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/conf_mode/bcast_relay.py b/src/conf_mode/bcast_relay.py index d93a2a8f4..1ace01758 100755 --- a/src/conf_mode/bcast_relay.py +++ b/src/conf_mode/bcast_relay.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (C) 2017-2020 VyOS maintainers and contributors +# Copyright (C) 2017-2023 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -17,12 +17,14 @@ import os from glob import glob -from netifaces import interfaces +from netifaces import AF_INET from sys import exit from vyos.config import Config -from vyos.util import call +from vyos.configverify import verify_interface_exists from vyos.template import render +from vyos.util import call +from vyos.validate import is_afi_configured from vyos import ConfigError from vyos import airbag airbag.enable() @@ -50,18 +52,16 @@ def verify(relay): # we certainly require a UDP port to listen to if 'port' not in config: - raise ConfigError(f'Port number mandatory for udp broadcast relay "{instance}"') + raise ConfigError(f'Port number is mandatory for UDP broadcast relay "{instance}"') - # if only oone interface is given it's a string -> move to list - if isinstance(config.get('interface', []), str): - config['interface'] = [ config['interface'] ] # Relaying data without two interface is kinda senseless ... if len(config.get('interface', [])) < 2: - raise ConfigError('At least two interfaces are required for udp broadcast relay "{instance}"') + raise ConfigError('At least two interfaces are required for UDP broadcast relay "{instance}"') for interface in config.get('interface', []): - if interface not in interfaces(): - raise ConfigError('Interface "{interface}" does not exist!') + verify_interface_exists(interface) + if not is_afi_configured(interface, AF_INET): + raise ConfigError(f'Interface "{interface}" has no IPv4 address configured!') return None |