/* Must be protected by xfrm_cfg_mutex. State and tunnel user references are always incremented on success.  */
static int ipcomp_tunnel_attach(struct xfrm_state *x)
/* Must be protected by xfrm_cfg_mutex. State and tunnel user references are always incremented on success.  */
static int ipcomp_tunnel_attach(struct xfrm_state *x)
{
	int err = 0;
	struct xfrm_state *t;
	t = xfrm_state_lookup(&init_net, (xfrm_address_t *)&x->id.daddr.a4,
			      x->props.saddr.a4, IPPROTO_IPIP, AF_INET);
	if (!t) {
		t = ipcomp_tunnel_create(x);
		if (!t) {
			err = -EINVAL;
			goto out;
		}
		xfrm_state_insert(t);
		xfrm_state_hold(t);
	}
	x->tunnel = t;
	atomic_inc(&t->tunnel_users);
out:
	return err;
}