Sync to systat:
* Fix byte-order of bytes, packets, age and expire fields. * Fix the order of traversal when printing the queues. Reported by many.
This commit is contained in:
parent
9582e06e0d
commit
368b3deb14
@ -1,10 +1,10 @@
|
||||
# $OpenBSD: Makefile,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
# $OpenBSD: Makefile,v 1.11 2008/12/20 04:36:11 canacar Exp $
|
||||
#
|
||||
|
||||
COMMENT= curses-based real time state and rule display for pf
|
||||
|
||||
DISTNAME= pftop-0.7
|
||||
PKGNAME= ${DISTNAME}p0
|
||||
PKGNAME= ${DISTNAME}p1
|
||||
CATEGORIES= sysutils
|
||||
|
||||
HOMEPAGE= http://www.eee.metu.edu.tr/~canacar/pftop/
|
||||
|
@ -1,12 +1,24 @@
|
||||
$OpenBSD: patch-config_h,v 1.3 2008/06/13 00:38:12 canacar Exp $
|
||||
--- config.h.orig Tue Nov 6 23:34:18 2007
|
||||
+++ config.h Thu Jun 12 17:49:32 2008
|
||||
@@ -74,6 +74,8 @@
|
||||
$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,20 @@
|
||||
#define HAVE_PFSYNC_STATE
|
||||
#endif
|
||||
|
||||
+#if OS_LEVEL > 43
|
||||
+#define HAVE_PFSYNC_KEY
|
||||
+#define HAVE_NETWORK_ORDER
|
||||
+#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;
|
||||
|
@ -1,7 +1,53 @@
|
||||
$OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
--- pftop.c.orig Tue Nov 6 23:36:46 2007
|
||||
+++ pftop.c Thu Jun 12 17:51:33 2008
|
||||
@@ -535,6 +535,8 @@ compare_addr(int af, const struct pf_addr *a, const st
|
||||
$OpenBSD: patch-pftop_c,v 1.11 2008/12/20 04:36:11 canacar Exp $
|
||||
--- pftop.c.orig Tue Nov 6 22:36:46 2007
|
||||
+++ pftop.c Fri Dec 19 20:28:06 2008
|
||||
@@ -127,6 +131,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 +456,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 +468,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 +546,8 @@ compare_addr(int af, const struct pf_addr *a, const st
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -10,7 +56,7 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
#ifdef __GNUC__
|
||||
__inline__
|
||||
#endif
|
||||
@@ -542,6 +544,113 @@ int
|
||||
@@ -542,6 +555,113 @@ int
|
||||
sort_addr_callback(const pf_state_t *s1,
|
||||
const pf_state_t *s2, int dir)
|
||||
{
|
||||
@ -124,7 +170,7 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
const pf_state_host_t *a, *b;
|
||||
int af, ret;
|
||||
|
||||
@@ -573,20 +682,6 @@ sort_addr_callback(const pf_state_t *s1,
|
||||
@@ -573,20 +693,6 @@ sort_addr_callback(const pf_state_t *s1,
|
||||
return -sortdir;
|
||||
}
|
||||
|
||||
@ -145,7 +191,7 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
#ifdef __GNUC__
|
||||
__inline__
|
||||
#endif
|
||||
@@ -625,7 +720,22 @@ sort_port_callback(const pf_state_t *s1,
|
||||
@@ -625,7 +731,22 @@ sort_port_callback(const pf_state_t *s1,
|
||||
return sortdir;
|
||||
return -sortdir;
|
||||
}
|
||||
@ -168,7 +214,7 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
int
|
||||
sort_sp_callback(const void *p1, const void *p2)
|
||||
{
|
||||
@@ -865,7 +975,48 @@ tb_print_addr(struct pf_addr * addr, struct pf_addr *
|
||||
@@ -865,7 +986,48 @@ tb_print_addr(struct pf_addr * addr, struct pf_addr *
|
||||
tbprintf("/%u", unmask(mask, af));
|
||||
}
|
||||
}
|
||||
@ -217,7 +263,7 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
void
|
||||
print_fld_host(field_def *fld, pf_state_host_t * h, int af)
|
||||
{
|
||||
@@ -889,6 +1040,7 @@ print_fld_host(field_def *fld, pf_state_host_t * h, in
|
||||
@@ -889,6 +1051,7 @@ print_fld_host(field_def *fld, pf_state_host_t * h, in
|
||||
|
||||
print_fld_tb(fld);
|
||||
}
|
||||
@ -225,7 +271,7 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
|
||||
void
|
||||
print_fld_state(field_def *fld, unsigned int proto,
|
||||
@@ -960,7 +1112,20 @@ print_state(pf_state_t * s, struct sc_ent * ent)
|
||||
@@ -960,7 +1123,20 @@ print_state(pf_state_t * s, struct sc_ent * ent)
|
||||
else
|
||||
print_fld_uint(FLD_PROTO, s->proto);
|
||||
|
||||
@ -246,7 +292,7 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
print_fld_host(FLD_SRC, &s->lan, s->af);
|
||||
print_fld_host(FLD_DEST, &s->ext, s->af);
|
||||
} else {
|
||||
@@ -972,6 +1137,7 @@ print_state(pf_state_t * s, struct sc_ent * ent)
|
||||
@@ -972,6 +1148,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);
|
||||
}
|
||||
@ -254,7 +300,37 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
|
||||
if (s->direction == PF_OUT)
|
||||
print_fld_str(FLD_DIR, "Out");
|
||||
@@ -1475,8 +1641,12 @@ print_rule(struct pf_rule *pr)
|
||||
@@ -979,8 +1156,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,14 +1165,14 @@ 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((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
|
||||
@@ -1475,8 +1652,12 @@ print_rule(struct pf_rule *pr)
|
||||
print_fld_str(FLD_LABEL, pr->label);
|
||||
#endif
|
||||
#ifdef HAVE_RULE_STATES
|
||||
@ -267,7 +343,7 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
|
||||
#ifdef HAVE_INOUT_COUNT_RULES
|
||||
print_fld_size(FLD_PKTS, pr->packets[0] + pr->packets[1]);
|
||||
@@ -1486,7 +1656,13 @@ print_rule(struct pf_rule *pr)
|
||||
@@ -1486,7 +1667,13 @@ print_rule(struct pf_rule *pr)
|
||||
print_fld_size(FLD_BYTES, pr->bytes);
|
||||
#endif
|
||||
print_fld_uint(FLD_RULE, pr->nr);
|
||||
@ -282,3 +358,76 @@ $OpenBSD: patch-pftop_c,v 1.10 2008/06/13 00:38:12 canacar Exp $
|
||||
if (pr->quick)
|
||||
print_fld_str(FLD_QUICK, "Quick");
|
||||
|
||||
@@ -1729,12 +1916,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 +1941,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 +1952,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 +1970,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 +1992,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
|
||||
|
Loading…
Reference in New Issue
Block a user