Closed
Description
Hello. Why routes are not deleted in the ipdb module when the interface is down. For example:
pc@user:~$ sudo ip route add 8.8.8.8 via 10.10.3.1 dev enp3s0 table 205
pc@user:~$ ip route show table 205
8.8.8.8 via 10.10.3.1 dev enp3s0 linkdown
pc@user:~$
In [1]: from pyroute2 import IPDB
In [2]: ipdb = IPDB()
In [3]: print(ipdb.routes.tables[205])
[{'family': 2, 'ipdb_priority': 0, 'metrics': {}, 'oif': 7859, 'type': 1, 'dst_len': 32, 'dst': '8.8.8.8/32', 'scope': 0, 'src_len': 0, 'flags': 16, 'tos': 0, 'encap': {}, 'proto': 3, 'ipdb_scope': 'system', 'multipath': (), 'table': 205, 'gateway': '10.10.3.1'}]
pc@user:~$ sudo ip link set enp3s0 down
pc@user:~$ ip route show table 205
pc@user:~$
In [4]: print(ipdb.routes.tables[205])
[{'family': 2, 'ipdb_priority': 0, 'metrics': {}, 'oif': 7859, 'type': 1, 'dst_len': 32, 'dst': '8.8.8.8/32', 'scope': 0, 'src_len': 0, 'flags': 16, 'tos': 0, 'encap': {}, 'proto': 3, 'ipdb_scope': 'system', 'multipath': (), 'table': 205, 'gateway': '10.10.3.1'}]
The RoutingTableSet class has method:
pyroute2/pyroute2/ipdb/routes.py
Line 1219 in 6b56aa2
associated with the RTM_DELLINK event. But RTM_DELLINK is raised only when interfaces are deleted, not turned off. Is it possible add the following method:
def gc_mark_down(self, msg):
if msg['family'] != 0 or msg['state'] != 'down':
return
for record in self.filter({'oif': msg['index']}):
with record['route']._direct_state:
record['route']['ipdb_scope'] = 'gc'
record['route']._gctime = time.time()
for record in self.filter({'iif': msg['index']}):
with record['route']._direct_state:
record['route']['ipdb_scope'] = 'gc'
record['route']._gctime = time.time()
and bind it to event RTM_NEWLINK ?
Activity