Skip to content

Commit

Permalink
1) Loopback interfaces with valid nexthop IP are not ignored/treated …
Browse files Browse the repository at this point in the history
…as loopback. (sonic-net#1565)

2) The vrf routes are *not* handled.
  • Loading branch information
renukamanavalan authored Apr 16, 2021
1 parent 149ccbd commit 176cc4a
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
22 changes: 18 additions & 4 deletions scripts/route_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,10 @@ def get_subscribe_updates(selector, subs):
return (sorted(adds), sorted(deletes))


def is_vrf(k):
return k.startswith("Vrf")


def get_routes():
"""
helper to read route table from APPL-DB.
Expand All @@ -276,7 +280,7 @@ def get_routes():

valid_rt = []
for k in keys:
if not is_local(k):
if not is_vrf(k) and not is_local(k):
valid_rt.append(add_prefix_ifnot(k.lower()))

print_message(syslog.LOG_DEBUG, json.dumps({"ROUTE_TABLE": sorted(valid_rt)}, indent=4))
Expand Down Expand Up @@ -341,15 +345,25 @@ def filter_out_local_interfaces(keys):
:return keys filtered out of local
"""
rt = []
local_if_re = [r'eth0', r'lo', r'docker0', r'tun0', r'Loopback\d+']
local_if_lst = {'eth0', 'docker0'}
local_if_lo = [r'tun0', r'lo', r'Loopback\d+']

db = swsscommon.DBConnector(APPL_DB_NAME, 0)
tbl = swsscommon.Table(db, 'ROUTE_TABLE')

for k in keys:
e = dict(tbl.get(k)[1])
if not e or all([not re.match(x, e['ifname']) for x in local_if_re]):
rt.append(k)

ifname = e.get('ifname', '')
if ifname in local_if_lst:
continue

if any([re.match(x, ifname) for x in local_if_lo]):
nh = e.get('nexthop')
if not nh or ipaddress.ip_address(nh).is_unspecified:
continue

rt.append(k)

return rt

Expand Down
34 changes: 34 additions & 0 deletions tests/route_check_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,40 @@
}
}
}
},
"5": {
DESCR: "local route with nexthop - fail",
ARGS: "route_check -m INFO -i 1000",
RET: -1,
PRE: {
APPL_DB: {
ROUTE_TABLE: {
"0.0.0.0/0" : { "ifname": "portchannel0" },
"10.10.196.12/31" : { "ifname": "portchannel0" },
"10.10.196.20/31" : { "ifname": "portchannel0" },
"10.10.196.30/31" : { "ifname": "lo", "nexthop": "100.0.0.2" }
},
INTF_TABLE: {
"PortChannel1013:10.10.196.24/31": {},
"PortChannel1023:2603:10b0:503:df4::5d/126": {},
"PortChannel1024": {}
}
},
ASIC_DB: {
RT_ENTRY_TABLE: {
RT_ENTRY_KEY_PREFIX + "10.10.196.12/31" + RT_ENTRY_KEY_SUFFIX: {},
RT_ENTRY_KEY_PREFIX + "10.10.196.20/31" + RT_ENTRY_KEY_SUFFIX: {},
RT_ENTRY_KEY_PREFIX + "10.10.196.24/32" + RT_ENTRY_KEY_SUFFIX: {},
RT_ENTRY_KEY_PREFIX + "2603:10b0:503:df4::5d/128" + RT_ENTRY_KEY_SUFFIX: {},
RT_ENTRY_KEY_PREFIX + "0.0.0.0/0" + RT_ENTRY_KEY_SUFFIX: {}
}
}
},
RESULT: {
"missed_ROUTE_TABLE_routes": [
"10.10.196.30/31"
]
}
}
}

Expand Down

0 comments on commit 176cc4a

Please sign in to comment.