summaryrefslogtreecommitdiffstats
path: root/sys/netgraph/netflow
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2005-03-03 11:01:05 +0000
committerglebius <glebius@FreeBSD.org>2005-03-03 11:01:05 +0000
commit698a8eb6dde41558b4c8e4309a71e70b5d41f32f (patch)
treee624dba288074775a9bf7f8cf2f888fe3b62274a /sys/netgraph/netflow
parentbed0867bba953572a2ce524b670548c8b76b7698 (diff)
downloadFreeBSD-src-698a8eb6dde41558b4c8e4309a71e70b5d41f32f.zip
FreeBSD-src-698a8eb6dde41558b4c8e4309a71e70b5d41f32f.tar.gz
Cisco uses milliseconds for uptime. This is stupid. Nobody cares of such
precision when IP packet may travel through internet for several seconds. Also uptime measured in milliseconds overflows every 48+ days. But we have to do same to keep compatibility with Cisco and flow-tools. Make a macro MILLIUPTIME, which does overflowable multiplication to 1000. Requested by: Sergey Ryabin, Oleg Bulyzhin MFC after: 1 week
Diffstat (limited to 'sys/netgraph/netflow')
-rw-r--r--sys/netgraph/netflow/netflow.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/sys/netgraph/netflow/netflow.c b/sys/netgraph/netflow/netflow.c
index cc4fbf3..6011e38 100644
--- a/sys/netgraph/netflow/netflow.c
+++ b/sys/netgraph/netflow/netflow.c
@@ -82,7 +82,19 @@ static const char rcs_id[] =
* of reachable host and 4-packet otherwise.
*/
#define SMALL(fle) (fle->f.packets <= 4)
-
+
+/*
+ * Cisco uses milliseconds for uptime. Bad idea, since it overflows
+ * every 48+ days. But we will do same to keep compatibility. This macro
+ * does overflowable multiplication to 1000.
+ */
+#define MILLIUPTIME(t) (((t) << 9) + /* 512 */ \
+ ((t) << 8) + /* 256 */ \
+ ((t) << 7) + /* 128 */ \
+ ((t) << 6) + /* 64 */ \
+ ((t) << 5) + /* 32 */ \
+ ((t) << 3)) /* 8 */
+
MALLOC_DECLARE(M_NETFLOW);
MALLOC_DEFINE(M_NETFLOW, "NetFlow", "flow cache");
@@ -578,7 +590,7 @@ export_send(priv_p priv)
int error = 0;
int mlen;
- header->sys_uptime = htonl(time_uptime);
+ header->sys_uptime = htonl(MILLIUPTIME(time_uptime));
getnanotime(&ts);
header->unix_secs = htonl(ts.tv_sec);
@@ -635,8 +647,8 @@ export_add(priv_p priv, struct flow_entry *fle)
rec->o_ifx = htons(fle->f.fle_o_ifx);
rec->packets = htonl(fle->f.packets);
rec->octets = htonl(fle->f.bytes);
- rec->first = htonl(fle->f.first);
- rec->last = htonl(fle->f.last);
+ rec->first = htonl(MILLIUPTIME(fle->f.first));
+ rec->last = htonl(MILLIUPTIME(fle->f.last));
rec->s_port = fle->f.r.r_sport;
rec->d_port = fle->f.r.r_dport;
rec->flags = fle->f.tcp_flags;
OpenPOWER on IntegriCloud