Import of pkgsrc-2013Q2

This commit is contained in:
2013-09-26 17:14:40 +02:00
commit 785076ae39
74991 changed files with 4380255 additions and 0 deletions

2
sysutils/pftop/DESCR Normal file
View File

@@ -0,0 +1,2 @@
Pftop is a small, curses-based utility for real-time display of
active states and rule statistics for PF, the packet filter from OpenBSD.

29
sysutils/pftop/Makefile Normal file
View File

@@ -0,0 +1,29 @@
# $NetBSD: Makefile,v 1.16 2013/02/06 19:31:05 jperkin Exp $
DISTNAME= pftop-0.7
PKGREVISION= 2
CATEGORIES= sysutils net
MASTER_SITES= http://www.eee.metu.edu.tr/~canacar/
MAINTAINER= pkgsrc-users@NetBSD.org
HOMEPAGE= http://www.eee.metu.edu.tr/~canacar/pftop/
COMMENT= Utility for real-time display of statistics for PF
NO_CONFIGURE= yes
MAKE_ENV+= OSLEVEL=${PF_VERSION:S/.//}
CFLAGS+= -I${PREFIX}/include
OSVERSION_SPECIFIC= yes
INSTALLATION_DIRS= ${PKGMANDIR}/man8 sbin
post-patch:
@${ECHO} "#include <pcap.h>" > ${WRKSRC}/pcap-int.h
do-install:
${INSTALL_PROGRAM} ${WRKSRC}/pftop ${DESTDIR}${PREFIX}/sbin
${INSTALL_MAN} ${WRKSRC}/pftop.8 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man8
.include "../../net/libpcap/buildlink3.mk"
.include "../../mk/pf.buildlink3.mk"
.include "../../mk/bsd.pkg.mk"

3
sysutils/pftop/PLIST Normal file
View File

@@ -0,0 +1,3 @@
@comment $NetBSD: PLIST,v 1.1.1.1 2004/11/05 15:08:33 peter Exp $
sbin/pftop
man/man8/pftop.8

17
sysutils/pftop/distinfo Normal file
View File

@@ -0,0 +1,17 @@
$NetBSD: distinfo,v 1.9 2011/06/10 11:45:01 obache Exp $
SHA1 (pftop-0.7.tar.gz) = 651afa532cfc8cf59c3598704deb9bf3788ac9e9
RMD160 (pftop-0.7.tar.gz) = 0e0c09e5feeb07deba8b540233dcb946ba0b4508
Size (pftop-0.7.tar.gz) = 59765 bytes
SHA1 (patch-aa) = ff5c522223472188933a6ccbe9725190dc8ec1b5
SHA1 (patch-ab) = fccf6fe5348f24d00dbf26cbe1880b9298774c6b
SHA1 (patch-ac) = 0bbbe06873c76393cc14c17f2f9a946ded71d068
SHA1 (patch-ad) = a2999c5c42d96baf6bde55c2925f83aadee17394
SHA1 (patch-ae) = 54619b846899a7c4f260191a772e41e1c07c178c
SHA1 (patch-af) = 59b907b20fa215b3f0a1e690c9c71d2f7077e322
SHA1 (patch-ag) = 2e749dc45b2b91a1563bc1467b69775f595e4d03
SHA1 (patch-ah) = 7adca5a484de91bf89e66d10ab645912068cd1c2
SHA1 (patch-ai) = 629c1668eab0d819e590fb62b7afa6c85709fd15
SHA1 (patch-aj) = ad0ddcbadbcd342c4973f932a3b7042a1c97e66b
SHA1 (patch-ak) = 78622d902016fa559ae3090d9c8407337d7cd0ed
SHA1 (patch-al) = 94f87c9655fd772e05e193da90617d12200a6ae5

View File

@@ -0,0 +1,30 @@
$NetBSD: patch-aa,v 1.3 2010/09/18 20:48:23 wiz Exp $
--- Makefile.orig 2007-11-07 07:34:18 +0100
+++ Makefile 2009-11-17 00:59:26 +0100
@@ -6,17 +6,21 @@
PROG= pftop
SRCS= pftop.c cache.c engine.c
-SRCS+= sf-gencode.c sf-grammer.y sf-scanner.l pcap-nametoaddr.c
-SRCS+= bpf_optimize.c bpf_filter.c bpf_dump.c bpf_image.c
+SRCS+= sf-gencode.c sf-grammer.c sf-scanner.l pcap-nametoaddr.c
+SRCS+= bpf_optimize.c
MAN= pftop.8
+CLEANFILES+= sf-grammer.c
+
CFLAGS+= -Wall -DOS_LEVEL=${OSLEVEL}
-LDADD+= -lcurses
+LDADD+= -lcurses -lpcap
+NOGCCERROR=yes
+
MANDIR=${LOCALBASE}/man/cat
BINDIR=${LOCALBASE}/sbin
-.y.c:
+sf-grammer.c: sf-grammer.y
${YACC.y} -d -b ${.TARGET:R} -o ${.TARGET} ${.IMPSRC}
.include <bsd.prog.mk>

View File

@@ -0,0 +1,93 @@
$NetBSD: patch-ab,v 1.6 2011/02/09 22:51:38 rumko Exp $
$OpenBSD: patch-cache_c,v 1.1 2008/06/13 00:38:12 canacar Exp $
* DragonFly compatibility
* Patches to support PF > 4.1 taken from OpenBSD's ports
--- cache.c.old 2008-06-14 17:43:59.000000000 +0200
+++ cache.c 2008-06-15 01:15:37.000000000 +0200
@@ -23,7 +23,11 @@
#include <netinet/in.h>
#include <netinet/tcp_fsm.h>
+#ifdef __DragonFly__
+#include <net/pf/pfvar.h>
+#else
#include <net/pfvar.h>
+#endif /* !__DragonFly__ */
#include <arpa/inet.h>
#include <stdio.h>
@@ -40,6 +44,7 @@
/* initialize the tree and queue */
RB_HEAD(sc_tree, sc_ent) sctree;
+RB_PROTOTYPE(sc_tree, sc_ent, tlink, sc_cmp);
TAILQ_HEAD(sc_queue, sc_ent) scq1, scq2, scq_free;
RB_GENERATE(sc_tree, sc_ent, tlink, sc_cmp);
@@ -118,12 +123,17 @@
cache_size--;
+#ifdef HAVE_PFSYNC_STATE
+ ent->id[0] = st->id[0];
+ ent->id[1] = st->id[1];
+#else
ent->addr[0] = st->lan.addr;
ent->port[0] = st->lan.port;
ent->addr[1] = st->ext.addr;
ent->port[1] = st->ext.port;
ent->af = st->af;
ent->proto = st->proto;
+#endif
#ifdef HAVE_INOUT_COUNT
ent->bytes = COUNTER(st->bytes[0]) + COUNTER(st->bytes[1]);
#else
@@ -147,13 +157,17 @@
if (cache_max == 0)
return (NULL);
+#ifdef HAVE_PFSYNC_STATE
+ ent.id[0] = st->id[0];
+ ent.id[1] = st->id[1];
+#else
ent.addr[0] = st->lan.addr;
ent.port[0] = st->lan.port;
ent.addr[1] = st->ext.addr;
ent.port[1] = st->ext.port;
ent.af = st->af;
ent.proto = st->proto;
-
+#endif
old = RB_FIND(sc_tree, &sctree, &ent);
if (old == NULL) {
@@ -210,8 +224,18 @@
static __inline int
sc_cmp(struct sc_ent *a, struct sc_ent *b)
{
+#ifdef HAVE_PFSYNC_STATE
+ if (a->id[0] > b->id[0])
+ return (1);
+ if (a->id[0] < b->id[0])
+ return (-1);
+ if (a->id[1] > b->id[1])
+ return (1);
+ if (a->id[1] < b->id[1])
+ return (-1);
+#else
int diff;
-
+
if ((diff = a->proto - b->proto) != 0)
return (diff);
if ((diff = a->af - b->af) != 0)
@@ -269,6 +293,6 @@
return (diff);
if ((diff = a->port[1] - b->port[1]) != 0)
return (diff);
-
+#endif
return (0);
}

View File

@@ -0,0 +1,32 @@
$NetBSD: patch-ac,v 1.4 2011/02/09 22:51:38 rumko Exp $
$OpenBSD: patch-config_h,v 1.5 2009/11/30 09:56:39 sthen Exp $
Patches to support PF > 4.1 taken from OpenBSD's ports.
--- config.h.old 2008-06-15 01:19:59.000000000 +0200
+++ config.h 2008-06-15 12:16:51.000000000 +0200
@@ -74,11 +74,24 @@
#define HAVE_PFSYNC_STATE
#endif
+#if OS_LEVEL > 43
+#define HAVE_PFSYNC_KEY
+#define HAVE_NETWORK_ORDER
+#endif
+
+/* #if OS_LEVEL > 46 */
+#undef HAVE_RULE_NATPASS
+/* #endif */
+
#ifdef HAVE_PFSYNC_STATE
typedef struct pfsync_state pf_state_t;
typedef struct pfsync_state_host pf_state_host_t;
typedef struct pfsync_state_peer pf_state_peer_t;
+#ifdef HAVE_NETWORK_ORDER
+#define COUNTER(c) ((((u_int64_t) ntohl(c[0]))<<32) + ntohl(c[1]))
+#else
#define COUNTER(c) ((((u_int64_t) c[0])<<32) + c[1])
+#endif
#define pfs_ifname ifname
#else
typedef struct pf_state pf_state_t;

View File

@@ -0,0 +1,283 @@
$NetBSD: patch-ad,v 1.3 2011/02/09 22:51:38 rumko Exp $
$OpenBSD: patch-engine_c,v 1.1 2008/06/13 00:38:12 canacar Exp $
* DragonFly compatibility
* Patches to support PF > 4.1 taken from OpenBSD's ports.
--- engine.c.orig 2007-11-07 07:35:44 +0100
+++ engine.c 2009-11-17 00:31:46 +0100
@@ -18,11 +18,18 @@
#include <sys/types.h>
+#ifdef __DragonFly__
+#include "queue.h"
+#else
#include <sys/queue.h>
+#endif
#include <ctype.h>
#include <curses.h>
+#include <errno.h>
+#include <poll.h>
#include <signal.h>
+#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -33,6 +40,10 @@
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
+#ifndef CIRCLEQ_END
+#define CIRCLEQ_END(head) ((void *)(head))
+#endif
+
/* circular linked list of views */
CIRCLEQ_HEAD(view_list, view_ent) view_head =
CIRCLEQ_HEAD_INITIALIZER(view_head);
@@ -55,9 +66,6 @@
volatile sig_atomic_t gotsig_close = 0;
volatile sig_atomic_t gotsig_resize = 0;
-volatile sig_atomic_t gotsig_alarm = 0;
-int need_update = 0;
-int need_sort = 0;
SCREEN *screen;
@@ -105,7 +113,6 @@
int
tbprintf(char *format, ...)
- GCC_PRINTFLIKE(1,2) /* defined in curses.h */
{
int len;
va_list arg;
@@ -482,7 +489,6 @@
v = ve->view;
if ((curr_view != NULL) && (curr_mgr != v->mgr)) {
- gotsig_alarm = 1;
if (v->mgr != NULL && v->mgr->select_fn != NULL)
v->mgr->select_fn();
}
@@ -491,7 +497,6 @@
curr_view = v;
curr_mgr = v->mgr;
field_setup();
- need_update = 1;
}
void
@@ -809,6 +814,9 @@
{
order_type *o, *oc;
+ if (curr_view->mgr->order_list == NULL)
+ return;
+
oc = curr_view->mgr->order_curr;
for (o = curr_view->mgr->order_list; o->name != NULL; o++) {
@@ -905,12 +913,6 @@
}
void
-sig_alarm(int signal)
-{
- gotsig_alarm = 1;
-}
-
-void
setup_term(int dmax)
{
max_disp = dmax;
@@ -941,8 +943,9 @@
keypad(stdscr, TRUE);
intrflush(stdscr, FALSE);
- halfdelay(10);
+ cbreak();
noecho();
+ timeout(0);
}
if (dmax == 0)
@@ -970,7 +973,6 @@
}
curr_message = NULL;
curr_cmd = cmd;
- need_update = 1;
return prev;
}
@@ -987,7 +989,6 @@
int
msgprintf(char *format, ...)
- GCC_PRINTFLIKE(1,2) /* defined in curses.h */
{
static char buf[1024];
int len;
@@ -1085,28 +1086,21 @@
if (curr_message != NULL) {
if (ch > 0) {
curr_message = NULL;
- need_update = 1;
}
}
switch (ch) {
- case ' ':
- gotsig_alarm = 1;
- break;
case 'o':
next_order();
- need_sort = 1;
break;
case 'p':
paused = !paused;
- gotsig_alarm = 1;
break;
case 'q':
gotsig_close = 1;
break;
case 'r':
sortdir *= -1;
- need_sort = 1;
break;
case 'v':
/* FALLTHROUGH */
@@ -1124,49 +1118,40 @@
/* FALLTHROUGH */
case CTRL_N:
dispstart++;
- need_update = 1;
break;
case KEY_UP:
/* FALLTHROUGH */
case CTRL_P:
dispstart--;
- need_update = 1;
break;
case KEY_NPAGE:
/* FALLTHROUGH */
case CTRL_V:
dispstart += maxprint;
- need_update = 1;
break;
case KEY_PPAGE:
/* FALLTHROUGH */
case META_V:
dispstart -= maxprint;
- need_update = 1;
break;
case KEY_HOME:
/* FALLTHROUGH */
case CTRL_A:
dispstart = 0;
- need_update = 1;
break;
case KEY_END:
/* FALLTHROUGH */
case CTRL_E:
dispstart = num_disp;
- need_update = 1;
break;
case CTRL_L:
clear();
- need_update = 1;
break;
default:
break;
}
- if (set_order_hotkey(ch))
- need_sort = 1;
- else
+ if (!set_order_hotkey(ch))
set_view_hotkey(ch);
}
@@ -1177,43 +1162,15 @@
signal(SIGINT, sig_close);
signal(SIGQUIT, sig_close);
signal(SIGWINCH, sig_resize);
- signal(SIGALRM, sig_alarm);
}
void
engine_loop(int countmax)
{
+ struct pollfd set[1];
int count = 0;
for (;;) {
- if (gotsig_alarm) {
- read_view();
- need_sort = 1;
- gotsig_alarm = 0;
- alarm(delay);
- }
-
- if (need_sort) {
- sort_view();
- need_sort = 0;
- need_update = 1;
-
- /* XXX if sort took too long */
- if (gotsig_alarm) {
- gotsig_alarm = 0;
- alarm(delay);
- }
- }
-
- if (need_update) {
- erase();
- disp_update();
- end_page();
- need_update = 0;
- if (countmax && ++count >= countmax)
- break;
- }
-
if (gotsig_close)
break;
if (gotsig_resize) {
@@ -1221,13 +1178,31 @@
endwin();
setup_term(max_disp);
gotsig_resize = 0;
- need_update = 1;
}
- if (interactive && need_update == 0)
- keyboard();
- else if (interactive == 0)
+ read_view();
+ sort_view();
+
+ if (rawmode == 0)
+ erase();
+ disp_update();
+ end_page();
+ if (countmax && ++count >= countmax)
+ break;
+
+ if (interactive) {
+ set[0].fd = STDIN_FILENO;
+ set[0].events = POLLIN;
+ if (poll(set, 1, delay * 1000) == -1) {
+ if (errno == EINTR)
+ continue;
+ break;
+ }
+ if ((set[0].revents & POLLIN) != 0)
+ keyboard();
+ } else {
sleep(delay);
+ }
}
if (rawmode == 0)

View File

@@ -0,0 +1,28 @@
$NetBSD: patch-ae,v 1.1 2008/06/15 14:09:04 peter Exp $
--- engine.h.old 2008-06-14 17:39:04.000000000 +0200
+++ engine.h 2008-06-15 12:38:21.000000000 +0200
@@ -100,8 +100,8 @@
void tb_end(void);
-int tbprintf(char *format, ...) GCC_PRINTFLIKE(1,2);
-int msgprintf(char *format, ...) GCC_PRINTFLIKE(1,2);
+int tbprintf(char *format, ...);
+int msgprintf(char *format, ...);
void end_line(void);
void end_page(void);
@@ -150,12 +150,8 @@
extern int rawwidth;
extern int columns, lines;
-extern int need_update;
-extern int need_sort;
-
extern volatile sig_atomic_t gotsig_close;
extern volatile sig_atomic_t gotsig_resize;
-extern volatile sig_atomic_t gotsig_alarm;
extern field_view *curr_view;
extern struct view_manager *curr_mgr;

View File

@@ -0,0 +1,12 @@
$NetBSD: patch-af,v 1.1 2008/06/15 14:09:04 peter Exp $
--- pftop.8.old 2008-06-14 18:16:37.000000000 +0200
+++ pftop.8 2008-06-14 18:16:47.000000000 +0200
@@ -143,6 +143,7 @@
.It Fl w Ar width
Set the width of the display for batch mode.
The default width is 80.
+.El
.Sh INTERACTIVE MODE
When
.Nm

View File

@@ -0,0 +1,627 @@
$NetBSD: patch-ag,v 1.3 2011/02/09 22:51:38 rumko Exp $
$OpenBSD: patch-pftop_c,v 1.13 2009/12/02 22:59:29 sthen Exp $
* DragonFly compatibility
* Patches to support PF > 4.1 taken from OpenBSD's ports.
--- pftop.c.orig 2007-11-07 07:36:46 +0100
+++ pftop.c 2009-11-16 23:37:03 +0100
@@ -40,21 +40,41 @@
#include <netinet/in.h>
#define TCPSTATES
#include <netinet/tcp_fsm.h>
+#ifdef __DragonFly__
+#include <net/pf/pfvar.h>
+#else
#include <net/pfvar.h>
+#endif /* !__DragonFly__ */
#include <arpa/inet.h>
#ifdef HAVE_ALTQ
+#ifdef __DragonFly__
+#include <net/altq/altq.h>
+#include <net/altq/altq_cbq.h>
+#include <net/altq/altq_priq.h>
+#include <net/altq/altq_hfsc.h>
+#else
#include <altq/altq.h>
#include <altq/altq_cbq.h>
#include <altq/altq_priq.h>
#include <altq/altq_hfsc.h>
#endif
+#ifdef ALTQT_FAIRQ
+#ifdef __DragonFly__
+#include <net/altq/altq_fairq.h>
+#else
+#include <altq/altq_fairq.h>
+#endif
+#endif
+#endif
+
#include <ctype.h>
#include <curses.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <limits.h>
#include <netdb.h>
#include <signal.h>
#include <stdio.h>
@@ -127,6 +147,13 @@
#define PT_NOROUTE(x) (0)
#endif
+#ifdef HAVE_NETWORK_ORDER
+#define PF_TSTAMP(x) ntohl(x)
+#else
+#define PF_TSTAMP(x) (x)
+#endif
+
+
/* view management */
int select_states(void);
int read_states(void);
@@ -371,6 +398,9 @@
class_stats_t cbq_stats;
struct priq_classstats priq_stats;
struct hfsc_classstats hfsc_stats;
+#ifdef ALTQT_FAIRQ
+ struct fairq_classstats fairq_stats;
+#endif
};
struct queue_stats {
@@ -445,11 +475,11 @@
int
sort_age_callback(const void *s1, const void *s2)
{
- if (state_buf[* (u_int32_t *) s2].creation >
- state_buf[* (u_int32_t *) s1].creation)
+ if (PF_TSTAMP(state_buf[* (u_int32_t *) s2].creation) >
+ PF_TSTAMP(state_buf[* (u_int32_t *) s1].creation))
return sortdir;
- if (state_buf[* (u_int32_t *) s2].creation <
- state_buf[* (u_int32_t *) s1].creation)
+ if (PF_TSTAMP(state_buf[* (u_int32_t *) s2].creation) <
+ PF_TSTAMP(state_buf[* (u_int32_t *) s1].creation))
return -sortdir;
return 0;
}
@@ -457,11 +487,11 @@
int
sort_exp_callback(const void *s1, const void *s2)
{
- if (state_buf[* (u_int32_t *) s2].expire >
- state_buf[* (u_int32_t *) s1].expire)
+ if (PF_TSTAMP(state_buf[* (u_int32_t *) s2].expire) >
+ PF_TSTAMP(state_buf[* (u_int32_t *) s1].expire))
return sortdir;
- if (state_buf[* (u_int32_t *) s2].expire <
- state_buf[* (u_int32_t *) s1].expire)
+ if (PF_TSTAMP(state_buf[* (u_int32_t *) s2].expire) <
+ PF_TSTAMP(state_buf[* (u_int32_t *) s1].expire))
return -sortdir;
return 0;
}
@@ -535,6 +565,115 @@
return 0;
}
+#ifdef HAVE_PFSYNC_KEY
+
+#ifdef __GNUC__
+__inline__
+#endif
+int
+sort_addr_callback(const pf_state_t *s1,
+ const pf_state_t *s2, int dir)
+{
+ const struct pf_addr *aa, *ab;
+ u_int16_t pa, pb;
+ int af, ret, ii, io;
+
+ af = s1->af;
+
+
+ if (af > s2->af)
+ return sortdir;
+ if (af < s2->af)
+ return -sortdir;
+
+ ii = io = 0;
+
+ if (dir == PF_OUT) /* looking for source addr */
+ io = 1;
+ else /* looking for dest addr */
+ ii = 1;
+
+ if (s1->direction == PF_IN) {
+ aa = &s1->key[PF_SK_STACK].addr[ii];
+ pa = s1->key[PF_SK_STACK].port[ii];
+ } else {
+ aa = &s1->key[PF_SK_WIRE].addr[io];
+ pa = s1->key[PF_SK_WIRE].port[io];
+ }
+
+ if (s2->direction == PF_IN) {
+ ab = &s2->key[PF_SK_STACK].addr[ii];;
+ pb = s2->key[PF_SK_STACK].port[ii];
+ } else {
+ ab = &s2->key[PF_SK_WIRE].addr[io];;
+ pb = s2->key[PF_SK_WIRE].port[io];
+ }
+
+ ret = compare_addr(af, aa, ab);
+ if (ret)
+ return ret * sortdir;
+
+ if (ntohs(pa) > ntohs(pb))
+ return sortdir;
+ return -sortdir;
+}
+
+#ifdef __GNUC__
+__inline__
+#endif
+int
+sort_port_callback(const pf_state_t *s1,
+ const pf_state_t *s2, int dir)
+{
+ const struct pf_addr *aa, *ab;
+ u_int16_t pa, pb;
+ int af, ret, ii, io;
+
+ af = s1->af;
+
+
+ if (af > s2->af)
+ return sortdir;
+ if (af < s2->af)
+ return -sortdir;
+
+ ii = io = 0;
+
+ if (dir == PF_OUT) /* looking for source addr */
+ io = 1;
+ else /* looking for dest addr */
+ ii = 1;
+
+ if (s1->direction == PF_IN) {
+ aa = &s1->key[PF_SK_STACK].addr[ii];
+ pa = s1->key[PF_SK_STACK].port[ii];
+ } else {
+ aa = &s1->key[PF_SK_WIRE].addr[io];
+ pa = s1->key[PF_SK_WIRE].port[io];
+ }
+
+ if (s2->direction == PF_IN) {
+ ab = &s2->key[PF_SK_STACK].addr[ii];;
+ pb = s2->key[PF_SK_STACK].port[ii];
+ } else {
+ ab = &s2->key[PF_SK_WIRE].addr[io];;
+ pb = s2->key[PF_SK_WIRE].port[io];
+ }
+
+
+ if (ntohs(pa) > ntohs(pb))
+ return sortdir;
+ if (ntohs(pa) < ntohs(pb))
+ return - sortdir;
+
+ ret = compare_addr(af, aa, ab);
+ if (ret)
+ return ret * sortdir;
+ return -sortdir;
+}
+
+#else /* HAVE_PFSYNC_KEY */
+
#ifdef __GNUC__
__inline__
#endif
@@ -573,20 +712,6 @@
return -sortdir;
}
-int sort_sa_callback(const void *p1, const void *p2)
-{
- pf_state_t *s1 = state_buf + (* (u_int32_t *) p1);
- pf_state_t *s2 = state_buf + (* (u_int32_t *) p2);
- return sort_addr_callback(s1, s2, PF_OUT);
-}
-
-int sort_da_callback(const void *p1, const void *p2)
-{
- pf_state_t *s1 = state_buf + (* (u_int32_t *) p1);
- pf_state_t *s2 = state_buf + (* (u_int32_t *) p2);
- return sort_addr_callback(s1, s2, PF_IN);
-}
-
#ifdef __GNUC__
__inline__
#endif
@@ -625,6 +750,21 @@
return sortdir;
return -sortdir;
}
+#endif /* HAVE_PFSYNC_KEY */
+
+int sort_sa_callback(const void *p1, const void *p2)
+{
+ pf_state_t *s1 = state_buf + (* (u_int32_t *) p1);
+ pf_state_t *s2 = state_buf + (* (u_int32_t *) p2);
+ return sort_addr_callback(s1, s2, PF_OUT);
+}
+
+int sort_da_callback(const void *p1, const void *p2)
+{
+ pf_state_t *s1 = state_buf + (* (u_int32_t *) p1);
+ pf_state_t *s2 = state_buf + (* (u_int32_t *) p2);
+ return sort_addr_callback(s1, s2, PF_IN);
+}
int
sort_sp_callback(const void *p1, const void *p2)
@@ -736,7 +876,7 @@
} else {
num_states = 0;
for (n = 0; n<num_states_all; n++)
- if (bpf_filter(filter_prog.bf_insns, (char *)(&state_buf[n]),
+ if (bpf_filter(filter_prog.bf_insns, (u_char *)(&state_buf[n]),
sizeof(pf_state_t), sizeof(pf_state_t)) > 0)
state_ord[num_states++] = n;
}
@@ -828,7 +968,7 @@
tbprintf(" PAUSED");
if (rawmode)
- printf("\n\n%s\n", tmp_buf);
+ printf("\n%s", tmp_buf);
else
mvprintw(0, 0, "%s", tmp_buf);
@@ -843,7 +983,10 @@
len = columns - strlen(tmp_buf);
if (len < 0)
len = 0;
- mvprintw(0, len, "%s", tmp_buf);
+ if (rawmode)
+ printf(" %s\n", tmp_buf);
+ else
+ mvprintw(0, len, "%s", tmp_buf);
}
tb_end();
@@ -865,7 +1008,48 @@
tbprintf("/%u", unmask(mask, af));
}
}
+#ifdef HAVE_PFSYNC_KEY
+void
+print_fld_host2(field_def *fld, struct pfsync_state_key *ks,
+ struct pfsync_state_key *kn, int idx, int af)
+{
+ struct pf_addr *as = &ks->addr[idx];
+ struct pf_addr *an = &kn->addr[idx];
+
+ u_int16_t ps = ntohs(ks->port[idx]);
+ u_int16_t pn = ntohs(kn->port[idx]);
+
+ if (fld == NULL)
+ return;
+
+ if (fld->width < 3) {
+ print_fld_str(fld, "*");
+ return;
+ }
+
+ tb_start();
+ tb_print_addr(as, NULL, af);
+
+ if (af == AF_INET)
+ tbprintf(":%u", ps);
+ else
+ tbprintf("[%u]", ps);
+
+ print_fld_tb(fld);
+
+ if (PF_ANEQ(as, an, af) || ps != pn) {
+ tb_start();
+ tb_print_addr(an, NULL, af);
+ if (af == AF_INET)
+ tbprintf(":%u", pn);
+ else
+ tbprintf("[%u]", pn);
+ print_fld_tb(FLD_GW);
+ }
+
+}
+#else
void
print_fld_host(field_def *fld, pf_state_host_t * h, int af)
{
@@ -889,6 +1073,7 @@
print_fld_tb(fld);
}
+#endif
void
print_fld_state(field_def *fld, unsigned int proto,
@@ -960,6 +1145,19 @@
else
print_fld_uint(FLD_PROTO, s->proto);
+#ifdef HAVE_PFSYNC_KEY
+ if (s->direction == PF_OUT) {
+ print_fld_host2(FLD_SRC, &s->key[PF_SK_WIRE],
+ &s->key[PF_SK_STACK], 1, s->af);
+ print_fld_host2(FLD_DEST, &s->key[PF_SK_WIRE],
+ &s->key[PF_SK_STACK], 0, s->af);
+ } else {
+ print_fld_host2(FLD_SRC, &s->key[PF_SK_STACK],
+ &s->key[PF_SK_WIRE], 0, s->af);
+ print_fld_host2(FLD_DEST, &s->key[PF_SK_STACK],
+ &s->key[PF_SK_WIRE], 1, s->af);
+ }
+#else
if (s->direction == PF_OUT) {
print_fld_host(FLD_SRC, &s->lan, s->af);
print_fld_host(FLD_DEST, &s->ext, s->af);
@@ -972,6 +1170,7 @@
(s->lan.port != s->gwy.port)) {
print_fld_host(FLD_GW, &s->gwy, s->af);
}
+#endif
if (s->direction == PF_OUT)
print_fld_str(FLD_DIR, "Out");
@@ -979,8 +1178,8 @@
print_fld_str(FLD_DIR, "In");
print_fld_state(FLD_STATE, s->proto, src->state, dst->state);
- print_fld_age(FLD_AGE, s->creation);
- print_fld_age(FLD_EXP, s->expire);
+ print_fld_age(FLD_AGE, PF_TSTAMP(s->creation));
+ print_fld_age(FLD_EXP, PF_TSTAMP(s->expire));
#ifdef HAVE_INOUT_COUNT
{
u_int64_t sz = COUNTER(s->bytes[0]) + COUNTER(s->bytes[1]);
@@ -988,14 +1187,14 @@
print_fld_size(FLD_PKTS, COUNTER(s->packets[0]) +
COUNTER(s->packets[1]));
print_fld_size(FLD_BYTES, sz);
- print_fld_rate(FLD_SA, (s->creation > 0) ?
- ((double)sz/(double)s->creation) : -1);
+ print_fld_rate(FLD_SA, (s->creation) ?
+ ((double)sz/PF_TSTAMP((double)s->creation)) : -1);
}
#else
print_fld_size(FLD_PKTS, s->packets);
print_fld_size(FLD_BYTES, s->bytes);
- print_fld_rate(FLD_SA, (s->creation > 0) ?
- ((double)s->bytes/(double)s->creation) : -1);
+ print_fld_rate(FLD_SA, (s->creation) ?
+ ((double)s->bytes/PF_TSTAMP((double)s->creation)) : -1);
#endif
#ifdef HAVE_PFSYNC_STATE
@@ -1244,7 +1443,6 @@
FLD_ANCHOR->max_width = mx;
FLD_ANCHOR->norm_width = nx;
field_setup();
- need_update = 1;
}
}
#endif
@@ -1279,7 +1477,6 @@
FLD_LABEL->norm_width = nw;
FLD_LABEL->max_width = mw;
field_setup();
- need_update = 1;
}
}
#endif
@@ -1458,8 +1655,9 @@
void
print_rule(struct pf_rule *pr)
{
- static const char *actiontypes[] = { "Pass", "Block", "Scrub", "Nat",
- "no Nat", "Binat", "no Binat", "Rdr", "no Rdr" };
+ static const char *actiontypes[] = { "Pass", "Block", "Scrub",
+ "no Scrub", "Nat", "no Nat", "Binat", "no Binat", "Rdr",
+ "no Rdr", "SynProxy Block", "Defer", "Match" };
int numact = sizeof(actiontypes) / sizeof(char *);
#ifdef HAVE_PF_ROUTE
@@ -1475,8 +1673,12 @@
print_fld_str(FLD_LABEL, pr->label);
#endif
#ifdef HAVE_RULE_STATES
+#ifdef HAVE_PFSYNC_KEY
+ print_fld_size(FLD_STATS, pr->states_tot);
+#else
print_fld_size(FLD_STATS, pr->states);
#endif
+#endif
#ifdef HAVE_INOUT_COUNT_RULES
print_fld_size(FLD_PKTS, pr->packets[0] + pr->packets[1]);
@@ -1486,7 +1688,13 @@
print_fld_size(FLD_BYTES, pr->bytes);
#endif
print_fld_uint(FLD_RULE, pr->nr);
- print_fld_str(FLD_DIR, pr->direction == PF_OUT ? "Out" : "In");
+ if (pr->direction == PF_OUT)
+ print_fld_str(FLD_DIR, "Out");
+ else if (pr->direction == PF_IN)
+ print_fld_str(FLD_DIR, "In");
+ else
+ print_fld_str(FLD_DIR, "Any");
+
if (pr->quick)
print_fld_str(FLD_QUICK, "Quick");
@@ -1729,12 +1937,19 @@
prev->next = node;
}
}
- if (*root != node) {
- struct pf_altq_node *prev_flat = *root;
- while (prev_flat->next_flat != NULL) {
- prev_flat = prev_flat->next_flat;
- }
- prev_flat->next_flat = node;
+}
+
+void
+pfctl_set_next_flat(struct pf_altq_node *node, struct pf_altq_node *up)
+{
+ while (node) {
+ struct pf_altq_node *next = node->next ? node->next : up;
+ if (node->children) {
+ node->next_flat = node->children;
+ pfctl_set_next_flat(node->children, next);
+ } else
+ node->next_flat = next;
+ node = node->next;
}
}
@@ -1747,6 +1962,7 @@
u_int32_t nr;
struct queue_stats qstats;
u_int32_t nr_queues;
+ int ret = 0;
*inserts = 0;
memset(&pa, 0, sizeof(pa));
@@ -1757,13 +1973,15 @@
strerror(errno));
return (-1);
}
+
num_queues = nr_queues = pa.nr;
for (nr = 0; nr < nr_queues; ++nr) {
pa.nr = nr;
if (ioctl(pf_dev, DIOCGETALTQ, &pa)) {
msgprintf("Error Reading Queue (DIOCGETALTQ): %s",
strerror(errno));
- return (-1);
+ ret = -1;
+ break;
}
if (pa.altq.qid > 0) {
pq.nr = nr;
@@ -1773,7 +1991,8 @@
if (ioctl(pf_dev, DIOCGETQSTATS, &pq)) {
msgprintf("Error Reading Queue (DIOCGETQSTATS): %s",
strerror(errno));
- return (-1);
+ ret = -1;
+ break;
}
qstats.valid = 1;
gettimeofday(&qstats.timestamp, NULL);
@@ -1794,7 +2013,10 @@
else
--num_queues;
}
- return (0);
+
+ pfctl_set_next_flat(*root, NULL);
+
+ return (ret);
}
void
@@ -1924,6 +2146,10 @@
node->altq.scheduler == ALTQT_HFSC
)
print_fld_bw(FLD_BANDW, (double)node->altq.bandwidth);
+#ifdef ALTQT_FAIRQ
+ if (node->altq.scheduler == ALTQT_FAIRQ)
+ print_fld_bw(FLD_BANDW, (double)node->altq.bandwidth);
+#endif
if (node->altq.priority != DEFAULT_PRIORITY)
print_fld_uint(FLD_PRIO,
@@ -1992,6 +2218,26 @@
node->qstats_last.data.hfsc_stats.xmit_cnt.bytes, interval);
}
break;
+#ifdef ALTQT_FAIRQ
+ case ALTQT_FAIRQ:
+ print_fld_str(FLD_SCHED, "fairq");
+ print_fld_size(FLD_PKTS,
+ node->qstats.data.fairq_stats.xmit_cnt.packets);
+ print_fld_size(FLD_BYTES,
+ node->qstats.data.fairq_stats.xmit_cnt.bytes);
+ print_fld_size(FLD_DROPP,
+ node->qstats.data.fairq_stats.drop_cnt.packets);
+ print_fld_size(FLD_DROPB,
+ node->qstats.data.fairq_stats.drop_cnt.bytes);
+ print_fld_size(FLD_QLEN, node->qstats.data.fairq_stats.qlength);
+ if (interval > 0) {
+ pps = calc_pps(node->qstats.data.fairq_stats.xmit_cnt.packets,
+ node->qstats_last.data.fairq_stats.xmit_cnt.packets, interval);
+ bps = calc_rate(node->qstats.data.fairq_stats.xmit_cnt.bytes,
+ node->qstats_last.data.fairq_stats.xmit_cnt.bytes, interval);
+ }
+ break;
+#endif
}
/* if (node->altq.scheduler != ALTQT_HFSC && interval > 0) { */
@@ -2041,11 +2287,9 @@
if (cachestates) {
show_field(FLD_SI);
show_field(FLD_SP);
- gotsig_alarm = 1;
} else {
hide_field(FLD_SI);
hide_field(FLD_SP);
- need_update = 1;
}
field_setup();
}
@@ -2105,8 +2349,10 @@
line++;
mvprintw(line++, 6, "press any key to continue ...");
- while (getch() == ERR);
-
+ timeout(-1);
+ while (getch() == ERR)
+ continue;
+ timeout(0);
}
@@ -2142,7 +2388,6 @@
del = atoi(cmdbuf);
if (del > 0) {
delay = del;
- gotsig_alarm = 1;
}
}
@@ -2175,7 +2420,6 @@
/* FALLTHROUGH */
case 'h':
show_help();
- need_update = 1;
break;
case 'n':
command_set(&cm_count, NULL);
@@ -2349,8 +2593,6 @@
if (rawmode && countmax == 0)
countmax = 1;
- gotsig_alarm = 1;
-
engine_loop(countmax);
close(pf_dev);

