From 97e75dae0c4e75fa35fed1fb3407a429f7bfe537 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 31 Dec 2017 12:16:23 +0100 Subject: Support setting optional 'type' node in command templates other than 'txt' --- schema/interface_definition.rng | 5 +++++ scripts/build-command-templates | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/schema/interface_definition.rng b/schema/interface_definition.rng index d1bd9a708..5a0a48845 100644 --- a/schema/interface_definition.rng +++ b/schema/interface_definition.rng @@ -168,6 +168,11 @@ + + + + + diff --git a/scripts/build-command-templates b/scripts/build-command-templates index ff0ce05f0..d1871c1c8 100755 --- a/scripts/build-command-templates +++ b/scripts/build-command-templates @@ -165,6 +165,12 @@ def get_properties(p): except: pass + # Get type + try: + props["type"] = p.find("type").text + except: + pass + # Get "multi" if p.find("multi") is not None: props["multi"] = True @@ -233,7 +239,8 @@ def process_node(n, tmpl_dir): props["owner"] = owner # Type should not be set for non-tag, non-leaf nodes if node_type != "node": - props["type"] = "txt" + if "type" not in props.keys(): + props["type"] = "txt" if node_type == "tagNode": props["tag"] = "True" -- cgit v1.2.3 From 4022a8820ccf0539f2eb5c19d9abd777810a48b4 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 30 Dec 2017 19:19:16 +0100 Subject: bcast-relay: Initial configuration nodes for 'service bcast-relay' --- interface-definitions/bcast-relay.xml | 64 ++++++++++++++++ src/conf-mode/vyos-config-bcast-relay.py | 124 +++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+) create mode 100644 interface-definitions/bcast-relay.xml create mode 100755 src/conf-mode/vyos-config-bcast-relay.py diff --git a/interface-definitions/bcast-relay.xml b/interface-definitions/bcast-relay.xml new file mode 100644 index 000000000..0e2f26425 --- /dev/null +++ b/interface-definitions/bcast-relay.xml @@ -0,0 +1,64 @@ + + + + + + + + + + UDP Broadcast Relay parameters + + + + + Unique ID for each UDP port to forward + + u32:1-99 + Numerical ID # + + u32 + 990 + + + + + Set source IP of forwarded packets, otherwise original senders address is used + + ipv4 + Optional source address for forwarded packets + + ipv4 + + + + + Description + + + + + Interface to repeat UDP broadcasts to [REQUIRED] + + + + + + + + + Destination or source port to listen and retransmit on [REQUIRED] + + u32:1-65535 + UDP port to listen on + + u32 + + + + + + + + + diff --git a/src/conf-mode/vyos-config-bcast-relay.py b/src/conf-mode/vyos-config-bcast-relay.py new file mode 100755 index 000000000..682cb220e --- /dev/null +++ b/src/conf-mode/vyos-config-bcast-relay.py @@ -0,0 +1,124 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2017 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 +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# + +import sys +import os +import fnmatch +import time +import subprocess + +from vyos.config import Config +from vyos.util import ConfigError + +config_file = r'/etc/default/udp-broadcast-relay' + +def get_config(): + conf = Config() + conf.set_level("service bcast-relay id") + relay_id = conf.list_nodes("") + relays = [] + + for id in relay_id: + interface_list = [] + address = conf.return_value("{0} address".format(id)) + description = conf.return_value("{0} description".format(id)) + port = conf.return_value("{0} port".format(id)) + + # split the interface name listing and form a list + if conf.exists("{0} interface".format(id)): + intfs_names = conf.return_values("{0} interface".format(id)) + intfs_names=intfs_names.replace("'", "") + intfs_names=intfs_names.split() + for name in intfs_names: + interface_list.append(name) + + relay = { + "id": id, + "address": address, + "description": description, + "interfaces" : interface_list, + "port": port + } + relays.append(relay) + + return relays + +def verify(relays): + for relay in relays: + if not relay["port"]: + raise ConfigError("UDP bcast relay 'id {0}' requires a port number".format(relay["id"])) + + if len(relay["interfaces"]) < 2: + raise ConfigError("UDP bcast relay 'id {0}' requires at least 2 interfaces".format(relay["id"])) + + return None + +def generate(relays): + config_header = '### Autogenerated by {0} on {tm} ###\n'.format(os.path.basename(__file__), + tm=time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime())) + + config_dir = os.path.dirname(config_file) + config_filename = os.path.basename(config_file) + active_configs = [] + + for config in fnmatch.filter(os.listdir(config_dir), config_filename + '*'): + # determine prefix length to identify service instance + prefix_len = len(config_filename) + active_configs.append(config[prefix_len:]) + + # sort our list + active_configs.sort() + + for id in active_configs[:]: + os.unlink(config_file + id) + + for relay in relays: + file = config_file + str(relay["id"]) + interfaces = ' '.join(str(intf) for intf in relay["interfaces"]) + config_args = 'DAEMON_ARGS="{0} {1} {2}"\n'.format(relay["id"], relay["port"], interfaces) + + f = open(file, 'w') + f.write(config_header) + if relay["description"]: + f.write('# ' + relay["description"] + '\n') + f.write(config_args) + f.close() + + return None + +def apply(relays): + # first stop all running services + cmd = "sudo systemctl stop udp-broadcast-relay@{1..99}" + os.system(cmd) + + # start only required service instances + for relay in relays: + cmd = "sudo systemctl start udp-broadcast-relay@{0}".format(relay["id"]) + os.system(cmd) + + return None + +if __name__ == '__main__': + try: + c = get_config() + verify(c) + generate(c) + apply(c) + except ConfigError as e: + print(e) + sys.exit(1) -- cgit v1.2.3