Home | History | Annotate | Line # | Download | only in netinet
in_gif.c revision 1.78
      1  1.78  knakahar /*	$NetBSD: in_gif.c,v 1.78 2016/07/04 04:22:47 knakahara Exp $	*/
      2  1.22    itojun /*	$KAME: in_gif.c,v 1.66 2001/07/29 04:46:09 itojun Exp $	*/
      3   1.3   thorpej 
      4   1.2    itojun /*
      5   1.2    itojun  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      6   1.2    itojun  * All rights reserved.
      7  1.12    itojun  *
      8   1.2    itojun  * Redistribution and use in source and binary forms, with or without
      9   1.2    itojun  * modification, are permitted provided that the following conditions
     10   1.2    itojun  * are met:
     11   1.2    itojun  * 1. Redistributions of source code must retain the above copyright
     12   1.2    itojun  *    notice, this list of conditions and the following disclaimer.
     13   1.2    itojun  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.2    itojun  *    notice, this list of conditions and the following disclaimer in the
     15   1.2    itojun  *    documentation and/or other materials provided with the distribution.
     16   1.2    itojun  * 3. Neither the name of the project nor the names of its contributors
     17   1.2    itojun  *    may be used to endorse or promote products derived from this software
     18   1.2    itojun  *    without specific prior written permission.
     19  1.12    itojun  *
     20   1.2    itojun  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     21   1.2    itojun  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     22   1.2    itojun  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23   1.2    itojun  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     24   1.2    itojun  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     25   1.2    itojun  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     26   1.2    itojun  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     27   1.2    itojun  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     28   1.2    itojun  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     29   1.2    itojun  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     30   1.2    itojun  * SUCH DAMAGE.
     31   1.2    itojun  */
     32  1.25     lukem 
     33  1.25     lukem #include <sys/cdefs.h>
     34  1.78  knakahar __KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.78 2016/07/04 04:22:47 knakahara Exp $");
     35   1.2    itojun 
     36  1.65     pooka #ifdef _KERNEL_OPT
     37   1.2    itojun #include "opt_inet.h"
     38  1.65     pooka #endif
     39   1.2    itojun 
     40   1.2    itojun #include <sys/param.h>
     41   1.2    itojun #include <sys/systm.h>
     42   1.2    itojun #include <sys/socket.h>
     43   1.2    itojun #include <sys/sockio.h>
     44   1.2    itojun #include <sys/mbuf.h>
     45   1.2    itojun #include <sys/errno.h>
     46   1.2    itojun #include <sys/ioctl.h>
     47  1.16    itojun #include <sys/syslog.h>
     48  1.45   mlelstv #include <sys/kernel.h>
     49  1.12    itojun 
     50   1.2    itojun #include <net/if.h>
     51   1.2    itojun #include <net/route.h>
     52   1.2    itojun 
     53   1.2    itojun #include <netinet/in.h>
     54   1.2    itojun #include <netinet/in_systm.h>
     55   1.2    itojun #include <netinet/ip.h>
     56   1.2    itojun #include <netinet/ip_var.h>
     57   1.2    itojun #include <netinet/in_gif.h>
     58  1.12    itojun #include <netinet/in_var.h>
     59  1.12    itojun #include <netinet/ip_encap.h>
     60   1.2    itojun #include <netinet/ip_ecn.h>
     61   1.2    itojun 
     62   1.2    itojun #ifdef INET6
     63   1.2    itojun #include <netinet/ip6.h>
     64   1.2    itojun #endif
     65   1.2    itojun 
     66  1.27    itojun #include <net/if_gif.h>
     67   1.2    itojun 
     68   1.2    itojun #include "gif.h"
     69   1.2    itojun 
     70   1.7    itojun #include <net/net_osdep.h>
     71   1.2    itojun 
     72  1.39     perry static int gif_validate4(const struct ip *, struct gif_softc *,
     73  1.39     perry 	struct ifnet *);
     74  1.22    itojun 
     75   1.2    itojun #if NGIF > 0
     76   1.4    itojun int ip_gif_ttl = GIF_TTL;
     77   1.2    itojun #else
     78   1.4    itojun int ip_gif_ttl = 0;
     79   1.7    itojun #endif
     80   1.2    itojun 
     81  1.74  knakahar static const struct encapsw in_gif_encapsw = {
     82  1.74  knakahar 	.encapsw4 = {
     83  1.74  knakahar 		.pr_input	= in_gif_input,
     84  1.74  knakahar 		.pr_ctlinput	= NULL,
     85  1.74  knakahar 	}
     86  1.26    itojun };
     87  1.22    itojun 
     88   1.2    itojun int
     89  1.40     perry in_gif_output(struct ifnet *ifp, int family, struct mbuf *m)
     90   1.2    itojun {
     91  1.57    dyoung 	struct rtentry *rt;
     92  1.60    dyoung 	struct gif_softc *sc = ifp->if_softc;
     93  1.67  knakahar 	struct sockaddr_in *sin_src = satosin(sc->gif_psrc);
     94  1.67  knakahar 	struct sockaddr_in *sin_dst = satosin(sc->gif_pdst);
     95   1.2    itojun 	struct ip iphdr;	/* capsule IP header, host byte ordered */
     96   1.2    itojun 	int proto, error;
     97   1.2    itojun 	u_int8_t tos;
     98  1.56    dyoung 	union {
     99  1.56    dyoung 		struct sockaddr		dst;
    100  1.56    dyoung 		struct sockaddr_in	dst4;
    101  1.56    dyoung 	} u;
    102   1.2    itojun 
    103   1.2    itojun 	if (sin_src == NULL || sin_dst == NULL ||
    104   1.2    itojun 	    sin_src->sin_family != AF_INET ||
    105   1.2    itojun 	    sin_dst->sin_family != AF_INET) {
    106   1.2    itojun 		m_freem(m);
    107   1.2    itojun 		return EAFNOSUPPORT;
    108   1.2    itojun 	}
    109   1.2    itojun 
    110   1.2    itojun 	switch (family) {
    111   1.2    itojun #ifdef INET
    112   1.2    itojun 	case AF_INET:
    113   1.2    itojun 	    {
    114  1.48    dyoung 		const struct ip *ip;
    115   1.2    itojun 
    116   1.2    itojun 		proto = IPPROTO_IPV4;
    117   1.2    itojun 		if (m->m_len < sizeof(*ip)) {
    118   1.2    itojun 			m = m_pullup(m, sizeof(*ip));
    119  1.49    dyoung 			if (m == NULL)
    120   1.2    itojun 				return ENOBUFS;
    121   1.2    itojun 		}
    122  1.48    dyoung 		ip = mtod(m, const struct ip *);
    123   1.2    itojun 		tos = ip->ip_tos;
    124   1.2    itojun 		break;
    125   1.2    itojun 	    }
    126  1.26    itojun #endif /* INET */
    127   1.2    itojun #ifdef INET6
    128   1.2    itojun 	case AF_INET6:
    129   1.2    itojun 	    {
    130  1.48    dyoung 		const struct ip6_hdr *ip6;
    131   1.2    itojun 		proto = IPPROTO_IPV6;
    132   1.2    itojun 		if (m->m_len < sizeof(*ip6)) {
    133   1.2    itojun 			m = m_pullup(m, sizeof(*ip6));
    134  1.62  liamjfoy 			if (m == NULL)
    135   1.2    itojun 				return ENOBUFS;
    136   1.2    itojun 		}
    137  1.48    dyoung 		ip6 = mtod(m, const struct ip6_hdr *);
    138   1.2    itojun 		tos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
    139   1.2    itojun 		break;
    140   1.2    itojun 	    }
    141  1.26    itojun #endif /* INET6 */
    142   1.2    itojun 	default:
    143   1.9    itojun #ifdef DEBUG
    144   1.2    itojun 		printf("in_gif_output: warning: unknown family %d passed\n",
    145   1.2    itojun 			family);
    146   1.2    itojun #endif
    147   1.2    itojun 		m_freem(m);
    148   1.2    itojun 		return EAFNOSUPPORT;
    149   1.2    itojun 	}
    150   1.2    itojun 
    151  1.60    dyoung 	memset(&iphdr, 0, sizeof(iphdr));
    152   1.2    itojun 	iphdr.ip_src = sin_src->sin_addr;
    153  1.21    itojun 	/* bidirectional configured tunnel mode */
    154  1.21    itojun 	if (sin_dst->sin_addr.s_addr != INADDR_ANY)
    155  1.21    itojun 		iphdr.ip_dst = sin_dst->sin_addr;
    156  1.21    itojun 	else {
    157  1.21    itojun 		m_freem(m);
    158  1.21    itojun 		return ENETUNREACH;
    159   1.2    itojun 	}
    160   1.2    itojun 	iphdr.ip_p = proto;
    161   1.2    itojun 	/* version will be set in ip_output() */
    162   1.4    itojun 	iphdr.ip_ttl = ip_gif_ttl;
    163  1.29    itojun 	iphdr.ip_len = htons(m->m_pkthdr.len + sizeof(struct ip));
    164   1.2    itojun 	if (ifp->if_flags & IFF_LINK1)
    165   1.2    itojun 		ip_ecn_ingress(ECN_ALLOWED, &iphdr.ip_tos, &tos);
    166  1.20    itojun 	else
    167  1.20    itojun 		ip_ecn_ingress(ECN_NOCARE, &iphdr.ip_tos, &tos);
    168   1.2    itojun 
    169   1.2    itojun 	/* prepend new IP header */
    170   1.2    itojun 	M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
    171  1.48    dyoung 	/* XXX Is m_pullup really necessary after M_PREPEND? */
    172  1.50    dyoung 	if (m != NULL && M_UNWRITABLE(m, sizeof(struct ip)))
    173   1.2    itojun 		m = m_pullup(m, sizeof(struct ip));
    174  1.22    itojun 	if (m == NULL)
    175   1.2    itojun 		return ENOBUFS;
    176  1.12    itojun 	bcopy(&iphdr, mtod(m, struct ip *), sizeof(struct ip));
    177   1.2    itojun 
    178  1.56    dyoung 	sockaddr_in_init(&u.dst4, &sin_dst->sin_addr, 0);
    179  1.57    dyoung 	if ((rt = rtcache_lookup(&sc->gif_ro, &u.dst)) == NULL) {
    180  1.56    dyoung 		m_freem(m);
    181  1.56    dyoung 		return ENETUNREACH;
    182  1.53     joerg 	}
    183  1.12    itojun 
    184  1.53     joerg 	/* If the route constitutes infinite encapsulation, punt. */
    185  1.57    dyoung 	if (rt->rt_ifp == ifp) {
    186  1.53     joerg 		rtcache_free(&sc->gif_ro);
    187  1.53     joerg 		m_freem(m);
    188  1.53     joerg 		return ENETUNREACH;	/*XXX*/
    189   1.2    itojun 	}
    190  1.12    itojun 
    191  1.33    itojun 	error = ip_output(m, NULL, &sc->gif_ro, 0, NULL, NULL);
    192  1.30    itojun 	return (error);
    193   1.2    itojun }
    194   1.2    itojun 
    195   1.2    itojun void
    196  1.75  knakahar in_gif_input(struct mbuf *m, int off, int proto)
    197   1.2    itojun {
    198   1.2    itojun 	struct ifnet *gifp = NULL;
    199  1.49    dyoung 	const struct ip *ip;
    200  1.12    itojun 	int af;
    201   1.2    itojun 	u_int8_t otos;
    202  1.76     ozaki 	struct ifnet *rcvif;
    203  1.76     ozaki 	struct psref psref;
    204   1.2    itojun 
    205  1.49    dyoung 	ip = mtod(m, const struct ip *);
    206   1.2    itojun 
    207  1.12    itojun 	gifp = (struct ifnet *)encap_getarg(m);
    208   1.2    itojun 
    209  1.77  knakahar 	if (gifp == NULL || (gifp->if_flags & (IFF_UP|IFF_RUNNING))
    210  1.77  knakahar 		!= (IFF_UP|IFF_RUNNING)) {
    211   1.2    itojun 		m_freem(m);
    212  1.59   thorpej 		ip_statinc(IP_STAT_NOGIF);
    213   1.2    itojun 		return;
    214   1.2    itojun 	}
    215  1.32    itojun #ifndef GIF_ENCAPCHECK
    216  1.66  knakahar 	struct gif_softc *sc = (struct gif_softc *)gifp->if_softc;
    217  1.66  knakahar 	/* other CPU do delete_tunnel */
    218  1.66  knakahar 	if (sc->gif_psrc == NULL || sc->gif_pdst == NULL) {
    219  1.66  knakahar 		m_freem(m);
    220  1.66  knakahar 		ip_statinc(IP_STAT_NOGIF);
    221  1.66  knakahar 		return;
    222  1.66  knakahar 	}
    223  1.66  knakahar 
    224  1.76     ozaki 	rcvif = m_get_rcvif_psref(m, &psref);
    225  1.76     ozaki 	if (!gif_validate4(ip, sc, rcvif)) {
    226  1.76     ozaki 		m_put_rcvif_psref(rcvif, &psref);
    227  1.22    itojun 		m_freem(m);
    228  1.59   thorpej 		ip_statinc(IP_STAT_NOGIF);
    229  1.22    itojun 		return;
    230  1.22    itojun 	}
    231  1.76     ozaki 	m_put_rcvif_psref(rcvif, &psref);
    232  1.22    itojun #endif
    233   1.2    itojun 	otos = ip->ip_tos;
    234   1.2    itojun 	m_adj(m, off);
    235   1.2    itojun 
    236   1.2    itojun 	switch (proto) {
    237   1.2    itojun #ifdef INET
    238   1.2    itojun 	case IPPROTO_IPV4:
    239   1.2    itojun 	    {
    240  1.42  christos 		struct ip *xip;
    241   1.2    itojun 		af = AF_INET;
    242  1.50    dyoung 		if (M_UNWRITABLE(m, sizeof(*xip))) {
    243  1.49    dyoung 			if ((m = m_pullup(m, sizeof(*xip))) == NULL)
    244   1.2    itojun 				return;
    245   1.2    itojun 		}
    246  1.42  christos 		xip = mtod(m, struct ip *);
    247   1.2    itojun 		if (gifp->if_flags & IFF_LINK1)
    248  1.42  christos 			ip_ecn_egress(ECN_ALLOWED, &otos, &xip->ip_tos);
    249  1.20    itojun 		else
    250  1.42  christos 			ip_ecn_egress(ECN_NOCARE, &otos, &xip->ip_tos);
    251   1.2    itojun 		break;
    252   1.2    itojun 	    }
    253   1.2    itojun #endif
    254   1.2    itojun #ifdef INET6
    255   1.2    itojun 	case IPPROTO_IPV6:
    256   1.2    itojun 	    {
    257   1.2    itojun 		struct ip6_hdr *ip6;
    258   1.2    itojun 		u_int8_t itos;
    259   1.2    itojun 		af = AF_INET6;
    260  1.50    dyoung 		if (M_UNWRITABLE(m, sizeof(*ip6))) {
    261  1.49    dyoung 			if ((m = m_pullup(m, sizeof(*ip6))) == NULL)
    262   1.2    itojun 				return;
    263   1.2    itojun 		}
    264   1.2    itojun 		ip6 = mtod(m, struct ip6_hdr *);
    265   1.2    itojun 		itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
    266   1.2    itojun 		if (gifp->if_flags & IFF_LINK1)
    267   1.2    itojun 			ip_ecn_egress(ECN_ALLOWED, &otos, &itos);
    268  1.20    itojun 		else
    269  1.20    itojun 			ip_ecn_egress(ECN_NOCARE, &otos, &itos);
    270   1.2    itojun 		ip6->ip6_flow &= ~htonl(0xff << 20);
    271   1.2    itojun 		ip6->ip6_flow |= htonl((u_int32_t)itos << 20);
    272   1.2    itojun 		break;
    273   1.2    itojun 	    }
    274   1.2    itojun #endif /* INET6 */
    275   1.2    itojun 	default:
    276  1.59   thorpej 		ip_statinc(IP_STAT_NOGIF);
    277   1.2    itojun 		m_freem(m);
    278   1.2    itojun 		return;
    279   1.2    itojun 	}
    280   1.2    itojun 	gif_input(m, af, gifp);
    281   1.2    itojun 	return;
    282  1.12    itojun }
    283  1.12    itojun 
    284  1.12    itojun /*
    285  1.22    itojun  * validate outer address.
    286  1.12    itojun  */
    287  1.22    itojun static int
    288  1.40     perry gif_validate4(const struct ip *ip, struct gif_softc *sc, struct ifnet *ifp)
    289  1.12    itojun {
    290  1.12    itojun 	struct sockaddr_in *src, *dst;
    291  1.12    itojun 	struct in_ifaddr *ia4;
    292  1.12    itojun 
    293  1.67  knakahar 	src = satosin(sc->gif_psrc);
    294  1.67  knakahar 	dst = satosin(sc->gif_pdst);
    295  1.12    itojun 
    296  1.12    itojun 	/* check for address match */
    297  1.22    itojun 	if (src->sin_addr.s_addr != ip->ip_dst.s_addr ||
    298  1.22    itojun 	    dst->sin_addr.s_addr != ip->ip_src.s_addr)
    299  1.12    itojun 		return 0;
    300  1.12    itojun 
    301  1.12    itojun 	/* martian filters on outer source - NOT done in ip_input! */
    302  1.22    itojun 	if (IN_MULTICAST(ip->ip_src.s_addr))
    303  1.12    itojun 		return 0;
    304  1.22    itojun 	switch ((ntohl(ip->ip_src.s_addr) & 0xff000000) >> 24) {
    305  1.12    itojun 	case 0: case 127: case 255:
    306  1.12    itojun 		return 0;
    307  1.12    itojun 	}
    308  1.12    itojun 	/* reject packets with broadcast on source */
    309  1.34  jonathan 	TAILQ_FOREACH(ia4, &in_ifaddrhead, ia_list) {
    310  1.12    itojun 		if ((ia4->ia_ifa.ifa_ifp->if_flags & IFF_BROADCAST) == 0)
    311  1.12    itojun 			continue;
    312  1.22    itojun 		if (ip->ip_src.s_addr == ia4->ia_broadaddr.sin_addr.s_addr)
    313  1.12    itojun 			return 0;
    314  1.12    itojun 	}
    315  1.12    itojun 
    316  1.12    itojun 	/* ingress filters on outer source */
    317  1.22    itojun 	if ((sc->gif_if.if_flags & IFF_LINK2) == 0 && ifp) {
    318  1.60    dyoung 		union {
    319  1.60    dyoung 			struct sockaddr sa;
    320  1.60    dyoung 			struct sockaddr_in sin;
    321  1.60    dyoung 		} u;
    322  1.12    itojun 		struct rtentry *rt;
    323  1.12    itojun 
    324  1.60    dyoung 		sockaddr_in_init(&u.sin, &ip->ip_src, 0);
    325  1.60    dyoung 		rt = rtalloc1(&u.sa, 0);
    326  1.60    dyoung 		if (rt == NULL || rt->rt_ifp != ifp) {
    327  1.16    itojun #if 0
    328  1.16    itojun 			log(LOG_WARNING, "%s: packet from 0x%x dropped "
    329  1.16    itojun 			    "due to ingress filter\n", if_name(&sc->gif_if),
    330  1.60    dyoung 			    (u_int32_t)ntohl(u.sin.sin_addr.s_addr));
    331  1.16    itojun #endif
    332  1.60    dyoung 			if (rt != NULL)
    333  1.16    itojun 				rtfree(rt);
    334  1.12    itojun 			return 0;
    335  1.12    itojun 		}
    336  1.12    itojun 		rtfree(rt);
    337  1.12    itojun 	}
    338  1.12    itojun 
    339  1.21    itojun 	return 32 * 2;
    340  1.22    itojun }
    341  1.22    itojun 
    342  1.32    itojun #ifdef GIF_ENCAPCHECK
    343  1.22    itojun /*
    344  1.22    itojun  * we know that we are in IFF_UP, outer address available, and outer family
    345  1.22    itojun  * matched the physical addr family.  see gif_encapcheck().
    346  1.22    itojun  */
    347  1.22    itojun int
    348  1.44      tron gif_encapcheck4(struct mbuf *m, int off, int proto, void *arg)
    349  1.22    itojun {
    350  1.22    itojun 	struct ip ip;
    351  1.22    itojun 	struct gif_softc *sc;
    352  1.22    itojun 	struct ifnet *ifp;
    353  1.22    itojun 
    354  1.22    itojun 	/* sanity check done in caller */
    355  1.60    dyoung 	sc = arg;
    356  1.22    itojun 
    357  1.60    dyoung 	m_copydata(m, 0, sizeof(ip), &ip);
    358  1.76     ozaki 	ifp = ((m->m_flags & M_PKTHDR) != 0) ? m_get_rcvif_NOMPSAFE(m) : NULL;
    359  1.22    itojun 
    360  1.22    itojun 	return gif_validate4(&ip, sc, ifp);
    361  1.22    itojun }
    362  1.32    itojun #endif
    363  1.22    itojun 
    364  1.22    itojun int
    365  1.40     perry in_gif_attach(struct gif_softc *sc)
    366  1.22    itojun {
    367  1.32    itojun #ifndef GIF_ENCAPCHECK
    368  1.22    itojun 	struct sockaddr_in mask4;
    369  1.22    itojun 
    370  1.60    dyoung 	memset(&mask4, 0, sizeof(mask4));
    371  1.22    itojun 	mask4.sin_len = sizeof(struct sockaddr_in);
    372  1.22    itojun 	mask4.sin_addr.s_addr = ~0;
    373  1.22    itojun 
    374  1.22    itojun 	if (!sc->gif_psrc || !sc->gif_pdst)
    375  1.22    itojun 		return EINVAL;
    376  1.22    itojun 	sc->encap_cookie4 = encap_attach(AF_INET, -1, sc->gif_psrc,
    377  1.22    itojun 	    (struct sockaddr *)&mask4, sc->gif_pdst, (struct sockaddr *)&mask4,
    378  1.74  knakahar 	    &in_gif_encapsw, sc);
    379  1.22    itojun #else
    380  1.22    itojun 	sc->encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck,
    381  1.74  knakahar 	    &in_gif_encapsw, sc);
    382  1.22    itojun #endif
    383  1.22    itojun 	if (sc->encap_cookie4 == NULL)
    384  1.22    itojun 		return EEXIST;
    385  1.22    itojun 	return 0;
    386  1.22    itojun }
    387  1.22    itojun 
    388  1.22    itojun int
    389  1.73  riastrad in_gif_detach(struct gif_softc *sc)
    390  1.22    itojun {
    391  1.22    itojun 	int error;
    392  1.22    itojun 
    393  1.78  knakahar 	error = in_gif_pause(sc);
    394  1.78  knakahar 
    395  1.78  knakahar 	rtcache_free(&sc->gif_ro);
    396  1.78  knakahar 
    397  1.78  knakahar 	return error;
    398  1.78  knakahar }
    399  1.78  knakahar 
    400  1.78  knakahar int
    401  1.78  knakahar in_gif_pause(struct gif_softc *sc)
    402  1.78  knakahar {
    403  1.78  knakahar 	int error;
    404  1.78  knakahar 
    405  1.22    itojun 	error = encap_detach(sc->encap_cookie4);
    406  1.22    itojun 	if (error == 0)
    407  1.22    itojun 		sc->encap_cookie4 = NULL;
    408  1.45   mlelstv 
    409  1.73  riastrad 	return error;
    410   1.2    itojun }
    411