[CRIU] [PATCH 1/2] sk-inet: Add initial support for raw sockets

Cyrill Gorcunov gorcunov at gmail.com
Wed Mar 22 07:55:21 PDT 2017


On Wed, Mar 15, 2017 at 03:33:18PM -0700, Andrey Vagin wrote:
> >  
> > -static int can_dump_ipproto(int ino, int proto)
> > +static int can_dump_ipproto(int ino, int proto, int type)
> >  {
> >  	/* Make sure it's a proto we support */
> >  	switch (proto) {
> > @@ -111,8 +111,12 @@ static int can_dump_ipproto(int ino, int proto)
> >  	case IPPROTO_UDPLITE:
> >  		break;
> >  	default:
> > -		pr_err("Unsupported proto %d for socket %x\n", proto, ino);
> > -		return 0;
> > +		/* Raw sockets may have any protocol inside */
> > +		if (type != SOCK_RAW) {
> 
> maybe we can check type out of this function?

ipproto depends on two factors -- protocol itself and socket type,
I think the reverse -- this place is very suitable for checking.

> >  
> > -	ret |= dump_opt(sk, SOL_IP, IP_FREEBIND, &ioe->freebind);
> > -	ioe->has_freebind = ioe->freebind;
> > +	if (type == SOCK_RAW) {
> > +		if (family == AF_INET6) {
> > +			ret |= dump_opt(sk, SOL_IPV6, IPV6_HDRINCL, &ioe->hdrincl);
> > +		} else {
> > +			ret |= dump_opt(sk, SOL_IP, IP_HDRINCL, &ioe->hdrincl);
> > +			ret |= dump_opt(sk, SOL_IP, IP_NODEFRAG, &ioe->nodefrag);
> > +			ioe->has_nodefrag = ioe->nodefrag;
> > +		}
> > +		ioe->has_hdrincl = ioe->hdrincl;
> > +	} else {
> > +		ret |= dump_opt(sk, SOL_IP, IP_FREEBIND, &ioe->freebind);
> 
> is IP_FREEBIND not suitable for raw sockets?

Well, strictly speaking kernel won't fail if we setup freebind here but
for first patches I don't want to modify it. I'll have to revisit raw
sockets more anyway and then I'll probably move it in.

> >  
> > -	if (!can_dump_ipproto(p->stat.st_ino, proto))
> > +	if (!can_dump_ipproto(p->stat.st_ino, proto, type))
> 
> something like this
> 
> 	if (type != SOCK_RAW && !can_dump_ipproto(p->stat.st_ino, proto, type))) {

No no, as I said I think can_dump_ipproto is better place for that.

> > +	else if (tmp == -ENOENT &&
> > +		 ((req->r.n.sdiag_family == AF_INET ||
> > +		   req->r.n.sdiag_family == AF_INET6) &&
> > +		  req->r.n.sdiag_protocol == IPPROTO_RAW)) {
> > +		pr_warn("No support for DIAG module on family %s with protocol IPPROTO_RAW, may fail later\n",
> > +			req->r.n.sdiag_family == AF_INET ? "IPv4" : "IPv6");
> > +		tmp = 0;
> 
> 
> can you handle this error in collect_sockets() like we do for netlink
> and packet sockers

There was some compilcation iirc. Would you allow me to do it on top?

	Cyrill


More information about the CRIU mailing list