Skip to content

Commit 176cc4a

Browse files
1) Loopback interfaces with valid nexthop IP are not ignored/treated as loopback. (sonic-net#1565)
2) The vrf routes are *not* handled.
1 parent 149ccbd commit 176cc4a

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

scripts/route_check.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ def get_subscribe_updates(selector, subs):
264264
return (sorted(adds), sorted(deletes))
265265

266266

267+
def is_vrf(k):
268+
return k.startswith("Vrf")
269+
270+
267271
def get_routes():
268272
"""
269273
helper to read route table from APPL-DB.
@@ -276,7 +280,7 @@ def get_routes():
276280

277281
valid_rt = []
278282
for k in keys:
279-
if not is_local(k):
283+
if not is_vrf(k) and not is_local(k):
280284
valid_rt.append(add_prefix_ifnot(k.lower()))
281285

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

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

349354
for k in keys:
350355
e = dict(tbl.get(k)[1])
351-
if not e or all([not re.match(x, e['ifname']) for x in local_if_re]):
352-
rt.append(k)
356+
357+
ifname = e.get('ifname', '')
358+
if ifname in local_if_lst:
359+
continue
360+
361+
if any([re.match(x, ifname) for x in local_if_lo]):
362+
nh = e.get('nexthop')
363+
if not nh or ipaddress.ip_address(nh).is_unspecified:
364+
continue
365+
366+
rt.append(k)
353367

354368
return rt
355369

tests/route_check_test.py

+34
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,40 @@
218218
}
219219
}
220220
}
221+
},
222+
"5": {
223+
DESCR: "local route with nexthop - fail",
224+
ARGS: "route_check -m INFO -i 1000",
225+
RET: -1,
226+
PRE: {
227+
APPL_DB: {
228+
ROUTE_TABLE: {
229+
"0.0.0.0/0" : { "ifname": "portchannel0" },
230+
"10.10.196.12/31" : { "ifname": "portchannel0" },
231+
"10.10.196.20/31" : { "ifname": "portchannel0" },
232+
"10.10.196.30/31" : { "ifname": "lo", "nexthop": "100.0.0.2" }
233+
},
234+
INTF_TABLE: {
235+
"PortChannel1013:10.10.196.24/31": {},
236+
"PortChannel1023:2603:10b0:503:df4::5d/126": {},
237+
"PortChannel1024": {}
238+
}
239+
},
240+
ASIC_DB: {
241+
RT_ENTRY_TABLE: {
242+
RT_ENTRY_KEY_PREFIX + "10.10.196.12/31" + RT_ENTRY_KEY_SUFFIX: {},
243+
RT_ENTRY_KEY_PREFIX + "10.10.196.20/31" + RT_ENTRY_KEY_SUFFIX: {},
244+
RT_ENTRY_KEY_PREFIX + "10.10.196.24/32" + RT_ENTRY_KEY_SUFFIX: {},
245+
RT_ENTRY_KEY_PREFIX + "2603:10b0:503:df4::5d/128" + RT_ENTRY_KEY_SUFFIX: {},
246+
RT_ENTRY_KEY_PREFIX + "0.0.0.0/0" + RT_ENTRY_KEY_SUFFIX: {}
247+
}
248+
}
249+
},
250+
RESULT: {
251+
"missed_ROUTE_TABLE_routes": [
252+
"10.10.196.30/31"
253+
]
254+
}
221255
}
222256
}
223257

0 commit comments

Comments
 (0)