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

Support for ip route save and ip route restore commands #1203

Open
pseusys opened this issue Jul 31, 2024 · 2 comments
Open

Support for ip route save and ip route restore commands #1203

pseusys opened this issue Jul 31, 2024 · 2 comments

Comments

@pseusys
Copy link

pseusys commented Jul 31, 2024

Browsing the ip command docs I have noticed three different commands for route bulk manipulation: ip route flush, ip route save and ip route restore. Sadly, it seems like only the first one is implemented in pyroute2. Is there an explanation for that? The latter two commands might be really useful for routing table manipulation. Is there any official workaround (involving IPRoute.get_routes(table=...) probably)? Could I maybe help adding support for that?
If no support is planned, could you please let me know, how can I restore a route thaat I once received with IPRoute.get_routes? It is received in a form of a dictionary.

@pseusys
Copy link
Author

pseusys commented Jan 12, 2025

Here's a patched implementation o IPRoute class, that implements both ip route save and ip route restore commands:

class PatchedIPRoute(IPRoute):
    def save_routes(self, *argv, **kwarg):
        return list(self.get_routes(*argv, **kwarg))

    def restore_routes(self, routes):
        for route in routes:
            self.put(route, msg_type=RTM_NEWROUTE, msg_flags=NLM_F_REQUEST)

@svinota
Copy link
Owner

svinota commented Jan 12, 2025

This might require some additional investigation if we need to serialize route objects — just not to exhaust all the memory on huge numbers of routes.

Beside of that it might be useful to make it compatible with ip route save format.

Ok, got it. Thanks for the request, I will dig around, and update you here next week.

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