Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys introduce sys/netinet/ip_encap.c, to dispatch inbound pa...
details: https://anonhg.NetBSD.org/src/rev/03614dcd6867
branches: trunk
changeset: 485104:03614dcd6867
user: itojun <itojun%NetBSD.org@localhost>
date: Wed Apr 19 06:30:51 2000 +0000
description:
introduce sys/netinet/ip_encap.c, to dispatch inbound packets
to protocol handlers, based on src/dst (for ip proto #4/41).
see comment in ip_encap.c for details of the problem we have.
there are too many protocol specs for ip proto #4/41.
backward compatibility with MROUTING case is now provided in ip_encap.c.
fix ipip to work with gif (using ip_encap.c). sorry for breakage.
gif now uses ip_encap.c.
introduce stf pseudo interface (implements 6to4, another IPv6-over-IPv4 code
with ip proto #41).
diffstat:
sys/conf/files | 7 +-
sys/net/if_gif.c | 318 +++++++++++++++-----
sys/net/if_gif.h | 29 +-
sys/net/if_stf.c | 711 +++++++++++++++++++++++++++++++++++++++++++++++
sys/net/if_stf.h | 38 ++
sys/net/if_types.h | 3 +-
sys/netinet/in_gif.c | 177 ++++++++---
sys/netinet/in_gif.h | 8 +-
sys/netinet/in_proto.c | 51 ++-
sys/netinet/ip_encap.c | 572 +++++++++++++++++++++++++++++++++++++
sys/netinet/ip_encap.h | 64 ++++
sys/netinet/ip_ipip.c | 92 ++---
sys/netinet/ip_ipip.h | 5 +-
sys/netinet/ip_mroute.c | 4 +-
sys/netinet6/in6_gif.c | 129 ++++++-
sys/netinet6/in6_gif.h | 8 +-
sys/netinet6/in6_proto.c | 30 +-
17 files changed, 1988 insertions(+), 258 deletions(-)
diffs (truncated from 2999 to 300 lines):
diff -r 790245d64709 -r 03614dcd6867 sys/conf/files
--- a/sys/conf/files Wed Apr 19 05:31:29 2000 +0000
+++ b/sys/conf/files Wed Apr 19 06:30:51 2000 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.360 2000/04/10 07:42:55 haya Exp $
+# $NetBSD: files,v 1.361 2000/04/19 06:30:51 itojun Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
@@ -497,6 +497,7 @@
defpseudo gre: ifnet
defpseudo gif: ifnet
defpseudo faith: ifnet
+defpseudo stf: ifnet
defpseudo sequencer
@@ -748,6 +749,7 @@
file net/if_loop.c loop needs-count
file net/if_media.c
file net/if_ppp.c ppp needs-count
+file net/if_stf.c stf & inet & inet6 needs-flag
file net/if_sl.c sl needs-count
file net/if_spppsubr.c sppp
file net/if_strip.c strip needs-count
@@ -800,13 +802,14 @@
file netinet/in_proto.c inet
file netinet/ip_auth.c ipfilter needs-flag
file netinet/ip_ecn.c inet | inet6
+file netinet/ip_encap.c inet | inet6
file netinet/ip_fil.c ipfilter
file netinet/ip_flow.c inet & gateway
file netinet/ip_frag.c ipfilter
file netinet/ip_gre.c inet
file netinet/ip_icmp.c inet
file netinet/ip_input.c inet
-file netinet/ip_ipip.c ipip | mrouting needs-flag
+file netinet/ip_ipip.c ipip needs-flag
file netinet/ip_log.c ipfilter & ipfilter_log
file netinet/ip_mroute.c inet & mrouting
file netinet/ip_nat.c ipfilter
diff -r 790245d64709 -r 03614dcd6867 sys/net/if_gif.c
--- a/sys/net/if_gif.c Wed Apr 19 05:31:29 2000 +0000
+++ b/sys/net/if_gif.c Wed Apr 19 06:30:51 2000 +0000
@@ -1,9 +1,10 @@
-/* $NetBSD: if_gif.c,v 1.8 2000/03/30 09:45:35 augustss Exp $ */
+/* $NetBSD: if_gif.c,v 1.9 2000/04/19 06:30:52 itojun Exp $ */
+/* $KAME: if_gif.c,v 1.21 2000/04/19 06:20:11 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -15,7 +16,7 @@
* 3. Neither the name of the project nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE PROJECT 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
@@ -33,18 +34,28 @@
* gif.c
*/
+#if (defined(__FreeBSD__) && __FreeBSD__ >= 3) || defined(__NetBSD__)
#include "opt_inet.h"
+#endif
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/kernel.h>
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+#include <sys/malloc.h>
+#endif
#include <sys/mbuf.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/errno.h>
+#if defined(__FreeBSD__) || __FreeBSD__ >= 3
+/*nothing*/
+#else
#include <sys/ioctl.h>
+#endif
#include <sys/time.h>
#include <sys/syslog.h>
+#include <sys/protosw.h>
#include <machine/cpu.h>
#include <net/if.h>
@@ -69,8 +80,10 @@
#include <netinet/ip6.h>
#include <netinet6/ip6_var.h>
#include <netinet6/in6_gif.h>
+#include <netinet6/ip6protosw.h>
#endif /* INET6 */
+#include <netinet/ip_encap.h>
#include <net/if_gif.h>
#include "gif.h"
@@ -80,25 +93,86 @@
#if NGIF > 0
+#ifdef __FreeBSD__
+void gifattach __P((void *));
+#else
void gifattach __P((int));
+#endif
+static int gif_encapcheck __P((const struct mbuf *, int, int, void *));
+#ifdef INET
+extern struct protosw in_gif_protosw;
+#endif
+#ifdef INET6
+extern struct ip6protosw in6_gif_protosw;
+#endif
/*
* gif global variable definitions
*/
-int ngif = NGIF; /* number of interfaces */
-struct gif_softc *gif = 0;
+static int ngif; /* number of interfaces */
+static struct gif_softc *gif = 0;
+
+#ifndef MAX_GIF_NEST
+/*
+ * This macro controls the upper limitation on nesting of gif tunnels.
+ * Since, setting a large value to this macro with a careless configuration
+ * may introduce system crash, we don't allow any nestings by default.
+ * If you need to configure nested gif tunnels, you can define this macro
+ * in your kernel configuration file. However, if you do so, please be
+ * careful to configure the tunnels so that it won't make a loop.
+ */
+#define MAX_GIF_NEST 1
+#endif
+static int max_gif_nesting = MAX_GIF_NEST;
void
gifattach(dummy)
+#ifdef __FreeBSD__
+ void *dummy;
+#else
int dummy;
+#endif
{
- struct gif_softc *sc;
- int i;
+ register struct gif_softc *sc;
+ register int i;
+#ifdef __NetBSD__
+ ngif = dummy;
+#else
+ ngif = NGIF;
+#endif
gif = sc = malloc (ngif * sizeof(struct gif_softc), M_DEVBUF, M_WAIT);
bzero(sc, ngif * sizeof(struct gif_softc));
for (i = 0; i < ngif; sc++, i++) {
+#if defined(__NetBSD__) || defined(__OpenBSD__)
sprintf(sc->gif_if.if_xname, "gif%d", i);
+#else
+ sc->gif_if.if_name = "gif";
+ sc->gif_if.if_unit = i;
+#endif
+
+ sc->encap_cookie4 = sc->encap_cookie6 = NULL;
+#ifdef INET
+ sc->encap_cookie4 = encap_attach_func(AF_INET, -1,
+ gif_encapcheck, &in_gif_protosw, sc);
+ if (sc->encap_cookie4 == NULL) {
+ printf("%s: attach failed\n", if_name(&sc->gif_if));
+ continue;
+ }
+#endif
+#ifdef INET6
+ sc->encap_cookie6 = encap_attach_func(AF_INET6, -1,
+ gif_encapcheck, (struct protosw *)&in6_gif_protosw, sc);
+ if (sc->encap_cookie6 == NULL) {
+ if (sc->encap_cookie4) {
+ encap_detach(sc->encap_cookie4);
+ sc->encap_cookie4 = NULL;
+ }
+ printf("%s: attach failed\n", if_name(&sc->gif_if));
+ continue;
+ }
+#endif
+
sc->gif_if.if_mtu = GIF_MTU;
sc->gif_if.if_flags = IFF_POINTOPOINT | IFF_MULTICAST;
sc->gif_if.if_ioctl = gif_ioctl;
@@ -106,8 +180,73 @@
sc->gif_if.if_type = IFT_GIF;
if_attach(&sc->gif_if);
#if NBPFILTER > 0
+#ifdef HAVE_OLD_BPF
+ bpfattach(&sc->gif_if, DLT_NULL, sizeof(u_int));
+#else
bpfattach(&sc->gif_if.if_bpf, &sc->gif_if, DLT_NULL, sizeof(u_int));
#endif
+#endif
+ }
+}
+
+#ifdef __FreeBSD__
+PSEUDO_SET(gifattach, if_gif);
+#endif
+
+static int
+gif_encapcheck(m, off, proto, arg)
+ const struct mbuf *m;
+ int off;
+ int proto;
+ void *arg;
+{
+ struct ip ip;
+ struct gif_softc *sc;
+
+ sc = (struct gif_softc *)arg;
+ if (sc == NULL)
+ return 0;
+
+ if ((sc->gif_if.if_flags & IFF_UP) == 0)
+ return 0;
+
+ /* no physical address */
+ if (!sc->gif_psrc || !sc->gif_pdst)
+ return 0;
+
+ switch (proto) {
+#ifdef INET
+ case IPPROTO_IPV4:
+ break;
+#endif
+#ifdef INET6
+ case IPPROTO_IPV6:
+ break;
+#endif
+ default:
+ return 0;
+ }
+
+ /* LINTED const cast */
+ m_copydata((struct mbuf *)m, 0, sizeof(ip), (caddr_t)&ip);
+
+ switch (ip.ip_v) {
+#ifdef INET
+ case 4:
+ if (sc->gif_psrc->sa_family != AF_INET ||
+ sc->gif_pdst->sa_family != AF_INET)
+ return 0;
+ return gif_encapcheck4(m, off, proto, arg);
+#endif
+#ifdef INET6
+ case 6:
+ if (sc->gif_psrc->sa_family != AF_INET6 ||
+ sc->gif_pdst->sa_family != AF_INET6)
+ return 0;
+ return gif_encapcheck6(m, off, proto, arg);
+#endif
+ default:
+ return 0;
}
}
@@ -118,10 +257,9 @@
struct sockaddr *dst;
struct rtentry *rt; /* added in net2 */
{
- struct gif_softc *sc = (struct gif_softc*)ifp;
+ register struct gif_softc *sc = (struct gif_softc*)ifp;
int error = 0;
static int called = 0; /* XXX: MUTEX */
- int calllimit = 10; /* XXX: adhoc */
/*
* gif may cause infinite recursion calls when misconfigured.
@@ -130,7 +268,7 @@
* mutual exclusion of the variable CALLED, especially if we
* use kernel thread.
*/
- if (++called >= calllimit) {
+ if (++called > max_gif_nesting) {
log(LOG_NOTICE,
"gif_output: recursively called too many times(%d)\n",
called);
@@ -139,12 +277,13 @@
goto end;
}
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+ getmicrotime(&ifp->if_lastchange);
+#else
ifp->if_lastchange = time;
Home |
Main Index |
Thread Index |
Old Index