Add ip route {save,restore}
Subsystems (2)
PATCH 1/1 Add ip route {save,restore}
This patch adds save and restore commands to "ip route". Save dumps the RTNL stream to stdout which can then be passed to restore later. This may be helpful in some normal situations, and will allow C/R to migrate the routing information in userspace. Tweaking of the stream can be done by userspace helpers to convert between versions and adjust things like device indexes when restoring routes in a different environment.
By factoring out some of the common bits of print_route() into filter_nlmsg(), the "save" command can use the same selection logic as "list," allowing the caller to save only specific routes as necessary.
The only change since the RFC is the addition of manpage and doc material.
--- doc/ip-cref.tex | 35 +++++++++++ ip/iproute.c | 169 +++++++++++++++++++++++++++++++++++++++++-------------- man/man8/ip.8 | 22 +++++++ 3 files changed, 184 insertions(+), 42 deletions(-)
doc/ip-cref.tex +35 -0
@@ -1675,6 +1675,41 @@ information about this route is shown: \item \verb|used| --- the number of lookups of this route since its creation. \end{itemize} +\subsection{{\tt ip route save} -- save routing tables} +\label{IP-ROUTE-SAVE} + +\paragraph{Description:} this command saves the contents of the routing +tables or the route(s) selected by some criteria to standard output. + +\paragraph{Arguments:} \verb|ip route save| has the same arguments as +\verb|ip route show|. + +\paragraph{Example:} This saves all the routes to the {\tt saved\_routes} +file: +\begin{verbatim} +dan@caffeine:~ # ip route save > saved_routes +\end{verbatim} + +\paragraph{Output format:} The format of the data stream provided by +\verb|ip route save| is that of \verb|rtnetlink|. See +\verb|rtnetlink(7)| for more information. + +\subsection{{\tt ip route restore} -- restore routing tables} +\label{IP-ROUTE-RESTORE} + +\paragraph{Description:} this command restores the contents of the routing +tables according to a data stream as provided by \verb|ip route save| via +standard input. Note that any routes already in the table are left unchanged. +Any routes in the input stream that already exist in the tables are ignored. + +\paragraph{Arguments:} This command takes no arguments. + +\paragraph{Example:} This restores all routes that were saved to the +{\tt saved\_routes} file: + +\begin{verbatim} +dan@caffeine:~ # ip route restore < saved_routes +\end{verbatim} \subsection{{\tt ip route flush} --- flush routing tables} \label{IP-ROUTE-FLUSH}
ip/iproute.c +127 -42
260 lines not on this page · raw message
man/man8/ip.8 +22 -0
@@ -132,6 +132,13 @@ tentative " | " deprecated " | " dadfailed " | " temporary " ]" .I SELECTOR .ti -8 +.BR "ip route save" +.I SELECTOR + +.ti -8 +.BR "ip route restore" + +.ti -8 .B ip route get .IR ADDRESS " [ " .BI from " ADDRESS " iif " STRING"
@@ -1867,6 +1874,21 @@ however, no packets are actually sent. With the argument, the kernel pretends that a packet arrived from this interface and searches for a path to forward the packet. +.SS ip route save - save routing table information to stdout +this command behaves like +.BR "ip route show" +except that the output is raw data suitable for passing to +.BR "ip route restore" . + +.SS ip route restore - restore routing table information from stdin +this command expects to read a data stream as returned from +.BR "ip route save" . +It will attempt to restore the routing table information exactly as +it was at the time of the save, so any translation of information +in the stream (such as device indexes) must be done first. Any existing +routes are left unchanged. Any routes specified in the data stream that +already exist in the table will be ignored. + .SH ip rule - routing policy database management .BR "Rule" s
Signature · 1 line
1.7.0.4
Quoted 13 lines · On Fri, 21 May 2010 09:45:11 -0700 Dan Smith <[email protected]> wrote:
This patch adds save and restore commands to "ip route". Save dumps the RTNL stream to stdout which can then be passed to restore later. This may be helpful in some normal situations, and will allow C/R to migrate the routing information in userspace. Tweaking of the stream can be done by userspace helpers to convert between versions and adjust things like device indexes when restoring routes in a different environment.
By factoring out some of the common bits of
print_route()intofilter_nlmsg(), the "save" command can use the same selection logic as "list," allowing the caller to save only specific routes as necessary.
Quoted 4 lines
The only change since the RFC is the addition of manpage and doc material.
Signed-off-by Dan Smith <[email protected]>
I think Jamal/Alexey original intent was that output of show command could be piped back in, allowing the same kind of save/restore without special format.
But probably over the intervening time, the output format diverged and that isn't possible.