Author: glebius
Date: Wed Jan 27 00:50:27 2016
New Revision: 294871
URL: https://svnweb.freebsd.org/changeset/base/294871

Log:
  Grab value for LEAF_tcpCurrEstab from net.inet.tcp.stats instead of
  net.inet.tcp.pcblist, which is much cheaper.

Modified:
  head/contrib/bsnmp/snmp_mibII/mibII_tcp.c

Modified: head/contrib/bsnmp/snmp_mibII/mibII_tcp.c
==============================================================================
--- head/contrib/bsnmp/snmp_mibII/mibII_tcp.c   Wed Jan 27 00:48:05 2016        
(r294870)
+++ head/contrib/bsnmp/snmp_mibII/mibII_tcp.c   Wed Jan 27 00:50:27 2016        
(r294871)
@@ -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 *
 }
 
 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
                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
                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:
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to