2002-10-16 02:10:08 +00:00
|
|
|
/* $FreeBSD$ */
|
|
|
|
/* $OpenBSD: ip_ipip.c,v 1.25 2002/06/10 18:04:55 itojun Exp $ */
|
2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2002-10-16 02:10:08 +00:00
|
|
|
* The authors of this code are John Ioannidis (ji@tla.org),
|
|
|
|
* Angelos D. Keromytis (kermit@csd.uch.gr) and
|
|
|
|
* Niels Provos (provos@physnet.uni-hamburg.de).
|
|
|
|
*
|
|
|
|
* The original version of this code was written by John Ioannidis
|
|
|
|
* for BSD/OS in Athens, Greece, in November 1995.
|
|
|
|
*
|
|
|
|
* Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
|
|
|
|
* by Angelos D. Keromytis.
|
|
|
|
*
|
|
|
|
* Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
|
|
|
|
* and Niels Provos.
|
|
|
|
*
|
|
|
|
* Additional features in 1999 by Angelos D. Keromytis.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
|
|
|
|
* Angelos D. Keromytis and Niels Provos.
|
|
|
|
* Copyright (c) 2001, Angelos D. Keromytis.
|
|
|
|
*
|
|
|
|
* Permission to use, copy, and modify this software with or without fee
|
|
|
|
* is hereby granted, provided that this entire notice is included in
|
|
|
|
* all copies of any software which is or includes a copy or
|
|
|
|
* modification of this software.
|
|
|
|
* You may use this code under the GNU public license if you so wish. Please
|
|
|
|
* contribute changes back to the authors under this freer than GPL license
|
|
|
|
* so that we may further the use of strong encryption without limitations to
|
|
|
|
* all.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
|
|
|
|
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
|
|
|
|
* MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
|
|
|
|
* PURPOSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IP-inside-IP processing
|
|
|
|
*/
|
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
2006-06-26 22:30:08 +00:00
|
|
|
#include "opt_enc.h"
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
2007-07-19 09:57:54 +00:00
|
|
|
#include <net/pfil.h>
|
2002-10-16 02:10:08 +00:00
|
|
|
#include <net/route.h>
|
|
|
|
#include <net/netisr.h>
|
2008-12-02 21:37:28 +00:00
|
|
|
#include <net/vnet.h>
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_ecn.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/ip_encap.h>
|
2008-12-02 21:37:28 +00:00
|
|
|
#ifdef MROUTING
|
|
|
|
#include <netinet/ip_mroute.h>
|
|
|
|
#endif
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
#include <netipsec/ipsec.h>
|
|
|
|
#include <netipsec/xform.h>
|
|
|
|
|
|
|
|
#include <netipsec/ipip_var.h>
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#include <netipsec/ipsec6.h>
|
|
|
|
#include <netinet6/ip6_ecn.h>
|
|
|
|
#include <netinet6/in6_var.h>
|
|
|
|
#include <netinet6/ip6protosw.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <netipsec/key.h>
|
|
|
|
#include <netipsec/key_debug.h>
|
|
|
|
|
|
|
|
#include <machine/stdarg.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can control the acceptance of IP4 packets by altering the sysctl
|
|
|
|
* net.inet.ipip.allow value. Zero means drop them, all else is acceptance.
|
|
|
|
*/
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
VNET_DEFINE(int, ipip_allow) = 0;
|
|
|
|
VNET_DEFINE(struct ipipstat, ipipstat);
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
SYSCTL_DECL(_net_inet_ipip);
|
Build on Jeff Roberson's linker-set based dynamic per-CPU allocator
(DPCPU), as suggested by Peter Wemm, and implement a new per-virtual
network stack memory allocator. Modify vnet to use the allocator
instead of monolithic global container structures (vinet, ...). This
change solves many binary compatibility problems associated with
VIMAGE, and restores ELF symbols for virtualized global variables.
Each virtualized global variable exists as a "reference copy", and also
once per virtual network stack. Virtualized global variables are
tagged at compile-time, placing the in a special linker set, which is
loaded into a contiguous region of kernel memory. Virtualized global
variables in the base kernel are linked as normal, but those in modules
are copied and relocated to a reserved portion of the kernel's vnet
region with the help of a the kernel linker.
Virtualized global variables exist in per-vnet memory set up when the
network stack instance is created, and are initialized statically from
the reference copy. Run-time access occurs via an accessor macro, which
converts from the current vnet and requested symbol to a per-vnet
address. When "options VIMAGE" is not compiled into the kernel, normal
global ELF symbols will be used instead and indirection is avoided.
This change restores static initialization for network stack global
variables, restores support for non-global symbols and types, eliminates
the need for many subsystem constructors, eliminates large per-subsystem
structures that caused many binary compatibility issues both for
monitoring applications (netstat) and kernel modules, removes the
per-function INIT_VNET_*() macros throughout the stack, eliminates the
need for vnet_symmap ksym(2) munging, and eliminates duplicate
definitions of virtualized globals under VIMAGE_GLOBALS.
Bump __FreeBSD_version and update UPDATING.
Portions submitted by: bz
Reviewed by: bz, zec
Discussed with: gnn, jamie, jeff, jhb, julian, sam
Suggested by: peter
Approved by: re (kensmith)
2009-07-14 22:48:30 +00:00
|
|
|
SYSCTL_VNET_INT(_net_inet_ipip, OID_AUTO,
|
|
|
|
ipip_allow, CTLFLAG_RW, &VNET_NAME(ipip_allow), 0, "");
|
|
|
|
SYSCTL_VNET_STRUCT(_net_inet_ipip, IPSECCTL_STATS,
|
|
|
|
stats, CTLFLAG_RD, &VNET_NAME(ipipstat), ipipstat, "");
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* XXX IPCOMP */
|
|
|
|
#define M_IPSEC (M_AUTHIPHDR|M_AUTHIPDGM|M_DECRYPTED)
|
|
|
|
|
|
|
|
static void _ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp);
|
Introduce vnet module registration / initialization framework with
dependency tracking and ordering enforcement.
With this change, per-vnet initialization functions introduced with
r190787 are no longer directly called from traditional initialization
functions (which cc in most cases inlined to pre-r190787 code), but are
instead registered via the vnet framework first, and are invoked only
after all prerequisite modules have been initialized. In the long run,
this framework should allow us to both initialize and dismantle
multiple vnet instances in a correct order.
The problem this change aims to solve is how to replay the
initialization sequence of various network stack components, which
have been traditionally triggered via different mechanisms (SYSINIT,
protosw). Note that this initialization sequence was and still can be
subtly different depending on whether certain pieces of code have been
statically compiled into the kernel, loaded as modules by boot
loader, or kldloaded at run time.
The approach is simple - we record the initialization sequence
established by the traditional mechanisms whenever vnet_mod_register()
is called for a particular vnet module. The vnet_mod_register_multi()
variant allows a single initializer function to be registered multiple
times but with different arguments - currently this is only used in
kern/uipc_domain.c by net_add_domain() with different struct domain *
as arguments, which allows for protosw-registered initialization
routines to be invoked in a correct order by the new vnet
initialization framework.
For the purpose of identifying vnet modules, each vnet module has to
have a unique ID, which is statically assigned in sys/vimage.h.
Dynamic assignment of vnet module IDs is not supported yet.
A vnet module may specify a single prerequisite module at registration
time by filling in the vmi_dependson field of its vnet_modinfo struct
with the ID of the module it depends on. Unless specified otherwise,
all vnet modules depend on VNET_MOD_NET (container for ifnet list head,
rt_tables etc.), which thus has to and will always be initialized
first. The framework will panic if it detects any unresolved
dependencies before completing system initialization. Detection of
unresolved dependencies for vnet modules registered after boot
(kldloaded modules) is not provided.
Note that the fact that each module can specify only a single
prerequisite may become problematic in the long run. In particular,
INET6 depends on INET being already instantiated, due to TCP / UDP
structures residing in INET container. IPSEC also depends on INET,
which will in turn additionally complicate making INET6-only kernel
configs a reality.
The entire registration framework can be compiled out by turning on the
VIMAGE_GLOBALS kernel config option.
Reviewed by: bz
Approved by: julian (mentor)
2009-04-11 05:58:58 +00:00
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
#ifdef INET6
|
|
|
|
/*
|
|
|
|
* Really only a wrapper for ipip_input(), for use with IPv6.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
ip4_input6(struct mbuf **m, int *offp, int proto)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* If we do not accept IP-in-IP explicitly, drop. */
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
if (!V_ipip_allow && ((*m)->m_flags & M_IPSEC) == 0) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: dropped due to policy\n", __func__));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_pdrops++;
|
2002-10-16 02:10:08 +00:00
|
|
|
m_freem(*m);
|
|
|
|
return IPPROTO_DONE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
_ipip_input(*m, *offp, NULL);
|
|
|
|
return IPPROTO_DONE;
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
/*
|
|
|
|
* Really only a wrapper for ipip_input(), for use with IPv4.
|
|
|
|
*/
|
|
|
|
void
|
2006-03-30 18:57:04 +00:00
|
|
|
ip4_input(struct mbuf *m, int off)
|
2002-10-16 02:10:08 +00:00
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
/* If we do not accept IP-in-IP explicitly, drop. */
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
if (!V_ipip_allow && (m->m_flags & M_IPSEC) == 0) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: dropped due to policy\n", __func__));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_pdrops++;
|
2002-10-16 02:10:08 +00:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2006-03-30 18:57:04 +00:00
|
|
|
_ipip_input(m, off, NULL);
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
|
|
|
#endif /* INET */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ipip_input gets called when we receive an IP{46} encapsulated packet,
|
|
|
|
* either because we got it at a real interface, or because AH or ESP
|
|
|
|
* were being used in tunnel mode (in which case the rcvif element will
|
|
|
|
* contain the address of the encX interface associated with the tunnel.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ipip_input(struct mbuf *m, int iphlen, struct ifnet *gifp)
|
|
|
|
{
|
2009-06-10 19:25:46 +00:00
|
|
|
#ifdef INET
|
2002-10-16 02:10:08 +00:00
|
|
|
register struct sockaddr_in *sin;
|
2009-06-10 19:25:46 +00:00
|
|
|
#endif
|
2002-10-16 02:10:08 +00:00
|
|
|
register struct ifnet *ifp;
|
|
|
|
register struct ifaddr *ifa;
|
|
|
|
struct ip *ipo;
|
|
|
|
#ifdef INET6
|
|
|
|
register struct sockaddr_in6 *sin6;
|
|
|
|
struct ip6_hdr *ip6 = NULL;
|
|
|
|
u_int8_t itos;
|
|
|
|
#endif
|
|
|
|
u_int8_t nxt;
|
|
|
|
int isr;
|
|
|
|
u_int8_t otos;
|
|
|
|
u_int8_t v;
|
|
|
|
int hlen;
|
|
|
|
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_ipackets++;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
m_copydata(m, 0, 1, &v);
|
|
|
|
|
|
|
|
switch (v >> 4) {
|
|
|
|
#ifdef INET
|
|
|
|
case 4:
|
|
|
|
hlen = sizeof(struct ip);
|
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case 6:
|
|
|
|
hlen = sizeof(struct ip6_hdr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_family++;
|
2002-10-16 02:10:08 +00:00
|
|
|
m_freem(m);
|
|
|
|
return /* EAFNOSUPPORT */;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bring the IP header in the first mbuf, if not there already */
|
|
|
|
if (m->m_len < hlen) {
|
|
|
|
if ((m = m_pullup(m, hlen)) == NULL) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: m_pullup (1) failed\n", __func__));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_hdrops++;
|
2002-10-16 02:10:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ipo = mtod(m, struct ip *);
|
|
|
|
|
|
|
|
#ifdef MROUTING
|
|
|
|
if (ipo->ip_v == IPVERSION && ipo->ip_p == IPPROTO_IPV4) {
|
|
|
|
if (IN_MULTICAST(((struct ip *)((char *) ipo + iphlen))->ip_dst.s_addr)) {
|
|
|
|
ipip_mroute_input (m, iphlen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* MROUTING */
|
|
|
|
|
|
|
|
/* Keep outer ecn field. */
|
|
|
|
switch (v >> 4) {
|
|
|
|
#ifdef INET
|
|
|
|
case 4:
|
|
|
|
otos = ipo->ip_tos;
|
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case 6:
|
|
|
|
otos = (ntohl(mtod(m, struct ip6_hdr *)->ip6_flow) >> 20) & 0xff;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
panic("ipip_input: unknown ip version %u (outer)", v>>4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove outer IP header */
|
|
|
|
m_adj(m, iphlen);
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (m->m_pkthdr.len < sizeof(struct ip)) {
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_hdrops++;
|
2002-10-16 02:10:08 +00:00
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_copydata(m, 0, 1, &v);
|
|
|
|
|
|
|
|
switch (v >> 4) {
|
|
|
|
#ifdef INET
|
|
|
|
case 4:
|
|
|
|
hlen = sizeof(struct ip);
|
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
case 6:
|
|
|
|
hlen = sizeof(struct ip6_hdr);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_family++;
|
2002-10-16 02:10:08 +00:00
|
|
|
m_freem(m);
|
|
|
|
return; /* EAFNOSUPPORT */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bring the inner IP header in the first mbuf, if not there already.
|
|
|
|
*/
|
|
|
|
if (m->m_len < hlen) {
|
|
|
|
if ((m = m_pullup(m, hlen)) == NULL) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: m_pullup (2) failed\n", __func__));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_hdrops++;
|
2002-10-16 02:10:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* RFC 1853 specifies that the inner TTL should not be touched on
|
|
|
|
* decapsulation. There's no reason this comment should be here, but
|
|
|
|
* this is as good as any a position.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Some sanity checks in the inner IP header */
|
|
|
|
switch (v >> 4) {
|
|
|
|
#ifdef INET
|
|
|
|
case 4:
|
|
|
|
ipo = mtod(m, struct ip *);
|
|
|
|
nxt = ipo->ip_p;
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
ip_ecn_egress(V_ip4_ipsec_ecn, &otos, &ipo->ip_tos);
|
2002-10-16 02:10:08 +00:00
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case 6:
|
|
|
|
ip6 = (struct ip6_hdr *) ipo;
|
|
|
|
nxt = ip6->ip6_nxt;
|
|
|
|
itos = (ntohl(ip6->ip6_flow) >> 20) & 0xff;
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
ip_ecn_egress(V_ip6_ipsec_ecn, &otos, &itos);
|
2002-10-16 02:10:08 +00:00
|
|
|
ip6->ip6_flow &= ~htonl(0xff << 20);
|
|
|
|
ip6->ip6_flow |= htonl((u_int32_t) itos << 20);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
panic("ipip_input: unknown ip version %u (inner)", v>>4);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for local address spoofing. */
|
|
|
|
if ((m->m_pkthdr.rcvif == NULL ||
|
|
|
|
!(m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK)) &&
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipip_allow != 2) {
|
2009-08-23 20:40:19 +00:00
|
|
|
IFNET_RLOCK_NOSLEEP();
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
TAILQ_FOREACH(ifp, &V_ifnet, if_link) {
|
2004-04-17 23:29:25 +00:00
|
|
|
TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
|
2002-10-16 02:10:08 +00:00
|
|
|
#ifdef INET
|
|
|
|
if (ipo) {
|
|
|
|
if (ifa->ifa_addr->sa_family !=
|
|
|
|
AF_INET)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sin = (struct sockaddr_in *) ifa->ifa_addr;
|
|
|
|
|
|
|
|
if (sin->sin_addr.s_addr ==
|
|
|
|
ipo->ip_src.s_addr) {
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_spoof++;
|
2002-10-16 02:10:08 +00:00
|
|
|
m_freem(m);
|
2009-08-23 20:40:19 +00:00
|
|
|
IFNET_RUNLOCK_NOSLEEP();
|
2002-10-16 02:10:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* INET */
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
if (ip6) {
|
|
|
|
if (ifa->ifa_addr->sa_family !=
|
|
|
|
AF_INET6)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sin6 = (struct sockaddr_in6 *) ifa->ifa_addr;
|
|
|
|
|
|
|
|
if (IN6_ARE_ADDR_EQUAL(&sin6->sin6_addr, &ip6->ip6_src)) {
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_spoof++;
|
2002-10-16 02:10:08 +00:00
|
|
|
m_freem(m);
|
2009-08-23 20:40:19 +00:00
|
|
|
IFNET_RUNLOCK_NOSLEEP();
|
2002-10-16 02:10:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
}
|
|
|
|
}
|
2009-08-23 20:40:19 +00:00
|
|
|
IFNET_RUNLOCK_NOSLEEP();
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Statistics */
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_ibytes += m->m_pkthdr.len - iphlen;
|
2002-10-16 02:10:08 +00:00
|
|
|
|
2006-06-26 22:30:08 +00:00
|
|
|
#ifdef DEV_ENC
|
2007-11-28 22:33:53 +00:00
|
|
|
switch (v >> 4) {
|
|
|
|
#ifdef INET
|
|
|
|
case 4:
|
|
|
|
ipsec_bpf(m, NULL, AF_INET, ENC_IN|ENC_AFTER);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case 6:
|
|
|
|
ipsec_bpf(m, NULL, AF_INET6, ENC_IN|ENC_AFTER);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
panic("%s: bogus ip version %u", __func__, v>>4);
|
|
|
|
}
|
2006-06-26 22:30:08 +00:00
|
|
|
/* pass the mbuf to enc0 for packet filtering */
|
2007-11-28 22:33:53 +00:00
|
|
|
if (ipsec_filter(&m, PFIL_IN, ENC_IN|ENC_AFTER) != 0)
|
2006-06-26 22:30:08 +00:00
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
/*
|
|
|
|
* Interface pointer stays the same; if no IPsec processing has
|
|
|
|
* been done (or will be done), this will point to a normal
|
|
|
|
* interface. Otherwise, it'll point to an enc interface, which
|
|
|
|
* will allow a packet filter to distinguish between secure and
|
|
|
|
* untrusted packets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
switch (v >> 4) {
|
|
|
|
#ifdef INET
|
|
|
|
case 4:
|
|
|
|
isr = NETISR_IP;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef INET6
|
|
|
|
case 6:
|
|
|
|
isr = NETISR_IPV6;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
2003-09-29 22:57:43 +00:00
|
|
|
panic("%s: bogus ip version %u", __func__, v>>4);
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
|
|
|
|
2004-08-27 18:33:08 +00:00
|
|
|
if (netisr_queue(isr, m)) { /* (0) on success. */
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_qfull++;
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: packet dropped because of full queue\n",
|
|
|
|
__func__));
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ipip_output(
|
|
|
|
struct mbuf *m,
|
|
|
|
struct ipsecrequest *isr,
|
|
|
|
struct mbuf **mp,
|
|
|
|
int skip,
|
|
|
|
int protoff
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct secasvar *sav;
|
|
|
|
u_int8_t tp, otos;
|
|
|
|
struct secasindex *saidx;
|
|
|
|
int error;
|
|
|
|
#ifdef INET
|
|
|
|
u_int8_t itos;
|
|
|
|
struct ip *ipo;
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
struct ip6_hdr *ip6, *ip6o;
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
sav = isr->sav;
|
2003-09-29 22:57:43 +00:00
|
|
|
IPSEC_ASSERT(sav != NULL, ("null SA"));
|
|
|
|
IPSEC_ASSERT(sav->sah != NULL, ("null SAH"));
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* XXX Deal with empty TDB source/destination addresses. */
|
|
|
|
|
|
|
|
m_copydata(m, 0, 1, &tp);
|
|
|
|
tp = (tp >> 4) & 0xff; /* Get the IP version number. */
|
|
|
|
|
|
|
|
saidx = &sav->sah->saidx;
|
|
|
|
switch (saidx->dst.sa.sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
if (saidx->src.sa.sa_family != AF_INET ||
|
|
|
|
saidx->src.sin.sin_addr.s_addr == INADDR_ANY ||
|
|
|
|
saidx->dst.sin.sin_addr.s_addr == INADDR_ANY) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: unspecified tunnel endpoint "
|
|
|
|
"address in SA %s/%08lx\n", __func__,
|
2002-10-16 02:10:08 +00:00
|
|
|
ipsec_address(&saidx->dst),
|
|
|
|
(u_long) ntohl(sav->spi)));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_unspec++;
|
2002-10-16 02:10:08 +00:00
|
|
|
error = EINVAL;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
M_PREPEND(m, sizeof(struct ip), M_DONTWAIT);
|
2002-10-16 02:10:08 +00:00
|
|
|
if (m == 0) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: M_PREPEND failed\n", __func__));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_hdrops++;
|
2002-10-16 02:10:08 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
ipo = mtod(m, struct ip *);
|
|
|
|
|
|
|
|
ipo->ip_v = IPVERSION;
|
|
|
|
ipo->ip_hl = 5;
|
|
|
|
ipo->ip_len = htons(m->m_pkthdr.len);
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
ipo->ip_ttl = V_ip_defttl;
|
2002-10-16 02:10:08 +00:00
|
|
|
ipo->ip_sum = 0;
|
|
|
|
ipo->ip_src = saidx->src.sin.sin_addr;
|
|
|
|
ipo->ip_dst = saidx->dst.sin.sin_addr;
|
|
|
|
|
2004-08-14 15:32:40 +00:00
|
|
|
ipo->ip_id = ip_newid();
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/* If the inner protocol is IP... */
|
|
|
|
if (tp == IPVERSION) {
|
|
|
|
/* Save ECN notification */
|
|
|
|
m_copydata(m, sizeof(struct ip) +
|
|
|
|
offsetof(struct ip, ip_tos),
|
|
|
|
sizeof(u_int8_t), (caddr_t) &itos);
|
|
|
|
|
|
|
|
ipo->ip_p = IPPROTO_IPIP;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We should be keeping tunnel soft-state and
|
|
|
|
* send back ICMPs if needed.
|
|
|
|
*/
|
|
|
|
m_copydata(m, sizeof(struct ip) +
|
|
|
|
offsetof(struct ip, ip_off),
|
|
|
|
sizeof(u_int16_t), (caddr_t) &ipo->ip_off);
|
|
|
|
ipo->ip_off = ntohs(ipo->ip_off);
|
|
|
|
ipo->ip_off &= ~(IP_DF | IP_MF | IP_OFFMASK);
|
|
|
|
ipo->ip_off = htons(ipo->ip_off);
|
|
|
|
}
|
|
|
|
#ifdef INET6
|
|
|
|
else if (tp == (IPV6_VERSION >> 4)) {
|
|
|
|
u_int32_t itos32;
|
|
|
|
|
|
|
|
/* Save ECN notification. */
|
|
|
|
m_copydata(m, sizeof(struct ip) +
|
|
|
|
offsetof(struct ip6_hdr, ip6_flow),
|
|
|
|
sizeof(u_int32_t), (caddr_t) &itos32);
|
|
|
|
itos = ntohl(itos32) >> 20;
|
|
|
|
ipo->ip_p = IPPROTO_IPV6;
|
|
|
|
ipo->ip_off = 0;
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
else {
|
|
|
|
goto nofamily;
|
|
|
|
}
|
|
|
|
|
|
|
|
otos = 0;
|
|
|
|
ip_ecn_ingress(ECN_ALLOWED, &otos, &itos);
|
|
|
|
ipo->ip_tos = otos;
|
|
|
|
break;
|
|
|
|
#endif /* INET */
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6:
|
|
|
|
if (IN6_IS_ADDR_UNSPECIFIED(&saidx->dst.sin6.sin6_addr) ||
|
|
|
|
saidx->src.sa.sa_family != AF_INET6 ||
|
|
|
|
IN6_IS_ADDR_UNSPECIFIED(&saidx->src.sin6.sin6_addr)) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: unspecified tunnel endpoint "
|
|
|
|
"address in SA %s/%08lx\n", __func__,
|
2002-10-16 02:10:08 +00:00
|
|
|
ipsec_address(&saidx->dst),
|
|
|
|
(u_long) ntohl(sav->spi)));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_unspec++;
|
2002-10-16 02:10:08 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* scoped address handling */
|
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
|
|
|
if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_src))
|
|
|
|
ip6->ip6_src.s6_addr16[1] = 0;
|
|
|
|
if (IN6_IS_SCOPE_LINKLOCAL(&ip6->ip6_dst))
|
|
|
|
ip6->ip6_dst.s6_addr16[1] = 0;
|
|
|
|
|
2003-02-19 05:47:46 +00:00
|
|
|
M_PREPEND(m, sizeof(struct ip6_hdr), M_DONTWAIT);
|
2002-10-16 02:10:08 +00:00
|
|
|
if (m == 0) {
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: M_PREPEND failed\n", __func__));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_hdrops++;
|
2002-10-16 02:10:08 +00:00
|
|
|
error = ENOBUFS;
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize IPv6 header */
|
|
|
|
ip6o = mtod(m, struct ip6_hdr *);
|
|
|
|
ip6o->ip6_flow = 0;
|
|
|
|
ip6o->ip6_vfc &= ~IPV6_VERSION_MASK;
|
|
|
|
ip6o->ip6_vfc |= IPV6_VERSION;
|
|
|
|
ip6o->ip6_plen = htons(m->m_pkthdr.len);
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
ip6o->ip6_hlim = V_ip_defttl;
|
2002-10-16 02:10:08 +00:00
|
|
|
ip6o->ip6_dst = saidx->dst.sin6.sin6_addr;
|
|
|
|
ip6o->ip6_src = saidx->src.sin6.sin6_addr;
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
if (tp == IPVERSION) {
|
|
|
|
/* Save ECN notification */
|
|
|
|
m_copydata(m, sizeof(struct ip6_hdr) +
|
|
|
|
offsetof(struct ip, ip_tos), sizeof(u_int8_t),
|
|
|
|
(caddr_t) &itos);
|
|
|
|
|
|
|
|
/* This is really IPVERSION. */
|
|
|
|
ip6o->ip6_nxt = IPPROTO_IPIP;
|
|
|
|
} else
|
|
|
|
#endif /* INET */
|
|
|
|
if (tp == (IPV6_VERSION >> 4)) {
|
|
|
|
u_int32_t itos32;
|
|
|
|
|
|
|
|
/* Save ECN notification. */
|
|
|
|
m_copydata(m, sizeof(struct ip6_hdr) +
|
|
|
|
offsetof(struct ip6_hdr, ip6_flow),
|
|
|
|
sizeof(u_int32_t), (caddr_t) &itos32);
|
|
|
|
itos = ntohl(itos32) >> 20;
|
|
|
|
|
|
|
|
ip6o->ip6_nxt = IPPROTO_IPV6;
|
|
|
|
} else {
|
|
|
|
goto nofamily;
|
|
|
|
}
|
|
|
|
|
|
|
|
otos = 0;
|
|
|
|
ip_ecn_ingress(ECN_ALLOWED, &otos, &itos);
|
|
|
|
ip6o->ip6_flow |= htonl((u_int32_t) otos << 20);
|
|
|
|
break;
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
default:
|
|
|
|
nofamily:
|
2003-09-29 22:57:43 +00:00
|
|
|
DPRINTF(("%s: unsupported protocol family %u\n", __func__,
|
2002-10-16 02:10:08 +00:00
|
|
|
saidx->dst.sa.sa_family));
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_family++;
|
2002-10-16 02:10:08 +00:00
|
|
|
error = EAFNOSUPPORT; /* XXX diffs from openbsd */
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_opackets++;
|
2002-10-16 02:10:08 +00:00
|
|
|
*mp = m;
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
if (saidx->dst.sa.sa_family == AF_INET) {
|
|
|
|
#if 0
|
|
|
|
if (sav->tdb_xform->xf_type == XF_IP4)
|
|
|
|
tdb->tdb_cur_bytes +=
|
|
|
|
m->m_pkthdr.len - sizeof(struct ip);
|
|
|
|
#endif
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_obytes += m->m_pkthdr.len - sizeof(struct ip);
|
2002-10-16 02:10:08 +00:00
|
|
|
}
|
|
|
|
#endif /* INET */
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
if (saidx->dst.sa.sa_family == AF_INET6) {
|
|
|
|
#if 0
|
|
|
|
if (sav->tdb_xform->xf_type == XF_IP4)
|
|
|
|
tdb->tdb_cur_bytes +=
|
|
|
|
m->m_pkthdr.len - sizeof(struct ip6_hdr);
|
|
|
|
#endif
|
Commit step 1 of the vimage project, (network stack)
virtualization work done by Marko Zec (zec@).
This is the first in a series of commits over the course
of the next few weeks.
Mark all uses of global variables to be virtualized
with a V_ prefix.
Use macros to map them back to their global names for
now, so this is a NOP change only.
We hope to have caught at least 85-90% of what is needed
so we do not invalidate a lot of outstanding patches again.
Obtained from: //depot/projects/vimage-commit2/...
Reviewed by: brooks, des, ed, mav, julian,
jamie, kris, rwatson, zec, ...
(various people I forgot, different versions)
md5 (with a bit of help)
Sponsored by: NLnet Foundation, The FreeBSD Foundation
X-MFC after: never
V_Commit_Message_Reviewed_By: more people than the patch
2008-08-17 23:27:27 +00:00
|
|
|
V_ipipstat.ipips_obytes +=
|
2002-10-16 02:10:08 +00:00
|
|
|
m->m_pkthdr.len - sizeof(struct ip6_hdr);
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
bad:
|
|
|
|
if (m)
|
2004-01-20 22:45:10 +00:00
|
|
|
m_freem(m);
|
|
|
|
*mp = NULL;
|
2002-10-16 02:10:08 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
2007-07-03 12:13:45 +00:00
|
|
|
#ifdef IPSEC
|
2002-10-16 02:10:08 +00:00
|
|
|
static int
|
|
|
|
ipe4_init(struct secasvar *sav, struct xformsw *xsp)
|
|
|
|
{
|
|
|
|
sav->tdb_xform = xsp;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ipe4_zeroize(struct secasvar *sav)
|
|
|
|
{
|
|
|
|
sav->tdb_xform = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ipe4_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff)
|
|
|
|
{
|
|
|
|
/* This is a rather serious mistake, so no conditional printing. */
|
2003-09-29 22:57:43 +00:00
|
|
|
printf("%s: should never be called\n", __func__);
|
2002-10-16 02:10:08 +00:00
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct xformsw ipe4_xformsw = {
|
|
|
|
XF_IP4, 0, "IPv4 Simple Encapsulation",
|
|
|
|
ipe4_init, ipe4_zeroize, ipe4_input, ipip_output,
|
|
|
|
};
|
|
|
|
|
|
|
|
extern struct domain inetdomain;
|
2009-01-05 20:29:01 +00:00
|
|
|
static struct protosw ipe4_protosw = {
|
|
|
|
.pr_type = SOCK_RAW,
|
|
|
|
.pr_domain = &inetdomain,
|
|
|
|
.pr_protocol = IPPROTO_IPV4,
|
|
|
|
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
|
|
|
.pr_input = ip4_input,
|
|
|
|
.pr_ctloutput = rip_ctloutput,
|
|
|
|
.pr_usrreqs = &rip_usrreqs
|
2006-03-30 18:57:04 +00:00
|
|
|
};
|
2002-10-16 02:10:08 +00:00
|
|
|
#ifdef INET6
|
2009-01-05 20:29:01 +00:00
|
|
|
static struct ip6protosw ipe6_protosw = {
|
|
|
|
.pr_type = SOCK_RAW,
|
|
|
|
.pr_domain = &inetdomain,
|
|
|
|
.pr_protocol = IPPROTO_IPV6,
|
|
|
|
.pr_flags = PR_ATOMIC|PR_ADDR|PR_LASTHDR,
|
|
|
|
.pr_input = ip4_input6,
|
|
|
|
.pr_ctloutput = rip_ctloutput,
|
|
|
|
.pr_usrreqs = &rip_usrreqs
|
2002-10-16 02:10:08 +00:00
|
|
|
};
|
2006-03-30 18:57:04 +00:00
|
|
|
#endif
|
2002-10-16 02:10:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check the encapsulated packet to see if we want it
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ipe4_encapcheck(const struct mbuf *m, int off, int proto, void *arg)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Only take packets coming from IPSEC tunnels; the rest
|
|
|
|
* must be handled by the gif tunnel code. Note that we
|
|
|
|
* also return a minimum priority when we want the packet
|
|
|
|
* so any explicit gif tunnels take precedence.
|
|
|
|
*/
|
|
|
|
return ((m->m_flags & M_IPSEC) != 0 ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
First pass at separating per-vnet initializer functions
from existing functions for initializing global state.
At this stage, the new per-vnet initializer functions are
directly called from the existing global initialization code,
which should in most cases result in compiler inlining those
new functions, hence yielding a near-zero functional change.
Modify the existing initializer functions which are invoked via
protosw, like ip_init() et. al., to allow them to be invoked
multiple times, i.e. per each vnet. Global state, if any,
is initialized only if such functions are called within the
context of vnet0, which will be determined via the
IS_DEFAULT_VNET(curvnet) check (currently always true).
While here, V_irtualize a few remaining global UMA zones
used by net/netinet/netipsec networking code. While it is
not yet clear to me or anybody else whether this is the right
thing to do, at this stage this makes the code more readable,
and makes it easier to track uncollected UMA-zone-backed
objects on vnet removal. In the long run, it's quite possible
that some form of shared use of UMA zone pools among multiple
vnets should be considered.
Bump __FreeBSD_version due to changes in layout of structs
vnet_ipfw, vnet_inet and vnet_net.
Approved by: julian (mentor)
2009-04-06 22:29:41 +00:00
|
|
|
static void
|
|
|
|
ipe4_attach(void)
|
|
|
|
{
|
2008-11-19 09:39:34 +00:00
|
|
|
|
2002-10-16 02:10:08 +00:00
|
|
|
xform_register(&ipe4_xformsw);
|
|
|
|
/* attach to encapsulation framework */
|
|
|
|
/* XXX save return cookie for detach on module remove */
|
|
|
|
(void) encap_attach_func(AF_INET, -1,
|
2006-03-30 18:57:04 +00:00
|
|
|
ipe4_encapcheck, &ipe4_protosw, NULL);
|
2002-10-16 02:10:08 +00:00
|
|
|
#ifdef INET6
|
|
|
|
(void) encap_attach_func(AF_INET6, -1,
|
2006-03-30 18:57:04 +00:00
|
|
|
ipe4_encapcheck, (struct protosw *)&ipe6_protosw, NULL);
|
2002-10-16 02:10:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
SYSINIT(ipe4_xform_init, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ipe4_attach, NULL);
|
2007-07-03 12:13:45 +00:00
|
|
|
#endif /* IPSEC */
|