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.
11 * $Id: packet-snmp.c,v 1.91 2002/04/01 21:59:59 guy Exp $
13 * Ethereal - Network traffic analyzer
14 * By Gerald Combs <gerald@ethereal.com>
15 * Copyright 1998 Gerald Combs
19 * GXSNMP -- An snmp mangament application
20 * Copyright (C) 1998 Gregory McLean & Jochen Friedrich
21 * Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version 2
26 * of the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
46 #ifdef HAVE_SYS_TYPES_H
47 # include <sys/types.h>
50 #ifdef HAVE_NETINET_IN_H
51 # include <netinet/in.h>
56 #include <epan/packet.h>
57 #include <epan/strutil.h>
58 #include <epan/conversation.h>
60 #include "packet-ipx.h"
63 # include <ucd-snmp/ucd-snmp-config.h>
64 # include <ucd-snmp/asn1.h>
65 # include <ucd-snmp/snmp_api.h>
66 # include <ucd-snmp/snmp_impl.h>
67 # include <ucd-snmp/mib.h>
68 # include <ucd-snmp/default_store.h>
69 # include <ucd-snmp/read_config.h>
70 # include <ucd-snmp/tools.h>
73 * Define values "sprint_realloc_value()" expects.
75 # define VALTYPE_INTEGER ASN_INTEGER
76 # define VALTYPE_COUNTER ASN_COUNTER
77 # define VALTYPE_GAUGE ASN_GAUGE
78 # define VALTYPE_TIMETICKS ASN_TIMETICKS
79 # define VALTYPE_STRING ASN_OCTET_STR
80 # define VALTYPE_IPADDR ASN_IPADDRESS
81 # define VALTYPE_OPAQUE ASN_OPAQUE
82 # define VALTYPE_NSAP ASN_NSAP
83 # define VALTYPE_OBJECTID ASN_OBJECT_ID
84 # define VALTYPE_BITSTR ASN_BIT_STR
85 # define VALTYPE_COUNTER64 ASN_COUNTER64
91 #include "packet-snmp.h"
92 #include "format-oid.h"
94 /* Null string of type "guchar[]". */
95 static const guchar nullstring[] = "";
97 /* Take a pointer that may be null and return a pointer that's not null
98 by turning null pointers into pointers to the above null string. */
99 #define SAFE_STRING(s) (((s) != NULL) ? (s) : nullstring)
101 static int proto_snmp = -1;
102 static int proto_smux = -1;
104 static gint ett_snmp = -1;
105 static gint ett_smux = -1;
106 static gint ett_parameters = -1;
107 static gint ett_parameters_qos = -1;
108 static gint ett_global = -1;
109 static gint ett_flags = -1;
110 static gint ett_secur = -1;
112 static int hf_snmpv3_flags = -1;
113 static int hf_snmpv3_flags_auth = -1;
114 static int hf_snmpv3_flags_crypt = -1;
115 static int hf_snmpv3_flags_report = -1;
117 static dissector_handle_t snmp_handle;
118 static dissector_handle_t data_handle;
121 #define TH_CRYPT 0x02
122 #define TH_REPORT 0x04
124 static const true_false_string flags_set_truth = {
129 #define UDP_PORT_SNMP 161
130 #define UDP_PORT_SNMP_TRAP 162
131 #define TCP_PORT_SMUX 199
133 /* Protocol version numbers */
134 #define SNMP_VERSION_1 0
135 #define SNMP_VERSION_2c 1
136 #define SNMP_VERSION_2u 2
137 #define SNMP_VERSION_3 3
139 static const value_string versions[] = {
140 { SNMP_VERSION_1, "1" },
141 { SNMP_VERSION_2c, "2C" },
142 { SNMP_VERSION_2u, "2U" },
143 { SNMP_VERSION_3, "3" },
148 #define SNMP_MSG_GET 0
149 #define SNMP_MSG_GETNEXT 1
150 #define SNMP_MSG_RESPONSE 2
151 #define SNMP_MSG_SET 3
152 #define SNMP_MSG_TRAP 4
154 #define SNMP_MSG_GETBULK 5
155 #define SNMP_MSG_INFORM 6
156 #define SNMP_MSG_TRAP2 7
157 #define SNMP_MSG_REPORT 8
159 static const value_string pdu_types[] = {
160 { SNMP_MSG_GET, "GET" },
161 { SNMP_MSG_GETNEXT, "GET-NEXT" },
162 { SNMP_MSG_SET, "SET" },
163 { SNMP_MSG_RESPONSE, "RESPONSE" },
164 { SNMP_MSG_TRAP, "TRAP-V1" },
165 { SNMP_MSG_GETBULK, "GETBULK" },
166 { SNMP_MSG_INFORM, "INFORM" },
167 { SNMP_MSG_TRAP2, "TRAP-V2" },
168 { SNMP_MSG_REPORT, "REPORT" },
173 #define SMUX_MSG_OPEN 0
174 #define SMUX_MSG_CLOSE 1
175 #define SMUX_MSG_RREQ 2
176 #define SMUX_MSG_RRSP 3
177 #define SMUX_MSG_SOUT 4
179 static const value_string smux_types[] = {
180 { SMUX_MSG_OPEN, "Open" },
181 { SMUX_MSG_CLOSE, "Close" },
182 { SMUX_MSG_RREQ, "Registration Request" },
183 { SMUX_MSG_RRSP, "Registration Response" },
184 { SMUX_MSG_SOUT, "Commit Or Rollback" },
188 /* SMUX Closing causes */
189 #define SMUX_CLOSE_DOWN 0
190 #define SMUX_CLOSE_VERSION 1
191 #define SMUX_CLOSE_PACKET 2
192 #define SMUX_CLOSE_PROTOCOL 3
193 #define SMUX_CLOSE_INTERNAL 4
194 #define SMUX_CLOSE_NOAUTH 5
196 static const value_string smux_close[] = {
197 { SMUX_CLOSE_DOWN, "Going down" },
198 { SMUX_CLOSE_VERSION, "Unsupported Version" },
199 { SMUX_CLOSE_PACKET, "Packet Format Error" },
200 { SMUX_CLOSE_PROTOCOL, "Protocol Error" },
201 { SMUX_CLOSE_INTERNAL, "Internal Error" },
202 { SMUX_CLOSE_NOAUTH, "Unauthorized" },
206 /* SMUX Request codes */
207 #define SMUX_RREQ_DELETE 0
208 #define SMUX_RREQ_READONLY 1
209 #define SMUX_RREQ_READWRITE 2
211 static const value_string smux_rreq[] = {
212 { SMUX_RREQ_DELETE, "Delete" },
213 { SMUX_RREQ_READONLY, "Read Only" },
214 { SMUX_RREQ_READWRITE, "Read Write" },
218 static const value_string smux_prio[] = {
223 /* SMUX SOut codes */
224 #define SMUX_SOUT_COMMIT 0
225 #define SMUX_SOUT_ROLLBACK 1
227 static const value_string smux_sout[] = {
228 { SMUX_SOUT_COMMIT, "Commit" },
229 { SMUX_SOUT_ROLLBACK, "Rollback" },
233 /* Error status values */
234 #define SNMP_ERR_NOERROR 0
235 #define SNMP_ERR_TOOBIG 1
236 #define SNMP_ERR_NOSUCHNAME 2
237 #define SNMP_ERR_BADVALUE 3
238 #define SNMP_ERR_READONLY 4
239 #define SNMP_ERR_GENERROR 5
241 #define SNMP_ERR_NOACCESS 6
242 #define SNMP_ERR_WRONGTYPE 7
243 #define SNMP_ERR_WRONGLENGTH 8
244 #define SNMP_ERR_WRONGENCODING 9
245 #define SNMP_ERR_WRONGVALUE 10
246 #define SNMP_ERR_NOCREATION 11
247 #define SNMP_ERR_INCONSISTENTVALUE 12
248 #define SNMP_ERR_RESOURCEUNAVAILABLE 13
249 #define SNMP_ERR_COMMITFAILED 14
250 #define SNMP_ERR_UNDOFAILED 15
251 #define SNMP_ERR_AUTHORIZATIONERROR 16
252 #define SNMP_ERR_NOTWRITABLE 17
253 #define SNMP_ERR_INCONSISTENTNAME 18
255 static const value_string error_statuses[] = {
256 { SNMP_ERR_NOERROR, "NO ERROR" },
257 { SNMP_ERR_TOOBIG, "TOOBIG" },
258 { SNMP_ERR_NOSUCHNAME, "NO SUCH NAME" },
259 { SNMP_ERR_BADVALUE, "BAD VALUE" },
260 { SNMP_ERR_READONLY, "READ ONLY" },
261 { SNMP_ERR_GENERROR, "GENERIC ERROR" },
262 { SNMP_ERR_NOACCESS, "NO ACCESS" },
263 { SNMP_ERR_WRONGTYPE, "WRONG TYPE" },
264 { SNMP_ERR_WRONGLENGTH, "WRONG LENGTH" },
265 { SNMP_ERR_WRONGENCODING, "WRONG ENCODING" },
266 { SNMP_ERR_WRONGVALUE, "WRONG VALUE" },
267 { SNMP_ERR_NOCREATION, "NO CREATION" },
268 { SNMP_ERR_INCONSISTENTVALUE, "INCONSISTENT VALUE" },
269 { SNMP_ERR_RESOURCEUNAVAILABLE, "RESOURCE UNAVAILABLE" },
270 { SNMP_ERR_COMMITFAILED, "COMMIT FAILED" },
271 { SNMP_ERR_UNDOFAILED, "UNDO FAILED" },
272 { SNMP_ERR_AUTHORIZATIONERROR, "AUTHORIZATION ERROR" },
273 { SNMP_ERR_NOTWRITABLE, "NOT WRITABLE" },
274 { SNMP_ERR_INCONSISTENTNAME, "INCONSISTENT NAME" },
278 /* General SNMP V1 Traps */
280 #define SNMP_TRAP_COLDSTART 0
281 #define SNMP_TRAP_WARMSTART 1
282 #define SNMP_TRAP_LINKDOWN 2
283 #define SNMP_TRAP_LINKUP 3
284 #define SNMP_TRAP_AUTHFAIL 4
285 #define SNMP_TRAP_EGPNEIGHBORLOSS 5
286 #define SNMP_TRAP_ENTERPRISESPECIFIC 6
288 static const value_string trap_types[] = {
289 { SNMP_TRAP_COLDSTART, "COLD START" },
290 { SNMP_TRAP_WARMSTART, "WARM START" },
291 { SNMP_TRAP_LINKDOWN, "LINK DOWN" },
292 { SNMP_TRAP_LINKUP, "LINK UP" },
293 { SNMP_TRAP_AUTHFAIL, "AUTHENTICATION FAILED" },
294 { SNMP_TRAP_EGPNEIGHBORLOSS, "EGP NEIGHBORLOSS" },
295 { SNMP_TRAP_ENTERPRISESPECIFIC, "ENTERPRISE SPECIFIC" },
299 /* Security Models */
301 #define SNMP_SEC_ANY 0
302 #define SNMP_SEC_V1 1
303 #define SNMP_SEC_V2C 2
304 #define SNMP_SEC_USM 3
306 static const value_string sec_models[] = {
307 { SNMP_SEC_ANY, "Any" },
308 { SNMP_SEC_V1, "V1" },
309 { SNMP_SEC_V2C, "V2C" },
310 { SNMP_SEC_USM, "USM" },
316 #define SNMP_IPA 0 /* IP Address */
317 #define SNMP_CNT 1 /* Counter (Counter32) */
318 #define SNMP_GGE 2 /* Gauge (Gauge32) */
319 #define SNMP_TIT 3 /* TimeTicks */
320 #define SNMP_OPQ 4 /* Opaque */
321 #define SNMP_NSP 5 /* NsapAddress */
322 #define SNMP_C64 6 /* Counter64 */
323 #define SNMP_U32 7 /* Uinteger32 */
332 #define SNMP_INTEGER 1 /* l */
333 #define SNMP_OCTETSTR 2 /* c */
334 #define SNMP_DISPLAYSTR 2 /* c */
335 #define SNMP_OBJECTID 3 /* ul */
336 #define SNMP_IPADDR 4 /* uc */
337 #define SNMP_COUNTER 5 /* ul */
338 #define SNMP_GAUGE 6 /* ul */
339 #define SNMP_TIMETICKS 7 /* ul */
340 #define SNMP_OPAQUE 8 /* c */
342 /* additional SNMPv2 Types */
344 #define SNMP_UINTEGER 5 /* ul */
345 #define SNMP_BITSTR 9 /* uc */
346 #define SNMP_NSAP 10 /* uc */
347 #define SNMP_COUNTER64 11 /* ul */
348 #define SNMP_NOSUCHOBJECT 12
349 #define SNMP_NOSUCHINSTANCE 13
350 #define SNMP_ENDOFMIBVIEW 14
352 typedef struct _SNMP_CNV SNMP_CNV;
362 static SNMP_CNV SnmpCnv [] =
364 {ASN1_UNI, ASN1_NUL, SNMP_NULL, "NULL"},
365 {ASN1_UNI, ASN1_INT, SNMP_INTEGER, "INTEGER"},
366 {ASN1_UNI, ASN1_OTS, SNMP_OCTETSTR, "OCTET STRING"},
367 {ASN1_UNI, ASN1_OJI, SNMP_OBJECTID, "OBJECTID"},
368 {ASN1_APL, SNMP_IPA, SNMP_IPADDR, "IPADDR"},
369 {ASN1_APL, SNMP_CNT, SNMP_COUNTER, "COUNTER"}, /* Counter32 */
370 {ASN1_APL, SNMP_GGE, SNMP_GAUGE, "GAUGE"}, /* Gauge32 == Unsigned32 */
371 {ASN1_APL, SNMP_TIT, SNMP_TIMETICKS, "TIMETICKS"},
372 {ASN1_APL, SNMP_OPQ, SNMP_OPAQUE, "OPAQUE"},
374 /* SNMPv2 data types and errors */
376 {ASN1_UNI, ASN1_BTS, SNMP_BITSTR, "BITSTR"},
377 {ASN1_APL, SNMP_C64, SNMP_COUNTER64, "COUNTER64"},
378 {ASN1_CTX, SERR_NSO, SNMP_NOSUCHOBJECT, "NOSUCHOBJECT"},
379 {ASN1_CTX, SERR_NSI, SNMP_NOSUCHINSTANCE, "NOSUCHINSTANCE"},
380 {ASN1_CTX, SERR_EOM, SNMP_ENDOFMIBVIEW, "ENDOFMIBVIEW"},
385 * NAME: g_snmp_tag_cls2syntax
386 * SYNOPSIS: gboolean g_snmp_tag_cls2syntax
392 * DESCRIPTION: Converts ASN1 tag and class to Syntax tag and name.
393 * See SnmpCnv for conversion.
394 * RETURNS: name on success, NULL on failure
398 snmp_tag_cls2syntax ( guint tag, guint cls, gushort *syntax)
403 while (cnv->syntax != -1)
405 if (cnv->tag == tag && cnv->class == cls)
407 *syntax = cnv->syntax;
416 dissect_snmp_parse_error(tvbuff_t *tvb, int offset, packet_info *pinfo,
417 proto_tree *tree, const char *field_name, int ret)
421 errstr = asn1_err_to_str(ret);
423 if (check_col(pinfo->cinfo, COL_INFO)) {
424 col_add_fstr(pinfo->cinfo, COL_INFO,
425 "ERROR: Couldn't parse %s: %s", field_name, errstr);
428 proto_tree_add_text(tree, tvb, offset, 0,
429 "ERROR: Couldn't parse %s: %s", field_name, errstr);
430 call_dissector(data_handle,
431 tvb_new_subset(tvb, offset, -1, -1), pinfo, tree);
436 dissect_snmp_error(tvbuff_t *tvb, int offset, packet_info *pinfo,
437 proto_tree *tree, const char *message)
439 if (check_col(pinfo->cinfo, COL_INFO))
440 col_add_str(pinfo->cinfo, COL_INFO, message);
443 proto_tree_add_text(tree, tvb, offset, 0, "%s", message);
444 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
449 format_oid(subid_t *oid, guint oid_length)
458 size_t oid_string_len;
462 result_len = oid_length * 22;
466 * Get the decoded form of the OID, and add its length to the
467 * length of the result string.
469 * XXX - check for "malloc" and "sprint_realloc_objid()" failure.
471 oid_string_len = 256;
472 oid_string = malloc(oid_string_len);
475 sprint_realloc_objid(&oid_string, &oid_string_len, &oid_out_len, 1,
477 result_len += strlen(oid_string) + 3;
480 result = g_malloc(result_len + 1);
482 len = sprintf(buf, "%lu", (unsigned long)oid[0]);
484 for (i = 1; i < oid_length;i++) {
485 len = sprintf(buf, ".%lu", (unsigned long)oid[i]);
491 * Append the decoded form of the OID.
493 sprintf(buf, " (%s)", oid_string);
502 check_var_length(guint vb_length, guint required_length)
505 static const char badlen_fmt[] = "Length is %u, should be %u";
507 if (vb_length != required_length) {
508 /* Enough room for the largest "Length is XXX,
509 should be XXX" message - 10 digits for each
511 buf = malloc(sizeof badlen_fmt + 10 + 10);
512 sprintf(buf, badlen_fmt, vb_length, required_length);
515 return NULL; /* length is OK */
519 format_var(struct variable_list *variable, subid_t *variable_oid,
520 guint variable_oid_length, gushort vb_type, guint val_len)
529 /* Length has to be 4 bytes. */
530 buf = check_var_length(val_len, 4);
532 return buf; /* it's not 4 bytes */
536 /* Length has to be 8 bytes. */
537 buf = check_var_length(val_len, 8);
539 return buf; /* it's not 8 bytes */
546 variable->next_variable = NULL;
547 variable->name = variable_oid;
548 variable->name_length = variable_oid_length;
552 variable->type = VALTYPE_INTEGER;
556 variable->type = VALTYPE_COUNTER;
560 variable->type = VALTYPE_GAUGE;
564 variable->type = VALTYPE_TIMETICKS;
568 variable->type = VALTYPE_STRING;
572 variable->type = VALTYPE_IPADDR;
576 variable->type = VALTYPE_OPAQUE;
580 variable->type = VALTYPE_NSAP;
584 variable->type = VALTYPE_OBJECTID;
588 variable->type = VALTYPE_BITSTR;
592 variable->type = VALTYPE_COUNTER64;
595 variable->val_len = val_len;
598 * XXX - check for "malloc" and "sprint_realloc_objid()" failure.
601 buf = malloc(buf_len);
604 sprint_realloc_value(&buf, &buf_len, &out_len, 1, variable_oid,
605 variable_oid_length, variable);
611 snmp_variable_decode(proto_tree *snmp_tree,
612 subid_t *variable_oid
613 #ifndef HAVE_UCD_SNMP
617 guint variable_oid_length
618 #ifndef HAVE_UCD_SNMP
622 ASN1_SCK *asn1, int offset, guint *lengthp)
633 gint32 vb_integer_value;
634 guint32 vb_uinteger_value;
636 guint8 *vb_octet_string;
641 gchar *vb_display_string;
644 struct variable_list variable;
646 #endif /* HAVE_UCD_SNMP */
651 /* parse the type of the object */
652 start = asn1->offset;
653 ret = asn1_header_decode (asn1, &cls, &con, &tag, &def, &vb_length);
654 if (ret != ASN1_ERR_NOERROR)
657 return ASN1_ERR_LENGTH_NOT_DEFINITE;
659 /* Convert the class, constructed flag, and tag to a type. */
660 vb_type_name = snmp_tag_cls2syntax(tag, cls, &vb_type);
661 if (vb_type_name == NULL) {
664 * Dissect the value as an opaque string of octets.
666 vb_type_name = "unsupported type";
667 vb_type = SNMP_OPAQUE;
670 /* parse the value */
674 ret = asn1_int32_value_decode(asn1, vb_length,
676 if (ret != ASN1_ERR_NOERROR)
678 length = asn1->offset - start;
681 value = vb_integer_value;
682 variable.val.integer = &value;
683 vb_display_string = format_var(&variable,
684 variable_oid, variable_oid_length, vb_type,
686 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
688 "Value: %s", vb_display_string);
689 free(vb_display_string);
690 #else /* HAVE_UCD_SNMP */
691 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
693 "Value: %s: %d (%#x)", vb_type_name,
694 vb_integer_value, vb_integer_value);
695 #endif /* HAVE_UCD_SNMP */
702 ret = asn1_uint32_value_decode(asn1, vb_length,
704 if (ret != ASN1_ERR_NOERROR)
706 length = asn1->offset - start;
709 value = vb_uinteger_value;
710 variable.val.integer = &value;
711 vb_display_string = format_var(&variable,
712 variable_oid, variable_oid_length, vb_type,
714 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
716 "Value: %s", vb_display_string);
717 free(vb_display_string);
718 #else /* HAVE_UCD_SNMP */
719 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
721 "Value: %s: %u (%#x)", vb_type_name,
722 vb_uinteger_value, vb_uinteger_value);
723 #endif /* HAVE_UCD_SNMP */
733 ret = asn1_string_value_decode (asn1, vb_length,
735 if (ret != ASN1_ERR_NOERROR)
737 length = asn1->offset - start;
740 variable.val.string = vb_octet_string;
741 vb_display_string = format_var(&variable,
742 variable_oid, variable_oid_length, vb_type,
744 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
746 "Value: %s", vb_display_string);
747 free(vb_display_string);
748 #else /* HAVE_UCD_SNMP */
750 * If some characters are not printable, display
751 * the string as bytes.
753 for (i = 0; i < vb_length; i++) {
754 if (!(isprint(vb_octet_string[i])
755 || isspace(vb_octet_string[i])))
760 * We stopped, due to a non-printable
761 * character, before we got to the end
764 vb_display_string = g_malloc(4*vb_length);
765 buf = &vb_display_string[0];
766 len = sprintf(buf, "%03u", vb_octet_string[0]);
768 for (i = 1; i < vb_length; i++) {
769 len = sprintf(buf, ".%03u",
773 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
775 "Value: %s: %s", vb_type_name,
777 g_free(vb_display_string);
779 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
781 "Value: %s: %.*s", vb_type_name,
783 SAFE_STRING(vb_octet_string));
785 #endif /* HAVE_UCD_SNMP */
787 g_free(vb_octet_string);
791 ret = asn1_null_decode (asn1, vb_length);
792 if (ret != ASN1_ERR_NOERROR)
794 length = asn1->offset - start;
796 proto_tree_add_text(snmp_tree, asn1->tvb, offset, length,
797 "Value: %s", vb_type_name);
802 ret = asn1_oid_value_decode (asn1, vb_length, &vb_oid,
804 if (ret != ASN1_ERR_NOERROR)
806 length = asn1->offset - start;
809 variable.val.objid = vb_oid;
810 vb_display_string = format_var(&variable,
811 variable_oid, variable_oid_length, vb_type,
812 vb_oid_length * sizeof (subid_t));
813 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
815 "Value: %s", vb_display_string);
816 free(vb_display_string);
817 #else /* HAVE_UCD_SNMP */
818 vb_display_string = format_oid(vb_oid, vb_oid_length);
819 proto_tree_add_text(snmp_tree, asn1->tvb, offset,
821 "Value: %s: %s", vb_type_name, vb_display_string);
822 g_free(vb_display_string);
823 #endif /* HAVE_UCD_SNMP */
828 case SNMP_NOSUCHOBJECT:
829 length = asn1->offset - start;
831 proto_tree_add_text(snmp_tree, asn1->tvb, offset, length,
832 "Value: %s: no such object", vb_type_name);
836 case SNMP_NOSUCHINSTANCE:
837 length = asn1->offset - start;
839 proto_tree_add_text(snmp_tree, asn1->tvb, offset, length,
840 "Value: %s: no such instance", vb_type_name);
844 case SNMP_ENDOFMIBVIEW:
845 length = asn1->offset - start;
847 proto_tree_add_text(snmp_tree, asn1->tvb, offset, length,
848 "Value: %s: end of mib view", vb_type_name);
853 g_assert_not_reached();
854 return ASN1_ERR_WRONG_TYPE;
857 return ASN1_ERR_NOERROR;
861 dissect_common_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
862 proto_tree *tree, ASN1_SCK asn1, guint pdu_type, int start)
866 guint sequence_length;
870 guint32 error_status;
874 char *pdu_type_string;
877 guint enterprise_length;
879 guint8 *agent_address;
880 guint agent_address_length;
884 guint32 specific_type;
887 guint timestamp_length;
891 guint variable_bindings_length;
894 guint variable_length;
895 subid_t *variable_oid;
896 guint variable_oid_length;
901 pdu_type_string = val_to_str(pdu_type, pdu_types,
902 "Unknown PDU type %#x");
903 if (check_col(pinfo->cinfo, COL_INFO))
904 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
905 length = asn1.offset - start;
907 proto_tree_add_text(tree, tvb, offset, length,
908 "PDU type: %s", pdu_type_string);
912 /* get the fields in the PDU preceeding the variable-bindings sequence */
916 case SNMP_MSG_GETNEXT:
917 case SNMP_MSG_RESPONSE:
919 case SNMP_MSG_GETBULK:
920 case SNMP_MSG_INFORM:
922 case SNMP_MSG_REPORT:
924 ret = asn1_uint32_decode (&asn1, &request_id, &length);
925 if (ret != ASN1_ERR_NOERROR) {
926 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
931 proto_tree_add_text(tree, tvb, offset, length,
932 "Request Id: %#x", request_id);
936 /* error status, or getbulk non-repeaters */
937 ret = asn1_uint32_decode (&asn1, &error_status, &length);
938 if (ret != ASN1_ERR_NOERROR) {
939 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
940 (pdu_type == SNMP_MSG_GETBULK) ? "non-repeaters"
946 if (pdu_type == SNMP_MSG_GETBULK) {
947 proto_tree_add_text(tree, tvb, offset,
948 length, "Non-repeaters: %u", error_status);
950 proto_tree_add_text(tree, tvb, offset,
951 length, "Error Status: %s",
952 val_to_str(error_status, error_statuses,
958 /* error index, or getbulk max-repetitions */
959 ret = asn1_uint32_decode (&asn1, &error_index, &length);
960 if (ret != ASN1_ERR_NOERROR) {
961 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
962 (pdu_type == SNMP_MSG_GETBULK) ? "max repetitions"
968 if (pdu_type == SNMP_MSG_GETBULK) {
969 proto_tree_add_text(tree, tvb, offset,
970 length, "Max repetitions: %u", error_index);
972 proto_tree_add_text(tree, tvb, offset,
973 length, "Error Index: %u", error_index);
981 ret = asn1_oid_decode (&asn1, &enterprise, &enterprise_length,
983 if (ret != ASN1_ERR_NOERROR) {
984 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
985 "enterprise OID", ret);
989 oid_string = format_oid(enterprise, enterprise_length);
990 proto_tree_add_text(tree, tvb, offset, length,
991 "Enterprise: %s", oid_string);
999 ret = asn1_header_decode (&asn1, &cls, &con, &tag,
1000 &def, &agent_address_length);
1001 if (ret != ASN1_ERR_NOERROR) {
1002 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1003 "agent address", ret);
1006 if (!((cls == ASN1_APL && con == ASN1_PRI && tag == SNMP_IPA) ||
1007 (cls == ASN1_UNI && con == ASN1_PRI && tag == ASN1_OTS))) {
1008 /* GXSNMP 0.0.15 says the latter is "needed for
1010 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1011 "agent_address", ASN1_ERR_WRONG_TYPE);
1014 if (agent_address_length != 4) {
1015 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1016 "agent_address", ASN1_ERR_WRONG_LENGTH_FOR_TYPE);
1019 ret = asn1_string_value_decode (&asn1,
1020 agent_address_length, &agent_address);
1021 if (ret != ASN1_ERR_NOERROR) {
1022 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1023 "agent address", ret);
1026 length = asn1.offset - start;
1028 if (agent_address_length != 4) {
1029 proto_tree_add_text(tree, tvb, offset,
1031 "Agent address: <length is %u, not 4>",
1032 agent_address_length);
1034 proto_tree_add_text(tree, tvb, offset,
1036 "Agent address: %s",
1037 ip_to_str(agent_address));
1040 g_free(agent_address);
1043 /* generic trap type */
1044 ret = asn1_uint32_decode (&asn1, &trap_type, &length);
1045 if (ret != ASN1_ERR_NOERROR) {
1046 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1047 "generic trap type", ret);
1051 proto_tree_add_text(tree, tvb, offset, length,
1053 val_to_str(trap_type, trap_types, "Unknown (%u)"));
1057 /* specific trap type */
1058 ret = asn1_uint32_decode (&asn1, &specific_type, &length);
1059 if (ret != ASN1_ERR_NOERROR) {
1060 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1061 "specific trap type", ret);
1065 proto_tree_add_text(tree, tvb, offset, length,
1066 "Specific trap type: %u (%#x)",
1067 specific_type, specific_type);
1072 start = asn1.offset;
1073 ret = asn1_header_decode (&asn1, &cls, &con, &tag,
1074 &def, ×tamp_length);
1075 if (ret != ASN1_ERR_NOERROR) {
1076 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1080 if (!((cls == ASN1_APL && con == ASN1_PRI && tag == SNMP_TIT) ||
1081 (cls == ASN1_UNI && con == ASN1_PRI && tag == ASN1_INT))) {
1082 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1083 "timestamp", ASN1_ERR_WRONG_TYPE);
1086 ret = asn1_uint32_value_decode(&asn1, timestamp_length,
1088 if (ret != ASN1_ERR_NOERROR) {
1089 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1093 length = asn1.offset - start;
1095 proto_tree_add_text(tree, tvb, offset, length,
1096 "Timestamp: %u", timestamp);
1102 /* variable bindings */
1103 /* get header for variable-bindings sequence */
1104 ret = asn1_sequence_decode(&asn1, &variable_bindings_length, &length);
1105 if (ret != ASN1_ERR_NOERROR) {
1106 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1107 "variable bindings header", ret);
1112 /* loop on variable bindings */
1114 while (variable_bindings_length > 0) {
1116 sequence_length = 0;
1119 ret = asn1_sequence_decode(&asn1, &variable_length, &length);
1120 if (ret != ASN1_ERR_NOERROR) {
1121 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1122 "variable binding header", ret);
1125 sequence_length += length;
1127 /* parse object identifier */
1128 ret = asn1_oid_decode (&asn1, &variable_oid,
1129 &variable_oid_length, &length);
1130 if (ret != ASN1_ERR_NOERROR) {
1131 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1132 "variable binding OID", ret);
1135 sequence_length += length;
1138 oid_string = format_oid(variable_oid,
1139 variable_oid_length);
1140 proto_tree_add_text(tree, tvb, offset, sequence_length,
1141 "Object identifier %d: %s", vb_index, oid_string);
1144 offset += sequence_length;
1145 variable_bindings_length -= sequence_length;
1147 /* Parse the variable's value */
1148 ret = snmp_variable_decode(tree, variable_oid,
1149 variable_oid_length, &asn1, offset, &length);
1150 if (ret != ASN1_ERR_NOERROR) {
1151 dissect_snmp_parse_error(tvb, offset, pinfo, tree,
1156 variable_bindings_length -= length;
1160 static const value_string qos_vals[] = {
1161 { 0x0, "No authentication or privacy" },
1162 { 0x1, "Authentication, no privacy" },
1163 { 0x2, "Authentication and privacy" },
1164 { 0x3, "Authentication and privacy" },
1169 dissect_snmp2u_parameters(proto_tree *tree, tvbuff_t *tvb, int offset, int length,
1170 guchar *parameters, int parameters_length)
1173 proto_tree *parameters_tree;
1174 proto_tree *qos_tree;
1179 item = proto_tree_add_text(tree, tvb, offset, length,
1181 parameters_tree = proto_item_add_subtree(item, ett_parameters);
1182 offset += length - parameters_length;
1184 if (parameters_length < 1)
1186 model = *parameters;
1187 proto_tree_add_text(parameters_tree, tvb, offset, 1,
1188 "model: %u", model);
1191 parameters_length -= 1;
1193 /* Unknown model. */
1194 proto_tree_add_text(parameters_tree, tvb, offset,
1195 parameters_length, "parameters: %s",
1196 bytes_to_str(parameters, parameters_length));
1200 if (parameters_length < 1)
1203 item = proto_tree_add_text(parameters_tree, tvb, offset, 1,
1205 qos_tree = proto_item_add_subtree(item, ett_parameters_qos);
1206 proto_tree_add_text(qos_tree, tvb, offset, 1, "%s",
1207 decode_boolean_bitfield(qos, 0x04,
1208 8, "Generation of report PDU allowed",
1209 "Generation of report PDU not allowed"));
1210 proto_tree_add_text(qos_tree, tvb, offset, 1, "%s",
1211 decode_enumerated_bitfield(qos, 0x03,
1212 8, qos_vals, "%s"));
1215 parameters_length -= 1;
1217 if (parameters_length < 12)
1219 proto_tree_add_text(parameters_tree, tvb, offset, 12,
1220 "agentID: %s", bytes_to_str(parameters, 12));
1223 parameters_length -= 12;
1225 if (parameters_length < 4)
1227 proto_tree_add_text(parameters_tree, tvb, offset, 4,
1228 "agentBoots: %u", pntohl(parameters));
1231 parameters_length -= 4;
1233 if (parameters_length < 4)
1235 proto_tree_add_text(parameters_tree, tvb, offset, 4,
1236 "agentTime: %u", pntohl(parameters));
1239 parameters_length -= 4;
1241 if (parameters_length < 2)
1243 proto_tree_add_text(parameters_tree, tvb, offset, 2,
1244 "maxSize: %u", pntohs(parameters));
1247 parameters_length -= 2;
1249 if (parameters_length < 1)
1252 proto_tree_add_text(parameters_tree, tvb, offset, 1,
1253 "userLen: %u", len);
1256 parameters_length -= 1;
1258 if (parameters_length < len)
1260 proto_tree_add_text(parameters_tree, tvb, offset, len,
1261 "userName: %.*s", len, parameters);
1264 parameters_length -= len;
1266 if (parameters_length < 1)
1269 proto_tree_add_text(parameters_tree, tvb, offset, 1,
1270 "authLen: %u", len);
1273 parameters_length -= 1;
1275 if (parameters_length < len)
1277 proto_tree_add_text(parameters_tree, tvb, offset, len,
1278 "authDigest: %s", bytes_to_str(parameters, len));
1281 parameters_length -= len;
1283 if (parameters_length < 1)
1285 proto_tree_add_text(parameters_tree, tvb, offset, parameters_length,
1286 "contextSelector: %s", bytes_to_str(parameters, parameters_length));
1290 dissect_snmp_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
1291 proto_tree *tree, char *proto_name, int proto, gint ett)
1298 guint message_length;
1299 guint global_length;
1305 guint32 engineboots;
1318 int msgflags_length;
1319 int community_length;
1321 int cengineid_length;
1323 int cryptpdu_length;
1324 int aengineid_length;
1325 int username_length;
1332 proto_tree *snmp_tree = NULL;
1333 proto_tree *global_tree = NULL;
1334 proto_tree *flags_tree = NULL;
1335 proto_tree *secur_tree = NULL;
1336 proto_item *item = NULL;
1338 guint cls, con, tag;
1340 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1341 col_add_str(pinfo->cinfo, COL_PROTOCOL, proto_name);
1344 item = proto_tree_add_item(tree, proto, tvb, offset, -1, FALSE);
1345 snmp_tree = proto_item_add_subtree(item, ett);
1348 /* NOTE: we have to parse the message piece by piece, since the
1349 * capture length may be less than the message length: a 'global'
1350 * parsing is likely to fail.
1352 /* parse the SNMP header */
1353 asn1_open(&asn1, tvb, offset);
1354 ret = asn1_sequence_decode(&asn1, &message_length, &length);
1355 if (ret != ASN1_ERR_NOERROR) {
1356 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1357 "message header", ret);
1362 ret = asn1_uint32_decode (&asn1, &version, &length);
1363 if (ret != ASN1_ERR_NOERROR) {
1364 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1365 "version number", ret);
1369 proto_tree_add_text(snmp_tree, tvb, offset, length,
1371 val_to_str(version, versions, "Unknown version %#x"));
1377 case SNMP_VERSION_1:
1378 case SNMP_VERSION_2c:
1379 ret = asn1_octet_string_decode (&asn1, &community,
1380 &community_length, &length);
1381 if (ret != ASN1_ERR_NOERROR) {
1382 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1387 proto_tree_add_text(snmp_tree, tvb, offset, length,
1388 "Community: %.*s", community_length,
1389 SAFE_STRING(community));
1394 case SNMP_VERSION_2u:
1395 ret = asn1_octet_string_decode (&asn1, &community,
1396 &community_length, &length);
1398 dissect_snmp2u_parameters(snmp_tree, tvb, offset, length,
1399 community, community_length);
1404 case SNMP_VERSION_3:
1405 ret = asn1_sequence_decode(&asn1, &global_length, &length);
1406 if (ret != ASN1_ERR_NOERROR) {
1407 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1408 "message global header", ret);
1412 item = proto_tree_add_text(snmp_tree, tvb, offset,
1413 global_length + length, "Message Global Header");
1414 global_tree = proto_item_add_subtree(item, ett_global);
1415 proto_tree_add_text(global_tree, tvb, offset,
1417 "Message Global Header Length: %d", global_length);
1420 ret = asn1_uint32_decode (&asn1, &msgid, &length);
1421 if (ret != ASN1_ERR_NOERROR) {
1422 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1427 proto_tree_add_text(global_tree, tvb, offset,
1428 length, "Message ID: %d", msgid);
1431 ret = asn1_uint32_decode (&asn1, &msgmax, &length);
1432 if (ret != ASN1_ERR_NOERROR) {
1433 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1434 "message max size", ret);
1438 proto_tree_add_text(global_tree, tvb, offset,
1439 length, "Message Max Size: %d", msgmax);
1442 ret = asn1_octet_string_decode (&asn1, &msgflags,
1443 &msgflags_length, &length);
1444 if (ret != ASN1_ERR_NOERROR) {
1445 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1446 "message flags", ret);
1449 if (msgflags_length != 1) {
1450 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1451 "message flags wrong length", ret);
1456 item = proto_tree_add_uint_format(global_tree,
1457 hf_snmpv3_flags, tvb, offset, length,
1458 msgflags[0], "Flags: 0x%02x", msgflags[0]);
1459 flags_tree = proto_item_add_subtree(item, ett_flags);
1460 proto_tree_add_boolean(flags_tree, hf_snmpv3_flags_report,
1461 tvb, offset, length, msgflags[0]);
1462 proto_tree_add_boolean(flags_tree, hf_snmpv3_flags_crypt,
1463 tvb, offset, length, msgflags[0]);
1464 proto_tree_add_boolean(flags_tree, hf_snmpv3_flags_auth,
1465 tvb, offset, length, msgflags[0]);
1467 encrypted = msgflags[0] & TH_CRYPT;
1470 ret = asn1_uint32_decode (&asn1, &msgsec, &length);
1471 if (ret != ASN1_ERR_NOERROR) {
1472 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1473 "message security model", ret);
1477 proto_tree_add_text(global_tree, tvb, offset,
1478 length, "Message Security Model: %s",
1479 val_to_str(msgsec, sec_models,
1480 "Unknown model %#x"));
1485 start = asn1.offset;
1486 ret = asn1_header_decode (&asn1, &cls, &con, &tag,
1487 &def, &secparm_length);
1488 length = asn1.offset - start;
1489 if (cls != ASN1_UNI && con != ASN1_PRI &&
1491 dissect_snmp_parse_error(tvb, offset, pinfo,
1492 snmp_tree, "Message Security Parameters",
1493 ASN1_ERR_WRONG_TYPE);
1497 item = proto_tree_add_text(snmp_tree, tvb,
1498 offset, secparm_length + length,
1499 "Message Security Parameters");
1500 secur_tree = proto_item_add_subtree(item,
1502 proto_tree_add_text(secur_tree, tvb, offset,
1504 "Message Security Parameters Length: %d",
1508 ret = asn1_sequence_decode(&asn1, &secparm_length,
1510 if (ret != ASN1_ERR_NOERROR) {
1511 dissect_snmp_parse_error(tvb, offset, pinfo,
1512 snmp_tree, "USM sequence header", ret);
1516 ret = asn1_octet_string_decode (&asn1, &aengineid,
1517 &aengineid_length, &length);
1518 if (ret != ASN1_ERR_NOERROR) {
1519 dissect_snmp_parse_error(tvb, offset, pinfo,
1520 snmp_tree, "authoritative engine id", ret);
1524 proto_tree_add_text(secur_tree, tvb, offset,
1525 length, "Authoritative Engine ID: %s",
1526 bytes_to_str(aengineid, aengineid_length));
1530 ret = asn1_uint32_decode (&asn1, &engineboots, &length);
1531 if (ret != ASN1_ERR_NOERROR) {
1532 dissect_snmp_parse_error(tvb, offset, pinfo,
1533 snmp_tree, "engine boots", ret);
1537 proto_tree_add_text(secur_tree, tvb,
1538 offset, length, "Engine Boots: %d",
1542 ret = asn1_uint32_decode (&asn1, &enginetime, &length);
1543 if (ret != ASN1_ERR_NOERROR) {
1544 dissect_snmp_parse_error(tvb, offset, pinfo,
1545 snmp_tree, "engine time", ret);
1549 proto_tree_add_text(secur_tree, tvb,
1550 offset, length, "Engine Time: %d",
1554 ret = asn1_octet_string_decode (&asn1, &username,
1555 &username_length, &length);
1556 if (ret != ASN1_ERR_NOERROR) {
1557 dissect_snmp_parse_error(tvb, offset, pinfo,
1558 snmp_tree, "user name", ret);
1562 proto_tree_add_text(secur_tree, tvb, offset,
1563 length, "User Name: %.*s",
1565 SAFE_STRING(username));
1569 ret = asn1_octet_string_decode (&asn1, &authpar,
1570 &authpar_length, &length);
1571 if (ret != ASN1_ERR_NOERROR) {
1572 dissect_snmp_parse_error(tvb, offset, pinfo,
1573 snmp_tree, "authentication parameter", ret);
1577 proto_tree_add_text(secur_tree, tvb, offset,
1578 length, "Authentication Parameter: %s",
1579 bytes_to_str(authpar, authpar_length));
1583 ret = asn1_octet_string_decode (&asn1, &privpar,
1584 &privpar_length, &length);
1585 if (ret != ASN1_ERR_NOERROR) {
1586 dissect_snmp_parse_error(tvb, offset, pinfo,
1587 snmp_tree, "privacy parameter", ret);
1591 proto_tree_add_text(secur_tree, tvb, offset,
1592 length, "Privacy Parameter: %s",
1593 bytes_to_str(privpar, privpar_length));
1599 ret = asn1_octet_string_decode (&asn1,
1600 &secparm, &secparm_length, &length);
1601 if (ret != ASN1_ERR_NOERROR) {
1602 dissect_snmp_parse_error(tvb, offset, pinfo,
1603 snmp_tree, "Message Security Parameters",
1608 proto_tree_add_text(snmp_tree, tvb, offset,
1610 "Message Security Parameters Data"
1611 " (%d bytes)", secparm_length);
1617 /* PDU starts here */
1619 ret = asn1_octet_string_decode (&asn1, &cryptpdu,
1620 &cryptpdu_length, &length);
1621 if (ret != ASN1_ERR_NOERROR) {
1622 dissect_snmp_parse_error(tvb, offset, pinfo,
1623 snmp_tree, "encrypted PDU header", ret);
1626 proto_tree_add_text(snmp_tree, tvb, offset, length,
1627 "Encrypted PDU (%d bytes)", length);
1629 if (check_col(pinfo->cinfo, COL_INFO))
1630 col_set_str(pinfo->cinfo, COL_INFO, "Encrypted PDU");
1633 ret = asn1_sequence_decode(&asn1, &global_length, &length);
1634 if (ret != ASN1_ERR_NOERROR) {
1635 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1640 ret = asn1_octet_string_decode (&asn1, &cengineid,
1641 &cengineid_length, &length);
1642 if (ret != ASN1_ERR_NOERROR) {
1643 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1644 "context engine id", ret);
1648 proto_tree_add_text(snmp_tree, tvb, offset, length,
1649 "Context Engine ID: %s",
1650 bytes_to_str(cengineid, cengineid_length));
1654 ret = asn1_octet_string_decode (&asn1, &cname,
1655 &cname_length, &length);
1656 if (ret != ASN1_ERR_NOERROR) {
1657 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1658 "context name", ret);
1662 proto_tree_add_text(snmp_tree, tvb, offset, length,
1663 "Context Name: %.*s", cname_length,
1664 SAFE_STRING(cname));
1670 dissect_snmp_error(tvb, offset, pinfo, snmp_tree,
1671 "PDU for unknown version of SNMP");
1675 start = asn1.offset;
1676 ret = asn1_header_decode (&asn1, &cls, &con, &pdu_type, &def,
1678 if (ret != ASN1_ERR_NOERROR) {
1679 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1683 if (cls != ASN1_CTX || con != ASN1_CON) {
1684 dissect_snmp_parse_error(tvb, offset, pinfo, snmp_tree,
1685 "PDU type", ASN1_ERR_WRONG_TYPE);
1688 dissect_common_pdu(tvb, offset, pinfo, snmp_tree, asn1, pdu_type, start);
1692 dissect_smux_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
1693 proto_tree *tree, int proto, gint ett)
1701 char *pdu_type_string;
1711 int password_length;
1713 guchar *application;
1714 int application_length;
1721 proto_tree *smux_tree = NULL;
1722 proto_item *item = NULL;
1726 if (check_col(pinfo->cinfo, COL_PROTOCOL))
1727 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMUX");
1730 item = proto_tree_add_item(tree, proto, tvb, offset, -1, FALSE);
1731 smux_tree = proto_item_add_subtree(item, ett);
1734 /* NOTE: we have to parse the message piece by piece, since the
1735 * capture length may be less than the message length: a 'global'
1736 * parsing is likely to fail.
1738 /* parse the SNMP header */
1739 asn1_open(&asn1, tvb, offset);
1740 start = asn1.offset;
1741 ret = asn1_header_decode (&asn1, &cls, &con, &pdu_type, &def,
1743 if (ret != ASN1_ERR_NOERROR) {
1744 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1749 /* Dissect SMUX here */
1750 if (cls == ASN1_APL && con == ASN1_CON && pdu_type == SMUX_MSG_OPEN) {
1751 pdu_type_string = val_to_str(pdu_type, smux_types,
1752 "Unknown PDU type %#x");
1753 if (check_col(pinfo->cinfo, COL_INFO))
1754 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
1755 length = asn1.offset - start;
1757 proto_tree_add_text(smux_tree, tvb, offset, length,
1758 "PDU type: %s", pdu_type_string);
1761 ret = asn1_uint32_decode (&asn1, &version, &length);
1762 if (ret != ASN1_ERR_NOERROR) {
1763 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1768 proto_tree_add_text(smux_tree, tvb, offset, length,
1769 "Version: %d", version);
1773 ret = asn1_oid_decode (&asn1, ®id, ®id_length, &length);
1774 if (ret != ASN1_ERR_NOERROR) {
1775 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1776 "registration OID", ret);
1780 oid_string = format_oid(regid, regid_length);
1781 proto_tree_add_text(smux_tree, tvb, offset, length,
1782 "Registration: %s", oid_string);
1788 ret = asn1_octet_string_decode (&asn1, &application,
1789 &application_length, &length);
1790 if (ret != ASN1_ERR_NOERROR) {
1791 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1792 "application", ret);
1796 proto_tree_add_text(smux_tree, tvb, offset, length,
1797 "Application: %.*s", application_length,
1798 SAFE_STRING(application));
1800 g_free(application);
1803 ret = asn1_octet_string_decode (&asn1, &password,
1804 &password_length, &length);
1805 if (ret != ASN1_ERR_NOERROR) {
1806 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1811 proto_tree_add_text(smux_tree, tvb, offset, length,
1812 "Password: %.*s", password_length,
1813 SAFE_STRING(password));
1819 if (cls == ASN1_APL && con == ASN1_PRI && pdu_type == SMUX_MSG_CLOSE) {
1820 pdu_type_string = val_to_str(pdu_type, smux_types,
1821 "Unknown PDU type %#x");
1822 if (check_col(pinfo->cinfo, COL_INFO))
1823 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
1824 length = asn1.offset - start;
1826 proto_tree_add_text(smux_tree, tvb, offset, length,
1827 "PDU type: %s", pdu_type_string);
1830 ret = asn1_uint32_value_decode (&asn1, pdu_length, &cause);
1831 if (ret != ASN1_ERR_NOERROR) {
1832 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1837 proto_tree_add_text(smux_tree, tvb, offset,
1838 pdu_length, "Cause: %s",
1839 val_to_str(cause, smux_close,
1840 "Unknown cause %#x"));
1842 offset += pdu_length;
1845 if (cls == ASN1_APL && con == ASN1_CON && pdu_type == SMUX_MSG_RREQ) {
1846 pdu_type_string = val_to_str(pdu_type, smux_types,
1847 "Unknown PDU type %#x");
1848 if (check_col(pinfo->cinfo, COL_INFO))
1849 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
1850 length = asn1.offset - start;
1852 proto_tree_add_text(smux_tree, tvb, offset, length,
1853 "PDU type: %s", pdu_type_string);
1856 ret = asn1_oid_decode (&asn1, ®id, ®id_length, &length);
1857 if (ret != ASN1_ERR_NOERROR) {
1858 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1859 "registration subtree", ret);
1863 oid_string = format_oid(regid, regid_length);
1864 proto_tree_add_text(smux_tree, tvb, offset, length,
1865 "Registration: %s", oid_string);
1871 ret = asn1_uint32_decode (&asn1, &priority, &length);
1872 if (ret != ASN1_ERR_NOERROR) {
1873 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1878 proto_tree_add_text(smux_tree, tvb, offset, length,
1879 "Priority: %d", priority);
1883 ret = asn1_uint32_decode (&asn1, &operation, &length);
1884 if (ret != ASN1_ERR_NOERROR) {
1885 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1890 proto_tree_add_text(smux_tree, tvb, offset, length,
1892 val_to_str(operation, smux_rreq,
1893 "Unknown operation %#x"));
1898 if (cls == ASN1_APL && con == ASN1_PRI && pdu_type == SMUX_MSG_RRSP) {
1899 pdu_type_string = val_to_str(pdu_type, smux_types,
1900 "Unknown PDU type %#x");
1901 if (check_col(pinfo->cinfo, COL_INFO))
1902 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
1903 length = asn1.offset - start;
1905 proto_tree_add_text(smux_tree, tvb, offset, length,
1906 "PDU type: %s", pdu_type_string);
1909 ret = asn1_uint32_value_decode (&asn1, pdu_length, &priority);
1910 if (ret != ASN1_ERR_NOERROR) {
1911 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1916 proto_tree_add_text(smux_tree, tvb, offset,
1918 val_to_str(priority, smux_prio,
1921 offset += pdu_length;
1924 if (cls == ASN1_APL && con == ASN1_PRI && pdu_type == SMUX_MSG_SOUT) {
1925 pdu_type_string = val_to_str(pdu_type, smux_types,
1926 "Unknown PDU type %#x");
1927 if (check_col(pinfo->cinfo, COL_INFO))
1928 col_add_str(pinfo->cinfo, COL_INFO, pdu_type_string);
1929 length = asn1.offset - start;
1931 proto_tree_add_text(smux_tree, tvb, offset, length,
1932 "PDU type: %s", pdu_type_string);
1935 ret = asn1_uint32_value_decode (&asn1, pdu_length, &commit);
1936 if (ret != ASN1_ERR_NOERROR) {
1937 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1942 proto_tree_add_text(smux_tree, tvb, offset,
1944 val_to_str(commit, smux_sout,
1945 "Unknown SOUT Value: %#x"));
1947 offset += pdu_length;
1950 if (cls != ASN1_CTX || con != ASN1_CON) {
1951 dissect_snmp_parse_error(tvb, offset, pinfo, smux_tree,
1952 "PDU type", ASN1_ERR_WRONG_TYPE);
1955 dissect_common_pdu(tvb, offset, pinfo, smux_tree, asn1, pdu_type, start);
1959 dissect_snmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1961 conversation_t *conversation;
1964 * The first SNMP packet goes to the SNMP port; the second one
1965 * may come from some *other* port, but goes back to the same
1966 * IP address and port as the ones from which the first packet
1967 * came; all subsequent packets presumably go between those two
1968 * IP addresses and ports.
1970 * If this packet went to the SNMP port, we check to see if
1971 * there's already a conversation with one address/port pair
1972 * matching the source IP address and port of this packet,
1973 * the other address matching the destination IP address of this
1974 * packet, and any destination port.
1976 * If not, we create one, with its address 1/port 1 pair being
1977 * the source address/port of this packet, its address 2 being
1978 * the destination address of this packet, and its port 2 being
1979 * wildcarded, and give it the SNMP dissector as a dissector.
1981 if (pinfo->destport == UDP_PORT_SNMP) {
1982 conversation = find_conversation(&pinfo->src, &pinfo->dst, PT_UDP,
1983 pinfo->srcport, 0, NO_PORT_B);
1984 if (conversation == NULL) {
1985 conversation = conversation_new(&pinfo->src, &pinfo->dst, PT_UDP,
1986 pinfo->srcport, 0, NO_PORT2);
1987 conversation_set_dissector(conversation, snmp_handle);
1991 dissect_snmp_pdu(tvb, 0, pinfo, tree, "SNMP", proto_snmp, ett_snmp);
1995 dissect_smux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1997 dissect_smux_pdu(tvb, 0, pinfo, tree, proto_smux, ett_smux);
2001 proto_register_snmp(void)
2003 static hf_register_info hf[] = {
2005 { "SNMPv3 Flags", "snmpv3.flags", FT_UINT8, BASE_HEX, NULL,
2007 { &hf_snmpv3_flags_auth,
2008 { "Authenticated", "snmpv3.flags.auth", FT_BOOLEAN, 8,
2009 TFS(&flags_set_truth), TH_AUTH, "", HFILL }},
2010 { &hf_snmpv3_flags_crypt,
2011 { "Encrypted", "snmpv3.flags.crypt", FT_BOOLEAN, 8,
2012 TFS(&flags_set_truth), TH_CRYPT, "", HFILL }},
2013 { &hf_snmpv3_flags_report,
2014 { "Reportable", "snmpv3.flags.report", FT_BOOLEAN, 8,
2015 TFS(&flags_set_truth), TH_REPORT, "", HFILL }},
2017 static gint *ett[] = {
2021 &ett_parameters_qos,
2027 #ifdef HAVE_UCD_SNMP
2029 * Suppress warnings about unknown tokens - we aren't initializing
2030 * UCD SNMP in its entirety, we're just initializing the
2031 * MIB-handling part because that's all we're using, which
2032 * means that entries in the configuration file for other
2033 * pars of the library will not be handled, and we don't want
2034 * the config file reading code to whine about that.
2036 ds_set_boolean(DS_LIBRARY_ID, DS_LIB_NO_TOKEN_WARNINGS, TRUE);
2037 ds_set_int(DS_LIBRARY_ID, DS_LIB_PRINT_SUFFIX_ONLY, 2);
2038 register_mib_handlers();
2039 read_premib_configs();
2042 #endif /* HAVE_UCD_SNMP */
2043 proto_snmp = proto_register_protocol("Simple Network Management Protocol",
2045 proto_smux = proto_register_protocol("SNMP Multiplex Protocol",
2047 proto_register_field_array(proto_snmp, hf, array_length(hf));
2048 proto_register_subtree_array(ett, array_length(ett));
2049 snmp_handle = create_dissector_handle(dissect_snmp, proto_snmp);
2053 proto_reg_handoff_snmp(void)
2055 dissector_handle_t smux_handle;
2057 dissector_add("udp.port", UDP_PORT_SNMP, snmp_handle);
2058 dissector_add("udp.port", UDP_PORT_SNMP_TRAP, snmp_handle);
2059 smux_handle = create_dissector_handle(dissect_smux, proto_smux);
2060 dissector_add("tcp.port", TCP_PORT_SMUX, smux_handle);
2061 dissector_add("ethertype", ETHERTYPE_SNMP, snmp_handle);
2062 dissector_add("ipx.socket", IPX_SOCKET_SNMP_AGENT, snmp_handle);
2063 dissector_add("ipx.socket", IPX_SOCKET_SNMP_SINK, snmp_handle);
2064 data_handle = find_dissector("data");