summaryrefslogtreecommitdiff
path: root/snmp_mibII/mibII_tcp.c
diff options
context:
space:
mode:
Diffstat (limited to 'snmp_mibII/mibII_tcp.c')
-rw-r--r--snmp_mibII/mibII_tcp.c56
1 files changed, 38 insertions, 18 deletions
diff --git a/snmp_mibII/mibII_tcp.c b/snmp_mibII/mibII_tcp.c
index 561216f0a5de..e6d5920d9f88 100644
--- a/snmp_mibII/mibII_tcp.c
+++ b/snmp_mibII/mibII_tcp.c
@@ -4,7 +4,7 @@
* All rights reserved.
*
* Author: Harti Brandt <harti@freebsd.org>
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -13,7 +13,7 @@
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -45,10 +45,11 @@ struct tcp_index {
};
static uint64_t tcp_tick;
+static uint64_t tcp_stats_tick;
static struct tcpstat tcpstat;
+static uint64_t tcps_states[TCP_NSTATES];
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 +65,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 +79,31 @@ fetch_tcp(void)
return (-1);
}
+ len = sizeof(tcps_states);
+ if (sysctlbyname("net.inet.tcp.states", &tcps_states, &len, NULL,
+ 0) == -1) {
+ syslog(LOG_ERR, "net.inet.tcp.states: %m");
+ return (-1);
+ }
+ if (len != sizeof(tcps_states)) {
+ syslog(LOG_ERR, "net.inet.tcp.states: wrong size");
+ 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,20 +124,17 @@ 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);
ptr = (struct xinpgen *)(void *)((char *)ptr + ptr->xig_len)) {
tp = (struct xtcpcb *)ptr;
if (tp->xt_inp.inp_gencnt > xinpgen->xig_gen ||
- (tp->xt_inp.inp_vflag & INP_IPV4) == 0)
+ (tp->xt_inp.inp_vflag & (INP_IPV4|INP_IPV6)) == 0)
continue;
- tcp_total++;
- if (tp->xt_tp.t_state == TCPS_ESTABLISHED ||
- tp->xt_tp.t_state == TCPS_CLOSE_WAIT)
- tcp_count++;
+ if (tp->xt_inp.inp_vflag & INP_IPV4)
+ tcp_total++;
}
if (oidnum < tcp_total) {
@@ -182,8 +201,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]) {
@@ -224,7 +243,8 @@ op_tcp(struct snmp_context *ctx __unused, struct snmp_value *value,
break;
case LEAF_tcpCurrEstab:
- value->v.uint32 = tcp_count;
+ value->v.uint32 = tcps_states[TCPS_ESTABLISHED] +
+ tcps_states[TCPS_CLOSE_WAIT];
break;
case LEAF_tcpInSegs:
@@ -290,7 +310,7 @@ op_tcpconn(struct snmp_context *ctx __unused, struct snmp_value *value,
switch (value->var.subs[sub - 1]) {
case LEAF_tcpConnState:
- switch (tcpoids[i].tp->xt_tp.t_state) {
+ switch (tcpoids[i].tp->t_state) {
case TCPS_CLOSED:
value->v.integer = 1;