SOURCES: net-snmp-snmpnetstat-getbulk.patch - for v1 use GetNext, for anyth...
glen
glen at pld-linux.org
Thu Jan 22 17:30:00 CET 2009
Author: glen Date: Thu Jan 22 16:30:00 2009 GMT
Module: SOURCES Tag: HEAD
---- Log message:
- for v1 use GetNext, for anything bigger use GetBulk
---- Files affected:
SOURCES:
net-snmp-snmpnetstat-getbulk.patch (1.1 -> 1.2)
---- Diffs:
================================================================
Index: SOURCES/net-snmp-snmpnetstat-getbulk.patch
diff -u SOURCES/net-snmp-snmpnetstat-getbulk.patch:1.1 SOURCES/net-snmp-snmpnetstat-getbulk.patch:1.2
--- SOURCES/net-snmp-snmpnetstat-getbulk.patch:1.1 Thu Jan 22 16:42:28 2009
+++ SOURCES/net-snmp-snmpnetstat-getbulk.patch Thu Jan 22 17:29:55 2009
@@ -1,56 +1,97 @@
--- net-snmp-5.4.2.1/apps/snmpnetstat/inet.c 2006-04-21 15:30:47.000000000 +0300
-+++ /home/glen/inet.c 2009-01-22 17:39:57.754383000 +0200
-@@ -110,8 +110,10 @@
- tcpprotopr(const char *name)
++++ net-snmp-5.4.2.1-dev/apps/snmpnetstat/inet.c 2009-01-22 18:26:23.264301468 +0200
+@@ -106,20 +106,65 @@
+ };
+ #define TCP_NSTATES 11
+
+-void
+-tcpprotopr(const char *name)
++static void
++tcpprotoprint_line(const char *name, netsnmp_variable_list *vp, int *first)
{
- netsnmp_variable_list *var, *vp;
+- netsnmp_variable_list *var, *vp;
- oid tcpConnState_oid[] = { 1,3,6,1,2,1,6,13,1,1 };
- size_t tcpConnState_len = OID_LENGTH( tcpConnState_oid );
-+ netsnmp_pdu *pdu, *response;
-+ oid tcpConnState_mib[] = { 1,3,6,1,2,1,6,13,1,1 };
-+ oid tcpConnState_oid[MAX_OID_LEN];
-+ size_t tcpConnState_len;
int state, width;
++ char *cp;
union {
struct in_addr addr;
-@@ -121,61 +123,126 @@
+ char data[4];
+ } tmpAddr;
+ oid localPort, remotePort;
struct in_addr localAddr, remoteAddr;
- char *cp;
- int first = 1;
-+ int running = 1;
-+ int status;
+- char *cp;
+
-+
-+ /*
-+ * setup initial object name
-+ */
-+ memmove(tcpConnState_oid, tcpConnState_mib, sizeof(tcpConnState_mib));
-+ tcpConnState_len = sizeof(tcpConnState_mib) / sizeof(oid);
++ state = *vp->val.integer;
++ if (!aflag && state == MIB_TCPCONNSTATE_LISTEN) {
++ return;
++ }
++
++ if (*first) {
++ printf("Active Internet (%s) Connections", name);
++ if (aflag)
++ printf(" (including servers)");
++ putchar('\n');
++ width = Aflag ? 18 : 22;
++ printf("%-5.5s %*.*s %*.*s %s\n",
++ "Proto", -width, width, "Local Address",
++ -width, width, "Remote Address", "(state)");
++ *first = 0;
++ }
++
++ /* Extract the local/remote information from the index values */
++ cp = tmpAddr.data;
++ cp[0] = vp->name[ 10 ] & 0xff;
++ cp[1] = vp->name[ 11 ] & 0xff;
++ cp[2] = vp->name[ 12 ] & 0xff;
++ cp[3] = vp->name[ 13 ] & 0xff;
++ localAddr.s_addr = tmpAddr.addr.s_addr;
++ localPort = ntohs(vp->name[ 14 ]);
++ cp = tmpAddr.data;
++ cp[0] = vp->name[ 15 ] & 0xff;
++ cp[1] = vp->name[ 16 ] & 0xff;
++ cp[2] = vp->name[ 17 ] & 0xff;
++ cp[3] = vp->name[ 18 ] & 0xff;
++ remoteAddr.s_addr = tmpAddr.addr.s_addr;
++ remotePort = ntohs(vp->name[ 19 ]);
++
++ printf("%-5.5s", name);
++ inetprint(&localAddr, localPort, name, 1);
++ inetprint(&remoteAddr, remotePort, name, 0);
++ if (state < 1 || state > TCP_NSTATES) {
++ printf("%d\n", state );
++ } else {
++ printf("%s\n", tcpstates[state]);
++ }
++}
++
++static void
++tcpprotopr_get(const char *name, oid *root, size_t root_len)
++{
++ netsnmp_variable_list *var, *vp;
+ int first = 1;
/*
- * Walking the tcpConnState column will provide all
+@@ -127,7 +172,7 @@
* the necessary information.
*/
-- var = NULL;
+ var = NULL;
- snmp_varlist_add_variable( &var, tcpConnState_oid, tcpConnState_len,
-- ASN_NULL, NULL, 0);
-- if (!var)
-- return;
-- if (netsnmp_query_walk( var, ss ) != SNMP_ERR_NOERROR)
-- return;
--
-- for (vp = var; vp ; vp=vp->next_variable) {
++ snmp_varlist_add_variable( &var, root, root_len,
+ ASN_NULL, NULL, 0);
+ if (!var)
+ return;
+@@ -135,47 +180,113 @@
+ return;
+
+ for (vp = var; vp ; vp=vp->next_variable) {
- state = *vp->val.integer;
- if (!aflag && state == MIB_TCPCONNSTATE_LISTEN)
- continue;
-+ while (running) {
-+ /*
-+ * create PDU for GETBULK request and add object name to request
-+ */
-+ pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
-+ pdu->non_repeaters = 0;
-+ pdu->max_repetitions = 1024; /* fill the packet */
-+ snmp_add_null_var(pdu, tcpConnState_oid, tcpConnState_len);
++ tcpprotoprint_line(name, vp, &first);
++ }
++ snmp_free_varbind( var );
++}
- if (first) {
- printf("Active Internet (%s) Connections", name);
@@ -62,6 +103,36 @@
- "Proto", -width, width, "Local Address",
- -width, width, "Remote Address", "(state)");
- first=0;
++void
++tcpprotopr_bulkget(const char *name, oid *root, size_t root_len)
++{
++ netsnmp_variable_list *vp;
++ netsnmp_pdu *pdu, *response;
++ oid tcpConnState_oid[MAX_OID_LEN];
++ size_t tcpConnState_len;
++ int first = 1;
++ int running = 1;
++ int status;
++
++ /*
++ * setup initial object name
++ */
++ memmove(tcpConnState_oid, root, sizeof(root) * root_len);
++ tcpConnState_len = root_len;
++
++ /*
++ * Walking the tcpConnState column will provide all
++ * the necessary information.
++ */
++ while (running) {
++ /*
++ * create PDU for GETBULK request and add object name to request
++ */
++ pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
++ pdu->non_repeaters = 0;
++ pdu->max_repetitions = 1024; /* fill the packet */
++ snmp_add_null_var(pdu, tcpConnState_oid, tcpConnState_len);
++
+ /*
+ * do the request
+ */
@@ -69,9 +140,8 @@
+ if (status == STAT_SUCCESS) {
+ if (response->errstat == SNMP_ERR_NOERROR) {
+ for (vp = response->variables; vp ; vp=vp->next_variable) {
-+
-+ if ((vp->name_length < sizeof(tcpConnState_mib) / sizeof(oid)) ||
-+ (memcmp(tcpConnState_mib, vp->name, sizeof(tcpConnState_mib)) != 0)) {
++ if ((vp->name_length < root_len) ||
++ (memcmp(root, vp->name, sizeof(oid) * root_len) != 0)) {
+ /*
+ * not part of this subtree
+ */
@@ -79,47 +149,7 @@
+ continue;
+ }
+
-+ state = *vp->val.integer;
-+ if (!aflag && state == MIB_TCPCONNSTATE_LISTEN) {
-+ continue;
-+ }
-+
-+ if (first) {
-+ printf("Active Internet (%s) Connections", name);
-+ if (aflag)
-+ printf(" (including servers)");
-+ putchar('\n');
-+ width = Aflag ? 18 : 22;
-+ printf("%-5.5s %*.*s %*.*s %s\n",
-+ "Proto", -width, width, "Local Address",
-+ -width, width, "Remote Address", "(state)");
-+ first = 0;
-+ }
-+
-+ /* Extract the local/remote information from the index values */
-+ cp = tmpAddr.data;
-+ cp[0] = vp->name[ 10 ] & 0xff;
-+ cp[1] = vp->name[ 11 ] & 0xff;
-+ cp[2] = vp->name[ 12 ] & 0xff;
-+ cp[3] = vp->name[ 13 ] & 0xff;
-+ localAddr.s_addr = tmpAddr.addr.s_addr;
-+ localPort = ntohs(vp->name[ 14 ]);
-+ cp = tmpAddr.data;
-+ cp[0] = vp->name[ 15 ] & 0xff;
-+ cp[1] = vp->name[ 16 ] & 0xff;
-+ cp[2] = vp->name[ 17 ] & 0xff;
-+ cp[3] = vp->name[ 18 ] & 0xff;
-+ remoteAddr.s_addr = tmpAddr.addr.s_addr;
-+ remotePort = ntohs(vp->name[ 19 ]);
-+
-+ printf("%-5.5s", name);
-+ inetprint(&localAddr, localPort, name, 1);
-+ inetprint(&remoteAddr, remotePort, name, 0);
-+ if (state < 1 || state > TCP_NSTATES) {
-+ printf("%d\n", state );
-+ } else {
-+ printf("%s\n", tcpstates[state]);
-+ }
++ tcpprotoprint_line(name, vp, &first);
+
+ if ((vp->type != SNMP_ENDOFMIBVIEW) &&
+ (vp->type != SNMP_NOSUCHOBJECT) &&
@@ -128,13 +158,9 @@
+ * Check if last variable, and if so, save for next request.
+ */
+ if (vp->next_variable == NULL) {
-+// printf("old: "); fprint_objid(stdout, tcpConnState_oid, tcpConnState_len);
-+
+ memmove(tcpConnState_oid, vp->name,
+ vp->name_length * sizeof(oid));
+ tcpConnState_len = vp->name_length;
-+
-+// printf("new: "); fprint_objid(stdout, tcpConnState_oid, tcpConnState_len);
+ }
+ } else {
+ /*
@@ -183,6 +209,26 @@
+ if (response) {
+ snmp_free_pdu(response);
+ }
++ }
++}
++
++void
++tcpprotopr(const char *name)
++{
++ oid tcpConnState_oid[] = { 1,3,6,1,2,1,6,13,1,1 };
++ size_t tcpConnState_len = OID_LENGTH( tcpConnState_oid );
++ int use_getbulk = 1;
++
++#ifndef NETSNMP_DISABLE_SNMPV1
++ if (ss->version == SNMP_VERSION_1) {
++ use_getbulk = 0;
++ }
++#endif
++
++ if (use_getbulk) {
++ tcpprotopr_bulkget(name, tcpConnState_oid, tcpConnState_len);
++ } else {
++ tcpprotopr_get(name, tcpConnState_oid, tcpConnState_len);
+ }
}
================================================================
---- CVS-web:
http://cvs.pld-linux.org/cgi-bin/cvsweb.cgi/SOURCES/net-snmp-snmpnetstat-getbulk.patch?r1=1.1&r2=1.2&f=u
More information about the pld-cvs-commit
mailing list