diff options
author | Ryan Thomas McBride <mcbride@cvs.openbsd.org> | 2008-06-29 08:42:16 +0000 |
---|---|---|
committer | Ryan Thomas McBride <mcbride@cvs.openbsd.org> | 2008-06-29 08:42:16 +0000 |
commit | 99e04e378e33075d748641da5140863b7b7f982d (patch) | |
tree | ae0b5cd3428dd52812e443fd85393c2d10f690e5 /usr.bin/systat | |
parent | 5e873aaaca6fb4b1a29dc92c01173dbf221481c3 (diff) |
Simplify state creation code; merge state import/export code between pfsync
and the state-related pf(4) ioctls, and make functions in state creation and
destruction paths more robust in error conditions.
All values in struct pfsync_state now in network byte order, as with pfsync.
testing by david
ok henning, systat parts ok canacar
Diffstat (limited to 'usr.bin/systat')
-rw-r--r-- | usr.bin/systat/config.h | 4 | ||||
-rw-r--r-- | usr.bin/systat/pftop.c | 30 |
2 files changed, 17 insertions, 17 deletions
diff --git a/usr.bin/systat/config.h b/usr.bin/systat/config.h index 53e112ded2a..6ea6b2f8988 100644 --- a/usr.bin/systat/config.h +++ b/usr.bin/systat/config.h @@ -1,4 +1,4 @@ -/* $Id: config.h,v 1.1 2008/06/12 22:26:01 canacar Exp $ */ +/* $Id: config.h,v 1.2 2008/06/29 08:42:15 mcbride Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar <canacar@openbsd.org> * @@ -72,7 +72,7 @@ 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; -#define COUNTER(c) ((((u_int64_t) c[0])<<32) + c[1]) +#define COUNTER(c) ((((u_int64_t) ntohl(c[0]))<<32) + ntohl(c[1])) #define pfs_ifname ifname #else typedef struct pf_state pf_state_t; diff --git a/usr.bin/systat/pftop.c b/usr.bin/systat/pftop.c index 5fccfba7d92..3d800186e9e 100644 --- a/usr.bin/systat/pftop.c +++ b/usr.bin/systat/pftop.c @@ -1,4 +1,4 @@ -/* $Id: pftop.c,v 1.2 2008/06/13 23:47:17 canacar Exp $ */ +/* $Id: pftop.c,v 1.3 2008/06/29 08:42:15 mcbride Exp $ */ /* * Copyright (c) 2001, 2007 Can Erkin Acar * Copyright (c) 2001 Daniel Hartmeier @@ -425,11 +425,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 (ntohl(state_buf[* (u_int32_t *) s2].creation) > + ntohl(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 (ntohl(state_buf[* (u_int32_t *) s2].creation) < + ntohl(state_buf[* (u_int32_t *) s1].creation)) return -sortdir; return 0; } @@ -437,11 +437,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 (ntohl(state_buf[* (u_int32_t *) s2].expire) > + ntohl(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 (ntohl(state_buf[* (u_int32_t *) s2].expire) < + ntohl(state_buf[* (u_int32_t *) s1].expire)) return -sortdir; return 0; } @@ -1041,8 +1041,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, ntohl(s->creation)); + print_fld_age(FLD_EXP, ntohl(s->expire)); #ifdef HAVE_INOUT_COUNT { u_int64_t sz = COUNTER(s->bytes[0]) + COUNTER(s->bytes[1]); @@ -1050,14 +1050,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/ntohl((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/ntohl((double)s->creation)) : -1); #endif #ifdef HAVE_PFSYNC_STATE |