[CRIU] [PATCH 03/11] soccr: add support for half-closed sockets

Andrei Vagin avagin at virtuozzo.com
Mon Nov 21 18:06:42 PST 2016


On Mon, Nov 21, 2016 at 05:45:20PM -0800, Andrei Vagin wrote:
> On Mon, Nov 21, 2016 at 10:36:29PM +0300, Pavel Emelyanov wrote:
> > On 11/11/2016 10:10 AM, Andrei Vagin wrote:
> > > From: Andrei Vagin <avagin at virtuozzo.com>
> > > 
> > > A socket is in one of half-closed states, if it sent a fin packet
> > > or it received a fin packet.
> > > 
> > > CRIU plays with fin packets to restore half-closed states too.
> > > 
> > > When we need to sent a fin packet from a socket, we can call
> > > shutdown(SHUT_WR). When a fin packet has to be restore in
> > > a received queue, criu generate a fin packet and send it via
> > > a raw ip socket.
> > > 
> > > A raw packet is sent with the SOCCR_MARK mark to be able
> > > to not block it.
> > > 
> > > Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
> > > ---
> > >  criu/Makefile.packages |   2 +-
> > >  soccr/soccr.c          | 165 ++++++++++++++++++++++++++++++++++++++++++++++++-
> > >  soccr/soccr.h          |  18 +++++-
> > >  3 files changed, 180 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/criu/Makefile.packages b/criu/Makefile.packages
> > > index 53fbdae..886394f 100644
> > > --- a/criu/Makefile.packages
> > > +++ b/criu/Makefile.packages
> > > @@ -19,7 +19,7 @@ REQ-DEB-PKG-NAMES	+= libcap-dev
> > >  
> > >  REQ-DEB-PKG-TEST-NAMES  += libaio-dev
> > >  
> > > -export LIBS		+= -lrt -lpthread -lprotobuf-c -ldl -lnl-3 -lsoccr -Lsoccr/
> > > +export LIBS		+= -lrt -lpthread -lprotobuf-c -ldl -lnl-3 -lsoccr -Lsoccr/ -lnet
> > >  
> > >  check-packages-failed:
> > >  	$(warning Can not find some of the required libraries)
> > > diff --git a/soccr/soccr.c b/soccr/soccr.c
> > > index 7c6bfb1..af39eda 100644
> > > --- a/soccr/soccr.c
> > > +++ b/soccr/soccr.c
> > > @@ -4,6 +4,9 @@
> > >  #include <sys/ioctl.h>
> > >  #include <errno.h>
> > >  #include <linux/sockios.h>
> > > +#include <libnet.h>
> > > +#include <assert.h>
> > > +
> > >  #include "soccr.h"
> > >  
> > >  #ifndef SIOCOUTQNSD
> > > @@ -11,6 +14,20 @@
> > >  #define SIOCOUTQNSD     0x894B
> > >  #endif
> > >  
> > > +enum {
> > > +        TCPF_ESTABLISHED = (1 << 1),
> > > +        TCPF_SYN_SENT    = (1 << 2),
> > > +        TCPF_SYN_RECV    = (1 << 3),
> > > +        TCPF_FIN_WAIT1   = (1 << 4),
> > > +        TCPF_FIN_WAIT2   = (1 << 5),
> > > +        TCPF_TIME_WAIT   = (1 << 6),
> > > +        TCPF_CLOSE       = (1 << 7),
> > > +        TCPF_CLOSE_WAIT  = (1 << 8),
> > > +        TCPF_LAST_ACK    = (1 << 9),
> > > +        TCPF_LISTEN      = (1 << 10),
> > > +        TCPF_CLOSING     = (1 << 11),
> > > +};
> > > +
> > >  static void (*log)(unsigned int loglevel, const char *format, ...)
> > >  	__attribute__ ((__format__ (__printf__, 2, 3)));
> > >  static unsigned int log_level = 0;
> > > @@ -89,6 +106,11 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
> > >  
> > >  	switch (ti->tcpi_state) {
> > >  	case TCP_ESTABLISHED:
> > > +	case TCP_FIN_WAIT1:
> > > +	case TCP_FIN_WAIT2:
> > > +	case TCP_LAST_ACK:
> > > +	case TCP_CLOSE_WAIT:
> > > +	case TCP_CLOSING:
> > >  	case TCP_CLOSE:
> > >  		break;
> > >  	default:
> > > @@ -96,7 +118,7 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
> > >  		return -1;
> > >  	}
> > >  
> > > -	data->state = TCP_ESTABLISHED;
> > > +	data->state = ti->tcpi_state;
> > >  
> > >  	if (ioctl(sk->fd, SIOCOUTQ, &size) == -1) {
> > >  		loge("Unable to get size of snd queue");
> > > @@ -112,6 +134,14 @@ static int refresh_sk(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, str
> > >  
> > >  	data->unsq_len = size;
> > >  
> > > +	/* Don't account the fin packet. It doesn't countain real data. */
> > > +	if ((1 << data->state) & (TCPF_FIN_WAIT1 | TCPF_LAST_ACK | TCPF_CLOSING)) {
> > > +		assert(data->outq_len > 0);
> > 
> > assert?! We have BUG_ON-s in criu for this, don't we?
> 
> soccr is a separate libary.
> 

I want to say that it may be better to use more general things in
libraries.


More information about the CRIU mailing list