-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Fix IPV6 forced-mgmt-route not work issue #17299
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
Changes from 11 commits
1527252
fde2d79
225cd34
6c7be0b
ae4905e
269269c
6d1554d
4bd7533
3a2adf2
ddc436c
ba1352c
dfc96df
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1458,6 +1458,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 is_ipv4(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 isinstance(ipaddress.ip_network(UNICODE_TYPE(address), False), ipaddress.IPv4Network) | ||
|
||
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_is_ipv4 = is_ipv4(mgmt_intf_addr) | ||
|
||
# add mgmt route to different mgmt interface by address type | ||
for mgmt_route in mgmt_routes: | ||
route_is_ipv4 = is_ipv4(mgmt_route) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change to route_iftype There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree type comparison is more readable than boolean comparison. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed, change to compare iftype. |
||
if mgmt_is_ipv4 == route_is_ipv4: | ||
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 | ||
|
@@ -1699,8 +1726,7 @@ def parse_xml(filename, platform=None, port_config_file=None, asic_name=None, hw | |
results['BGP_VOQ_CHASSIS_NEIGHBOR'] = bgp_voq_chassis_sessions | ||
results['BGP_SENTINELS'] = bgp_sentinel_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) | ||
liuh-80 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
results['MGMT_PORT'] = {} | ||
results['MGMT_INTERFACE'] = {} | ||
mgmt_intf_count = 0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the title is about ipv6, but new test cases are all ipv4, am i missing something here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will add new test case for IPV6. For IPV4 address, following 2 commands are exactly same: But for IPV6 address, we always need add '-6' parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||
iface eth0 inet6 static | ||
address 2603:10e2:0:2902::8 | ||
netmask 64 | ||
|
@@ -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/* | ||
# | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed mgmt_iftype
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, change to compare iftype.