Skip to contentSkip to conversation

Add ip rule save/restore

PATCH In review Kirill Tkhai 2 participants 2 messages Oct 20, 2015 – Oct 23, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add ip rule save/restore

This patch adds save and restore commands to "ip rule" similar the same is made in commit f4ff11e3e298 for "ip route".

The feature is useful in checkpoint/restore for container migration, also it may be helpful in some normal situations.

---
 doc/ip-cref.tex    |   36 ++++++++++++++++++
 ip/iprule.c        |  103 +++++++++++++++++++++++++++++++++++++++++++++++++---
 man/man8/ip-rule.8 |   26 +++++++++++++
 3 files changed, 158 insertions(+), 7 deletions(-)
doc/ip-cref.tex +36 -0
index ea14795..67094c9 100644
@@ -2246,6 +2246,42 @@ Besides that, the host 193.233.7.83 is translated into
 another prefix to look like 192.203.80.144 when talking
 to the outer world.
 
+\subsection{{\tt ip rule save} -- save rules tables}
+\label{IP-RULE-SAVE}
+
+\paragraph{Description:} this command saves the contents of the rules
+tables or the rule(s) selected by some criteria to standard output.
+
+\paragraph{Arguments:} \verb|ip rule save| has the same arguments as
+\verb|ip rule show|.
+
+\paragraph{Example:} This saves all the rules to the {\tt saved\_rules}
+file:
+\begin{verbatim}
+dan@caffeine:~ # ip rule save > saved_rules
+\end{verbatim}
+
+\paragraph{Output format:} The format of the data stream provided by
+\verb|ip rule save| is that of \verb|rtnetlink|.  See
+\verb|rtnetlink(7)| for more information.
+
+\subsection{{\tt ip rule restore} -- restore rules tables}
+\label{IP-RULE-RESTORE}
+
+\paragraph{Description:} this command restores the contents of the rules
+tables according to a data stream as provided by \verb|ip rule save| via
+standard input.  Note that any rules already in the table are left unchanged,
+and duplicates are not ignored.
+
+\paragraph{Arguments:} This command takes no arguments.
+
+\paragraph{Example:} This restores all rules that were saved to the
+{\tt saved\_rules} file:
+
+\begin{verbatim}
+dan@caffeine:~ # ip rule restore < saved_rules
+\end{verbatim}
+
 
 
 \section{{\tt ip maddress} --- multicast addresses management}
ip/iprule.c +97 -6

151 lines not on this page · raw message

man/man8/ip-rule.8 +25 -1
index 6245d8c..b1d03e7 100644
@@ -15,10 +15,13 @@ ip-rule \- routing policy database management
 
 .ti -8
 .B  ip rule
-.RB " [ " list " | " add " | " del " | " flush " ]"
+.RB " [ " list " | " add " | " del " | " flush " | " save " ]"
 .I  SELECTOR ACTION
 
 .ti -8
+.B  ip rule  " restore "
+
+.ti -8
 .IR SELECTOR " := [ "
 .B  from
 .IR PREFIX " ] [ "
@@ -265,6 +268,27 @@ This command has no arguments.
 This command has no arguments.
 The options list or lst are synonyms with show.
 
+.TP
+.B ip rule save
+save rules table information to stdout
+.RS
+This command behaves like
+.BR "ip rule show"
+except that the output is raw data suitable for passing to
+.BR "ip rule restore" .
+.RE
+
+.TP
+.B ip rule restore
+restore rules table information from stdin
+.RS
+This command expects to read a data stream as returned from
+.BR "ip rule save" .
+It will attempt to restore the rules table information exactly as
+it was at the time of the save. Any rules already in the table are
+left unchanged, and duplicates are not ignored.
+.RE
+
 .SH SEE ALSO
 .br
 .BR ip (8)
#1 lore raw
Quoted 7 lines · On Tue, 20 Oct 2015 13:41:48 +0300 Kirill Tkhai <[email protected]> wrote:

This patch adds save and restore commands to "ip rule" similar the same is made in commit f4ff11e3e298 for "ip route".

The feature is useful in checkpoint/restore for container migration, also it may be helpful in some normal situations.

Sure applied.