<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Hi Tycho,</div><div class="gmail_quote"><br></div><div class="gmail_quote">2016-08-04 0:23 GMT+03:00 Tycho Andersen <span dir="ltr">&lt;<a href="mailto:tycho.andersen@canonical.com" target="_blank">tycho.andersen@canonical.com</a>&gt;</span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">Hi Eugene,<br>
<br>
Sorry for the delay, and thanks for looking into this,<br>
<div><div class="h5"><br>
On Thu, Jul 28, 2016 at 08:14:41AM +0300, Eugene Batalov wrote:<br>
&gt; The logic is the same as on criu restore.<br>
&gt;<br>
&gt; First we read ps tree dump to get information about all its<br>
&gt; tcp connections. If ps tree shares net ns with host then<br>
&gt; we simply run iptables to unlock all ps tree tcp connections.<br>
&gt; If ps tree has unshared net ns then we do nothing because we know<br>
&gt; that this net ns is already destroyed with its ps tree and all<br>
&gt; incoming ps tree TCP packets are just dropped (no destination tcp stack<br>
&gt; exists).<br>
&gt;<br>
&gt; Signed-off-by: Eugene Batalov &lt;<a href="mailto:eabatalov89@gmail.com">eabatalov89@gmail.com</a>&gt;<br>
&gt; ---<br>
&gt;  criu/cr-gc.c           | 10 ++++++++++<br>
&gt;  criu/include/net.h     |  1 +<br>
&gt;  criu/include/sk-inet.h |  2 +-<br>
&gt;  criu/net.c             | 12 ++++++++++++<br>
&gt;  criu/sk-tcp.c          |  9 ++++++---<br>
&gt;  5 files changed, 30 insertions(+), 4 deletions(-)<br>
&gt;<br>
&gt; diff --git a/criu/cr-gc.c b/criu/cr-gc.c<br>
&gt; index 2879365..4c8bea9 100644<br>
&gt; --- a/criu/cr-gc.c<br>
&gt; +++ b/criu/cr-gc.c<br>
&gt; @@ -10,6 +10,8 @@<br>
&gt;  #include &quot;cr_options.h&quot;<br>
&gt;  #include &quot;namespaces.h&quot;<br>
&gt;  #include &quot;util.h&quot;<br>
&gt; +#include &quot;sockets.h&quot;<br>
&gt; +#include &quot;net.h&quot;<br>
&gt;<br>
&gt;  static int gc_validate_opts(void)<br>
&gt;  {<br>
&gt; @@ -80,6 +82,9 @@ static int gc_do(void)<br>
&gt;       if (gc_link_remaps() &lt; 0)<br>
&gt;               return -1;<br>
&gt;<br>
&gt; +     if (gc_network_unlock() &lt; 0)<br>
&gt; +             return -1;<br>
&gt; +<br>
&gt;       return 0;<br>
&gt;  }<br>
&gt;<br>
&gt; @@ -122,6 +127,11 @@ int cr_gc(void)<br>
&gt;               goto exit;<br>
&gt;       }<br>
&gt;<br>
&gt; +     if (collect_inet_sockets()) {<br>
&gt; +             ret = -1;<br>
&gt; +             goto exit;<br>
&gt; +     }<br>
&gt; +<br>
&gt;       if (opts.show)<br>
&gt;               ret = gc_show();<br>
&gt;       else<br>
&gt; diff --git a/criu/include/net.h b/criu/include/net.h<br>
&gt; index ede380f..5e6260a 100644<br>
&gt; --- a/criu/include/net.h<br>
&gt; +++ b/criu/include/net.h<br>
&gt; @@ -19,6 +19,7 @@ extern int collect_net_namespaces(bool for_dump);<br>
&gt;<br>
&gt;  extern int network_lock(void);<br>
&gt;  extern void network_unlock(void);<br>
&gt; +extern int gc_network_unlock(void);<br>
&gt;<br>
&gt;  extern struct ns_desc net_ns_desc;<br>
&gt;<br>
&gt; diff --git a/criu/include/sk-inet.h b/criu/include/sk-inet.h<br>
&gt; index 9d2bda6..c82ffd4 100644<br>
&gt; --- a/criu/include/sk-inet.h<br>
&gt; +++ b/criu/include/sk-inet.h<br>
&gt; @@ -65,7 +65,7 @@ static inline void tcp_repair_off(int fd)<br>
&gt;  }<br>
&gt;<br>
&gt;  extern void tcp_locked_conn_add(struct inet_sk_info *);<br>
&gt; -extern void rst_unlock_tcp_connections(<wbr>void);<br>
&gt; +extern int rst_unlock_tcp_connections(<wbr>void);<br>
&gt;  extern void cpt_unlock_tcp_connections(<wbr>void);<br>
&gt;<br>
&gt;  extern int dump_one_tcp(int sk, struct inet_sk_desc *sd);<br>
&gt; diff --git a/criu/net.c b/criu/net.c<br>
&gt; index a03c168..ef203a8 100644<br>
&gt; --- a/criu/net.c<br>
&gt; +++ b/criu/net.c<br>
&gt; @@ -1618,6 +1618,18 @@ void network_unlock(void)<br>
&gt;       }<br>
&gt;  }<br>
&gt;<br>
&gt; +int gc_network_unlock(void)<br>
&gt; +{<br>
&gt; +     /*<br>
&gt; +      * Unshared ps tree net ns is destroyed after successful dump.<br>
&gt; +      * No need to call network_unlock_internal.<br>
&gt; +      * Also don&#39;t call ACT_NET_UNLOCK script because we don&#39;t<br>
&gt; +      * resume/restore ps tree - this call would break<br>
&gt; +      * ACT_NET_UNLOCK semantics.<br>
&gt; +      */<br>
&gt; +     return rst_unlock_tcp_connections();<br>
<br>
</div></div>What about cpt_unlock_tcp_connections()? IIUC this list is not<br>
persisted, and so if we leave around the network lock stuff, we would<br>
never turn of TCP repair mode.<br>
<br>
Tycho<br></blockquote><div>Let&#39;s consider the moment when we start criu gc or criu restore. At this moment dumpee ps tree doesn&#39;t exist and ps tree sockets don&#39;t exist.<br></div><div>That&#39;s why we don&#39;t need to turn any tcp repair mode off - it is per socket thing.</div><div>Also cpt_unlock_tcp_connections called from network_unlock() that is called during criu restore</div><div>does nothing because cpt_tcp_repair_sockets list is empty. So for me it looks like criu gc works</div><div>the same as criu restore but without calling of network unlock action script.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<div><div class="h5"><br>
&gt; +}<br>
&gt; +<br>
&gt;  int veth_pair_add(char *in, char *out)<br>
&gt;  {<br>
&gt;       char *aux;<br>
&gt; diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c<br>
&gt; index 13d175a..c4aa58f 100644<br>
&gt; --- a/criu/sk-tcp.c<br>
&gt; +++ b/criu/sk-tcp.c<br>
&gt; @@ -713,16 +713,19 @@ void tcp_locked_conn_add(struct inet_sk_info *ii)<br>
&gt;       ii-&gt;sk_fd = -1;<br>
&gt;  }<br>
&gt;<br>
&gt; -void rst_unlock_tcp_connections(<wbr>void)<br>
&gt; +int rst_unlock_tcp_connections(<wbr>void)<br>
&gt;  {<br>
&gt;       struct inet_sk_info *ii;<br>
&gt;<br>
&gt;       /* Network will be unlocked by network-unlock scripts */<br>
&gt;       if (root_ns_mask &amp; CLONE_NEWNET)<br>
&gt; -             return;<br>
&gt; +             return 0;<br>
&gt;<br>
&gt;       list_for_each_entry(ii, &amp;rst_tcp_repair_sockets, rlist)<br>
&gt; -             nf_unlock_connection_info(ii);<br>
&gt; +             if (nf_unlock_connection_info(ii)<wbr>)<br>
&gt; +                     return -1;<br>
&gt; +<br>
&gt; +     return 0;<br>
&gt;  }<br>
&gt;<br>
&gt;  int check_tcp(void)<br>
&gt; --<br>
&gt; 1.9.1<br>
&gt;<br>
</div></div>&gt; ______________________________<wbr>_________________<br>
&gt; CRIU mailing list<br>
&gt; <a href="mailto:CRIU@openvz.org">CRIU@openvz.org</a><br>
&gt; <a href="https://lists.openvz.org/mailman/listinfo/criu" rel="noreferrer" target="_blank">https://lists.openvz.org/<wbr>mailman/listinfo/criu</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">Best regards,<br>Eugene Batalov.</div>
</div></div>