Skip to content

Commit

Permalink
[filter-fdb] Fix Filter FDB With IPv6 Present in Config DB (sonic-net…
Browse files Browse the repository at this point in the history
…#1059)

Filter fdb was wiping out IPv4 entries when both IPv4 and IPv6
are associated with VLan interface. The reason is IPv6 network
was overwriting IPv4 network. This pr add support to filter
both IPv4 and IPv6 addresses

signed-off-by: Tamer Ahmed <tamer.ahmed@microsoft.com>
  • Loading branch information
tahmed-dev authored Aug 25, 2020
1 parent 0fa1fb2 commit ca8ffe7
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
19 changes: 11 additions & 8 deletions fdbutil/filter_fdb_entries.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import argparse
import json
import sys
import os
import argparse
import sys
import syslog
import traceback
import time
import traceback

from ipaddress import ip_address, ip_network, ip_interface
from collections import defaultdict
from ipaddress import ip_address, ip_network, ip_interface

def get_vlan_cidr_map(filename):
"""
Expand All @@ -33,7 +33,9 @@ def get_vlan_cidr_map(filename):
continue
vlan, cidr = tuple(vlan_key.split('|'))
if vlan in config_db_entries["VLAN"]:
vlan_cidr[vlan] = ip_interface(cidr).network
if vlan not in vlan_cidr:
vlan_cidr[vlan] = {4: ip_address("0.0.0.0".decode()), 6: ip_address("::".decode())}
vlan_cidr[vlan][ip_interface(cidr).version] = ip_interface(cidr).network

return vlan_cidr

Expand Down Expand Up @@ -63,8 +65,9 @@ def get_arp_entries_map(arp_filename, config_db_filename):
continue
table, vlan, ip = tuple(key.split(':'))
if "NEIGH_TABLE" in table and vlan in vlan_cidr.keys() \
and ip_address(ip) in ip_network(vlan_cidr[vlan]) and "neigh" in config.keys():
arp_map[config["neigh"].replace(':', '-')] = ""
and ip_address(ip) in ip_network(vlan_cidr[vlan][ip_interface(ip).version]) \
and "neigh" in config.keys():
arp_map[config["neigh"].replace(':', '-').upper()] = ""

return arp_map

Expand Down Expand Up @@ -92,7 +95,7 @@ def filter_fdb_entries(fdb_filename, arp_filename, config_db_filename, backup_fi
def filter_fdb_entry(fdb_entry):
for key, _ in fdb_entry.items():
if 'FDB_TABLE' in key:
return key.split(':')[-1] in arp_map
return key.split(':')[-1].upper() in arp_map

# malformed entry, default to False so it will be deleted
return False
Expand Down
4 changes: 3 additions & 1 deletion tests/filter_fdb_input/config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -1125,7 +1125,9 @@
}
},
"VLAN_INTERFACE": {
"Vlan1000|192.168.0.1/21": {}
"Vlan1000": {},
"Vlan1000|192.168.0.1/21": {},
"Vlan1000|fc02:1000::1/64": {}
},
"BUFFER_PG": {
"Ethernet4|0": {
Expand Down
9 changes: 8 additions & 1 deletion tests/filter_fdb_input/expected_fdb.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@
},
"OP": "SET"
},
{
"FDB_TABLE:Vlan1000:24-8A-07-4C-F5-18": {
"type": "dynamic",
"port": "Ethernet24"
},
"OP": "SET"
},
{
"FDB_TABLE:Vlan1000:72-06-00-01-02-72": {
"type": "dynamic",
Expand Down Expand Up @@ -398,4 +405,4 @@
},
"OP": "SET"
}
]
]
13 changes: 9 additions & 4 deletions tests/filter_fdb_input/test_vectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@
"Vlan1000": {}
},
"VLAN_INTERFACE": {
"Vlan1000|192.168.0.1/21": {}
"Vlan1000": {},
"Vlan1000|192.168.0.1/21": {},
"Vlan1000|fc02:1000::1/64": {}
},
},
"expected_fdb": [
Expand Down Expand Up @@ -80,7 +82,8 @@
"Vlan1000": {}
},
"VLAN_INTERFACE": {
"Vlan1000|192.168.0.1/21": {}
"Vlan1000|192.168.0.1/21": {},
"Vlan1000|fc02:1000::1/64": {}
},
},
"expected_fdb": [
Expand Down Expand Up @@ -154,8 +157,10 @@
"Vlan1": {}
},
"VLAN_INTERFACE": {
"Vlan1|25.103.178.1/21": {}
},
"Vlan1|25.103.178.1/21": {},
"Vlan1": {},
"Vlan1|fc02:1000::1/64": {}
},
},
"expected_fdb": [
{
Expand Down

0 comments on commit ca8ffe7

Please sign in to comment.