summaryrefslogtreecommitdiffstats
path: root/contrib/bsnmp
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2016-01-27 00:50:27 +0000
committerglebius <glebius@FreeBSD.org>2016-01-27 00:50:27 +0000
commit6c4255a1e633d69e779125ce66e6032a1abca475 (patch)
treea8de5083c53b6c565a56672b15907f3261af59a3 /contrib/bsnmp
parentccaed9e02be515e0496ee4dc90e02aac28c3485a (diff)
downloadFreeBSD-src-6c4255a1e633d69e779125ce66e6032a1abca475.zip
FreeBSD-src-6c4255a1e633d69e779125ce66e6032a1abca475.tar.gz
Grab value for LEAF_tcpCurrEstab from net.inet.tcp.stats instead of
net.inet.tcp.pcblist, which is much cheaper.
Diffstat (limited to 'contrib/bsnmp')
-rw-r--r--contrib/bsnmp/snmp_mibII/mibII_tcp.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/contrib/bsnmp/snmp_mibII/mibII_tcp.c b/contrib/bsnmp/snmp_mibII/mibII_tcp.c
index a61052d..c798bae 100644
--- a/contrib/bsnmp/snmp_mibII/mibII_tcp.c
+++ b/contrib/bsnmp/snmp_mibII/mibII_tcp.c
@@ -45,10 +45,10 @@ struct tcp_index {
};
static uint64_t tcp_tick;
+static uint64_t tcp_stats_tick;
static struct tcpstat tcpstat;
static struct xinpgen *xinpgen;
static size_t xinpgen_len;
-static u_int tcp_count;
static u_int tcp_total;
static u_int oidnum;
@@ -64,13 +64,9 @@ tcp_compare(const void *p1, const void *p2)
}
static int
-fetch_tcp(void)
+fetch_tcp_stats(void)
{
size_t len;
- struct xinpgen *ptr;
- struct xtcpcb *tp;
- struct tcp_index *oid;
- in_addr_t inaddr;
len = sizeof(tcpstat);
if (sysctlbyname("net.inet.tcp.stats", &tcpstat, &len, NULL, 0) == -1) {
@@ -82,6 +78,20 @@ fetch_tcp(void)
return (-1);
}
+ tcp_stats_tick = get_ticks();
+
+ return (0);
+}
+
+static int
+fetch_tcp(void)
+{
+ size_t len;
+ struct xinpgen *ptr;
+ struct xtcpcb *tp;
+ struct tcp_index *oid;
+ in_addr_t inaddr;
+
len = 0;
if (sysctlbyname("net.inet.tcp.pcblist", NULL, &len, NULL, 0) == -1) {
syslog(LOG_ERR, "net.inet.tcp.pcblist: %m");
@@ -102,7 +112,6 @@ fetch_tcp(void)
tcp_tick = get_ticks();
- tcp_count = 0;
tcp_total = 0;
for (ptr = (struct xinpgen *)(void *)((char *)xinpgen + xinpgen->xig_len);
ptr->xig_len > sizeof(struct xinpgen);
@@ -114,10 +123,6 @@ fetch_tcp(void)
if (tp->xt_inp.inp_vflag & INP_IPV4)
tcp_total++;
-
- if (tp->xt_tp.t_state == TCPS_ESTABLISHED ||
- tp->xt_tp.t_state == TCPS_CLOSE_WAIT)
- tcp_count++;
}
if (oidnum < tcp_total) {
@@ -184,8 +189,8 @@ op_tcp(struct snmp_context *ctx __unused, struct snmp_value *value,
abort();
}
- if (tcp_tick < this_tick)
- if (fetch_tcp() == -1)
+ if (tcp_stats_tick < this_tick)
+ if (fetch_tcp_stats() == -1)
return (SNMP_ERR_GENERR);
switch (value->var.subs[sub - 1]) {
@@ -226,7 +231,8 @@ op_tcp(struct snmp_context *ctx __unused, struct snmp_value *value,
break;
case LEAF_tcpCurrEstab:
- value->v.uint32 = tcp_count;
+ value->v.uint32 = tcpstat.tcps_states[TCPS_ESTABLISHED] +
+ tcpstat.tcps_states[TCPS_CLOSE_WAIT];
break;
case LEAF_tcpInSegs:
OpenPOWER on IntegriCloud