2012-12-28 09:19:49 +00:00
|
|
|
/*-
|
2004-02-26 02:04:28 +00:00
|
|
|
* Copyright 2001 Niels Provos <provos@citi.umich.edu>
|
2015-02-16 03:38:27 +00:00
|
|
|
* Copyright 2011 Alexander Bluhm <bluhm@openbsd.org>
|
2004-02-26 02:04:28 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 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.
|
2012-12-28 09:19:49 +00:00
|
|
|
*
|
|
|
|
* $OpenBSD: pf_norm.c,v 1.114 2009/01/29 14:11:45 henning Exp $
|
2004-02-26 02:04:28 +00:00
|
|
|
*/
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#include "opt_inet.h"
|
|
|
|
#include "opt_inet6.h"
|
|
|
|
#include "opt_pf.h"
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2015-05-19 14:04:21 +00:00
|
|
|
#include <sys/kernel.h>
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#include <sys/lock.h>
|
2004-02-26 02:04:28 +00:00
|
|
|
#include <sys/mbuf.h>
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/refcount.h>
|
|
|
|
#include <sys/rwlock.h>
|
2004-02-26 02:04:28 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <net/if.h>
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#include <net/vnet.h>
|
|
|
|
#include <net/pfvar.h>
|
2004-02-26 02:04:28 +00:00
|
|
|
#include <net/if_pflog.h>
|
|
|
|
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <netinet/ip_var.h>
|
2015-02-16 03:38:27 +00:00
|
|
|
#include <netinet6/ip6_var.h>
|
2004-02-26 02:04:28 +00:00
|
|
|
#include <netinet/tcp.h>
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#include <netinet/tcp_fsm.h>
|
2004-02-26 02:04:28 +00:00
|
|
|
#include <netinet/tcp_seq.h>
|
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
#include <netinet/ip6.h>
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
|
|
|
struct pf_frent {
|
2015-02-16 03:38:27 +00:00
|
|
|
TAILQ_ENTRY(pf_frent) fr_next;
|
|
|
|
struct mbuf *fe_m;
|
2016-05-03 18:05:43 +00:00
|
|
|
uint16_t fe_hdrlen; /* ipv4 header length with ip options
|
2015-02-16 03:38:27 +00:00
|
|
|
ipv6, extension, fragment header */
|
|
|
|
uint16_t fe_extoff; /* last extension header offset or 0 */
|
|
|
|
uint16_t fe_len; /* fragment length */
|
|
|
|
uint16_t fe_off; /* fragment offset */
|
|
|
|
uint16_t fe_mff; /* more fragment flag */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pf_fragment_cmp {
|
|
|
|
struct pf_addr frc_src;
|
|
|
|
struct pf_addr frc_dst;
|
|
|
|
uint32_t frc_id;
|
|
|
|
sa_family_t frc_af;
|
|
|
|
uint8_t frc_proto;
|
2004-02-26 02:04:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct pf_fragment {
|
2015-02-16 03:38:27 +00:00
|
|
|
struct pf_fragment_cmp fr_key;
|
|
|
|
#define fr_src fr_key.frc_src
|
|
|
|
#define fr_dst fr_key.frc_dst
|
|
|
|
#define fr_id fr_key.frc_id
|
|
|
|
#define fr_af fr_key.frc_af
|
|
|
|
#define fr_proto fr_key.frc_proto
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
RB_ENTRY(pf_fragment) fr_entry;
|
|
|
|
TAILQ_ENTRY(pf_fragment) frag_next;
|
2015-02-16 03:38:27 +00:00
|
|
|
uint32_t fr_timeout;
|
|
|
|
uint16_t fr_maxlen; /* maximum length of single fragment */
|
|
|
|
TAILQ_HEAD(pf_fragq, pf_frent) fr_queue;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pf_fragment_tag {
|
|
|
|
uint16_t ft_hdrlen; /* header length of reassembled pkt */
|
|
|
|
uint16_t ft_extoff; /* last extension header offset or 0 */
|
|
|
|
uint16_t ft_maxlen; /* maximum fragment payload length */
|
2015-04-01 12:15:01 +00:00
|
|
|
uint32_t ft_id; /* fragment id */
|
2004-02-26 02:04:28 +00:00
|
|
|
};
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static struct mtx pf_frag_mtx;
|
2015-05-19 14:04:21 +00:00
|
|
|
MTX_SYSINIT(pf_frag_mtx, &pf_frag_mtx, "pf fragments", MTX_DEF);
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#define PF_FRAG_LOCK() mtx_lock(&pf_frag_mtx)
|
|
|
|
#define PF_FRAG_UNLOCK() mtx_unlock(&pf_frag_mtx)
|
|
|
|
#define PF_FRAG_ASSERT() mtx_assert(&pf_frag_mtx, MA_OWNED)
|
|
|
|
|
|
|
|
VNET_DEFINE(uma_zone_t, pf_state_scrub_z); /* XXX: shared with pfsync */
|
|
|
|
|
|
|
|
static VNET_DEFINE(uma_zone_t, pf_frent_z);
|
|
|
|
#define V_pf_frent_z VNET(pf_frent_z)
|
|
|
|
static VNET_DEFINE(uma_zone_t, pf_frag_z);
|
|
|
|
#define V_pf_frag_z VNET(pf_frag_z)
|
|
|
|
|
2011-06-28 11:57:25 +00:00
|
|
|
TAILQ_HEAD(pf_fragqueue, pf_fragment);
|
|
|
|
TAILQ_HEAD(pf_cachequeue, pf_fragment);
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static VNET_DEFINE(struct pf_fragqueue, pf_fragqueue);
|
2011-06-28 11:57:25 +00:00
|
|
|
#define V_pf_fragqueue VNET(pf_fragqueue)
|
|
|
|
RB_HEAD(pf_frag_tree, pf_fragment);
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static VNET_DEFINE(struct pf_frag_tree, pf_frag_tree);
|
2011-06-28 11:57:25 +00:00
|
|
|
#define V_pf_frag_tree VNET(pf_frag_tree)
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static int pf_frag_compare(struct pf_fragment *,
|
|
|
|
struct pf_fragment *);
|
|
|
|
static RB_PROTOTYPE(pf_frag_tree, pf_fragment, fr_entry, pf_frag_compare);
|
|
|
|
static RB_GENERATE(pf_frag_tree, pf_fragment, fr_entry, pf_frag_compare);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-17 22:33:22 +00:00
|
|
|
static void pf_flush_fragments(void);
|
2015-02-16 23:50:53 +00:00
|
|
|
static void pf_free_fragment(struct pf_fragment *);
|
|
|
|
static void pf_remove_fragment(struct pf_fragment *);
|
|
|
|
static int pf_normalize_tcpopt(struct pf_rule *, struct mbuf *,
|
|
|
|
struct tcphdr *, int, sa_family_t);
|
2015-02-17 22:33:22 +00:00
|
|
|
static struct pf_frent *pf_create_fragment(u_short *);
|
|
|
|
static struct pf_fragment *pf_find_fragment(struct pf_fragment_cmp *key,
|
2015-02-16 23:50:53 +00:00
|
|
|
struct pf_frag_tree *tree);
|
2015-02-17 22:33:22 +00:00
|
|
|
static struct pf_fragment *pf_fillup_fragment(struct pf_fragment_cmp *,
|
|
|
|
struct pf_frent *, u_short *);
|
2015-02-16 23:50:53 +00:00
|
|
|
static int pf_isfull_fragment(struct pf_fragment *);
|
2015-02-17 22:33:22 +00:00
|
|
|
static struct mbuf *pf_join_fragment(struct pf_fragment *);
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#ifdef INET
|
2015-02-16 23:50:53 +00:00
|
|
|
static void pf_scrub_ip(struct mbuf **, uint32_t, uint8_t, uint8_t);
|
|
|
|
static int pf_reassemble(struct mbuf **, struct ip *, int, u_short *);
|
|
|
|
#endif /* INET */
|
2011-06-28 11:57:25 +00:00
|
|
|
#ifdef INET6
|
2015-02-16 23:50:53 +00:00
|
|
|
static int pf_reassemble6(struct mbuf **, struct ip6_hdr *,
|
2015-06-11 17:57:47 +00:00
|
|
|
struct ip6_frag *, uint16_t, uint16_t, u_short *);
|
2015-02-16 23:50:53 +00:00
|
|
|
static void pf_scrub_ip6(struct mbuf **, uint8_t);
|
|
|
|
#endif /* INET6 */
|
|
|
|
|
2011-06-28 11:57:25 +00:00
|
|
|
#define DPFPRINTF(x) do { \
|
|
|
|
if (V_pf_status.debug >= PF_DEBUG_MISC) { \
|
|
|
|
printf("%s: ", __func__); \
|
|
|
|
printf x ; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 23:50:53 +00:00
|
|
|
#ifdef INET
|
2015-02-16 03:38:27 +00:00
|
|
|
static void
|
|
|
|
pf_ip2key(struct ip *ip, int dir, struct pf_fragment_cmp *key)
|
|
|
|
{
|
|
|
|
|
|
|
|
key->frc_src.v4 = ip->ip_src;
|
|
|
|
key->frc_dst.v4 = ip->ip_dst;
|
|
|
|
key->frc_af = AF_INET;
|
|
|
|
key->frc_proto = ip->ip_p;
|
|
|
|
key->frc_id = ip->ip_id;
|
|
|
|
}
|
2015-02-16 23:50:53 +00:00
|
|
|
#endif /* INET */
|
2015-02-16 03:38:27 +00:00
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
void
|
Back out r276841, r276756, r276747, r276746. The change in r276747 is very
very questionable, since it makes vimages more dependent on each other. But
the reason for the backout is that it screwed up shutting down the pf purge
threads, and now kernel immedially panics on pf module unload. Although module
unloading isn't an advertised feature of pf, it is very important for
development process.
I'd like to not backout r276746, since in general it is good. But since it
has introduced numerous build breakages, that later were addressed in
r276841, r276756, r276747, I need to back it out as well. Better replay it
in clean fashion from scratch.
2015-01-22 01:23:16 +00:00
|
|
|
pf_normalize_init(void)
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
V_pf_frag_z = uma_zcreate("pf frags", sizeof(struct pf_fragment),
|
|
|
|
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
|
|
|
|
V_pf_frent_z = uma_zcreate("pf frag entries", sizeof(struct pf_frent),
|
|
|
|
NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
|
|
|
|
V_pf_state_scrub_z = uma_zcreate("pf state scrubs",
|
|
|
|
sizeof(struct pf_state_scrub), NULL, NULL, NULL, NULL,
|
|
|
|
UMA_ALIGN_PTR, 0);
|
|
|
|
|
|
|
|
V_pf_limits[PF_LIMIT_FRAGS].zone = V_pf_frent_z;
|
|
|
|
V_pf_limits[PF_LIMIT_FRAGS].limit = PFFRAG_FRENT_HIWAT;
|
|
|
|
uma_zone_set_max(V_pf_frent_z, PFFRAG_FRENT_HIWAT);
|
2012-12-17 10:10:13 +00:00
|
|
|
uma_zone_set_warning(V_pf_frent_z, "PF frag entries limit reached");
|
Back out r276841, r276756, r276747, r276746. The change in r276747 is very
very questionable, since it makes vimages more dependent on each other. But
the reason for the backout is that it screwed up shutting down the pf purge
threads, and now kernel immedially panics on pf module unload. Although module
unloading isn't an advertised feature of pf, it is very important for
development process.
I'd like to not backout r276746, since in general it is good. But since it
has introduced numerous build breakages, that later were addressed in
r276841, r276756, r276747, I need to back it out as well. Better replay it
in clean fashion from scratch.
2015-01-22 01:23:16 +00:00
|
|
|
|
2011-06-28 11:57:25 +00:00
|
|
|
TAILQ_INIT(&V_pf_fragqueue);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
void
|
|
|
|
pf_normalize_cleanup(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
uma_zdestroy(V_pf_state_scrub_z);
|
|
|
|
uma_zdestroy(V_pf_frent_z);
|
|
|
|
uma_zdestroy(V_pf_frag_z);
|
|
|
|
}
|
|
|
|
|
2004-02-29 16:34:43 +00:00
|
|
|
static int
|
2004-02-26 02:04:28 +00:00
|
|
|
pf_frag_compare(struct pf_fragment *a, struct pf_fragment *b)
|
|
|
|
{
|
|
|
|
int diff;
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
if ((diff = a->fr_id - b->fr_id) != 0)
|
2004-02-26 02:04:28 +00:00
|
|
|
return (diff);
|
2015-02-16 03:38:27 +00:00
|
|
|
if ((diff = a->fr_proto - b->fr_proto) != 0)
|
|
|
|
return (diff);
|
|
|
|
if ((diff = a->fr_af - b->fr_af) != 0)
|
|
|
|
return (diff);
|
|
|
|
if ((diff = pf_addr_cmp(&a->fr_src, &b->fr_src, a->fr_af)) != 0)
|
|
|
|
return (diff);
|
|
|
|
if ((diff = pf_addr_cmp(&a->fr_dst, &b->fr_dst, a->fr_af)) != 0)
|
2004-02-26 02:04:28 +00:00
|
|
|
return (diff);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pf_purge_expired_fragments(void)
|
|
|
|
{
|
|
|
|
struct pf_fragment *frag;
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
u_int32_t expire = time_uptime -
|
2011-06-28 11:57:25 +00:00
|
|
|
V_pf_default_rule.timeout[PFTM_FRAG];
|
2004-02-26 02:04:28 +00:00
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PF_FRAG_LOCK();
|
2011-06-28 11:57:25 +00:00
|
|
|
while ((frag = TAILQ_LAST(&V_pf_fragqueue, pf_fragqueue)) != NULL) {
|
2004-02-26 02:04:28 +00:00
|
|
|
if (frag->fr_timeout > expire)
|
|
|
|
break;
|
|
|
|
|
|
|
|
DPFPRINTF(("expiring %d(%p)\n", frag->fr_id, frag));
|
|
|
|
pf_free_fragment(frag);
|
|
|
|
}
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PF_FRAG_UNLOCK();
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to flush old fragments to make space for new ones
|
|
|
|
*/
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static void
|
2004-02-26 02:04:28 +00:00
|
|
|
pf_flush_fragments(void)
|
|
|
|
{
|
2015-08-27 21:27:47 +00:00
|
|
|
struct pf_fragment *frag;
|
2004-02-26 02:04:28 +00:00
|
|
|
int goal;
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PF_FRAG_ASSERT();
|
2004-02-26 02:04:28 +00:00
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
goal = uma_zone_get_cur(V_pf_frent_z) * 9 / 10;
|
|
|
|
DPFPRINTF(("trying to free %d frag entriess\n", goal));
|
|
|
|
while (goal < uma_zone_get_cur(V_pf_frent_z)) {
|
|
|
|
frag = TAILQ_LAST(&V_pf_fragqueue, pf_fragqueue);
|
|
|
|
if (frag)
|
|
|
|
pf_free_fragment(frag);
|
2015-08-27 21:27:47 +00:00
|
|
|
else
|
2004-02-26 02:04:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Frees the fragments and all associated entries */
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static void
|
2004-02-26 02:04:28 +00:00
|
|
|
pf_free_fragment(struct pf_fragment *frag)
|
|
|
|
{
|
|
|
|
struct pf_frent *frent;
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
|
|
|
|
PF_FRAG_ASSERT();
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/* Free all fragments */
|
2015-08-27 21:27:47 +00:00
|
|
|
for (frent = TAILQ_FIRST(&frag->fr_queue); frent;
|
|
|
|
frent = TAILQ_FIRST(&frag->fr_queue)) {
|
|
|
|
TAILQ_REMOVE(&frag->fr_queue, frent, fr_next);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-08-27 21:27:47 +00:00
|
|
|
m_freem(frent->fe_m);
|
|
|
|
uma_zfree(V_pf_frent_z, frent);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pf_remove_fragment(frag);
|
|
|
|
}
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static struct pf_fragment *
|
2015-02-16 03:38:27 +00:00
|
|
|
pf_find_fragment(struct pf_fragment_cmp *key, struct pf_frag_tree *tree)
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
|
|
|
struct pf_fragment *frag;
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PF_FRAG_ASSERT();
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
frag = RB_FIND(pf_frag_tree, tree, (struct pf_fragment *)key);
|
2004-02-26 02:04:28 +00:00
|
|
|
if (frag != NULL) {
|
|
|
|
/* XXX Are we sure we want to update the timeout? */
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
frag->fr_timeout = time_uptime;
|
2015-08-27 21:27:47 +00:00
|
|
|
TAILQ_REMOVE(&V_pf_fragqueue, frag, frag_next);
|
|
|
|
TAILQ_INSERT_HEAD(&V_pf_fragqueue, frag, frag_next);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (frag);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Removes a fragment from the fragment queue and frees the fragment */
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static void
|
2004-02-26 02:04:28 +00:00
|
|
|
pf_remove_fragment(struct pf_fragment *frag)
|
|
|
|
{
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
|
|
|
|
PF_FRAG_ASSERT();
|
|
|
|
|
2015-08-27 21:27:47 +00:00
|
|
|
RB_REMOVE(pf_frag_tree, &V_pf_frag_tree, frag);
|
|
|
|
TAILQ_REMOVE(&V_pf_fragqueue, frag, frag_next);
|
|
|
|
uma_zfree(V_pf_frag_z, frag);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-17 22:33:22 +00:00
|
|
|
static struct pf_frent *
|
2015-02-16 03:38:27 +00:00
|
|
|
pf_create_fragment(u_short *reason)
|
|
|
|
{
|
|
|
|
struct pf_frent *frent;
|
|
|
|
|
|
|
|
PF_FRAG_ASSERT();
|
|
|
|
|
|
|
|
frent = uma_zalloc(V_pf_frent_z, M_NOWAIT);
|
|
|
|
if (frent == NULL) {
|
|
|
|
pf_flush_fragments();
|
|
|
|
frent = uma_zalloc(V_pf_frent_z, M_NOWAIT);
|
|
|
|
if (frent == NULL) {
|
|
|
|
REASON_SET(reason, PFRES_MEMORY);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (frent);
|
|
|
|
}
|
|
|
|
|
2015-03-26 13:31:04 +00:00
|
|
|
static struct pf_fragment *
|
2015-02-16 03:38:27 +00:00
|
|
|
pf_fillup_fragment(struct pf_fragment_cmp *key, struct pf_frent *frent,
|
|
|
|
u_short *reason)
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
2015-02-16 03:38:27 +00:00
|
|
|
struct pf_frent *after, *next, *prev;
|
|
|
|
struct pf_fragment *frag;
|
|
|
|
uint16_t total;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PF_FRAG_ASSERT();
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
/* No empty fragments. */
|
|
|
|
if (frent->fe_len == 0) {
|
|
|
|
DPFPRINTF(("bad fragment: len 0"));
|
|
|
|
goto bad_fragment;
|
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
/* All fragments are 8 byte aligned. */
|
|
|
|
if (frent->fe_mff && (frent->fe_len & 0x7)) {
|
|
|
|
DPFPRINTF(("bad fragment: mff and len %d", frent->fe_len));
|
|
|
|
goto bad_fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Respect maximum length, IP_MAXPACKET == IPV6_MAXPACKET. */
|
|
|
|
if (frent->fe_off + frent->fe_len > IP_MAXPACKET) {
|
|
|
|
DPFPRINTF(("bad fragment: max packet %d",
|
|
|
|
frent->fe_off + frent->fe_len));
|
|
|
|
goto bad_fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPFPRINTF((key->frc_af == AF_INET ?
|
|
|
|
"reass frag %d @ %d-%d" : "reass frag %#08x @ %d-%d",
|
|
|
|
key->frc_id, frent->fe_off, frent->fe_off + frent->fe_len));
|
|
|
|
|
|
|
|
/* Fully buffer all of the fragments in this fragment queue. */
|
|
|
|
frag = pf_find_fragment(key, &V_pf_frag_tree);
|
|
|
|
|
|
|
|
/* Create a new reassembly queue for this packet. */
|
|
|
|
if (frag == NULL) {
|
|
|
|
frag = uma_zalloc(V_pf_frag_z, M_NOWAIT);
|
|
|
|
if (frag == NULL) {
|
2004-02-26 02:04:28 +00:00
|
|
|
pf_flush_fragments();
|
2015-02-16 03:38:27 +00:00
|
|
|
frag = uma_zalloc(V_pf_frag_z, M_NOWAIT);
|
|
|
|
if (frag == NULL) {
|
|
|
|
REASON_SET(reason, PFRES_MEMORY);
|
2004-02-26 02:04:28 +00:00
|
|
|
goto drop_fragment;
|
2015-02-16 03:38:27 +00:00
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
*(struct pf_fragment_cmp *)frag = *key;
|
2016-05-20 15:41:05 +00:00
|
|
|
frag->fr_timeout = time_uptime;
|
2015-02-16 03:38:27 +00:00
|
|
|
frag->fr_maxlen = frent->fe_len;
|
|
|
|
TAILQ_INIT(&frag->fr_queue);
|
|
|
|
|
|
|
|
RB_INSERT(pf_frag_tree, &V_pf_frag_tree, frag);
|
|
|
|
TAILQ_INSERT_HEAD(&V_pf_fragqueue, frag, frag_next);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
/* We do not have a previous fragment. */
|
|
|
|
TAILQ_INSERT_HEAD(&frag->fr_queue, frent, fr_next);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
return (frag);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
KASSERT(!TAILQ_EMPTY(&frag->fr_queue), ("!TAILQ_EMPTY()->fr_queue"));
|
|
|
|
|
|
|
|
/* Remember maximum fragment len for refragmentation. */
|
|
|
|
if (frent->fe_len > frag->fr_maxlen)
|
|
|
|
frag->fr_maxlen = frent->fe_len;
|
|
|
|
|
|
|
|
/* Maximum data we have seen already. */
|
|
|
|
total = TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_off +
|
|
|
|
TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_len;
|
|
|
|
|
|
|
|
/* Non terminal fragments must have more fragments flag. */
|
|
|
|
if (frent->fe_off + frent->fe_len < total && !frent->fe_mff)
|
|
|
|
goto bad_fragment;
|
|
|
|
|
|
|
|
/* Check if we saw the last fragment already. */
|
|
|
|
if (!TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_mff) {
|
|
|
|
if (frent->fe_off + frent->fe_len > total ||
|
|
|
|
(frent->fe_off + frent->fe_len == total && frent->fe_mff))
|
|
|
|
goto bad_fragment;
|
|
|
|
} else {
|
|
|
|
if (frent->fe_off + frent->fe_len == total && !frent->fe_mff)
|
|
|
|
goto bad_fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a fragment after the current one. */
|
|
|
|
prev = NULL;
|
|
|
|
TAILQ_FOREACH(after, &frag->fr_queue, fr_next) {
|
|
|
|
if (after->fe_off > frent->fe_off)
|
2004-02-26 02:04:28 +00:00
|
|
|
break;
|
2015-02-16 03:38:27 +00:00
|
|
|
prev = after;
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
KASSERT(prev != NULL || after != NULL,
|
|
|
|
("prev != NULL || after != NULL"));
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
if (prev != NULL && prev->fe_off + prev->fe_len > frent->fe_off) {
|
|
|
|
uint16_t precut;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
precut = prev->fe_off + prev->fe_len - frent->fe_off;
|
|
|
|
if (precut >= frent->fe_len)
|
|
|
|
goto bad_fragment;
|
|
|
|
DPFPRINTF(("overlap -%d", precut));
|
|
|
|
m_adj(frent->fe_m, precut);
|
|
|
|
frent->fe_off += precut;
|
|
|
|
frent->fe_len -= precut;
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
for (; after != NULL && frent->fe_off + frent->fe_len > after->fe_off;
|
|
|
|
after = next) {
|
|
|
|
uint16_t aftercut;
|
|
|
|
|
|
|
|
aftercut = frent->fe_off + frent->fe_len - after->fe_off;
|
|
|
|
DPFPRINTF(("adjust overlap %d", aftercut));
|
|
|
|
if (aftercut < after->fe_len) {
|
|
|
|
m_adj(after->fe_m, aftercut);
|
|
|
|
after->fe_off += aftercut;
|
|
|
|
after->fe_len -= aftercut;
|
2004-02-26 02:04:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
/* This fragment is completely overlapped, lose it. */
|
|
|
|
next = TAILQ_NEXT(after, fr_next);
|
|
|
|
m_freem(after->fe_m);
|
|
|
|
TAILQ_REMOVE(&frag->fr_queue, after, fr_next);
|
|
|
|
uma_zfree(V_pf_frent_z, after);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
if (prev == NULL)
|
|
|
|
TAILQ_INSERT_HEAD(&frag->fr_queue, frent, fr_next);
|
2004-02-26 02:04:28 +00:00
|
|
|
else
|
2015-02-16 03:38:27 +00:00
|
|
|
TAILQ_INSERT_AFTER(&frag->fr_queue, prev, frent, fr_next);
|
|
|
|
|
|
|
|
return (frag);
|
|
|
|
|
|
|
|
bad_fragment:
|
|
|
|
REASON_SET(reason, PFRES_FRAG);
|
|
|
|
drop_fragment:
|
|
|
|
uma_zfree(V_pf_frent_z, frent);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
2015-02-16 23:50:53 +00:00
|
|
|
static int
|
2015-02-16 03:38:27 +00:00
|
|
|
pf_isfull_fragment(struct pf_fragment *frag)
|
|
|
|
{
|
|
|
|
struct pf_frent *frent, *next;
|
|
|
|
uint16_t off, total;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/* Check if we are completely reassembled */
|
2015-02-16 03:38:27 +00:00
|
|
|
if (TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_mff)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* Maximum data we have seen already */
|
|
|
|
total = TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_off +
|
|
|
|
TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_len;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/* Check if we have all the data */
|
|
|
|
off = 0;
|
2015-02-16 03:38:27 +00:00
|
|
|
for (frent = TAILQ_FIRST(&frag->fr_queue); frent; frent = next) {
|
|
|
|
next = TAILQ_NEXT(frent, fr_next);
|
|
|
|
|
|
|
|
off += frent->fe_len;
|
|
|
|
if (off < total && (next == NULL || next->fe_off != off)) {
|
|
|
|
DPFPRINTF(("missing fragment at %d, next %d, total %d",
|
|
|
|
off, next == NULL ? -1 : next->fe_off, total));
|
|
|
|
return (0);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-16 03:38:27 +00:00
|
|
|
DPFPRINTF(("%d < %d?", off, total));
|
|
|
|
if (off < total)
|
|
|
|
return (0);
|
|
|
|
KASSERT(off == total, ("off == total"));
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
2015-02-17 22:33:22 +00:00
|
|
|
static struct mbuf *
|
2015-02-16 03:38:27 +00:00
|
|
|
pf_join_fragment(struct pf_fragment *frag)
|
|
|
|
{
|
|
|
|
struct mbuf *m, *m2;
|
|
|
|
struct pf_frent *frent, *next;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
frent = TAILQ_FIRST(&frag->fr_queue);
|
|
|
|
next = TAILQ_NEXT(frent, fr_next);
|
|
|
|
|
|
|
|
m = frent->fe_m;
|
2015-04-01 12:16:56 +00:00
|
|
|
m_adj(m, (frent->fe_hdrlen + frent->fe_len) - m->m_pkthdr.len);
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
uma_zfree(V_pf_frent_z, frent);
|
2004-02-26 02:04:28 +00:00
|
|
|
for (frent = next; frent != NULL; frent = next) {
|
2015-02-16 03:38:27 +00:00
|
|
|
next = TAILQ_NEXT(frent, fr_next);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
m2 = frent->fe_m;
|
|
|
|
/* Strip off ip header. */
|
|
|
|
m_adj(m2, frent->fe_hdrlen);
|
2015-04-01 12:16:56 +00:00
|
|
|
/* Strip off any trailing bytes. */
|
|
|
|
m_adj(m2, frent->fe_len - m2->m_pkthdr.len);
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
uma_zfree(V_pf_frent_z, frent);
|
2004-02-26 02:04:28 +00:00
|
|
|
m_cat(m, m2);
|
|
|
|
}
|
2011-06-28 11:57:25 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
/* Remove from fragment queue. */
|
|
|
|
pf_remove_fragment(frag);
|
|
|
|
|
|
|
|
return (m);
|
|
|
|
}
|
|
|
|
|
2015-02-16 23:50:53 +00:00
|
|
|
#ifdef INET
|
2015-02-16 03:38:27 +00:00
|
|
|
static int
|
|
|
|
pf_reassemble(struct mbuf **m0, struct ip *ip, int dir, u_short *reason)
|
|
|
|
{
|
|
|
|
struct mbuf *m = *m0;
|
|
|
|
struct pf_frent *frent;
|
|
|
|
struct pf_fragment *frag;
|
|
|
|
struct pf_fragment_cmp key;
|
|
|
|
uint16_t total, hdrlen;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
/* Get an entry for the fragment queue */
|
|
|
|
if ((frent = pf_create_fragment(reason)) == NULL)
|
|
|
|
return (PF_DROP);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
frent->fe_m = m;
|
|
|
|
frent->fe_hdrlen = ip->ip_hl << 2;
|
|
|
|
frent->fe_extoff = 0;
|
|
|
|
frent->fe_len = ntohs(ip->ip_len) - (ip->ip_hl << 2);
|
|
|
|
frent->fe_off = (ntohs(ip->ip_off) & IP_OFFMASK) << 3;
|
|
|
|
frent->fe_mff = ntohs(ip->ip_off) & IP_MF;
|
|
|
|
|
|
|
|
pf_ip2key(ip, dir, &key);
|
|
|
|
|
|
|
|
if ((frag = pf_fillup_fragment(&key, frent, reason)) == NULL)
|
|
|
|
return (PF_DROP);
|
|
|
|
|
|
|
|
/* The mbuf is part of the fragment entry, no direct free or access */
|
|
|
|
m = *m0 = NULL;
|
|
|
|
|
|
|
|
if (!pf_isfull_fragment(frag))
|
|
|
|
return (PF_PASS); /* drop because *m0 is NULL, no error */
|
|
|
|
|
|
|
|
/* We have all the data */
|
|
|
|
frent = TAILQ_FIRST(&frag->fr_queue);
|
|
|
|
KASSERT(frent != NULL, ("frent != NULL"));
|
|
|
|
total = TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_off +
|
|
|
|
TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_len;
|
|
|
|
hdrlen = frent->fe_hdrlen;
|
|
|
|
|
|
|
|
m = *m0 = pf_join_fragment(frag);
|
|
|
|
frag = NULL;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
if (m->m_flags & M_PKTHDR) {
|
|
|
|
int plen = 0;
|
2015-02-16 03:38:27 +00:00
|
|
|
for (m = *m0; m; m = m->m_next)
|
|
|
|
plen += m->m_len;
|
|
|
|
m = *m0;
|
2004-02-26 02:04:28 +00:00
|
|
|
m->m_pkthdr.len = plen;
|
|
|
|
}
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
ip = mtod(m, struct ip *);
|
|
|
|
ip->ip_len = htons(hdrlen + total);
|
|
|
|
ip->ip_off &= ~(IP_MF|IP_OFFMASK);
|
|
|
|
|
|
|
|
if (hdrlen + total > IP_MAXPACKET) {
|
|
|
|
DPFPRINTF(("drop: too big: %d", total));
|
|
|
|
ip->ip_len = 0;
|
|
|
|
REASON_SET(reason, PFRES_SHORT);
|
|
|
|
/* PF_DROP requires a valid mbuf *m0 in pf_test() */
|
|
|
|
return (PF_DROP);
|
|
|
|
}
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
DPFPRINTF(("complete: %p(%d)\n", m, ntohs(ip->ip_len)));
|
2015-02-16 03:38:27 +00:00
|
|
|
return (PF_PASS);
|
|
|
|
}
|
2015-02-17 22:33:22 +00:00
|
|
|
#endif /* INET */
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
#ifdef INET6
|
2015-02-16 23:50:53 +00:00
|
|
|
static int
|
2015-02-16 03:38:27 +00:00
|
|
|
pf_reassemble6(struct mbuf **m0, struct ip6_hdr *ip6, struct ip6_frag *fraghdr,
|
2015-06-11 17:57:47 +00:00
|
|
|
uint16_t hdrlen, uint16_t extoff, u_short *reason)
|
2015-02-16 03:38:27 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m = *m0;
|
|
|
|
struct pf_frent *frent;
|
|
|
|
struct pf_fragment *frag;
|
|
|
|
struct pf_fragment_cmp key;
|
2015-02-16 07:01:02 +00:00
|
|
|
struct m_tag *mtag;
|
|
|
|
struct pf_fragment_tag *ftag;
|
2015-02-16 03:38:27 +00:00
|
|
|
int off;
|
2015-04-01 12:15:01 +00:00
|
|
|
uint32_t frag_id;
|
2015-02-16 03:38:27 +00:00
|
|
|
uint16_t total, maxlen;
|
|
|
|
uint8_t proto;
|
|
|
|
|
|
|
|
PF_FRAG_LOCK();
|
|
|
|
|
|
|
|
/* Get an entry for the fragment queue. */
|
|
|
|
if ((frent = pf_create_fragment(reason)) == NULL) {
|
|
|
|
PF_FRAG_UNLOCK();
|
|
|
|
return (PF_DROP);
|
|
|
|
}
|
|
|
|
|
|
|
|
frent->fe_m = m;
|
|
|
|
frent->fe_hdrlen = hdrlen;
|
|
|
|
frent->fe_extoff = extoff;
|
|
|
|
frent->fe_len = sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) - hdrlen;
|
|
|
|
frent->fe_off = ntohs(fraghdr->ip6f_offlg & IP6F_OFF_MASK);
|
|
|
|
frent->fe_mff = fraghdr->ip6f_offlg & IP6F_MORE_FRAG;
|
|
|
|
|
|
|
|
key.frc_src.v6 = ip6->ip6_src;
|
|
|
|
key.frc_dst.v6 = ip6->ip6_dst;
|
|
|
|
key.frc_af = AF_INET6;
|
|
|
|
/* Only the first fragment's protocol is relevant. */
|
|
|
|
key.frc_proto = 0;
|
|
|
|
key.frc_id = fraghdr->ip6f_ident;
|
|
|
|
|
|
|
|
if ((frag = pf_fillup_fragment(&key, frent, reason)) == NULL) {
|
|
|
|
PF_FRAG_UNLOCK();
|
|
|
|
return (PF_DROP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The mbuf is part of the fragment entry, no direct free or access. */
|
|
|
|
m = *m0 = NULL;
|
|
|
|
|
|
|
|
if (!pf_isfull_fragment(frag)) {
|
|
|
|
PF_FRAG_UNLOCK();
|
|
|
|
return (PF_PASS); /* Drop because *m0 is NULL, no error. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We have all the data. */
|
|
|
|
extoff = frent->fe_extoff;
|
|
|
|
maxlen = frag->fr_maxlen;
|
2015-04-01 12:15:01 +00:00
|
|
|
frag_id = frag->fr_id;
|
2015-02-16 03:38:27 +00:00
|
|
|
frent = TAILQ_FIRST(&frag->fr_queue);
|
|
|
|
KASSERT(frent != NULL, ("frent != NULL"));
|
|
|
|
total = TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_off +
|
|
|
|
TAILQ_LAST(&frag->fr_queue, pf_fragq)->fe_len;
|
|
|
|
hdrlen = frent->fe_hdrlen - sizeof(struct ip6_frag);
|
|
|
|
|
|
|
|
m = *m0 = pf_join_fragment(frag);
|
|
|
|
frag = NULL;
|
|
|
|
|
|
|
|
PF_FRAG_UNLOCK();
|
|
|
|
|
|
|
|
/* Take protocol from first fragment header. */
|
|
|
|
m = m_getptr(m, hdrlen + offsetof(struct ip6_frag, ip6f_nxt), &off);
|
|
|
|
KASSERT(m, ("%s: short mbuf chain", __func__));
|
|
|
|
proto = *(mtod(m, caddr_t) + off);
|
|
|
|
m = *m0;
|
|
|
|
|
|
|
|
/* Delete frag6 header */
|
|
|
|
if (ip6_deletefraghdr(m, hdrlen, M_NOWAIT) != 0)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (m->m_flags & M_PKTHDR) {
|
|
|
|
int plen = 0;
|
|
|
|
for (m = *m0; m; m = m->m_next)
|
|
|
|
plen += m->m_len;
|
|
|
|
m = *m0;
|
|
|
|
m->m_pkthdr.len = plen;
|
|
|
|
}
|
|
|
|
|
2015-02-16 07:01:02 +00:00
|
|
|
if ((mtag = m_tag_get(PF_REASSEMBLED, sizeof(struct pf_fragment_tag),
|
|
|
|
M_NOWAIT)) == NULL)
|
|
|
|
goto fail;
|
|
|
|
ftag = (struct pf_fragment_tag *)(mtag + 1);
|
|
|
|
ftag->ft_hdrlen = hdrlen;
|
|
|
|
ftag->ft_extoff = extoff;
|
|
|
|
ftag->ft_maxlen = maxlen;
|
2015-04-01 12:15:01 +00:00
|
|
|
ftag->ft_id = frag_id;
|
2015-02-16 07:01:02 +00:00
|
|
|
m_tag_prepend(m, mtag);
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
ip6 = mtod(m, struct ip6_hdr *);
|
|
|
|
ip6->ip6_plen = htons(hdrlen - sizeof(struct ip6_hdr) + total);
|
|
|
|
if (extoff) {
|
|
|
|
/* Write protocol into next field of last extension header. */
|
|
|
|
m = m_getptr(m, extoff + offsetof(struct ip6_ext, ip6e_nxt),
|
|
|
|
&off);
|
|
|
|
KASSERT(m, ("%s: short mbuf chain", __func__));
|
|
|
|
*(mtod(m, char *) + off) = proto;
|
|
|
|
m = *m0;
|
|
|
|
} else
|
|
|
|
ip6->ip6_nxt = proto;
|
|
|
|
|
|
|
|
if (hdrlen - sizeof(struct ip6_hdr) + total > IPV6_MAXPACKET) {
|
|
|
|
DPFPRINTF(("drop: too big: %d", total));
|
|
|
|
ip6->ip6_plen = 0;
|
|
|
|
REASON_SET(reason, PFRES_SHORT);
|
|
|
|
/* PF_DROP requires a valid mbuf *m0 in pf_test6(). */
|
|
|
|
return (PF_DROP);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPFPRINTF(("complete: %p(%d)", m, ntohs(ip6->ip6_plen)));
|
|
|
|
return (PF_PASS);
|
|
|
|
|
|
|
|
fail:
|
|
|
|
REASON_SET(reason, PFRES_MEMORY);
|
|
|
|
/* PF_DROP requires a valid mbuf *m0 in pf_test6(), will free later. */
|
|
|
|
return (PF_DROP);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
2015-02-16 23:50:53 +00:00
|
|
|
#endif /* INET6 */
|
2015-02-16 03:38:27 +00:00
|
|
|
|
2015-02-16 21:52:28 +00:00
|
|
|
#ifdef INET6
|
2015-02-16 07:01:02 +00:00
|
|
|
int
|
|
|
|
pf_refragment6(struct ifnet *ifp, struct mbuf **m0, struct m_tag *mtag)
|
|
|
|
{
|
|
|
|
struct mbuf *m = *m0, *t;
|
|
|
|
struct pf_fragment_tag *ftag = (struct pf_fragment_tag *)(mtag + 1);
|
|
|
|
struct pf_pdesc pd;
|
2015-04-01 12:15:01 +00:00
|
|
|
uint32_t frag_id;
|
2015-02-16 07:01:02 +00:00
|
|
|
uint16_t hdrlen, extoff, maxlen;
|
|
|
|
uint8_t proto;
|
|
|
|
int error, action;
|
|
|
|
|
|
|
|
hdrlen = ftag->ft_hdrlen;
|
|
|
|
extoff = ftag->ft_extoff;
|
|
|
|
maxlen = ftag->ft_maxlen;
|
2015-04-01 12:15:01 +00:00
|
|
|
frag_id = ftag->ft_id;
|
2015-02-16 07:01:02 +00:00
|
|
|
m_tag_delete(m, mtag);
|
|
|
|
mtag = NULL;
|
|
|
|
ftag = NULL;
|
|
|
|
|
|
|
|
if (extoff) {
|
|
|
|
int off;
|
|
|
|
|
|
|
|
/* Use protocol from next field of last extension header */
|
|
|
|
m = m_getptr(m, extoff + offsetof(struct ip6_ext, ip6e_nxt),
|
|
|
|
&off);
|
|
|
|
KASSERT((m != NULL), ("pf_refragment6: short mbuf chain"));
|
|
|
|
proto = *(mtod(m, caddr_t) + off);
|
|
|
|
*(mtod(m, char *) + off) = IPPROTO_FRAGMENT;
|
|
|
|
m = *m0;
|
|
|
|
} else {
|
|
|
|
struct ip6_hdr *hdr;
|
|
|
|
|
|
|
|
hdr = mtod(m, struct ip6_hdr *);
|
|
|
|
proto = hdr->ip6_nxt;
|
|
|
|
hdr->ip6_nxt = IPPROTO_FRAGMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Maxlen may be less than 8 if there was only a single
|
|
|
|
* fragment. As it was fragmented before, add a fragment
|
|
|
|
* header also for a single fragment. If total or maxlen
|
|
|
|
* is less than 8, ip6_fragment() will return EMSGSIZE and
|
|
|
|
* we drop the packet.
|
|
|
|
*/
|
2015-04-01 12:15:01 +00:00
|
|
|
error = ip6_fragment(ifp, m, hdrlen, proto, maxlen, frag_id);
|
2015-02-16 07:01:02 +00:00
|
|
|
m = (*m0)->m_nextpkt;
|
|
|
|
(*m0)->m_nextpkt = NULL;
|
|
|
|
if (error == 0) {
|
|
|
|
/* The first mbuf contains the unfragmented packet. */
|
|
|
|
m_freem(*m0);
|
|
|
|
*m0 = NULL;
|
|
|
|
action = PF_PASS;
|
|
|
|
} else {
|
|
|
|
/* Drop expects an mbuf to free. */
|
|
|
|
DPFPRINTF(("refragment error %d", error));
|
|
|
|
action = PF_DROP;
|
|
|
|
}
|
|
|
|
for (t = m; m; m = t) {
|
|
|
|
t = m->m_nextpkt;
|
|
|
|
m->m_nextpkt = NULL;
|
2015-04-06 19:05:00 +00:00
|
|
|
m->m_flags |= M_SKIP_FIREWALL;
|
2015-02-16 07:01:02 +00:00
|
|
|
memset(&pd, 0, sizeof(pd));
|
|
|
|
pd.pf_mtag = pf_find_mtag(m);
|
|
|
|
if (error == 0)
|
|
|
|
ip6_forward(m, 0);
|
|
|
|
else
|
|
|
|
m_freem(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (action);
|
|
|
|
}
|
2015-02-16 21:52:28 +00:00
|
|
|
#endif /* INET6 */
|
2015-02-16 07:01:02 +00:00
|
|
|
|
2015-02-17 22:33:22 +00:00
|
|
|
#ifdef INET
|
2004-02-26 02:04:28 +00:00
|
|
|
int
|
2005-05-03 16:43:32 +00:00
|
|
|
pf_normalize_ip(struct mbuf **m0, int dir, struct pfi_kif *kif, u_short *reason,
|
|
|
|
struct pf_pdesc *pd)
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m = *m0;
|
|
|
|
struct pf_rule *r;
|
|
|
|
struct ip *h = mtod(m, struct ip *);
|
|
|
|
int mff = (ntohs(h->ip_off) & IP_MF);
|
|
|
|
int hlen = h->ip_hl << 2;
|
|
|
|
u_int16_t fragoff = (ntohs(h->ip_off) & IP_OFFMASK) << 3;
|
|
|
|
u_int16_t max;
|
|
|
|
int ip_len;
|
|
|
|
int ip_off;
|
2011-06-28 11:57:25 +00:00
|
|
|
int tag = -1;
|
2015-02-16 03:38:27 +00:00
|
|
|
int verdict;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PF_RULES_RASSERT();
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr);
|
|
|
|
while (r != NULL) {
|
|
|
|
r->evaluations++;
|
2007-07-03 12:16:07 +00:00
|
|
|
if (pfi_kif_match(r->kif, kif) == r->ifnot)
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_IFP].ptr;
|
|
|
|
else if (r->direction && r->direction != dir)
|
|
|
|
r = r->skip[PF_SKIP_DIR].ptr;
|
|
|
|
else if (r->af && r->af != AF_INET)
|
|
|
|
r = r->skip[PF_SKIP_AF].ptr;
|
|
|
|
else if (r->proto && r->proto != h->ip_p)
|
|
|
|
r = r->skip[PF_SKIP_PROTO].ptr;
|
|
|
|
else if (PF_MISMATCHAW(&r->src.addr,
|
2007-07-03 12:16:07 +00:00
|
|
|
(struct pf_addr *)&h->ip_src.s_addr, AF_INET,
|
2012-02-03 13:20:48 +00:00
|
|
|
r->src.neg, kif, M_GETFIB(m)))
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_SRC_ADDR].ptr;
|
|
|
|
else if (PF_MISMATCHAW(&r->dst.addr,
|
2007-07-03 12:16:07 +00:00
|
|
|
(struct pf_addr *)&h->ip_dst.s_addr, AF_INET,
|
2012-02-03 13:20:48 +00:00
|
|
|
r->dst.neg, NULL, M_GETFIB(m)))
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_DST_ADDR].ptr;
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
else if (r->match_tag && !pf_match_tag(m, r, &tag,
|
|
|
|
pd->pf_mtag ? pd->pf_mtag->tag : 0))
|
2011-06-28 11:57:25 +00:00
|
|
|
r = TAILQ_NEXT(r, entries);
|
2004-02-26 02:04:28 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
if (r == NULL || r->action == PF_NOSCRUB)
|
2004-02-26 02:04:28 +00:00
|
|
|
return (PF_PASS);
|
2007-07-03 12:16:07 +00:00
|
|
|
else {
|
|
|
|
r->packets[dir == PF_OUT]++;
|
|
|
|
r->bytes[dir == PF_OUT] += pd->tot_len;
|
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/* Check for illegal packets */
|
2015-08-27 21:27:47 +00:00
|
|
|
if (hlen < (int)sizeof(struct ip)) {
|
|
|
|
REASON_SET(reason, PFRES_NORM);
|
2004-02-26 02:04:28 +00:00
|
|
|
goto drop;
|
2015-08-27 21:27:47 +00:00
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-08-27 21:27:47 +00:00
|
|
|
if (hlen > ntohs(h->ip_len)) {
|
|
|
|
REASON_SET(reason, PFRES_NORM);
|
2004-02-26 02:04:28 +00:00
|
|
|
goto drop;
|
2015-08-27 21:27:47 +00:00
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/* Clear IP_DF if the rule uses the no-df option */
|
2006-03-25 21:15:25 +00:00
|
|
|
if (r->rule_flag & PFRULE_NODF && h->ip_off & htons(IP_DF)) {
|
|
|
|
u_int16_t ip_off = h->ip_off;
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
h->ip_off &= htons(~IP_DF);
|
2006-03-25 21:15:25 +00:00
|
|
|
h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_off, h->ip_off, 0);
|
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/* We will need other tests here */
|
|
|
|
if (!fragoff && !mff)
|
|
|
|
goto no_fragment;
|
|
|
|
|
|
|
|
/* We're dealing with a fragment now. Don't allow fragments
|
|
|
|
* with IP_DF to enter the cache. If the flag was cleared by
|
|
|
|
* no-df above, fine. Otherwise drop it.
|
|
|
|
*/
|
|
|
|
if (h->ip_off & htons(IP_DF)) {
|
|
|
|
DPFPRINTF(("IP_DF\n"));
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
ip_len = ntohs(h->ip_len) - hlen;
|
|
|
|
ip_off = (ntohs(h->ip_off) & IP_OFFMASK) << 3;
|
|
|
|
|
|
|
|
/* All fragments are 8 byte aligned */
|
|
|
|
if (mff && (ip_len & 0x7)) {
|
|
|
|
DPFPRINTF(("mff and %d\n", ip_len));
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Respect maximum length */
|
|
|
|
if (fragoff + ip_len > IP_MAXPACKET) {
|
|
|
|
DPFPRINTF(("max packet %d\n", fragoff + ip_len));
|
|
|
|
goto bad;
|
|
|
|
}
|
|
|
|
max = fragoff + ip_len;
|
|
|
|
|
2015-08-27 21:27:47 +00:00
|
|
|
/* Fully buffer all of the fragments
|
|
|
|
* Might return a completely reassembled mbuf, or NULL */
|
|
|
|
PF_FRAG_LOCK();
|
|
|
|
DPFPRINTF(("reass frag %d @ %d-%d\n", h->ip_id, fragoff, max));
|
|
|
|
verdict = pf_reassemble(m0, h, dir, reason);
|
|
|
|
PF_FRAG_UNLOCK();
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-08-27 21:27:47 +00:00
|
|
|
if (verdict != PF_PASS)
|
|
|
|
return (PF_DROP);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2015-08-27 21:27:47 +00:00
|
|
|
m = *m0;
|
|
|
|
if (m == NULL)
|
|
|
|
return (PF_DROP);
|
2007-07-03 12:16:07 +00:00
|
|
|
|
2015-08-27 21:27:47 +00:00
|
|
|
h = mtod(m, struct ip *);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
no_fragment:
|
|
|
|
/* At this point, only IP_DF is allowed in ip_off */
|
2006-03-25 21:15:25 +00:00
|
|
|
if (h->ip_off & ~htons(IP_DF)) {
|
|
|
|
u_int16_t ip_off = h->ip_off;
|
|
|
|
|
|
|
|
h->ip_off &= htons(IP_DF);
|
|
|
|
h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_off, h->ip_off, 0);
|
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
|
2011-06-28 11:57:25 +00:00
|
|
|
pf_scrub_ip(&m, r->rule_flag, r->min_ttl, r->set_tos);
|
2006-03-25 21:15:25 +00:00
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
return (PF_PASS);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
DPFPRINTF(("dropping bad fragment\n"));
|
|
|
|
REASON_SET(reason, PFRES_FRAG);
|
2015-08-27 21:27:47 +00:00
|
|
|
drop:
|
2004-02-26 02:04:28 +00:00
|
|
|
if (r != NULL && r->log)
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PFLOG_PACKET(kif, m, AF_INET, dir, *reason, r, NULL, NULL, pd,
|
|
|
|
1);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
return (PF_DROP);
|
|
|
|
}
|
2011-05-31 15:05:29 +00:00
|
|
|
#endif
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
#ifdef INET6
|
|
|
|
int
|
2004-06-16 23:24:02 +00:00
|
|
|
pf_normalize_ip6(struct mbuf **m0, int dir, struct pfi_kif *kif,
|
2005-05-03 16:43:32 +00:00
|
|
|
u_short *reason, struct pf_pdesc *pd)
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
|
|
|
struct mbuf *m = *m0;
|
|
|
|
struct pf_rule *r;
|
|
|
|
struct ip6_hdr *h = mtod(m, struct ip6_hdr *);
|
2015-02-16 03:38:27 +00:00
|
|
|
int extoff;
|
2004-02-26 02:04:28 +00:00
|
|
|
int off;
|
|
|
|
struct ip6_ext ext;
|
|
|
|
struct ip6_opt opt;
|
|
|
|
struct ip6_opt_jumbo jumbo;
|
|
|
|
struct ip6_frag frag;
|
|
|
|
u_int32_t jumbolen = 0, plen;
|
|
|
|
int optend;
|
|
|
|
int ooff;
|
|
|
|
u_int8_t proto;
|
|
|
|
int terminal;
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PF_RULES_RASSERT();
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr);
|
|
|
|
while (r != NULL) {
|
|
|
|
r->evaluations++;
|
2007-07-03 12:16:07 +00:00
|
|
|
if (pfi_kif_match(r->kif, kif) == r->ifnot)
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_IFP].ptr;
|
|
|
|
else if (r->direction && r->direction != dir)
|
|
|
|
r = r->skip[PF_SKIP_DIR].ptr;
|
|
|
|
else if (r->af && r->af != AF_INET6)
|
|
|
|
r = r->skip[PF_SKIP_AF].ptr;
|
|
|
|
#if 0 /* header chain! */
|
|
|
|
else if (r->proto && r->proto != h->ip6_nxt)
|
|
|
|
r = r->skip[PF_SKIP_PROTO].ptr;
|
|
|
|
#endif
|
|
|
|
else if (PF_MISMATCHAW(&r->src.addr,
|
2007-07-03 12:16:07 +00:00
|
|
|
(struct pf_addr *)&h->ip6_src, AF_INET6,
|
2012-02-03 13:20:48 +00:00
|
|
|
r->src.neg, kif, M_GETFIB(m)))
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_SRC_ADDR].ptr;
|
|
|
|
else if (PF_MISMATCHAW(&r->dst.addr,
|
2007-07-03 12:16:07 +00:00
|
|
|
(struct pf_addr *)&h->ip6_dst, AF_INET6,
|
2012-02-03 13:20:48 +00:00
|
|
|
r->dst.neg, NULL, M_GETFIB(m)))
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_DST_ADDR].ptr;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-07-03 12:16:07 +00:00
|
|
|
if (r == NULL || r->action == PF_NOSCRUB)
|
2004-02-26 02:04:28 +00:00
|
|
|
return (PF_PASS);
|
2007-07-03 12:16:07 +00:00
|
|
|
else {
|
|
|
|
r->packets[dir == PF_OUT]++;
|
|
|
|
r->bytes[dir == PF_OUT] += pd->tot_len;
|
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/* Check for illegal packets */
|
|
|
|
if (sizeof(struct ip6_hdr) + IPV6_MAXPACKET < m->m_pkthdr.len)
|
|
|
|
goto drop;
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
extoff = 0;
|
2004-02-26 02:04:28 +00:00
|
|
|
off = sizeof(struct ip6_hdr);
|
|
|
|
proto = h->ip6_nxt;
|
|
|
|
terminal = 0;
|
|
|
|
do {
|
|
|
|
switch (proto) {
|
|
|
|
case IPPROTO_FRAGMENT:
|
|
|
|
goto fragment;
|
|
|
|
break;
|
|
|
|
case IPPROTO_AH:
|
|
|
|
case IPPROTO_ROUTING:
|
|
|
|
case IPPROTO_DSTOPTS:
|
|
|
|
if (!pf_pull_hdr(m, off, &ext, sizeof(ext), NULL,
|
|
|
|
NULL, AF_INET6))
|
|
|
|
goto shortpkt;
|
2015-02-16 03:38:27 +00:00
|
|
|
extoff = off;
|
2004-02-26 02:04:28 +00:00
|
|
|
if (proto == IPPROTO_AH)
|
|
|
|
off += (ext.ip6e_len + 2) * 4;
|
|
|
|
else
|
|
|
|
off += (ext.ip6e_len + 1) * 8;
|
|
|
|
proto = ext.ip6e_nxt;
|
|
|
|
break;
|
|
|
|
case IPPROTO_HOPOPTS:
|
|
|
|
if (!pf_pull_hdr(m, off, &ext, sizeof(ext), NULL,
|
|
|
|
NULL, AF_INET6))
|
|
|
|
goto shortpkt;
|
2015-02-16 03:38:27 +00:00
|
|
|
extoff = off;
|
2004-02-26 02:04:28 +00:00
|
|
|
optend = off + (ext.ip6e_len + 1) * 8;
|
|
|
|
ooff = off + sizeof(ext);
|
|
|
|
do {
|
|
|
|
if (!pf_pull_hdr(m, ooff, &opt.ip6o_type,
|
|
|
|
sizeof(opt.ip6o_type), NULL, NULL,
|
|
|
|
AF_INET6))
|
|
|
|
goto shortpkt;
|
|
|
|
if (opt.ip6o_type == IP6OPT_PAD1) {
|
|
|
|
ooff++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!pf_pull_hdr(m, ooff, &opt, sizeof(opt),
|
|
|
|
NULL, NULL, AF_INET6))
|
|
|
|
goto shortpkt;
|
|
|
|
if (ooff + sizeof(opt) + opt.ip6o_len > optend)
|
|
|
|
goto drop;
|
|
|
|
switch (opt.ip6o_type) {
|
|
|
|
case IP6OPT_JUMBO:
|
|
|
|
if (h->ip6_plen != 0)
|
|
|
|
goto drop;
|
|
|
|
if (!pf_pull_hdr(m, ooff, &jumbo,
|
|
|
|
sizeof(jumbo), NULL, NULL,
|
|
|
|
AF_INET6))
|
|
|
|
goto shortpkt;
|
|
|
|
memcpy(&jumbolen, jumbo.ip6oj_jumbo_len,
|
|
|
|
sizeof(jumbolen));
|
|
|
|
jumbolen = ntohl(jumbolen);
|
|
|
|
if (jumbolen <= IPV6_MAXPACKET)
|
|
|
|
goto drop;
|
|
|
|
if (sizeof(struct ip6_hdr) + jumbolen !=
|
|
|
|
m->m_pkthdr.len)
|
|
|
|
goto drop;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ooff += sizeof(opt) + opt.ip6o_len;
|
|
|
|
} while (ooff < optend);
|
|
|
|
|
|
|
|
off = optend;
|
|
|
|
proto = ext.ip6e_nxt;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
terminal = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (!terminal);
|
|
|
|
|
|
|
|
/* jumbo payload option must be present, or plen > 0 */
|
|
|
|
if (ntohs(h->ip6_plen) == 0)
|
|
|
|
plen = jumbolen;
|
|
|
|
else
|
|
|
|
plen = ntohs(h->ip6_plen);
|
|
|
|
if (plen == 0)
|
|
|
|
goto drop;
|
|
|
|
if (sizeof(struct ip6_hdr) + plen > m->m_pkthdr.len)
|
|
|
|
goto shortpkt;
|
|
|
|
|
2011-06-28 11:57:25 +00:00
|
|
|
pf_scrub_ip6(&m, r->min_ttl);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
return (PF_PASS);
|
|
|
|
|
|
|
|
fragment:
|
2015-02-16 03:38:27 +00:00
|
|
|
/* Jumbo payload packets cannot be fragmented. */
|
2004-02-26 02:04:28 +00:00
|
|
|
plen = ntohs(h->ip6_plen);
|
2015-02-16 03:38:27 +00:00
|
|
|
if (plen == 0 || jumbolen)
|
|
|
|
goto drop;
|
|
|
|
if (sizeof(struct ip6_hdr) + plen > m->m_pkthdr.len)
|
|
|
|
goto shortpkt;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
if (!pf_pull_hdr(m, off, &frag, sizeof(frag), NULL, NULL, AF_INET6))
|
|
|
|
goto shortpkt;
|
|
|
|
|
2015-02-16 03:38:27 +00:00
|
|
|
/* Offset now points to data portion. */
|
|
|
|
off += sizeof(frag);
|
|
|
|
|
|
|
|
/* Returns PF_DROP or *m0 is NULL or completely reassembled mbuf. */
|
2015-06-11 17:57:47 +00:00
|
|
|
if (pf_reassemble6(m0, h, &frag, off, extoff, reason) != PF_PASS)
|
2015-02-16 03:38:27 +00:00
|
|
|
return (PF_DROP);
|
|
|
|
m = *m0;
|
|
|
|
if (m == NULL)
|
|
|
|
return (PF_DROP);
|
|
|
|
|
|
|
|
pd->flags |= PFDESC_IP_REAS;
|
2004-02-26 02:04:28 +00:00
|
|
|
return (PF_PASS);
|
|
|
|
|
|
|
|
shortpkt:
|
|
|
|
REASON_SET(reason, PFRES_SHORT);
|
|
|
|
if (r != NULL && r->log)
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PFLOG_PACKET(kif, m, AF_INET6, dir, *reason, r, NULL, NULL, pd,
|
|
|
|
1);
|
2004-02-26 02:04:28 +00:00
|
|
|
return (PF_DROP);
|
|
|
|
|
|
|
|
drop:
|
|
|
|
REASON_SET(reason, PFRES_NORM);
|
|
|
|
if (r != NULL && r->log)
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PFLOG_PACKET(kif, m, AF_INET6, dir, *reason, r, NULL, NULL, pd,
|
|
|
|
1);
|
2004-02-26 02:04:28 +00:00
|
|
|
return (PF_DROP);
|
|
|
|
}
|
2005-05-03 16:43:32 +00:00
|
|
|
#endif /* INET6 */
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
int
|
2004-06-16 23:24:02 +00:00
|
|
|
pf_normalize_tcp(int dir, struct pfi_kif *kif, struct mbuf *m, int ipoff,
|
2004-02-26 02:04:28 +00:00
|
|
|
int off, void *h, struct pf_pdesc *pd)
|
|
|
|
{
|
|
|
|
struct pf_rule *r, *rm = NULL;
|
|
|
|
struct tcphdr *th = pd->hdr.tcp;
|
|
|
|
int rewrite = 0;
|
|
|
|
u_short reason;
|
|
|
|
u_int8_t flags;
|
|
|
|
sa_family_t af = pd->af;
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PF_RULES_RASSERT();
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
r = TAILQ_FIRST(pf_main_ruleset.rules[PF_RULESET_SCRUB].active.ptr);
|
|
|
|
while (r != NULL) {
|
|
|
|
r->evaluations++;
|
2007-07-03 12:16:07 +00:00
|
|
|
if (pfi_kif_match(r->kif, kif) == r->ifnot)
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_IFP].ptr;
|
|
|
|
else if (r->direction && r->direction != dir)
|
|
|
|
r = r->skip[PF_SKIP_DIR].ptr;
|
|
|
|
else if (r->af && r->af != af)
|
|
|
|
r = r->skip[PF_SKIP_AF].ptr;
|
|
|
|
else if (r->proto && r->proto != pd->proto)
|
|
|
|
r = r->skip[PF_SKIP_PROTO].ptr;
|
2007-07-03 12:16:07 +00:00
|
|
|
else if (PF_MISMATCHAW(&r->src.addr, pd->src, af,
|
2012-02-03 13:20:48 +00:00
|
|
|
r->src.neg, kif, M_GETFIB(m)))
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_SRC_ADDR].ptr;
|
|
|
|
else if (r->src.port_op && !pf_match_port(r->src.port_op,
|
|
|
|
r->src.port[0], r->src.port[1], th->th_sport))
|
|
|
|
r = r->skip[PF_SKIP_SRC_PORT].ptr;
|
2007-07-03 12:16:07 +00:00
|
|
|
else if (PF_MISMATCHAW(&r->dst.addr, pd->dst, af,
|
2012-02-03 13:20:48 +00:00
|
|
|
r->dst.neg, NULL, M_GETFIB(m)))
|
2004-02-26 02:04:28 +00:00
|
|
|
r = r->skip[PF_SKIP_DST_ADDR].ptr;
|
|
|
|
else if (r->dst.port_op && !pf_match_port(r->dst.port_op,
|
|
|
|
r->dst.port[0], r->dst.port[1], th->th_dport))
|
|
|
|
r = r->skip[PF_SKIP_DST_PORT].ptr;
|
|
|
|
else if (r->os_fingerprint != PF_OSFP_ANY && !pf_osfp_match(
|
|
|
|
pf_osfp_fingerprint(pd, m, off, th),
|
|
|
|
r->os_fingerprint))
|
|
|
|
r = TAILQ_NEXT(r, entries);
|
|
|
|
else {
|
|
|
|
rm = r;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-03 16:43:32 +00:00
|
|
|
if (rm == NULL || rm->action == PF_NOSCRUB)
|
2004-02-26 02:04:28 +00:00
|
|
|
return (PF_PASS);
|
2007-07-03 12:16:07 +00:00
|
|
|
else {
|
|
|
|
r->packets[dir == PF_OUT]++;
|
|
|
|
r->bytes[dir == PF_OUT] += pd->tot_len;
|
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
if (rm->rule_flag & PFRULE_REASSEMBLE_TCP)
|
|
|
|
pd->flags |= PFDESC_TCP_NORM;
|
|
|
|
|
|
|
|
flags = th->th_flags;
|
|
|
|
if (flags & TH_SYN) {
|
|
|
|
/* Illegal packet */
|
|
|
|
if (flags & TH_RST)
|
|
|
|
goto tcp_drop;
|
|
|
|
|
|
|
|
if (flags & TH_FIN)
|
2015-04-14 14:43:42 +00:00
|
|
|
goto tcp_drop;
|
2004-02-26 02:04:28 +00:00
|
|
|
} else {
|
|
|
|
/* Illegal packet */
|
|
|
|
if (!(flags & (TH_ACK|TH_RST)))
|
|
|
|
goto tcp_drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(flags & TH_ACK)) {
|
|
|
|
/* These flags are only valid if ACK is set */
|
|
|
|
if ((flags & TH_FIN) || (flags & TH_PUSH) || (flags & TH_URG))
|
|
|
|
goto tcp_drop;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for illegal header length */
|
|
|
|
if (th->th_off < (sizeof(struct tcphdr) >> 2))
|
|
|
|
goto tcp_drop;
|
|
|
|
|
|
|
|
/* If flags changed, or reserved data set, then adjust */
|
|
|
|
if (flags != th->th_flags || th->th_x2 != 0) {
|
|
|
|
u_int16_t ov, nv;
|
|
|
|
|
|
|
|
ov = *(u_int16_t *)(&th->th_ack + 1);
|
|
|
|
th->th_flags = flags;
|
|
|
|
th->th_x2 = 0;
|
|
|
|
nv = *(u_int16_t *)(&th->th_ack + 1);
|
|
|
|
|
2015-10-14 16:21:41 +00:00
|
|
|
th->th_sum = pf_proto_cksum_fixup(m, th->th_sum, ov, nv, 0);
|
2004-02-26 02:04:28 +00:00
|
|
|
rewrite = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Remove urgent pointer, if TH_URG is not set */
|
|
|
|
if (!(flags & TH_URG) && th->th_urp) {
|
2015-10-14 16:21:41 +00:00
|
|
|
th->th_sum = pf_proto_cksum_fixup(m, th->th_sum, th->th_urp,
|
|
|
|
0, 0);
|
2004-02-26 02:04:28 +00:00
|
|
|
th->th_urp = 0;
|
|
|
|
rewrite = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Process options */
|
2011-06-28 11:57:25 +00:00
|
|
|
if (r->max_mss && pf_normalize_tcpopt(r, m, th, off, pd->af))
|
2004-02-26 02:04:28 +00:00
|
|
|
rewrite = 1;
|
|
|
|
|
|
|
|
/* copy back packet headers if we sanitized */
|
|
|
|
if (rewrite)
|
2004-02-26 02:34:12 +00:00
|
|
|
m_copyback(m, off, sizeof(*th), (caddr_t)th);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
return (PF_PASS);
|
|
|
|
|
|
|
|
tcp_drop:
|
|
|
|
REASON_SET(&reason, PFRES_NORM);
|
|
|
|
if (rm != NULL && r->log)
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
PFLOG_PACKET(kif, m, AF_INET, dir, reason, r, NULL, NULL, pd,
|
|
|
|
1);
|
2004-02-26 02:04:28 +00:00
|
|
|
return (PF_DROP);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pf_normalize_tcp_init(struct mbuf *m, int off, struct pf_pdesc *pd,
|
|
|
|
struct tcphdr *th, struct pf_state_peer *src, struct pf_state_peer *dst)
|
|
|
|
{
|
2005-05-03 16:43:32 +00:00
|
|
|
u_int32_t tsval, tsecr;
|
2004-02-26 02:04:28 +00:00
|
|
|
u_int8_t hdr[60];
|
|
|
|
u_int8_t *opt;
|
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
KASSERT((src->scrub == NULL),
|
2004-02-26 02:34:12 +00:00
|
|
|
("pf_normalize_tcp_init: src->scrub != NULL"));
|
2011-06-28 11:57:25 +00:00
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
src->scrub = uma_zalloc(V_pf_state_scrub_z, M_ZERO | M_NOWAIT);
|
2004-02-26 02:04:28 +00:00
|
|
|
if (src->scrub == NULL)
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
switch (pd->af) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET: {
|
|
|
|
struct ip *h = mtod(m, struct ip *);
|
|
|
|
src->scrub->pfss_ttl = h->ip_ttl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6: {
|
|
|
|
struct ip6_hdr *h = mtod(m, struct ip6_hdr *);
|
|
|
|
src->scrub->pfss_ttl = h->ip6_hlim;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All normalizations below are only begun if we see the start of
|
|
|
|
* the connections. They must all set an enabled bit in pfss_flags
|
|
|
|
*/
|
|
|
|
if ((th->th_flags & TH_SYN) == 0)
|
2004-06-16 23:24:02 +00:00
|
|
|
return (0);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (th->th_off > (sizeof(struct tcphdr) >> 2) && src->scrub &&
|
|
|
|
pf_pull_hdr(m, off, hdr, th->th_off << 2, NULL, NULL, pd->af)) {
|
|
|
|
/* Diddle with TCP options */
|
|
|
|
int hlen;
|
|
|
|
opt = hdr + sizeof(struct tcphdr);
|
|
|
|
hlen = (th->th_off << 2) - sizeof(struct tcphdr);
|
|
|
|
while (hlen >= TCPOLEN_TIMESTAMP) {
|
|
|
|
switch (*opt) {
|
|
|
|
case TCPOPT_EOL: /* FALLTHROUGH */
|
|
|
|
case TCPOPT_NOP:
|
|
|
|
opt++;
|
|
|
|
hlen--;
|
|
|
|
break;
|
|
|
|
case TCPOPT_TIMESTAMP:
|
|
|
|
if (opt[1] >= TCPOLEN_TIMESTAMP) {
|
|
|
|
src->scrub->pfss_flags |=
|
|
|
|
PFSS_TIMESTAMP;
|
2005-05-03 16:43:32 +00:00
|
|
|
src->scrub->pfss_ts_mod =
|
|
|
|
htonl(arc4random());
|
|
|
|
|
|
|
|
/* note PFSS_PAWS not set yet */
|
|
|
|
memcpy(&tsval, &opt[2],
|
|
|
|
sizeof(u_int32_t));
|
|
|
|
memcpy(&tsecr, &opt[6],
|
|
|
|
sizeof(u_int32_t));
|
|
|
|
src->scrub->pfss_tsval0 = ntohl(tsval);
|
|
|
|
src->scrub->pfss_tsval = ntohl(tsval);
|
|
|
|
src->scrub->pfss_tsecr = ntohl(tsecr);
|
|
|
|
getmicrouptime(&src->scrub->pfss_last);
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
2004-06-17 16:59:47 +00:00
|
|
|
hlen -= MAX(opt[1], 2);
|
|
|
|
opt += MAX(opt[1], 2);
|
2004-02-26 02:04:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pf_normalize_tcp_cleanup(struct pf_state *state)
|
|
|
|
{
|
|
|
|
if (state->src.scrub)
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
uma_zfree(V_pf_state_scrub_z, state->src.scrub);
|
2004-02-26 02:04:28 +00:00
|
|
|
if (state->dst.scrub)
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
uma_zfree(V_pf_state_scrub_z, state->dst.scrub);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/* Someday... flush the TCP segment reassembly descriptors. */
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pf_normalize_tcp_stateful(struct mbuf *m, int off, struct pf_pdesc *pd,
|
2005-05-03 16:43:32 +00:00
|
|
|
u_short *reason, struct tcphdr *th, struct pf_state *state,
|
|
|
|
struct pf_state_peer *src, struct pf_state_peer *dst, int *writeback)
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
2005-05-03 16:43:32 +00:00
|
|
|
struct timeval uptime;
|
|
|
|
u_int32_t tsval, tsecr;
|
|
|
|
u_int tsval_from_last;
|
2004-02-26 02:04:28 +00:00
|
|
|
u_int8_t hdr[60];
|
|
|
|
u_int8_t *opt;
|
|
|
|
int copyback = 0;
|
2005-05-03 16:43:32 +00:00
|
|
|
int got_ts = 0;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
KASSERT((src->scrub || dst->scrub),
|
|
|
|
("%s: src->scrub && dst->scrub!", __func__));
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enforce the minimum TTL seen for this connection. Negate a common
|
|
|
|
* technique to evade an intrusion detection system and confuse
|
|
|
|
* firewall state code.
|
|
|
|
*/
|
|
|
|
switch (pd->af) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET: {
|
|
|
|
if (src->scrub) {
|
|
|
|
struct ip *h = mtod(m, struct ip *);
|
|
|
|
if (h->ip_ttl > src->scrub->pfss_ttl)
|
|
|
|
src->scrub->pfss_ttl = h->ip_ttl;
|
|
|
|
h->ip_ttl = src->scrub->pfss_ttl;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* INET */
|
|
|
|
#ifdef INET6
|
|
|
|
case AF_INET6: {
|
2004-06-16 23:24:02 +00:00
|
|
|
if (src->scrub) {
|
2004-02-26 02:04:28 +00:00
|
|
|
struct ip6_hdr *h = mtod(m, struct ip6_hdr *);
|
|
|
|
if (h->ip6_hlim > src->scrub->pfss_ttl)
|
|
|
|
src->scrub->pfss_ttl = h->ip6_hlim;
|
|
|
|
h->ip6_hlim = src->scrub->pfss_ttl;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* INET6 */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (th->th_off > (sizeof(struct tcphdr) >> 2) &&
|
|
|
|
((src->scrub && (src->scrub->pfss_flags & PFSS_TIMESTAMP)) ||
|
|
|
|
(dst->scrub && (dst->scrub->pfss_flags & PFSS_TIMESTAMP))) &&
|
|
|
|
pf_pull_hdr(m, off, hdr, th->th_off << 2, NULL, NULL, pd->af)) {
|
|
|
|
/* Diddle with TCP options */
|
|
|
|
int hlen;
|
|
|
|
opt = hdr + sizeof(struct tcphdr);
|
|
|
|
hlen = (th->th_off << 2) - sizeof(struct tcphdr);
|
|
|
|
while (hlen >= TCPOLEN_TIMESTAMP) {
|
|
|
|
switch (*opt) {
|
|
|
|
case TCPOPT_EOL: /* FALLTHROUGH */
|
|
|
|
case TCPOPT_NOP:
|
|
|
|
opt++;
|
|
|
|
hlen--;
|
|
|
|
break;
|
|
|
|
case TCPOPT_TIMESTAMP:
|
|
|
|
/* Modulate the timestamps. Can be used for
|
|
|
|
* NAT detection, OS uptime determination or
|
|
|
|
* reboot detection.
|
|
|
|
*/
|
2005-05-03 16:43:32 +00:00
|
|
|
|
|
|
|
if (got_ts) {
|
|
|
|
/* Huh? Multiple timestamps!? */
|
2011-06-28 11:57:25 +00:00
|
|
|
if (V_pf_status.debug >= PF_DEBUG_MISC) {
|
2005-05-03 16:43:32 +00:00
|
|
|
DPFPRINTF(("multiple TS??"));
|
|
|
|
pf_print_state(state);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
REASON_SET(reason, PFRES_TS);
|
|
|
|
return (PF_DROP);
|
|
|
|
}
|
2004-02-26 02:04:28 +00:00
|
|
|
if (opt[1] >= TCPOLEN_TIMESTAMP) {
|
2005-05-03 16:43:32 +00:00
|
|
|
memcpy(&tsval, &opt[2],
|
|
|
|
sizeof(u_int32_t));
|
|
|
|
if (tsval && src->scrub &&
|
2004-02-26 02:04:28 +00:00
|
|
|
(src->scrub->pfss_flags &
|
|
|
|
PFSS_TIMESTAMP)) {
|
2005-05-03 16:43:32 +00:00
|
|
|
tsval = ntohl(tsval);
|
2015-10-14 16:21:41 +00:00
|
|
|
pf_change_proto_a(m, &opt[2],
|
2005-05-03 16:43:32 +00:00
|
|
|
&th->th_sum,
|
|
|
|
htonl(tsval +
|
|
|
|
src->scrub->pfss_ts_mod),
|
|
|
|
0);
|
2004-02-26 02:04:28 +00:00
|
|
|
copyback = 1;
|
|
|
|
}
|
2004-06-16 23:24:02 +00:00
|
|
|
|
|
|
|
/* Modulate TS reply iff valid (!0) */
|
2005-05-03 16:43:32 +00:00
|
|
|
memcpy(&tsecr, &opt[6],
|
2004-06-16 23:24:02 +00:00
|
|
|
sizeof(u_int32_t));
|
2005-05-03 16:43:32 +00:00
|
|
|
if (tsecr && dst->scrub &&
|
2004-02-26 02:04:28 +00:00
|
|
|
(dst->scrub->pfss_flags &
|
|
|
|
PFSS_TIMESTAMP)) {
|
2005-05-03 16:43:32 +00:00
|
|
|
tsecr = ntohl(tsecr)
|
|
|
|
- dst->scrub->pfss_ts_mod;
|
2015-10-14 16:21:41 +00:00
|
|
|
pf_change_proto_a(m, &opt[6],
|
2005-05-03 16:43:32 +00:00
|
|
|
&th->th_sum, htonl(tsecr),
|
|
|
|
0);
|
2004-02-26 02:04:28 +00:00
|
|
|
copyback = 1;
|
|
|
|
}
|
2005-05-03 16:43:32 +00:00
|
|
|
got_ts = 1;
|
2004-02-26 02:04:28 +00:00
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
default:
|
2004-06-17 16:59:47 +00:00
|
|
|
hlen -= MAX(opt[1], 2);
|
|
|
|
opt += MAX(opt[1], 2);
|
2004-02-26 02:04:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (copyback) {
|
|
|
|
/* Copyback the options, caller copys back header */
|
|
|
|
*writeback = 1;
|
|
|
|
m_copyback(m, off + sizeof(struct tcphdr),
|
|
|
|
(th->th_off << 2) - sizeof(struct tcphdr), hdr +
|
|
|
|
sizeof(struct tcphdr));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-05-03 16:43:32 +00:00
|
|
|
/*
|
|
|
|
* Must invalidate PAWS checks on connections idle for too long.
|
|
|
|
* The fastest allowed timestamp clock is 1ms. That turns out to
|
|
|
|
* be about 24 days before it wraps. XXX Right now our lowerbound
|
|
|
|
* TS echo check only works for the first 12 days of a connection
|
|
|
|
* when the TS has exhausted half its 32bit space
|
|
|
|
*/
|
|
|
|
#define TS_MAX_IDLE (24*24*60*60)
|
|
|
|
#define TS_MAX_CONN (12*24*60*60) /* XXX remove when better tsecr check */
|
|
|
|
|
|
|
|
getmicrouptime(&uptime);
|
|
|
|
if (src->scrub && (src->scrub->pfss_flags & PFSS_PAWS) &&
|
|
|
|
(uptime.tv_sec - src->scrub->pfss_last.tv_sec > TS_MAX_IDLE ||
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
time_uptime - state->creation > TS_MAX_CONN)) {
|
2011-06-28 11:57:25 +00:00
|
|
|
if (V_pf_status.debug >= PF_DEBUG_MISC) {
|
2005-05-03 16:43:32 +00:00
|
|
|
DPFPRINTF(("src idled out of PAWS\n"));
|
|
|
|
pf_print_state(state);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
src->scrub->pfss_flags = (src->scrub->pfss_flags & ~PFSS_PAWS)
|
|
|
|
| PFSS_PAWS_IDLED;
|
|
|
|
}
|
|
|
|
if (dst->scrub && (dst->scrub->pfss_flags & PFSS_PAWS) &&
|
|
|
|
uptime.tv_sec - dst->scrub->pfss_last.tv_sec > TS_MAX_IDLE) {
|
2011-06-28 11:57:25 +00:00
|
|
|
if (V_pf_status.debug >= PF_DEBUG_MISC) {
|
2005-05-03 16:43:32 +00:00
|
|
|
DPFPRINTF(("dst idled out of PAWS\n"));
|
|
|
|
pf_print_state(state);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
dst->scrub->pfss_flags = (dst->scrub->pfss_flags & ~PFSS_PAWS)
|
|
|
|
| PFSS_PAWS_IDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (got_ts && src->scrub && dst->scrub &&
|
|
|
|
(src->scrub->pfss_flags & PFSS_PAWS) &&
|
|
|
|
(dst->scrub->pfss_flags & PFSS_PAWS)) {
|
|
|
|
/* Validate that the timestamps are "in-window".
|
|
|
|
* RFC1323 describes TCP Timestamp options that allow
|
|
|
|
* measurement of RTT (round trip time) and PAWS
|
|
|
|
* (protection against wrapped sequence numbers). PAWS
|
|
|
|
* gives us a set of rules for rejecting packets on
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
* long fat pipes (packets that were somehow delayed
|
2005-05-03 16:43:32 +00:00
|
|
|
* in transit longer than the time it took to send the
|
|
|
|
* full TCP sequence space of 4Gb). We can use these
|
|
|
|
* rules and infer a few others that will let us treat
|
|
|
|
* the 32bit timestamp and the 32bit echoed timestamp
|
|
|
|
* as sequence numbers to prevent a blind attacker from
|
|
|
|
* inserting packets into a connection.
|
|
|
|
*
|
|
|
|
* RFC1323 tells us:
|
|
|
|
* - The timestamp on this packet must be greater than
|
|
|
|
* or equal to the last value echoed by the other
|
|
|
|
* endpoint. The RFC says those will be discarded
|
|
|
|
* since it is a dup that has already been acked.
|
|
|
|
* This gives us a lowerbound on the timestamp.
|
|
|
|
* timestamp >= other last echoed timestamp
|
|
|
|
* - The timestamp will be less than or equal to
|
|
|
|
* the last timestamp plus the time between the
|
|
|
|
* last packet and now. The RFC defines the max
|
|
|
|
* clock rate as 1ms. We will allow clocks to be
|
|
|
|
* up to 10% fast and will allow a total difference
|
|
|
|
* or 30 seconds due to a route change. And this
|
|
|
|
* gives us an upperbound on the timestamp.
|
|
|
|
* timestamp <= last timestamp + max ticks
|
|
|
|
* We have to be careful here. Windows will send an
|
|
|
|
* initial timestamp of zero and then initialize it
|
|
|
|
* to a random value after the 3whs; presumably to
|
|
|
|
* avoid a DoS by having to call an expensive RNG
|
|
|
|
* during a SYN flood. Proof MS has at least one
|
|
|
|
* good security geek.
|
|
|
|
*
|
|
|
|
* - The TCP timestamp option must also echo the other
|
|
|
|
* endpoints timestamp. The timestamp echoed is the
|
|
|
|
* one carried on the earliest unacknowledged segment
|
|
|
|
* on the left edge of the sequence window. The RFC
|
|
|
|
* states that the host will reject any echoed
|
|
|
|
* timestamps that were larger than any ever sent.
|
|
|
|
* This gives us an upperbound on the TS echo.
|
|
|
|
* tescr <= largest_tsval
|
|
|
|
* - The lowerbound on the TS echo is a little more
|
|
|
|
* tricky to determine. The other endpoint's echoed
|
|
|
|
* values will not decrease. But there may be
|
|
|
|
* network conditions that re-order packets and
|
|
|
|
* cause our view of them to decrease. For now the
|
|
|
|
* only lowerbound we can safely determine is that
|
2011-06-28 11:57:25 +00:00
|
|
|
* the TS echo will never be less than the original
|
2005-05-03 16:43:32 +00:00
|
|
|
* TS. XXX There is probably a better lowerbound.
|
|
|
|
* Remove TS_MAX_CONN with better lowerbound check.
|
|
|
|
* tescr >= other original TS
|
|
|
|
*
|
|
|
|
* It is also important to note that the fastest
|
|
|
|
* timestamp clock of 1ms will wrap its 32bit space in
|
|
|
|
* 24 days. So we just disable TS checking after 24
|
|
|
|
* days of idle time. We actually must use a 12d
|
|
|
|
* connection limit until we can come up with a better
|
|
|
|
* lowerbound to the TS echo check.
|
|
|
|
*/
|
|
|
|
struct timeval delta_ts;
|
|
|
|
int ts_fudge;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PFTM_TS_DIFF is how many seconds of leeway to allow
|
|
|
|
* a host's timestamp. This can happen if the previous
|
|
|
|
* packet got delayed in transit for much longer than
|
|
|
|
* this packet.
|
|
|
|
*/
|
|
|
|
if ((ts_fudge = state->rule.ptr->timeout[PFTM_TS_DIFF]) == 0)
|
2011-06-28 11:57:25 +00:00
|
|
|
ts_fudge = V_pf_default_rule.timeout[PFTM_TS_DIFF];
|
2005-05-03 16:43:32 +00:00
|
|
|
|
|
|
|
/* Calculate max ticks since the last timestamp */
|
|
|
|
#define TS_MAXFREQ 1100 /* RFC max TS freq of 1Khz + 10% skew */
|
|
|
|
#define TS_MICROSECS 1000000 /* microseconds per second */
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
delta_ts = uptime;
|
|
|
|
timevalsub(&delta_ts, &src->scrub->pfss_last);
|
2005-05-03 16:43:32 +00:00
|
|
|
tsval_from_last = (delta_ts.tv_sec + ts_fudge) * TS_MAXFREQ;
|
|
|
|
tsval_from_last += delta_ts.tv_usec / (TS_MICROSECS/TS_MAXFREQ);
|
|
|
|
|
|
|
|
if ((src->state >= TCPS_ESTABLISHED &&
|
|
|
|
dst->state >= TCPS_ESTABLISHED) &&
|
|
|
|
(SEQ_LT(tsval, dst->scrub->pfss_tsecr) ||
|
|
|
|
SEQ_GT(tsval, src->scrub->pfss_tsval + tsval_from_last) ||
|
|
|
|
(tsecr && (SEQ_GT(tsecr, dst->scrub->pfss_tsval) ||
|
|
|
|
SEQ_LT(tsecr, dst->scrub->pfss_tsval0))))) {
|
|
|
|
/* Bad RFC1323 implementation or an insertion attack.
|
|
|
|
*
|
|
|
|
* - Solaris 2.6 and 2.7 are known to send another ACK
|
|
|
|
* after the FIN,FIN|ACK,ACK closing that carries
|
|
|
|
* an old timestamp.
|
|
|
|
*/
|
|
|
|
|
|
|
|
DPFPRINTF(("Timestamp failed %c%c%c%c\n",
|
|
|
|
SEQ_LT(tsval, dst->scrub->pfss_tsecr) ? '0' : ' ',
|
|
|
|
SEQ_GT(tsval, src->scrub->pfss_tsval +
|
|
|
|
tsval_from_last) ? '1' : ' ',
|
|
|
|
SEQ_GT(tsecr, dst->scrub->pfss_tsval) ? '2' : ' ',
|
|
|
|
SEQ_LT(tsecr, dst->scrub->pfss_tsval0)? '3' : ' '));
|
|
|
|
DPFPRINTF((" tsval: %u tsecr: %u +ticks: %u "
|
2005-12-25 22:57:08 +00:00
|
|
|
"idle: %jus %lums\n",
|
|
|
|
tsval, tsecr, tsval_from_last,
|
|
|
|
(uintmax_t)delta_ts.tv_sec,
|
2005-05-03 16:43:32 +00:00
|
|
|
delta_ts.tv_usec / 1000));
|
|
|
|
DPFPRINTF((" src->tsval: %u tsecr: %u\n",
|
|
|
|
src->scrub->pfss_tsval, src->scrub->pfss_tsecr));
|
|
|
|
DPFPRINTF((" dst->tsval: %u tsecr: %u tsval0: %u"
|
|
|
|
"\n", dst->scrub->pfss_tsval,
|
|
|
|
dst->scrub->pfss_tsecr, dst->scrub->pfss_tsval0));
|
2011-06-28 11:57:25 +00:00
|
|
|
if (V_pf_status.debug >= PF_DEBUG_MISC) {
|
2005-05-03 16:43:32 +00:00
|
|
|
pf_print_state(state);
|
|
|
|
pf_print_flags(th->th_flags);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
REASON_SET(reason, PFRES_TS);
|
|
|
|
return (PF_DROP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX I'd really like to require tsecr but it's optional */
|
|
|
|
|
|
|
|
} else if (!got_ts && (th->th_flags & TH_RST) == 0 &&
|
|
|
|
((src->state == TCPS_ESTABLISHED && dst->state == TCPS_ESTABLISHED)
|
|
|
|
|| pd->p_len > 0 || (th->th_flags & TH_SYN)) &&
|
|
|
|
src->scrub && dst->scrub &&
|
|
|
|
(src->scrub->pfss_flags & PFSS_PAWS) &&
|
|
|
|
(dst->scrub->pfss_flags & PFSS_PAWS)) {
|
|
|
|
/* Didn't send a timestamp. Timestamps aren't really useful
|
|
|
|
* when:
|
|
|
|
* - connection opening or closing (often not even sent).
|
|
|
|
* but we must not let an attacker to put a FIN on a
|
|
|
|
* data packet to sneak it through our ESTABLISHED check.
|
|
|
|
* - on a TCP reset. RFC suggests not even looking at TS.
|
|
|
|
* - on an empty ACK. The TS will not be echoed so it will
|
|
|
|
* probably not help keep the RTT calculation in sync and
|
|
|
|
* there isn't as much danger when the sequence numbers
|
|
|
|
* got wrapped. So some stacks don't include TS on empty
|
|
|
|
* ACKs :-(
|
|
|
|
*
|
|
|
|
* To minimize the disruption to mostly RFC1323 conformant
|
|
|
|
* stacks, we will only require timestamps on data packets.
|
|
|
|
*
|
|
|
|
* And what do ya know, we cannot require timestamps on data
|
|
|
|
* packets. There appear to be devices that do legitimate
|
|
|
|
* TCP connection hijacking. There are HTTP devices that allow
|
|
|
|
* a 3whs (with timestamps) and then buffer the HTTP request.
|
|
|
|
* If the intermediate device has the HTTP response cache, it
|
|
|
|
* will spoof the response but not bother timestamping its
|
|
|
|
* packets. So we can look for the presence of a timestamp in
|
|
|
|
* the first data packet and if there, require it in all future
|
|
|
|
* packets.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (pd->p_len > 0 && (src->scrub->pfss_flags & PFSS_DATA_TS)) {
|
|
|
|
/*
|
|
|
|
* Hey! Someone tried to sneak a packet in. Or the
|
|
|
|
* stack changed its RFC1323 behavior?!?!
|
|
|
|
*/
|
2011-06-28 11:57:25 +00:00
|
|
|
if (V_pf_status.debug >= PF_DEBUG_MISC) {
|
2005-05-03 16:43:32 +00:00
|
|
|
DPFPRINTF(("Did not receive expected RFC1323 "
|
|
|
|
"timestamp\n"));
|
|
|
|
pf_print_state(state);
|
|
|
|
pf_print_flags(th->th_flags);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
REASON_SET(reason, PFRES_TS);
|
|
|
|
return (PF_DROP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We will note if a host sends his data packets with or without
|
|
|
|
* timestamps. And require all data packets to contain a timestamp
|
|
|
|
* if the first does. PAWS implicitly requires that all data packets be
|
|
|
|
* timestamped. But I think there are middle-man devices that hijack
|
2007-07-03 12:16:07 +00:00
|
|
|
* TCP streams immediately after the 3whs and don't timestamp their
|
2005-05-03 16:43:32 +00:00
|
|
|
* packets (seen in a WWW accelerator or cache).
|
|
|
|
*/
|
|
|
|
if (pd->p_len > 0 && src->scrub && (src->scrub->pfss_flags &
|
|
|
|
(PFSS_TIMESTAMP|PFSS_DATA_TS|PFSS_DATA_NOTS)) == PFSS_TIMESTAMP) {
|
|
|
|
if (got_ts)
|
|
|
|
src->scrub->pfss_flags |= PFSS_DATA_TS;
|
|
|
|
else {
|
|
|
|
src->scrub->pfss_flags |= PFSS_DATA_NOTS;
|
2011-06-28 11:57:25 +00:00
|
|
|
if (V_pf_status.debug >= PF_DEBUG_MISC && dst->scrub &&
|
2005-05-03 16:43:32 +00:00
|
|
|
(dst->scrub->pfss_flags & PFSS_TIMESTAMP)) {
|
|
|
|
/* Don't warn if other host rejected RFC1323 */
|
|
|
|
DPFPRINTF(("Broken RFC1323 stack did not "
|
|
|
|
"timestamp data packet. Disabled PAWS "
|
|
|
|
"security.\n"));
|
|
|
|
pf_print_state(state);
|
|
|
|
pf_print_flags(th->th_flags);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update PAWS values
|
|
|
|
*/
|
|
|
|
if (got_ts && src->scrub && PFSS_TIMESTAMP == (src->scrub->pfss_flags &
|
|
|
|
(PFSS_PAWS_IDLED|PFSS_TIMESTAMP))) {
|
|
|
|
getmicrouptime(&src->scrub->pfss_last);
|
|
|
|
if (SEQ_GEQ(tsval, src->scrub->pfss_tsval) ||
|
|
|
|
(src->scrub->pfss_flags & PFSS_PAWS) == 0)
|
|
|
|
src->scrub->pfss_tsval = tsval;
|
|
|
|
|
|
|
|
if (tsecr) {
|
|
|
|
if (SEQ_GEQ(tsecr, src->scrub->pfss_tsecr) ||
|
|
|
|
(src->scrub->pfss_flags & PFSS_PAWS) == 0)
|
|
|
|
src->scrub->pfss_tsecr = tsecr;
|
|
|
|
|
|
|
|
if ((src->scrub->pfss_flags & PFSS_PAWS) == 0 &&
|
|
|
|
(SEQ_LT(tsval, src->scrub->pfss_tsval0) ||
|
|
|
|
src->scrub->pfss_tsval0 == 0)) {
|
|
|
|
/* tsval0 MUST be the lowest timestamp */
|
|
|
|
src->scrub->pfss_tsval0 = tsval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Only fully initialized after a TS gets echoed */
|
|
|
|
if ((src->scrub->pfss_flags & PFSS_PAWS) == 0)
|
|
|
|
src->scrub->pfss_flags |= PFSS_PAWS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
/* I have a dream.... TCP segment reassembly.... */
|
|
|
|
return (0);
|
|
|
|
}
|
2005-05-03 16:43:32 +00:00
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static int
|
2004-02-26 02:04:28 +00:00
|
|
|
pf_normalize_tcpopt(struct pf_rule *r, struct mbuf *m, struct tcphdr *th,
|
2011-06-28 11:57:25 +00:00
|
|
|
int off, sa_family_t af)
|
2004-02-26 02:04:28 +00:00
|
|
|
{
|
|
|
|
u_int16_t *mss;
|
|
|
|
int thoff;
|
|
|
|
int opt, cnt, optlen = 0;
|
|
|
|
int rewrite = 0;
|
2011-06-28 11:57:25 +00:00
|
|
|
u_char opts[TCP_MAXOLEN];
|
|
|
|
u_char *optp = opts;
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
thoff = th->th_off << 2;
|
|
|
|
cnt = thoff - sizeof(struct tcphdr);
|
2011-06-28 11:57:25 +00:00
|
|
|
|
|
|
|
if (cnt > 0 && !pf_pull_hdr(m, off + sizeof(*th), opts, cnt,
|
|
|
|
NULL, NULL, af))
|
|
|
|
return (rewrite);
|
2004-02-26 02:04:28 +00:00
|
|
|
|
|
|
|
for (; cnt > 0; cnt -= optlen, optp += optlen) {
|
|
|
|
opt = optp[0];
|
|
|
|
if (opt == TCPOPT_EOL)
|
|
|
|
break;
|
|
|
|
if (opt == TCPOPT_NOP)
|
|
|
|
optlen = 1;
|
|
|
|
else {
|
|
|
|
if (cnt < 2)
|
|
|
|
break;
|
|
|
|
optlen = optp[1];
|
|
|
|
if (optlen < 2 || optlen > cnt)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (opt) {
|
|
|
|
case TCPOPT_MAXSEG:
|
|
|
|
mss = (u_int16_t *)(optp + 2);
|
|
|
|
if ((ntohs(*mss)) > r->max_mss) {
|
2015-10-14 16:21:41 +00:00
|
|
|
th->th_sum = pf_proto_cksum_fixup(m,
|
|
|
|
th->th_sum, *mss, htons(r->max_mss), 0);
|
2004-02-26 02:04:28 +00:00
|
|
|
*mss = htons(r->max_mss);
|
|
|
|
rewrite = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-28 11:57:25 +00:00
|
|
|
if (rewrite)
|
|
|
|
m_copyback(m, off + sizeof(*th), thoff - sizeof(*th), opts);
|
|
|
|
|
2004-02-26 02:04:28 +00:00
|
|
|
return (rewrite);
|
|
|
|
}
|
2011-06-28 11:57:25 +00:00
|
|
|
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#ifdef INET
|
|
|
|
static void
|
2011-06-28 11:57:25 +00:00
|
|
|
pf_scrub_ip(struct mbuf **m0, u_int32_t flags, u_int8_t min_ttl, u_int8_t tos)
|
|
|
|
{
|
|
|
|
struct mbuf *m = *m0;
|
|
|
|
struct ip *h = mtod(m, struct ip *);
|
|
|
|
|
|
|
|
/* Clear IP_DF if no-df was requested */
|
|
|
|
if (flags & PFRULE_NODF && h->ip_off & htons(IP_DF)) {
|
|
|
|
u_int16_t ip_off = h->ip_off;
|
|
|
|
|
|
|
|
h->ip_off &= htons(~IP_DF);
|
|
|
|
h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_off, h->ip_off, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enforce a minimum ttl, may cause endless packet loops */
|
|
|
|
if (min_ttl && h->ip_ttl < min_ttl) {
|
|
|
|
u_int16_t ip_ttl = h->ip_ttl;
|
|
|
|
|
|
|
|
h->ip_ttl = min_ttl;
|
|
|
|
h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_ttl, h->ip_ttl, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enforce tos */
|
|
|
|
if (flags & PFRULE_SET_TOS) {
|
|
|
|
u_int16_t ov, nv;
|
|
|
|
|
|
|
|
ov = *(u_int16_t *)h;
|
2016-10-13 20:34:44 +00:00
|
|
|
h->ip_tos = tos | (h->ip_tos & IPTOS_ECN_MASK);
|
2011-06-28 11:57:25 +00:00
|
|
|
nv = *(u_int16_t *)h;
|
|
|
|
|
|
|
|
h->ip_sum = pf_cksum_fixup(h->ip_sum, ov, nv, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* random-id, but not for fragments */
|
|
|
|
if (flags & PFRULE_RANDOMID && !(h->ip_off & ~htons(IP_DF))) {
|
2015-04-01 22:26:39 +00:00
|
|
|
uint16_t ip_id = h->ip_id;
|
2011-06-28 11:57:25 +00:00
|
|
|
|
2015-04-01 22:26:39 +00:00
|
|
|
ip_fillid(h);
|
2011-06-28 11:57:25 +00:00
|
|
|
h->ip_sum = pf_cksum_fixup(h->ip_sum, ip_id, h->ip_id, 0);
|
|
|
|
}
|
|
|
|
}
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
#endif /* INET */
|
2011-06-28 11:57:25 +00:00
|
|
|
|
|
|
|
#ifdef INET6
|
Merge the projects/pf/head branch, that was worked on for last six months,
into head. The most significant achievements in the new code:
o Fine grained locking, thus much better performance.
o Fixes to many problems in pf, that were specific to FreeBSD port.
New code doesn't have that many ifdefs and much less OpenBSDisms, thus
is more attractive to our developers.
Those interested in details, can browse through SVN log of the
projects/pf/head branch. And for reference, here is exact list of
revisions merged:
r232043, r232044, r232062, r232148, r232149, r232150, r232298, r232330,
r232332, r232340, r232386, r232390, r232391, r232605, r232655, r232656,
r232661, r232662, r232663, r232664, r232673, r232691, r233309, r233782,
r233829, r233830, r233834, r233835, r233836, r233865, r233866, r233868,
r233873, r234056, r234096, r234100, r234108, r234175, r234187, r234223,
r234271, r234272, r234282, r234307, r234309, r234382, r234384, r234456,
r234486, r234606, r234640, r234641, r234642, r234644, r234651, r235505,
r235506, r235535, r235605, r235606, r235826, r235991, r235993, r236168,
r236173, r236179, r236180, r236181, r236186, r236223, r236227, r236230,
r236252, r236254, r236298, r236299, r236300, r236301, r236397, r236398,
r236399, r236499, r236512, r236513, r236525, r236526, r236545, r236548,
r236553, r236554, r236556, r236557, r236561, r236570, r236630, r236672,
r236673, r236679, r236706, r236710, r236718, r237154, r237155, r237169,
r237314, r237363, r237364, r237368, r237369, r237376, r237440, r237442,
r237751, r237783, r237784, r237785, r237788, r237791, r238421, r238522,
r238523, r238524, r238525, r239173, r239186, r239644, r239652, r239661,
r239773, r240125, r240130, r240131, r240136, r240186, r240196, r240212.
I'd like to thank people who participated in early testing:
Tested by: Florian Smeets <flo freebsd.org>
Tested by: Chekaluk Vitaly <artemrts ukr.net>
Tested by: Ben Wilber <ben desync.com>
Tested by: Ian FREISLICH <ianf cloudseed.co.za>
2012-09-08 06:41:54 +00:00
|
|
|
static void
|
2011-06-28 11:57:25 +00:00
|
|
|
pf_scrub_ip6(struct mbuf **m0, u_int8_t min_ttl)
|
|
|
|
{
|
|
|
|
struct mbuf *m = *m0;
|
|
|
|
struct ip6_hdr *h = mtod(m, struct ip6_hdr *);
|
|
|
|
|
|
|
|
/* Enforce a minimum ttl, may cause endless packet loops */
|
|
|
|
if (min_ttl && h->ip6_hlim < min_ttl)
|
|
|
|
h->ip6_hlim = min_ttl;
|
|
|
|
}
|
|
|
|
#endif
|