Skip to content

Commit

Permalink
Fix IPV6 forced-mgmt-route not work issue (#17299)
Browse files Browse the repository at this point in the history
ix IPV6 forced-mgmt-route not work issue

Why I did it
IPV6 forced-mgmt-route not work

When add a IPV6 route, should use 'ip -6 rule add pref 32764 address' command, but currently in the template the '-6' parameter are missing, so the IPV6 route been add to IPV4 route table.

Also this PR depends on #17281 , which will fix the IPV6 'default' route table missing in IPV6 route lookup issue. 

Microsoft ADO (number only):24719238
  • Loading branch information
liuh-80 authored and mssonicbld committed Feb 7, 2024
1 parent 7cc5ee2 commit b62eb94
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 13 deletions.
4 changes: 2 additions & 2 deletions files/image_config/interfaces/interfaces.j2
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ iface {{ name }} {{ 'inet' if prefix | ipv4 else 'inet6' }} static
up ip {{ '-4' if prefix | ipv4 else '-6' }} route add {{ prefix | network }}/{{ prefix | prefixlen }} dev {{ name }} table {{ vrf_table }}
up ip {{ '-4' if prefix | ipv4 else '-6' }} rule add pref {{ force_mgmt_route_priority + 1 }} from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table {{ vrf_table }}
{% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %}
up ip rule add pref {{ force_mgmt_route_priority }} to {{ route }} table {{ vrf_table }}
up ip {{ '-4' if prefix | ipv4 else '-6' }} rule add pref {{ force_mgmt_route_priority }} to {{ route }} table {{ vrf_table }}
{% endfor %}
{% if prefix | ipv6 and vrf_table == 'default'%}
# IPV6 default table not add to lookup by default, management server need this to access IPV6 address when BGP shutdown
Expand All @@ -97,7 +97,7 @@ iface {{ name }} {{ 'inet' if prefix | ipv4 else 'inet6' }} static
pre-down ip {{ '-4' if prefix | ipv4 else '-6' }} route delete {{ prefix | network }}/{{ prefix | prefixlen }} dev {{ name }} table {{ vrf_table }}
pre-down ip {{ '-4' if prefix | ipv4 else '-6' }} rule delete pref {{ force_mgmt_route_priority + 1 }} from {{ prefix | ip }}/{{ '32' if prefix | ipv4 else '128' }} table {{ vrf_table }}
{% for route in MGMT_INTERFACE[(name, prefix)]['forced_mgmt_routes'] %}
pre-down ip rule delete pref {{ force_mgmt_route_priority }} to {{ route }} table {{ vrf_table }}
pre-down ip {{ '-4' if route | ipv4 else '-6' }} rule delete pref {{ force_mgmt_route_priority }} to {{ route }} table {{ vrf_table }}
{% endfor %}
{% if prefix | ipv6 and vrf_table == 'default'%}
pre-down ip -6 rule delete pref {{ force_mgmt_route_priority + 3 }} lookup {{ vrf_table }}
Expand Down
30 changes: 28 additions & 2 deletions src/sonic-config-engine/minigraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,33 @@ def select_mmu_profiles(profile, platform, hwsku):
base_file = os.path.join(path, file_item)
exec_cmd(["sudo", "cp", file_in_dir, base_file])

def address_type(address):
# encode and decode to unicode, because when address is bytes type, ip_network will throw AddressValueError
# set strict to False because address may set host bit, for example 192.168.0.1/24
return type(ipaddress.ip_network(UNICODE_TYPE(address), False))

def update_forced_mgmt_route(mgmt_intf, mgmt_routes):
for mgmt_intf_key in mgmt_intf.keys():
forced_mgmt_routes = []

try:
# get mgmt interface type
mgmt_intf_addr = mgmt_intf_key[1]
mgmt_iftype = address_type(mgmt_intf_addr)

# add mgmt route to different mgmt interface by address type
for mgmt_route in mgmt_routes:
route_iftype = address_type(mgmt_route)
if mgmt_iftype == route_iftype:
forced_mgmt_routes.append(mgmt_route)
except ValueError as e:
print("Warning: invalid management routes in minigraph, exception: {}".format(e), file=sys.stderr)
continue

# forced_mgmt_routes yang model not support empty list
if len(forced_mgmt_routes) > 0:
mgmt_intf[mgmt_intf_key]['forced_mgmt_routes'] = forced_mgmt_routes

###############################################################################
#
# Main functions
Expand Down Expand Up @@ -1677,8 +1704,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw
results['BGP_INTERNAL_NEIGHBOR'] = bgp_internal_sessions
results['BGP_VOQ_CHASSIS_NEIGHBOR'] = bgp_voq_chassis_sessions
if mgmt_routes:
# TODO: differentiate v4 and v6
next(iter(mgmt_intf.values()))['forced_mgmt_routes'] = mgmt_routes
update_forced_mgmt_route(mgmt_intf, mgmt_routes)
results['MGMT_PORT'] = {}
results['MGMT_INTERFACE'] = {}
mgmt_intf_count = 0
Expand Down
10 changes: 6 additions & 4 deletions src/sonic-config-engine/tests/sample_output/py2/mvrf_interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ iface eth0 inet static
up ip -4 route add default via 10.0.0.1 dev eth0 table 5000 metric 201
up ip -4 route add 10.0.0.0/24 dev eth0 table 5000
up ip -4 rule add pref 32765 from 10.0.0.100/32 table 5000
up ip rule add pref 32764 to 11.11.11.11 table 5000
up ip rule add pref 32764 to 22.22.22.0/23 table 5000
up ip -4 rule add pref 32764 to 11.11.11.11 table 5000
up ip -4 rule add pref 32764 to 22.22.22.0/23 table 5000
# management port down rules
pre-down ip -4 route delete default via 10.0.0.1 dev eth0 table 5000
pre-down ip -4 route delete 10.0.0.0/24 dev eth0 table 5000
pre-down ip -4 rule delete pref 32765 from 10.0.0.100/32 table 5000
pre-down ip rule delete pref 32764 to 11.11.11.11 table 5000
pre-down ip rule delete pref 32764 to 22.22.22.0/23 table 5000
pre-down ip -4 rule delete pref 32764 to 11.11.11.11 table 5000
pre-down ip -4 rule delete pref 32764 to 22.22.22.0/23 table 5000
iface eth0 inet6 static
address 2603:10e2:0:2902::8
netmask 64
Expand All @@ -53,10 +53,12 @@ iface eth0 inet6 static
up ip -6 route add default via 2603:10e2:0:2902::1 dev eth0 table 5000 metric 201
up ip -6 route add 2603:10e2:0:2902::/64 dev eth0 table 5000
up ip -6 rule add pref 32765 from 2603:10e2:0:2902::8/128 table 5000
up ip -6 rule add pref 32764 to 33:33:33::0/64 table 5000
# management port down rules
pre-down ip -6 route delete default via 2603:10e2:0:2902::1 dev eth0 table 5000
pre-down ip -6 route delete 2603:10e2:0:2902::/64 dev eth0 table 5000
pre-down ip -6 rule delete pref 32765 from 2603:10e2:0:2902::8/128 table 5000
pre-down ip -6 rule delete pref 32764 to 33:33:33::0/64 table 5000
#
source /etc/network/interfaces.d/*
#
Expand Down
10 changes: 6 additions & 4 deletions src/sonic-config-engine/tests/sample_output/py3/mvrf_interfaces
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ iface eth0 inet static
up ip -4 route add default via 10.0.0.1 dev eth0 table 5000 metric 201
up ip -4 route add 10.0.0.0/24 dev eth0 table 5000
up ip -4 rule add pref 32765 from 10.0.0.100/32 table 5000
up ip rule add pref 32764 to 11.11.11.11 table 5000
up ip rule add pref 32764 to 22.22.22.0/23 table 5000
up ip -4 rule add pref 32764 to 11.11.11.11 table 5000
up ip -4 rule add pref 32764 to 22.22.22.0/23 table 5000
# management port down rules
pre-down ip -4 route delete default via 10.0.0.1 dev eth0 table 5000
pre-down ip -4 route delete 10.0.0.0/24 dev eth0 table 5000
pre-down ip -4 rule delete pref 32765 from 10.0.0.100/32 table 5000
pre-down ip rule delete pref 32764 to 11.11.11.11 table 5000
pre-down ip rule delete pref 32764 to 22.22.22.0/23 table 5000
pre-down ip -4 rule delete pref 32764 to 11.11.11.11 table 5000
pre-down ip -4 rule delete pref 32764 to 22.22.22.0/23 table 5000
iface eth0 inet6 static
address 2603:10e2:0:2902::8
netmask 64
Expand All @@ -53,10 +53,12 @@ iface eth0 inet6 static
up ip -6 route add default via 2603:10e2:0:2902::1 dev eth0 table 5000 metric 201
up ip -6 route add 2603:10e2:0:2902::/64 dev eth0 table 5000
up ip -6 rule add pref 32765 from 2603:10e2:0:2902::8/128 table 5000
up ip -6 rule add pref 32764 to 33:33:33::0/64 table 5000
# management port down rules
pre-down ip -6 route delete default via 2603:10e2:0:2902::1 dev eth0 table 5000
pre-down ip -6 route delete 2603:10e2:0:2902::/64 dev eth0 table 5000
pre-down ip -6 rule delete pref 32765 from 2603:10e2:0:2902::8/128 table 5000
pre-down ip -6 rule delete pref 32764 to 33:33:33::0/64 table 5000
#
source /etc/network/interfaces.d/*
#
Expand Down
2 changes: 1 addition & 1 deletion src/sonic-config-engine/tests/t0-sample-graph-mvrf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@
<a:DeviceProperty>
<a:Name>ForcedMgmtRoutes</a:Name>
<a:Reference i:nil="true"/>
<a:Value>11.11.11.11;22.22.22.0/23</a:Value>
<a:Value>11.11.11.11;22.22.22.0/23;33:33:33::0/64</a:Value>
</a:DeviceProperty>
<a:DeviceProperty>
<a:Name>ErspanDestinationIpv4</a:Name>
Expand Down

0 comments on commit b62eb94

Please sign in to comment.