Home | History | Annotate | Line # | Download | only in netinet
in_gif.c revision 1.25
      1  1.25    lukem /*	$NetBSD: in_gif.c,v 1.25 2001/11/13 00:32:36 lukem 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.25    lukem __KERNEL_RCSID(0, "$NetBSD: in_gif.c,v 1.25 2001/11/13 00:32:36 lukem Exp $");
     35   1.2   itojun 
     36   1.2   itojun #include "opt_inet.h"
     37  1.18   itojun #include "opt_iso.h"
     38   1.2   itojun 
     39  1.22   itojun /* define it if you want to use encap_attach_func (it helps *BSD merge) */
     40  1.22   itojun #define USE_ENCAPCHECK
     41  1.22   itojun 
     42   1.2   itojun #include <sys/param.h>
     43   1.2   itojun #include <sys/systm.h>
     44   1.2   itojun #include <sys/socket.h>
     45   1.2   itojun #include <sys/sockio.h>
     46   1.2   itojun #include <sys/mbuf.h>
     47   1.2   itojun #include <sys/errno.h>
     48   1.2   itojun #include <sys/ioctl.h>
     49  1.16   itojun #include <sys/syslog.h>
     50  1.12   itojun 
     51   1.2   itojun #include <net/if.h>
     52   1.2   itojun #include <net/route.h>
     53   1.2   itojun 
     54   1.2   itojun #include <netinet/in.h>
     55   1.2   itojun #include <netinet/in_systm.h>
     56   1.2   itojun #include <netinet/ip.h>
     57   1.2   itojun #include <netinet/ip_var.h>
     58   1.2   itojun #include <netinet/in_gif.h>
     59  1.12   itojun #include <netinet/in_var.h>
     60  1.12   itojun #include <netinet/ip_encap.h>
     61   1.2   itojun #include <netinet/ip_ecn.h>
     62   1.2   itojun 
     63   1.2   itojun #ifdef INET6
     64   1.2   itojun #include <netinet/ip6.h>
     65   1.2   itojun #endif
     66   1.2   itojun 
     67   1.2   itojun #include <net/if_gif.h>
     68   1.2   itojun 
     69   1.2   itojun #include "gif.h"
     70   1.2   itojun 
     71   1.2   itojun #include <machine/stdarg.h>
     72   1.7   itojun 
     73   1.7   itojun #include <net/net_osdep.h>
     74   1.2   itojun 
     75  1.22   itojun static int gif_validate4 __P((const struct ip *, struct gif_softc *,
     76  1.22   itojun 	struct ifnet *));
     77  1.22   itojun 
     78   1.2   itojun #if NGIF > 0
     79   1.4   itojun int ip_gif_ttl = GIF_TTL;
     80   1.2   itojun #else
     81   1.4   itojun int ip_gif_ttl = 0;
     82   1.7   itojun #endif
     83   1.2   itojun 
     84  1.22   itojun extern struct protosw in_gif_protosw;
     85  1.22   itojun 
     86   1.2   itojun int
     87  1.23   itojun in_gif_output(ifp, family, m)
     88   1.2   itojun 	struct ifnet	*ifp;
     89   1.2   itojun 	int		family;
     90   1.2   itojun 	struct mbuf	*m;
     91   1.2   itojun {
     92  1.16   itojun 	struct gif_softc *sc = (struct gif_softc*)ifp;
     93   1.2   itojun 	struct sockaddr_in *dst = (struct sockaddr_in *)&sc->gif_ro.ro_dst;
     94   1.2   itojun 	struct sockaddr_in *sin_src = (struct sockaddr_in *)sc->gif_psrc;
     95   1.2   itojun 	struct sockaddr_in *sin_dst = (struct sockaddr_in *)sc->gif_pdst;
     96   1.2   itojun 	struct ip iphdr;	/* capsule IP header, host byte ordered */
     97   1.2   itojun 	int proto, error;
     98   1.2   itojun 	u_int8_t tos;
     99   1.2   itojun 
    100   1.2   itojun 	if (sin_src == NULL || sin_dst == NULL ||
    101   1.2   itojun 	    sin_src->sin_family != AF_INET ||
    102   1.2   itojun 	    sin_dst->sin_family != AF_INET) {
    103   1.2   itojun 		m_freem(m);
    104   1.2   itojun 		return EAFNOSUPPORT;
    105   1.2   itojun 	}
    106   1.2   itojun 
    107   1.2   itojun 	switch (family) {
    108   1.2   itojun #ifdef INET
    109   1.2   itojun 	case AF_INET:
    110   1.2   itojun 	    {
    111   1.2   itojun 		struct ip *ip;
    112   1.2   itojun 
    113   1.2   itojun 		proto = IPPROTO_IPV4;
    114   1.2   itojun 		if (m->m_len < sizeof(*ip)) {
    115   1.2   itojun 			m = m_pullup(m, sizeof(*ip));
    116   1.2   itojun 			if (!m)
    117   1.2   itojun 				return ENOBUFS;
    118   1.2   itojun 		}
    119   1.2   itojun 		ip = mtod(m, struct ip *);
    120   1.2   itojun 		tos = ip->ip_tos;
    121   1.2   itojun 		break;
    122   1.2   itojun 	    }
    123   1.2   itojun #endif /*INET*/
    124   1.2   itojun #ifdef INET6
    125   1.2   itojun 	case AF_INET6:
    126   1.2   itojun 	    {
    127   1.2   itojun 		struct ip6_hdr *ip6;
    128   1.2   itojun 		proto = IPPROTO_IPV6;
    129   1.2   itojun 		if (m->m_len < sizeof(*ip6)) {
    130   1.2   itojun 			m = m_pullup(m, sizeof(*ip6));
    131   1.2   itojun 			if (!m)
    132   1.2   itojun 				return ENOBUFS;
    133   1.2   itojun 		}
    134   1.2   itojun 		ip6 = mtod(m, struct ip6_hdr *);
    135   1.2   itojun 		tos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
    136   1.2   itojun 		break;
    137   1.2   itojun 	    }
    138   1.2   itojun #endif /*INET6*/
    139  1.19   itojun #ifdef ISO
    140  1.19   itojun 	case AF_ISO:
    141  1.19   itojun 		proto = IPPROTO_EON;
    142  1.19   itojun 		tos = 0;
    143  1.19   itojun 		break;
    144  1.19   itojun #endif
    145   1.2   itojun 	default:
    146   1.9   itojun #ifdef DEBUG
    147   1.2   itojun 		printf("in_gif_output: warning: unknown family %d passed\n",
    148   1.2   itojun 			family);
    149   1.2   itojun #endif
    150   1.2   itojun 		m_freem(m);
    151   1.2   itojun 		return EAFNOSUPPORT;
    152   1.2   itojun 	}
    153   1.2   itojun 
    154  1.16   itojun 	bzero(&iphdr, sizeof(iphdr));
    155   1.2   itojun 	iphdr.ip_src = sin_src->sin_addr;
    156  1.21   itojun 	/* bidirectional configured tunnel mode */
    157  1.21   itojun 	if (sin_dst->sin_addr.s_addr != INADDR_ANY)
    158  1.21   itojun 		iphdr.ip_dst = sin_dst->sin_addr;
    159  1.21   itojun 	else {
    160  1.21   itojun 		m_freem(m);
    161  1.21   itojun 		return ENETUNREACH;
    162   1.2   itojun 	}
    163   1.2   itojun 	iphdr.ip_p = proto;
    164   1.2   itojun 	/* version will be set in ip_output() */
    165   1.4   itojun 	iphdr.ip_ttl = ip_gif_ttl;
    166   1.2   itojun 	iphdr.ip_len = m->m_pkthdr.len + sizeof(struct ip);
    167   1.2   itojun 	if (ifp->if_flags & IFF_LINK1)
    168   1.2   itojun 		ip_ecn_ingress(ECN_ALLOWED, &iphdr.ip_tos, &tos);
    169  1.20   itojun 	else
    170  1.20   itojun 		ip_ecn_ingress(ECN_NOCARE, &iphdr.ip_tos, &tos);
    171   1.2   itojun 
    172   1.2   itojun 	/* prepend new IP header */
    173   1.2   itojun 	M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
    174   1.2   itojun 	if (m && m->m_len < sizeof(struct ip))
    175   1.2   itojun 		m = m_pullup(m, sizeof(struct ip));
    176  1.22   itojun 	if (m == NULL)
    177   1.2   itojun 		return ENOBUFS;
    178  1.12   itojun 	bcopy(&iphdr, mtod(m, struct ip *), sizeof(struct ip));
    179   1.2   itojun 
    180   1.2   itojun 	if (dst->sin_family != sin_dst->sin_family ||
    181   1.2   itojun 	    dst->sin_addr.s_addr != sin_dst->sin_addr.s_addr) {
    182   1.2   itojun 		/* cache route doesn't match */
    183   1.2   itojun 		dst->sin_family = sin_dst->sin_family;
    184   1.2   itojun 		dst->sin_len = sizeof(struct sockaddr_in);
    185   1.2   itojun 		dst->sin_addr = sin_dst->sin_addr;
    186   1.2   itojun 		if (sc->gif_ro.ro_rt) {
    187   1.2   itojun 			RTFREE(sc->gif_ro.ro_rt);
    188   1.2   itojun 			sc->gif_ro.ro_rt = NULL;
    189   1.2   itojun 		}
    190   1.2   itojun 	}
    191   1.2   itojun 
    192   1.2   itojun 	if (sc->gif_ro.ro_rt == NULL) {
    193   1.2   itojun 		rtalloc(&sc->gif_ro);
    194   1.2   itojun 		if (sc->gif_ro.ro_rt == NULL) {
    195   1.2   itojun 			m_freem(m);
    196   1.2   itojun 			return ENETUNREACH;
    197   1.2   itojun 		}
    198  1.12   itojun 
    199  1.12   itojun 		/* if it constitutes infinite encapsulation, punt. */
    200  1.12   itojun 		if (sc->gif_ro.ro_rt->rt_ifp == ifp) {
    201  1.12   itojun 			m_freem(m);
    202  1.12   itojun 			return ENETUNREACH;	/*XXX*/
    203  1.12   itojun 		}
    204   1.2   itojun 	}
    205  1.12   itojun 
    206   1.7   itojun 	error = ip_output(m, NULL, &sc->gif_ro, 0, NULL);
    207   1.2   itojun 	return(error);
    208   1.2   itojun }
    209   1.2   itojun 
    210   1.2   itojun void
    211   1.2   itojun #if __STDC__
    212   1.2   itojun in_gif_input(struct mbuf *m, ...)
    213   1.2   itojun #else
    214   1.2   itojun in_gif_input(m, va_alist)
    215   1.2   itojun 	struct mbuf *m;
    216   1.2   itojun 	va_dcl
    217   1.2   itojun #endif
    218   1.2   itojun {
    219   1.2   itojun 	int off, proto;
    220   1.2   itojun 	struct ifnet *gifp = NULL;
    221   1.2   itojun 	struct ip *ip;
    222  1.18   itojun 	va_list ap;
    223  1.12   itojun 	int af;
    224   1.2   itojun 	u_int8_t otos;
    225   1.2   itojun 
    226   1.2   itojun 	va_start(ap, m);
    227   1.2   itojun 	off = va_arg(ap, int);
    228   1.2   itojun 	proto = va_arg(ap, int);
    229   1.2   itojun 	va_end(ap);
    230   1.2   itojun 
    231   1.2   itojun 	ip = mtod(m, struct ip *);
    232   1.2   itojun 
    233  1.12   itojun 	gifp = (struct ifnet *)encap_getarg(m);
    234   1.2   itojun 
    235  1.12   itojun 	if (gifp == NULL || (gifp->if_flags & IFF_UP) == 0) {
    236   1.2   itojun 		m_freem(m);
    237   1.2   itojun 		ipstat.ips_nogif++;
    238   1.2   itojun 		return;
    239   1.2   itojun 	}
    240  1.22   itojun #ifndef USE_ENCAPCHECK
    241  1.22   itojun 	if (!gif_validate4(ip, (struct gif_softc *)gifp, m->m_pkthdr.rcvif)) {
    242  1.22   itojun 		m_freem(m);
    243  1.22   itojun 		ipstat.ips_nogif++;
    244  1.22   itojun 		return;
    245  1.22   itojun 	}
    246  1.22   itojun #endif
    247   1.2   itojun 
    248   1.2   itojun 	otos = ip->ip_tos;
    249   1.2   itojun 	m_adj(m, off);
    250   1.2   itojun 
    251   1.2   itojun 	switch (proto) {
    252   1.2   itojun #ifdef INET
    253   1.2   itojun 	case IPPROTO_IPV4:
    254   1.2   itojun 	    {
    255   1.2   itojun 		struct ip *ip;
    256   1.2   itojun 		af = AF_INET;
    257   1.2   itojun 		if (m->m_len < sizeof(*ip)) {
    258   1.2   itojun 			m = m_pullup(m, sizeof(*ip));
    259   1.2   itojun 			if (!m)
    260   1.2   itojun 				return;
    261   1.2   itojun 		}
    262   1.2   itojun 		ip = mtod(m, struct ip *);
    263   1.2   itojun 		if (gifp->if_flags & IFF_LINK1)
    264   1.2   itojun 			ip_ecn_egress(ECN_ALLOWED, &otos, &ip->ip_tos);
    265  1.20   itojun 		else
    266  1.20   itojun 			ip_ecn_egress(ECN_NOCARE, &otos, &ip->ip_tos);
    267   1.2   itojun 		break;
    268   1.2   itojun 	    }
    269   1.2   itojun #endif
    270   1.2   itojun #ifdef INET6
    271   1.2   itojun 	case IPPROTO_IPV6:
    272   1.2   itojun 	    {
    273   1.2   itojun 		struct ip6_hdr *ip6;
    274   1.2   itojun 		u_int8_t itos;
    275   1.2   itojun 		af = AF_INET6;
    276   1.2   itojun 		if (m->m_len < sizeof(*ip6)) {
    277   1.2   itojun 			m = m_pullup(m, sizeof(*ip6));
    278   1.2   itojun 			if (!m)
    279   1.2   itojun 				return;
    280   1.2   itojun 		}
    281   1.2   itojun 		ip6 = mtod(m, struct ip6_hdr *);
    282   1.2   itojun 		itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
    283   1.2   itojun 		if (gifp->if_flags & IFF_LINK1)
    284   1.2   itojun 			ip_ecn_egress(ECN_ALLOWED, &otos, &itos);
    285  1.20   itojun 		else
    286  1.20   itojun 			ip_ecn_egress(ECN_NOCARE, &otos, &itos);
    287   1.2   itojun 		ip6->ip6_flow &= ~htonl(0xff << 20);
    288   1.2   itojun 		ip6->ip6_flow |= htonl((u_int32_t)itos << 20);
    289   1.2   itojun 		break;
    290   1.2   itojun 	    }
    291   1.2   itojun #endif /* INET6 */
    292  1.18   itojun #ifdef ISO
    293  1.18   itojun 	case IPPROTO_EON:
    294  1.18   itojun 		af = AF_ISO;
    295  1.18   itojun 		break;
    296  1.18   itojun #endif
    297   1.2   itojun 	default:
    298   1.2   itojun 		ipstat.ips_nogif++;
    299   1.2   itojun 		m_freem(m);
    300   1.2   itojun 		return;
    301   1.2   itojun 	}
    302   1.2   itojun 	gif_input(m, af, gifp);
    303   1.2   itojun 	return;
    304  1.12   itojun }
    305  1.12   itojun 
    306  1.12   itojun /*
    307  1.22   itojun  * validate outer address.
    308  1.12   itojun  */
    309  1.22   itojun static int
    310  1.22   itojun gif_validate4(ip, sc, ifp)
    311  1.22   itojun 	const struct ip *ip;
    312  1.22   itojun 	struct gif_softc *sc;
    313  1.22   itojun 	struct ifnet *ifp;
    314  1.12   itojun {
    315  1.12   itojun 	struct sockaddr_in *src, *dst;
    316  1.12   itojun 	struct in_ifaddr *ia4;
    317  1.12   itojun 
    318  1.12   itojun 	src = (struct sockaddr_in *)sc->gif_psrc;
    319  1.12   itojun 	dst = (struct sockaddr_in *)sc->gif_pdst;
    320  1.12   itojun 
    321  1.12   itojun 	/* check for address match */
    322  1.22   itojun 	if (src->sin_addr.s_addr != ip->ip_dst.s_addr ||
    323  1.22   itojun 	    dst->sin_addr.s_addr != ip->ip_src.s_addr)
    324  1.12   itojun 		return 0;
    325  1.12   itojun 
    326  1.12   itojun 	/* martian filters on outer source - NOT done in ip_input! */
    327  1.22   itojun 	if (IN_MULTICAST(ip->ip_src.s_addr))
    328  1.12   itojun 		return 0;
    329  1.22   itojun 	switch ((ntohl(ip->ip_src.s_addr) & 0xff000000) >> 24) {
    330  1.12   itojun 	case 0: case 127: case 255:
    331  1.12   itojun 		return 0;
    332  1.12   itojun 	}
    333  1.12   itojun 	/* reject packets with broadcast on source */
    334  1.24     matt 	TAILQ_FOREACH(ia4, &in_ifaddr, ia_list) {
    335  1.12   itojun 		if ((ia4->ia_ifa.ifa_ifp->if_flags & IFF_BROADCAST) == 0)
    336  1.12   itojun 			continue;
    337  1.22   itojun 		if (ip->ip_src.s_addr == ia4->ia_broadaddr.sin_addr.s_addr)
    338  1.12   itojun 			return 0;
    339  1.12   itojun 	}
    340  1.12   itojun 
    341  1.12   itojun 	/* ingress filters on outer source */
    342  1.22   itojun 	if ((sc->gif_if.if_flags & IFF_LINK2) == 0 && ifp) {
    343  1.12   itojun 		struct sockaddr_in sin;
    344  1.12   itojun 		struct rtentry *rt;
    345  1.12   itojun 
    346  1.12   itojun 		bzero(&sin, sizeof(sin));
    347  1.12   itojun 		sin.sin_family = AF_INET;
    348  1.12   itojun 		sin.sin_len = sizeof(struct sockaddr_in);
    349  1.22   itojun 		sin.sin_addr = ip->ip_src;
    350  1.12   itojun 		rt = rtalloc1((struct sockaddr *)&sin, 0);
    351  1.22   itojun 		if (!rt || rt->rt_ifp != ifp) {
    352  1.16   itojun #if 0
    353  1.16   itojun 			log(LOG_WARNING, "%s: packet from 0x%x dropped "
    354  1.16   itojun 			    "due to ingress filter\n", if_name(&sc->gif_if),
    355  1.16   itojun 			    (u_int32_t)ntohl(sin.sin_addr.s_addr));
    356  1.16   itojun #endif
    357  1.16   itojun 			if (rt)
    358  1.16   itojun 				rtfree(rt);
    359  1.12   itojun 			return 0;
    360  1.12   itojun 		}
    361  1.12   itojun 		rtfree(rt);
    362  1.12   itojun 	}
    363  1.12   itojun 
    364  1.21   itojun 	return 32 * 2;
    365  1.22   itojun }
    366  1.22   itojun 
    367  1.22   itojun /*
    368  1.22   itojun  * we know that we are in IFF_UP, outer address available, and outer family
    369  1.22   itojun  * matched the physical addr family.  see gif_encapcheck().
    370  1.22   itojun  */
    371  1.22   itojun int
    372  1.22   itojun gif_encapcheck4(m, off, proto, arg)
    373  1.22   itojun 	const struct mbuf *m;
    374  1.22   itojun 	int off;
    375  1.22   itojun 	int proto;
    376  1.22   itojun 	void *arg;
    377  1.22   itojun {
    378  1.22   itojun 	struct ip ip;
    379  1.22   itojun 	struct gif_softc *sc;
    380  1.22   itojun 	struct ifnet *ifp;
    381  1.22   itojun 
    382  1.22   itojun 	/* sanity check done in caller */
    383  1.22   itojun 	sc = (struct gif_softc *)arg;
    384  1.22   itojun 
    385  1.22   itojun 	/* LINTED const cast */
    386  1.22   itojun 	m_copydata((struct mbuf *)m, 0, sizeof(ip), (caddr_t)&ip);
    387  1.22   itojun 	ifp = ((m->m_flags & M_PKTHDR) != 0) ? m->m_pkthdr.rcvif : NULL;
    388  1.22   itojun 
    389  1.22   itojun 	return gif_validate4(&ip, sc, ifp);
    390  1.22   itojun }
    391  1.22   itojun 
    392  1.22   itojun int
    393  1.22   itojun in_gif_attach(sc)
    394  1.22   itojun 	struct gif_softc *sc;
    395  1.22   itojun {
    396  1.22   itojun #ifndef USE_ENCAPCHECK
    397  1.22   itojun 	struct sockaddr_in mask4;
    398  1.22   itojun 
    399  1.22   itojun 	bzero(&mask4, sizeof(mask4));
    400  1.22   itojun 	mask4.sin_len = sizeof(struct sockaddr_in);
    401  1.22   itojun 	mask4.sin_addr.s_addr = ~0;
    402  1.22   itojun 
    403  1.22   itojun 	if (!sc->gif_psrc || !sc->gif_pdst)
    404  1.22   itojun 		return EINVAL;
    405  1.22   itojun 	sc->encap_cookie4 = encap_attach(AF_INET, -1, sc->gif_psrc,
    406  1.22   itojun 	    (struct sockaddr *)&mask4, sc->gif_pdst, (struct sockaddr *)&mask4,
    407  1.22   itojun 	    (struct protosw *)&in_gif_protosw, sc);
    408  1.22   itojun #else
    409  1.22   itojun 	sc->encap_cookie4 = encap_attach_func(AF_INET, -1, gif_encapcheck,
    410  1.22   itojun 	    &in_gif_protosw, sc);
    411  1.22   itojun #endif
    412  1.22   itojun 	if (sc->encap_cookie4 == NULL)
    413  1.22   itojun 		return EEXIST;
    414  1.22   itojun 	return 0;
    415  1.22   itojun }
    416  1.22   itojun 
    417  1.22   itojun int
    418  1.22   itojun in_gif_detach(sc)
    419  1.22   itojun 	struct gif_softc *sc;
    420  1.22   itojun {
    421  1.22   itojun 	int error;
    422  1.22   itojun 
    423  1.22   itojun 	error = encap_detach(sc->encap_cookie4);
    424  1.22   itojun 	if (error == 0)
    425  1.22   itojun 		sc->encap_cookie4 = NULL;
    426  1.22   itojun 	return error;
    427   1.2   itojun }
    428