SNMPv2 trap and community strings

This is a discussion on SNMPv2 trap and community strings within the SNMP Coders forums, part of the Networking and Network Related category; This is a multi-part message in MIME format. --------------010807090209030000080806 Content-Type: text/plain; charset=ISO-8859-1; format=flowed ...


Go Back   Usenet Forums > Networking and Network Related > SNMP Coders

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-04-2006
Mikael Göransson
 
Posts: n/a
Default SNMPv2 trap and community strings

This is a multi-part message in MIME format.
--------------010807090209030000080806
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

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,





--------------010807090209030000080806
Content-Type: text/plain;
name="net-snmp-5.1.2-snmpv2-community-hack.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="net-snmp-5.1.2-snmpv2-community-hack.patch"

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.

--------------010807090209030000080806
Content-Type: text/x-vcard; charset=utf-8;
name="mikael.goransson.vcf"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="mikael.goransson.vcf"

begin:vcard
fn;quoted-printable:Mikael G=C3=B6ransson
n;quoted-printable:G=C3=B6ransson;Mikael
email;internet:mikael.goransson@netadmin.se
tel;work:+46 13 20 00 48
x-mozilla-html:FALSE
version:2.1
end:vcard


--------------010807090209030000080806
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

-------------------------------------------------------------------------
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?p...rge&CID=DEVDEV
--------------010807090209030000080806
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/...et-snmp-coders

--------------010807090209030000080806--

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:06 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0