2005-12-11 15:16:03 +03:00
|
|
|
/* $NetBSD: ip_gre.c,v 1.36 2005/12/11 12:24:57 christos Exp $ */
|
1998-09-14 00:27:47 +04:00
|
|
|
|
|
|
|
/*
|
1998-10-08 03:33:02 +04:00
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
1998-09-14 00:27:47 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Heiko W.Rupp <hwr@pilhuhn.de>
|
|
|
|
*
|
2005-03-30 20:34:54 +04:00
|
|
|
* IPv6-over-GRE contributed by Gert Doering <gert@greenie.muc.de>
|
|
|
|
*
|
1998-09-14 00:27:47 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
2002-06-09 20:33:36 +04:00
|
|
|
*
|
1998-09-14 00:27:47 +04:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
1998-09-30 09:59:27 +04:00
|
|
|
* deencapsulate tunneled packets and send them on
|
1998-10-08 03:33:02 +04:00
|
|
|
* output half is in net/if_gre.[ch]
|
1999-01-12 00:32:13 +03:00
|
|
|
* This currently handles IPPROTO_GRE, IPPROTO_MOBILE
|
1998-09-14 00:27:47 +04:00
|
|
|
*/
|
|
|
|
|
2001-11-13 03:32:34 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-12-11 15:16:03 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: ip_gre.c,v 1.36 2005/12/11 12:24:57 christos Exp $");
|
1998-09-14 00:27:47 +04:00
|
|
|
|
|
|
|
#include "gre.h"
|
|
|
|
#if NGRE > 0
|
|
|
|
|
|
|
|
#include "opt_inet.h"
|
1999-10-25 23:18:10 +04:00
|
|
|
#include "opt_ns.h"
|
|
|
|
#include "opt_atalk.h"
|
2000-08-25 04:51:20 +04:00
|
|
|
#include "bpfilter.h"
|
1998-09-14 00:27:47 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/syslog.h>
|
2000-08-25 04:51:20 +04:00
|
|
|
#include <net/bpf.h>
|
1998-09-14 00:27:47 +04:00
|
|
|
#include <net/ethertypes.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/netisr.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/raw_cb.h>
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
1998-12-22 04:49:04 +03:00
|
|
|
#include <netinet/ip_gre.h>
|
1998-09-14 00:27:47 +04:00
|
|
|
#else
|
1998-10-03 01:21:04 +04:00
|
|
|
#error ip_gre input without IP?
|
1998-09-14 00:27:47 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NETATALK
|
|
|
|
#include <netatalk/at.h>
|
|
|
|
#include <netatalk/at_var.h>
|
|
|
|
#include <netatalk/at_extern.h>
|
|
|
|
#endif
|
|
|
|
|
1998-12-22 04:49:04 +03:00
|
|
|
/* Needs IP headers. */
|
1998-09-14 00:27:47 +04:00
|
|
|
#include <net/if_gre.h>
|
|
|
|
|
1998-12-22 04:49:04 +03:00
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
1998-09-30 09:59:27 +04:00
|
|
|
#if 1
|
|
|
|
void gre_inet_ntoa(struct in_addr in); /* XXX */
|
|
|
|
#endif
|
|
|
|
|
2005-02-03 00:41:55 +03:00
|
|
|
struct gre_softc *gre_lookup(struct mbuf *, u_int8_t);
|
1998-09-30 09:59:27 +04:00
|
|
|
|
2005-02-04 01:45:28 +03:00
|
|
|
int gre_input2(struct mbuf *, int, u_char);
|
2000-07-06 08:34:26 +04:00
|
|
|
|
1998-09-14 00:27:47 +04:00
|
|
|
/*
|
|
|
|
* De-encapsulate a packet and feed it back through ip input (this
|
|
|
|
* routine is called whenever IP gets a packet with proto type
|
|
|
|
* IPPROTO_GRE and a local destination address).
|
|
|
|
* This really is simple
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gre_input(struct mbuf *m, ...)
|
|
|
|
{
|
2002-08-10 09:40:54 +04:00
|
|
|
int off, ret, proto;
|
1998-09-14 00:27:47 +04:00
|
|
|
va_list ap;
|
|
|
|
|
1998-09-30 09:59:27 +04:00
|
|
|
va_start(ap, m);
|
2002-08-10 09:40:54 +04:00
|
|
|
off = va_arg(ap, int);
|
|
|
|
proto = va_arg(ap, int);
|
1998-09-30 09:59:27 +04:00
|
|
|
va_end(ap);
|
1998-09-14 00:27:47 +04:00
|
|
|
|
2002-08-10 09:40:54 +04:00
|
|
|
ret = gre_input2(m, off, proto);
|
2002-06-09 20:33:36 +04:00
|
|
|
/*
|
2005-02-27 01:45:09 +03:00
|
|
|
* ret == 0 : packet not processed, meaning that
|
2002-08-10 09:40:54 +04:00
|
|
|
* no matching tunnel that is up is found.
|
|
|
|
* we inject it to raw ip socket to see if anyone picks it up.
|
1998-09-14 00:27:47 +04:00
|
|
|
*/
|
2002-06-09 23:49:49 +04:00
|
|
|
if (ret == 0)
|
2002-08-10 09:40:54 +04:00
|
|
|
rip_input(m, off, proto);
|
1998-09-14 00:27:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* decapsulate.
|
|
|
|
* Does the real work and is called from gre_input() (above)
|
2002-06-09 20:33:36 +04:00
|
|
|
* returns 0 if packet is not yet processed
|
1998-09-14 00:27:47 +04:00
|
|
|
* and 1 if it needs no further processing
|
|
|
|
* proto is the protocol number of the "calling" foo_input()
|
|
|
|
* routine.
|
|
|
|
*/
|
|
|
|
int
|
2003-04-21 10:52:47 +04:00
|
|
|
gre_input2(struct mbuf *m, int hlen, u_char proto)
|
1998-09-14 00:27:47 +04:00
|
|
|
{
|
2003-04-21 10:52:47 +04:00
|
|
|
struct greip *gip;
|
2005-03-30 20:34:54 +04:00
|
|
|
int s, isr;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifqueue *ifq;
|
1998-12-22 04:49:04 +03:00
|
|
|
struct gre_softc *sc;
|
2003-09-06 03:02:40 +04:00
|
|
|
u_int16_t flags;
|
2005-07-27 01:26:48 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
u_int32_t af = AF_INET; /* af passed to BPF tap */
|
|
|
|
#endif
|
1998-09-14 00:27:47 +04:00
|
|
|
|
1998-12-22 04:49:04 +03:00
|
|
|
if ((sc = gre_lookup(m, proto)) == NULL) {
|
|
|
|
/* No matching tunnel or tunnel is down. */
|
|
|
|
return (0);
|
1998-09-14 00:27:47 +04:00
|
|
|
}
|
|
|
|
|
2003-04-21 10:52:47 +04:00
|
|
|
if (m->m_len < sizeof(*gip)) {
|
|
|
|
m = m_pullup(m, sizeof(*gip));
|
|
|
|
if (m == NULL)
|
|
|
|
return (ENOBUFS);
|
|
|
|
}
|
|
|
|
gip = mtod(m, struct greip *);
|
|
|
|
|
1998-12-22 04:49:04 +03:00
|
|
|
sc->sc_if.if_ipackets++;
|
|
|
|
sc->sc_if.if_ibytes += m->m_pkthdr.len;
|
|
|
|
|
1998-09-14 00:27:47 +04:00
|
|
|
switch (proto) {
|
|
|
|
case IPPROTO_GRE:
|
2003-04-21 10:52:47 +04:00
|
|
|
hlen += sizeof(struct gre_h);
|
1998-09-14 00:27:47 +04:00
|
|
|
|
|
|
|
/* process GRE flags as packet can be of variable len */
|
|
|
|
flags = ntohs(gip->gi_flags);
|
|
|
|
|
|
|
|
/* Checksum & Offset are present */
|
|
|
|
if ((flags & GRE_CP) | (flags & GRE_RP))
|
|
|
|
hlen += 4;
|
|
|
|
/* We don't support routing fields (variable length) */
|
|
|
|
if (flags & GRE_RP)
|
2002-09-11 06:46:42 +04:00
|
|
|
return (0);
|
1998-09-14 00:27:47 +04:00
|
|
|
if (flags & GRE_KP)
|
|
|
|
hlen += 4;
|
|
|
|
if (flags & GRE_SP)
|
2003-04-21 10:52:47 +04:00
|
|
|
hlen += 4;
|
1998-09-14 00:27:47 +04:00
|
|
|
|
|
|
|
switch (ntohs(gip->gi_ptype)) { /* ethertypes */
|
|
|
|
case ETHERTYPE_IP: /* shouldn't need a schednetisr(), as */
|
|
|
|
ifq = &ipintrq; /* we are in ip_input */
|
2005-03-30 20:34:54 +04:00
|
|
|
isr = NETISR_IP;
|
1998-09-14 00:27:47 +04:00
|
|
|
break;
|
|
|
|
#ifdef NS
|
|
|
|
case ETHERTYPE_NS:
|
|
|
|
ifq = &nsintrq;
|
2005-03-30 20:34:54 +04:00
|
|
|
isr = NETISR_NS;
|
2005-07-27 01:26:48 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
af = AF_NS;
|
|
|
|
#endif
|
1998-09-14 00:27:47 +04:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef NETATALK
|
1998-10-13 06:34:31 +04:00
|
|
|
case ETHERTYPE_ATALK:
|
1998-09-14 00:27:47 +04:00
|
|
|
ifq = &atintrq1;
|
2005-03-30 20:34:54 +04:00
|
|
|
isr = NETISR_ATALK;
|
2005-07-27 01:26:48 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
af = AF_APPLETALK;
|
|
|
|
#endif
|
1998-09-14 00:27:47 +04:00
|
|
|
break;
|
|
|
|
#endif
|
2005-03-30 20:34:54 +04:00
|
|
|
#ifdef INET6
|
1998-09-14 00:27:47 +04:00
|
|
|
case ETHERTYPE_IPV6:
|
2005-03-30 20:34:54 +04:00
|
|
|
#ifdef GRE_DEBUG
|
|
|
|
printf( "ip_gre.c/gre_input2: IPv6 packet\n" );
|
|
|
|
#endif
|
|
|
|
ifq = &ip6intrq;
|
|
|
|
isr = NETISR_IPV6;
|
2005-07-27 01:26:48 +04:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
af = AF_INET6;
|
|
|
|
#endif
|
2005-03-30 20:34:54 +04:00
|
|
|
break;
|
|
|
|
#endif
|
1998-09-14 00:27:47 +04:00
|
|
|
default: /* others not yet supported */
|
2005-03-30 20:34:54 +04:00
|
|
|
printf( "ip_gre.c/gre_input2: unhandled ethertype 0x%04x\n", (int) ntohs(gip->gi_ptype) );
|
2002-09-11 06:46:42 +04:00
|
|
|
return (0);
|
1998-09-14 00:27:47 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* others not yet supported */
|
2002-09-11 06:46:42 +04:00
|
|
|
return (0);
|
1998-09-14 00:27:47 +04:00
|
|
|
}
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-04-21 10:52:47 +04:00
|
|
|
if (hlen > m->m_pkthdr.len) {
|
|
|
|
m_freem(m);
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
m_adj(m, hlen);
|
1998-09-14 00:27:47 +04:00
|
|
|
|
2000-08-25 04:51:20 +04:00
|
|
|
#if NBPFILTER > 0
|
2000-12-12 21:00:22 +03:00
|
|
|
if (sc->sc_if.if_bpf) {
|
2000-08-25 04:51:20 +04:00
|
|
|
struct mbuf m0;
|
|
|
|
|
2003-05-02 06:13:16 +04:00
|
|
|
m0.m_flags = 0;
|
2000-08-25 04:51:20 +04:00
|
|
|
m0.m_next = m;
|
|
|
|
m0.m_len = 4;
|
|
|
|
m0.m_data = (char *)⁡
|
|
|
|
|
2000-12-12 21:00:22 +03:00
|
|
|
bpf_mtap(sc->sc_if.if_bpf, &m0);
|
2003-04-21 10:52:47 +04:00
|
|
|
}
|
2000-08-25 04:51:20 +04:00
|
|
|
#endif /*NBPFILTER > 0*/
|
|
|
|
|
2000-10-21 00:43:26 +04:00
|
|
|
m->m_pkthdr.rcvif = &sc->sc_if;
|
|
|
|
|
2001-04-14 03:29:55 +04:00
|
|
|
s = splnet(); /* possible */
|
1998-09-14 00:27:47 +04:00
|
|
|
if (IF_QFULL(ifq)) {
|
|
|
|
IF_DROP(ifq);
|
|
|
|
m_freem(m);
|
|
|
|
} else {
|
2003-04-21 10:52:47 +04:00
|
|
|
IF_ENQUEUE(ifq, m);
|
1998-09-14 00:27:47 +04:00
|
|
|
}
|
2005-03-30 20:34:54 +04:00
|
|
|
/* we need schednetisr since the address family may change */
|
|
|
|
schednetisr(isr);
|
1998-09-14 00:27:47 +04:00
|
|
|
splx(s);
|
|
|
|
|
2002-09-11 06:46:42 +04:00
|
|
|
return (1); /* packet is done, no further processing needed */
|
1998-09-14 00:27:47 +04:00
|
|
|
}
|
|
|
|
|
1998-09-30 09:59:27 +04:00
|
|
|
/*
|
|
|
|
* input routine for IPPRPOTO_MOBILE
|
2002-06-09 20:33:36 +04:00
|
|
|
* This is a little bit diffrent from the other modes, as the
|
1998-09-30 09:59:27 +04:00
|
|
|
* encapsulating header was not prepended, but instead inserted
|
|
|
|
* between IP header and payload
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gre_mobile_input(struct mbuf *m, ...)
|
|
|
|
{
|
2003-04-21 10:52:47 +04:00
|
|
|
struct ip *ip;
|
|
|
|
struct mobip_h *mip;
|
2000-03-30 16:51:13 +04:00
|
|
|
struct ifqueue *ifq;
|
1998-12-22 04:49:04 +03:00
|
|
|
struct gre_softc *sc;
|
2003-04-21 10:52:47 +04:00
|
|
|
int hlen, s;
|
1998-09-30 09:59:27 +04:00
|
|
|
va_list ap;
|
1998-12-22 04:49:04 +03:00
|
|
|
int msiz;
|
1998-09-30 09:59:27 +04:00
|
|
|
|
2003-04-21 10:52:47 +04:00
|
|
|
va_start(ap, m);
|
2002-06-09 23:49:49 +04:00
|
|
|
hlen = va_arg(ap, int);
|
1998-09-30 09:59:27 +04:00
|
|
|
va_end(ap);
|
|
|
|
|
1998-12-22 04:49:04 +03:00
|
|
|
if ((sc = gre_lookup(m, IPPROTO_MOBILE)) == NULL) {
|
|
|
|
/* No matching tunnel or tunnel is down. */
|
1998-09-30 09:59:27 +04:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-04-21 10:52:47 +04:00
|
|
|
if (m->m_len < sizeof(*mip)) {
|
|
|
|
m = m_pullup(m, sizeof(*mip));
|
|
|
|
if (m == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
mip = mtod(m, struct mobip_h *);
|
|
|
|
|
2002-06-09 20:33:36 +04:00
|
|
|
sc->sc_if.if_ipackets++;
|
1998-12-22 04:49:04 +03:00
|
|
|
sc->sc_if.if_ibytes += m->m_pkthdr.len;
|
|
|
|
|
2003-04-21 10:52:47 +04:00
|
|
|
if (ntohs(mip->mh.proto) & MOB_H_SBIT) {
|
2002-06-09 23:49:49 +04:00
|
|
|
msiz = MOB_H_SIZ_L;
|
|
|
|
mip->mi.ip_src.s_addr = mip->mh.osrc;
|
2003-04-21 10:52:47 +04:00
|
|
|
} else
|
2002-06-09 23:49:49 +04:00
|
|
|
msiz = MOB_H_SIZ_S;
|
2003-04-21 10:52:47 +04:00
|
|
|
|
2003-04-21 11:02:31 +04:00
|
|
|
if (m->m_len < (ip->ip_hl << 2) + msiz) {
|
|
|
|
m = m_pullup(m, (ip->ip_hl << 2) + msiz);
|
2003-04-21 10:52:47 +04:00
|
|
|
if (m == NULL)
|
|
|
|
return;
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
mip = mtod(m, struct mobip_h *);
|
1998-09-30 09:59:27 +04:00
|
|
|
}
|
2003-04-21 10:52:47 +04:00
|
|
|
|
2002-06-09 23:49:49 +04:00
|
|
|
mip->mi.ip_dst.s_addr = mip->mh.odst;
|
|
|
|
mip->mi.ip_p = (ntohs(mip->mh.proto) >> 8);
|
2002-06-09 20:33:36 +04:00
|
|
|
|
2003-09-06 03:02:40 +04:00
|
|
|
if (gre_in_cksum((u_int16_t *)&mip->mh, msiz) != 0) {
|
1998-09-30 09:59:27 +04:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-06-09 23:49:49 +04:00
|
|
|
memmove(ip + (ip->ip_hl << 2), ip + (ip->ip_hl << 2) + msiz,
|
|
|
|
m->m_len - msiz - (ip->ip_hl << 2));
|
|
|
|
m->m_len -= msiz;
|
2002-08-14 04:23:27 +04:00
|
|
|
ip->ip_len = htons(ntohs(ip->ip_len) - msiz);
|
2002-06-09 23:49:49 +04:00
|
|
|
m->m_pkthdr.len -= msiz;
|
1998-09-30 09:59:27 +04:00
|
|
|
|
2002-06-09 23:49:49 +04:00
|
|
|
ip->ip_sum = 0;
|
|
|
|
ip->ip_sum = in_cksum(m, (ip->ip_hl << 2));
|
1998-09-30 09:59:27 +04:00
|
|
|
|
2000-08-25 04:51:20 +04:00
|
|
|
#if NBPFILTER > 0
|
2000-12-12 21:00:22 +03:00
|
|
|
if (sc->sc_if.if_bpf) {
|
2000-08-25 04:51:20 +04:00
|
|
|
struct mbuf m0;
|
2002-06-09 20:33:36 +04:00
|
|
|
u_int af = AF_INET;
|
2000-08-25 04:51:20 +04:00
|
|
|
|
|
|
|
m0.m_next = m;
|
|
|
|
m0.m_len = 4;
|
|
|
|
m0.m_data = (char *)⁡
|
|
|
|
|
2000-12-12 21:00:22 +03:00
|
|
|
bpf_mtap(sc->sc_if.if_bpf, &m0);
|
2003-04-21 10:52:47 +04:00
|
|
|
}
|
2000-08-25 04:51:20 +04:00
|
|
|
#endif /*NBPFILTER > 0*/
|
|
|
|
|
1998-09-30 09:59:27 +04:00
|
|
|
ifq = &ipintrq;
|
2001-04-14 03:29:55 +04:00
|
|
|
s = splnet(); /* possible */
|
1998-09-30 09:59:27 +04:00
|
|
|
if (IF_QFULL(ifq)) {
|
|
|
|
IF_DROP(ifq);
|
|
|
|
m_freem(m);
|
2002-06-09 20:33:36 +04:00
|
|
|
} else {
|
2003-04-21 10:52:47 +04:00
|
|
|
IF_ENQUEUE(ifq, m);
|
2002-06-09 20:33:36 +04:00
|
|
|
}
|
1998-09-30 09:59:27 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-12-22 04:49:04 +03:00
|
|
|
* Find the gre interface associated with our src/dst/proto set.
|
1998-09-30 09:59:27 +04:00
|
|
|
*/
|
1998-12-22 04:49:04 +03:00
|
|
|
struct gre_softc *
|
2005-02-04 01:45:28 +03:00
|
|
|
gre_lookup(struct mbuf *m, u_int8_t proto)
|
1998-09-30 09:59:27 +04:00
|
|
|
{
|
1998-12-22 04:49:04 +03:00
|
|
|
struct ip *ip = mtod(m, struct ip *);
|
|
|
|
struct gre_softc *sc;
|
1998-09-14 00:27:47 +04:00
|
|
|
|
2000-07-06 02:45:25 +04:00
|
|
|
for (sc = LIST_FIRST(&gre_softc_list); sc != NULL;
|
|
|
|
sc = LIST_NEXT(sc, sc_list)) {
|
1998-12-22 04:49:04 +03:00
|
|
|
if ((sc->g_dst.s_addr == ip->ip_src.s_addr) &&
|
|
|
|
(sc->g_src.s_addr == ip->ip_dst.s_addr) &&
|
|
|
|
(sc->g_proto == proto) &&
|
|
|
|
((sc->sc_if.if_flags & IFF_UP) != 0))
|
|
|
|
return (sc);
|
1998-09-30 09:59:27 +04:00
|
|
|
}
|
|
|
|
|
1998-12-22 04:49:04 +03:00
|
|
|
return (NULL);
|
1998-09-30 09:59:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* if NGRE > 0 */
|