PERFORCE change 82494 for review
Victor Cruceru
soc-victor at FreeBSD.org
Wed Aug 24 10:38:38 GMT 2005
http://perforce.freebsd.org/chv.cgi?CH=82494
Change 82494 by soc-victor at soc-victor_82.76.158.176 on 2005/08/24 10:38:21
- Added the SNMP instrumentation for the deprecated
tcpConnTable (IPv4 only, backward compatible).
- Added the missing Makefile for this tcp46 module.
Affected files ...
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/Makefile#1 add
.. //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/tcp46_snmp.c#3 edit
Differences ...
==== //depot/projects/soc2005/bsnmp/usr.sbin/bsnmpd/modules/snmp_tcp46/tcp46_snmp.c#3 (text+ko) ====
@@ -85,7 +85,11 @@
#include <sys/types.h>
#include <sys/sysctl.h>
+/*forward declaration*/
+static int
+fetch_tcp(void);
+
/*a debug macro*/
#ifndef NDEBUG
#define TCP46_DPRINTF(ARGS) do { \
@@ -109,6 +113,20 @@
static
const struct asn_oid oid_tcp46 = OIDX_tcpMIB; /*see the generated file tcp46_oid.h*/
+enum TCP_ConnState {
+ TCPS_closed = 1,
+ TCPS_listen = 2,
+ TCPS_synSent = 3,
+ TCPS_synReceived = 4,
+ TCPS_established = 5,
+ TCPS_finWait1 = 6,
+ TCPS_finWait2 = 7,
+ TCPS_closeWait = 8,
+ TCPS_lastAck = 9,
+ TCPS_closing = 10,
+ TCPS_timeWait = 11,
+ TCPS_deleteTCB = 12
+};
struct tcp_index {
@@ -251,7 +269,12 @@
tcp46_module);
if (tcp46_registration_id == 0) {
syslog(LOG_ERR, "Failed to register the tcp46 module." );
+ return;
}
+ if (fetch_tcp() == -1) {
+ syslog(LOG_ERR, "Failed to fetch the TCP data in tcp46 module." );
+ }
+
TCP46_DPRINTF((stderr, "[%s] done.\n ", __func__));
}
@@ -314,6 +337,7 @@
tcp46_state_g.tcp_tick = get_ticks();
tcp46_state_g.tcp_estab_count = 0;
+ tcp46_state_g.tcp4_total = 0;
/*First count the endpoints*/
for (ptr = (struct xinpgen *)(void *)((char *)tcp46_state_g.xinpgen + tcp46_state_g.xinpgen->xig_len);
@@ -323,12 +347,21 @@
assert(ptr != NULL);
/* Ignore sockets for protocols other than the desired one. */
- if (((struct xinpcb *)ptr)->xi_socket.xso_protocol != IPPROTO_TCP) {
+ if ((( struct xtcpcb *)ptr)->xt_socket.xso_protocol != IPPROTO_TCP) {
+ TCP46_DPRINTF((stderr, "[%s] One tcp4 conn. ignored (protocol missmatch: %d)\n ",
+ __func__,
+ ((struct xinpcb *)ptr)->xi_socket.xso_protocol
+ ));
+
continue;
}
/* Ignore PCBs which were freed during copyout. */
if (tp->xt_inp.inp_gencnt > tcp46_state_g.xinpgen->xig_gen ) {
+ TCP46_DPRINTF((stderr, "[%s] One tcp4 conn. ignored (freed during copyout)\n ",
+ __func__
+ ));
+
continue;
}
@@ -343,6 +376,10 @@
}
}
+ TCP46_DPRINTF((stderr, "[%s] Got %d tcp4 connections.\n ",
+ __func__,
+ tcp46_state_g.tcp4_total));
+
/*Then reallocate the SNMP holder if needed*/
if (tcp46_state_g.tcp4oids_len < tcp46_state_g.tcp4_total) {
oid = realloc(tcp46_state_g.tcp4oids,
@@ -356,7 +393,7 @@
tcp46_state_g.tcp4oids_len = tcp46_state_g.tcp4_total;
}
- /*Fimally fill in the SNMP index*/
+ /*Finally fill in the SNMP index*/
memset(tcp46_state_g.tcp4oids, 0,
tcp46_state_g.tcp4_total * sizeof(tcp46_state_g.tcp4oids[0]) );
@@ -367,7 +404,7 @@
tp = (struct xtcpcb *)ptr;
assert(ptr != NULL);
/* Ignore sockets for protocols other than the desired one. */
- if (((struct xinpcb *)ptr)->xi_socket.xso_protocol != IPPROTO_TCP) {
+ if (((struct xtcpcb *)ptr)->xt_socket.xso_protocol != IPPROTO_TCP) {
continue;
}
@@ -397,7 +434,7 @@
/*Keep the list sorted ins SNMP index ordering*/
qsort( tcp46_state_g.tcp4oids,
tcp46_state_g.tcp4_total,
- sizeof(tcp46_state_g.tcp4oids),
+ sizeof(tcp46_state_g.tcp4oids[0]),
tcp_compare);
return (0);
@@ -515,13 +552,118 @@
return (SNMP_ERR_NOERROR);
}
+
+/*
+ * This is the deprecated TCP Connection table
+ * tcpConnTable
+*/
int
-op_tcpConnTable( struct snmp_context *ctx __unused,
- struct snmp_value *value __unused,
- u_int sub __unused,
- u_int iidx __unused,
- enum snmp_op curr_op __unused ) {
- return (SNMP_ERR_NOSUCHNAME);
+op_tcpConnTable( struct snmp_context *ctx __unused, struct snmp_value *value,
+ u_int sub, u_int iidx __unused, enum snmp_op op)
+{
+ u_int i;
+
+ if (tcp46_state_g.tcp_tick < this_tick)
+ if (fetch_tcp() == -1)
+ return (SNMP_ERR_GENERR);
+
+ switch (op) {
+
+ case SNMP_OP_GETNEXT:
+ for (i = 0; i < tcp46_state_g.tcp4_total; i++)
+ if (index_compare(&value->var, sub, &tcp46_state_g.tcp4oids[i].index) < 0)
+ break;
+ if (i == tcp46_state_g.tcp4_total)
+ return (SNMP_ERR_NOSUCHNAME);
+ index_append(&value->var, sub, &tcp46_state_g.tcp4oids[i].index);
+ break;
+
+ case SNMP_OP_GET:
+ for (i = 0; i < tcp46_state_g.tcp4_total; i++)
+ if (index_compare(&value->var, sub, &tcp46_state_g.tcp4oids[i].index) == 0)
+ break;
+ if (i == tcp46_state_g.tcp4_total)
+ return (SNMP_ERR_NOSUCHNAME);
+ break;
+
+ case SNMP_OP_SET:
+ return (SNMP_ERR_NOT_WRITEABLE);
+
+ case SNMP_OP_ROLLBACK:
+ case SNMP_OP_COMMIT:
+ default:
+ abort();
+ }
+
+ switch (value->var.subs[sub - 1]) {
+
+ case LEAF_tcpConnState:
+ switch (tcp46_state_g.tcp4oids[i].tp->xt_tp.t_state) {
+
+ case TCPS_CLOSED:
+ value->v.integer = TCPS_closed;
+ break;
+ case TCPS_LISTEN:
+ value->v.integer = TCPS_listen;
+ break;
+ case TCPS_SYN_SENT:
+ value->v.integer = TCPS_synSent;
+ break;
+ case TCPS_SYN_RECEIVED:
+ value->v.integer = TCPS_synReceived;
+ break;
+ case TCPS_ESTABLISHED:
+ value->v.integer = TCPS_established;
+ break;
+ case TCPS_CLOSE_WAIT:
+ value->v.integer = TCPS_closeWait;
+ break;
+ case TCPS_FIN_WAIT_1:
+ value->v.integer = TCPS_finWait1;
+ break;
+ case TCPS_CLOSING:
+ value->v.integer = TCPS_closing;
+ break;
+ case TCPS_LAST_ACK:
+ value->v.integer = TCPS_lastAck;
+ break;
+ case TCPS_FIN_WAIT_2:
+ value->v.integer = TCPS_finWait2;
+ break;
+ case TCPS_TIME_WAIT:
+ value->v.integer = TCPS_timeWait;
+ break;
+ default:
+ value->v.integer = 0;
+ break;
+ }
+ break;
+
+ assert(tcp46_state_g.tcp4oids[i].index.len == 10);
+
+ case LEAF_tcpConnLocalAddress:
+ value->v.ipaddress[0] = tcp46_state_g.tcp4oids[i].index.subs[0];
+ value->v.ipaddress[1] = tcp46_state_g.tcp4oids[i].index.subs[1];
+ value->v.ipaddress[2] = tcp46_state_g.tcp4oids[i].index.subs[2];
+ value->v.ipaddress[3] = tcp46_state_g.tcp4oids[i].index.subs[3];
+ break;
+
+ case LEAF_tcpConnLocalPort:
+ value->v.integer = tcp46_state_g.tcp4oids[i].index.subs[4];
+ break;
+
+ case LEAF_tcpConnRemAddress:
+ value->v.ipaddress[0] = tcp46_state_g.tcp4oids[i].index.subs[5];
+ value->v.ipaddress[1] = tcp46_state_g.tcp4oids[i].index.subs[6];
+ value->v.ipaddress[2] = tcp46_state_g.tcp4oids[i].index.subs[7];
+ value->v.ipaddress[3] = tcp46_state_g.tcp4oids[i].index.subs[8];
+ break;
+
+ case LEAF_tcpConnRemPort:
+ value->v.integer = tcp46_state_g.tcp4oids[i].index.subs[9];
+ break;
+ }
+ return (SNMP_ERR_NOERROR);
}
int
More information about the p4-projects
mailing list