2005-01-07 01:45:51 +00:00
|
|
|
/*-
|
2003-11-14 21:02:22 +00:00
|
|
|
* Copyright (c) 2003 Andre Oppermann, Internet Business Solutions AG
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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. The name of the author may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ip_fastforward gets its speed from processing the forwarded packet to
|
|
|
|
* completion (if_output on the other side) without any queues or netisr's.
|
|
|
|
* The receiving interface DMAs the packet into memory, the upper half of
|
|
|
|
* driver calls ip_fastforward, we do our routing table lookup and directly
|
2005-07-23 00:59:13 +00:00
|
|
|
* send it off to the outgoing interface, which DMAs the packet to the
|
2003-11-14 21:02:22 +00:00
|
|
|
* network card. The only part of the packet we touch with the CPU is the
|
2003-11-15 17:03:37 +00:00
|
|
|
* IP header (unless there are complex firewall rules touching other parts
|
|
|
|
* of the packet, but that is up to you). We are essentially limited by bus
|
|
|
|
* bandwidth and how fast the network card/driver can set up receives and
|
|
|
|
* transmits.
|
2003-11-14 21:02:22 +00:00
|
|
|
*
|
2005-07-23 00:59:13 +00:00
|
|
|
* We handle basic errors, IP header errors, checksum errors,
|
2003-11-14 21:02:22 +00:00
|
|
|
* destination unreachable, fragmentation and fragmentation needed and
|
2005-07-23 00:59:13 +00:00
|
|
|
* report them via ICMP to the sender.
|
2003-11-14 21:02:22 +00:00
|
|
|
*
|
|
|
|
* Else if something is not pure IPv4 unicast forwarding we fall back to
|
|
|
|
* the normal ip_input processing path. We should only be called from
|
|
|
|
* interfaces connected to the outside world.
|
|
|
|
*
|
|
|
|
* Firewalling is fully supported including divert, ipfw fwd and ipfilter
|
|
|
|
* ipnat and address rewrite.
|
|
|
|
*
|
|
|
|
* IPSEC is not supported if this host is a tunnel broker. IPSEC is
|
|
|
|
* supported for connections to/from local host.
|
|
|
|
*
|
|
|
|
* We try to do the least expensive (in CPU ops) checks and operations
|
|
|
|
* first to catch junk with as little overhead as possible.
|
|
|
|
*
|
2005-07-23 00:59:13 +00:00
|
|
|
* We take full advantage of hardware support for IP checksum and
|
2003-11-14 21:02:22 +00:00
|
|
|
* fragmentation offloading.
|
|
|
|
*
|
|
|
|
* We don't do ICMP redirect in the fast forwarding path. I have had my own
|
|
|
|
* cases where two core routers with Zebra routing suite would send millions
|
2005-07-23 00:59:13 +00:00
|
|
|
* ICMP redirects to connected hosts if the destination router was not the
|
|
|
|
* default gateway. In one case it was filling the routing table of a host
|
|
|
|
* with approximately 300.000 cloned redirect entries until it ran out of
|
|
|
|
* kernel memory. However the networking code proved very robust and it didn't
|
|
|
|
* crash or fail in other ways.
|
2003-11-14 21:02:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Many thanks to Matt Thomas of NetBSD for basic structure of ip_flow.c which
|
|
|
|
* is being followed here.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 20:44:24 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2003-11-14 21:02:22 +00:00
|
|
|
#include "opt_ipfw.h"
|
|
|
|
#include "opt_ipstealth.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sysctl.h>
|
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
|
|
|
#include <sys/vimage.h>
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
#include <net/pfil.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_var.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
|
|
|
#include <netinet/ip_icmp.h>
|
2005-11-18 20:12:40 +00:00
|
|
|
#include <netinet/ip_options.h>
|
2008-12-02 21:37:28 +00:00
|
|
|
#include <netinet/vinet.h>
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
#include <machine/in_cksum.h>
|
|
|
|
|
2008-11-19 09:39:34 +00:00
|
|
|
#ifdef VIMAGE_GLOBALS
|
|
|
|
static int ipfastforward_active;
|
|
|
|
#endif
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
SYSCTL_V_INT(V_NET, vnet_inet, _net_inet_ip, OID_AUTO, fastforwarding,
|
|
|
|
CTLFLAG_RW, ipfastforward_active, 0, "Enable fast IP forwarding");
|
2003-11-14 21:02:22 +00:00
|
|
|
|
2004-05-03 13:52:47 +00:00
|
|
|
static struct sockaddr_in *
|
2004-08-11 12:32:10 +00:00
|
|
|
ip_findroute(struct route *ro, struct in_addr dest, struct mbuf *m)
|
2004-05-03 13:52:47 +00:00
|
|
|
{
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
INIT_VNET_INET(curvnet);
|
2004-05-03 13:52:47 +00:00
|
|
|
struct sockaddr_in *dst;
|
|
|
|
struct rtentry *rt;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find route to destination.
|
|
|
|
*/
|
|
|
|
bzero(ro, sizeof(*ro));
|
|
|
|
dst = (struct sockaddr_in *)&ro->ro_dst;
|
|
|
|
dst->sin_family = AF_INET;
|
|
|
|
dst->sin_len = sizeof(*dst);
|
2004-08-11 12:32:10 +00:00
|
|
|
dst->sin_addr.s_addr = dest.s_addr;
|
This main goals of this project are:
1. separating L2 tables (ARP, NDP) from the L3 routing tables
2. removing as much locking dependencies among these layers as
possible to allow for some parallelism in the search operations
3. simplify the logic in the routing code,
The most notable end result is the obsolescent of the route
cloning (RTF_CLONING) concept, which translated into code reduction
in both IPv4 ARP and IPv6 NDP related modules, and size reduction in
struct rtentry{}. The change in design obsoletes the semantics of
RTF_CLONING, RTF_WASCLONE and RTF_LLINFO routing flags. The userland
applications such as "arp" and "ndp" have been modified to reflect
those changes. The output from "netstat -r" shows only the routing
entries.
Quite a few developers have contributed to this project in the
past: Glebius Smirnoff, Luigi Rizzo, Alessandro Cerri, and
Andre Oppermann. And most recently:
- Kip Macy revised the locking code completely, thus completing
the last piece of the puzzle, Kip has also been conducting
active functional testing
- Sam Leffler has helped me improving/refactoring the code, and
provided valuable reviews
- Julian Elischer setup the perforce tree for me and has helped
me maintaining that branch before the svn conversion
2008-12-15 06:10:57 +00:00
|
|
|
in_rtalloc_ign(ro, 0, M_GETFIB(m));
|
2004-05-03 13:52:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Route there and interface still up?
|
|
|
|
*/
|
|
|
|
rt = ro->ro_rt;
|
|
|
|
if (rt && (rt->rt_flags & RTF_UP) &&
|
|
|
|
(rt->rt_ifp->if_flags & IFF_UP) &&
|
2005-08-09 10:20:02 +00:00
|
|
|
(rt->rt_ifp->if_drv_flags & IFF_DRV_RUNNING)) {
|
2004-05-03 13:52:47 +00:00
|
|
|
if (rt->rt_flags & RTF_GATEWAY)
|
|
|
|
dst = (struct sockaddr_in *)rt->rt_gateway;
|
|
|
|
} else {
|
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_ipstat.ips_noroute++;
|
|
|
|
V_ipstat.ips_cantforward++;
|
2004-05-03 13:52:47 +00:00
|
|
|
if (rt)
|
|
|
|
RTFREE(rt);
|
2005-05-04 13:09:19 +00:00
|
|
|
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
|
2004-05-03 13:52:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Try to forward a packet based on the destination address.
|
|
|
|
* This is a fast path optimized for the plain forwarding case.
|
|
|
|
* If the packet is handled (and consumed) here then we return 1;
|
|
|
|
* otherwise 0 is returned and the packet should be delivered
|
|
|
|
* to ip_input for full processing.
|
|
|
|
*/
|
2006-01-18 14:24:39 +00:00
|
|
|
struct mbuf *
|
2003-11-14 21:02:22 +00:00
|
|
|
ip_fastforward(struct mbuf *m)
|
|
|
|
{
|
Step 1.5 of importing the network stack virtualization infrastructure
from the vimage project, as per plan established at devsummit 08/08:
http://wiki.freebsd.org/Image/Notes200808DevSummit
Introduce INIT_VNET_*() initializer macros, VNET_FOREACH() iterator
macros, and CURVNET_SET() context setting macros, all currently
resolving to NOPs.
Prepare for virtualization of selected SYSCTL objects by introducing a
family of SYSCTL_V_*() macros, currently resolving to their global
counterparts, i.e. SYSCTL_V_INT() == SYSCTL_INT().
Move selected #defines from sys/sys/vimage.h to newly introduced header
files specific to virtualized subsystems (sys/net/vnet.h,
sys/netinet/vinet.h etc.).
All the changes are verified to have zero functional impact at this
point in time by doing MD5 comparision between pre- and post-change
object files(*).
(*) netipsec/keysock.c did not validate depending on compile time options.
Implemented by: julian, bz, brooks, zec
Reviewed by: julian, bz, brooks, kris, rwatson, ...
Approved by: julian (mentor)
Obtained from: //depot/projects/vimage-commit2/...
X-MFC after: never
Sponsored by: NLnet Foundation, The FreeBSD Foundation
2008-10-02 15:37:58 +00:00
|
|
|
INIT_VNET_INET(curvnet);
|
2003-11-14 21:02:22 +00:00
|
|
|
struct ip *ip;
|
|
|
|
struct mbuf *m0 = NULL;
|
|
|
|
struct route ro;
|
|
|
|
struct sockaddr_in *dst = NULL;
|
2004-05-03 13:52:47 +00:00
|
|
|
struct ifnet *ifp;
|
2004-08-11 12:32:10 +00:00
|
|
|
struct in_addr odest, dest;
|
2004-05-03 13:52:47 +00:00
|
|
|
u_short sum, ip_len;
|
2003-11-14 21:02:22 +00:00
|
|
|
int error = 0;
|
2004-08-17 22:05:54 +00:00
|
|
|
int hlen, mtu;
|
|
|
|
#ifdef IPFIREWALL_FORWARD
|
|
|
|
struct m_tag *fwd_tag;
|
|
|
|
#endif
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Are we active and forwarding packets?
|
|
|
|
*/
|
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_ipfastforward_active || !V_ipforwarding)
|
2006-01-18 14:24:39 +00:00
|
|
|
return m;
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
M_ASSERTVALID(m);
|
|
|
|
M_ASSERTPKTHDR(m);
|
|
|
|
|
2004-05-03 13:52:47 +00:00
|
|
|
ro.ro_rt = NULL;
|
|
|
|
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Step 1: check for packet drop conditions (and sanity checks)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is entire packet big enough?
|
|
|
|
*/
|
|
|
|
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_ipstat.ips_tooshort++;
|
2003-11-14 21:02:22 +00:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is first mbuf large enough for ip header and is header present?
|
|
|
|
*/
|
|
|
|
if (m->m_len < sizeof (struct ip) &&
|
2004-11-06 10:47:36 +00:00
|
|
|
(m = m_pullup(m, sizeof (struct ip))) == NULL) {
|
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_ipstat.ips_toosmall++;
|
2006-01-18 14:24:39 +00:00
|
|
|
return NULL; /* mbuf already free'd */
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is it IPv4?
|
|
|
|
*/
|
|
|
|
if (ip->ip_v != IPVERSION) {
|
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_ipstat.ips_badvers++;
|
2003-11-14 21:02:22 +00:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is IP header length correct and is it in first mbuf?
|
|
|
|
*/
|
|
|
|
hlen = ip->ip_hl << 2;
|
|
|
|
if (hlen < sizeof(struct ip)) { /* minimum header length */
|
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_ipstat.ips_badlen++;
|
2003-11-14 21:02:22 +00:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
if (hlen > m->m_len) {
|
2006-01-18 14:24:39 +00:00
|
|
|
if ((m = m_pullup(m, hlen)) == NULL) {
|
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_ipstat.ips_badhlen++;
|
2006-01-18 14:24:39 +00:00
|
|
|
return NULL; /* mbuf already free'd */
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Checksum correct?
|
|
|
|
*/
|
|
|
|
if (m->m_pkthdr.csum_flags & CSUM_IP_CHECKED)
|
|
|
|
sum = !(m->m_pkthdr.csum_flags & CSUM_IP_VALID);
|
|
|
|
else {
|
|
|
|
if (hlen == sizeof(struct ip))
|
|
|
|
sum = in_cksum_hdr(ip);
|
|
|
|
else
|
|
|
|
sum = in_cksum(m, hlen);
|
|
|
|
}
|
|
|
|
if (sum) {
|
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_ipstat.ips_badsum++;
|
2003-11-14 21:02:22 +00:00
|
|
|
goto drop;
|
|
|
|
}
|
2004-10-19 14:31:56 +00:00
|
|
|
|
|
|
|
/*
|
2005-07-23 00:59:13 +00:00
|
|
|
* Remember that we have checked the IP header and found it valid.
|
2004-10-19 14:31:56 +00:00
|
|
|
*/
|
2003-11-14 21:02:22 +00:00
|
|
|
m->m_pkthdr.csum_flags |= (CSUM_IP_CHECKED | CSUM_IP_VALID);
|
|
|
|
|
2004-05-03 13:52:47 +00:00
|
|
|
ip_len = ntohs(ip->ip_len);
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Is IP length longer than packet we have got?
|
|
|
|
*/
|
2004-05-03 13:52:47 +00:00
|
|
|
if (m->m_pkthdr.len < ip_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
|
|
|
V_ipstat.ips_tooshort++;
|
2003-11-14 21:02:22 +00:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is packet longer than IP header tells us? If yes, truncate packet.
|
|
|
|
*/
|
2004-05-03 13:52:47 +00:00
|
|
|
if (m->m_pkthdr.len > ip_len) {
|
2003-11-14 21:02:22 +00:00
|
|
|
if (m->m_len == m->m_pkthdr.len) {
|
2004-05-03 13:52:47 +00:00
|
|
|
m->m_len = ip_len;
|
|
|
|
m->m_pkthdr.len = ip_len;
|
2003-11-14 21:02:22 +00:00
|
|
|
} else
|
2004-05-03 13:52:47 +00:00
|
|
|
m_adj(m, ip_len - m->m_pkthdr.len);
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is packet from or to 127/8?
|
|
|
|
*/
|
|
|
|
if ((ntohl(ip->ip_dst.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET ||
|
|
|
|
(ntohl(ip->ip_src.s_addr) >> IN_CLASSA_NSHIFT) == IN_LOOPBACKNET) {
|
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_ipstat.ips_badaddr++;
|
2003-11-14 21:02:22 +00:00
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
|
2004-08-11 10:42:59 +00:00
|
|
|
#ifdef ALTQ
|
|
|
|
/*
|
|
|
|
* Is packet dropped by traffic conditioner?
|
|
|
|
*/
|
|
|
|
if (altq_input != NULL && (*altq_input)(m, AF_INET) == 0)
|
2006-01-18 14:24:39 +00:00
|
|
|
goto drop;
|
2004-08-11 10:42:59 +00:00
|
|
|
#endif
|
|
|
|
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Step 2: fallback conditions to normal ip_input path processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Only IP packets without options
|
|
|
|
*/
|
2004-05-06 18:46:03 +00:00
|
|
|
if (ip->ip_hl != (sizeof(struct ip) >> 2)) {
|
|
|
|
if (ip_doopts == 1)
|
2006-01-18 14:24:39 +00:00
|
|
|
return m;
|
2004-05-06 18:46:03 +00:00
|
|
|
else if (ip_doopts == 2) {
|
|
|
|
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_FILTER_PROHIB,
|
2005-05-04 13:09:19 +00:00
|
|
|
0, 0);
|
2006-01-18 14:24:39 +00:00
|
|
|
return NULL; /* mbuf already free'd */
|
2004-05-06 18:46:03 +00:00
|
|
|
}
|
|
|
|
/* else ignore IP options and continue */
|
|
|
|
}
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only unicast IP, not from loopback, no L2 or IP broadcast,
|
|
|
|
* no multicast, no INADDR_ANY
|
|
|
|
*
|
|
|
|
* XXX: Probably some of these checks could be direct drop
|
|
|
|
* conditions. However it is not clear whether there are some
|
|
|
|
* hacks or obscure behaviours which make it neccessary to
|
|
|
|
* let ip_input handle it. We play safe here and let ip_input
|
|
|
|
* deal with it until it is proven that we can directly drop it.
|
|
|
|
*/
|
2005-08-22 12:06:26 +00:00
|
|
|
if ((m->m_flags & (M_BCAST|M_MCAST)) ||
|
|
|
|
(m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) ||
|
2003-11-14 21:02:22 +00:00
|
|
|
ntohl(ip->ip_src.s_addr) == (u_long)INADDR_BROADCAST ||
|
|
|
|
ntohl(ip->ip_dst.s_addr) == (u_long)INADDR_BROADCAST ||
|
|
|
|
IN_MULTICAST(ntohl(ip->ip_src.s_addr)) ||
|
|
|
|
IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) ||
|
2007-02-03 06:46:48 +00:00
|
|
|
IN_LINKLOCAL(ntohl(ip->ip_src.s_addr)) ||
|
|
|
|
IN_LINKLOCAL(ntohl(ip->ip_dst.s_addr)) ||
|
2005-08-22 12:06:26 +00:00
|
|
|
ip->ip_src.s_addr == INADDR_ANY ||
|
2003-11-14 21:02:22 +00:00
|
|
|
ip->ip_dst.s_addr == INADDR_ANY )
|
2006-01-18 14:24:39 +00:00
|
|
|
return m;
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Is it for a local address on this host?
|
|
|
|
*/
|
2004-08-11 12:32:10 +00:00
|
|
|
if (in_localip(ip->ip_dst))
|
2006-01-18 14:24:39 +00:00
|
|
|
return m;
|
2003-11-14 21:02:22 +00:00
|
|
|
|
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_ipstat.ips_total++;
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Step 3: incoming packet firewall processing
|
|
|
|
*/
|
|
|
|
|
2004-05-03 13:52:47 +00:00
|
|
|
/*
|
|
|
|
* Convert to host representation
|
|
|
|
*/
|
|
|
|
ip->ip_len = ntohs(ip->ip_len);
|
|
|
|
ip->ip_off = ntohs(ip->ip_off);
|
|
|
|
|
2004-08-11 12:32:10 +00:00
|
|
|
odest.s_addr = dest.s_addr = ip->ip_dst.s_addr;
|
2004-08-27 15:16:24 +00:00
|
|
|
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Run through list of ipfilter hooks for input packets
|
|
|
|
*/
|
2006-02-02 03:13:16 +00:00
|
|
|
if (!PFIL_HOOKED(&inet_pfil_hook))
|
2004-08-27 15:16:24 +00:00
|
|
|
goto passin;
|
|
|
|
|
2004-09-29 04:54:33 +00:00
|
|
|
if (pfil_run_hooks(&inet_pfil_hook, &m, m->m_pkthdr.rcvif, PFIL_IN, NULL) ||
|
2003-11-14 21:02:22 +00:00
|
|
|
m == NULL)
|
2006-01-18 14:24:39 +00:00
|
|
|
goto drop;
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
M_ASSERTVALID(m);
|
|
|
|
M_ASSERTPKTHDR(m);
|
|
|
|
|
|
|
|
ip = mtod(m, struct ip *); /* m may have changed by pfil hook */
|
2004-08-11 12:32:10 +00:00
|
|
|
dest.s_addr = ip->ip_dst.s_addr;
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Destination address changed?
|
|
|
|
*/
|
2004-08-11 12:32:10 +00:00
|
|
|
if (odest.s_addr != dest.s_addr) {
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Is it now for a local address on this host?
|
|
|
|
*/
|
2004-08-11 12:32:10 +00:00
|
|
|
if (in_localip(dest))
|
|
|
|
goto forwardlocal;
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Go on with new destination address
|
|
|
|
*/
|
|
|
|
}
|
2004-08-17 22:05:54 +00:00
|
|
|
#ifdef IPFIREWALL_FORWARD
|
|
|
|
if (m->m_flags & M_FASTFWD_OURS) {
|
|
|
|
/*
|
|
|
|
* ipfw changed it for a local address on this host.
|
|
|
|
*/
|
|
|
|
goto forwardlocal;
|
|
|
|
}
|
|
|
|
#endif /* IPFIREWALL_FORWARD */
|
2003-11-14 21:02:22 +00:00
|
|
|
|
2004-08-27 15:16:24 +00:00
|
|
|
passin:
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Step 4: decrement TTL and look up route
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check TTL
|
|
|
|
*/
|
|
|
|
#ifdef IPSTEALTH
|
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_ipstealth) {
|
2003-11-14 21:02:22 +00:00
|
|
|
#endif
|
|
|
|
if (ip->ip_ttl <= IPTTLDEC) {
|
2005-05-04 13:09:19 +00:00
|
|
|
icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, 0, 0);
|
2006-01-18 14:24:39 +00:00
|
|
|
return NULL; /* mbuf already free'd */
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-10-19 14:31:56 +00:00
|
|
|
* Decrement the TTL and incrementally change the IP header checksum.
|
|
|
|
* Don't bother doing this with hw checksum offloading, it's faster
|
|
|
|
* doing it right here.
|
2003-11-14 21:02:22 +00:00
|
|
|
*/
|
|
|
|
ip->ip_ttl -= IPTTLDEC;
|
|
|
|
if (ip->ip_sum >= (u_int16_t) ~htons(IPTTLDEC << 8))
|
|
|
|
ip->ip_sum -= ~htons(IPTTLDEC << 8);
|
|
|
|
else
|
|
|
|
ip->ip_sum += htons(IPTTLDEC << 8);
|
|
|
|
#ifdef IPSTEALTH
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find route to destination.
|
|
|
|
*/
|
2004-05-03 13:52:47 +00:00
|
|
|
if ((dst = ip_findroute(&ro, dest, m)) == NULL)
|
2006-01-18 14:24:39 +00:00
|
|
|
return NULL; /* icmp unreach already sent */
|
2004-05-03 13:52:47 +00:00
|
|
|
ifp = ro.ro_rt->rt_ifp;
|
2003-11-14 21:02:22 +00:00
|
|
|
|
2004-11-04 02:14:38 +00:00
|
|
|
/*
|
2007-02-05 00:15:40 +00:00
|
|
|
* Immediately drop blackholed traffic, and directed broadcasts
|
|
|
|
* for either the all-ones or all-zero subnet addresses on
|
|
|
|
* locally attached networks.
|
2004-11-04 02:14:38 +00:00
|
|
|
*/
|
2007-02-05 00:15:40 +00:00
|
|
|
if ((ro.ro_rt->rt_flags & (RTF_BLACKHOLE|RTF_BROADCAST)) != 0)
|
2004-11-04 02:14:38 +00:00
|
|
|
goto drop;
|
|
|
|
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Step 5: outgoing firewall packet processing
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run through list of hooks for output packets.
|
|
|
|
*/
|
2006-02-02 03:13:16 +00:00
|
|
|
if (!PFIL_HOOKED(&inet_pfil_hook))
|
2004-08-27 15:16:24 +00:00
|
|
|
goto passout;
|
|
|
|
|
2004-09-29 04:54:33 +00:00
|
|
|
if (pfil_run_hooks(&inet_pfil_hook, &m, ifp, PFIL_OUT, NULL) || m == NULL) {
|
2006-01-18 14:24:39 +00:00
|
|
|
goto drop;
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
M_ASSERTVALID(m);
|
|
|
|
M_ASSERTPKTHDR(m);
|
|
|
|
|
|
|
|
ip = mtod(m, struct ip *);
|
2004-08-11 12:32:10 +00:00
|
|
|
dest.s_addr = ip->ip_dst.s_addr;
|
2003-11-14 21:02:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Destination address changed?
|
|
|
|
*/
|
2004-08-17 22:05:54 +00:00
|
|
|
#ifndef IPFIREWALL_FORWARD
|
2004-08-11 12:32:10 +00:00
|
|
|
if (odest.s_addr != dest.s_addr) {
|
2004-08-17 22:05:54 +00:00
|
|
|
#else
|
|
|
|
fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL);
|
|
|
|
if (odest.s_addr != dest.s_addr || fwd_tag != NULL) {
|
|
|
|
#endif /* IPFIREWALL_FORWARD */
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Is it now for a local address on this host?
|
|
|
|
*/
|
2004-08-17 22:05:54 +00:00
|
|
|
#ifndef IPFIREWALL_FORWARD
|
2004-08-11 12:32:10 +00:00
|
|
|
if (in_localip(dest)) {
|
2004-08-17 22:05:54 +00:00
|
|
|
#else
|
2004-10-19 14:31:56 +00:00
|
|
|
if (m->m_flags & M_FASTFWD_OURS || in_localip(dest)) {
|
2004-08-17 22:05:54 +00:00
|
|
|
#endif /* IPFIREWALL_FORWARD */
|
2003-11-14 21:02:22 +00:00
|
|
|
forwardlocal:
|
2004-08-11 12:32:10 +00:00
|
|
|
/*
|
2004-09-13 17:01:53 +00:00
|
|
|
* Return packet for processing by ip_input().
|
|
|
|
* Keep host byte order as expected at ip_input's
|
|
|
|
* "ours"-label.
|
2004-08-11 12:32:10 +00:00
|
|
|
*/
|
2004-09-13 17:01:53 +00:00
|
|
|
m->m_flags |= M_FASTFWD_OURS;
|
2004-08-11 12:32:10 +00:00
|
|
|
if (ro.ro_rt)
|
|
|
|
RTFREE(ro.ro_rt);
|
2006-01-18 14:24:39 +00:00
|
|
|
return m;
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Redo route lookup with new destination address
|
|
|
|
*/
|
2004-08-17 22:05:54 +00:00
|
|
|
#ifdef IPFIREWALL_FORWARD
|
|
|
|
if (fwd_tag) {
|
2006-08-17 00:37:03 +00:00
|
|
|
dest.s_addr = ((struct sockaddr_in *)
|
2006-04-18 09:20:16 +00:00
|
|
|
(fwd_tag + 1))->sin_addr.s_addr;
|
2004-08-17 22:05:54 +00:00
|
|
|
m_tag_delete(m, fwd_tag);
|
|
|
|
}
|
|
|
|
#endif /* IPFIREWALL_FORWARD */
|
2003-11-14 21:02:22 +00:00
|
|
|
RTFREE(ro.ro_rt);
|
2004-05-03 13:52:47 +00:00
|
|
|
if ((dst = ip_findroute(&ro, dest, m)) == NULL)
|
2006-01-18 14:24:39 +00:00
|
|
|
return NULL; /* icmp unreach already sent */
|
2004-05-03 13:52:47 +00:00
|
|
|
ifp = ro.ro_rt->rt_ifp;
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
|
|
|
|
2004-08-27 15:16:24 +00:00
|
|
|
passout:
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
|
|
|
* Step 6: send off the packet
|
|
|
|
*/
|
|
|
|
|
2004-05-03 13:52:47 +00:00
|
|
|
/*
|
|
|
|
* Check if route is dampned (when ARP is unable to resolve)
|
|
|
|
*/
|
|
|
|
if ((ro.ro_rt->rt_flags & RTF_REJECT) &&
|
2007-03-18 23:05:20 +00:00
|
|
|
(ro.ro_rt->rt_rmx.rmx_expire == 0 ||
|
|
|
|
time_uptime < ro.ro_rt->rt_rmx.rmx_expire)) {
|
2005-05-04 13:09:19 +00:00
|
|
|
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
|
2004-05-03 13:52:47 +00:00
|
|
|
goto consumed;
|
|
|
|
}
|
|
|
|
|
2004-08-11 10:42:59 +00:00
|
|
|
#ifndef ALTQ
|
2004-05-03 13:52:47 +00:00
|
|
|
/*
|
|
|
|
* Check if there is enough space in the interface queue
|
|
|
|
*/
|
|
|
|
if ((ifp->if_snd.ifq_len + ip->ip_len / ifp->if_mtu + 1) >=
|
|
|
|
ifp->if_snd.ifq_maxlen) {
|
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_ipstat.ips_odropped++;
|
2004-05-03 13:52:47 +00:00
|
|
|
/* would send source quench here but that is depreciated */
|
|
|
|
goto drop;
|
|
|
|
}
|
2004-08-11 10:42:59 +00:00
|
|
|
#endif
|
2004-05-03 13:52:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if media link state of interface is not down
|
|
|
|
*/
|
|
|
|
if (ifp->if_link_state == LINK_STATE_DOWN) {
|
2005-05-04 13:09:19 +00:00
|
|
|
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
|
2004-05-03 13:52:47 +00:00
|
|
|
goto consumed;
|
|
|
|
}
|
|
|
|
|
2003-11-14 21:02:22 +00:00
|
|
|
/*
|
2005-07-23 00:59:13 +00:00
|
|
|
* Check if packet fits MTU or if hardware will fragment for us
|
2003-11-14 21:02:22 +00:00
|
|
|
*/
|
|
|
|
if (ro.ro_rt->rt_rmx.rmx_mtu)
|
|
|
|
mtu = min(ro.ro_rt->rt_rmx.rmx_mtu, ifp->if_mtu);
|
|
|
|
else
|
|
|
|
mtu = ifp->if_mtu;
|
|
|
|
|
|
|
|
if (ip->ip_len <= mtu ||
|
|
|
|
(ifp->if_hwassist & CSUM_FRAGMENT && (ip->ip_off & IP_DF) == 0)) {
|
|
|
|
/*
|
|
|
|
* Restore packet header fields to original values
|
|
|
|
*/
|
|
|
|
ip->ip_len = htons(ip->ip_len);
|
|
|
|
ip->ip_off = htons(ip->ip_off);
|
|
|
|
/*
|
|
|
|
* Send off the packet via outgoing interface
|
|
|
|
*/
|
|
|
|
error = (*ifp->if_output)(ifp, m,
|
|
|
|
(struct sockaddr *)dst, ro.ro_rt);
|
|
|
|
} else {
|
|
|
|
/*
|
2004-05-03 13:52:47 +00:00
|
|
|
* Handle EMSGSIZE with icmp reply needfrag for TCP MTU discovery
|
2003-11-14 21:02:22 +00:00
|
|
|
*/
|
|
|
|
if (ip->ip_off & IP_DF) {
|
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_ipstat.ips_cantfrag++;
|
2003-11-14 21:02:22 +00:00
|
|
|
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_NEEDFRAG,
|
2005-05-04 13:09:19 +00:00
|
|
|
0, mtu);
|
2004-05-03 13:52:47 +00:00
|
|
|
goto consumed;
|
2003-11-14 21:02:22 +00:00
|
|
|
} else {
|
|
|
|
/*
|
2005-07-23 00:59:13 +00:00
|
|
|
* We have to fragment the packet
|
2003-11-14 21:02:22 +00:00
|
|
|
*/
|
|
|
|
m->m_pkthdr.csum_flags |= CSUM_IP;
|
2004-05-03 13:52:47 +00:00
|
|
|
/*
|
|
|
|
* ip_fragment expects ip_len and ip_off in host byte
|
|
|
|
* order but returns all packets in network byte order
|
|
|
|
*/
|
2003-11-14 21:02:22 +00:00
|
|
|
if (ip_fragment(ip, &m, mtu, ifp->if_hwassist,
|
|
|
|
(~ifp->if_hwassist & CSUM_DELAY_IP))) {
|
|
|
|
goto drop;
|
|
|
|
}
|
|
|
|
KASSERT(m != NULL, ("null mbuf and no error"));
|
|
|
|
/*
|
|
|
|
* Send off the fragments via outgoing interface
|
|
|
|
*/
|
|
|
|
error = 0;
|
|
|
|
do {
|
|
|
|
m0 = m->m_nextpkt;
|
|
|
|
m->m_nextpkt = NULL;
|
|
|
|
|
|
|
|
error = (*ifp->if_output)(ifp, m,
|
|
|
|
(struct sockaddr *)dst, ro.ro_rt);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
} while ((m = m0) != NULL);
|
|
|
|
if (error) {
|
|
|
|
/* Reclaim remaining fragments */
|
2005-03-29 13:43:09 +00:00
|
|
|
for (m = m0; m; m = m0) {
|
2003-11-14 21:02:22 +00:00
|
|
|
m0 = m->m_nextpkt;
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
} else
|
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_ipstat.ips_fragmented++;
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error != 0)
|
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_ipstat.ips_odropped++;
|
2003-11-14 21:02:22 +00:00
|
|
|
else {
|
|
|
|
ro.ro_rt->rt_rmx.rmx_pksent++;
|
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_ipstat.ips_forward++;
|
|
|
|
V_ipstat.ips_fastforward++;
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|
2004-05-03 13:52:47 +00:00
|
|
|
consumed:
|
2003-11-14 21:02:22 +00:00
|
|
|
RTFREE(ro.ro_rt);
|
2006-01-18 14:24:39 +00:00
|
|
|
return NULL;
|
2003-11-14 21:02:22 +00:00
|
|
|
drop:
|
|
|
|
if (m)
|
|
|
|
m_freem(m);
|
2004-05-03 13:52:47 +00:00
|
|
|
if (ro.ro_rt)
|
|
|
|
RTFREE(ro.ro_rt);
|
2006-01-18 14:24:39 +00:00
|
|
|
return NULL;
|
2003-11-14 21:02:22 +00:00
|
|
|
}
|