summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--interface-definitions/include/ipv4-address-prefix-range.xml.i39
-rw-r--r--interface-definitions/include/port-port-range.xml.i26
-rw-r--r--interface-definitions/load-balancing-wan.xml.in395
-rwxr-xr-xsrc/conf_mode/load-balancing-wan.py65
5 files changed, 528 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 5e01108c0..56d446a27 100644
--- a/Makefile
+++ b/Makefile
@@ -42,6 +42,9 @@ interface_definitions: $(config_xml_obj)
# T2773 - EIGRP support for VRF
rm -rf $(TMPL_DIR)/vrf/name/node.tag/protocols/eigrp
+ # T4518, T4470 Load-balancing wan
+ rm -rf $(TMPL_DIR)/load-balancing
+
# XXX: test if there are empty node.def files - this is not allowed as these
# could mask help strings or mandatory priority statements
find $(TMPL_DIR) -name node.def -type f -empty -exec false {} + || sh -c 'echo "There are empty node.def files! Check your interface definitions." && exit 1'
diff --git a/interface-definitions/include/ipv4-address-prefix-range.xml.i b/interface-definitions/include/ipv4-address-prefix-range.xml.i
new file mode 100644
index 000000000..aadc6aaec
--- /dev/null
+++ b/interface-definitions/include/ipv4-address-prefix-range.xml.i
@@ -0,0 +1,39 @@
+<!-- include start from ipv4-address-prefix-range.xml.i -->
+<leafNode name="address">
+ <properties>
+ <help>IP address, subnet, or range</help>
+ <valueHelp>
+ <format>ipv4</format>
+ <description>IPv4 address to match</description>
+ </valueHelp>
+ <valueHelp>
+ <format>ipv4net</format>
+ <description>IPv4 prefix to match</description>
+ </valueHelp>
+ <valueHelp>
+ <format>ipv4range</format>
+ <description>IPv4 address range to match</description>
+ </valueHelp>
+ <valueHelp>
+ <format>!ipv4</format>
+ <description>Match everything except the specified address</description>
+ </valueHelp>
+ <valueHelp>
+ <format>!ipv4net</format>
+ <description>Match everything except the specified prefix</description>
+ </valueHelp>
+ <valueHelp>
+ <format>!ipv4range</format>
+ <description>Match everything except the specified range</description>
+ </valueHelp>
+ <constraint>
+ <validator name="ipv4-address"/>
+ <validator name="ipv4-prefix"/>
+ <validator name="ipv4-range"/>
+ <validator name="ipv4-address-exclude"/>
+ <validator name="ipv4-prefix-exclude"/>
+ <validator name="ipv4-range-exclude"/>
+ </constraint>
+ </properties>
+</leafNode>
+<!-- include end -->
diff --git a/interface-definitions/include/port-port-range.xml.i b/interface-definitions/include/port-port-range.xml.i
new file mode 100644
index 000000000..ce550f549
--- /dev/null
+++ b/interface-definitions/include/port-port-range.xml.i
@@ -0,0 +1,26 @@
+<!-- include start from port-port-range.xml.i -->
+<leafNode name="port">
+ <properties>
+ <help>Port number</help>
+ <valueHelp>
+ <format>txt</format>
+ <description>Named port (any name in /etc/services, e.g., http)</description>
+ </valueHelp>
+ <valueHelp>
+ <format>u32:1-65535</format>
+ <description>Numeric IP port</description>
+ </valueHelp>
+ <valueHelp>
+ <format>start-end</format>
+ <description>Numbered port range (e.g. 1001-1005)</description>
+ </valueHelp>
+ <valueHelp>
+ <format/>
+ <description>\n\nMultiple destination ports can be specified as a comma-separated list.\nThe whole list can also be negated using '!'.\nFor example: '!22,telnet,http,123,1001-1005'</description>
+ </valueHelp>
+ <constraint>
+ <validator name="port-multi"/>
+ </constraint>
+ </properties>
+</leafNode>
+<!-- include end -->
diff --git a/interface-definitions/load-balancing-wan.xml.in b/interface-definitions/load-balancing-wan.xml.in
new file mode 100644
index 000000000..c2b6316ae
--- /dev/null
+++ b/interface-definitions/load-balancing-wan.xml.in
@@ -0,0 +1,395 @@
+<?xml version="1.0"?>
+<interfaceDefinition>
+ <node name="load-balancing">
+ <properties>
+ <help>Configure load-balancing</help>
+ </properties>
+ <children>
+ <node name="wan" owner="${vyos_conf_scripts_dir}/load-balancing-wan.py">
+ <properties>
+ <help>Configure Wide Area Network (WAN) load-balancing</help>
+ </properties>
+ <children>
+ <leafNode name="disable-source-nat">
+ <properties>
+ <help>Disable source NAT rules from being configured for WAN load balancing</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ <leafNode name="enable-local-traffic">
+ <properties>
+ <help>Enable WAN load balancing for locally sourced traffic</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ <leafNode name="flush-connections">
+ <properties>
+ <help>Flush connection tracking tables on connection state change</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ <leafNode name="hook">
+ <properties>
+ <help>Script to be executed on interface status change</help>
+ <valueHelp>
+ <format>txt</format>
+ <description>Script in /config/scripts</description>
+ </valueHelp>
+ <constraint>
+ <validator name="script"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <tagNode name="interface-health">
+ <properties>
+ <help>Interface name</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_interfaces.py</script>
+ </completionHelp>
+ </properties>
+ <children>
+ <leafNode name="failure-count">
+ <properties>
+ <help>Failure count</help>
+ <valueHelp>
+ <format>u32:1-10</format>
+ <description>Failure count</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-10"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="nexthop">
+ <properties>
+ <help>Outbound interface nexthop address. Can be 'DHCP or IPv4 address' [REQUIRED]</help>
+ <completionHelp>
+ <list>dhcp</list>
+ </completionHelp>
+ <valueHelp>
+ <format>ipv4</format>
+ <description>Nexthop IP address</description>
+ </valueHelp>
+ <valueHelp>
+ <format>dhcp</format>
+ <description>Set the nexthop via DHCP</description>
+ </valueHelp>
+ <constraint>
+ <validator name="ipv4-address"/>
+ <regex>(dhcp)</regex>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="success-count">
+ <properties>
+ <help>Success count</help>
+ <valueHelp>
+ <format>u32:1-10</format>
+ <description>Success count</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-10"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <tagNode name="test">
+ <properties>
+ <help>Rule number</help>
+ <valueHelp>
+ <format>u32:0-4294967295</format>
+ <description>Rule number</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 0-4294967295"/>
+ </constraint>
+ </properties>
+ <children>
+ <leafNode name="resp-time">
+ <properties>
+ <help>Ping response time (seconds)</help>
+ <valueHelp>
+ <format>u32:1-30</format>
+ <description>Response time (seconds)</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-30"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="target">
+ <properties>
+ <help>Health target address</help>
+ <valueHelp>
+ <format>ipv4</format>
+ <description>Health target address</description>
+ </valueHelp>
+ <constraint>
+ <validator name="ipv4-address"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="test-script">
+ <properties>
+ <help>Path to user-defined script</help>
+ <valueHelp>
+ <format>txt</format>
+ <description>Script in /config/scripts</description>
+ </valueHelp>
+ <constraint>
+ <validator name="script"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="ttl-limit">
+ <properties>
+ <help>TTL limit (hop count)</help>
+ <valueHelp>
+ <format>u32:1-254</format>
+ <description>Number of hops</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-254"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="type">
+ <properties>
+ <help>WLB test type</help>
+ <completionHelp>
+ <list>ping ttl user-defined</list>
+ </completionHelp>
+ <valueHelp>
+ <format>ping</format>
+ <description>Test with ICMP echo response</description>
+ </valueHelp>
+ <valueHelp>
+ <format>ttl</format>
+ <description>Test with UDP TTL expired response</description>
+ </valueHelp>
+ <valueHelp>
+ <format>user-defined</format>
+ <description>User-defined test script</description>
+ </valueHelp>
+ <constraint>
+ <regex>(ping|ttl|user-defined)</regex>
+ </constraint>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ </children>
+ </tagNode>
+ <tagNode name="rule">
+ <properties>
+ <help>Rule number (1-9999)</help>
+ <valueHelp>
+ <format>u32:1-9999</format>
+ <description>Rule number</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-9999"/>
+ </constraint>
+ </properties>
+ <children>
+ <leafNode name="description">
+ <properties>
+ <help>Description for this rule</help>
+ <valueHelp>
+ <format>txt</format>
+ <description>Description for this rule</description>
+ </valueHelp>
+ </properties>
+ </leafNode>
+ <node name="destination">
+ <properties>
+ <help>Destination</help>
+ </properties>
+ <children>
+ #include <include/ipv4-address-prefix-range.xml.i>
+ #include <include/port-port-range.xml.i>
+ </children>
+ </node>
+ <leafNode name="exclude">
+ <properties>
+ <help>Exclude packets matching this rule from WAN load balance</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ <leafNode name="failover">
+ <properties>
+ <help>Enable failover for packets matching this rule from WAN load balance</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ <leafNode name="inbound-interface">
+ <properties>
+ <help>Inbound interface name (e.g., "eth0") [REQUIRED]</help>
+ <completionHelp>
+ <list>any</list>
+ <script>${vyos_completion_dir}/list_interfaces.py</script>
+ </completionHelp>
+ </properties>
+ </leafNode>
+ <tagNode name="interface">
+ <properties>
+ <help>Interface name [REQUIRED]</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_interfaces.py</script>
+ </completionHelp>
+ </properties>
+ <children>
+ <leafNode name="weight">
+ <properties>
+ <help>Load-balance weight</help>
+ <valueHelp>
+ <format>u32:1-255</format>
+ <description>Interface weight</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 1-255"/>
+ </constraint>
+ <constraintErrorMessage>Weight must be between 1 and 255</constraintErrorMessage>
+ </properties>
+ </leafNode>
+ </children>
+ </tagNode>
+ <node name="limit">
+ <properties>
+ <help>Enable packet limit for this rule</help>
+ </properties>
+ <children>
+ <leafNode name="burst">
+ <properties>
+ <help>Burst limit for matching packets</help>
+ <valueHelp>
+ <format>u32:0-4294967295</format>
+ <description>Burst limit for matching packets</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 0-4294967295"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="period">
+ <properties>
+ <help>Time window for rate calculation</help>
+ <completionHelp>
+ <list>hour minute second</list>
+ </completionHelp>
+ <valueHelp>
+ <format>hour</format>
+ <description>hour</description>
+ </valueHelp>
+ <valueHelp>
+ <format>minute</format>
+ <description>minute</description>
+ </valueHelp>
+ <valueHelp>
+ <format>second</format>
+ <description>second</description>
+ </valueHelp>
+ <constraint>
+ <regex>(hour|minute|second)</regex>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="rate">
+ <properties>
+ <help>Number of packets used for rate limit</help>
+ <valueHelp>
+ <format>u32:0-4294967295</format>
+ <description>Number of packets used for rate limit</description>
+ </valueHelp>
+ <constraint>
+ <validator name="numeric" argument="--range 0-4294967295"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <leafNode name="threshold">
+ <properties>
+ <help>Threshold behavior for limit</help>
+ <completionHelp>
+ <list>above below</list>
+ </completionHelp>
+ <valueHelp>
+ <format>above</format>
+ <description>Above limit</description>
+ </valueHelp>
+ <valueHelp>
+ <format>below</format>
+ <description>Below limit</description>
+ </valueHelp>
+ <constraint>
+ <regex>(above|below)</regex>
+ </constraint>
+ </properties>
+ </leafNode>
+ </children>
+ </node>
+ <leafNode name="per-packet-balancing">
+ <properties>
+ <help>Option to match traffic per-packet instead of the default, per-flow</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ <leafNode name="protocol">
+ <properties>
+ <help>Protocol to match (protocol name, number, or "all")</help>
+ <completionHelp>
+ <script>${vyos_completion_dir}/list_protocols.sh</script>
+ <list>all tcp_udp</list>
+ </completionHelp>
+ <valueHelp>
+ <format>all</format>
+ <description>All IP protocols</description>
+ </valueHelp>
+ <valueHelp>
+ <format>tcp_udp</format>
+ <description>Both TCP and UDP</description>
+ </valueHelp>
+ <valueHelp>
+ <format>u32:0-255</format>
+ <description>IP protocol number</description>
+ </valueHelp>
+ <valueHelp>
+ <format>&lt;protocol&gt;</format>
+ <description>IP protocol name</description>
+ </valueHelp>
+ <valueHelp>
+ <format>!&lt;protocol&gt;</format>
+ <description>IP protocol name</description>
+ </valueHelp>
+ <constraint>
+ <validator name="ip-protocol"/>
+ </constraint>
+ </properties>
+ </leafNode>
+ <node name="source">
+ <properties>
+ <help>Source information</help>
+ </properties>
+ <children>
+ #include <include/ipv4-address-prefix-range.xml.i>
+ #include <include/port-port-range.xml.i>
+ </children>
+ </node>
+ </children>
+ </tagNode>
+ <node name="sticky-connections">
+ <properties>
+ <help>Configure sticky connections</help>
+ </properties>
+ <children>
+ <leafNode name="inbound">
+ <properties>
+ <help>Enable sticky incoming WAN connections</help>
+ <valueless/>
+ </properties>
+ </leafNode>
+ </children>
+ </node>
+ </children>
+ </node>
+ </children>
+ </node>
+</interfaceDefinition>
diff --git a/src/conf_mode/load-balancing-wan.py b/src/conf_mode/load-balancing-wan.py
new file mode 100755
index 000000000..11840249f
--- /dev/null
+++ b/src/conf_mode/load-balancing-wan.py
@@ -0,0 +1,65 @@
+#!/usr/bin/env python3
+#
+# Copyright (C) 2022 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 <http://www.gnu.org/licenses/>.
+
+
+from sys import exit
+
+from vyos.config import Config
+from vyos.configdict import node_changed
+from vyos.util import call
+from vyos import ConfigError
+from pprint import pprint
+from vyos import airbag
+airbag.enable()
+
+
+def get_config(config=None):
+ if config:
+ conf = config
+ else:
+ conf = Config()
+
+ base = ['load-balancing', 'wan']
+ lb = conf.get_config_dict(base, get_first_key=True,
+ no_tag_node_value_mangle=True)
+
+ pprint(lb)
+ return lb
+
+def verify(lb):
+ return None
+
+
+def generate(lb):
+ if not lb:
+ return None
+
+ return None
+
+
+def apply(lb):
+
+ return None
+
+if __name__ == '__main__':
+ try:
+ c = get_config()
+ verify(c)
+ generate(c)
+ apply(c)
+ except ConfigError as e:
+ print(e)
+ exit(1)