git: 6ee581673e84 - main - sysutils/pftop: Update to 0.9 (support 15-CURRENT)
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Sat, 04 Nov 2023 14:00:03 UTC
The branch main has been updated by grembo: URL: https://cgit.FreeBSD.org/ports/commit/?id=6ee581673e8495e4cb3afef4aa4f6e5e3aa5a811 commit 6ee581673e8495e4cb3afef4aa4f6e5e3aa5a811 Author: Michael Gmelin <grembo@FreeBSD.org> AuthorDate: 2023-11-04 13:51:23 +0000 Commit: Michael Gmelin <grembo@FreeBSD.org> CommitDate: 2023-11-04 13:51:23 +0000 sysutils/pftop: Update to 0.9 (support 15-CURRENT) All local patches have been upstreamed and upstream has been cleaned up by removing support for outdated versions of FreeBSD. The tool now depends on net/libpfctl, important work contributed by kp@, which means that pftop will now work on 15-CURRENT and its code could be simplified due to having an abstraction for supporting multiple releases of FreeBSD. --- sysutils/pftop/Makefile | 56 +-- sysutils/pftop/distinfo | 6 +- sysutils/pftop/files/extra-patch-bpf_dump.c | 15 - sysutils/pftop/files/extra-patch-cache.c | 84 ---- sysutils/pftop/files/extra-patch-cache.h | 29 -- sysutils/pftop/files/extra-patch-config.h | 28 -- sysutils/pftop/files/extra-patch-engine.c | 13 - sysutils/pftop/files/extra-patch-fairq_codel.diff | 102 ----- sysutils/pftop/files/extra-patch-pftop.c | 426 ----------------- sysutils/pftop/files/extra-patch-sf-gencode.c | 352 --------------- sysutils/pftop/files/extra-patch-sf-gencode.h | 10 - sysutils/pftop/files/patch-bpf_filter.c | 13 - sysutils/pftop/files/patch-bpf_image.c | 11 - sysutils/pftop/files/patch-config.h | 11 - sysutils/pftop/files/patch-pftop.c | 43 -- sysutils/pftop/files/patch-sf-scanner.l | 11 - sysutils/pftop/files/queue.h | 527 ---------------------- sysutils/pftop/pkg-descr | 2 +- 18 files changed, 14 insertions(+), 1725 deletions(-) diff --git a/sysutils/pftop/Makefile b/sysutils/pftop/Makefile index fabc231849d8..a48c78026d7c 100644 --- a/sysutils/pftop/Makefile +++ b/sysutils/pftop/Makefile @@ -1,6 +1,5 @@ PORTNAME= pftop -PORTVERSION= 0.8 -PORTREVISION= 4 +PORTVERSION= 0.9 CATEGORIES= sysutils net MAINTAINER= grembo@FreeBSD.org @@ -9,68 +8,33 @@ WWW= https://github.com/grembo/pftop/ LICENSE= BSD2CLAUSE +LIB_DEPENDS= libpfctl.so:net/libpfctl + USE_GITHUB= yes GH_ACCOUNT= grembo +CFLAGS+= -I${LOCALBASE}/include +LDFLAGS+= -L${LOCALBASE}/lib -lpfctl + OPTIONS_DEFINE= ALTQ ALTQ_DESC= ALTQ support for queue statistics .include <bsd.port.options.mk> -EXTRA_PATCHES+= ${FILESDIR}/extra-patch-bpf_dump.c \ - ${FILESDIR}/extra-patch-sf-gencode.h - -MAKE_ARGS= LOCALBASE="${PREFIX}" \ - -.if ${OPSYS} == FreeBSD && ${OSVERSION} >= 1400090 -MAKE_ARGS+= OSLEVEL=46 -.else -MAKE_ARGS+= OSLEVEL=45 -.endif +MAKE_ARGS= LOCALBASE="${PREFIX}" -CFLAGS+= -DHAVE_SNPRINTF=1 -DHAVE_VSNPRINTF=1 \ - -DHAVE_FINE_GRAINED_LOCKING=1 +CFLAGS+= -DHAVE_SNPRINTF=1 -DHAVE_VSNPRINTF=1 .if ${PORT_OPTIONS:MALTQ} CFLAGS+= -DHAVE_ALTQ=1 .endif -EXTRA_PATCHES+= ${FILESDIR}/extra-patch-cache.c ${FILESDIR}/extra-patch-cache.h \ - ${FILESDIR}/extra-patch-config.h \ - ${FILESDIR}/extra-patch-pftop.c \ - ${FILESDIR}/extra-patch-sf-gencode.c - -EXTRA_PATCHES+= ${FILESDIR}/extra-patch-engine.c - MAKE_ARGS+= CSTD=gnu89 MAKE_ENV+= __MAKE_CONF=/dev/null -PLIST_FILES= sbin/pftop \ - man/man8/pftop.8.gz - -post-patch: - @${ECHO_MSG} "===> Applying FairQ/Codel patches to ${PORTNAME}." - @${CAT} ${FILESDIR}/extra-patch-fairq_codel.diff | \ - ${PATCH} -d ${PATCH_WRKSRC} ${PATCH_ARGS} - @${REINPLACE_CMD} -e 's|<sys/queue.h>|"${FILESDIR}/queue.h"|g' \ - ${WRKSRC}/engine.c - @${REINPLACE_CMD} -e 's|__dead|__dead2|g' \ - ${WRKSRC}/sf-gencode.h - @${REINPLACE_CMD} -e 's|__dead|__dead2|g' \ - ${WRKSRC}/sf-gencode.c - @${REINPLACE_CMD} -e 's|#include <net/if_pflog.h>||g' \ - ${WRKSRC}/sf-gencode.c - @${REINPLACE_CMD} -e 's|altq/|net/&|' \ - ${WRKSRC}/pftop.c - @${REINPLACE_CMD} -e 's|#include .pcap-int.h.|#include <pcap/pcap.h>|g' \ - ${WRKSRC}/bpf_image.c \ - ${WRKSRC}/bpf_optimize.c \ - ${WRKSRC}/pcap-nametoaddr.c \ - ${WRKSRC}/sf-gencode.c \ - ${WRKSRC}/sf-gencode.h \ - ${WRKSRC}/sf-grammer.y \ - ${WRKSRC}/sf-scanner.l +PLIST_FILES= man/man8/pftop.8.gz \ + sbin/pftop do-install: ${INSTALL_PROGRAM} ${WRKSRC}/pftop \ diff --git a/sysutils/pftop/distinfo b/sysutils/pftop/distinfo index 945fc7dc87e6..cdc0c5c4a12a 100644 --- a/sysutils/pftop/distinfo +++ b/sysutils/pftop/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1654618929 -SHA256 (grembo-pftop-0.8_GH0.tar.gz) = 72b2ed39664771c22689ccb5ec7098792335717d926a8b87d987d8b628902d65 -SIZE (grembo-pftop-0.8_GH0.tar.gz) = 59599 +TIMESTAMP = 1699105116 +SHA256 (grembo-pftop-0.9_GH0.tar.gz) = 9b2dd44dba66c228ae03a88d65e6424f42872d2d73be776e055c5005998731d9 +SIZE (grembo-pftop-0.9_GH0.tar.gz) = 62612 diff --git a/sysutils/pftop/files/extra-patch-bpf_dump.c b/sysutils/pftop/files/extra-patch-bpf_dump.c deleted file mode 100644 index cc31af8c928a..000000000000 --- a/sysutils/pftop/files/extra-patch-bpf_dump.c +++ /dev/null @@ -1,15 +0,0 @@ ---- bpf_dump.c.orig 2007-11-07 07:34:18.000000000 +0100 -+++ bpf_dump.c 2014-10-17 12:39:01.000000000 +0200 -@@ -33,10 +33,10 @@ - #include <stdio.h> - - --extern void bpf_dump(struct bpf_program *, int); -+extern void bpf_dump(const struct bpf_program *, int); - - void --bpf_dump(struct bpf_program *p, int option) -+bpf_dump(const struct bpf_program *p, int option) - { - struct bpf_insn *insn; - int i; diff --git a/sysutils/pftop/files/extra-patch-cache.c b/sysutils/pftop/files/extra-patch-cache.c deleted file mode 100644 index 8a345a3f3d8b..000000000000 --- a/sysutils/pftop/files/extra-patch-cache.c +++ /dev/null @@ -1,84 +0,0 @@ -# Adjusted to work with the changes in r240233. -$OpenBSD: patch-cache_c,v 1.1 2008/06/13 00:38:12 canacar Exp $ ---- cache.c.orig Tue Nov 6 23:34:18 2007 -+++ cache.c Wed Jun 11 19:50:07 2008 -@@ -118,12 +118,21 @@ - - cache_size--; - -+#ifdef HAVE_PFSYNC_STATE -+#ifdef HAVE_FINE_GRAINED_LOCKING -+ ent->id = st->id; -+#else -+ ent->id[0] = st->id[0]; -+ ent->id[1] = st->id[1]; -+#endif -+#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 +156,21 @@ - if (cache_max == 0) - return (NULL); - -+#ifdef HAVE_PFSYNC_STATE -+#ifdef HAVE_FINE_GRAINED_LOCKING -+ ent.id = st->id; -+#else -+ ent.id[0] = st->id[0]; -+ ent.id[1] = st->id[1]; -+#endif -+#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 +227,25 @@ - static __inline int - sc_cmp(struct sc_ent *a, struct sc_ent *b) - { -+#ifdef HAVE_PFSYNC_STATE -+#ifdef HAVE_FINE_GRAINED_LOCKING -+ if (a->id > b->id) -+ return (1); -+ if (a->id < b->id) -+ return (-1); -+#else -+ 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); -+#endif -+#else - int diff; -- -+ - if ((diff = a->proto - b->proto) != 0) - return (diff); - if ((diff = a->af - b->af) != 0) -@@ -269,6 +303,6 @@ - return (diff); - if ((diff = a->port[1] - b->port[1]) != 0) - return (diff); -- -+#endif - return (0); - } diff --git a/sysutils/pftop/files/extra-patch-cache.h b/sysutils/pftop/files/extra-patch-cache.h deleted file mode 100644 index 4d6e3ac9d82d..000000000000 --- a/sysutils/pftop/files/extra-patch-cache.h +++ /dev/null @@ -1,29 +0,0 @@ -# Adjusted to work with FreeBSD r240233. -$OpenBSD: patch-cache_h,v 1.1 2008/06/13 00:38:12 canacar Exp $ ---- cache.h.orig Tue Nov 6 23:34:18 2007 -+++ cache.h Wed Jun 11 19:50:07 2008 -@@ -31,14 +31,24 @@ - struct sc_ent { - RB_ENTRY(sc_ent) tlink; - TAILQ_ENTRY(sc_ent) qlink; -+#ifdef HAVE_PFSYNC_STATE -+#ifdef HAVE_FINE_GRAINED_LOCKING -+ u_int64_t id; -+#else -+ u_int32_t id[2]; -+#endif -+#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); diff --git a/sysutils/pftop/files/extra-patch-config.h b/sysutils/pftop/files/extra-patch-config.h deleted file mode 100644 index ecd30c862dad..000000000000 --- a/sysutils/pftop/files/extra-patch-config.h +++ /dev/null @@ -1,28 +0,0 @@ -$OpenBSD: patch-config_h,v 1.4 2008/12/20 04:36:11 canacar Exp $ ---- config.h.orig Tue Nov 6 22:34:18 2007 -+++ config.h Fri Dec 19 20:28:01 2008 -@@ -74,11 +74,24 @@ - #define HAVE_PFSYNC_STATE - #endif - -+#if OS_LEVEL > 43 -+#define HAVE_PFSYNC_KEY -+#define HAVE_NETWORK_ORDER -+#endif -+ - #ifdef HAVE_PFSYNC_STATE -+#if OS_LEVEL > 45 -+typedef struct pfsync_state_1301 pf_state_t; -+#else - typedef struct pfsync_state pf_state_t; -+#endif - 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; diff --git a/sysutils/pftop/files/extra-patch-engine.c b/sysutils/pftop/files/extra-patch-engine.c deleted file mode 100644 index 329d307fc1fc..000000000000 --- a/sysutils/pftop/files/extra-patch-engine.c +++ /dev/null @@ -1,13 +0,0 @@ -$OpenBSD: patch-engine_c,v 1.1 2008/06/13 00:38:12 canacar Exp $ ---- engine.c.orig Tue Nov 6 23:35:44 2007 -+++ engine.c Thu Jun 12 17:49:32 2008 -@@ -809,6 +809,9 @@ next_order(void) - { - 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++) { diff --git a/sysutils/pftop/files/extra-patch-fairq_codel.diff b/sysutils/pftop/files/extra-patch-fairq_codel.diff deleted file mode 100644 index 3c501b15f501..000000000000 --- a/sysutils/pftop/files/extra-patch-fairq_codel.diff +++ /dev/null @@ -1,102 +0,0 @@ ---- pftop.c.orig 2013-05-11 12:53:55.000000000 +0000 -+++ pftop.c 2013-05-11 12:54:00.000000000 +0000 -@@ -48,6 +48,8 @@ - #include <altq/altq_cbq.h> - #include <altq/altq_priq.h> - #include <altq/altq_hfsc.h> -+#include <altq/altq_fairq.h> -+#include <altq/altq_codel.h> - #endif - - #include <ctype.h> -@@ -371,6 +373,8 @@ - class_stats_t cbq_stats; - struct priq_classstats priq_stats; - struct hfsc_classstats hfsc_stats; -+ struct fairq_classstats fairq_stats; -+ struct codel_ifstats codel_stats; - }; - - struct queue_stats { -@@ -1764,6 +1768,8 @@ - return (-1); - } - num_queues = nr_queues = pa.nr; -+ if (pa.altq.scheduler == ALTQT_CODEL) -+ num_queues = 1; - for (nr = 0; nr < nr_queues; ++nr) { - pa.nr = nr; - if (ioctl(pf_dev, DIOCGETALTQ, &pa)) { -@@ -1772,10 +1778,10 @@ - return (-1); - } - #ifdef PFALTQ_FLAG_IF_REMOVED -- if (pa.altq.qid > 0 && -+ if ((pa.altq.qid > 0 || pa.altq.scheduler == ALTQT_CODEL) && - !(pa.altq.local_flags & PFALTQ_FLAG_IF_REMOVED)) { - #else -- if (pa.altq.qid > 0) { -+ if (pa.altq.qid > 0 || pa.altq.scheduler == ALTQT_CODEL) { - #endif - pq.nr = nr; - pq.ticket = pa.ticket; -@@ -1928,11 +1934,14 @@ - tb_start(); - for (d = 0; d < node->depth; d++) - tbprintf(" "); -- tbprintf(node->altq.qname); -+ if (node->altq.qname[0] != '\0') -+ tbprintf(node->altq.qname); -+ else -+ tbprintf("root"); - print_fld_tb(FLD_QUEUE); - - if (node->altq.scheduler == ALTQT_CBQ || -- node->altq.scheduler == ALTQT_HFSC -+ node->altq.scheduler == ALTQT_HFSC || node->altq.scheduler == ALTQT_FAIRQ || node->altq.scheduler == ALTQT_CODEL - ) - print_fld_bw(FLD_BANDW, (double)node->altq.bandwidth); - -@@ -2003,6 +2012,42 @@ - node->qstats_last.data.hfsc_stats.xmit_cnt.bytes, interval); - } - break; -+ 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; -+ case ALTQT_CODEL: -+ print_fld_str(FLD_SCHED, "codel"); -+ print_fld_size(FLD_PKTS, -+ node->qstats.data.codel_stats.cl_xmitcnt.packets); -+ print_fld_size(FLD_BYTES, -+ node->qstats.data.codel_stats.cl_xmitcnt.bytes); -+ print_fld_size(FLD_DROPP, -+ node->qstats.data.codel_stats.cl_dropcnt.packets); -+ print_fld_size(FLD_DROPB, -+ node->qstats.data.codel_stats.cl_dropcnt.bytes); -+ print_fld_size(FLD_QLEN, node->qstats.data.codel_stats.qlength); -+ if (interval > 0) { -+ pps = calc_pps(node->qstats.data.codel_stats.cl_xmitcnt.packets, -+ node->qstats_last.data.codel_stats.cl_xmitcnt.packets, interval); -+ bps = calc_rate(node->qstats.data.codel_stats.cl_xmitcnt.bytes, -+ node->qstats_last.data.codel_stats.cl_xmitcnt.bytes, interval); -+ } -+ break; - } - - /* if (node->altq.scheduler != ALTQT_HFSC && interval > 0) { */ diff --git a/sysutils/pftop/files/extra-patch-pftop.c b/sysutils/pftop/files/extra-patch-pftop.c deleted file mode 100644 index c066876c4b5c..000000000000 --- a/sysutils/pftop/files/extra-patch-pftop.c +++ /dev/null @@ -1,426 +0,0 @@ -# One chunk of this OpenBSD patch has been removed as it's -# already part of patch-pftop.c, another one has been extended -# to fix the rule display in some views. -$OpenBSD: patch-pftop_c,v 1.12 2009/12/02 21:16:10 sthen Exp $ ---- pftop.c.orig Wed Nov 7 06:36:46 2007 -+++ pftop.c Wed Dec 2 21:14:56 2009 -@@ -127,6 +127,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); -@@ -445,11 +452,11 @@ sort_pkt_callback(const void *s1, const void *s2) - 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 +464,11 @@ sort_age_callback(const void *s1, const void *s2) - 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 +542,8 @@ compare_addr(int af, const struct pf_addr *a, const st - return 0; - } - -+#ifdef HAVE_PFSYNC_KEY -+ - #ifdef __GNUC__ - __inline__ - #endif -@@ -542,6 +551,113 @@ 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 -+int -+sort_addr_callback(const pf_state_t *s1, -+ const pf_state_t *s2, int dir) -+{ - const pf_state_host_t *a, *b; - int af, ret; - -@@ -573,20 +689,6 @@ sort_addr_callback(const pf_state_t *s1, - 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,7 +727,22 @@ sort_port_callback(const pf_state_t *s1, - 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) - { -@@ -865,7 +982,48 @@ tb_print_addr(struct pf_addr * addr, struct pf_addr * - 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 +1047,7 @@ print_fld_host(field_def *fld, pf_state_host_t * h, in - - print_fld_tb(fld); - } -+#endif - - void - print_fld_state(field_def *fld, unsigned int proto, -@@ -960,7 +1119,20 @@ print_state(pf_state_t * s, struct sc_ent * ent) - 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); - } else { -@@ -972,6 +1144,7 @@ print_state(pf_state_t * s, struct sc_ent * ent) - (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 +1152,8 @@ print_state(pf_state_t * s, struct sc_ent * ent) - 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,18 +1161,18 @@ print_state(pf_state_t * s, struct sc_ent * ent) - 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(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(s->creation)) : -1); - - #endif - #ifdef HAVE_PFSYNC_STATE -- print_fld_uint(FLD_RULE, s->rule); -+ print_fld_uint(FLD_RULE, ntohl(s->rule)); - #else - #ifdef HAVE_RULE_NUMBER - print_fld_uint(FLD_RULE, s->rule.nr); -@@ -1475,8 +1648,12 @@ print_rule(struct pf_rule *pr) - print_fld_str(FLD_LABEL, pr->label); - #endif - #ifdef HAVE_RULE_STATES -+#ifdef HAVE_PFSYNC_KEY -+ print_fld_size(FLD_STATS, pr->u_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]); -@@ -1729,12 +1912,19 @@ pfctl_insert_altq_node(struct pf_altq_node **root, - 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 +1937,7 @@ pfctl_update_qstats(struct pf_altq_node **root, int *i - 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 +1948,15 @@ pfctl_update_qstats(struct pf_altq_node **root, int *i - 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 +1966,8 @@ pfctl_update_qstats(struct pf_altq_node **root, int *i - 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 +1988,10 @@ pfctl_update_qstats(struct pf_altq_node **root, int *i - else - --num_queues; - } -- return (0); -+ -+ pfctl_set_next_flat(*root, NULL); -+ -+ return (ret); - } - - void diff --git a/sysutils/pftop/files/extra-patch-sf-gencode.c b/sysutils/pftop/files/extra-patch-sf-gencode.c deleted file mode 100644 index b9155667393a..000000000000 --- a/sysutils/pftop/files/extra-patch-sf-gencode.c +++ /dev/null @@ -1,352 +0,0 @@ -$OpenBSD: patch-sf-gencode_c,v 1.1 2008/06/13 00:38:12 canacar Exp $ ---- sf-gencode.c.orig Tue Nov 6 23:34:18 2007 -+++ sf-gencode.c Wed Jun 11 19:50:10 2008 -@@ -474,9 +474,107 @@ gen_proto(int proto) - (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); -+ -+ addr = ntohl(addr); -+ mask = ntohl(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_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); *** 928 LINES SKIPPED ***