Skip to content
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

Hanging routes #620

Closed
pyroute2user opened this issue Jul 5, 2019 · 2 comments
Closed

Hanging routes #620

pyroute2user opened this issue Jul 5, 2019 · 2 comments

Comments

@pyroute2user
Copy link

pyroute2user commented Jul 5, 2019

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:

def gc_mark_link(self, msg):

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 ?

@pyroute2user
Copy link
Author

pyroute2user commented Jul 5, 2019

It seems that here:

self.ipdb.nl.route('get', **route['route'])

the route method returns routes from main table, so possible invalid routes will be restored.
Looks like you need to do an additional check here.
Something like this:

                if not self.ipdb.nl.route('dump', **route['route']): 
                    raise

@svinota svinota added the bug label Aug 20, 2019
svinota added a commit that referenced this issue Aug 20, 2019
@svinota
Copy link
Owner

svinota commented Aug 20, 2019

Ough. True. Fixed according to your proposal.

@svinota svinota added the fixed label Aug 20, 2019
@svinota svinota closed this as completed Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants