Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T5654: policy: move local-route[6] to ip-rule[6] #3781

Draft
wants to merge 1 commit into
base: current
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<!-- include start from include/version/policy-version.xml.i -->
<syntaxVersion component='policy' version='8'></syntaxVersion>
<syntaxVersion component='policy' version='9'></syntaxVersion>
<!-- include end -->
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0"?>
<!-- Policy local-route -->
<!-- Policy ip-rule -->
<interfaceDefinition>
<node name="policy">
<children>
<node name="local-route" owner="${vyos_conf_scripts_dir}/policy_local-route.py">
<node name="ip-rule" owner="${vyos_conf_scripts_dir}/policy_ip-rule.py">
<properties>
<help>IPv4 policy route of local traffic</help>
<priority>500</priority>
</properties>
<children>
<tagNode name="rule">
<properties>
<help>Policy local-route rule set number</help>
<help>Policy ip-rule rule set number</help>
<valueHelp>
<!-- table main with prio 32766 -->
<format>u32:1-32765</format>
Expand Down Expand Up @@ -53,13 +53,13 @@
</constraint>
</properties>
</leafNode>
#include <include/policy/local-route_rule_protocol.xml.i>
#include <include/policy/ip-rule_rule_protocol.xml.i>
<node name="source">
<properties>
<help>Source parameters</help>
</properties>
<children>
#include <include/policy/local-route_rule_ipv4_address.xml.i>
#include <include/policy/ip-rule_rule_ipv4_address.xml.i>
#include <include/port-number.xml.i>
</children>
</node>
Expand All @@ -68,7 +68,7 @@
<help>Destination parameters</help>
</properties>
<children>
#include <include/policy/local-route_rule_ipv4_address.xml.i>
#include <include/policy/ip-rule_rule_ipv4_address.xml.i>
#include <include/port-number.xml.i>
</children>
</node>
Expand All @@ -77,15 +77,15 @@
</tagNode>
</children>
</node>
<node name="local-route6" owner="${vyos_conf_scripts_dir}/policy_local-route.py">
<node name="ip-rule6" owner="${vyos_conf_scripts_dir}/policy_ip-rule.py">
<properties>
<help>IPv6 policy route of local traffic</help>
<priority>500</priority>
</properties>
<children>
<tagNode name="rule">
<properties>
<help>IPv6 policy local-route rule set number</help>
<help>IPv6 policy ip-rule rule set number</help>
<valueHelp>
<!-- table main with prio 32766 -->
<format>u32:1-32765</format>
Expand Down Expand Up @@ -127,13 +127,13 @@
</constraint>
</properties>
</leafNode>
#include <include/policy/local-route_rule_protocol.xml.i>
#include <include/policy/ip-rule_rule_protocol.xml.i>
<node name="source">
<properties>
<help>Source parameters</help>
</properties>
<children>
#include <include/policy/local-route_rule_ipv6_address.xml.i>
#include <include/policy/ip-rule_rule_ipv6_address.xml.i>
#include <include/port-number.xml.i>
</children>
</node>
Expand All @@ -142,7 +142,7 @@
<help>Destination parameters</help>
</properties>
<children>
#include <include/policy/local-route_rule_ipv6_address.xml.i>
#include <include/policy/ip-rule_rule_ipv6_address.xml.i>
#include <include/port-number.xml.i>
</children>
</node>
Expand Down
34 changes: 17 additions & 17 deletions smoketest/scripts/cli/test_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ def test_route_map(self):

# Test set table for some sources
def test_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

sources = ['203.0.113.1', '203.0.113.2']
rule = '50'
Expand All @@ -1509,7 +1509,7 @@ def test_table_id(self):

# Test set table for fwmark
def test_fwmark_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

fwmk = '24'
rule = '101'
Expand All @@ -1529,7 +1529,7 @@ def test_fwmark_table_id(self):

# Test set table for destination
def test_destination_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

