Hello,

I've been having trouble with community strings not beeing passed to traphandlers as it does with SNMPv1. For SNMPv1 trap it seems like the community string is added to the variable list when converting it to a v2 PDU (convert_v1_to_v2pdu()).

I know that the community string is present in the traps that snmptrapd recevies but it is not passed to the traphandler, so today i decided to hack snmptrapd_handlers.c so the community string will be added in the variable list. I've achieved the result i want but i would like some input about the changes from more experienced net-snmp coders.

cheers,




diff -uNr net-snmp-5.1.2.orig/apps/snmptrapd_handlers.c 
net-snmp-5.1.2-7.0/apps/snmptrapd_handlers.c
--- net-snmp-5.1.2.orig/apps/snmptrapd_handlers.c       2006-12-04 
18:07:58.000000000 +0100
+++ net-snmp-5.1.2-7.0/apps/snmptrapd_handlers.c        2006-12-04 
18:18:35.000000000 +0100
@@ -891,15 +891,17 @@
 {
     oid stdTrapOidRoot[] = { 1, 3, 6, 1, 6, 3, 1, 1, 5 };
     oid snmpTrapOid[]    = { 1, 3, 6, 1, 6, 3, 1, 1, 4, 1, 0 };
+    oid snmpTrapCom[]    = { 1, 3, 6, 1, 6, 3, 18, 1, 4, 0 };
     oid trapOid[MAX_OID_LEN+2] = {0};
     int trapOidLen;
-    netsnmp_variable_list *vars;
+    netsnmp_variable_list *vars, *var;
     netsnmp_trapd_handler *traph;
     netsnmp_transport *transport = (netsnmp_transport *) magic;
     int ret;
     extern netsnmp_trapd_handler *netsnmp_auth_global_traphandlers;
     extern netsnmp_trapd_handler *netsnmp_pre_global_traphandlers;
     extern netsnmp_trapd_handler *netsnmp_post_global_traphandlers;
+    size_t snmpTrapCom_len = OID_LENGTH(snmpTrapCom);
 
 
     switch (op) {
@@ -959,6 +961,19 @@
            }
             memcpy(trapOid, vars->val.objid, vars->val_len);
             trapOidLen = vars->val_len /sizeof(oid);
+
+            /*
+             * Hack for adding community in the varbind list for snnmpv2 traps
+             */
+            var = find_varbind_in_list( pdu->variables, snmpTrapCom, 
snmpTrapCom_len );
+            if(!var && pdu->community) {
+                if( !snmp_varlist_add_variable( &(pdu->variables),
+                                                snmpTrapCom, snmpTrapCom_len,
+                                                ASN_OCTET_STR,
+                                                pdu->community,
+                                                pdu->community_len))
+                                                    snmp_log(LOG_WARNING, 
"Failed to append snmpTrapCommunity varbind\n");
+            }
             break;
 
         default:
diff -uNr net-snmp-5.1.2.orig/apps/snmptrapd_handlers.h 
net-snmp-5.1.2-7.0/apps/snmptrapd_handlers.h
--- net-snmp-5.1.2.orig/apps/snmptrapd_handlers.h       2006-12-04 
18:07:58.000000000 +0100
+++ net-snmp-5.1.2-7.0/apps/snmptrapd_handlers.h        2006-12-04 
18:07:17.000000000 +0100
@@ -55,4 +55,5 @@
 int snmp_input(int op, netsnmp_session *session,
            int reqid, netsnmp_pdu *pdu, void *magic);
 
+netsnmp_variable_list* find_varbind_in_list( netsnmp_variable_list *vblist, 
oid *name, size_t len); // might not be the best way to place it (prevents an 
compile warning)
 #endif                          /* SNMPTRAPD_HANDLERS_H */
diff -uNr net-snmp-5.1.2.orig/apps/snmptrapd_handlers.loT 
net-snmp-5.1.2-7.0/apps/snmptrapd_handlers.loT
--- net-snmp-5.1.2.orig/apps/snmptrapd_handlers.loT     1970-01-01 
01:00:00.000000000 +0100
+++ net-snmp-5.1.2-7.0/apps/snmptrapd_handlers.loT      2006-12-04 
18:17:41.000000000 +0100
@@ -0,0 +1,7 @@
+# snmptrapd_handlers.lo - a libtool object file
+# Generated by ltmain.sh - GNU libtool 1.5.6 (1.1220.2.95 2004/04/11 05:50:42) 
Debian: 224 $
+#
+# Please DO NOT delete this file!
+# It is necessary for linking the library.
+
+# Name of the PIC object.
begin:vcard
fn;quoted-printable:Mikael G=C3=B6ransson
n;quoted-printable:G=C3=B6ransson;Mikael
email;internet:[EMAIL PROTECTED]
tel;work:+46 13 20 00 48
x-mozilla-html:FALSE
version:2.1
end:vcard

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to