View File

@@ -0,0 +1,435 @@
$NetBSD: patch-ah,v 1.3 2011/02/09 22:51:38 rumko Exp $
$OpenBSD: patch-sf-gencode_c,v 1.1 2008/06/13 00:38:12 canacar Exp $
* DragonFly compatibility
* Patches to support PF > 4.1 taken from OpenBSD's ports.
--- sf-gencode.c.orig 2007-11-07 07:34:18 +0100
+++ sf-gencode.c 2010-09-16 01:35:22 +0200
@@ -32,8 +32,12 @@
#include <netinet/in.h>
#include <netinet/if_ether.h>
-#include <net/if_pflog.h>
+#ifdef __DragonFly__
+#include <sys/param.h>
+#include <net/pf/pfvar.h>
+#else
#include <net/pfvar.h>
+#endif /* !__DragonFly__ */
#include <netdb.h>
#include <stdlib.h>
@@ -44,7 +48,7 @@
#define INET6
-#include <pcap-int.h>
+#include "pcap-int.h"
#include <pcap-namedb.h>
#include "sf-gencode.h"
@@ -60,7 +64,11 @@
static char sf_errbuf[PFTOP_ERRBUF_SIZE];
/* VARARGS */
+#ifdef __DragonFly__
+void
+#else
__dead void
+#endif
sf_error(const char *fmt, ...)
{
va_list ap;
@@ -474,6 +482,106 @@
(bpf_int32)proto));
}
+#ifdef HAVE_PFSYNC_KEY
+static struct block *
+gen_hostop(bpf_u_int32 addr, bpf_u_int32 mask, int dir)
+{
+ struct block *b0, *b1, *b2, *bi, *bo;
+ const static int isrc_off = offsetof(pf_state_t, key[PF_SK_STACK].addr[0].v4);
+ const static int osrc_off = offsetof(pf_state_t, key[PF_SK_WIRE].addr[1].v4);
+ const static int idst_off = offsetof(pf_state_t, key[PF_SK_STACK].addr[1].v4);
+ const static int odst_off = offsetof(pf_state_t, key[PF_SK_WIRE].addr[0].v4);
+
+ const static int igwy1_off = offsetof(pf_state_t, key[PF_SK_WIRE].addr[0].v4);
+ const static int ogwy1_off = offsetof(pf_state_t, key[PF_SK_STACK].addr[1].v4);
+ const static int igwy2_off = offsetof(pf_state_t, key[PF_SK_WIRE].addr[1].v4);
+ const static int ogwy2_off = offsetof(pf_state_t, key[PF_SK_STACK].addr[0].v4);
+
+#if !defined(__DragonFly__)
+ addr = ntohl(addr);
+ mask = ntohl(mask);
+#endif
+
+ bi = gen_cmp(offsetof(pf_state_t, direction), BPF_B, (bpf_int32)PF_IN);
+ bo = gen_cmp(offsetof(pf_state_t, direction), BPF_B, (bpf_int32)PF_OUT);
+
+ switch (dir) {
+
+ case Q_SRC:
+ b1 = gen_mcmp(osrc_off, BPF_W, addr, mask);
+ gen_and(bo, b1);
+ b0 = gen_mcmp(isrc_off, BPF_W, addr, mask);
+ gen_and(bi, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_DST:
+ b1 = gen_mcmp(odst_off, BPF_W, addr, mask);
+ gen_and(bo, b1);
+ b0 = gen_mcmp(idst_off, BPF_W, addr, mask);
+ gen_and(bi, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_GATEWAY:
+ /* (in && (addr == igwy1 || addr == igwy2)) ||
+ (out && (addr == ogwy1 || addr == ogwy2)) phew! */
+ b1 = gen_mcmp(igwy1_off, BPF_W, addr, mask);
+ b0 = gen_mcmp(igwy2_off, BPF_W, addr, mask);
+ gen_or(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_mcmp(ogwy1_off, BPF_W, addr, mask);
+ b0 = gen_mcmp(ogwy2_off, BPF_W, addr, mask);
+ gen_or(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_AND:
+ b1 = gen_mcmp(isrc_off, BPF_W, addr, mask);
+ b0 = gen_mcmp(idst_off, BPF_W, addr, mask);
+ gen_and(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_mcmp(osrc_off, BPF_W, addr, mask);
+ b0 = gen_mcmp(odst_off, BPF_W, addr, mask);
+ gen_and(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_OR:
+ b1 = gen_mcmp(isrc_off, BPF_W, addr, mask);
+ b0 = gen_mcmp(idst_off, BPF_W, addr, mask);
+ gen_or(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_mcmp(osrc_off, BPF_W, addr, mask);
+ b0 = gen_mcmp(odst_off, BPF_W, addr, mask);
+ gen_or(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_DEFAULT:
+ b1 = gen_mcmp(isrc_off, BPF_W, addr, mask);
+ b0 = gen_mcmp(idst_off, BPF_W, addr, mask);
+ gen_or(b0, b1);
+ b0 = gen_mcmp(osrc_off, BPF_W, addr, mask);
+ gen_or(b0, b1);
+ b0 = gen_mcmp(odst_off, BPF_W, addr, mask);
+ gen_or(b0, b1);
+ break;
+
+ default:
+ sf_error("Internal error: Invalid direcion specifier: %d", dir);
+ }
+
+ b0 = gen_linktype(ETHERTYPE_IP);
+ gen_and(b0, b1);
+
+ return b1;
+}
+
+#else
static struct block *
gen_hostop(bpf_u_int32 addr, bpf_u_int32 mask, int dir)
{
@@ -482,8 +590,10 @@
const static int gwy_off = offsetof(pf_state_t, gwy.addr.v4);
const static int ext_off = offsetof(pf_state_t, ext.addr.v4);
+#if !defined(__DragonFly__)
addr = ntohl(addr);
mask = ntohl(mask);
+#endif
switch (dir) {
@@ -542,6 +652,7 @@
return b1;
}
+#endif
static struct block *
gen_hostcmp6(u_int off, u_int32_t *a, u_int32_t *m)
@@ -560,6 +671,105 @@
return b1;
}
+#ifdef HAVE_PFSYNC_KEY
+static struct block *
+gen_hostop6(struct in6_addr *addr, struct in6_addr *mask, int dir)
+
+{
+ struct block *b0, *b1, *b2, *bi, *bo;
+ u_int32_t *a, *m;
+ const static int isrc_off = offsetof(pf_state_t, key[PF_SK_STACK].addr[0].v6);
+ const static int osrc_off = offsetof(pf_state_t, key[PF_SK_WIRE].addr[1].v6);
+ const static int idst_off = offsetof(pf_state_t, key[PF_SK_STACK].addr[1].v6);
+ const static int odst_off = offsetof(pf_state_t, key[PF_SK_WIRE].addr[0].v6);
+
+ const static int igwy1_off = offsetof(pf_state_t, key[PF_SK_WIRE].addr[0].v6);
+ const static int ogwy1_off = offsetof(pf_state_t, key[PF_SK_STACK].addr[1].v6);
+ const static int igwy2_off = offsetof(pf_state_t, key[PF_SK_WIRE].addr[1].v6);
+ const static int ogwy2_off = offsetof(pf_state_t, key[PF_SK_STACK].addr[0].v6);
+
+ a = (u_int32_t *)addr;
+ m = (u_int32_t *)mask;
+
+ bi = gen_cmp(offsetof(pf_state_t, direction), BPF_B, (bpf_int32)PF_IN);
+ bo = gen_cmp(offsetof(pf_state_t, direction), BPF_B, (bpf_int32)PF_OUT);
+
+ switch (dir) {
+
+ case Q_SRC:
+ b1 = gen_hostcmp6(osrc_off, a, m);
+ gen_and(bo, b1);
+ b0 = gen_hostcmp6(isrc_off, a, m);
+ gen_and(bi, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_DST:
+ b1 = gen_hostcmp6(odst_off, a, m);
+ gen_and(bo, b1);
+ b0 = gen_hostcmp6(idst_off, a, m);
+ gen_and(bi, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_GATEWAY:
+ /* (in && (addr == igwy1 || addr == igwy2)) ||
+ (out && (addr == ogwy1 || addr == ogwy2)) phew! */
+ b1 = gen_hostcmp6(igwy1_off, a, m);
+ b0 = gen_hostcmp6(igwy2_off, a, m);
+ gen_or(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_hostcmp6(ogwy1_off, a, m);
+ b0 = gen_hostcmp6(ogwy2_off, a, m);
+ gen_or(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_AND:
+ b1 = gen_hostcmp6(isrc_off, a, m);
+ b0 = gen_hostcmp6(idst_off, a, m);
+ gen_and(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_hostcmp6(osrc_off, a, m);
+ b0 = gen_hostcmp6(odst_off, a, m);
+ gen_and(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_OR:
+ b1 = gen_hostcmp6(isrc_off, a, m);
+ b0 = gen_hostcmp6(idst_off, a, m);
+ gen_or(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_hostcmp6(osrc_off, a, m);
+ b0 = gen_hostcmp6(odst_off, a, m);
+ gen_or(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_DEFAULT:
+ b1 = gen_hostcmp6(isrc_off, a, m);
+ b0 = gen_hostcmp6(idst_off, a, m);
+ gen_or(b0, b1);
+ b0 = gen_hostcmp6(osrc_off, a, m);
+ gen_or(b0, b1);
+ b0 = gen_hostcmp6(odst_off, a, m);
+ gen_or(b0, b1);
+ break;
+
+ default:
+ sf_error("Internal error: Invalid direcion specifier: %d", dir);
+ }
+
+ b0 = gen_linktype(ETHERTYPE_IPV6);
+ gen_and(b0, b1);
+
+ return b1;
+}
+#else
static struct block *
gen_hostop6(struct in6_addr *addr, struct in6_addr *mask, int dir)
{
@@ -630,6 +840,7 @@
gen_and(b0, b1);
return b1;
}
+#endif
static const char *
get_modifier_by_id(int id)
@@ -733,13 +944,17 @@
b1 = gen_proto(IPPROTO_ESP);
break;
+#ifdef IPPROTO_PFSYNC
case Q_PFSYNC:
b1 = gen_proto(IPPROTO_PFSYNC);
break;
+#endif /* IPPROTO_PFSYNC */
+#ifdef IPPROTO_CARP
case Q_CARP:
b1 = gen_proto(IPPROTO_CARP);
break;
+#endif /* IPPROTO_CARP */
default:
sf_error("Unknown protocol abbreviation");
@@ -748,6 +963,106 @@
return b1;
}
+#ifdef HAVE_PFSYNC_KEY
+struct block *
+gen_portop(int port, int proto, int dir)
+{
+ struct block *b0, *b1, *b2, *bi, *bo;
+ const static int isrc_off = offsetof(pf_state_t, key[PF_SK_STACK].port[0]);
+ const static int osrc_off = offsetof(pf_state_t, key[PF_SK_WIRE].port[1]);
+ const static int idst_off = offsetof(pf_state_t, key[PF_SK_STACK].port[1]);
+ const static int odst_off = offsetof(pf_state_t, key[PF_SK_WIRE].port[0]);
+
+ const static int igwy1_off = offsetof(pf_state_t, key[PF_SK_WIRE].port[0]);
+ const static int ogwy1_off = offsetof(pf_state_t, key[PF_SK_STACK].port[1]);
+ const static int igwy2_off = offsetof(pf_state_t, key[PF_SK_WIRE].port[1]);
+ const static int ogwy2_off = offsetof(pf_state_t, key[PF_SK_STACK].port[0]);
+
+#if !defined(__DragonFly__)
+ port = ntohs(port);
+#endif
+
+ bi = gen_cmp(offsetof(pf_state_t, direction), BPF_B, (bpf_int32)PF_IN);
+ bo = gen_cmp(offsetof(pf_state_t, direction), BPF_B, (bpf_int32)PF_OUT);
+
+ switch (dir) {
+
+ case Q_SRC:
+ b1 = gen_cmp(osrc_off, BPF_H, (bpf_int32)port);
+ gen_and(bo, b1);
+ b0 = gen_cmp(isrc_off, BPF_H, (bpf_int32)port);
+ gen_and(bi, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_DST:
+ b1 = gen_cmp(odst_off, BPF_H, (bpf_int32)port);
+ gen_and(bo, b1);
+ b0 = gen_cmp(idst_off, BPF_H, (bpf_int32)port);
+ gen_and(bi, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_GATEWAY:
+ /* (in && (addr == igwy1 || addr == igwy2)) ||
+ (out && (addr == ogwy1 || addr == ogwy2)) phew! */
+ b1 = gen_cmp(igwy1_off, BPF_H, (bpf_int32)port);
+ b0 = gen_cmp(igwy2_off, BPF_H, (bpf_int32)port);
+ gen_or(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_cmp(ogwy1_off, BPF_H, (bpf_int32)port);
+ b0 = gen_cmp(ogwy2_off, BPF_H, (bpf_int32)port);
+ gen_or(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_AND:
+ b1 = gen_cmp(isrc_off, BPF_H, (bpf_int32)port);
+ b0 = gen_cmp(idst_off, BPF_H, (bpf_int32)port);
+ gen_and(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_cmp(osrc_off, BPF_H, (bpf_int32)port);
+ b0 = gen_cmp(odst_off, BPF_H, (bpf_int32)port);
+ gen_and(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_OR:
+ b1 = gen_cmp(isrc_off, BPF_H, (bpf_int32)port);
+ b0 = gen_cmp(idst_off, BPF_H, (bpf_int32)port);
+ gen_or(b0, b1);
+ gen_and(bi, b1);
+ b2 = gen_cmp(osrc_off, BPF_H, (bpf_int32)port);
+ b0 = gen_cmp(odst_off, BPF_H, (bpf_int32)port);
+ gen_or(b2, b0);
+ gen_and(bo, b0);
+ gen_or(b0, b1);
+ break;
+
+ case Q_DEFAULT:
+ b1 = gen_cmp(isrc_off, BPF_H, (bpf_int32)port);
+ b0 = gen_cmp(idst_off, BPF_H, (bpf_int32)port);
+ gen_or(b0, b1);
+ b0 = gen_cmp(osrc_off, BPF_H, (bpf_int32)port);
+ gen_or(b0, b1);
+ b0 = gen_cmp(odst_off, BPF_H, (bpf_int32)port);
+ gen_or(b0, b1);
+ break;
+
+ default:
+ sf_error("Internal error: Invalid direcion specifier: %d", dir);
+ }
+
+
+
+ b0 = gen_proto(proto);
+ gen_and(b0, b1);
+
+ return b1;
+}
+#else
struct block *
gen_portop(int port, int proto, int dir)
{
@@ -756,7 +1071,9 @@
const static int gwy_off = offsetof(pf_state_t, gwy.port);
const static int ext_off = offsetof(pf_state_t, ext.port);
+#if !defined(__DragonFly__)
port = ntohs(port);
+#endif
switch (dir) {
@@ -815,6 +1132,7 @@
return b1;
}
+#endif
static struct block *
gen_port(int port, int ip_proto, int dir)
@@ -1560,7 +1878,7 @@
/* NOTREACHED */
}
- b0 = gen_bcmp(off, strlen(ifname), ifname);
+ b0 = gen_bcmp(off, strlen(ifname), (const u_char *)ifname);
return (b0);
#else
sf_error("ifname not supported in this OpenBSD release");

View File

@@ -0,0 +1,33 @@
$NetBSD: patch-ai,v 1.1 2008/06/15 14:09:04 peter Exp $
--- sf-scanner.l.old 2008-06-14 18:04:30.000000000 +0200
+++ sf-scanner.l 2008-06-14 18:19:59.000000000 +0200
@@ -222,7 +222,8 @@
if (getaddrinfo(yytext, NULL, &hints, &res))
sf_error("bogus IPv6 address %s", yytext);
else {
- yylval.e = sdup((char *)yytext); return HID6;
+ yylval.e = (u_char *)sdup((char *)yytext);
+ return HID6;
}
}
[A-Za-z0-9][-_.A-Za-z0-9]*[.A-Za-z0-9] {
@@ -232,8 +233,17 @@
[^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+ {
size_t len = strlen(yytext) * 4 + 1;
char *v = malloc(len);
- if (v != NULL)
+ if (v != NULL) {
+#ifdef __NetBSD__
+ size_t len = strlen(yytext);
+ if (len > sizeof v) {
+ len = sizeof v;
+ }
+ strvisx(v, yytext, len, 0);
+#else
strnvis(v, yytext, len, 0);
+#endif /* !__NetBSD__ */
+ }
sf_error("illegal token: %s", v);
free(v);
}

View File

@@ -0,0 +1,34 @@
$NetBSD: patch-aj,v 1.2 2011/06/10 11:45:01 obache Exp $
--- sf-gencode.h.orig 2007-11-07 06:34:18.000000000 +0000
+++ sf-gencode.h
@@ -169,8 +169,13 @@ struct arth *gen_loadage(void);
struct arth *gen_loadexpire(void);
void bpf_optimize(struct block **);
+#ifdef __DragonFly__
+void bpf_error(const char *, ...)
+ __attribute__((volatile, __format__ (printf, 1, 2)));
+#else
__dead void bpf_error(const char *, ...)
__attribute__((volatile, __format__ (printf, 1, 2)));
+#endif
void finish_parse(struct block *);
char *sdup(const char *);
@@ -184,11 +189,14 @@ void sappend(struct slist *, struct slis
#define JT(b) ((b)->et.succ)
#define JF(b) ((b)->ef.succ)
+#ifdef __DragonFly__
+void sf_error(const char *fmt, ...);
+#else
__dead void sf_error(const char *fmt, ...);
+#endif
const char *sf_get_error(void);
int sf_compile(struct bpf_program *, char *, int, bpf_u_int32);
void sf_freecode(struct bpf_program *);
-void bpf_dump(struct bpf_program *, int);
extern int no_optimize;

View File

@@ -0,0 +1,534 @@
$NetBSD: patch-ak,v 1.1 2010/09/18 20:48:24 wiz Exp $
Taken from FreeBSD ports.
--- /dev/null 2009-11-17 00:30:11 +0100
+++ queue.h 2009-11-17 00:31:32 +0100
@@ -0,0 +1,527 @@
+/* $OpenBSD: queue.h,v 1.32 2007/04/30 18:42:34 pedro Exp $ */
+/* NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp */
+
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#)queue.h 8.5 (Berkeley) 8/20/94
+ */
+
+#ifndef _QUEUE_H_
+#define _QUEUE_H_
+
+/*
+ * This file defines five types of data structures: singly-linked lists,
+ * lists, simple queues, tail queues, and circular queues.
+ *
+ *
+ * A singly-linked list is headed by a single forward pointer. The elements
+ * are singly linked for minimum space and pointer manipulation overhead at
+ * the expense of O(n) removal for arbitrary elements. New elements can be
+ * added to the list after an existing element or at the head of the list.
+ * Elements being removed from the head of the list should use the explicit
+ * macro for this purpose for optimum efficiency. A singly-linked list may
+ * only be traversed in the forward direction. Singly-linked lists are ideal
+ * for applications with large datasets and few or no removals or for
+ * implementing a LIFO queue.
+ *
+ * A list is headed by a single forward pointer (or an array of forward
+ * pointers for a hash table header). The elements are doubly linked
+ * so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before
+ * or after an existing element or at the head of the list. A list
+ * may only be traversed in the forward direction.
+ *
+ * A simple queue is headed by a pair of pointers, one the head of the
+ * list and the other to the tail of the list. The elements are singly
+ * linked to save space, so elements can only be removed from the
+ * head of the list. New elements can be added to the list before or after
+ * an existing element, at the head of the list, or at the end of the
+ * list. A simple queue may only be traversed in the forward direction.
+ *
+ * A tail queue is headed by a pair of pointers, one to the head of the
+ * list and the other to the tail of the list. The elements are doubly
+ * linked so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before or
+ * after an existing element, at the head of the list, or at the end of
+ * the list. A tail queue may be traversed in either direction.
+ *
+ * A circle queue is headed by a pair of pointers, one to the head of the
+ * list and the other to the tail of the list. The elements are doubly
+ * linked so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before or after
+ * an existing element, at the head of the list, or at the end of the list.
+ * A circle queue may be traversed in either direction, but has a more
+ * complex end of list detection.
+ *
+ * For details on the use of these macros, see the queue(3) manual page.
+ */
+
+#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
+#define _Q_INVALIDATE(a) (a) = ((void *)-1)
+#else
+#define _Q_INVALIDATE(a)
+#endif
+
+/*
+ * Singly-linked List definitions.
+ */
+#define SLIST_HEAD(name, type) \
+struct name { \
+ struct type *slh_first; /* first element */ \
+}
+
+#define SLIST_HEAD_INITIALIZER(head) \
+ { NULL }
+
+#define SLIST_ENTRY(type) \
+struct { \
+ struct type *sle_next; /* next element */ \
+}
+
+/*
+ * Singly-linked List access methods.
+ */
+#define SLIST_FIRST(head) ((head)->slh_first)
+#define SLIST_END(head) NULL
+#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
+#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
+
+#define SLIST_FOREACH(var, head, field) \
+ for((var) = SLIST_FIRST(head); \
+ (var) != SLIST_END(head); \
+ (var) = SLIST_NEXT(var, field))
+
+#define SLIST_FOREACH_PREVPTR(var, varp, head, field) \
+ for ((varp) = &SLIST_FIRST((head)); \
+ ((var) = *(varp)) != SLIST_END(head); \
+ (varp) = &SLIST_NEXT((var), field))
+
+/*
+ * Singly-linked List functions.
+ */
+#define SLIST_INIT(head) { \
+ SLIST_FIRST(head) = SLIST_END(head); \
+}
+
+#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
+ (elm)->field.sle_next = (slistelm)->field.sle_next; \
+ (slistelm)->field.sle_next = (elm); \
+} while (0)
+
+#define SLIST_INSERT_HEAD(head, elm, field) do { \
+ (elm)->field.sle_next = (head)->slh_first; \
+ (head)->slh_first = (elm); \
+} while (0)
+
+#define SLIST_REMOVE_NEXT(head, elm, field) do { \
+ (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
+} while (0)
+
+#define SLIST_REMOVE_HEAD(head, field) do { \
+ (head)->slh_first = (head)->slh_first->field.sle_next; \
+} while (0)
+
+#define SLIST_REMOVE(head, elm, type, field) do { \
+ if ((head)->slh_first == (elm)) { \
+ SLIST_REMOVE_HEAD((head), field); \
+ } else { \
+ struct type *curelm = (head)->slh_first; \
+ \
+ while (curelm->field.sle_next != (elm)) \
+ curelm = curelm->field.sle_next; \
+ curelm->field.sle_next = \
+ curelm->field.sle_next->field.sle_next; \
+ _Q_INVALIDATE((elm)->field.sle_next); \
+ } \
+} while (0)
+
+/*
+ * List definitions.
+ */
+#define LIST_HEAD(name, type) \
+struct name { \
+ struct type *lh_first; /* first element */ \
+}
+
+#define LIST_HEAD_INITIALIZER(head) \
+ { NULL }
+
+#define LIST_ENTRY(type) \
+struct { \
+ struct type *le_next; /* next element */ \
+ struct type **le_prev; /* address of previous next element */ \
+}
+
+/*
+ * List access methods
+ */
+#define LIST_FIRST(head) ((head)->lh_first)
+#define LIST_END(head) NULL
+#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
+#define LIST_NEXT(elm, field) ((elm)->field.le_next)
+
+#define LIST_FOREACH(var, head, field) \
+ for((var) = LIST_FIRST(head); \
+ (var)!= LIST_END(head); \
+ (var) = LIST_NEXT(var, field))
+
+/*
+ * List functions.
+ */
+#define LIST_INIT(head) do { \
+ LIST_FIRST(head) = LIST_END(head); \
+} while (0)
+
+#define LIST_INSERT_AFTER(listelm, elm, field) do { \
+ if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
+ (listelm)->field.le_next->field.le_prev = \
+ &(elm)->field.le_next; \
+ (listelm)->field.le_next = (elm); \
+ (elm)->field.le_prev = &(listelm)->field.le_next; \
+} while (0)
+
+#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.le_prev = (listelm)->field.le_prev; \
+ (elm)->field.le_next = (listelm); \
+ *(listelm)->field.le_prev = (elm); \
+ (listelm)->field.le_prev = &(elm)->field.le_next; \
+} while (0)
+
+#define LIST_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.le_next = (head)->lh_first) != NULL) \
+ (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
+ (head)->lh_first = (elm); \
+ (elm)->field.le_prev = &(head)->lh_first; \
+} while (0)
+
+#define LIST_REMOVE(elm, field) do { \
+ if ((elm)->field.le_next != NULL) \
+ (elm)->field.le_next->field.le_prev = \
+ (elm)->field.le_prev; \
+ *(elm)->field.le_prev = (elm)->field.le_next; \
+ _Q_INVALIDATE((elm)->field.le_prev); \
+ _Q_INVALIDATE((elm)->field.le_next); \
+} while (0)
+
+#define LIST_REPLACE(elm, elm2, field) do { \
+ if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
+ (elm2)->field.le_next->field.le_prev = \
+ &(elm2)->field.le_next; \
+ (elm2)->field.le_prev = (elm)->field.le_prev; \
+ *(elm2)->field.le_prev = (elm2); \
+ _Q_INVALIDATE((elm)->field.le_prev); \
+ _Q_INVALIDATE((elm)->field.le_next); \
+} while (0)
+
+/*
+ * Simple queue definitions.
+ */
+#define SIMPLEQ_HEAD(name, type) \
+struct name { \
+ struct type *sqh_first; /* first element */ \
+ struct type **sqh_last; /* addr of last next element */ \
+}
+
+#define SIMPLEQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).sqh_first }
+
+#define SIMPLEQ_ENTRY(type) \
+struct { \
+ struct type *sqe_next; /* next element */ \
+}
+
+/*
+ * Simple queue access methods.
+ */
+#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
+#define SIMPLEQ_END(head) NULL
+#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
+#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
+
+#define SIMPLEQ_FOREACH(var, head, field) \
+ for((var) = SIMPLEQ_FIRST(head); \
+ (var) != SIMPLEQ_END(head); \
+ (var) = SIMPLEQ_NEXT(var, field))
+
+/*
+ * Simple queue functions.
+ */
+#define SIMPLEQ_INIT(head) do { \
+ (head)->sqh_first = NULL; \
+ (head)->sqh_last = &(head)->sqh_first; \
+} while (0)
+
+#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+ (head)->sqh_first = (elm); \
+} while (0)
+
+#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.sqe_next = NULL; \
+ *(head)->sqh_last = (elm); \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+} while (0)
+
+#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+ (listelm)->field.sqe_next = (elm); \
+} while (0)
+
+#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
+ if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
+ (head)->sqh_last = &(head)->sqh_first; \
+} while (0)
+
+/*
+ * Tail queue definitions.
+ */
+#define TAILQ_HEAD(name, type) \
+struct name { \
+ struct type *tqh_first; /* first element */ \
+ struct type **tqh_last; /* addr of last next element */ \
+}
+
+#define TAILQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).tqh_first }
+
+#define TAILQ_ENTRY(type) \
+struct { \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
+}
+
+/*
+ * tail queue access methods
+ */
+#define TAILQ_FIRST(head) ((head)->tqh_first)
+#define TAILQ_END(head) NULL
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+#define TAILQ_LAST(head, headname) \
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))
+/* XXX */
+#define TAILQ_PREV(elm, headname, field) \
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+#define TAILQ_EMPTY(head) \
+ (TAILQ_FIRST(head) == TAILQ_END(head))
+
+#define TAILQ_FOREACH(var, head, field) \
+ for((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_NEXT(var, field))
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
+ for((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_PREV(var, headname, field))
+
+/*
+ * Tail queue functions.
+ */
+#define TAILQ_INIT(head) do { \
+ (head)->tqh_first = NULL; \
+ (head)->tqh_last = &(head)->tqh_first; \
+} while (0)
+
+#define TAILQ_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
+ (head)->tqh_first->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (head)->tqh_first = (elm); \
+ (elm)->field.tqe_prev = &(head)->tqh_first; \
+} while (0)
+
+#define TAILQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.tqe_next = NULL; \
+ (elm)->field.tqe_prev = (head)->tqh_last; \
+ *(head)->tqh_last = (elm); \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
+ (elm)->field.tqe_next->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (listelm)->field.tqe_next = (elm); \
+ (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
+ (elm)->field.tqe_next = (listelm); \
+ *(listelm)->field.tqe_prev = (elm); \
+ (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_REMOVE(head, elm, field) do { \
+ if (((elm)->field.tqe_next) != NULL) \
+ (elm)->field.tqe_next->field.tqe_prev = \
+ (elm)->field.tqe_prev; \
+ else \
+ (head)->tqh_last = (elm)->field.tqe_prev; \
+ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
+ _Q_INVALIDATE((elm)->field.tqe_prev); \
+ _Q_INVALIDATE((elm)->field.tqe_next); \
+} while (0)
+
+#define TAILQ_REPLACE(head, elm, elm2, field) do { \
+ if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
+ (elm2)->field.tqe_next->field.tqe_prev = \
+ &(elm2)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm2)->field.tqe_next; \
+ (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
+ *(elm2)->field.tqe_prev = (elm2); \
+ _Q_INVALIDATE((elm)->field.tqe_prev); \
+ _Q_INVALIDATE((elm)->field.tqe_next); \
+} while (0)
+
+/*
+ * Circular queue definitions.
+ */
+#define CIRCLEQ_HEAD(name, type) \
+struct name { \
+ struct type *cqh_first; /* first element */ \
+ struct type *cqh_last; /* last element */ \
+}
+
+#define CIRCLEQ_HEAD_INITIALIZER(head) \
+ { CIRCLEQ_END(&head), CIRCLEQ_END(&head) }
+
+#define CIRCLEQ_ENTRY(type) \
+struct { \
+ struct type *cqe_next; /* next element */ \
+ struct type *cqe_prev; /* previous element */ \
+}
+
+/*
+ * Circular queue access methods
+ */
+#define CIRCLEQ_FIRST(head) ((head)->cqh_first)
+#define CIRCLEQ_LAST(head) ((head)->cqh_last)
+#define CIRCLEQ_END(head) ((void *)(head))
+#define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next)
+#define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev)
+#define CIRCLEQ_EMPTY(head) \
+ (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head))
+
+#define CIRCLEQ_FOREACH(var, head, field) \
+ for((var) = CIRCLEQ_FIRST(head); \
+ (var) != CIRCLEQ_END(head); \
+ (var) = CIRCLEQ_NEXT(var, field))
+
+#define CIRCLEQ_FOREACH_REVERSE(var, head, field) \
+ for((var) = CIRCLEQ_LAST(head); \
+ (var) != CIRCLEQ_END(head); \
+ (var) = CIRCLEQ_PREV(var, field))
+
+/*
+ * Circular queue functions.
+ */
+#define CIRCLEQ_INIT(head) do { \
+ (head)->cqh_first = CIRCLEQ_END(head); \
+ (head)->cqh_last = CIRCLEQ_END(head); \
+} while (0)
+
+#define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ (elm)->field.cqe_next = (listelm)->field.cqe_next; \
+ (elm)->field.cqe_prev = (listelm); \
+ if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \
+ (head)->cqh_last = (elm); \
+ else \
+ (listelm)->field.cqe_next->field.cqe_prev = (elm); \
+ (listelm)->field.cqe_next = (elm); \
+} while (0)
+
+#define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \
+ (elm)->field.cqe_next = (listelm); \
+ (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \
+ if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \
+ (head)->cqh_first = (elm); \
+ else \
+ (listelm)->field.cqe_prev->field.cqe_next = (elm); \
+ (listelm)->field.cqe_prev = (elm); \
+} while (0)
+
+#define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \
+ (elm)->field.cqe_next = (head)->cqh_first; \
+ (elm)->field.cqe_prev = CIRCLEQ_END(head); \
+ if ((head)->cqh_last == CIRCLEQ_END(head)) \
+ (head)->cqh_last = (elm); \
+ else \
+ (head)->cqh_first->field.cqe_prev = (elm); \
+ (head)->cqh_first = (elm); \
+} while (0)
+
+#define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.cqe_next = CIRCLEQ_END(head); \
+ (elm)->field.cqe_prev = (head)->cqh_last; \
+ if ((head)->cqh_first == CIRCLEQ_END(head)) \
+ (head)->cqh_first = (elm); \
+ else \
+ (head)->cqh_last->field.cqe_next = (elm); \
+ (head)->cqh_last = (elm); \
+} while (0)
+
+#define CIRCLEQ_REMOVE(head, elm, field) do { \
+ if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \
+ (head)->cqh_last = (elm)->field.cqe_prev; \
+ else \
+ (elm)->field.cqe_next->field.cqe_prev = \
+ (elm)->field.cqe_prev; \
+ if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \
+ (head)->cqh_first = (elm)->field.cqe_next; \
+ else \
+ (elm)->field.cqe_prev->field.cqe_next = \
+ (elm)->field.cqe_next; \
+ _Q_INVALIDATE((elm)->field.cqe_prev); \
+ _Q_INVALIDATE((elm)->field.cqe_next); \
+} while (0)
+
+#define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \
+ if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \
+ CIRCLEQ_END(head)) \
+ (head).cqh_last = (elm2); \
+ else \
+ (elm2)->field.cqe_next->field.cqe_prev = (elm2); \
+ if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \
+ CIRCLEQ_END(head)) \
+ (head).cqh_first = (elm2); \
+ else \
+ (elm2)->field.cqe_prev->field.cqe_next = (elm2); \
+ _Q_INVALIDATE((elm)->field.cqe_prev); \
+ _Q_INVALIDATE((elm)->field.cqe_next); \
+} while (0)
+
+#endif /* !_SYS_QUEUE_H_ */

View File

@@ -0,0 +1,28 @@
$NetBSD: patch-al,v 1.1 2011/02/09 22:51:38 rumko Exp $
$OpenBSD: patch-cache_h,v 1.1 2008/06/13 00:38:12 canacar Exp $
Patches to support PF > 4.1 taken from OpenBSD's ports.
--- cache.h.orig Tue Nov 6 23:34:18 2007
+++ cache.h Wed Jun 11 19:50:07 2008
@@ -31,14 +31,20 @@
struct sc_ent {
RB_ENTRY(sc_ent) tlink;
TAILQ_ENTRY(sc_ent) qlink;
+#ifdef HAVE_PFSYNC_STATE
+ u_int32_t id[2];
+#else
struct pf_addr addr[2];
+#endif
double peak;
double rate;
time_t t;
u_int32_t bytes;
+#ifndef HAVE_PFSYNC_STATE
u_int16_t port[2];
u_int8_t af;
u_int8_t proto;
+#endif
};
int cache_init(int);