2 /* $KAME: if_gif.c,v 1.87 2001/10/19 08:50:27 itojun Exp $ */
5 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the project nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "opt_inet6.h"
36 #include <sys/param.h>
37 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
42 #include <sys/module.h>
43 #include <sys/socket.h>
44 #include <sys/sockio.h>
45 #include <sys/errno.h>
47 #include <sys/sysctl.h>
48 #include <sys/syslog.h>
51 #include <sys/protosw.h>
53 #include <machine/cpu.h>
56 #include <net/if_clone.h>
57 #include <net/if_types.h>
58 #include <net/netisr.h>
59 #include <net/route.h>
63 #include <netinet/in.h>
64 #include <netinet/in_systm.h>
65 #include <netinet/ip.h>
67 #include <netinet/in_var.h>
68 #include <netinet/in_gif.h>
69 #include <netinet/ip_var.h>
74 #include <netinet/in.h>
76 #include <netinet6/in6_var.h>
77 #include <netinet/ip6.h>
78 #include <netinet6/ip6_var.h>
79 #include <netinet6/scope6_var.h>
80 #include <netinet6/in6_gif.h>
81 #include <netinet6/ip6protosw.h>
84 #include <netinet/ip_encap.h>
85 #include <net/ethernet.h>
86 #include <net/if_bridgevar.h>
87 #include <net/if_gif.h>
89 #include <security/mac/mac_framework.h>
91 static const char gifname[] = "gif";
94 * gif_mtx protects the global gif_softc_list.
96 static struct mtx gif_mtx;
97 static MALLOC_DEFINE(M_GIF, "gif", "Generic Tunnel Interface");
98 static VNET_DEFINE(LIST_HEAD(, gif_softc), gif_softc_list);
99 #define V_gif_softc_list VNET(gif_softc_list)
101 void (*ng_gif_input_p)(struct ifnet *ifp, struct mbuf **mp, int af);
102 void (*ng_gif_input_orphan_p)(struct ifnet *ifp, struct mbuf *m, int af);
103 void (*ng_gif_attach_p)(struct ifnet *ifp);
104 void (*ng_gif_detach_p)(struct ifnet *ifp);
106 static void gif_start(struct ifnet *);
107 static int gif_clone_create(struct if_clone *, int, caddr_t);
108 static void gif_clone_destroy(struct ifnet *);
109 static struct if_clone *gif_cloner;
111 static int gifmodevent(module_t, int, void *);
113 SYSCTL_DECL(_net_link);
114 static SYSCTL_NODE(_net_link, IFT_GIF, gif, CTLFLAG_RW, 0,
115 "Generic Tunnel Interface");
118 * This macro controls the default upper limitation on nesting of gif tunnels.
119 * Since, setting a large value to this macro with a careless configuration
120 * may introduce system crash, we don't allow any nestings by default.
121 * If you need to configure nested gif tunnels, you can define this macro
122 * in your kernel configuration file. However, if you do so, please be
123 * careful to configure the tunnels so that it won't make a loop.
125 #define MAX_GIF_NEST 1
127 static VNET_DEFINE(int, max_gif_nesting) = MAX_GIF_NEST;
128 #define V_max_gif_nesting VNET(max_gif_nesting)
129 SYSCTL_VNET_INT(_net_link_gif, OID_AUTO, max_nesting, CTLFLAG_RW,
130 &VNET_NAME(max_gif_nesting), 0, "Max nested tunnels");
133 * By default, we disallow creation of multiple tunnels between the same
134 * pair of addresses. Some applications require this functionality so
135 * we allow control over this check here.
138 static VNET_DEFINE(int, parallel_tunnels) = 1;
140 static VNET_DEFINE(int, parallel_tunnels) = 0;
142 #define V_parallel_tunnels VNET(parallel_tunnels)
143 SYSCTL_VNET_INT(_net_link_gif, OID_AUTO, parallel_tunnels, CTLFLAG_RW,
144 &VNET_NAME(parallel_tunnels), 0, "Allow parallel tunnels?");
146 /* copy from src/sys/net/if_ethersubr.c */
147 static const u_char etherbroadcastaddr[ETHER_ADDR_LEN] =
148 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
149 #ifndef ETHER_IS_BROADCAST
150 #define ETHER_IS_BROADCAST(addr) \
151 (bcmp(etherbroadcastaddr, (addr), ETHER_ADDR_LEN) == 0)
155 gif_clone_create(ifc, unit, params)
156 struct if_clone *ifc;
160 struct gif_softc *sc;
162 sc = malloc(sizeof(struct gif_softc), M_GIF, M_WAITOK | M_ZERO);
163 sc->gif_fibnum = curthread->td_proc->p_fibnum;
164 GIF2IFP(sc) = if_alloc(IFT_GIF);
165 if (GIF2IFP(sc) == NULL) {
172 GIF2IFP(sc)->if_softc = sc;
173 if_initname(GIF2IFP(sc), gifname, unit);
175 sc->encap_cookie4 = sc->encap_cookie6 = NULL;
176 sc->gif_options = GIF_ACCEPT_REVETHIP;
178 GIF2IFP(sc)->if_addrlen = 0;
179 GIF2IFP(sc)->if_mtu = GIF_MTU;
180 GIF2IFP(sc)->if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
182 /* turn off ingress filter */
183 GIF2IFP(sc)->if_flags |= IFF_LINK2;
185 GIF2IFP(sc)->if_ioctl = gif_ioctl;
186 GIF2IFP(sc)->if_start = gif_start;
187 GIF2IFP(sc)->if_output = gif_output;
188 GIF2IFP(sc)->if_snd.ifq_maxlen = ifqmaxlen;
189 if_attach(GIF2IFP(sc));
190 bpfattach(GIF2IFP(sc), DLT_NULL, sizeof(u_int32_t));
191 if (ng_gif_attach_p != NULL)
192 (*ng_gif_attach_p)(GIF2IFP(sc));
195 LIST_INSERT_HEAD(&V_gif_softc_list, sc, gif_list);
196 mtx_unlock(&gif_mtx);
202 gif_clone_destroy(ifp)
205 #if defined(INET) || defined(INET6)
208 struct gif_softc *sc = ifp->if_softc;
211 LIST_REMOVE(sc, gif_list);
212 mtx_unlock(&gif_mtx);
214 gif_delete_tunnel(ifp);
216 if (sc->encap_cookie6 != NULL) {
217 err = encap_detach(sc->encap_cookie6);
218 KASSERT(err == 0, ("Unexpected error detaching encap_cookie6"));
222 if (sc->encap_cookie4 != NULL) {
223 err = encap_detach(sc->encap_cookie4);
224 KASSERT(err == 0, ("Unexpected error detaching encap_cookie4"));
228 if (ng_gif_detach_p != NULL)
229 (*ng_gif_detach_p)(ifp);
234 GIF_LOCK_DESTROY(sc);
240 vnet_gif_init(const void *unused __unused)
243 LIST_INIT(&V_gif_softc_list);
245 VNET_SYSINIT(vnet_gif_init, SI_SUB_PSEUDO, SI_ORDER_MIDDLE, vnet_gif_init,
249 gifmodevent(mod, type, data)
257 mtx_init(&gif_mtx, "gif_mtx", NULL, MTX_DEF);
258 gif_cloner = if_clone_simple(gifname, gif_clone_create,
259 gif_clone_destroy, 0);
263 if_clone_detach(gif_cloner);
264 mtx_destroy(&gif_mtx);
272 static moduledata_t gif_mod = {
278 DECLARE_MODULE(if_gif, gif_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
279 MODULE_VERSION(if_gif, 1);
282 gif_encapcheck(m, off, proto, arg)
283 const struct mbuf *m;
289 struct gif_softc *sc;
291 sc = (struct gif_softc *)arg;
295 if ((GIF2IFP(sc)->if_flags & IFF_UP) == 0)
298 /* no physical address */
299 if (!sc->gif_psrc || !sc->gif_pdst)
311 case IPPROTO_ETHERIP:
318 /* Bail on short packets */
319 if (m->m_pkthdr.len < sizeof(ip))
322 m_copydata(m, 0, sizeof(ip), (caddr_t)&ip);
327 if (sc->gif_psrc->sa_family != AF_INET ||
328 sc->gif_pdst->sa_family != AF_INET)
330 return gif_encapcheck4(m, off, proto, arg);
334 if (m->m_pkthdr.len < sizeof(struct ip6_hdr))
336 if (sc->gif_psrc->sa_family != AF_INET6 ||
337 sc->gif_pdst->sa_family != AF_INET6)
339 return gif_encapcheck6(m, off, proto, arg);
346 #define GIF_HDR_LEN (ETHER_HDR_LEN + sizeof (struct ip))
349 #define GIF_HDR_LEN6 (ETHER_HDR_LEN + sizeof (struct ip6_hdr))
353 gif_start(struct ifnet *ifp)
355 struct gif_softc *sc;
362 ifp->if_drv_flags |= IFF_DRV_OACTIVE;
363 while (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) {
365 IFQ_DRV_DEQUEUE(&ifp->if_snd, m);
370 /* Take out those altq bytes we add in gif_output */
372 if (sc->gif_psrc->sa_family == AF_INET)
373 m->m_pkthdr.len -= GIF_HDR_LEN;
376 if (sc->gif_psrc->sa_family == AF_INET6)
377 m->m_pkthdr.len -= GIF_HDR_LEN6;
381 * Now pull back the af that we
382 * stashed in the csum_data.
384 af = m->m_pkthdr.csum_data;
389 BPF_MTAP2(ifp, &af, sizeof(af), m);
392 /* Done by IFQ_HANDOFF */
393 /* ifp->if_obytes += m->m_pkthdr.len;*/
394 /* override to IPPROTO_ETHERIP for bridged traffic */
396 M_SETFIB(m, sc->gif_fibnum);
397 /* inner AF-specific encapsulation */
398 /* XXX should we check if our outer source is legal? */
399 /* dispatch to output logic based on outer AF */
400 switch (sc->gif_psrc->sa_family) {
403 error = in_gif_output(ifp, af, m);
408 error = in6_gif_output(ifp, af, m);
419 ifp->if_drv_flags &= ~IFF_DRV_OACTIVE;
425 gif_output(struct ifnet *ifp, struct mbuf *m, const struct sockaddr *dst,
428 struct gif_softc *sc = ifp->if_softc;
434 error = mac_ifnet_check_transmit(ifp, m);
442 * gif may cause infinite recursion calls when misconfigured.
443 * We'll prevent this by detecting loops.
445 * High nesting level may cause stack exhaustion.
446 * We'll prevent this by introducing upper limit.
449 mtag = m_tag_locate(m, MTAG_GIF, MTAG_GIF_CALLED, NULL);
450 while (mtag != NULL) {
451 if (*(struct ifnet **)(mtag + 1) == ifp) {
453 "gif_output: loop detected on %s\n",
454 (*(struct ifnet **)(mtag + 1))->if_xname);
456 error = EIO; /* is there better errno? */
459 mtag = m_tag_locate(m, MTAG_GIF, MTAG_GIF_CALLED, mtag);
462 if (gif_called > V_max_gif_nesting) {
464 "gif_output: recursively called too many times(%d)\n",
467 error = EIO; /* is there better errno? */
470 mtag = m_tag_alloc(MTAG_GIF, MTAG_GIF_CALLED, sizeof(struct ifnet *),
477 *(struct ifnet **)(mtag + 1) = ifp;
478 m_tag_prepend(m, mtag);
480 m->m_flags &= ~(M_BCAST|M_MCAST);
481 /* BPF writes need to be handled specially. */
482 if (dst->sa_family == AF_UNSPEC)
483 bcopy(dst->sa_data, &af, sizeof(af));
487 * Now save the af in the inbound pkt csum
488 * data, this is a cheat since we are using
489 * the inbound csum_data field to carry the
490 * af over to the gif_start() routine, avoiding
491 * using yet another mtag.
493 m->m_pkthdr.csum_data = af;
494 if (!(ifp->if_flags & IFF_UP) ||
495 sc->gif_psrc == NULL || sc->gif_pdst == NULL) {
502 * Make altq aware of the bytes we will add
503 * when we actually send it.
506 if (sc->gif_psrc->sa_family == AF_INET)
507 m->m_pkthdr.len += GIF_HDR_LEN;
510 if (sc->gif_psrc->sa_family == AF_INET6)
511 m->m_pkthdr.len += GIF_HDR_LEN6;
515 * Queue message on interface, update output statistics if
516 * successful, and start output if interface not yet active.
518 IFQ_HANDOFF(ifp, m, error);
526 gif_input(m, af, ifp)
532 struct gif_softc *sc;
533 struct etherip_header *eip;
534 struct ether_header *eh;
535 struct ifnet *oldifp;
543 m->m_pkthdr.rcvif = ifp;
546 mac_ifnet_create_mbuf(ifp, m);
549 if (bpf_peers_present(ifp->if_bpf)) {
551 bpf_mtap2(ifp->if_bpf, &af1, sizeof(af1), m);
554 if (ng_gif_input_p != NULL) {
555 (*ng_gif_input_p)(ifp, &m, af);
561 * Put the packet to the network layer input queue according to the
562 * specified address family.
563 * Note: older versions of gif_input directly called network layer
564 * input functions, e.g. ip6_input, here. We changed the policy to
565 * prevent too many recursive calls of such input functions, which
566 * might cause kernel panic. But the change may introduce another
567 * problem; if the input queue is full, packets are discarded.
568 * The kernel stack overflow really happened, and we believed
569 * queue-full rarely occurs, so we changed the policy.
583 n = sizeof(struct etherip_header) + sizeof(struct ether_header);
592 eip = mtod(m, struct etherip_header *);
594 * GIF_ACCEPT_REVETHIP (enabled by default) intentionally
595 * accepts an EtherIP packet with revered version field in
596 * the header. This is a knob for backward compatibility
597 * with FreeBSD 7.2R or prior.
599 if (sc->gif_options & GIF_ACCEPT_REVETHIP) {
600 if (eip->eip_resvl != ETHERIP_VERSION
601 && eip->eip_ver != ETHERIP_VERSION) {
602 /* discard unknown versions */
607 if (eip->eip_ver != ETHERIP_VERSION) {
608 /* discard unknown versions */
613 m_adj(m, sizeof(struct etherip_header));
615 m->m_flags &= ~(M_BCAST|M_MCAST);
616 m->m_pkthdr.rcvif = ifp;
618 if (ifp->if_bridge) {
620 eh = mtod(m, struct ether_header *);
621 if (ETHER_IS_MULTICAST(eh->ether_dhost)) {
622 if (ETHER_IS_BROADCAST(eh->ether_dhost))
623 m->m_flags |= M_BCAST;
625 m->m_flags |= M_MCAST;
628 BRIDGE_INPUT(ifp, m);
630 if (m != NULL && ifp != oldifp) {
632 * The bridge gave us back itself or one of the
633 * members for which the frame is addressed.
644 if (ng_gif_input_orphan_p != NULL)
645 (*ng_gif_input_orphan_p)(ifp, m, af);
652 ifp->if_ibytes += m->m_pkthdr.len;
653 M_SETFIB(m, ifp->if_fib);
654 netisr_dispatch(isr, m);
657 /* XXX how should we handle IPv6 scope on SIOC[GS]IFPHYADDR? */
659 gif_ioctl(ifp, cmd, data)
664 struct gif_softc *sc = ifp->if_softc;
665 struct ifreq *ifr = (struct ifreq*)data;
668 struct sockaddr *dst, *src;
669 #ifdef SIOCSIFMTU /* xxx */
675 ifp->if_flags |= IFF_UP;
685 #ifdef SIOCSIFMTU /* xxx */
691 if (mtu < GIF_MTU_MIN || mtu > GIF_MTU_MAX)
695 #endif /* SIOCSIFMTU */
701 case SIOCSIFPHYADDR_IN6:
703 case SIOCSLIFPHYADDR:
707 src = (struct sockaddr *)
708 &(((struct in_aliasreq *)data)->ifra_addr);
709 dst = (struct sockaddr *)
710 &(((struct in_aliasreq *)data)->ifra_dstaddr);
714 case SIOCSIFPHYADDR_IN6:
715 src = (struct sockaddr *)
716 &(((struct in6_aliasreq *)data)->ifra_addr);
717 dst = (struct sockaddr *)
718 &(((struct in6_aliasreq *)data)->ifra_dstaddr);
721 case SIOCSLIFPHYADDR:
722 src = (struct sockaddr *)
723 &(((struct if_laddrreq *)data)->addr);
724 dst = (struct sockaddr *)
725 &(((struct if_laddrreq *)data)->dstaddr);
731 /* sa_family must be equal */
732 if (src->sa_family != dst->sa_family)
735 /* validate sa_len */
736 switch (src->sa_family) {
739 if (src->sa_len != sizeof(struct sockaddr_in))
745 if (src->sa_len != sizeof(struct sockaddr_in6))
752 switch (dst->sa_family) {
755 if (dst->sa_len != sizeof(struct sockaddr_in))
761 if (dst->sa_len != sizeof(struct sockaddr_in6))
769 /* check sa_family looks sane for the cmd */
772 if (src->sa_family == AF_INET)
776 case SIOCSIFPHYADDR_IN6:
777 if (src->sa_family == AF_INET6)
781 case SIOCSLIFPHYADDR:
782 /* checks done in the above */
786 error = gif_set_tunnel(GIF2IFP(sc), src, dst);
789 #ifdef SIOCDIFPHYADDR
791 gif_delete_tunnel(GIF2IFP(sc));
795 case SIOCGIFPSRCADDR:
797 case SIOCGIFPSRCADDR_IN6:
799 if (sc->gif_psrc == NULL) {
800 error = EADDRNOTAVAIL;
806 case SIOCGIFPSRCADDR:
807 dst = &ifr->ifr_addr;
808 size = sizeof(ifr->ifr_addr);
812 case SIOCGIFPSRCADDR_IN6:
813 dst = (struct sockaddr *)
814 &(((struct in6_ifreq *)data)->ifr_addr);
815 size = sizeof(((struct in6_ifreq *)data)->ifr_addr);
819 error = EADDRNOTAVAIL;
822 if (src->sa_len > size)
824 bcopy((caddr_t)src, (caddr_t)dst, src->sa_len);
826 if (dst->sa_family == AF_INET6) {
827 error = sa6_recoverscope((struct sockaddr_in6 *)dst);
834 case SIOCGIFPDSTADDR:
836 case SIOCGIFPDSTADDR_IN6:
838 if (sc->gif_pdst == NULL) {
839 error = EADDRNOTAVAIL;
845 case SIOCGIFPDSTADDR:
846 dst = &ifr->ifr_addr;
847 size = sizeof(ifr->ifr_addr);
851 case SIOCGIFPDSTADDR_IN6:
852 dst = (struct sockaddr *)
853 &(((struct in6_ifreq *)data)->ifr_addr);
854 size = sizeof(((struct in6_ifreq *)data)->ifr_addr);
858 error = EADDRNOTAVAIL;
861 if (src->sa_len > size)
863 error = prison_if(curthread->td_ucred, src);
866 error = prison_if(curthread->td_ucred, dst);
869 bcopy((caddr_t)src, (caddr_t)dst, src->sa_len);
871 if (dst->sa_family == AF_INET6) {
872 error = sa6_recoverscope((struct sockaddr_in6 *)dst);
879 case SIOCGLIFPHYADDR:
880 if (sc->gif_psrc == NULL || sc->gif_pdst == NULL) {
881 error = EADDRNOTAVAIL;
887 dst = (struct sockaddr *)
888 &(((struct if_laddrreq *)data)->addr);
889 size = sizeof(((struct if_laddrreq *)data)->addr);
890 if (src->sa_len > size)
892 bcopy((caddr_t)src, (caddr_t)dst, src->sa_len);
896 dst = (struct sockaddr *)
897 &(((struct if_laddrreq *)data)->dstaddr);
898 size = sizeof(((struct if_laddrreq *)data)->dstaddr);
899 if (src->sa_len > size)
901 bcopy((caddr_t)src, (caddr_t)dst, src->sa_len);
905 /* if_ioctl() takes care of it */
909 options = sc->gif_options;
910 error = copyout(&options, ifr->ifr_data,
915 if ((error = priv_check(curthread, PRIV_NET_GIF)) != 0)
917 error = copyin(ifr->ifr_data, &options, sizeof(options));
920 if (options & ~GIF_OPTMASK)
923 sc->gif_options = options;
935 * XXXRW: There's a general event-ordering issue here: the code to check
936 * if a given tunnel is already present happens before we perform a
937 * potentially blocking setup of the tunnel. This code needs to be
938 * re-ordered so that the check and replacement can be atomic using
942 gif_set_tunnel(ifp, src, dst)
944 struct sockaddr *src;
945 struct sockaddr *dst;
947 struct gif_softc *sc = ifp->if_softc;
948 struct gif_softc *sc2;
949 struct sockaddr *osrc, *odst, *sa;
953 LIST_FOREACH(sc2, &V_gif_softc_list, gif_list) {
956 if (!sc2->gif_pdst || !sc2->gif_psrc)
958 if (sc2->gif_pdst->sa_family != dst->sa_family ||
959 sc2->gif_pdst->sa_len != dst->sa_len ||
960 sc2->gif_psrc->sa_family != src->sa_family ||
961 sc2->gif_psrc->sa_len != src->sa_len)
965 * Disallow parallel tunnels unless instructed
968 if (!V_parallel_tunnels &&
969 bcmp(sc2->gif_pdst, dst, dst->sa_len) == 0 &&
970 bcmp(sc2->gif_psrc, src, src->sa_len) == 0) {
971 error = EADDRNOTAVAIL;
972 mtx_unlock(&gif_mtx);
976 /* XXX both end must be valid? (I mean, not 0.0.0.0) */
978 mtx_unlock(&gif_mtx);
980 /* XXX we can detach from both, but be polite just in case */
982 switch (sc->gif_psrc->sa_family) {
985 (void)in_gif_detach(sc);
990 (void)in6_gif_detach(sc);
996 sa = (struct sockaddr *)malloc(src->sa_len, M_IFADDR, M_WAITOK);
997 bcopy((caddr_t)src, (caddr_t)sa, src->sa_len);
1000 odst = sc->gif_pdst;
1001 sa = (struct sockaddr *)malloc(dst->sa_len, M_IFADDR, M_WAITOK);
1002 bcopy((caddr_t)dst, (caddr_t)sa, dst->sa_len);
1005 switch (sc->gif_psrc->sa_family) {
1008 error = in_gif_attach(sc);
1014 * Check validity of the scope zone ID of the addresses, and
1015 * convert it into the kernel internal form if necessary.
1017 error = sa6_embedscope((struct sockaddr_in6 *)sc->gif_psrc, 0);
1020 error = sa6_embedscope((struct sockaddr_in6 *)sc->gif_pdst, 0);
1023 error = in6_gif_attach(sc);
1029 free((caddr_t)sc->gif_psrc, M_IFADDR);
1030 free((caddr_t)sc->gif_pdst, M_IFADDR);
1031 sc->gif_psrc = osrc;
1032 sc->gif_pdst = odst;
1037 free((caddr_t)osrc, M_IFADDR);
1039 free((caddr_t)odst, M_IFADDR);
1042 if (sc->gif_psrc && sc->gif_pdst)
1043 ifp->if_drv_flags |= IFF_DRV_RUNNING;
1045 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
1051 gif_delete_tunnel(ifp)
1054 struct gif_softc *sc = ifp->if_softc;
1057 free((caddr_t)sc->gif_psrc, M_IFADDR);
1058 sc->gif_psrc = NULL;
1061 free((caddr_t)sc->gif_pdst, M_IFADDR);
1062 sc->gif_pdst = NULL;
1064 /* it is safe to detach from both */
1066 (void)in_gif_detach(sc);
1069 (void)in6_gif_detach(sc);
1071 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;