dst = '203.0.113.1'
rule = '102'
Expand All @@ -1549,7 +1549,7 @@ def test_destination_table_id(self):

# Test set table for destination and protocol
def test_protocol_destination_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

dst = '203.0.113.12'
rule = '85'
Expand All @@ -1571,7 +1571,7 @@ def test_protocol_destination_table_id(self):

# Test set table for destination, source, protocol, fwmark and port
def test_protocol_port_address_fwmark_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

dst = '203.0.113.5'
src_list = ['203.0.113.1', '203.0.113.2']
Expand Down Expand Up @@ -1621,7 +1621,7 @@ def test_protocol_port_address_fwmark_table_id(self):

# Test set table for sources with fwmark
def test_fwmark_sources_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

sources = ['203.0.113.11', '203.0.113.12']
fwmk = '23'
Expand All @@ -1644,7 +1644,7 @@ def test_fwmark_sources_table_id(self):

# Test set table for sources with iif
def test_iif_sources_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

sources = ['203.0.113.11', '203.0.113.12']
iif = 'lo'
Expand All @@ -1670,7 +1670,7 @@ def test_iif_sources_table_id(self):

# Test set table for sources and destinations with fwmark
def test_fwmark_sources_destination_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

sources = ['203.0.113.11', '203.0.113.12']
destinations = ['203.0.113.13', '203.0.113.15']
Expand Down Expand Up @@ -1698,7 +1698,7 @@ def test_fwmark_sources_destination_table_id(self):

# Test set table ipv6 for some sources ipv6
def test_ipv6_table_id(self):
path = base_path + ['local-route6']
path = base_path + ['ip-rule6']

sources = ['2001:db8:123::/48', '2001:db8:126::/48']
rule = '50'
Expand All @@ -1719,7 +1719,7 @@ def test_ipv6_table_id(self):

# Test set table for fwmark ipv6
def test_fwmark_ipv6_table_id(self):
path = base_path + ['local-route6']
path = base_path + ['ip-rule6']

fwmk = '24'
rule = '100'
Expand All @@ -1739,7 +1739,7 @@ def test_fwmark_ipv6_table_id(self):

# Test set table for destination ipv6
def test_destination_ipv6_table_id(self):
path = base_path + ['local-route6']
path = base_path + ['ip-rule6']

dst = '2001:db8:1337::/126'
rule = '101'
Expand All @@ -1759,7 +1759,7 @@ def test_destination_ipv6_table_id(self):

# Test set table for sources with fwmark ipv6
def test_fwmark_sources_ipv6_table_id(self):
path = base_path + ['local-route6']
path = base_path + ['ip-rule6']

sources = ['2001:db8:1338::/126', '2001:db8:1339::/126']
fwmk = '23'
Expand All @@ -1782,7 +1782,7 @@ def test_fwmark_sources_ipv6_table_id(self):

# Test set table for sources with iif ipv6
def test_iif_sources_ipv6_table_id(self):
path = base_path + ['local-route6']
path = base_path + ['ip-rule6']

sources = ['2001:db8:1338::/126', '2001:db8:1339::/126']
iif = 'lo'
Expand All @@ -1807,7 +1807,7 @@ def test_iif_sources_ipv6_table_id(self):

# Test set table for sources and destinations with fwmark ipv6
def test_fwmark_sources_destination_ipv6_table_id(self):
path = base_path + ['local-route6']
path = base_path + ['ip-rule6']

sources = ['2001:db8:1338::/126', '2001:db8:1339::/56']
destinations = ['2001:db8:13::/48', '2001:db8:16::/48']
Expand Down Expand Up @@ -1835,8 +1835,8 @@ def test_fwmark_sources_destination_ipv6_table_id(self):

# Test delete table for sources and destination with fwmark ipv4/ipv6
def test_delete_ipv4_ipv6_table_id(self):
path = base_path + ['local-route']
path_v6 = base_path + ['local-route6']
path = base_path + ['ip-rule']
path_v6 = base_path + ['ip-rule6']

