2 * Routines for SNMP (simple network management protocol)
3 * Copyright (C) 1998 Didier Jorand
5 * See RFC 1157 for SNMPv1.
7 * See RFCs 1901, 1905, and 1906 for SNMPv2c.
9 * See RFCs 1905, 1906, 1909, and 1910 for SNMPv2u [historic].
11 * See RFCs 2570-2576 for SNMPv3
13 * $Id: packet-snmp.c,v 1.126 2004/01/23 10:25:08 guy Exp $
15 * Ethereal - Network traffic analyzer
16 * By Gerald Combs <gerald@ethereal.com>
17 * Copyright 1998 Gerald Combs
21 * GXSNMP -- An snmp mangament application
22 * Copyright (C) 1998 Gregory McLean & Jochen Friedrich
23 * Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version 2
28 * of the License, or (at your option) any later version.
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU General Public License for more details.
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
50 #include <epan/packet.h>
51 #include <epan/strutil.h>
52 #include <epan/conversation.h>
55 #include "packet-ipx.h"
56 #include "packet-hpext.h"
57 #include "packet-frame.h"
62 # include <net-snmp/net-snmp-config.h>
63 # include <net-snmp/mib_api.h>
64 # include <net-snmp/library/default_store.h>
65 # include <net-snmp/config_api.h>
66 #else /* HAVE_NET_SNMP */
67 # include <ucd-snmp/ucd-snmp-config.h>
68 # include <ucd-snmp/asn1.h>
69 # include <ucd-snmp/snmp_api.h>
70 # include <ucd-snmp/snmp_impl.h>
71 # include <ucd-snmp/mib.h>
72 # include <ucd-snmp/default_store.h>
73 # include <ucd-snmp/read_config.h>
74 # include <ucd-snmp/tools.h>
75 #endif /* HAVE_NET_SNMP */
77 #ifndef NETSNMP_DS_LIBRARY_ID
78 # define NETSNMP_DS_LIBRARY_ID DS_LIBRARY_ID
79 # define NETSNMP_DS_LIB_NO_TOKEN_WARNINGS DS_LIB_NO_TOKEN_WARNINGS
80 # define NETSNMP_DS_LIB_PRINT_SUFFIX_ONLY DS_LIB_PRINT_SUFFIX_ONLY
81 # define netsnmp_ds_set_boolean ds_set_boolean
82 # define netsnmp_ds_set_int ds_set_int
86 # include <epan/filesystem.h>
90 * Define values "sprint_realloc_value()" expects.
92 # define VALTYPE_INTEGER ASN_INTEGER
93 # define VALTYPE_COUNTER ASN_COUNTER
94 # define VALTYPE_GAUGE ASN_GAUGE
95 # define VALTYPE_TIMETICKS ASN_TIMETICKS
96 # define VALTYPE_STRING ASN_OCTET_STR
97 # define VALTYPE_IPADDR ASN_IPADDRESS
98 # define VALTYPE_OPAQUE ASN_OPAQUE
99 # define VALTYPE_NSAP ASN_NSAP
100 # define VALTYPE_OBJECTID ASN_OBJECT_ID
101 # define VALTYPE_BITSTR ASN_BIT_STR
102 # define VALTYPE_COUNTER64 ASN_COUNTER64
104 #endif /* HAVE_SOME_SNMP */
108 #include "packet-snmp.h"
109 #include "format-oid.h"
111 /* Take a pointer that may be null and return a pointer that's not null
112 by turning null pointers into pointers to the above null string,
113 and, if the argument pointer wasn't null, make sure we handle
114 non-printable characters in the string by escaping them. */
115 #define SAFE_STRING(s, l) (((s) != NULL) ? format_text((s), (l)) : "")
117 static int proto_snmp = -1;
119 /* Default MIB modules to load */
120 #define DEF_MIB_MODULES "IP-MIB:IF-MIB:TCP-MIB:UDP-MIB:SNMPv2-MIB:RFC1213-MIB:UCD-SNMP-MIB"
122 static gchar *mib_modules = DEF_MIB_MODULES;
123 static gboolean display_oid = TRUE;
125 static gint ett_snmp = -1;
126 static gint ett_parameters = -1;
127 static gint ett_parameters_qos = -1;
128 static gint ett_global = -1;
129 static gint ett_flags = -1;
130 static gint ett_secur = -1;
132 static int hf_snmp_version = -1;
133 static int hf_snmp_community = -1;
134 static int hf_snmp_request_id = -1;
135 static int hf_snmp_pdutype = -1;
136 static int hf_snmp_agent = -1;
137 static int hf_snmp_enterprise = -1;
138 static int hf_snmp_error_status = -1;
139 static int hf_snmp_oid = -1;
140 static int hf_snmp_traptype = -1;
141 static int hf_snmp_spectraptype = -1;
142 static int hf_snmp_timestamp = -1;
143 static int hf_snmpv3_flags = -1;
144 static int hf_snmpv3_flags_auth = -1;
145 static int hf_snmpv3_flags_crypt = -1;
146 static int hf_snmpv3_flags_report = -1;
148 static int proto_smux = -1;
150 static gint ett_smux = -1;
152 static int hf_smux_version = -1;
153 static int hf_smux_pdutype = -1;
155 /* desegmentation of SNMP-over-TCP */
156 static gboolean snmp_desegment = TRUE;
158 static dissector_handle_t snmp_handle;
159 static dissector_handle_t data_handle;
162 #define TH_CRYPT 0x02
163 #define TH_REPORT 0x04
165 #define UDP_PORT_SNMP 161
166 #define UDP_PORT_SNMP_TRAP 162
167 #define TCP_PORT_SNMP 161
168 #define TCP_PORT_SNMP_TRAP 162
169 #define TCP_PORT_SMUX 199
171 /* Protocol version numbers */
172 #define SNMP_VERSION_1 0
173 #define SNMP_VERSION_2c 1
174 #define SNMP_VERSION_2u 2
175 #define SNMP_VERSION_3 3
177 static const value_string versions[] = {
178 { SNMP_VERSION_1, "1" },
179 { SNMP_VERSION_2c, "2C" },
180 { SNMP_VERSION_2u, "2U" },
181 { SNMP_VERSION_3, "3" },
185 /* defined in net-SNMP; include/net-snmp/library/snmp.h */
188 #undef SNMP_MSG_GETNEXT
189 #undef SNMP_MSG_RESPONSE
191 #undef SNMP_MSG_GETBULK
192 #undef SNMP_MSG_INFORM
193 #undef SNMP_MSG_TRAP2
194 #undef SNMP_MSG_REPORT
195 #undef SNMP_NOSUCHOBJECT
196 #undef SNMP_NOSUCHINSTANCE
197 #undef SNMP_ENDOFMIBVIEW
200 #define SNMP_MSG_GET 0
201 #define SNMP_MSG_GETNEXT 1
202 #define SNMP_MSG_RESPONSE 2
203 #define SNMP_MSG_SET 3
204 #define SNMP_MSG_TRAP 4
206 #define SNMP_MSG_GETBULK 5
207 #define SNMP_MSG_INFORM 6
208 #define SNMP_MSG_TRAP2 7
209 #define SNMP_MSG_REPORT 8
211 static const value_string pdu_types[] = {
212 { SNMP_MSG_GET, "GET" },
213 { SNMP_MSG_GETNEXT, "GET-NEXT" },
214 { SNMP_MSG_SET, "SET" },
215 { SNMP_MSG_RESPONSE, "RESPONSE" },
216 { SNMP_MSG_TRAP, "TRAP-V1" },
217 { SNMP_MSG_GETBULK, "GETBULK" },
218 { SNMP_MSG_INFORM, "INFORM" },
219 { SNMP_MSG_TRAP2, "TRAP-V2" },
220 { SNMP_MSG_REPORT, "REPORT" },
225 #define SMUX_MSG_OPEN 0
226 #define SMUX_MSG_CLOSE 1
227 #define SMUX_MSG_RREQ 2
228 #define SMUX_MSG_RRSP 3
229 #define SMUX_MSG_SOUT 4
231 static const value_string smux_types[] = {
232 { SMUX_MSG_OPEN, "Open" },
233 { SMUX_MSG_CLOSE, "Close" },
234 { SMUX_MSG_RREQ, "Registration Request" },
235 { SMUX_MSG_RRSP, "Registration Response" },
236 { SMUX_MSG_SOUT, "Commit Or Rollback" },
240 /* SMUX Closing causes */
241 #define SMUX_CLOSE_DOWN 0
242 #define SMUX_CLOSE_VERSION 1
243 #define SMUX_CLOSE_PACKET 2
244 #define SMUX_CLOSE_PROTOCOL 3
245 #define SMUX_CLOSE_INTERNAL 4
246 #define SMUX_CLOSE_NOAUTH 5
248 static const value_string smux_close[] = {
249 { SMUX_CLOSE_DOWN, "Going down" },
250 { SMUX_CLOSE_VERSION, "Unsupported Version" },
251 { SMUX_CLOSE_PACKET, "Packet Format Error" },
252 { SMUX_CLOSE_PROTOCOL, "Protocol Error" },
253 { SMUX_CLOSE_INTERNAL, "Internal Error" },
254 { SMUX_CLOSE_NOAUTH, "Unauthorized" },
258 /* SMUX Request codes */
259 #define SMUX_RREQ_DELETE 0
260 #define SMUX_RREQ_READONLY 1
261 #define SMUX_RREQ_READWRITE 2
263 static const value_string smux_rreq[] = {
264 { SMUX_RREQ_DELETE, "Delete" },
265 { SMUX_RREQ_READONLY, "Read Only" },
266 { SMUX_RREQ_READWRITE, "Read Write" },
270 static const value_string smux_prio[] = {
275 /* SMUX SOut codes */
276 #define SMUX_SOUT_COMMIT 0
277 #define SMUX_SOUT_ROLLBACK 1
279 static const value_string smux_sout[] = {
280 { SMUX_SOUT_COMMIT, "Commit" },
281 { SMUX_SOUT_ROLLBACK, "Rollback" },
285 /* Error status values */
286 #ifndef SNMP_ERR_NOERROR
287 #define SNMP_ERR_NOERROR 0
289 #ifndef SNMP_ERR_TOOBIG
290 #define SNMP_ERR_TOOBIG 1
292 #ifndef SNMP_ERR_NOSUCHNAME
293 #define SNMP_ERR_NOSUCHNAME 2
295 #ifndef SNMP_ERR_BADVALUE
296 #define SNMP_ERR_BADVALUE 3
298 #ifndef SNMP_ERR_READONLY
299 #define SNMP_ERR_READONLY 4
301 #ifndef SNMP_ERR_GENERR
302 #define SNMP_ERR_GENERR 5
304 #ifndef SNMP_ERR_NOACCESS
305 #define SNMP_ERR_NOACCESS 6
307 #ifndef SNMP_ERR_WRONGTYPE
308 #define SNMP_ERR_WRONGTYPE 7
310 #ifndef SNMP_ERR_WRONGLENGTH
311 #define SNMP_ERR_WRONGLENGTH 8
313 #ifndef SNMP_ERR_WRONGENCODING
314 #define SNMP_ERR_WRONGENCODING 9
316 #ifndef SNMP_ERR_WRONGVALUE
317 #define SNMP_ERR_WRONGVALUE 10
319 #ifndef SNMP_ERR_NOCREATION
320 #define SNMP_ERR_NOCREATION 11
322 #ifndef SNMP_ERR_INCONSISTENTVALUE
323 #define SNMP_ERR_INCONSISTENTVALUE 12
325 #ifndef SNMP_ERR_RESOURCEUNAVAILABLE
326 #define SNMP_ERR_RESOURCEUNAVAILABLE 13
328 #ifndef SNMP_ERR_COMMITFAILED
329 #define SNMP_ERR_COMMITFAILED 14
331 #ifndef SNMP_ERR_UNDOFAILED
332 #define SNMP_ERR_UNDOFAILED 15
334 #ifndef SNMP_ERR_AUTHORIZATIONERROR
335 #define SNMP_ERR_AUTHORIZATIONERROR 16
337 #ifndef SNMP_ERR_NOTWRITABLE
338 #define SNMP_ERR_NOTWRITABLE 17
340 #ifndef SNMP_ERR_INCONSISTENTNAME
341 #define SNMP_ERR_INCONSISTENTNAME 18
344 static const value_string error_statuses[] = {
345 { SNMP_ERR_NOERROR, "NO ERROR" },
346 { SNMP_ERR_TOOBIG, "TOOBIG" },
347 { SNMP_ERR_NOSUCHNAME, "NO SUCH NAME" },
348 { SNMP_ERR_BADVALUE, "BAD VALUE" },
349 { SNMP_ERR_READONLY, "READ ONLY" },
350 { SNMP_ERR_GENERR, "GENERIC ERROR" },
351 { SNMP_ERR_NOACCESS, "NO ACCESS" },
352 { SNMP_ERR_WRONGTYPE, "WRONG TYPE" },
353 { SNMP_ERR_WRONGLENGTH, "WRONG LENGTH" },
354 { SNMP_ERR_WRONGENCODING, "WRONG ENCODING" },
355 { SNMP_ERR_WRONGVALUE, "WRONG VALUE" },
356 { SNMP_ERR_NOCREATION, "NO CREATION" },
357 { SNMP_ERR_INCONSISTENTVALUE, "INCONSISTENT VALUE" },
358 { SNMP_ERR_RESOURCEUNAVAILABLE, "RESOURCE UNAVAILABLE" },
359 { SNMP_ERR_COMMITFAILED, "COMMIT FAILED" },
360 { SNMP_ERR_UNDOFAILED, "UNDO FAILED" },
361 { SNMP_ERR_AUTHORIZATIONERROR, "AUTHORIZATION ERROR" },
362 { SNMP_ERR_NOTWRITABLE, "NOT WRITABLE" },
363 { SNMP_ERR_INCONSISTENTNAME, "INCONSISTENT NAME" },
367 /* General SNMP V1 Traps */
369 #ifndef SNMP_TRAP_COLDSTART
370 #define SNMP_TRAP_COLDSTART 0
372 #ifndef SNMP_TRAP_WARMSTART
373 #define SNMP_TRAP_WARMSTART 1
375 #ifndef SNMP_TRAP_LINKDOWN
376 #define SNMP_TRAP_LINKDOWN 2
378 #ifndef SNMP_TRAP_LINKUP
379 #define SNMP_TRAP_LINKUP 3
381 #ifndef SNMP_TRAP_AUTHFAIL
382 #define SNMP_TRAP_AUTHFAIL 4
384 #ifndef SNMP_TRAP_EGPNEIGHBORLOSS
385 #define SNMP_TRAP_EGPNEIGHBORLOSS 5
387 #ifndef SNMP_TRAP_ENTERPRISESPECIFIC
388 #define SNMP_TRAP_ENTERPRISESPECIFIC 6
391 static const value_string trap_types[] = {
392 { SNMP_TRAP_COLDSTART, "COLD START" },
393 { SNMP_TRAP_WARMSTART, "WARM START" },
394 { SNMP_TRAP_LINKDOWN, "LINK DOWN" },
395 { SNMP_TRAP_LINKUP, "LINK UP" },
396 { SNMP_TRAP_AUTHFAIL, "AUTHENTICATION FAILED" },
397 { SNMP_TRAP_EGPNEIGHBORLOSS, "EGP NEIGHBORLOSS" },
398 { SNMP_TRAP_ENTERPRISESPECIFIC, "ENTERPRISE SPECIFIC" },
402 /* Security Models */
404 #define SNMP_SEC_ANY 0
405 #define SNMP_SEC_V1 1
406 #define SNMP_SEC_V2C 2
407 #define SNMP_SEC_USM 3
409 static const value_string sec_models[] = {
410 { SNMP_SEC_ANY, "Any" },
411 { SNMP_SEC_V1, "V1" },
412 { SNMP_SEC_V2C, "V2C" },
413 { SNMP_SEC_USM, "USM" },
419 #define SNMP_IPA 0 /* IP Address */
420 #define SNMP_CNT 1 /* Counter (Counter32) */
421 #define SNMP_GGE 2 /* Gauge (Gauge32) */
422 #define SNMP_TIT 3 /* TimeTicks */
423 #define SNMP_OPQ 4 /* Opaque */
424 #define SNMP_NSP 5 /* NsapAddress */
425 #define SNMP_C64 6 /* Counter64 */
426 #define SNMP_U32 7 /* Uinteger32 */
435 #define SNMP_INTEGER 1 /* l */
436 #define SNMP_OCTETSTR 2 /* c */
437 #define SNMP_DISPLAYSTR 2 /* c */
438 #define SNMP_OBJECTID 3 /* ul */
439 #define SNMP_IPADDR 4 /* uc */
440 #define SNMP_COUNTER 5 /* ul */
441 #define SNMP_GAUGE 6 /* ul */
442 #define SNMP_TIMETICKS 7 /* ul */
443 #define SNMP_OPAQUE 8 /* c */
445 /* additional SNMPv2 Types */
447 #define SNMP_UINTEGER 5 /* ul */
448 #define SNMP_BITSTR 9 /* uc */
449 #define SNMP_NSAP 10 /* uc */
450 #define SNMP_COUNTER64 11 /* ul */
451 #define SNMP_NOSUCHOBJECT 12
452 #define SNMP_NOSUCHINSTANCE 13
453 #define SNMP_ENDOFMIBVIEW 14
455 typedef struct _SNMP_CNV SNMP_CNV;
465 static SNMP_CNV SnmpCnv [] =
467 {ASN1_UNI, ASN1_NUL, SNMP_NULL, "NULL"},
468 {ASN1_UNI, ASN1_INT, SNMP_INTEGER, "INTEGER"},
469 {ASN1_UNI, ASN1_OTS, SNMP_OCTETSTR, "OCTET STRING"},
470 {ASN1_UNI, ASN1_OJI, SNMP_OBJECTID, "OBJECTID"},
471 {ASN1_APL, SNMP_IPA, SNMP_IPADDR, "IPADDR"},
472 {ASN1_APL, SNMP_CNT, SNMP_COUNTER, "COUNTER"}, /* Counter32 */
473 {ASN1_APL, SNMP_GGE, SNMP_GAUGE, "GAUGE"}, /* Gauge32 == Unsigned32 */
474 {ASN1_APL, SNMP_TIT, SNMP_TIMETICKS, "TIMETICKS"},
475 {ASN1_APL, SNMP_OPQ, SNMP_OPAQUE, "OPAQUE"},
477 /* SNMPv2 data types and errors */
479 {ASN1_UNI, ASN1_BTS, SNMP_BITSTR, "BITSTR"},
480 {ASN1_APL, SNMP_C64, SNMP_COUNTER64, "COUNTER64"},
481 {ASN1_CTX, SERR_NSO, SNMP_NOSUCHOBJECT, "NOSUCHOBJECT"},
482 {ASN1_CTX, SERR_NSI, SNMP_NOSUCHINSTANCE, "NOSUCHINSTANCE"},
483 {ASN1_CTX, SERR_EOM, SNMP_ENDOFMIBVIEW, "ENDOFMIBVIEW"},
488 * NAME: g_snmp_tag_cls2syntax
489 * SYNOPSIS: gboolean g_snmp_tag_cls2syntax
495 * DESCRIPTION: Converts ASN1 tag and class to Syntax tag and name.
496 * See SnmpCnv for conversion.
497 * RETURNS: name on success, NULL on failure
501 snmp_tag_cls2syntax ( guint tag, guint cls, gushort *syntax)
506 while (cnv->syntax != -1)
508 if (cnv->tag == tag && cnv->class == cls)
510 *syntax = cnv->syntax;
519 dissect_snmp_parse_error(tvbuff_t *tvb, int offset, packet_info *pinfo,
520 proto_tree *tree, const char *field_name, int ret)
524 errstr = asn1_err_to_str(ret);
526 if (check_col(pinfo->cinfo, COL_INFO)) {
527 col_add_fstr(pinfo->cinfo, COL_INFO,
528 "ERROR: Couldn't parse %s: %s", field_name, errstr);
531 proto_tree_add_text(tree, tvb, offset, 0,
532 "ERROR: Couldn't parse %s: %s", field_name, errstr);
533 call_dissector(data_handle,
534 tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
539 dissect_snmp_error(tvbuff_t *tvb, int offset, packet_info *pinfo,
540 proto_tree *tree, const char *message)
542 if (check_col(pinfo->cinfo, COL_INFO))
543 col_add_str(pinfo->cinfo, COL_INFO, message);
546 proto_tree_add_text(tree, tvb, offset, 0, "%s", message);
547 call_dissector(data_handle,
548 tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
553 format_oid(subid_t *oid, guint oid_length)
560 #ifdef HAVE_SOME_SNMP
562 size_t oid_string_len;
566 result_len = oid_length * 22;
568 #ifdef HAVE_SOME_SNMP
570 * Get the decoded form of the OID, and add its length to the
571 * length of the result string.
573 * XXX - check for "sprint_realloc_objid()" failure.
575 oid_string_len = 256;
576 oid_string = g_malloc(oid_string_len);
579 sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, 1,
581 result_len += strlen(oid_string) + 3;
584 result = g_malloc(result_len + 1);
586 len = sprintf(buf, "%lu", (unsigned long)oid[0]);
588 for (i = 1; i < oid_length;i++) {
589 len = sprintf(buf, ".%lu", (unsigned long)oid[i]);
593 #ifdef HAVE_SOME_SNMP
595 * Append the decoded form of the OID.
597 sprintf(buf, " (%s)", oid_string);
604 /* returns the decoded (can be NULL) and non_decoded OID strings,
605 returned pointers shall be freed by the caller */
607 new_format_oid(subid_t *oid, guint oid_length,
608 gchar **non_decoded, gchar **decoded)
614 #ifdef HAVE_SOME_SNMP
616 size_t oid_string_len;
620 * Get the decoded form of the OID, and add its length to the
621 * length of the result string.
624 oid_string_len = 256;
625 oid_string = g_malloc(oid_string_len);
628 sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, 1,
630 *decoded = oid_string;
635 *non_decoded = g_malloc(oid_length * 22 + 1);
637 len = sprintf(buf, "%lu", (unsigned long)oid[0]);
639 for (i = 1; i < oid_length; i++) {
640 len = sprintf(buf, ".%lu", (unsigned long)oid[i]);
645 #ifdef HAVE_SOME_SNMP
647 check_var_length(guint vb_length, guint required_length)
650 static const char badlen_fmt[] = "Length is %u, should be %u";
652 if (vb_length != required_length) {
653 /* Enough room for the largest "Length is XXX,
654 should be XXX" message - 10 digits for each
656 buf = g_malloc(sizeof badlen_fmt + 10 + 10);
657 sprintf(buf, badlen_fmt, vb_length, required_length);
660 return NULL; /* length is OK */
664 format_var(struct variable_list *variable, subid_t *variable_oid,
665 guint variable_oid_length, gushort vb_type, guint val_len)
674 /* Length has to be 4 bytes. */
675 buf = check_var_length(val_len, 4);
677 return buf; /* it's not 4 bytes */
681 /* Length has to be 8 bytes. */
682 buf = check_var_length(val_len, 8);
684 return buf; /* it's not 8 bytes */
691 variable->next_variable = NULL;
692 variable->name = variable_oid;
693 variable->name_length = variable_oid_length;
697 variable->type = VALTYPE_INTEGER;
701 variable->type = VALTYPE_COUNTER;
705 variable->type = VALTYPE_GAUGE;
709 variable->type = VALTYPE_TIMETICKS;
713 variable->type = VALTYPE_STRING;
717 variable->type = VALTYPE_IPADDR;
721 variable->type = VALTYPE_OPAQUE;
725 variable->type = VALTYPE_NSAP;
729 variable->type = VALTYPE_OBJECTID;
733 variable->type = VALTYPE_BITSTR;
737 variable->type = VALTYPE_COUNTER64;
740 variable->val_len = val_len;
743 * XXX - check for "sprint_realloc_objid()" failure.
746 buf = g_malloc(buf_len);
749 sprint_realloc_value(&buf, &buf_len, &out_len, 1, variable_oid,
750 variable_oid_length, variable);
756 snmp_variable_decode(proto_tree *snmp_tree,
757 subid_t *variable_oid
758 #ifndef HAVE_SOME_SNMP
762 guint variable_oid_length
763 #ifndef HAVE_SOME_SNMP
767 ASN1_SCK *asn1, int offset, guint *lengthp)
778 gint32 vb_integer_value;
779 guint32 vb_uinteger_value;
781 guint8 *vb_octet_string;
786 gchar *vb_display_string;
788 #ifdef HAVE_SOME_SNMP
789 struct variable_list variable;
791 #else /* HAVE_SOME_SNMP */
795 #endif /* HAVE_SOME_SNMP */
797 /* parse the type of the object */
798 start = asn1->offset;
799 ret = asn1_header_decode (asn1, &cls, &con, &tag, &def, &vb_length);
800 if (ret != ASN1_ERR_NOERROR)
803 return ASN1_ERR_LENGTH_NOT_DEFINITE;
805 /* Convert the class, constructed flag, and tag to a type. */
806 vb_type_name = snmp_tag_cls2syntax(tag, cls, &vb_type);
807 if (vb_type_name == NULL) {
810 * Dissect the value as an opaque string of octets.
812 vb_type_name = "unsupported type";
813 vb_type = SNMP_OPAQUE;
816 /* parse the value */
820 ret = asn1_int32_value_decode(asn1, vb_length,
822 if (ret != ASN1_ERR_NOERROR)
824 length = asn1->offset - start;
826 #ifdef HAVE_SOME_SNMP
827 value = vb_integer_value;
828 variable.val.integer = &value;
829 vb_display_string = format_var(&variable,
830 variable_oid, variable_oid_length, vb_type,
832 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
834 "Value: %s", vb_display_string);
835 g_free(vb_display_string);
836 #else /* HAVE_SOME_SNMP */
837 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
839 "Value: %s: %d (%#x)", vb_type_name,
840 vb_integer_value, vb_integer_value);
841 #endif /* HAVE_SOME_SNMP */
848 ret = asn1_uint32_value_decode(asn1, vb_length,
850 if (ret != ASN1_ERR_NOERROR)
852 length = asn1->offset - start;
854 #ifdef HAVE_SOME_SNMP
855 value = vb_uinteger_value;
856 variable.val.integer = &value;
857 vb_display_string = format_var(&variable,
858 variable_oid, variable_oid_length, vb_type,
860 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
862 "Value: %s", vb_display_string);
863 g_free(vb_display_string);
864 #else /* HAVE_SOME_SNMP */
865 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
867 "Value: %s: %u (%#x)", vb_type_name,
868 vb_uinteger_value, vb_uinteger_value);
869 #endif /* HAVE_SOME_SNMP */
879 ret = asn1_string_value_decode (asn1, vb_length,
881 if (ret != ASN1_ERR_NOERROR)
883 length = asn1->offset - start;
885 #ifdef HAVE_SOME_SNMP
886 variable.val.string = vb_octet_string;
887 vb_display_string = format_var(&variable,
888 variable_oid, variable_oid_length, vb_type,
890 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
892 "Value: %s", vb_display_string);
893 g_free(vb_display_string);
894 #else /* HAVE_SOME_SNMP */
896 * If some characters are not printable, display
897 * the string as bytes.
899 for (i = 0; i < vb_length; i++) {
900 if (!(isprint(vb_octet_string[i])
901 || isspace(vb_octet_string[i])))
906 * We stopped, due to a non-printable
907 * character, before we got to the end
910 vb_display_string = g_malloc(4*vb_length);
911 buf = &vb_display_string[0];
912 len = sprintf(buf, "%03u", vb_octet_string[0]);
914 for (i = 1; i < vb_length; i++) {
915 len = sprintf(buf, ".%03u",
919 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
921 "Value: %s: %s", vb_type_name,
923 g_free(vb_display_string);
925 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
927 "Value: %s: %s", vb_type_name,
928 SAFE_STRING(vb_octet_string, vb_length));
930 #endif /* HAVE_SOME_SNMP */
932 g_free(vb_octet_string);
936 ret = asn1_null_decode (asn1, vb_length);
937 if (ret != ASN1_ERR_NOERROR)
939 length = asn1->offset - start;
941 proto_tree_add_text(snmp_tree, asn1->tvb, offset, length,
942 "Value: %s", vb_type_name);
947 ret = asn1_oid_value_decode (asn1, vb_length, &vb_oid,
949 if (ret != ASN1_ERR_NOERROR)
951 length = asn1->offset - start;
953 #ifdef HAVE_SOME_SNMP
954 variable.val.objid = vb_oid;
955 vb_display_string = format_var(&variable,
956 variable_oid, variable_oid_length, vb_type,
957 vb_oid_length * sizeof (subid_t));
958 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
960 "Value: %s", vb_display_string);
961 g_free(vb_display_string);
962 #else /* HAVE_SOME_SNMP */
963 vb_display_string = format_oid(vb_oid, vb_oid_length);
964 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
966 "Value: %s: %s", vb_type_name, vb_display_string);
967 g_free(vb_display_string);
968 #endif /* HAVE_SOME_SNMP */
973 case SNMP_NOSUCHOBJECT:
974 length = asn1->offset - start;
976 proto_tree_add_text(snmp_tree, asn1->tvb, offset, length,
977 "Value: %s: no such object", vb_type_name);
981 case SNMP_NOSUCHINSTANCE:
982 length = asn1->offset - start;
984 proto_tree_add_text(snmp_tree, asn1->tvb, offset, length,
985 "Value: %s: no such instance", vb_type_name);
989 case SNMP_ENDOFMIBVIEW:
990 length = asn1->offset - start;
992 proto_tree_add_text(snmp_tree, asn1->tvb, offset, length,
993 "Value: %s: end of mib view", vb_type_name);
998 g_assert_not_reached();
999 return ASN1_ERR_WRONG_TYPE;
1002 return ASN1_ERR_NOERROR;
1006 dissect_common_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
1007 proto_tree *tree, ASN1_SCK asn1, guint pdu_type, int start)
1011 guint sequence_length;
1015 guint32 error_status;
1017 guint32 error_index;
1019 char *pdu_type_string;
1021 subid_t *enterprise;
1022 guint enterprise_length;
1024 guint32 agent_ipaddr;
1026 guint8 *agent_address;
1027 guint agent_address_length;
1031 guint32 specific_type;
1034 guint timestamp_length;
1038 guint variable_bindings_length;
1041 guint variable_length;
1042 subid_t *variable_oid;
1043 guint variable_oid_length;
1046 guint cls, con, tag;
1048 pdu_type_string = val_to_str(pdu_type, pdu_types,
1049 "Unknown PDU type %#x");
1050 if (check_col(pinfo->cinfo, COL_INFO))
1051 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
1052 length = asn1.offset - start;
1054 proto_tree_add_uint(tree, hf_snmp_pdutype, tvb, offset, length,
1059 /* get the fields in the PDU preceeding the variable-bindings sequence */
1063 case SNMP_MSG_GETNEXT:
1064 case SNMP_MSG_RESPONSE:
1066 case SNMP_MSG_GETBULK:
1067 case SNMP_MSG_INFORM:
1068 case SNMP_MSG_TRAP2:
1069 case SNMP_MSG_REPORT:
1071 ret = asn1_uint32_decode (&asn1, &request_id, &length);
1072 if (ret != ASN1_ERR_NOERROR) {
1073 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1078 proto_tree_add_uint(tree, hf_snmp_request_id,
1079 tvb, offset, length, request_id);
1083 /* error status, or getbulk non-repeaters */
1084 ret = asn1_uint32_decode (&asn1, &error_status, &length);
1085 if (ret != ASN1_ERR_NOERROR) {
1086 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1087 (pdu_type == SNMP_MSG_GETBULK) ? "non-repeaters"
1093 if (pdu_type == SNMP_MSG_GETBULK) {
1094 proto_tree_add_text(tree, tvb, offset,
1095 length, "Non-repeaters: %u", error_status);
1097 proto_tree_add_uint(tree,
1098 hf_snmp_error_status,
1100 length, error_status);
1105 /* error index, or getbulk max-repetitions */
1106 ret = asn1_uint32_decode (&asn1, &error_index, &length);
1107 if (ret != ASN1_ERR_NOERROR) {
1108 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1109 (pdu_type == SNMP_MSG_GETBULK) ? "max repetitions"
1115 if (pdu_type == SNMP_MSG_GETBULK) {
1116 proto_tree_add_text(tree, tvb, offset,
1117 length, "Max repetitions: %u", error_index);
1119 proto_tree_add_text(tree, tvb, offset,
1120 length, "Error Index: %u", error_index);
1128 ret = asn1_oid_decode (&asn1, &enterprise, &enterprise_length,
1130 if (ret != ASN1_ERR_NOERROR) {
1131 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1132 "enterprise OID", ret);
1136 oid_string = format_oid(enterprise, enterprise_length);
1137 proto_tree_add_string(tree, hf_snmp_enterprise, tvb,
1138 offset, length, oid_string);
1145 start = asn1.offset;
1146 ret = asn1_header_decode (&asn1, &cls, &con, &tag,
1147 &def, &agent_address_length);
1148 if (ret != ASN1_ERR_NOERROR) {
1149 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1150 "agent address", ret);
1153 if (!((cls == ASN1_APL && con == ASN1_PRI && tag == SNMP_IPA) ||
1154 (cls == ASN1_UNI && con == ASN1_PRI && tag == ASN1_OTS))) {
1155 /* GXSNMP 0.0.15 says the latter is "needed for
1157 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1158 "agent_address", ASN1_ERR_WRONG_TYPE);
1161 if (agent_address_length != 4) {
1162 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1163 "agent_address", ASN1_ERR_WRONG_LENGTH_FOR_TYPE);
1166 ret = asn1_string_value_decode (&asn1,
1167 agent_address_length, &agent_address);
1168 if (ret != ASN1_ERR_NOERROR) {
1169 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1170 "agent address", ret);
1173 length = asn1.offset - start;
1175 if (agent_address_length != 4) {
1176 proto_tree_add_text(tree, tvb, offset,
1178 "Agent address: <length is %u, not 4>",
1179 agent_address_length);
1181 memcpy((guint8 *)&agent_ipaddr, agent_address,
1182 agent_address_length);
1183 proto_tree_add_ipv4(tree, hf_snmp_agent, tvb,
1184 offset, length, agent_ipaddr);
1187 g_free(agent_address);
1190 /* generic trap type */
1191 ret = asn1_uint32_decode (&asn1, &trap_type, &length);
1192 if (ret != ASN1_ERR_NOERROR) {
1193 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1194 "generic trap type", ret);
1198 proto_tree_add_uint(tree, hf_snmp_traptype, tvb,
1199 offset, length, trap_type);
1203 /* specific trap type */
1204 ret = asn1_uint32_decode (&asn1, &specific_type, &length);
1205 if (ret != ASN1_ERR_NOERROR) {
1206 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1207 "specific trap type", ret);
1211 proto_tree_add_uint(tree, hf_snmp_spectraptype, tvb,
1212 offset, length, specific_type);
1217 start = asn1.offset;
1218 ret = asn1_header_decode (&asn1, &cls, &con, &tag,
1219 &def, ×tamp_length);
1220 if (ret != ASN1_ERR_NOERROR) {
1221 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1225 if (!((cls == ASN1_APL && con == ASN1_PRI && tag == SNMP_TIT) ||
1226 (cls == ASN1_UNI && con == ASN1_PRI && tag == ASN1_INT))) {
1227 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1228 "timestamp", ASN1_ERR_WRONG_TYPE);
1231 ret = asn1_uint32_value_decode(&asn1, timestamp_length,
1233 if (ret != ASN1_ERR_NOERROR) {
1234 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1238 length = asn1.offset - start;
1240 proto_tree_add_uint(tree, hf_snmp_timestamp, tvb,
1241 offset, length, timestamp);
1247 /* variable bindings */
1248 /* get header for variable-bindings sequence */
1249 ret = asn1_sequence_decode(&asn1, &variable_bindings_length, &length);
1250 if (ret != ASN1_ERR_NOERROR) {
1251 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1252 "variable bindings header", ret);
1257 /* loop on variable bindings */
1259 while (variable_bindings_length > 0) {
1261 sequence_length = 0;
1264 ret = asn1_sequence_decode(&asn1, &variable_length, &length);
1265 if (ret != ASN1_ERR_NOERROR) {
1266 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1267 "variable binding header", ret);
1270 sequence_length += length;
1272 /* parse object identifier */
1273 ret = asn1_oid_decode (&asn1, &variable_oid,
1274 &variable_oid_length, &length);
1275 if (ret != ASN1_ERR_NOERROR) {
1276 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1277 "variable binding OID", ret);
1280 sequence_length += length;
1282 if (display_oid || tree) {
1285 gchar *non_decoded_oid;
1287 new_format_oid(variable_oid, variable_oid_length,
1288 &non_decoded_oid, &decoded_oid);
1290 if (display_oid && check_col(pinfo->cinfo, COL_INFO)) {
1291 col_append_fstr(pinfo->cinfo, COL_INFO,
1293 (decoded_oid == NULL) ? non_decoded_oid :
1299 proto_tree_add_string_format(tree, hf_snmp_oid,
1303 "Object identifier %d: %s (%s)",
1307 /* add also the non decoded oid string */
1308 proto_tree_add_string_hidden(tree, hf_snmp_oid,
1313 proto_tree_add_string_format(tree, hf_snmp_oid,
1317 "Object identifier %d: %s",
1323 if (decoded_oid) g_free(decoded_oid);
1324 g_free(non_decoded_oid);
1328 offset += sequence_length;
1329 variable_bindings_length -= sequence_length;
1332 * Register a cleanup function in case one of our
1333 * tvbuff accesses throws an exception. We need
1334 * to clean up variable_oid.
1336 CLEANUP_PUSH(g_free, variable_oid);
1338 /* Parse the variable's value */
1339 ret = snmp_variable_decode(tree, variable_oid,
1340 variable_oid_length, &asn1, offset, &length);
1343 * We're done with variable_oid, so we can call the cleanup
1344 * handler to free* it, and then pop the cleanup handler.
1346 CLEANUP_CALL_AND_POP;
1348 if (ret != ASN1_ERR_NOERROR) {
1349 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1354 variable_bindings_length -= length;
1358 static const value_string qos_vals[] = {
1359 { 0x0, "No authentication or privacy" },
1360 { 0x1, "Authentication, no privacy" },
1361 { 0x2, "Authentication and privacy" },
1362 { 0x3, "Authentication and privacy" },
1367 dissect_snmp2u_parameters(proto_tree *tree, tvbuff_t *tvb, int offset, int length,
1368 guchar *parameters, int parameters_length)
1371 proto_tree *parameters_tree;
1372 proto_tree *qos_tree;
1377 item = proto_tree_add_text(tree, tvb, offset, length,
1379 parameters_tree = proto_item_add_subtree(item, ett_parameters);
1380 offset += length - parameters_length;
1382 if (parameters_length < 1)
1384 model = *parameters;
1385 proto_tree_add_text(parameters_tree, tvb, offset, 1,
1386 "model: %u", model);
1389 parameters_length -= 1;
1391 /* Unknown model. */
1392 proto_tree_add_text(parameters_tree, tvb, offset, parameters_length, "parameters: %s",
1393 bytes_to_str(parameters, parameters_length));
1397 if (parameters_length < 1)
1400 item = proto_tree_add_text(parameters_tree, tvb, offset, 1,
1402 qos_tree = proto_item_add_subtree(item, ett_parameters_qos);
1403 proto_tree_add_text(qos_tree, tvb, offset, 1, "%s",
1404 decode_boolean_bitfield(qos, 0x04,
1405 8, "Generation of report PDU allowed",
1406 "Generation of report PDU not allowed"));
1407 proto_tree_add_text(qos_tree, tvb, offset, 1, "%s",
1408 decode_enumerated_bitfield(qos, 0x03,
1409 8, qos_vals, "%s"));
1412 parameters_length -= 1;
1414 if (parameters_length < 12)
1416 proto_tree_add_text(parameters_tree, tvb, offset, 12,
1417 "agentID: %s", bytes_to_str(parameters, 12));
1420 parameters_length -= 12;
1422 if (parameters_length < 4)
1424 proto_tree_add_text(parameters_tree, tvb, offset, 4,
1425 "agentBoots: %u", pntohl(parameters));
1428 parameters_length -= 4;
1430 if (parameters_length < 4)
1432 proto_tree_add_text(parameters_tree, tvb, offset, 4,
1433 "agentTime: %u", pntohl(parameters));
1436 parameters_length -= 4;
1438 if (parameters_length < 2)
1440 proto_tree_add_text(parameters_tree, tvb, offset, 2,
1441 "maxSize: %u", pntohs(parameters));
1444 parameters_length -= 2;
1446 if (parameters_length < 1)
1449 proto_tree_add_text(parameters_tree, tvb, offset, 1,
1450 "userLen: %u", len);
1453 parameters_length -= 1;
1455 if (parameters_length < len)
1457 proto_tree_add_text(parameters_tree, tvb, offset, len,
1458 "userName: %.*s", len, parameters);
1461 parameters_length -= len;
1463 if (parameters_length < 1)
1466 proto_tree_add_text(parameters_tree, tvb, offset, 1,
1467 "authLen: %u", len);
1470 parameters_length -= 1;
1472 if (parameters_length < len)
1474 proto_tree_add_text(parameters_tree, tvb, offset, len,
1475 "authDigest: %s", bytes_to_str(parameters, len));
1478 parameters_length -= len;
1480 if (parameters_length < 1)
1482 proto_tree_add_text(parameters_tree, tvb, offset, parameters_length,
1483 "contextSelector: %s", bytes_to_str(parameters, parameters_length));
1487 dissect_snmp_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
1488 proto_tree *tree, int proto, gint ett, gboolean is_tcp)
1490 guint length_remaining;
1496 guint message_length;
1497 guint global_length;
1503 guint32 engineboots;
1517 guint msgflags_length;
1518 guint community_length;
1519 guint secparm_length;
1520 guint cengineid_length;
1522 guint cryptpdu_length;
1523 guint aengineid_length;
1524 guint username_length;
1525 guint authpar_length;
1526 guint privpar_length;
1531 proto_tree *snmp_tree = NULL;
1532 proto_tree *global_tree = NULL;
1533 proto_tree *flags_tree = NULL;
1534 proto_tree *secur_tree = NULL;
1535 proto_item *item = NULL;
1537 guint cls, con, tag;
1540 * This will throw an exception if we don't have any data left.
1541 * That's what we want. (See "tcp_dissect_pdus()", which is
1542 * similar, but doesn't have to deal with ASN.1.
1543 * XXX - can we make "tcp_dissect_pdus()" provide enough
1544 * information to the "get_pdu_len" routine so that we could
1545 * have that routine deal with ASN.1, and just use
1546 * "tcp_dissect_pdus()"?)
1548 length_remaining = tvb_ensure_length_remaining(tvb, offset);
1550 /* NOTE: we have to parse the message piece by piece, since the
1551 * capture length may be less than the message length: a 'global'
1552 * parsing is likely to fail.
1556 * If this is SNMP-over-TCP, we might have to do reassembly
1557 * in order to read the "Sequence Of" header.
1559 if (is_tcp && snmp_desegment && pinfo->can_desegment) {
1561 * This is TCP, and we should, and can, do reassembly.
1563 * Is the "Sequence Of" header split across segment
1564 * boundaries? We requre at least 6 bytes for the
1565 * header, which allows for a 4-byte length (ASN.1
1568 if (length_remaining < 6) {
1569 pinfo->desegment_offset = offset;
1570 pinfo->desegment_len = 6 - length_remaining;
1573 * Return 0, which means "I didn't dissect anything
1574 * because I don't have enough data - we need
1582 * OK, try to read the "Sequence Of" header; this gets the total
1583 * length of the SNMP message.
1585 asn1_open(&asn1, tvb, offset);
1586 ret = asn1_sequence_decode(&asn1, &message_length, &length);
1587 if (ret != ASN1_ERR_NOERROR) {
1589 item = proto_tree_add_item(tree, proto, tvb, offset,
1591 snmp_tree = proto_item_add_subtree(item, ett);
1593 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1594 "message header", ret);
1597 * Return the length remaining in the tvbuff, so
1598 * if this is SNMP-over-TCP, our caller thinks there's
1599 * nothing left to dissect.
1601 return length_remaining;
1605 * Add the length of the "Sequence Of" header to the message
1608 message_length += length;
1609 if (message_length < length) {
1611 * The message length was probably so large that the
1612 * total length overflowed.
1614 * Report this as an error.
1616 show_reported_bounds_error(tvb, pinfo, tree);
1619 * Return the length remaining in the tvbuff, so
1620 * if this is SNMP-over-TCP, our caller thinks there's
1621 * nothing left to dissect.
1623 return length_remaining;
1627 * If this is SNMP-over-TCP, we might have to do reassembly
1628 * to get all of this message.
1630 if (is_tcp && snmp_desegment && pinfo->can_desegment) {
1632 * Yes - is the message split across segment boundaries?
1634 if (length_remaining < message_length) {
1636 * Yes. Tell the TCP dissector where the data
1637 * for this message starts in the data it handed
1638 * us, and how many more bytes we need, and
1641 pinfo->desegment_offset = offset;
1642 pinfo->desegment_len =
1643 message_length - length_remaining;
1646 * Return 0, which means "I didn't dissect anything
1647 * because I don't have enough data - we need
1654 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
1655 col_set_str(pinfo->cinfo, COL_PROTOCOL,
1656 proto_get_protocol_short_name(find_protocol_by_id(proto)));
1660 item = proto_tree_add_item(tree, proto, tvb, offset,
1661 message_length, FALSE);
1662 snmp_tree = proto_item_add_subtree(item, ett);
1666 ret = asn1_uint32_decode (&asn1, &version, &length);
1667 if (ret != ASN1_ERR_NOERROR) {
1668 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1669 "version number", ret);
1670 return message_length;
1673 proto_tree_add_uint(snmp_tree, hf_snmp_version, tvb, offset,
1680 case SNMP_VERSION_1:
1681 case SNMP_VERSION_2c:
1682 ret = asn1_octet_string_decode (&asn1, &community,
1683 &community_length, &length);
1684 if (ret != ASN1_ERR_NOERROR) {
1685 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1687 return message_length;
1690 commustr = g_malloc(community_length+1);
1691 memcpy(commustr, community, community_length);
1692 commustr[community_length] = '\0';
1694 proto_tree_add_string(snmp_tree, hf_snmp_community,
1695 tvb, offset, length, commustr);
1701 case SNMP_VERSION_2u:
1702 ret = asn1_octet_string_decode (&asn1, &community,
1703 &community_length, &length);
1705 dissect_snmp2u_parameters(snmp_tree, tvb, offset, length,
1706 community, community_length);
1711 case SNMP_VERSION_3:
1712 ret = asn1_sequence_decode(&asn1, &global_length, &length);
1713 if (ret != ASN1_ERR_NOERROR) {
1714 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1715 "message global header", ret);
1716 return message_length;
1719 item = proto_tree_add_text(snmp_tree, tvb, offset,
1720 global_length + length, "Message Global Header");
1721 global_tree = proto_item_add_subtree(item, ett_global);
1722 proto_tree_add_text(global_tree, tvb, offset,
1724 "Message Global Header Length: %d", global_length);
1727 ret = asn1_uint32_decode (&asn1, &msgid, &length);
1728 if (ret != ASN1_ERR_NOERROR) {
1729 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1731 return message_length;
1734 proto_tree_add_text(global_tree, tvb, offset,
1735 length, "Message ID: %d", msgid);
1738 ret = asn1_uint32_decode (&asn1, &msgmax, &length);
1739 if (ret != ASN1_ERR_NOERROR) {
1740 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1741 "message max size", ret);
1742 return message_length;
1745 proto_tree_add_text(global_tree, tvb, offset,
1746 length, "Message Max Size: %d", msgmax);
1749 ret = asn1_octet_string_decode (&asn1, &msgflags,
1750 &msgflags_length, &length);
1751 if (ret != ASN1_ERR_NOERROR) {
1752 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1753 "message flags", ret);
1754 return message_length;
1756 if (msgflags_length != 1) {
1757 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1758 "message flags wrong length", ret);
1760 return message_length;
1763 item = proto_tree_add_uint_format(global_tree,
1764 hf_snmpv3_flags, tvb, offset, length,
1765 msgflags[0], "Flags: 0x%02x", msgflags[0]);
1766 flags_tree = proto_item_add_subtree(item, ett_flags);
1767 proto_tree_add_boolean(flags_tree, hf_snmpv3_flags_report,
1768 tvb, offset, length, msgflags[0]);
1769 proto_tree_add_boolean(flags_tree, hf_snmpv3_flags_crypt,
1770 tvb, offset, length, msgflags[0]);
1771 proto_tree_add_boolean(flags_tree, hf_snmpv3_flags_auth,
1772 tvb, offset, length, msgflags[0]);
1774 encrypted = msgflags[0] & TH_CRYPT;
1777 ret = asn1_uint32_decode (&asn1, &msgsec, &length);
1778 if (ret != ASN1_ERR_NOERROR) {
1779 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1780 "message security model", ret);
1781 return message_length;
1784 proto_tree_add_text(global_tree, tvb, offset,
1785 length, "Message Security Model: %s",
1786 val_to_str(msgsec, sec_models,
1787 "Unknown model %#x"));
1792 start = asn1.offset;
1793 ret = asn1_header_decode (&asn1, &cls, &con, &tag,
1794 &def, &secparm_length);
1795 length = asn1.offset - start;
1796 if (cls != ASN1_UNI && con != ASN1_PRI &&
1798 dissect_snmp_parse_error(tvb, offset, pinfo,
1799 snmp_tree, "Message Security Parameters",
1800 ASN1_ERR_WRONG_TYPE);
1801 return message_length;
1804 item = proto_tree_add_text(snmp_tree, tvb,
1805 offset, secparm_length + length,
1806 "Message Security Parameters");
1807 secur_tree = proto_item_add_subtree(item,
1809 proto_tree_add_text(secur_tree, tvb, offset,
1811 "Message Security Parameters Length: %d",
1815 ret = asn1_sequence_decode(&asn1, &secparm_length,
1817 if (ret != ASN1_ERR_NOERROR) {
1818 dissect_snmp_parse_error(tvb, offset, pinfo,
1819 snmp_tree, "USM sequence header", ret);
1820 return message_length;
1823 ret = asn1_octet_string_decode (&asn1, &aengineid,
1824 &aengineid_length, &length);
1825 if (ret != ASN1_ERR_NOERROR) {
1826 dissect_snmp_parse_error(tvb, offset, pinfo,
1827 snmp_tree, "authoritative engine id", ret);
1828 return message_length;
1831 proto_tree_add_text(secur_tree, tvb, offset,
1832 length, "Authoritative Engine ID: %s",
1833 bytes_to_str(aengineid, aengineid_length));
1837 ret = asn1_uint32_decode (&asn1, &engineboots, &length);
1838 if (ret != ASN1_ERR_NOERROR) {
1839 dissect_snmp_parse_error(tvb, offset, pinfo,
1840 snmp_tree, "engine boots", ret);
1841 return message_length;
1844 proto_tree_add_text(secur_tree, tvb,
1845 offset, length, "Engine Boots: %d",
1849 ret = asn1_uint32_decode (&asn1, &enginetime, &length);
1850 if (ret != ASN1_ERR_NOERROR) {
1851 dissect_snmp_parse_error(tvb, offset, pinfo,
1852 snmp_tree, "engine time", ret);
1853 return message_length;
1856 proto_tree_add_text(secur_tree, tvb,
1857 offset, length, "Engine Time: %d",
1861 ret = asn1_octet_string_decode (&asn1, &username,
1862 &username_length, &length);
1863 if (ret != ASN1_ERR_NOERROR) {
1864 dissect_snmp_parse_error(tvb, offset, pinfo,
1865 snmp_tree, "user name", ret);
1866 return message_length;
1869 proto_tree_add_text(secur_tree, tvb, offset,
1870 length, "User Name: %s",
1871 SAFE_STRING(username, username_length));
1875 ret = asn1_octet_string_decode (&asn1, &authpar,
1876 &authpar_length, &length);
1877 if (ret != ASN1_ERR_NOERROR) {
1878 dissect_snmp_parse_error(tvb, offset, pinfo,
1879 snmp_tree, "authentication parameter", ret);
1880 return message_length;
1883 proto_tree_add_text(secur_tree, tvb, offset,
1884 length, "Authentication Parameter: %s",
1885 bytes_to_str(authpar, authpar_length));
1889 ret = asn1_octet_string_decode (&asn1, &privpar,
1890 &privpar_length, &length);
1891 if (ret != ASN1_ERR_NOERROR) {
1892 dissect_snmp_parse_error(tvb, offset, pinfo,
1893 snmp_tree, "privacy parameter", ret);
1894 return message_length;
1897 proto_tree_add_text(secur_tree, tvb, offset,
1898 length, "Privacy Parameter: %s",
1899 bytes_to_str(privpar, privpar_length));
1905 ret = asn1_octet_string_decode (&asn1,
1906 &secparm, &secparm_length, &length);
1907 if (ret != ASN1_ERR_NOERROR) {
1908 dissect_snmp_parse_error(tvb, offset, pinfo,
1909 snmp_tree, "Message Security Parameters",
1911 return message_length;
1914 proto_tree_add_text(snmp_tree, tvb, offset,
1916 "Message Security Parameters Data"
1917 " (%d bytes)", secparm_length);
1923 /* PDU starts here */
1925 ret = asn1_octet_string_decode (&asn1, &cryptpdu,
1926 &cryptpdu_length, &length);
1927 if (ret != ASN1_ERR_NOERROR) {
1928 dissect_snmp_parse_error(tvb, offset, pinfo,
1929 snmp_tree, "encrypted PDU header", ret);
1930 return message_length;
1932 proto_tree_add_text(snmp_tree, tvb, offset, length,
1933 "Encrypted PDU (%d bytes)", length);
1935 if (check_col(pinfo->cinfo, COL_INFO))
1936 col_set_str(pinfo->cinfo, COL_INFO, "Encrypted PDU");
1937 return message_length;
1939 ret = asn1_sequence_decode(&asn1, &global_length, &length);
1940 if (ret != ASN1_ERR_NOERROR) {
1941 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1943 return message_length;
1946 ret = asn1_octet_string_decode (&asn1, &cengineid,
1947 &cengineid_length, &length);
1948 if (ret != ASN1_ERR_NOERROR) {
1949 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1950 "context engine id", ret);
1951 return message_length;
1954 proto_tree_add_text(snmp_tree, tvb, offset, length,
1955 "Context Engine ID: %s",
1956 bytes_to_str(cengineid, cengineid_length));
1960 ret = asn1_octet_string_decode (&asn1, &cname,
1961 &cname_length, &length);
1962 if (ret != ASN1_ERR_NOERROR) {
1963 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1964 "context name", ret);
1965 return message_length;
1968 proto_tree_add_text(snmp_tree, tvb, offset, length,
1970 SAFE_STRING(cname, cname_length));
1976 dissect_snmp_error(tvb, offset, pinfo, snmp_tree,
1977 "PDU for unknown version of SNMP");
1978 return message_length;
1981 start = asn1.offset;
1982 ret = asn1_header_decode (&asn1, &cls, &con, &pdu_type, &def,
1984 if (ret != ASN1_ERR_NOERROR) {
1985 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1987 return message_length;
1989 if (cls != ASN1_CTX || con != ASN1_CON) {
1990 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1991 "PDU type", ASN1_ERR_WRONG_TYPE);
1992 return message_length;
1994 dissect_common_pdu(tvb, offset, pinfo, snmp_tree, asn1, pdu_type, start);
1995 return message_length;
1999 dissect_smux_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
2000 proto_tree *tree, int proto, gint ett)
2008 char *pdu_type_string;
2018 guint password_length;
2020 guchar *application;
2021 guint application_length;
2028 proto_tree *smux_tree = NULL;
2029 proto_item *item = NULL;
2033 if (check_col(pinfo->cinfo, COL_PROTOCOL))
2034 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMUX");
2037 item = proto_tree_add_item(tree, proto, tvb, offset, -1, FALSE);
2038 smux_tree = proto_item_add_subtree(item, ett);
2041 /* NOTE: we have to parse the message piece by piece, since the
2042 * capture length may be less than the message length: a 'global'
2043 * parsing is likely to fail.
2045 /* parse the SNMP header */
2046 asn1_open(&asn1, tvb, offset);
2047 start = asn1.offset;
2048 ret = asn1_header_decode (&asn1, &cls, &con, &pdu_type, &def,
2050 if (ret != ASN1_ERR_NOERROR) {
2051 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2056 /* Dissect SMUX here */
2057 if (cls == ASN1_APL && con == ASN1_CON && pdu_type == SMUX_MSG_OPEN) {
2058 pdu_type_string = val_to_str(pdu_type, smux_types,
2059 "Unknown PDU type %#x");
2060 if (check_col(pinfo->cinfo, COL_INFO))
2061 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
2062 length = asn1.offset - start;
2064 proto_tree_add_uint(smux_tree, hf_smux_pdutype, tvb,
2065 offset, length, pdu_type);
2068 ret = asn1_uint32_decode (&asn1, &version, &length);
2069 if (ret != ASN1_ERR_NOERROR) {
2070 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2075 proto_tree_add_uint(smux_tree, hf_smux_version, tvb,
2076 offset, length, version);
2080 ret = asn1_oid_decode (&asn1, ®id, ®id_length, &length);
2081 if (ret != ASN1_ERR_NOERROR) {
2082 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2083 "registration OID", ret);
2087 oid_string = format_oid(regid, regid_length);
2088 proto_tree_add_text(smux_tree, tvb, offset, length,
2089 "Registration: %s", oid_string);
2095 ret = asn1_octet_string_decode (&asn1, &application,
2096 &application_length, &length);
2097 if (ret != ASN1_ERR_NOERROR) {
2098 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2099 "application", ret);
2103 proto_tree_add_text(smux_tree, tvb, offset, length,
2105 SAFE_STRING(application, application_length));
2107 g_free(application);
2110 ret = asn1_octet_string_decode (&asn1, &password,
2111 &password_length, &length);
2112 if (ret != ASN1_ERR_NOERROR) {
2113 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2118 proto_tree_add_text(smux_tree, tvb, offset, length,
2120 SAFE_STRING(password, password_length));
2126 if (cls == ASN1_APL && con == ASN1_PRI && pdu_type == SMUX_MSG_CLOSE) {
2127 pdu_type_string = val_to_str(pdu_type, smux_types,
2128 "Unknown PDU type %#x");
2129 if (check_col(pinfo->cinfo, COL_INFO))
2130 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
2131 length = asn1.offset - start;
2133 proto_tree_add_uint(smux_tree, hf_smux_pdutype, tvb,
2134 offset, length, pdu_type);
2137 ret = asn1_uint32_value_decode (&asn1, pdu_length, &cause);
2138 if (ret != ASN1_ERR_NOERROR) {
2139 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2144 proto_tree_add_text(smux_tree, tvb, offset,
2145 pdu_length, "Cause: %s",
2146 val_to_str(cause, smux_close,
2147 "Unknown cause %#x"));
2149 offset += pdu_length;
2152 if (cls == ASN1_APL && con == ASN1_CON && pdu_type == SMUX_MSG_RREQ) {
2153 pdu_type_string = val_to_str(pdu_type, smux_types,
2154 "Unknown PDU type %#x");
2155 if (check_col(pinfo->cinfo, COL_INFO))
2156 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
2157 length = asn1.offset - start;
2159 proto_tree_add_uint(smux_tree, hf_smux_pdutype, tvb,
2160 offset, length, pdu_type);
2163 ret = asn1_oid_decode (&asn1, ®id, ®id_length, &length);
2164 if (ret != ASN1_ERR_NOERROR) {
2165 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2166 "registration subtree", ret);
2170 oid_string = format_oid(regid, regid_length);
2171 proto_tree_add_text(smux_tree, tvb, offset, length,
2172 "Registration: %s", oid_string);
2178 ret = asn1_uint32_decode (&asn1, &priority, &length);
2179 if (ret != ASN1_ERR_NOERROR) {
2180 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2185 proto_tree_add_text(smux_tree, tvb, offset, length,
2186 "Priority: %d", priority);
2190 ret = asn1_uint32_decode (&asn1, &operation, &length);
2191 if (ret != ASN1_ERR_NOERROR) {
2192 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2197 proto_tree_add_text(smux_tree, tvb, offset, length,
2199 val_to_str(operation, smux_rreq,
2200 "Unknown operation %#x"));
2205 if (cls == ASN1_APL && con == ASN1_PRI && pdu_type == SMUX_MSG_RRSP) {
2206 pdu_type_string = val_to_str(pdu_type, smux_types,
2207 "Unknown PDU type %#x");
2208 if (check_col(pinfo->cinfo, COL_INFO))
2209 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
2210 length = asn1.offset - start;
2212 proto_tree_add_uint(smux_tree, hf_smux_pdutype, tvb,
2213 offset, length, pdu_type);
2216 ret = asn1_uint32_value_decode (&asn1, pdu_length, &priority);
2217 if (ret != ASN1_ERR_NOERROR) {
2218 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2223 proto_tree_add_text(smux_tree, tvb, offset,
2225 val_to_str(priority, smux_prio,
2228 offset += pdu_length;
2231 if (cls == ASN1_APL && con == ASN1_PRI && pdu_type == SMUX_MSG_SOUT) {
2232 pdu_type_string = val_to_str(pdu_type, smux_types,
2233 "Unknown PDU type %#x");
2234 if (check_col(pinfo->cinfo, COL_INFO))
2235 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
2236 length = asn1.offset - start;
2238 proto_tree_add_uint(smux_tree, hf_smux_pdutype, tvb,
2239 offset, length, pdu_type);
2242 ret = asn1_uint32_value_decode (&asn1, pdu_length, &commit);
2243 if (ret != ASN1_ERR_NOERROR) {
2244 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2249 proto_tree_add_text(smux_tree, tvb, offset,
2251 val_to_str(commit, smux_sout,
2252 "Unknown SOUT Value: %#x"));
2254 offset += pdu_length;
2257 if (cls != ASN1_CTX || con != ASN1_CON) {
2258 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
2259 "PDU type", ASN1_ERR_WRONG_TYPE);
2262 dissect_common_pdu(tvb, offset, pinfo, smux_tree, asn1, pdu_type, start);
2266 dissect_snmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2268 conversation_t *conversation;
2271 * The first SNMP packet goes to the SNMP port; the second one
2272 * may come from some *other* port, but goes back to the same
2273 * IP address and port as the ones from which the first packet
2274 * came; all subsequent packets presumably go between those two
2275 * IP addresses and ports.
2277 * If this packet went to the SNMP port, we check to see if
2278 * there's already a conversation with one address/port pair
2279 * matching the source IP address and port of this packet,
2280 * the other address matching the destination IP address of this
2281 * packet, and any destination port.
2283 * If not, we create one, with its address 1/port 1 pair being
2284 * the source address/port of this packet, its address 2 being
2285 * the destination address of this packet, and its port 2 being
2286 * wildcarded, and give it the SNMP dissector as a dissector.
2288 if (pinfo->destport == UDP_PORT_SNMP) {
2289 conversation = find_conversation(&pinfo->src, &pinfo->dst, PT_UDP,
2290 pinfo->srcport, 0, NO_PORT_B);
2291 if (conversation == NULL) {
2292 conversation = conversation_new(&pinfo->src, &pinfo->dst, PT_UDP,
2293 pinfo->srcport, 0, NO_PORT2);
2294 conversation_set_dissector(conversation, snmp_handle);
2298 dissect_snmp_pdu(tvb, 0, pinfo, tree, proto_snmp, ett_snmp, FALSE);
2302 dissect_snmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2307 while (tvb_reported_length_remaining(tvb, offset) > 0) {
2308 message_len = dissect_snmp_pdu(tvb, 0, pinfo, tree,
2309 proto_snmp, ett_snmp, TRUE);
2310 if (message_len == 0) {
2312 * We don't have all the data for that message,
2313 * so we need to do desegmentation;
2314 * "dissect_snmp_pdu()" has set that up.
2318 offset += message_len;
2323 dissect_smux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2325 dissect_smux_pdu(tvb, 0, pinfo, tree, proto_smux, ett_smux);
2331 #ifdef HAVE_SOME_SNMP
2332 gchar *tmp_mib_modules;
2333 static gboolean mibs_loaded = FALSE;
2337 * Unload the MIBs, as we'll be reloading them based on
2338 * the current preference setting.
2340 shutdown_mib(); /* unload MIBs */
2344 * Cannot check if MIBS is already set, as it could be set by Ethereal.
2346 * If we have a list of modules to load, put that list in MIBS,
2347 * otherwise clear MIBS.
2349 if (mib_modules != NULL) {
2350 tmp_mib_modules = g_strconcat("MIBS=", mib_modules, NULL);
2353 _putenv(tmp_mib_modules);
2355 putenv(tmp_mib_modules);
2368 register_mib_handlers();
2369 read_premib_configs();
2373 #endif /* HAVE_SOME_SNMP */
2377 proto_register_snmp(void)
2379 #if defined(WIN32) && defined(HAVE_SOME_SNMP)
2381 #define MIB_PATH_APPEND "snmp\\mibs"
2383 gchar *tmp_mib_modules;
2385 static hf_register_info hf[] = {
2387 { "Version", "snmp.version", FT_UINT8, BASE_DEC, VALS(versions),
2389 { &hf_snmp_community,
2390 { "Community", "snmp.community", FT_STRING, BASE_NONE, NULL,
2392 { &hf_snmp_request_id,
2393 { "Request Id", "snmp.id", FT_UINT32, BASE_HEX, NULL,
2394 0x0, "Id for this transaction", HFILL }},
2396 { "PDU type", "snmp.pdutype", FT_UINT8, BASE_DEC, VALS(pdu_types),
2399 { "Agent address", "snmp.agent", FT_IPv4, BASE_NONE, NULL,
2401 { &hf_snmp_enterprise,
2402 { "Enterprise", "snmp.enterprise", FT_STRING, BASE_NONE, NULL,
2404 { &hf_snmp_error_status,
2405 { "Error Status", "snmp.error", FT_UINT8, BASE_DEC, VALS(error_statuses),
2408 { "Object identifier", "snmp.oid", FT_STRING, BASE_NONE, NULL,
2410 { &hf_snmp_traptype,
2411 { "Trap type", "snmp.traptype", FT_UINT8, BASE_DEC, VALS(trap_types),
2413 { &hf_snmp_spectraptype,
2414 { "Specific trap type", "snmp.spectraptype", FT_UINT32, BASE_DEC, NULL,
2416 { &hf_snmp_timestamp,
2417 { "Timestamp", "snmp.timestamp", FT_UINT8, BASE_DEC, NULL,
2420 { "SNMPv3 Flags", "snmpv3.flags", FT_UINT8, BASE_HEX, NULL,
2422 { &hf_snmpv3_flags_auth,
2423 { "Authenticated", "snmpv3.flags.auth", FT_BOOLEAN, 8,
2424 TFS(&flags_set_truth), TH_AUTH, "", HFILL }},
2425 { &hf_snmpv3_flags_crypt,
2426 { "Encrypted", "snmpv3.flags.crypt", FT_BOOLEAN, 8,
2427 TFS(&flags_set_truth), TH_CRYPT, "", HFILL }},
2428 { &hf_snmpv3_flags_report,
2429 { "Reportable", "snmpv3.flags.report", FT_BOOLEAN, 8,
2430 TFS(&flags_set_truth), TH_REPORT, "", HFILL }},
2432 static gint *ett[] = {
2435 &ett_parameters_qos,
2440 module_t *snmp_module;
2442 #ifdef HAVE_SOME_SNMP
2445 /* Set MIBDIRS so that the SNMP library can find its mibs. */
2446 /* XXX - Should we set MIBS or MIBFILES as well? */
2448 mib_path = g_malloc (strlen(get_datafile_dir()) + strlen(MIB_PATH_APPEND) + 20);
2449 sprintf (mib_path, "MIBDIRS=%s\\%s", get_datafile_dir(), MIB_PATH_APPEND);
2450 /* Amazingly enough, Windows does not provide setenv(). */
2451 if (getenv("MIBDIRS") == NULL)
2458 * Suppress warnings about unknown tokens - we aren't initializing
2459 * UCD SNMP in its entirety, we're just initializing the
2460 * MIB-handling part because that's all we're using, which
2461 * means that entries in the configuration file for other
2462 * pars of the library will not be handled, and we don't want
2463 * the config file reading code to whine about that.
2465 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID,
2466 NETSNMP_DS_LIB_NO_TOKEN_WARNINGS, TRUE);
2467 netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
2468 NETSNMP_DS_LIB_PRINT_SUFFIX_ONLY, 2);
2469 #endif /* HAVE_SOME_SNMP */
2470 proto_snmp = proto_register_protocol("Simple Network Management Protocol",
2472 proto_register_field_array(proto_snmp, hf, array_length(hf));
2473 proto_register_subtree_array(ett, array_length(ett));
2474 snmp_handle = create_dissector_handle(dissect_snmp, proto_snmp);
2476 /* Register configuration preferences */
2477 snmp_module = prefs_register_protocol(proto_snmp, process_prefs);
2478 prefs_register_bool_preference(snmp_module, "display_oid",
2479 "Show SNMP OID in info column",
2480 "Whether the SNMP OID should be shown in the info column",
2484 * Set the default value of "mib_modules".
2486 * If the MIBS environment variable is set, make its value
2487 * the value of "mib_modules", otherwise, set "mib_modules"
2488 * to DEF_MIB_MODULES.
2490 tmp_mib_modules = getenv("MIBS");
2491 if (tmp_mib_modules != NULL)
2492 mib_modules = tmp_mib_modules;
2493 prefs_register_string_preference(snmp_module, "mib_modules",
2494 "MIB modules to load",
2495 "List of MIB modules to load (the list is set to environment variable MIBS if the variable is not already set)",
2497 prefs_register_bool_preference(snmp_module, "desegment",
2498 "Desegment all SNMP-over-TCP messages\nspanning multiple TCP segments",
2499 "Whether the SNMP dissector should desegment all messages "
2500 "spanning multiple TCP segments",
2505 proto_reg_handoff_snmp(void)
2507 dissector_handle_t snmp_tcp_handle;
2509 dissector_add("udp.port", UDP_PORT_SNMP, snmp_handle);
2510 dissector_add("udp.port", UDP_PORT_SNMP_TRAP, snmp_handle);
2511 dissector_add("ethertype", ETHERTYPE_SNMP, snmp_handle);
2512 dissector_add("ipx.socket", IPX_SOCKET_SNMP_AGENT, snmp_handle);
2513 dissector_add("ipx.socket", IPX_SOCKET_SNMP_SINK, snmp_handle);
2514 dissector_add("hpext.dxsap", HPEXT_SNMP, snmp_handle);
2516 snmp_tcp_handle = create_dissector_handle(dissect_snmp_tcp, proto_snmp);
2517 dissector_add("tcp.port", TCP_PORT_SNMP, snmp_tcp_handle);
2518 dissector_add("tcp.port", TCP_PORT_SNMP_TRAP, snmp_tcp_handle);
2520 data_handle = find_dissector("data");
2523 * Process preference settings.
2525 * We can't do this in the register routine, as preferences aren't
2526 * read until all dissector register routines have been called (so
2527 * that all dissector preferences have been registered).
2533 proto_register_smux(void)
2535 static hf_register_info hf[] = {
2537 { "Version", "smux.version", FT_UINT8, BASE_DEC, NULL,
2540 { "PDU type", "smux.pdutype", FT_UINT8, BASE_DEC, VALS(smux_types),
2543 static gint *ett[] = {
2547 proto_smux = proto_register_protocol("SNMP Multiplex Protocol",
2549 proto_register_field_array(proto_smux, hf, array_length(hf));
2550 proto_register_subtree_array(ett, array_length(ett));
2554 proto_reg_handoff_smux(void)
2556 dissector_handle_t smux_handle;
2558 smux_handle = create_dissector_handle(dissect_smux, proto_smux);
2559 dissector_add("tcp.port", TCP_PORT_SMUX, smux_handle);