1 /* $NetBSD: if_gre.c,v 1.49 2003/12/11 00:22:29 itojun Exp $ */
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Heiko W.Rupp <hwr@pilhuhn.de>
11 * IPv6-over-GRE contributed by Gert Doering <gert@greenie.muc.de>
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
36 * Encapsulate L3 protocols into IP
37 * See RFC 2784 (successor of RFC 1701 and 1702) for more details.
38 * If_gre is compatible with Cisco GRE tunnels, so you can
39 * have a NetBSD box as the other end of a tunnel interface of a Cisco
40 * router. See gre(4) for more details.
41 * Also supported: IP in IP encaps (proto 55) as of RFC 2004
44 #include "opt_atalk.h"
46 #include "opt_inet6.h"
48 #include <sys/param.h>
50 #include <sys/kernel.h>
51 #include <sys/malloc.h>
52 #include <sys/module.h>
56 #include <sys/protosw.h>
57 #include <sys/socket.h>
58 #include <sys/sockio.h>
59 #include <sys/sysctl.h>
60 #include <sys/systm.h>
62 #include <net/ethernet.h>
64 #include <net/if_clone.h>
65 #include <net/if_types.h>
66 #include <net/route.h>
70 #include <netinet/in.h>
71 #include <netinet/in_systm.h>
72 #include <netinet/in_var.h>
73 #include <netinet/ip.h>
74 #include <netinet/ip_gre.h>
75 #include <netinet/ip_var.h>
76 #include <netinet/ip_encap.h>
78 #error "Huh? if_gre without inet?"
83 #include <net/if_gre.h>
86 * It is not easy to calculate the right value for a GRE MTU.
87 * We leave this task to the admin and use the same default that
95 * gre_mtx protects all global variables in if_gre.c.
96 * XXX: gre_softc data not protected yet.
99 static MALLOC_DEFINE(M_GRE, GRENAME, "Generic Routing Encapsulation");
101 struct gre_softc_head gre_softc_list;
103 static int gre_clone_create(struct if_clone *, int, caddr_t);
104 static void gre_clone_destroy(struct ifnet *);
105 static int gre_ioctl(struct ifnet *, u_long, caddr_t);
106 static int gre_output(struct ifnet *, struct mbuf *, struct sockaddr *,
109 IFC_SIMPLE_DECLARE(gre, 0);
111 static int gre_compute_route(struct gre_softc *sc);
113 static void greattach(void);
116 extern struct domain inetdomain;
117 static const struct protosw in_gre_protosw = {
119 .pr_domain = &inetdomain,
120 .pr_protocol = IPPROTO_GRE,
121 .pr_flags = PR_ATOMIC|PR_ADDR,
122 .pr_input = gre_input,
123 .pr_output = (pr_output_t *)rip_output,
124 .pr_ctlinput = rip_ctlinput,
125 .pr_ctloutput = rip_ctloutput,
126 .pr_usrreqs = &rip_usrreqs
128 static const struct protosw in_mobile_protosw = {
130 .pr_domain = &inetdomain,
131 .pr_protocol = IPPROTO_MOBILE,
132 .pr_flags = PR_ATOMIC|PR_ADDR,
133 .pr_input = gre_mobile_input,
134 .pr_output = (pr_output_t *)rip_output,
135 .pr_ctlinput = rip_ctlinput,
136 .pr_ctloutput = rip_ctloutput,
137 .pr_usrreqs = &rip_usrreqs
141 SYSCTL_DECL(_net_link);
142 SYSCTL_NODE(_net_link, IFT_TUNNEL, gre, CTLFLAG_RW, 0,
143 "Generic Routing Encapsulation");
146 * This macro controls the default upper limitation on nesting of gre tunnels.
147 * Since, setting a large value to this macro with a careless configuration
148 * may introduce system crash, we don't allow any nestings by default.
149 * If you need to configure nested gre tunnels, you can define this macro
150 * in your kernel configuration file. However, if you do so, please be
151 * careful to configure the tunnels so that it won't make a loop.
153 #define MAX_GRE_NEST 1
155 static int max_gre_nesting = MAX_GRE_NEST;
156 SYSCTL_INT(_net_link_gre, OID_AUTO, max_nesting, CTLFLAG_RW,
157 &max_gre_nesting, 0, "Max nested tunnels");
164 mtx_init(&gre_mtx, "gre_mtx", NULL, MTX_DEF);
165 LIST_INIT(&gre_softc_list);
166 if_clone_attach(&gre_cloner);
170 gre_clone_create(ifc, unit, params)
171 struct if_clone *ifc;
175 struct gre_softc *sc;
177 sc = malloc(sizeof(struct gre_softc), M_GRE, M_WAITOK | M_ZERO);
179 GRE2IFP(sc) = if_alloc(IFT_TUNNEL);
180 if (GRE2IFP(sc) == NULL) {
185 GRE2IFP(sc)->if_softc = sc;
186 if_initname(GRE2IFP(sc), ifc->ifc_name, unit);
188 GRE2IFP(sc)->if_snd.ifq_maxlen = ifqmaxlen;
189 GRE2IFP(sc)->if_addrlen = 0;
190 GRE2IFP(sc)->if_hdrlen = 24; /* IP + GRE */
191 GRE2IFP(sc)->if_mtu = GREMTU;
192 GRE2IFP(sc)->if_flags = IFF_POINTOPOINT|IFF_MULTICAST;
193 GRE2IFP(sc)->if_output = gre_output;
194 GRE2IFP(sc)->if_ioctl = gre_ioctl;
195 sc->g_dst.s_addr = sc->g_src.s_addr = INADDR_ANY;
196 sc->g_proto = IPPROTO_GRE;
197 GRE2IFP(sc)->if_flags |= IFF_LINK0;
200 sc->gre_fibnum = curthread->td_proc->p_fibnum;
201 sc->wccp_ver = WCCP_V1;
203 if_attach(GRE2IFP(sc));
204 bpfattach(GRE2IFP(sc), DLT_NULL, sizeof(u_int32_t));
206 LIST_INSERT_HEAD(&gre_softc_list, sc, sc_list);
207 mtx_unlock(&gre_mtx);
212 gre_clone_destroy(ifp)
215 struct gre_softc *sc = ifp->if_softc;
218 LIST_REMOVE(sc, sc_list);
219 mtx_unlock(&gre_mtx);
222 if (sc->encap != NULL)
223 encap_detach(sc->encap);
232 * The output routine. Takes a packet and encapsulates it in the protocol
233 * given by sc->g_proto. See also RFC 1701 and RFC 2004
236 gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
240 struct gre_softc *sc = ifp->if_softc;
243 u_short gre_ip_id = 0;
244 uint8_t gre_ip_tos = 0;
246 struct mobile_h mob_h;
251 * gre may cause infinite recursion calls when misconfigured.
252 * We'll prevent this by introducing upper limit.
254 if (++(sc->called) > max_gre_nesting) {
255 printf("%s: gre_output: recursively called too many "
256 "times(%d)\n", if_name(GRE2IFP(sc)), sc->called);
258 error = EIO; /* is there better errno? */
262 if (!((ifp->if_flags & IFF_UP) &&
263 (ifp->if_drv_flags & IFF_DRV_RUNNING)) ||
264 sc->g_src.s_addr == INADDR_ANY || sc->g_dst.s_addr == INADDR_ANY) {
273 /* BPF writes need to be handled specially. */
274 if (dst->sa_family == AF_UNSPEC) {
275 bcopy(dst->sa_data, &af, sizeof(af));
279 if (bpf_peers_present(ifp->if_bpf)) {
281 bpf_mtap2(ifp->if_bpf, &af, sizeof(af), m);
284 m->m_flags &= ~(M_BCAST|M_MCAST);
286 if (sc->g_proto == IPPROTO_MOBILE) {
287 if (dst->sa_family == AF_INET) {
291 ip = mtod(m, struct ip *);
294 * RFC2004 specifies that fragmented diagrams shouldn't
297 if (ip->ip_off & (IP_MF | IP_OFFMASK)) {
298 _IF_DROP(&ifp->if_snd);
300 error = EINVAL; /* is there better errno? */
303 memset(&mob_h, 0, MOB_H_SIZ_L);
304 mob_h.proto = (ip->ip_p) << 8;
305 mob_h.odst = ip->ip_dst.s_addr;
306 ip->ip_dst.s_addr = sc->g_dst.s_addr;
309 * If the packet comes from our host, we only change
310 * the destination address in the IP header.
311 * Else we also need to save and change the source
313 if (in_hosteq(ip->ip_src, sc->g_src)) {
316 mob_h.proto |= MOB_H_SBIT;
317 mob_h.osrc = ip->ip_src.s_addr;
318 ip->ip_src.s_addr = sc->g_src.s_addr;
321 mob_h.proto = htons(mob_h.proto);
322 mob_h.hcrc = gre_in_cksum((u_int16_t *)&mob_h, msiz);
324 if ((m->m_data - msiz) < m->m_pktdat) {
326 MGETHDR(m0, M_DONTWAIT, MT_DATA);
328 _IF_DROP(&ifp->if_snd);
334 m->m_data += sizeof(struct ip);
335 m->m_len -= sizeof(struct ip);
336 m0->m_pkthdr.len = m->m_pkthdr.len + msiz;
337 m0->m_len = msiz + sizeof(struct ip);
338 m0->m_data += max_linkhdr;
339 memcpy(mtod(m0, caddr_t), (caddr_t)ip,
342 } else { /* we have some space left in the old one */
345 m->m_pkthdr.len += msiz;
346 bcopy(ip, mtod(m, caddr_t),
349 ip = mtod(m, struct ip *);
350 memcpy((caddr_t)(ip + 1), &mob_h, (unsigned)msiz);
351 ip->ip_len = ntohs(ip->ip_len) + msiz;
352 } else { /* AF_INET */
353 _IF_DROP(&ifp->if_snd);
358 } else if (sc->g_proto == IPPROTO_GRE) {
359 switch (dst->sa_family) {
361 ip = mtod(m, struct ip *);
362 gre_ip_tos = ip->ip_tos;
363 gre_ip_id = ip->ip_id;
364 if (sc->wccp_ver == WCCP_V2) {
365 extra = sizeof(uint32_t);
366 etype = WCCP_PROTOCOL_TYPE;
368 etype = ETHERTYPE_IP;
373 gre_ip_id = ip_newid();
374 etype = ETHERTYPE_IPV6;
379 etype = ETHERTYPE_ATALK;
383 _IF_DROP(&ifp->if_snd);
385 error = EAFNOSUPPORT;
389 /* Reserve space for GRE header + optional GRE key */
390 int hdrlen = sizeof(struct greip) + extra;
392 hdrlen += sizeof(uint32_t);
393 M_PREPEND(m, hdrlen, M_DONTWAIT);
395 _IF_DROP(&ifp->if_snd);
401 if (m == NULL) { /* mbuf allocation failed */
402 _IF_DROP(&ifp->if_snd);
407 M_SETFIB(m, sc->gre_fibnum); /* The envelope may use a different FIB */
409 gh = mtod(m, struct greip *);
410 if (sc->g_proto == IPPROTO_GRE) {
411 uint32_t *options = gh->gi_options;
413 memset((void *)gh, 0, sizeof(struct greip) + extra);
414 gh->gi_ptype = htons(etype);
420 gh->gi_flags |= htons(GRE_KP);
421 *(options++) = htonl(sc->key);
425 gh->gi_pr = sc->g_proto;
426 if (sc->g_proto != IPPROTO_MOBILE) {
427 gh->gi_src = sc->g_src;
428 gh->gi_dst = sc->g_dst;
429 ((struct ip*)gh)->ip_v = IPPROTO_IPV4;
430 ((struct ip*)gh)->ip_hl = (sizeof(struct ip)) >> 2;
431 ((struct ip*)gh)->ip_ttl = GRE_TTL;
432 ((struct ip*)gh)->ip_tos = gre_ip_tos;
433 ((struct ip*)gh)->ip_id = gre_ip_id;
434 gh->gi_len = m->m_pkthdr.len;
438 ifp->if_obytes += m->m_pkthdr.len;
440 * Send it off and with IP_FORWARD flag to prevent it from
441 * overwriting the ip_id again. ip_id is already set to the
442 * ip_id of the encapsulated packet.
444 error = ip_output(m, NULL, &sc->route, IP_FORWARDING,
445 (struct ip_moptions *)NULL, (struct inpcb *)NULL);
454 gre_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
456 struct ifreq *ifr = (struct ifreq *)data;
457 struct if_laddrreq *lifr = (struct if_laddrreq *)data;
458 struct in_aliasreq *aifr = (struct in_aliasreq *)data;
459 struct gre_softc *sc = ifp->if_softc;
461 struct sockaddr_in si;
462 struct sockaddr *sa = NULL;
464 struct sockaddr_in sp, sm, dp, dm;
473 ifp->if_flags |= IFF_UP;
479 * XXXRW: Isn't this priv_check() redundant to the ifnet
482 if ((error = priv_check(curthread, PRIV_NET_SETIFFLAGS)) != 0)
484 if ((ifr->ifr_flags & IFF_LINK0) != 0)
485 sc->g_proto = IPPROTO_GRE;
487 sc->g_proto = IPPROTO_MOBILE;
488 if ((ifr->ifr_flags & IFF_LINK2) != 0)
489 sc->wccp_ver = WCCP_V2;
491 sc->wccp_ver = WCCP_V1;
495 * XXXRW: Isn't this priv_check() redundant to the ifnet
498 if ((error = priv_check(curthread, PRIV_NET_SETIFMTU)) != 0)
500 if (ifr->ifr_mtu < 576) {
504 ifp->if_mtu = ifr->ifr_mtu;
507 ifr->ifr_mtu = GRE2IFP(sc)->if_mtu;
511 * XXXRW: Isn't this priv_checkr() redundant to the ifnet
514 if ((error = priv_check(curthread, PRIV_NET_ADDMULTI)) != 0)
517 error = EAFNOSUPPORT;
520 switch (ifr->ifr_addr.sa_family) {
530 error = EAFNOSUPPORT;
536 * XXXRW: Isn't this priv_check() redundant to the ifnet
539 if ((error = priv_check(curthread, PRIV_NET_DELIFGROUP)) != 0)
542 error = EAFNOSUPPORT;
545 switch (ifr->ifr_addr.sa_family) {
555 error = EAFNOSUPPORT;
561 * XXXRW: Isn't this priv_check() redundant to the ifnet
564 if ((error = priv_check(curthread, PRIV_NET_GRE)) != 0)
566 sc->g_proto = ifr->ifr_flags;
567 switch (sc->g_proto) {
569 ifp->if_flags |= IFF_LINK0;
572 ifp->if_flags &= ~IFF_LINK0;
575 error = EPROTONOSUPPORT;
580 ifr->ifr_flags = sc->g_proto;
584 error = priv_check(curthread, PRIV_NET_GRE);
588 * set tunnel endpoints, compute a less specific route
589 * to the remote end and mark if as up
592 if (cmd == GRESADDRS)
593 sc->g_src = (satosin(sa))->sin_addr;
594 if (cmd == GRESADDRD)
595 sc->g_dst = (satosin(sa))->sin_addr;
598 if (sc->encap != NULL) {
599 encap_detach(sc->encap);
603 if ((sc->g_src.s_addr != INADDR_ANY) &&
604 (sc->g_dst.s_addr != INADDR_ANY)) {
605 bzero(&sp, sizeof(sp));
606 bzero(&sm, sizeof(sm));
607 bzero(&dp, sizeof(dp));
608 bzero(&dm, sizeof(dm));
609 sp.sin_len = sm.sin_len = dp.sin_len = dm.sin_len =
610 sizeof(struct sockaddr_in);
611 sp.sin_family = sm.sin_family = dp.sin_family =
612 dm.sin_family = AF_INET;
613 sp.sin_addr = sc->g_src;
614 dp.sin_addr = sc->g_dst;
615 sm.sin_addr.s_addr = dm.sin_addr.s_addr =
618 sc->encap = encap_attach(AF_INET, sc->g_proto,
619 sintosa(&sp), sintosa(&sm), sintosa(&dp),
620 sintosa(&dm), (sc->g_proto == IPPROTO_GRE) ?
621 &in_gre_protosw : &in_mobile_protosw, sc);
622 if (sc->encap == NULL)
623 printf("%s: unable to attach encap\n",
624 if_name(GRE2IFP(sc)));
626 if (sc->route.ro_rt != 0) /* free old route */
627 RTFREE(sc->route.ro_rt);
628 if (gre_compute_route(sc) == 0)
629 ifp->if_drv_flags |= IFF_DRV_RUNNING;
631 ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
635 memset(&si, 0, sizeof(si));
636 si.sin_family = AF_INET;
637 si.sin_len = sizeof(struct sockaddr_in);
638 si.sin_addr.s_addr = sc->g_src.s_addr;
640 error = prison_if(curthread->td_ucred, sa);
646 memset(&si, 0, sizeof(si));
647 si.sin_family = AF_INET;
648 si.sin_len = sizeof(struct sockaddr_in);
649 si.sin_addr.s_addr = sc->g_dst.s_addr;
651 error = prison_if(curthread->td_ucred, sa);
658 * XXXRW: Isn't this priv_check() redundant to the ifnet
661 if ((error = priv_check(curthread, PRIV_NET_SETIFPHYS)) != 0)
663 if (aifr->ifra_addr.sin_family != AF_INET ||
664 aifr->ifra_dstaddr.sin_family != AF_INET) {
665 error = EAFNOSUPPORT;
668 if (aifr->ifra_addr.sin_len != sizeof(si) ||
669 aifr->ifra_dstaddr.sin_len != sizeof(si)) {
673 sc->g_src = aifr->ifra_addr.sin_addr;
674 sc->g_dst = aifr->ifra_dstaddr.sin_addr;
676 case SIOCSLIFPHYADDR:
678 * XXXRW: Isn't this priv_check() redundant to the ifnet
681 if ((error = priv_check(curthread, PRIV_NET_SETIFPHYS)) != 0)
683 if (lifr->addr.ss_family != AF_INET ||
684 lifr->dstaddr.ss_family != AF_INET) {
685 error = EAFNOSUPPORT;
688 if (lifr->addr.ss_len != sizeof(si) ||
689 lifr->dstaddr.ss_len != sizeof(si)) {
693 sc->g_src = (satosin(&lifr->addr))->sin_addr;
695 (satosin(&lifr->dstaddr))->sin_addr;
699 * XXXRW: Isn't this priv_check() redundant to the ifnet
702 if ((error = priv_check(curthread, PRIV_NET_SETIFPHYS)) != 0)
704 sc->g_src.s_addr = INADDR_ANY;
705 sc->g_dst.s_addr = INADDR_ANY;
707 case SIOCGLIFPHYADDR:
708 if (sc->g_src.s_addr == INADDR_ANY ||
709 sc->g_dst.s_addr == INADDR_ANY) {
710 error = EADDRNOTAVAIL;
713 memset(&si, 0, sizeof(si));
714 si.sin_family = AF_INET;
715 si.sin_len = sizeof(struct sockaddr_in);
716 si.sin_addr.s_addr = sc->g_src.s_addr;
717 error = prison_if(curthread->td_ucred, (struct sockaddr *)&si);
720 memcpy(&lifr->addr, &si, sizeof(si));
721 si.sin_addr.s_addr = sc->g_dst.s_addr;
722 error = prison_if(curthread->td_ucred, (struct sockaddr *)&si);
725 memcpy(&lifr->dstaddr, &si, sizeof(si));
727 case SIOCGIFPSRCADDR:
729 case SIOCGIFPSRCADDR_IN6:
731 if (sc->g_src.s_addr == INADDR_ANY) {
732 error = EADDRNOTAVAIL;
735 memset(&si, 0, sizeof(si));
736 si.sin_family = AF_INET;
737 si.sin_len = sizeof(struct sockaddr_in);
738 si.sin_addr.s_addr = sc->g_src.s_addr;
739 error = prison_if(curthread->td_ucred, (struct sockaddr *)&si);
742 bcopy(&si, &ifr->ifr_addr, sizeof(ifr->ifr_addr));
744 case SIOCGIFPDSTADDR:
746 case SIOCGIFPDSTADDR_IN6:
748 if (sc->g_dst.s_addr == INADDR_ANY) {
749 error = EADDRNOTAVAIL;
752 memset(&si, 0, sizeof(si));
753 si.sin_family = AF_INET;
754 si.sin_len = sizeof(struct sockaddr_in);
755 si.sin_addr.s_addr = sc->g_dst.s_addr;
756 error = prison_if(curthread->td_ucred, (struct sockaddr *)&si);
759 bcopy(&si, &ifr->ifr_addr, sizeof(ifr->ifr_addr));
762 error = priv_check(curthread, PRIV_NET_GRE);
765 error = copyin(ifr->ifr_data, &key, sizeof(key));
768 /* adjust MTU for option header */
769 if (key == 0 && sc->key != 0) /* clear */
771 else if (key != 0 && sc->key == 0) /* set */
774 if (ifp->if_mtu + adj < 576) {
782 error = copyout(&sc->key, ifr->ifr_data, sizeof(sc->key));
795 * computes a route to our destination that is not the one
796 * which would be taken by ip_output(), as this one will loop back to
797 * us. If the interface is p2p as a--->b, then a routing entry exists
798 * If we now send a packet to b (e.g. ping b), this will come down here
799 * gets src=a, dst=b tacked on and would from ip_output() sent back to
801 * Goal here is to compute a route to b that is less specific than
802 * a-->b. We know that this one exists as in normal operation we have
803 * at least a default route which matches.
806 gre_compute_route(struct gre_softc *sc)
812 memset(ro, 0, sizeof(struct route));
813 ((struct sockaddr_in *)&ro->ro_dst)->sin_addr = sc->g_dst;
814 ro->ro_dst.sa_family = AF_INET;
815 ro->ro_dst.sa_len = sizeof(ro->ro_dst);
818 * toggle last bit, so our interface is not found, but a less
819 * specific route. I'd rather like to specify a shorter mask,
820 * but this is not possible. Should work though. XXX
821 * XXX MRT Use a different FIB for the tunnel to solve this problem.
823 if ((GRE2IFP(sc)->if_flags & IFF_LINK1) == 0) {
824 ((struct sockaddr_in *)&ro->ro_dst)->sin_addr.s_addr ^=
829 printf("%s: searching for a route to %s", if_name(GRE2IFP(sc)),
830 inet_ntoa(((struct sockaddr_in *)&ro->ro_dst)->sin_addr));
833 rtalloc_fib(ro, sc->gre_fibnum);
836 * check if this returned a route at all and this route is no
837 * recursion to ourself
839 if (ro->ro_rt == NULL || ro->ro_rt->rt_ifp->if_softc == sc) {
841 if (ro->ro_rt == NULL)
842 printf(" - no route found!\n");
844 printf(" - route loops back to ourself!\n");
846 return EADDRNOTAVAIL;
850 * now change it back - else ip_output will just drop
851 * the route and search one to this interface ...
853 if ((GRE2IFP(sc)->if_flags & IFF_LINK1) == 0)
854 ((struct sockaddr_in *)&ro->ro_dst)->sin_addr = sc->g_dst;
857 printf(", choosing %s with gateway %s", if_name(ro->ro_rt->rt_ifp),
858 inet_ntoa(((struct sockaddr_in *)(ro->ro_rt->rt_gateway))->sin_addr));
866 * do a checksum of a buffer - much like in_cksum, which operates on
870 gre_in_cksum(u_int16_t *p, u_int len)
873 int nwords = len >> 1;
875 while (nwords-- != 0)
883 u.c[0] = *(u_char *)p;
888 /* end-around-carry */
889 sum = (sum >> 16) + (sum & 0xffff);
895 gremodevent(module_t mod, int type, void *data)
903 if_clone_detach(&gre_cloner);
904 mtx_destroy(&gre_mtx);
912 static moduledata_t gre_mod = {
918 DECLARE_MODULE(if_gre, gre_mod, SI_SUB_PSEUDO, SI_ORDER_ANY);
919 MODULE_VERSION(if_gre, 1);