sources = ['203.0.113.0/24', '203.0.114.5']
destinations = ['203.0.112.0/24', '203.0.116.5']
Expand Down Expand Up @@ -1891,7 +1891,7 @@ def test_delete_ipv4_ipv6_table_id(self):

# Test multiple commits ipv4
def test_multiple_commit_ipv4_table_id(self):
path = base_path + ['local-route']
path = base_path + ['ip-rule']

sources = ['192.0.2.1', '192.0.2.2']
destination = '203.0.113.25'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def get_config(config=None):

pbr = conf.get_config_dict(base, key_mangling=('-', '_'), get_first_key=True)

for route in ['local_route', 'local_route6']:
dict_id = 'rule_remove' if route == 'local_route' else 'rule6_remove'
route_key = 'local-route' if route == 'local_route' else 'local-route6'
for route in ['ip_rule', 'ip_rule6']:
dict_id = 'rule_remove' if route == 'ip_rule' else 'rule6_remove'
route_key = 'ip-rule' if route == 'ip_rule' else 'ip-rule6'
base_rule = base + [route_key, 'rule']

# delete policy local-route
# delete policy ip-rule
dict = {}
tmp = node_changed(conf, base_rule, key_mangling=('-', '_'))
if tmp:
Expand Down Expand Up @@ -78,9 +78,9 @@ def get_config(config=None):
if not route in pbr:
continue

# delete policy local-route rule x source x.x.x.x
# delete policy local-route rule x fwmark x
# delete policy local-route rule x destination x.x.x.x
# delete policy ip-rule rule x source x.x.x.x
# delete policy ip-rule rule x fwmark x
# delete policy ip-rule rule x destination x.x.x.x
if 'rule' in pbr[route]:
for rule, rule_config in pbr[route]['rule'].items():
src = leaf_node_changed(conf, base_rule + [rule, 'source', 'address'])
Expand Down Expand Up @@ -202,7 +202,7 @@ def verify(pbr):
if not pbr:
return None

for route in ['local_route', 'local_route6']:
for route in ['ip_rule', 'ip_rule6']:
if not route in pbr:
continue

Expand Down Expand Up @@ -267,11 +267,11 @@ def apply(pbr):
call(f'ip{v6} rule del prio {rule} {f_src}{f_dst}{f_proto}{f_src_port}{f_dst_port}{f_fwmk}{f_iif}{f_table}')

# Generate new config
for route in ['local_route', 'local_route6']:
for route in ['ip_rule', 'ip_rule6']:
if not route in pbr:
continue

v6 = " -6" if route == 'local_route6' else ""
v6 = " -6" if route == 'ip_rule6' else ""
pbr_route = pbr[route]

if 'rule' in pbr_route:
Expand Down
38 changes: 38 additions & 0 deletions src/migration-scripts/policy/8-to-9
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2022-2024 VyOS maintainers and contributors <[email protected]>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this library. If not, see <http://www.gnu.org/licenses/>.

# T5654: Migrate <policy local-route> to <policy ip-rule>
# T5654: Migrate <policy local-route6> to <policy ip-rule6>

from vyos.configtree import ConfigTree

base = ['policy']

def migrate(config: ConfigTree) -> None:
if not config.exists(base):
# Nothing to do
return

if config.exists(base + ['local-route']):
config.set(base + ['ip-rule'])
for rule in config.list_nodes(base + ['local-route']):
config.copy(base + ['local-route', rule], base + ['ip-rule', rule])
config.delete(base + ['local-route'])

if config.exists(base + ['local-route6']):
config.set(base + ['ip-rule6'])
for rule in config.list_nodes(base + ['local-route6']):
config.copy(base + ['local-route6', rule], base + ['ip-rule6', rule])
config.delete(base + ['local-route6'])
Loading