summaryrefslogtreecommitdiff
path: root/sysutils/pftop/patches/patch-ab
blob: 553a10b772aacb7855b8ed7db5a940f11d7febfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
$NetBSD: patch-ab,v 1.7 2015/01/14 20:39:42 rumko Exp $
$OpenBSD: patch-cache_c,v 1.1 2008/06/13 00:38:12 canacar Exp $

* DragonFly and FreeBSD compatibility
* Patches to support PF > 4.1 taken from OpenBSD's ports

--- cache.c.orig	2007-11-07 06:34:18.000000000 +0000
+++ cache.c
@@ -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 @@ static __inline int sc_cmp(struct sc_ent
 
 /* 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,21 @@ add_state(pf_state_t *st)
 
 	cache_size--;
 
+#ifdef HAVE_PFSYNC_STATE
+#if defined(__FreeBSD__) && __FreeBSD_version > 1000017
+	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 +161,21 @@ cache_state(pf_state_t *st)
 	if (cache_max == 0)
 		return (NULL);
 
+#ifdef HAVE_PFSYNC_STATE
+#if defined(__FreeBSD__) && __FreeBSD_version > 1000017
+	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 +232,25 @@ cache_endupdate(void)
 static __inline int
 sc_cmp(struct sc_ent *a, struct sc_ent *b)
 {
+#ifdef HAVE_PFSYNC_STATE
+#if defined(__FreeBSD__) && __FreeBSD_version > 1000017
+	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 +308,6 @@ sc_cmp(struct sc_ent *a, struct sc_ent *
 		return (diff);
 	if ((diff = a->port[1] - b->port[1]) != 0)
 		return (diff);
-
+#endif
 	return (0);
 }