1 /* Do not modify this file. */
2 /* It is created automatically by the ASN.1 to Wireshark dissector compiler */
4 /* ../../tools/asn2wrs.py -b -p snmp -c ./snmp.cnf -s ./packet-snmp-template -D . snmp.asn */
6 /* Input file: packet-snmp-template.c */
8 #line 1 "../../asn1/snmp/packet-snmp-template.c"
10 * Routines for SNMP (simple network management protocol)
11 * Copyright (C) 1998 Didier Jorand
13 * See RFC 1157 for SNMPv1.
15 * See RFCs 1901, 1905, and 1906 for SNMPv2c.
17 * See RFCs 1905, 1906, 1909, and 1910 for SNMPv2u [historic].
19 * See RFCs 2570-2576 for SNMPv3
20 * Updated to use the asn2wrs compiler made by Tomas Kukosa
21 * Copyright (C) 2005 - 2006 Anders Broman [AT] ericsson.com
23 * See RFC 3414 for User-based Security Model for SNMPv3
24 * See RFC 3826 for (AES) Cipher Algorithm in the SNMP USM
25 * See RFC 2578 for Structure of Management Information Version 2 (SMIv2)
26 * Copyright (C) 2007 Luis E. Garcia Ontanon <luis@ontanon.org>
30 * Wireshark - Network traffic analyzer
31 * By Gerald Combs <gerald@wireshark.org>
32 * Copyright 1998 Gerald Combs
36 * GXSNMP -- An snmp mangament application
37 * Copyright (C) 1998 Gregory McLean & Jochen Friedrich
38 * Beholder RMON ethernet network monitor,Copyright (C) 1993 DNPAP group
40 * This program is free software; you can redistribute it and/or
41 * modify it under the terms of the GNU General Public License
42 * as published by the Free Software Foundation; either version 2
43 * of the License, or (at your option) any later version.
45 * This program is distributed in the hope that it will be useful,
46 * but WITHOUT ANY WARRANTY; without even the implied warranty of
47 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48 * GNU General Public License for more details.
50 * You should have received a copy of the GNU General Public License
51 * along with this program; if not, write to the Free Software
52 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
55 #define D(args) do {printf args; fflush(stdout); } while(0)
66 #include <epan/packet.h>
67 #include <epan/strutil.h>
68 #include <epan/conversation.h>
69 #include <epan/etypes.h>
70 #include <epan/prefs.h>
71 #include <epan/sminmpec.h>
72 #include <epan/emem.h>
73 #include <epan/next_tvb.h>
75 #include <epan/asn1.h>
76 #include "packet-ipx.h"
77 #include "packet-hpext.h"
80 #include "packet-ber.h"
82 #include "packet-snmp.h"
84 #include <epan/crypt/crypt-sha1.h>
85 #include <epan/crypt/crypt-md5.h>
86 #include <epan/expert.h>
87 #include <epan/report_err.h>
88 #include <epan/oids.h>
95 /* Take a pointer that may be null and return a pointer that's not null
96 by turning null pointers into pointers to the above null string,
97 and, if the argument pointer wasn't null, make sure we handle
98 non-printable characters in the string by escaping them. */
99 #define SAFE_STRING(s, l) (((s) != NULL) ? format_text((s), (l)) : "")
101 #define PNAME "Simple Network Management Protocol"
102 #define PSNAME "SNMP"
103 #define PFNAME "snmp"
105 #define UDP_PORT_SNMP 161
106 #define UDP_PORT_SNMP_TRAP 162
107 #define TCP_PORT_SNMP 161
108 #define TCP_PORT_SNMP_TRAP 162
109 #define TCP_PORT_SMUX 199
110 #define UDP_PORT_SNMP_PATROL 8161
112 /* Initialize the protocol and registered fields */
113 static int proto_snmp = -1;
114 static int proto_smux = -1;
116 static gboolean display_oid = TRUE;
117 static gboolean snmp_var_in_tree = TRUE;
119 static gboolean snmp_usm_auth_md5(snmp_usm_params_t* p, guint8**, guint*, gchar const**);
120 static gboolean snmp_usm_auth_sha1(snmp_usm_params_t* p, guint8**, guint*, gchar const**);
122 static tvbuff_t* snmp_usm_priv_des(snmp_usm_params_t*, tvbuff_t*, gchar const**);
123 static tvbuff_t* snmp_usm_priv_aes(snmp_usm_params_t*, tvbuff_t*, gchar const**);
126 static void snmp_usm_password_to_key_md5(const guint8 *password, guint passwordlen, const guint8 *engineID, guint engineLength, guint8 *key);
127 static void snmp_usm_password_to_key_sha1(const guint8 *password, guint passwordlen, const guint8 *engineID, guint engineLength, guint8 *key);
130 static snmp_usm_auth_model_t model_md5 = {snmp_usm_password_to_key_md5, snmp_usm_auth_md5, 16};
131 static snmp_usm_auth_model_t model_sha1 = {snmp_usm_password_to_key_sha1, snmp_usm_auth_sha1, 20};
133 static const value_string auth_types[] = {
138 static snmp_usm_auth_model_t* auth_models[] = {&model_md5,&model_sha1};
141 static const value_string priv_types[] = {
146 static snmp_usm_decoder_t priv_protos[] = {snmp_usm_priv_des, snmp_usm_priv_aes};
148 static snmp_ue_assoc_t* ueas = NULL;
149 static guint num_ueas = 0;
150 static snmp_ue_assoc_t* localized_ues = NULL;
151 static snmp_ue_assoc_t* unlocalized_ues = NULL;
154 /* Variabled used for handling enterprise spesific trap types */
155 typedef struct _snmp_st_assoc_t {
160 static guint num_specific_traps = 0;
161 static snmp_st_assoc_t *specific_traps = NULL;
162 static const char *enterprise_oid = NULL;
163 static guint generic_trap = 0;
166 static snmp_usm_params_t usm_p = {FALSE,FALSE,0,0,0,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,FALSE};
169 #define TH_CRYPT 0x02
170 #define TH_REPORT 0x04
172 /* desegmentation of SNMP-over-TCP */
173 static gboolean snmp_desegment = TRUE;
175 /* Global variables */
177 guint32 MsgSecurityModel;
178 tvbuff_t *oid_tvb=NULL;
179 tvbuff_t *value_tvb=NULL;
181 static dissector_handle_t snmp_handle;
182 static dissector_handle_t data_handle;
184 static next_tvb_list_t var_list;
186 static int hf_snmp_v3_flags_auth = -1;
187 static int hf_snmp_v3_flags_crypt = -1;
188 static int hf_snmp_v3_flags_report = -1;
190 static int hf_snmp_engineid_conform = -1;
191 static int hf_snmp_engineid_enterprise = -1;
192 static int hf_snmp_engineid_format = -1;
193 static int hf_snmp_engineid_ipv4 = -1;
194 static int hf_snmp_engineid_ipv6 = -1;
195 static int hf_snmp_engineid_cisco_type = -1;
196 static int hf_snmp_engineid_mac = -1;
197 static int hf_snmp_engineid_text = -1;
198 static int hf_snmp_engineid_time = -1;
199 static int hf_snmp_engineid_data = -1;
200 static int hf_snmp_decryptedPDU = -1;
201 static int hf_snmp_msgAuthentication = -1;
203 static int hf_snmp_noSuchObject = -1;
204 static int hf_snmp_noSuchInstance = -1;
205 static int hf_snmp_endOfMibView = -1;
206 static int hf_snmp_unSpecified = -1;
208 static int hf_snmp_integer32_value = -1;
209 static int hf_snmp_octetstring_value = -1;
210 static int hf_snmp_oid_value = -1;
211 static int hf_snmp_null_value = -1;
212 static int hf_snmp_ipv4_value = -1;
213 static int hf_snmp_ipv6_value = -1;
214 static int hf_snmp_anyaddress_value = -1;
215 static int hf_snmp_unsigned32_value = -1;
216 static int hf_snmp_unknown_value = -1;
217 static int hf_snmp_opaque_value = -1;
218 static int hf_snmp_nsap_value = -1;
219 static int hf_snmp_counter_value = -1;
220 static int hf_snmp_timeticks_value = -1;
221 static int hf_snmp_big_counter_value = -1;
222 static int hf_snmp_gauge32_value = -1;
224 static int hf_snmp_objectname = -1;
225 static int hf_snmp_scalar_instance_index = -1;
229 /*--- Included file: packet-snmp-hf.c ---*/
230 #line 1 "../../asn1/snmp/packet-snmp-hf.c"
231 static int hf_snmp_SMUX_PDUs_PDU = -1; /* SMUX_PDUs */
232 static int hf_snmp_version = -1; /* Version */
233 static int hf_snmp_community = -1; /* Community */
234 static int hf_snmp_data = -1; /* PDUs */
235 static int hf_snmp_parameters = -1; /* OCTET_STRING */
236 static int hf_snmp_datav2u = -1; /* T_datav2u */
237 static int hf_snmp_v2u_plaintext = -1; /* PDUs */
238 static int hf_snmp_encrypted = -1; /* OCTET_STRING */
239 static int hf_snmp_msgAuthoritativeEngineID = -1; /* T_msgAuthoritativeEngineID */
240 static int hf_snmp_msgAuthoritativeEngineBoots = -1; /* T_msgAuthoritativeEngineBoots */
241 static int hf_snmp_msgAuthoritativeEngineTime = -1; /* T_msgAuthoritativeEngineTime */
242 static int hf_snmp_msgUserName = -1; /* T_msgUserName */
243 static int hf_snmp_msgAuthenticationParameters = -1; /* T_msgAuthenticationParameters */
244 static int hf_snmp_msgPrivacyParameters = -1; /* T_msgPrivacyParameters */
245 static int hf_snmp_msgVersion = -1; /* Version */
246 static int hf_snmp_msgGlobalData = -1; /* HeaderData */
247 static int hf_snmp_msgSecurityParameters = -1; /* T_msgSecurityParameters */
248 static int hf_snmp_msgData = -1; /* ScopedPduData */
249 static int hf_snmp_msgID = -1; /* INTEGER_0_2147483647 */
250 static int hf_snmp_msgMaxSize = -1; /* INTEGER_484_2147483647 */
251 static int hf_snmp_msgFlags = -1; /* T_msgFlags */
252 static int hf_snmp_msgSecurityModel = -1; /* T_msgSecurityModel */
253 static int hf_snmp_plaintext = -1; /* ScopedPDU */
254 static int hf_snmp_encryptedPDU = -1; /* T_encryptedPDU */
255 static int hf_snmp_contextEngineID = -1; /* SnmpEngineID */
256 static int hf_snmp_contextName = -1; /* OCTET_STRING */
257 static int hf_snmp_get_request = -1; /* GetRequest_PDU */
258 static int hf_snmp_get_next_request = -1; /* GetNextRequest_PDU */
259 static int hf_snmp_get_response = -1; /* GetResponse_PDU */
260 static int hf_snmp_set_request = -1; /* SetRequest_PDU */
261 static int hf_snmp_trap = -1; /* Trap_PDU */
262 static int hf_snmp_getBulkRequest = -1; /* GetBulkRequest_PDU */
263 static int hf_snmp_informRequest = -1; /* InformRequest_PDU */
264 static int hf_snmp_sNMPv2_Trap = -1; /* SNMPv2_Trap_PDU */
265 static int hf_snmp_report = -1; /* Report_PDU */
266 static int hf_snmp_request_id = -1; /* INTEGER */
267 static int hf_snmp_error_status = -1; /* T_error_status */
268 static int hf_snmp_error_index = -1; /* INTEGER */
269 static int hf_snmp_variable_bindings = -1; /* VarBindList */
270 static int hf_snmp_bulkPDU_request_id = -1; /* Integer32 */
271 static int hf_snmp_non_repeaters = -1; /* INTEGER_0_2147483647 */
272 static int hf_snmp_max_repetitions = -1; /* INTEGER_0_2147483647 */
273 static int hf_snmp_enterprise = -1; /* EnterpriseOID */
274 static int hf_snmp_agent_addr = -1; /* NetworkAddress */
275 static int hf_snmp_generic_trap = -1; /* GenericTrap */
276 static int hf_snmp_specific_trap = -1; /* SpecificTrap */
277 static int hf_snmp_time_stamp = -1; /* TimeTicks */
278 static int hf_snmp_name = -1; /* ObjectName */
279 static int hf_snmp_valueType = -1; /* NULL */
280 static int hf_snmp_VarBindList_item = -1; /* VarBind */
281 static int hf_snmp_open = -1; /* OpenPDU */
282 static int hf_snmp_close = -1; /* ClosePDU */
283 static int hf_snmp_registerRequest = -1; /* RReqPDU */
284 static int hf_snmp_registerResponse = -1; /* RegisterResponse */
285 static int hf_snmp_commitOrRollback = -1; /* SOutPDU */
286 static int hf_snmp_rRspPDU = -1; /* RRspPDU */
287 static int hf_snmp_pDUs = -1; /* PDUs */
288 static int hf_snmp_smux_simple = -1; /* SimpleOpen */
289 static int hf_snmp_smux_version = -1; /* T_smux_version */
290 static int hf_snmp_identity = -1; /* OBJECT_IDENTIFIER */
291 static int hf_snmp_description = -1; /* DisplayString */
292 static int hf_snmp_password = -1; /* OCTET_STRING */
293 static int hf_snmp_subtree = -1; /* ObjectName */
294 static int hf_snmp_priority = -1; /* INTEGER_M1_2147483647 */
295 static int hf_snmp_operation = -1; /* T_operation */
297 /*--- End of included file: packet-snmp-hf.c ---*/
298 #line 221 "../../asn1/snmp/packet-snmp-template.c"
300 static int hf_smux_version = -1;
301 static int hf_smux_pdutype = -1;
303 /* Initialize the subtree pointers */
304 static gint ett_smux = -1;
305 static gint ett_snmp = -1;
306 static gint ett_engineid = -1;
307 static gint ett_msgFlags = -1;
308 static gint ett_encryptedPDU = -1;
309 static gint ett_decrypted = -1;
310 static gint ett_authParameters = -1;
311 static gint ett_internet = -1;
312 static gint ett_varbind = -1;
313 static gint ett_name = -1;
314 static gint ett_value = -1;
315 static gint ett_decoding_error = -1;
318 /*--- Included file: packet-snmp-ett.c ---*/
319 #line 1 "../../asn1/snmp/packet-snmp-ett.c"
320 static gint ett_snmp_Message = -1;
321 static gint ett_snmp_Messagev2u = -1;
322 static gint ett_snmp_T_datav2u = -1;
323 static gint ett_snmp_UsmSecurityParameters = -1;
324 static gint ett_snmp_SNMPv3Message = -1;
325 static gint ett_snmp_HeaderData = -1;
326 static gint ett_snmp_ScopedPduData = -1;
327 static gint ett_snmp_ScopedPDU = -1;
328 static gint ett_snmp_PDUs = -1;
329 static gint ett_snmp_PDU = -1;
330 static gint ett_snmp_BulkPDU = -1;
331 static gint ett_snmp_Trap_PDU_U = -1;
332 static gint ett_snmp_VarBind = -1;
333 static gint ett_snmp_VarBindList = -1;
334 static gint ett_snmp_SMUX_PDUs = -1;
335 static gint ett_snmp_RegisterResponse = -1;
336 static gint ett_snmp_OpenPDU = -1;
337 static gint ett_snmp_SimpleOpen_U = -1;
338 static gint ett_snmp_RReqPDU_U = -1;
340 /*--- End of included file: packet-snmp-ett.c ---*/
341 #line 240 "../../asn1/snmp/packet-snmp-template.c"
343 static const true_false_string auth_flags = {
348 /* Security Models */
350 #define SNMP_SEC_ANY 0
351 #define SNMP_SEC_V1 1
352 #define SNMP_SEC_V2C 2
353 #define SNMP_SEC_USM 3
355 static const value_string sec_models[] = {
356 { SNMP_SEC_ANY, "Any" },
357 { SNMP_SEC_V1, "V1" },
358 { SNMP_SEC_V2C, "V2C" },
359 { SNMP_SEC_USM, "USM" },
364 #define SMUX_MSG_OPEN 0
365 #define SMUX_MSG_CLOSE 1
366 #define SMUX_MSG_RREQ 2
367 #define SMUX_MSG_RRSP 3
368 #define SMUX_MSG_SOUT 4
370 static const value_string smux_types[] = {
371 { SMUX_MSG_OPEN, "Open" },
372 { SMUX_MSG_CLOSE, "Close" },
373 { SMUX_MSG_RREQ, "Registration Request" },
374 { SMUX_MSG_RRSP, "Registration Response" },
375 { SMUX_MSG_SOUT, "Commit Or Rollback" },
380 #define SNMP_IPA 0 /* IP Address */
381 #define SNMP_CNT 1 /* Counter (Counter32) */
382 #define SNMP_GGE 2 /* Gauge (Gauge32) */
383 #define SNMP_TIT 3 /* TimeTicks */
384 #define SNMP_OPQ 4 /* Opaque */
385 #define SNMP_NSP 5 /* NsapAddress */
386 #define SNMP_C64 6 /* Counter64 */
387 #define SNMP_U32 7 /* Uinteger32 */
394 dissector_table_t value_sub_dissectors_table;
398 snmp_lookup_specific_trap (guint specific_trap)
402 for (i = 0; i < num_specific_traps; i++) {
403 snmp_st_assoc_t *u = &(specific_traps[i]);
405 if ((u->trap == specific_trap) &&
406 (strcmp (u->enterprise, enterprise_oid) == 0))
416 * dissect_snmp_VarBind
417 * this routine dissects variable bindings, looking for the oid information in our oid reporsitory
418 * to format and add the value adequatelly.
420 * The choice to handwrite this code instead of using the asn compiler is to avoid having tons
421 * of uses of global variables distributed in very different parts of the code.
422 * Other than that there's a cosmetic thing: the tree from ASN generated code would be so
423 * convoluted due to the nesting of CHOICEs in the definition of VarBind/value.
425 * XXX: the length of this function (~400 lines) is an aberration!
426 * oid_key_t:key_type could become a series of callbacks instead of an enum
427 * the (! oid_info_is_ok) switch could be made into an array (would be slower)
430 NetworkAddress ::= CHOICE { internet IpAddress }
431 IpAddress ::= [APPLICATION 0] IMPLICIT OCTET STRING (SIZE (4))
432 TimeTicks ::= [APPLICATION 3] IMPLICIT INTEGER (0..4294967295)
433 Integer32 ::= INTEGER (-2147483648..2147483647)
434 ObjectName ::= OBJECT IDENTIFIER
435 Counter32 ::= [APPLICATION 1] IMPLICIT INTEGER (0..4294967295)
436 Gauge32 ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295)
437 Unsigned32 ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295)
438 Integer-value ::= INTEGER (-2147483648..2147483647)
439 Integer32 ::= INTEGER (-2147483648..2147483647)
440 ObjectID-value ::= OBJECT IDENTIFIER
442 TimeTicks ::= [APPLICATION 3] IMPLICIT INTEGER (0..4294967295)
443 Opaque ::= [APPLICATION 4] IMPLICIT OCTET STRING
444 Counter64 ::= [APPLICATION 6] IMPLICIT INTEGER (0..18446744073709551615)
446 ObjectSyntax ::= CHOICE {
448 application-wide ApplicationSyntax
451 SimpleSyntax ::= CHOICE {
452 integer-value Integer-value,
453 string-value String-value,
454 objectID-value ObjectID-value,
458 ApplicationSyntax ::= CHOICE {
459 ipAddress-value IpAddress,
460 counter-value Counter32,
461 timeticks-value TimeTicks,
462 arbitrary-value Opaque,
463 big-counter-value Counter64,
464 unsigned-integer-value Unsigned32
467 ValueType ::= CHOICE {
470 noSuchObject[0] IMPLICIT NULL,
471 noSuchInstance[1] IMPLICIT NULL,
472 endOfMibView[2] IMPLICIT NULL
475 VarBind ::= SEQUENCE {
483 dissect_snmp_VarBind(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset,
484 asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_)
486 int seq_offset, name_offset, value_offset, value_start;
487 guint32 seq_len, name_len, value_len;
494 oid_info_t* oid_info = NULL;
495 guint oid_matched, oid_left;
496 proto_item *pi_name, *pi_varbind, *pi_value = NULL;
497 proto_tree *pt, *pt_varbind, *pt_name, *pt_value;
498 char label[ITEM_LABEL_LENGTH];
499 const char* repr = NULL;
500 const char* info_oid = NULL;
503 int min_len = 0, max_len = 0;
504 gboolean oid_info_is_ok;
505 const char* oid_string = NULL;
506 enum {BER_NO_ERROR, BER_WRONG_LENGTH, BER_WRONG_TAG} format_error = BER_NO_ERROR;
510 /* first have the VarBind's sequence header */
511 offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
512 offset = get_ber_length(tvb, offset, &seq_len, &ind);
514 seq_len += offset - seq_offset;
516 if (!pc && ber_class==BER_CLASS_UNI && tag==BER_UNI_TAG_SEQUENCE) {
517 proto_item* pi = proto_tree_add_text(tree, tvb, seq_offset, seq_len,"VarBind must be an universal class sequence");
518 pt = proto_item_add_subtree(pi,ett_decoding_error);
519 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "VarBind is not an universal class sequence");
520 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
524 proto_item* pi = proto_tree_add_text(tree, tvb, seq_offset, seq_len,"Indicator must be clear in VarBind");
525 pt = proto_item_add_subtree(pi,ett_decoding_error);
526 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "VarBind has indicator set");
527 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
530 /* then we have the ObjectName's header */
532 offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
533 name_offset = offset = get_ber_length(tvb, offset, &name_len, &ind);
535 if (! ( !pc && ber_class==BER_CLASS_UNI && tag==BER_UNI_TAG_OID) ) {
536 proto_item* pi = proto_tree_add_text(tree, tvb, seq_offset, seq_len,"ObjectName must be an OID in primitive encoding");
537 pt = proto_item_add_subtree(pi,ett_decoding_error);
538 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "ObjectName not an OID");
539 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
543 proto_item* pi = proto_tree_add_text(tree, tvb, seq_offset, seq_len,"Indicator must be clear in ObjectName");
544 pt = proto_item_add_subtree(pi,ett_decoding_error);
545 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "ObjectName has indicator set");
546 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
550 value_start = offset;
552 /* then we have the value's header */
553 offset = get_ber_identifier(tvb, offset, &ber_class, &pc, &tag);
554 value_offset = get_ber_length(tvb, offset, &value_len, &ind);
557 proto_item* pi = proto_tree_add_text(tree, tvb, seq_offset, seq_len,"the value must be in primitive encoding");
558 pt = proto_item_add_subtree(pi,ett_decoding_error);
559 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "value not in primitive encoding");
560 return dissect_unknown_ber(actx->pinfo, tvb, seq_offset, pt);
563 /* Now, we know where everithing is */
567 /* we add the varbind tree root with a dummy label we'll fill later on */
568 pi_varbind = proto_tree_add_text(tree,tvb,seq_offset,seq_len,"VarBind");
569 pt_varbind = proto_item_add_subtree(pi_varbind,ett_varbind);
572 pi_name = proto_tree_add_item(pt_varbind,hf_snmp_objectname,tvb,name_offset,name_len,FALSE);
573 pt_name = proto_item_add_subtree(pi_name,ett_name);
575 /* fetch ObjectName and its relative oid_info */
576 oid_bytes = ep_tvb_memdup(tvb, name_offset, name_len);
577 oid_info = oid_get_from_encoded(oid_bytes, name_len, &subids, &oid_matched, &oid_left);
579 add_oid_debug_subtree(oid_info,pt_name);
584 repr = oid_encoded2string(oid_bytes, name_len);
585 pi = proto_tree_add_text(pt_name,tvb, 0, 0, "invalid oid: %s", repr);
586 pt = proto_item_add_subtree(pi, ett_decoding_error);
587 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "invalid oid: %s", repr);
588 return dissect_unknown_ber(actx->pinfo, tvb, name_offset, pt);
591 if (oid_matched+oid_left) {
592 oid_string = oid_subid2string(subids,oid_matched+oid_left);
595 if (ber_class == BER_CLASS_CON) {
596 /* if we have an error value just add it and get out the way ASAP */
600 if (value_len != 0) {
601 min_len = max_len = 0;
602 format_error = BER_WRONG_LENGTH;
607 hfid = hf_snmp_noSuchObject;
608 note = "noSuchObject";
611 hfid = hf_snmp_noSuchInstance;
612 note = "noSuchInstance";
615 hfid = hf_snmp_endOfMibView;
616 note = "endOfMibView";
619 pi = proto_tree_add_text(pt_varbind,tvb,0,0,"Wrong tag for Error Value: expected 0, 1, or 2 but got: %d",tag);
620 pt = proto_item_add_subtree(pi,ett_decoding_error);
621 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "Wrong tag for SNMP VarBind error value");
622 return dissect_unknown_ber(actx->pinfo, tvb, value_start, pt);
626 pi = proto_tree_add_item(pt_varbind,hfid,tvb,value_offset,value_len,FALSE);
627 expert_add_info_format(actx->pinfo, pi, PI_RESPONSE_CODE, PI_NOTE, "%s",note);
628 g_strlcpy (label, note, ITEM_LABEL_LENGTH);
632 /* now we'll try to figure out which are the indexing sub-oids and whether the oid we know about is the one oid we have to use */
633 switch (oid_info->kind) {
634 case OID_KIND_SCALAR:
636 /* OK: we got the instance sub-id */
637 proto_tree_add_uint64(pt_name,hf_snmp_scalar_instance_index,tvb,name_offset,name_len,subids[oid_matched]);
638 oid_info_is_ok = TRUE;
640 } else if (oid_left == 0) {
641 if (ber_class == BER_CLASS_UNI && tag == BER_UNI_TAG_NULL) {
642 /* unSpecified does not require an instance sub-id add the new value and get off the way! */
643 pi_value = proto_tree_add_item(pt_varbind,hf_snmp_unSpecified,tvb,value_offset,value_len,FALSE);
646 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"A scalar should have one instance sub-id this one has none");
647 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "No instance sub-id in scalar value");
648 oid_info_is_ok = FALSE;
652 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"A scalar should have only one instance sub-id this has: %d",oid_left);
653 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "Wrong number of instance sub-ids in scalar value");
654 oid_info_is_ok = FALSE;
658 case OID_KIND_COLUMN:
659 if ( oid_info->parent->kind == OID_KIND_ROW) {
660 oid_key_t* k = oid_info->parent->key;
661 guint key_start = oid_matched;
662 guint key_len = oid_left;
663 oid_info_is_ok = TRUE;
665 if ( key_len == 0 && ber_class == BER_CLASS_UNI && tag == BER_UNI_TAG_NULL) {
666 /* unSpecified does not require an instance sub-id add the new value and get off the way! */
667 pi_value = proto_tree_add_item(pt_varbind,hf_snmp_unSpecified,tvb,value_offset,value_len,FALSE);
672 for (;k;k = k->next) {
675 if (key_start >= oid_matched+oid_left) {
676 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"index sub-oid shorter than expected");
677 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "index sub-oid shorter than expected");
678 oid_info_is_ok = FALSE;
682 switch(k->key_type) {
683 case OID_KEY_TYPE_WRONG: {
684 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"OID instaces not handled, if you want this implemented please contact the wireshark developers");
685 expert_add_info_format(actx->pinfo, pi, PI_UNDECODED, PI_WARN, "Unimplemented instance index");
686 oid_info_is_ok = FALSE;
689 case OID_KEY_TYPE_INTEGER: {
690 if (IS_FT_INT(k->ft_type)) {
691 proto_tree_add_int(pt_name,k->hfid,tvb,name_offset,name_len,(guint)subids[key_start]);
692 } else { /* if it's not an unsigned int let proto_tree_add_uint throw a warning */
693 proto_tree_add_uint(pt_name,k->hfid,tvb,name_offset,name_len,(guint)subids[key_start]);
697 continue; /* k->next */
699 case OID_KEY_TYPE_IMPLIED_OID:
700 suboid_len = key_len;
704 case OID_KEY_TYPE_OID: {
706 guint suboid_buf_len;
709 suboid_len = subids[key_start++];
713 suboid = &(subids[key_start]);
715 if( suboid_len == 0 ) {
716 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"an index sub-oid OID cannot be 0 bytes long!");
717 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "index sub-oid OID with len=0");
718 oid_info_is_ok = FALSE;
722 if( key_len < suboid_len ) {
723 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"index sub-oid should not be longer than remaining oid size");
724 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "index sub-oid longer than remaining oid size");
725 oid_info_is_ok = FALSE;
729 suboid_buf_len = oid_subid2encoded(suboid_len, suboid, &suboid_buf);
731 DISSECTOR_ASSERT(suboid_buf_len);
733 proto_tree_add_oid(pt_name,k->hfid,tvb,name_offset, suboid_buf_len, suboid_buf);
735 key_start += suboid_len;
736 key_len -= suboid_len + 1;
737 continue; /* k->next */
746 switch (k->key_type) {
747 case OID_KEY_TYPE_IPADDR:
748 suboid = &(subids[key_start]);
751 case OID_KEY_TYPE_IMPLIED_STRING:
752 case OID_KEY_TYPE_IMPLIED_BYTES:
753 case OID_KEY_TYPE_ETHER:
754 suboid = &(subids[key_start]);
758 buf_len = k->num_subids;
759 suboid = &(subids[key_start]);
769 if( key_len < buf_len ) {
770 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"index string should not be longer than remaining oid size");
771 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "index string longer than remaining oid size");
772 oid_info_is_ok = FALSE;
776 buf = ep_alloc(buf_len+1);
777 for (i = 0; i < buf_len; i++)
778 buf[i] = (guint8)suboid[i];
781 switch(k->key_type) {
782 case OID_KEY_TYPE_STRING:
783 case OID_KEY_TYPE_IMPLIED_STRING:
784 proto_tree_add_string(pt_name,k->hfid,tvb,name_offset,buf_len, buf);
786 case OID_KEY_TYPE_BYTES:
787 case OID_KEY_TYPE_NSAP:
788 case OID_KEY_TYPE_IMPLIED_BYTES:
789 proto_tree_add_bytes(pt_name,k->hfid,tvb,name_offset,buf_len, buf);
791 case OID_KEY_TYPE_ETHER:
792 proto_tree_add_ether(pt_name,k->hfid,tvb,name_offset,buf_len, buf);
794 case OID_KEY_TYPE_IPADDR: {
795 guint32* ipv4_p = (void*)buf;
796 proto_tree_add_ipv4(pt_name,k->hfid,tvb,name_offset,buf_len, *ipv4_p);
800 DISSECTOR_ASSERT_NOT_REACHED();
804 key_start += buf_len;
806 continue; /* k->next*/
812 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"We do not know how to handle this OID, if you want this implemented please contact the wireshark developers");
813 expert_add_info_format(actx->pinfo, pi, PI_UNDECODED, PI_WARN, "Unimplemented instance index");
814 oid_info_is_ok = FALSE;
818 proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"The COLUMS's parent is not a ROW. This is a BUG! please contact the wireshark developers.");
819 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_ERROR, "COLUMS's parent is not a ROW");
820 oid_info_is_ok = FALSE;
824 /* proto_item* pi = proto_tree_add_text(pt_name,tvb,0,0,"This kind OID should have no value");
825 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "This kind OID should have no value"); */
826 oid_info_is_ok = FALSE;
832 if (oid_info_is_ok && oid_info->value_type) {
833 if (ber_class == BER_CLASS_UNI && tag == BER_UNI_TAG_NULL) {
834 pi_value = proto_tree_add_item(pt_varbind,hf_snmp_unSpecified,tvb,value_offset,value_len,FALSE);
836 /* Provide a tree_item to attach errors to, if needed. */
839 if ((oid_info->value_type->ber_class != BER_CLASS_ANY) &&
840 (ber_class != oid_info->value_type->ber_class))
841 format_error = BER_WRONG_TAG;
842 else if ((oid_info->value_type->ber_tag != BER_TAG_ANY) &&
843 (tag != oid_info->value_type->ber_tag))
844 format_error = BER_WRONG_TAG;
846 max_len = oid_info->value_type->max_len == -1 ? 0xffffff : oid_info->value_type->max_len;
847 min_len = oid_info->value_type->min_len;
849 if ((int)value_len < min_len || (int)value_len > max_len)
850 format_error = BER_WRONG_LENGTH;
853 if (format_error == BER_NO_ERROR)
854 pi_value = proto_tree_add_item(pt_varbind,oid_info->value_hfid,tvb,value_offset,value_len,FALSE);
857 switch(ber_class|(tag<<4)) {
858 case BER_CLASS_UNI|(BER_UNI_TAG_INTEGER<<4):
861 unsigned int_val_offset = value_offset;
864 max_len = 5; min_len = 1;
865 if (value_len > (guint)max_len && value_len < (guint)min_len) {
866 format_error = BER_WRONG_LENGTH;
871 /* extend sign bit */
872 if(tvb_get_guint8(tvb, int_val_offset)&0x80) {
875 for(i=0;i<value_len;i++) {
876 val=(val<<8)|tvb_get_guint8(tvb, int_val_offset);
880 proto_tree_add_int64(pt_varbind, hf_snmp_integer32_value, tvb,value_offset,value_len, val);
884 case BER_CLASS_UNI|(BER_UNI_TAG_OCTETSTRING<<4):
885 hfid = hf_snmp_octetstring_value;
887 case BER_CLASS_UNI|(BER_UNI_TAG_OID<<4):
888 max_len = -1; min_len = 1;
889 if (value_len < (guint)min_len) format_error = BER_WRONG_LENGTH;
890 hfid = hf_snmp_oid_value;
892 case BER_CLASS_UNI|(BER_UNI_TAG_NULL<<4):
893 max_len = 0; min_len = 0;
894 if (value_len != 0) format_error = BER_WRONG_LENGTH;
895 hfid = hf_snmp_null_value;
897 case BER_CLASS_APP: /* | (SNMP_IPA<<4)*/
899 case 4: hfid = hf_snmp_ipv4_value; break;
900 case 16: hfid = hf_snmp_ipv6_value; break;
901 default: hfid = hf_snmp_anyaddress_value; break;
904 case BER_CLASS_APP|(SNMP_U32<<4):
905 hfid = hf_snmp_unsigned32_value;
907 case BER_CLASS_APP|(SNMP_GGE<<4):
908 hfid = hf_snmp_gauge32_value;
910 case BER_CLASS_APP|(SNMP_CNT<<4):
911 hfid = hf_snmp_counter_value;
913 case BER_CLASS_APP|(SNMP_TIT<<4):
914 hfid = hf_snmp_timeticks_value;
916 case BER_CLASS_APP|(SNMP_OPQ<<4):
917 hfid = hf_snmp_opaque_value;
919 case BER_CLASS_APP|(SNMP_NSP<<4):
920 hfid = hf_snmp_nsap_value;
922 case BER_CLASS_APP|(SNMP_C64<<4):
923 hfid = hf_snmp_big_counter_value;
926 hfid = hf_snmp_unknown_value;
930 pi_value = proto_tree_add_item(pt_varbind,hfid,tvb,value_offset,value_len,FALSE);
931 if (format_error != BER_NO_ERROR) {
932 expert_add_info_format(actx->pinfo, pi_value, PI_UNDECODED, PI_NOTE, "Unresolved value, Missing MIB");
936 oid_info_is_ok = FALSE;
939 pt_value = proto_item_add_subtree(pi_value,ett_value);
941 if (value_len > 0 && oid_string) {
942 tvbuff_t* sub_tvb = tvb_new_subset(tvb, value_offset, value_len, value_len);
944 next_tvb_add_string(&var_list, sub_tvb, (snmp_var_in_tree) ? pt_value : NULL, value_sub_dissectors_table, oid_string);
949 if (pi_value) proto_item_fill_label(PITEM_FINFO(pi_value), label);
951 if (oid_info && oid_info->name) {
953 repr = ep_strdup_printf("%s.%s (%s)", oid_info->name,
954 oid_subid2string(&(subids[oid_matched]),oid_left),
955 oid_subid2string(subids,oid_matched+oid_left));
956 info_oid = ep_strdup_printf("%s.%s", oid_info->name,
957 oid_subid2string(&(subids[oid_matched]),oid_left));
959 repr = ep_strdup_printf("%s (%s)", oid_info->name,
960 oid_subid2string(subids,oid_matched));
961 info_oid = oid_info->name;
963 } else if (oid_string) {
964 repr = ep_strdup(oid_string);
965 info_oid = oid_string;
967 repr = ep_strdup("[Bad OID]");
970 valstr = strstr(label,": ");
971 valstr = valstr ? valstr+2 : label;
973 proto_item_set_text(pi_varbind,"%s: %s",repr,valstr);
975 if (display_oid && info_oid) {
976 col_append_fstr (actx->pinfo->cinfo, COL_INFO, " %s", info_oid);
979 switch (format_error) {
980 case BER_WRONG_LENGTH: {
981 proto_tree* pt = proto_item_add_subtree(pi_value,ett_decoding_error);
982 proto_item* pi = proto_tree_add_text(pt,tvb,0,0,"Wrong value length: %u expecting: %u <= len <= %u",
983 value_len, min_len, max_len == -1 ? 0xFFFFFF : max_len);
984 pt = proto_item_add_subtree(pi,ett_decoding_error);
985 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "Wrong length for SNMP VarBind/value");
986 return dissect_unknown_ber(actx->pinfo, tvb, value_start, pt);
988 case BER_WRONG_TAG: {
989 proto_tree* pt = proto_item_add_subtree(pi_value,ett_decoding_error);
990 proto_item* pi = proto_tree_add_text(pt,tvb,0,0,"Wrong class/tag for Value expected: %d,%d got: %d,%d",
991 oid_info->value_type->ber_class, oid_info->value_type->ber_tag,
993 pt = proto_item_add_subtree(pi,ett_decoding_error);
994 expert_add_info_format(actx->pinfo, pi, PI_MALFORMED, PI_WARN, "Wrong class/tag for SNMP VarBind/value");
995 return dissect_unknown_ber(actx->pinfo, tvb, value_start, pt);
1001 return seq_offset + seq_len;
1005 #define F_SNMP_ENGINEID_CONFORM 0x80
1006 #define SNMP_ENGINEID_RFC1910 0x00
1007 #define SNMP_ENGINEID_RFC3411 0x01
1009 static const true_false_string tfs_snmp_engineid_conform = {
1011 "RFC1910 (Non-SNMPv3)"
1014 #define SNMP_ENGINEID_FORMAT_IPV4 0x01
1015 #define SNMP_ENGINEID_FORMAT_IPV6 0x02
1016 #define SNMP_ENGINEID_FORMAT_MACADDRESS 0x03
1017 #define SNMP_ENGINEID_FORMAT_TEXT 0x04
1018 #define SNMP_ENGINEID_FORMAT_OCTETS 0x05
1020 static const value_string snmp_engineid_format_vals[] = {
1021 { SNMP_ENGINEID_FORMAT_IPV4, "IPv4 address" },
1022 { SNMP_ENGINEID_FORMAT_IPV6, "IPv6 address" },
1023 { SNMP_ENGINEID_FORMAT_MACADDRESS, "MAC address" },
1024 { SNMP_ENGINEID_FORMAT_TEXT, "Text, administratively assigned" },
1025 { SNMP_ENGINEID_FORMAT_OCTETS, "Octets, administratively assigned" },
1029 #define SNMP_ENGINEID_CISCO_AGENT 0x00
1030 #define SNMP_ENGINEID_CISCO_MANAGER 0x01
1032 static const value_string snmp_engineid_cisco_type_vals[] = {
1033 { SNMP_ENGINEID_CISCO_AGENT, "Agent" },
1034 { SNMP_ENGINEID_CISCO_MANAGER, "Manager" },
1039 * SNMP Engine ID dissection according to RFC 3411 (SnmpEngineID TC)
1040 * or historic RFC 1910 (AgentID)
1043 dissect_snmp_engineid(proto_tree *tree, tvbuff_t *tvb, int offset, int len)
1045 proto_item *item = NULL;
1046 guint8 conformance, format;
1047 guint32 enterpriseid, seconds;
1049 int len_remain = len;
1051 /* first bit: engine id conformance */
1052 if (len_remain<4) return offset;
1053 conformance = ((tvb_get_guint8(tvb, offset)>>7) & 0x01);
1054 proto_tree_add_item(tree, hf_snmp_engineid_conform, tvb, offset, 1, FALSE);
1056 /* 4-byte enterprise number/name */
1057 if (len_remain<4) return offset;
1058 enterpriseid = tvb_get_ntohl(tvb, offset);
1060 enterpriseid -= 0x80000000; /* ignore first bit */
1061 proto_tree_add_uint(tree, hf_snmp_engineid_enterprise, tvb, offset, 4, enterpriseid);
1065 switch(conformance) {
1067 case SNMP_ENGINEID_RFC1910:
1068 /* 12-byte AgentID w/ 8-byte trailer */
1069 if (len_remain==8) {
1070 proto_tree_add_text(tree, tvb, offset, 8, "AgentID Trailer: 0x%s",
1071 tvb_bytes_to_str(tvb, offset, 8));
1075 proto_tree_add_text(tree, tvb, offset, len_remain, "<Data not conforming to RFC1910>");
1080 case SNMP_ENGINEID_RFC3411: /* variable length: 5..32 */
1082 /* 1-byte format specifier */
1083 if (len_remain<1) return offset;
1084 format = tvb_get_guint8(tvb, offset);
1085 item = proto_tree_add_uint_format(tree, hf_snmp_engineid_format, tvb, offset, 1, format, "Engine ID Format: %s (%d)",
1086 val_to_str(format, snmp_engineid_format_vals, "Reserved/Enterprise-specific"), format);
1091 case SNMP_ENGINEID_FORMAT_IPV4:
1092 /* 4-byte IPv4 address */
1093 if (len_remain==4) {
1094 proto_tree_add_item(tree, hf_snmp_engineid_ipv4, tvb, offset, 4, FALSE);
1099 case SNMP_ENGINEID_FORMAT_IPV6:
1100 /* 16-byte IPv6 address */
1101 if (len_remain==16) {
1102 proto_tree_add_item(tree, hf_snmp_engineid_ipv6, tvb, offset, 16, FALSE);
1107 case SNMP_ENGINEID_FORMAT_MACADDRESS:
1108 /* See: https://supportforums.cisco.com/message/3010617#3010617 for details. */
1109 if ((enterpriseid==9)&&(len_remain==7)) {
1110 proto_tree_add_item(tree, hf_snmp_engineid_cisco_type, tvb, offset, 1, FALSE);
1114 /* 6-byte MAC address */
1115 if (len_remain==6) {
1116 proto_tree_add_item(tree, hf_snmp_engineid_mac, tvb, offset, 6, FALSE);
1121 case SNMP_ENGINEID_FORMAT_TEXT:
1122 /* max. 27-byte string, administratively assigned */
1123 if (len_remain<=27) {
1124 proto_tree_add_item(tree, hf_snmp_engineid_text, tvb, offset, len_remain, FALSE);
1130 /* most common enterprise-specific format: (ucd|net)-snmp random */
1131 if ((enterpriseid==2021)||(enterpriseid==8072)) {
1132 proto_item_append_text(item, (enterpriseid==2021) ? ": UCD-SNMP Random" : ": Net-SNMP Random");
1133 /* demystify: 4B random, 4B epoch seconds */
1134 if (len_remain==8) {
1135 proto_tree_add_item(tree, hf_snmp_engineid_data, tvb, offset, 4, FALSE);
1136 seconds = tvb_get_letohl(tvb, offset+4);
1139 proto_tree_add_time_format_value(tree, hf_snmp_engineid_time, tvb, offset+4, 4,
1141 abs_time_secs_to_str(seconds, ABSOLUTE_TIME_LOCAL, TRUE));
1147 case SNMP_ENGINEID_FORMAT_OCTETS:
1149 /* max. 27 bytes, administratively assigned or unknown format */
1150 if (len_remain<=27) {
1151 proto_tree_add_item(tree, hf_snmp_engineid_data, tvb, offset, len_remain, FALSE);
1160 proto_tree_add_text(tree, tvb, offset, len_remain, "<Data not conforming to RFC3411>");
1167 static void set_ue_keys(snmp_ue_assoc_t* n ) {
1168 guint key_size = n->user.authModel->key_size;
1170 n->user.authKey.data = se_alloc(key_size);
1171 n->user.authKey.len = key_size;
1172 n->user.authModel->pass2key(n->user.authPassword.data,
1173 n->user.authPassword.len,
1176 n->user.authKey.data);
1178 n->user.privKey.data = se_alloc(key_size);
1179 n->user.privKey.len = key_size;
1180 n->user.authModel->pass2key(n->user.privPassword.data,
1181 n->user.privPassword.len,
1184 n->user.privKey.data);
1187 static snmp_ue_assoc_t*
1188 ue_se_dup(snmp_ue_assoc_t* o)
1190 snmp_ue_assoc_t* d = se_memdup(o,sizeof(snmp_ue_assoc_t));
1192 d->user.authModel = o->user.authModel;
1194 d->user.privProtocol = o->user.privProtocol;
1196 d->user.userName.data = se_memdup(o->user.userName.data,o->user.userName.len);
1197 d->user.userName.len = o->user.userName.len;
1199 d->user.authPassword.data = o->user.authPassword.data ? se_memdup(o->user.authPassword.data,o->user.authPassword.len) : NULL;
1200 d->user.authPassword.len = o->user.authPassword.len;
1202 d->user.privPassword.data = o->user.privPassword.data ? se_memdup(o->user.privPassword.data,o->user.privPassword.len) : NULL;
1203 d->user.privPassword.len = o->user.privPassword.len;
1205 d->engine.len = o->engine.len;
1207 if (d->engine.len) {
1208 d->engine.data = se_memdup(o->engine.data,o->engine.len);
1217 #define CACHE_INSERT(c,a) if (c) { snmp_ue_assoc_t* t = c; c = a; c->next = t; } else { c = a; a->next = NULL; }
1220 renew_ue_cache(void)
1222 localized_ues = NULL;
1223 unlocalized_ues = NULL;
1228 for(i = 0; i < num_ueas; i++) {
1229 snmp_ue_assoc_t* a = ue_se_dup(&(ueas[i]));
1231 if (a->engine.len) {
1232 CACHE_INSERT(localized_ues,a);
1235 CACHE_INSERT(unlocalized_ues,a);
1243 static snmp_ue_assoc_t*
1244 localize_ue( snmp_ue_assoc_t* o, const guint8* engine, guint engine_len )
1246 snmp_ue_assoc_t* n = se_memdup(o,sizeof(snmp_ue_assoc_t));
1248 n->engine.data = se_memdup(engine,engine_len);
1249 n->engine.len = engine_len;
1257 #define localized_match(a,u,ul,e,el) \
1258 ( a->user.userName.len == ul \
1259 && a->engine.len == el \
1260 && memcmp( a->user.userName.data, u, ul ) == 0 \
1261 && memcmp( a->engine.data, e, el ) == 0 )
1263 #define unlocalized_match(a,u,l) \
1264 ( a->user.userName.len == l && memcmp( a->user.userName.data, u, l) == 0 )
1266 static snmp_ue_assoc_t*
1267 get_user_assoc(tvbuff_t* engine_tvb, tvbuff_t* user_tvb)
1269 static snmp_ue_assoc_t* a;
1270 guint given_username_len;
1271 guint8* given_username;
1272 guint given_engine_len;
1273 guint8* given_engine;
1275 if ( ! (localized_ues || unlocalized_ues ) ) return NULL;
1277 if (! ( user_tvb && engine_tvb ) ) return NULL;
1279 given_username_len = tvb_ensure_length_remaining(user_tvb,0);
1280 given_username = ep_tvb_memdup(user_tvb,0,-1);
1281 given_engine_len = tvb_ensure_length_remaining(engine_tvb,0);
1282 given_engine = ep_tvb_memdup(engine_tvb,0,-1);
1284 for (a = localized_ues; a; a = a->next) {
1285 if ( localized_match(a, given_username, given_username_len, given_engine, given_engine_len) ) {
1290 for (a = unlocalized_ues; a; a = a->next) {
1291 if ( unlocalized_match(a, given_username, given_username_len) ) {
1292 snmp_ue_assoc_t* n = localize_ue( a, given_engine, given_engine_len );
1293 CACHE_INSERT(localized_ues,n);
1302 snmp_usm_auth_md5(snmp_usm_params_t* p, guint8** calc_auth_p, guint* calc_auth_len_p, gchar const** error)
1316 *error = "No Authenticator";
1320 key = p->user_assoc->user.authKey.data;
1321 key_len = p->user_assoc->user.authKey.len;
1324 *error = "User has no authKey";
1329 auth_len = tvb_length_remaining(p->auth_tvb,0);
1331 if (auth_len != 12) {
1332 *error = "Authenticator length wrong";
1336 msg_len = tvb_length_remaining(p->msg_tvb,0);
1337 msg = ep_tvb_memdup(p->msg_tvb,0,msg_len);
1340 auth = ep_tvb_memdup(p->auth_tvb,0,auth_len);
1342 start = p->auth_offset - p->start_offset;
1343 end = start + auth_len;
1345 /* fill the authenticator with zeros */
1346 for ( i = start ; i < end ; i++ ) {
1350 calc_auth = ep_alloc(16);
1352 md5_hmac(msg, msg_len, key, key_len, calc_auth);
1354 if (calc_auth_p) *calc_auth_p = calc_auth;
1355 if (calc_auth_len_p) *calc_auth_len_p = 12;
1357 return ( memcmp(auth,calc_auth,12) != 0 ) ? FALSE : TRUE;
1362 snmp_usm_auth_sha1(snmp_usm_params_t* p _U_, guint8** calc_auth_p, guint* calc_auth_len_p, gchar const** error _U_)
1376 *error = "No Authenticator";
1380 key = p->user_assoc->user.authKey.data;
1381 key_len = p->user_assoc->user.authKey.len;
1384 *error = "User has no authKey";
1389 auth_len = tvb_length_remaining(p->auth_tvb,0);
1392 if (auth_len != 12) {
1393 *error = "Authenticator length wrong";
1397 msg_len = tvb_length_remaining(p->msg_tvb,0);
1398 msg = ep_tvb_memdup(p->msg_tvb,0,msg_len);
1400 auth = ep_tvb_memdup(p->auth_tvb,0,auth_len);
1402 start = p->auth_offset - p->start_offset;
1403 end = start + auth_len;
1405 /* fill the authenticator with zeros */
1406 for ( i = start ; i < end ; i++ ) {
1410 calc_auth = ep_alloc(20);
1412 sha1_hmac(key, key_len, msg, msg_len, calc_auth);
1414 if (calc_auth_p) *calc_auth_p = calc_auth;
1415 if (calc_auth_len_p) *calc_auth_len_p = 12;
1417 return ( memcmp(auth,calc_auth,12) != 0 ) ? FALSE : TRUE;
1421 snmp_usm_priv_des(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U_, gchar const** error _U_)
1423 #ifdef HAVE_LIBGCRYPT
1425 gcry_cipher_hd_t hd = NULL;
1428 guint8* des_key = p->user_assoc->user.privKey.data; /* first 8 bytes */
1429 guint8* pre_iv = &(p->user_assoc->user.privKey.data[8]); /* last 8 bytes */
1434 tvbuff_t* clear_tvb;
1439 salt_len = tvb_length_remaining(p->priv_tvb,0);
1441 if (salt_len != 8) {
1442 *error = "decryptionError: msgPrivacyParameters length != 8";
1446 salt = ep_tvb_memdup(p->priv_tvb,0,salt_len);
1449 The resulting "salt" is XOR-ed with the pre-IV to obtain the IV.
1451 for (i=0; i<8; i++) {
1452 iv[i] = pre_iv[i] ^ salt[i];
1455 cryptgrm_len = tvb_length_remaining(encryptedData,0);
1457 if (cryptgrm_len % 8) {
1458 *error = "decryptionError: the length of the encrypted data is not a mutiple of 8 octets";
1462 cryptgrm = ep_tvb_memdup(encryptedData,0,-1);
1464 cleartext = ep_alloc(cryptgrm_len);
1466 err = gcry_cipher_open(&hd, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_CBC, 0);
1467 if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1469 err = gcry_cipher_setiv(hd, iv, 8);
1470 if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1472 err = gcry_cipher_setkey(hd,des_key,8);
1473 if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1475 err = gcry_cipher_decrypt(hd, cleartext, cryptgrm_len, cryptgrm, cryptgrm_len);
1476 if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1478 gcry_cipher_close(hd);
1480 clear_tvb = tvb_new_child_real_data(encryptedData, cleartext, cryptgrm_len, cryptgrm_len);
1485 *error = (void*)gpg_strerror(err);
1486 if (hd) gcry_cipher_close(hd);
1489 *error = "libgcrypt not present, cannot decrypt";
1495 snmp_usm_priv_aes(snmp_usm_params_t* p _U_, tvbuff_t* encryptedData _U_, gchar const** error _U_)
1497 #ifdef HAVE_LIBGCRYPT
1499 gcry_cipher_hd_t hd = NULL;
1502 guint8* aes_key = p->user_assoc->user.privKey.data; /* first 16 bytes */
1507 tvbuff_t* clear_tvb;
1509 priv_len = tvb_length_remaining(p->priv_tvb,0);
1511 if (priv_len != 8) {
1512 *error = "decryptionError: msgPrivacyParameters length != 8";
1516 iv[0] = (p->boots & 0xff000000) >> 24;
1517 iv[1] = (p->boots & 0x00ff0000) >> 16;
1518 iv[2] = (p->boots & 0x0000ff00) >> 8;
1519 iv[3] = (p->boots & 0x000000ff);
1520 iv[4] = (p->time & 0xff000000) >> 24;
1521 iv[5] = (p->time & 0x00ff0000) >> 16;
1522 iv[6] = (p->time & 0x0000ff00) >> 8;
1523 iv[7] = (p->time & 0x000000ff);
1524 tvb_memcpy(p->priv_tvb,&(iv[8]),0,8);
1526 cryptgrm_len = tvb_length_remaining(encryptedData,0);
1527 cryptgrm = ep_tvb_memdup(encryptedData,0,-1);
1529 cleartext = ep_alloc(cryptgrm_len);
1531 err = gcry_cipher_open(&hd, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_CFB, 0);
1532 if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1534 err = gcry_cipher_setiv(hd, iv, 16);
1535 if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1537 err = gcry_cipher_setkey(hd,aes_key,16);
1538 if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1540 err = gcry_cipher_decrypt(hd, cleartext, cryptgrm_len, cryptgrm, cryptgrm_len);
1541 if (err != GPG_ERR_NO_ERROR) goto on_gcry_error;
1543 gcry_cipher_close(hd);
1545 clear_tvb = tvb_new_child_real_data(encryptedData, cleartext, cryptgrm_len, cryptgrm_len);
1550 *error = (void*)gpg_strerror(err);
1551 if (hd) gcry_cipher_close(hd);
1554 *error = "libgcrypt not present, cannot decrypt";
1561 check_ScopedPdu(tvbuff_t* tvb)
1567 int hoffset, eoffset;
1570 offset = get_ber_identifier(tvb, 0, &class, &pc, &tag);
1571 offset = get_ber_length(tvb, offset, NULL, NULL);
1573 if ( ! (((class!=BER_CLASS_APP) && (class!=BER_CLASS_PRI) )
1574 && ( (!pc) || (class!=BER_CLASS_UNI) || (tag!=BER_UNI_TAG_ENUMERATED) )
1577 if((tvb_get_guint8(tvb, offset)==0)&&(tvb_get_guint8(tvb, offset+1)==0))
1582 offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
1583 offset = get_ber_length(tvb, offset, &len, NULL);
1584 eoffset = offset + len;
1586 if (eoffset <= hoffset) return FALSE;
1588 if ((class!=BER_CLASS_APP)&&(class!=BER_CLASS_PRI))
1589 if( (class!=BER_CLASS_UNI)
1590 ||((tag<BER_UNI_TAG_NumericString)&&(tag!=BER_UNI_TAG_OCTETSTRING)&&(tag!=BER_UNI_TAG_UTF8String)) )
1598 /*--- Included file: packet-snmp-fn.c ---*/
1599 #line 1 "../../asn1/snmp/packet-snmp-fn.c"
1604 dissect_snmp_EnterpriseOID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1605 #line 64 "../../asn1/snmp/snmp.cnf"
1608 offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &enterprise_oid);
1611 if (display_oid && enterprise_oid) {
1612 name = oid_resolved_from_string(enterprise_oid);
1614 col_append_fstr (actx->pinfo->cinfo, COL_INFO, " %s", name);
1626 dissect_snmp_OCTET_STRING_SIZE_4(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1627 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
1636 dissect_snmp_NetworkAddress(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1637 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1638 hf_index, BER_CLASS_APP, 0, TRUE, dissect_snmp_OCTET_STRING_SIZE_4);
1646 dissect_snmp_INTEGER_0_4294967295(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1647 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1656 dissect_snmp_TimeTicks(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1657 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1658 hf_index, BER_CLASS_APP, 3, TRUE, dissect_snmp_INTEGER_0_4294967295);
1666 dissect_snmp_Integer32(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1667 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1676 dissect_snmp_ObjectName(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1677 offset = dissect_ber_object_identifier(implicit_tag, actx, tree, tvb, offset, hf_index, NULL);
1683 static const value_string snmp_Version_vals[] = {
1693 dissect_snmp_Version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1694 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1703 dissect_snmp_Community(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1704 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
1713 dissect_snmp_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1714 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1721 static const value_string snmp_T_error_status_vals[] = {
1724 { 2, "noSuchName" },
1730 { 8, "wrongLength" },
1731 { 9, "wrongEncoding" },
1732 { 10, "wrongValue" },
1733 { 11, "noCreation" },
1734 { 12, "inconsistentValue" },
1735 { 13, "resourceUnavailable" },
1736 { 14, "commitFailed" },
1737 { 15, "undoFailed" },
1738 { 16, "authorizationError" },
1739 { 17, "notWritable" },
1740 { 18, "inconsistentName" },
1746 dissect_snmp_T_error_status(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1747 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1756 dissect_snmp_NULL(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1757 offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
1764 static const ber_sequence_t VarBindList_sequence_of[1] = {
1765 { &hf_snmp_VarBindList_item, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_VarBind },
1769 dissect_snmp_VarBindList(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1770 offset = dissect_ber_sequence_of(implicit_tag, actx, tree, tvb, offset,
1771 VarBindList_sequence_of, hf_index, ett_snmp_VarBindList);
1777 static const ber_sequence_t PDU_sequence[] = {
1778 { &hf_snmp_request_id , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER },
1779 { &hf_snmp_error_status , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_error_status },
1780 { &hf_snmp_error_index , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER },
1781 { &hf_snmp_variable_bindings, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_VarBindList },
1782 { NULL, 0, 0, 0, NULL }
1786 dissect_snmp_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1787 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1788 PDU_sequence, hf_index, ett_snmp_PDU);
1796 dissect_snmp_GetRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1797 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1798 hf_index, BER_CLASS_CON, 0, TRUE, dissect_snmp_PDU);
1806 dissect_snmp_GetNextRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1807 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1808 hf_index, BER_CLASS_CON, 1, TRUE, dissect_snmp_PDU);
1816 dissect_snmp_GetResponse_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1817 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1818 hf_index, BER_CLASS_CON, 2, TRUE, dissect_snmp_PDU);
1826 dissect_snmp_SetRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1827 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1828 hf_index, BER_CLASS_CON, 3, TRUE, dissect_snmp_PDU);
1834 static const value_string snmp_GenericTrap_vals[] = {
1839 { 4, "authenticationFailure" },
1840 { 5, "egpNeighborLoss" },
1841 { 6, "enterpriseSpecific" },
1847 dissect_snmp_GenericTrap(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1848 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1857 dissect_snmp_SpecificTrap(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1858 #line 48 "../../asn1/snmp/snmp.cnf"
1859 guint specific_trap;
1861 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1865 if (generic_trap == 6) { /* enterprise specific */
1866 const gchar *specific_str = snmp_lookup_specific_trap (specific_trap);
1868 proto_item_append_text(actx->created_item, " (%s)", specific_str);
1877 static const ber_sequence_t Trap_PDU_U_sequence[] = {
1878 { &hf_snmp_enterprise , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_snmp_EnterpriseOID },
1879 { &hf_snmp_agent_addr , BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_snmp_NetworkAddress },
1880 { &hf_snmp_generic_trap , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_GenericTrap },
1881 { &hf_snmp_specific_trap , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_SpecificTrap },
1882 { &hf_snmp_time_stamp , BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_snmp_TimeTicks },
1883 { &hf_snmp_variable_bindings, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_VarBindList },
1884 { NULL, 0, 0, 0, NULL }
1888 dissect_snmp_Trap_PDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1889 #line 40 "../../asn1/snmp/snmp.cnf"
1891 enterprise_oid = NULL;
1893 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1894 Trap_PDU_U_sequence, hf_index, ett_snmp_Trap_PDU_U);
1905 dissect_snmp_Trap_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1906 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1907 hf_index, BER_CLASS_CON, 4, TRUE, dissect_snmp_Trap_PDU_U);
1915 dissect_snmp_INTEGER_0_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1916 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
1923 static const ber_sequence_t BulkPDU_sequence[] = {
1924 { &hf_snmp_bulkPDU_request_id, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_Integer32 },
1925 { &hf_snmp_non_repeaters , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_0_2147483647 },
1926 { &hf_snmp_max_repetitions, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_0_2147483647 },
1927 { &hf_snmp_variable_bindings, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_VarBindList },
1928 { NULL, 0, 0, 0, NULL }
1932 dissect_snmp_BulkPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1933 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
1934 BulkPDU_sequence, hf_index, ett_snmp_BulkPDU);
1942 dissect_snmp_GetBulkRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1943 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1944 hf_index, BER_CLASS_CON, 5, TRUE, dissect_snmp_BulkPDU);
1952 dissect_snmp_InformRequest_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1953 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1954 hf_index, BER_CLASS_CON, 6, TRUE, dissect_snmp_PDU);
1962 dissect_snmp_SNMPv2_Trap_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1963 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1964 hf_index, BER_CLASS_CON, 7, TRUE, dissect_snmp_PDU);
1972 dissect_snmp_Report_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
1973 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
1974 hf_index, BER_CLASS_CON, 8, TRUE, dissect_snmp_PDU);
1980 static const value_string snmp_PDUs_vals[] = {
1981 { 0, "get-request" },
1982 { 1, "get-next-request" },
1983 { 2, "get-response" },
1984 { 3, "set-request" },
1986 { 5, "getBulkRequest" },
1987 { 6, "informRequest" },
1988 { 7, "sNMPv2-Trap" },
1993 static const ber_choice_t PDUs_choice[] = {
1994 { 0, &hf_snmp_get_request , BER_CLASS_CON, 0, BER_FLAGS_NOOWNTAG, dissect_snmp_GetRequest_PDU },
1995 { 1, &hf_snmp_get_next_request, BER_CLASS_CON, 1, BER_FLAGS_NOOWNTAG, dissect_snmp_GetNextRequest_PDU },
1996 { 2, &hf_snmp_get_response , BER_CLASS_CON, 2, BER_FLAGS_NOOWNTAG, dissect_snmp_GetResponse_PDU },
1997 { 3, &hf_snmp_set_request , BER_CLASS_CON, 3, BER_FLAGS_NOOWNTAG, dissect_snmp_SetRequest_PDU },
1998 { 4, &hf_snmp_trap , BER_CLASS_CON, 4, BER_FLAGS_NOOWNTAG, dissect_snmp_Trap_PDU },
1999 { 5, &hf_snmp_getBulkRequest , BER_CLASS_CON, 5, BER_FLAGS_NOOWNTAG, dissect_snmp_GetBulkRequest_PDU },
2000 { 6, &hf_snmp_informRequest , BER_CLASS_CON, 6, BER_FLAGS_NOOWNTAG, dissect_snmp_InformRequest_PDU },
2001 { 7, &hf_snmp_sNMPv2_Trap , BER_CLASS_CON, 7, BER_FLAGS_NOOWNTAG, dissect_snmp_SNMPv2_Trap_PDU },
2002 { 8, &hf_snmp_report , BER_CLASS_CON, 8, BER_FLAGS_NOOWNTAG, dissect_snmp_Report_PDU },
2003 { 0, NULL, 0, 0, 0, NULL }
2007 dissect_snmp_PDUs(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2008 #line 28 "../../asn1/snmp/snmp.cnf"
2011 col_clear(actx->pinfo->cinfo, COL_INFO);
2013 offset = dissect_ber_choice(actx, tree, tvb, offset,
2014 PDUs_choice, hf_index, ett_snmp_PDUs,
2017 if( (pdu_type!=-1) && snmp_PDUs_vals[pdu_type].strptr ){
2018 col_prepend_fstr(actx->pinfo->cinfo, COL_INFO, "%s", snmp_PDUs_vals[pdu_type].strptr);
2027 static const ber_sequence_t Message_sequence[] = {
2028 { &hf_snmp_version , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_Version },
2029 { &hf_snmp_community , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_Community },
2030 { &hf_snmp_data , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_snmp_PDUs },
2031 { NULL, 0, 0, 0, NULL }
2035 dissect_snmp_Message(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2036 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2037 Message_sequence, hf_index, ett_snmp_Message);
2045 dissect_snmp_OCTET_STRING(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2046 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2053 static const value_string snmp_T_datav2u_vals[] = {
2059 static const ber_choice_t T_datav2u_choice[] = {
2060 { 0, &hf_snmp_v2u_plaintext , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_snmp_PDUs },
2061 { 1, &hf_snmp_encrypted , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_OCTET_STRING },
2062 { 0, NULL, 0, 0, 0, NULL }
2066 dissect_snmp_T_datav2u(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2067 offset = dissect_ber_choice(actx, tree, tvb, offset,
2068 T_datav2u_choice, hf_index, ett_snmp_T_datav2u,
2075 static const ber_sequence_t Messagev2u_sequence[] = {
2076 { &hf_snmp_version , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_Version },
2077 { &hf_snmp_parameters , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_OCTET_STRING },
2078 { &hf_snmp_datav2u , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_snmp_T_datav2u },
2079 { NULL, 0, 0, 0, NULL }
2083 dissect_snmp_Messagev2u(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2084 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2085 Messagev2u_sequence, hf_index, ett_snmp_Messagev2u);
2093 dissect_snmp_SnmpEngineID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2094 #line 99 "../../asn1/snmp/snmp.cnf"
2095 tvbuff_t* param_tvb = NULL;
2097 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2100 proto_tree* engine_tree = proto_item_add_subtree(actx->created_item,ett_engineid);
2101 dissect_snmp_engineid(engine_tree, param_tvb, 0, tvb_length_remaining(param_tvb,0));
2112 dissect_snmp_T_msgAuthoritativeEngineID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2113 #line 90 "../../asn1/snmp/snmp.cnf"
2115 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2117 if (usm_p.engine_tvb) {
2118 proto_tree* engine_tree = proto_item_add_subtree(actx->created_item,ett_engineid);
2119 dissect_snmp_engineid(engine_tree, usm_p.engine_tvb, 0, tvb_length_remaining(usm_p.engine_tvb,0));
2130 dissect_snmp_T_msgAuthoritativeEngineBoots(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2131 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2140 dissect_snmp_T_msgAuthoritativeEngineTime(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2141 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2150 dissect_snmp_T_msgUserName(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2151 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2160 dissect_snmp_T_msgAuthenticationParameters(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2161 #line 112 "../../asn1/snmp/snmp.cnf"
2162 offset = dissect_ber_octet_string(FALSE, actx, tree, tvb, offset, hf_index, &usm_p.auth_tvb);
2163 if (usm_p.auth_tvb) {
2164 usm_p.auth_item = actx->created_item;
2165 usm_p.auth_offset = tvb_offset_from_real_beginning(usm_p.auth_tvb);
2175 dissect_snmp_T_msgPrivacyParameters(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2176 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2183 static const ber_sequence_t UsmSecurityParameters_sequence[] = {
2184 { &hf_snmp_msgAuthoritativeEngineID, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgAuthoritativeEngineID },
2185 { &hf_snmp_msgAuthoritativeEngineBoots, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgAuthoritativeEngineBoots },
2186 { &hf_snmp_msgAuthoritativeEngineTime, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgAuthoritativeEngineTime },
2187 { &hf_snmp_msgUserName , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgUserName },
2188 { &hf_snmp_msgAuthenticationParameters, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgAuthenticationParameters },
2189 { &hf_snmp_msgPrivacyParameters, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgPrivacyParameters },
2190 { NULL, 0, 0, 0, NULL }
2194 dissect_snmp_UsmSecurityParameters(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2195 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2196 UsmSecurityParameters_sequence, hf_index, ett_snmp_UsmSecurityParameters);
2204 dissect_snmp_INTEGER_484_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2205 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2214 dissect_snmp_T_msgFlags(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2215 #line 227 "../../asn1/snmp/snmp.cnf"
2216 tvbuff_t *parameter_tvb = NULL;
2218 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2222 guint8 v3_flags = tvb_get_guint8(parameter_tvb, 0);
2223 proto_tree* flags_tree = proto_item_add_subtree(actx->created_item,ett_msgFlags);
2225 proto_tree_add_item(flags_tree, hf_snmp_v3_flags_report, parameter_tvb, 0, 1, FALSE);
2226 proto_tree_add_item(flags_tree, hf_snmp_v3_flags_crypt, parameter_tvb, 0, 1, FALSE);
2227 proto_tree_add_item(flags_tree, hf_snmp_v3_flags_auth, parameter_tvb, 0, 1, FALSE);
2229 usm_p.encrypted = v3_flags & TH_CRYPT ? TRUE : FALSE;
2230 usm_p.authenticated = v3_flags & TH_AUTH ? TRUE : FALSE;
2242 dissect_snmp_T_msgSecurityModel(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2243 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2250 static const ber_sequence_t HeaderData_sequence[] = {
2251 { &hf_snmp_msgID , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_0_2147483647 },
2252 { &hf_snmp_msgMaxSize , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_484_2147483647 },
2253 { &hf_snmp_msgFlags , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgFlags },
2254 { &hf_snmp_msgSecurityModel, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgSecurityModel },
2255 { NULL, 0, 0, 0, NULL }
2259 dissect_snmp_HeaderData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2260 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2261 HeaderData_sequence, hf_index, ett_snmp_HeaderData);
2269 dissect_snmp_T_msgSecurityParameters(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2270 #line 170 "../../asn1/snmp/snmp.cnf"
2272 switch(MsgSecurityModel){
2273 case SNMP_SEC_USM: /* 3 */
2274 offset = dissect_snmp_UsmSecurityParameters(FALSE, tvb, offset+2, actx, tree, -1);
2275 usm_p.user_assoc = get_user_assoc(usm_p.engine_tvb, usm_p.user_tvb);
2277 case SNMP_SEC_ANY: /* 0 */
2278 case SNMP_SEC_V1: /* 1 */
2279 case SNMP_SEC_V2C: /* 2 */
2281 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2293 static const ber_sequence_t ScopedPDU_sequence[] = {
2294 { &hf_snmp_contextEngineID, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_SnmpEngineID },
2295 { &hf_snmp_contextName , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_OCTET_STRING },
2296 { &hf_snmp_data , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_snmp_PDUs },
2297 { NULL, 0, 0, 0, NULL }
2301 dissect_snmp_ScopedPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2302 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2303 ScopedPDU_sequence, hf_index, ett_snmp_ScopedPDU);
2311 dissect_snmp_T_encryptedPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2312 #line 121 "../../asn1/snmp/snmp.cnf"
2313 tvbuff_t* crypt_tvb;
2314 offset = dissect_ber_octet_string(FALSE, actx, tree, tvb, offset, hf_snmp_encryptedPDU, &crypt_tvb);
2316 if( usm_p.encrypted && crypt_tvb
2318 && usm_p.user_assoc->user.privProtocol ) {
2320 const gchar* error = NULL;
2321 proto_tree* encryptedpdu_tree = proto_item_add_subtree(actx->created_item,ett_encryptedPDU);
2322 tvbuff_t* cleartext_tvb = usm_p.user_assoc->user.privProtocol(&usm_p, crypt_tvb, &error );
2324 if (! cleartext_tvb) {
2325 proto_item* cause = proto_tree_add_text(encryptedpdu_tree, crypt_tvb, 0, -1,
2326 "Failed to decrypt encryptedPDU: %s", error);
2328 expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN,
2329 "Failed to decrypt encryptedPDU: %s", error);
2331 col_set_str(actx->pinfo->cinfo, COL_INFO, "encryptedPDU: Failed to decrypt");
2335 proto_item* decrypted_item;
2336 proto_tree* decrypted_tree;
2338 if (! check_ScopedPdu(cleartext_tvb)) {
2339 proto_item* cause = proto_tree_add_text(encryptedpdu_tree, cleartext_tvb, 0, -1,
2340 "Decrypted data not formatted as expected, wrong key?");
2342 expert_add_info_format(actx->pinfo, cause, PI_MALFORMED, PI_WARN,
2343 "Decrypted data not formatted as expected");
2345 col_set_str(actx->pinfo->cinfo, COL_INFO, "encryptedPDU: Decrypted data not formatted as expected");
2351 add_new_data_source(actx->pinfo, cleartext_tvb, "Decrypted ScopedPDU");
2353 decrypted_item = proto_tree_add_item(encryptedpdu_tree, hf_snmp_decryptedPDU,cleartext_tvb,0,-1,FALSE);
2354 decrypted_tree = proto_item_add_subtree(decrypted_item,ett_decrypted);
2355 dissect_snmp_ScopedPDU(FALSE, cleartext_tvb, 0, actx, decrypted_tree, -1);
2358 col_set_str(actx->pinfo->cinfo, COL_INFO, "encryptedPDU: privKey Unknown");
2367 static const value_string snmp_ScopedPduData_vals[] = {
2369 { 1, "encryptedPDU" },
2373 static const ber_choice_t ScopedPduData_choice[] = {
2374 { 0, &hf_snmp_plaintext , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_ScopedPDU },
2375 { 1, &hf_snmp_encryptedPDU , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_encryptedPDU },
2376 { 0, NULL, 0, 0, 0, NULL }
2380 dissect_snmp_ScopedPduData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2381 offset = dissect_ber_choice(actx, tree, tvb, offset,
2382 ScopedPduData_choice, hf_index, ett_snmp_ScopedPduData,
2389 static const ber_sequence_t SNMPv3Message_sequence[] = {
2390 { &hf_snmp_msgVersion , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_Version },
2391 { &hf_snmp_msgGlobalData , BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_snmp_HeaderData },
2392 { &hf_snmp_msgSecurityParameters, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_T_msgSecurityParameters },
2393 { &hf_snmp_msgData , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_snmp_ScopedPduData },
2394 { NULL, 0, 0, 0, NULL }
2398 dissect_snmp_SNMPv3Message(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2399 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2400 SNMPv3Message_sequence, hf_index, ett_snmp_SNMPv3Message);
2402 #line 185 "../../asn1/snmp/snmp.cnf"
2404 if( usm_p.authenticated
2406 && usm_p.user_assoc->user.authModel ) {
2407 const gchar* error = NULL;
2408 proto_item* authen_item;
2409 proto_tree* authen_tree = proto_item_add_subtree(usm_p.auth_item,ett_authParameters);
2411 guint calc_auth_len;
2413 usm_p.authOK = usm_p.user_assoc->user.authModel->authenticate( &usm_p, &calc_auth, &calc_auth_len, &error );
2416 authen_item = proto_tree_add_text(authen_tree,tvb,0,0,"Error while verifying Message authenticity: %s", error);
2417 PROTO_ITEM_SET_GENERATED(authen_item);
2418 expert_add_info_format( actx->pinfo, authen_item, PI_MALFORMED, PI_ERROR, "Error while verifying Message authenticity: %s", error );
2423 authen_item = proto_tree_add_boolean(authen_tree, hf_snmp_msgAuthentication, tvb, 0, 0, usm_p.authOK);
2424 PROTO_ITEM_SET_GENERATED(authen_item);
2427 msg = "SNMP Authentication OK";
2430 gchar* calc_auth_str = bytestring_to_str(calc_auth,calc_auth_len,' ');
2431 proto_item_append_text(authen_item, " calculated = %s", calc_auth_str);
2432 msg = "SNMP Authentication Error";
2436 expert_add_info_format( actx->pinfo, authen_item, PI_CHECKSUM, severity, "%s", msg );
2445 static const value_string snmp_T_smux_version_vals[] = {
2452 dissect_snmp_T_smux_version(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2453 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2462 dissect_snmp_OBJECT_IDENTIFIER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2463 offset = dissect_ber_object_identifier(implicit_tag, actx, tree, tvb, offset, hf_index, NULL);
2471 dissect_snmp_DisplayString(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2472 offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
2479 static const ber_sequence_t SimpleOpen_U_sequence[] = {
2480 { &hf_snmp_smux_version , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_smux_version },
2481 { &hf_snmp_identity , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_snmp_OBJECT_IDENTIFIER },
2482 { &hf_snmp_description , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_DisplayString },
2483 { &hf_snmp_password , BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, BER_FLAGS_NOOWNTAG, dissect_snmp_OCTET_STRING },
2484 { NULL, 0, 0, 0, NULL }
2488 dissect_snmp_SimpleOpen_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2489 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2490 SimpleOpen_U_sequence, hf_index, ett_snmp_SimpleOpen_U);
2498 dissect_snmp_SimpleOpen(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2499 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2500 hf_index, BER_CLASS_APP, 0, TRUE, dissect_snmp_SimpleOpen_U);
2506 static const value_string snmp_OpenPDU_vals[] = {
2507 { 0, "smux-simple" },
2511 static const ber_choice_t OpenPDU_choice[] = {
2512 { 0, &hf_snmp_smux_simple , BER_CLASS_APP, 0, BER_FLAGS_NOOWNTAG, dissect_snmp_SimpleOpen },
2513 { 0, NULL, 0, 0, 0, NULL }
2517 dissect_snmp_OpenPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2518 offset = dissect_ber_choice(actx, tree, tvb, offset,
2519 OpenPDU_choice, hf_index, ett_snmp_OpenPDU,
2526 static const value_string snmp_ClosePDU_U_vals[] = {
2528 { 1, "unsupportedVersion" },
2529 { 2, "packetFormat" },
2530 { 3, "protocolError" },
2531 { 4, "internalError" },
2532 { 5, "authenticationFailure" },
2538 dissect_snmp_ClosePDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2539 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2548 dissect_snmp_ClosePDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2549 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2550 hf_index, BER_CLASS_APP, 1, TRUE, dissect_snmp_ClosePDU_U);
2558 dissect_snmp_INTEGER_M1_2147483647(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2559 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2566 static const value_string snmp_T_operation_vals[] = {
2575 dissect_snmp_T_operation(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2576 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2583 static const ber_sequence_t RReqPDU_U_sequence[] = {
2584 { &hf_snmp_subtree , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_snmp_ObjectName },
2585 { &hf_snmp_priority , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_INTEGER_M1_2147483647 },
2586 { &hf_snmp_operation , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_snmp_T_operation },
2587 { NULL, 0, 0, 0, NULL }
2591 dissect_snmp_RReqPDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2592 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
2593 RReqPDU_U_sequence, hf_index, ett_snmp_RReqPDU_U);
2601 dissect_snmp_RReqPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2602 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2603 hf_index, BER_CLASS_APP, 2, TRUE, dissect_snmp_RReqPDU_U);
2609 static const value_string snmp_RRspPDU_U_vals[] = {
2616 dissect_snmp_RRspPDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2617 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2626 dissect_snmp_RRspPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2627 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2628 hf_index, BER_CLASS_APP, 3, TRUE, dissect_snmp_RRspPDU_U);
2634 static const value_string snmp_RegisterResponse_vals[] = {
2640 static const ber_choice_t RegisterResponse_choice[] = {
2641 { 0, &hf_snmp_rRspPDU , BER_CLASS_APP, 3, BER_FLAGS_NOOWNTAG, dissect_snmp_RRspPDU },
2642 { 1, &hf_snmp_pDUs , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_snmp_PDUs },
2643 { 0, NULL, 0, 0, 0, NULL }
2647 dissect_snmp_RegisterResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2648 offset = dissect_ber_choice(actx, tree, tvb, offset,
2649 RegisterResponse_choice, hf_index, ett_snmp_RegisterResponse,
2656 static const value_string snmp_SOutPDU_U_vals[] = {
2664 dissect_snmp_SOutPDU_U(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2665 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
2674 dissect_snmp_SOutPDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2675 offset = dissect_ber_tagged_type(implicit_tag, actx, tree, tvb, offset,
2676 hf_index, BER_CLASS_APP, 4, TRUE, dissect_snmp_SOutPDU_U);
2682 static const value_string snmp_SMUX_PDUs_vals[] = {
2685 { 2, "registerRequest" },
2686 { 3, "registerResponse" },
2687 { 4, "commitOrRollback" },
2691 static const ber_choice_t SMUX_PDUs_choice[] = {
2692 { 0, &hf_snmp_open , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_snmp_OpenPDU },
2693 { 1, &hf_snmp_close , BER_CLASS_APP, 1, BER_FLAGS_NOOWNTAG, dissect_snmp_ClosePDU },
2694 { 2, &hf_snmp_registerRequest, BER_CLASS_APP, 2, BER_FLAGS_NOOWNTAG, dissect_snmp_RReqPDU },
2695 { 3, &hf_snmp_registerResponse, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG, dissect_snmp_RegisterResponse },
2696 { 4, &hf_snmp_commitOrRollback, BER_CLASS_APP, 4, BER_FLAGS_NOOWNTAG, dissect_snmp_SOutPDU },
2697 { 0, NULL, 0, 0, 0, NULL }
2701 dissect_snmp_SMUX_PDUs(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
2702 offset = dissect_ber_choice(actx, tree, tvb, offset,
2703 SMUX_PDUs_choice, hf_index, ett_snmp_SMUX_PDUs,
2711 static void dissect_SMUX_PDUs_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
2712 asn1_ctx_t asn1_ctx;
2713 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
2714 dissect_snmp_SMUX_PDUs(FALSE, tvb, 0, &asn1_ctx, tree, hf_snmp_SMUX_PDUs_PDU);
2718 /*--- End of included file: packet-snmp-fn.c ---*/
2719 #line 1496 "../../asn1/snmp/packet-snmp-template.c"
2723 dissect_snmp_pdu(tvbuff_t *tvb, int offset, packet_info *pinfo,
2724 proto_tree *tree, int proto, gint ett, gboolean is_tcp)
2727 guint length_remaining;
2729 gboolean pc, ind = 0;
2732 guint message_length;
2733 int start_offset = offset;
2734 guint32 version = 0;
2737 proto_tree *snmp_tree = NULL;
2738 proto_item *item = NULL;
2739 asn1_ctx_t asn1_ctx;
2740 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
2743 usm_p.msg_tvb = tvb;
2744 usm_p.start_offset = tvb_offset_from_real_beginning(tvb);
2745 usm_p.engine_tvb = NULL;
2746 usm_p.user_tvb = NULL;
2747 usm_p.auth_item = NULL;
2748 usm_p.auth_tvb = NULL;
2749 usm_p.auth_offset = 0;
2750 usm_p.priv_tvb = NULL;
2751 usm_p.user_assoc = NULL;
2752 usm_p.authenticated = FALSE;
2753 usm_p.encrypted = FALSE;
2756 usm_p.authOK = FALSE;
2759 * This will throw an exception if we don't have any data left.
2760 * That's what we want. (See "tcp_dissect_pdus()", which is
2761 * similar, but doesn't have to deal with ASN.1.
2762 * XXX - can we make "tcp_dissect_pdus()" provide enough
2763 * information to the "get_pdu_len" routine so that we could
2764 * have that routine deal with ASN.1, and just use
2765 * "tcp_dissect_pdus()"?)
2767 length_remaining = tvb_ensure_length_remaining(tvb, offset);
2769 /* NOTE: we have to parse the message piece by piece, since the
2770 * capture length may be less than the message length: a 'global'
2771 * parsing is likely to fail.
2775 * If this is SNMP-over-TCP, we might have to do reassembly
2776 * in order to read the "Sequence Of" header.
2778 if (is_tcp && snmp_desegment && pinfo->can_desegment) {
2780 * This is TCP, and we should, and can, do reassembly.
2782 * Is the "Sequence Of" header split across segment
2783 * boundaries? We require at least 6 bytes for the
2784 * header, which allows for a 4-byte length (ASN.1
2787 if (length_remaining < 6) {
2789 * Yes. Tell the TCP dissector where the data
2790 * for this message starts in the data it handed
2791 * us and that we need "some more data." Don't tell
2792 * it exactly how many bytes we need because if/when
2793 * we ask for even more (after the header) that will
2796 pinfo->desegment_offset = offset;
2797 pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
2800 * Return 0, which means "I didn't dissect anything
2801 * because I don't have enough data - we need
2809 * OK, try to read the "Sequence Of" header; this gets the total
2810 * length of the SNMP message.
2812 /* Set tree to 0 to not display internal BER fields if option used.*/
2813 offset = dissect_ber_identifier(pinfo, 0, tvb, offset, &class, &pc, &tag);
2814 /*Get the total octet length of the SNMP data*/
2815 offset = dissect_ber_length(pinfo, 0, tvb, offset, &len, &ind);
2816 message_length = len + 2;
2818 /*Get the SNMP version data*/
2819 offset = dissect_ber_integer(FALSE, &asn1_ctx, 0, tvb, offset, -1, &version);
2823 * If this is SNMP-over-TCP, we might have to do reassembly
2824 * to get all of this message.
2826 if (is_tcp && snmp_desegment && pinfo->can_desegment) {
2828 * Yes - is the message split across segment boundaries?
2830 if (length_remaining < message_length) {
2832 * Yes. Tell the TCP dissector where the data
2833 * for this message starts in the data it handed
2834 * us, and how many more bytes we need, and
2837 pinfo->desegment_offset = start_offset;
2838 pinfo->desegment_len =
2839 message_length - length_remaining;
2842 * Return 0, which means "I didn't dissect anything
2843 * because I don't have enough data - we need
2850 next_tvb_init(&var_list);
2852 col_set_str(pinfo->cinfo, COL_PROTOCOL,
2853 proto_get_protocol_short_name(find_protocol_by_id(proto)));
2856 item = proto_tree_add_item(tree, proto, tvb, start_offset,
2857 message_length, FALSE);
2858 snmp_tree = proto_item_add_subtree(item, ett);
2864 offset = dissect_snmp_Message(FALSE , tvb, start_offset, &asn1_ctx, snmp_tree, -1);
2867 offset = dissect_snmp_Messagev2u(FALSE , tvb, start_offset, &asn1_ctx, snmp_tree, -1);
2871 offset = dissect_snmp_SNMPv3Message(FALSE , tvb, start_offset, &asn1_ctx, snmp_tree, -1);
2875 * Return the length remaining in the tvbuff, so
2876 * if this is SNMP-over-TCP, our caller thinks there's
2877 * nothing left to dissect.
2879 proto_tree_add_text(snmp_tree, tvb, offset, -1,"Unknown version");
2880 return length_remaining;
2884 /* There may be appended data after the SNMP data, so treat as raw
2885 * data which needs to be dissected in case of UDP as UDP is PDU oriented.
2887 if((!is_tcp) && (length_remaining > (guint)offset)) {
2888 next_tvb = tvb_new_subset_remaining(tvb, offset);
2889 call_dissector(data_handle, next_tvb, pinfo, tree);
2891 next_tvb_call(&var_list, pinfo, tree, NULL, data_handle);
2898 dissect_snmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2900 conversation_t *conversation;
2909 * See if this looks like SNMP or not. if not, return 0 so
2910 * wireshark can try som other dissector instead.
2912 /* All SNMP packets are BER encoded and consist of a SEQUENCE
2913 * that spans the entire PDU. The first item is an INTEGER that
2914 * has the values 0-2 (version 1-3).
2915 * if not it is not snmp.
2917 /* SNMP starts with a SEQUENCE */
2918 offset = get_ber_identifier(tvb, 0, &tmp_class, &tmp_pc, &tmp_tag);
2919 if((tmp_class!=BER_CLASS_UNI)||(tmp_tag!=BER_UNI_TAG_SEQUENCE)) {
2922 /* then comes a length which spans the rest of the tvb */
2923 offset = get_ber_length(tvb, offset, &tmp_length, &tmp_ind);
2924 /* if(tmp_length!=(guint32)tvb_reported_length_remaining(tvb, offset)) {
2925 * Losen the heuristic a bit to handle the case where data has intentionally
2926 * been added after the snmp PDU ( UDP case)
2928 if ( pinfo->ptype == PT_UDP ) {
2929 if(tmp_length>(guint32)tvb_reported_length_remaining(tvb, offset)) {
2933 if(tmp_length!=(guint32)tvb_reported_length_remaining(tvb, offset)) {
2937 /* then comes an INTEGER (version)*/
2938 get_ber_identifier(tvb, offset, &tmp_class, &tmp_pc, &tmp_tag);
2939 if((tmp_class!=BER_CLASS_UNI)||(tmp_tag!=BER_UNI_TAG_INTEGER)) {
2942 /* do we need to test that version is 0 - 2 (version1-3) ? */
2946 * The first SNMP packet goes to the SNMP port; the second one
2947 * may come from some *other* port, but goes back to the same
2948 * IP address and port as the ones from which the first packet
2949 * came; all subsequent packets presumably go between those two
2950 * IP addresses and ports.
2952 * If this packet went to the SNMP port, we check to see if
2953 * there's already a conversation with one address/port pair
2954 * matching the source IP address and port of this packet,
2955 * the other address matching the destination IP address of this
2956 * packet, and any destination port.
2958 * If not, we create one, with its address 1/port 1 pair being
2959 * the source address/port of this packet, its address 2 being
2960 * the destination address of this packet, and its port 2 being
2961 * wildcarded, and give it the SNMP dissector as a dissector.
2963 if (pinfo->destport == UDP_PORT_SNMP) {
2964 conversation = find_conversation(pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
2965 pinfo->srcport, 0, NO_PORT_B);
2966 if( (conversation == NULL) || (conversation->dissector_handle!=snmp_handle) ) {
2967 conversation = conversation_new(pinfo->fd->num, &pinfo->src, &pinfo->dst, PT_UDP,
2968 pinfo->srcport, 0, NO_PORT2);
2969 conversation_set_dissector(conversation, snmp_handle);
2973 return dissect_snmp_pdu(tvb, 0, pinfo, tree, proto_snmp, ett_snmp, FALSE);
2977 dissect_snmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
2982 while (tvb_reported_length_remaining(tvb, offset) > 0) {
2983 message_len = dissect_snmp_pdu(tvb, 0, pinfo, tree,
2984 proto_snmp, ett_snmp, TRUE);
2985 if (message_len == 0) {
2987 * We don't have all the data for that message,
2988 * so we need to do desegmentation;
2989 * "dissect_snmp_pdu()" has set that up.
2993 offset += message_len;
2998 dissect_smux(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
3000 proto_tree *smux_tree = NULL;
3001 proto_item *item = NULL;
3003 next_tvb_init(&var_list);
3005 col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMUX");
3008 item = proto_tree_add_item(tree, proto_smux, tvb, 0, -1, FALSE);
3009 smux_tree = proto_item_add_subtree(item, ett_smux);
3012 dissect_SMUX_PDUs_PDU(tvb, pinfo, smux_tree);
3017 MD5 Password to Key Algorithm
3021 snmp_usm_password_to_key_md5(const guint8 *password, guint passwordlen,
3022 const guint8 *engineID, guint engineLength,
3026 guint8 *cp, password_buf[64];
3027 guint32 password_index = 0;
3028 guint32 count = 0, i;
3030 md5_init(&MD); /* initialize MD5 */
3032 /**********************************************/
3033 /* Use while loop until we've done 1 Megabyte */
3034 /**********************************************/
3035 while (count < 1048576) {
3037 for (i = 0; i < 64; i++) {
3038 /*************************************************/
3039 /* Take the next octet of the password, wrapping */
3040 /* to the beginning of the password as necessary.*/
3041 /*************************************************/
3042 *cp++ = password[password_index++ % passwordlen];
3044 md5_append(&MD, password_buf, 64);
3047 md5_finish(&MD, key1); /* tell MD5 we're done */
3049 /*****************************************************/
3050 /* Now localize the key with the engineID and pass */
3051 /* through MD5 to produce final key */
3052 /* We ignore invalid engineLengths here. More strict */
3053 /* checking is done in snmp_users_update_cb. */
3054 /*****************************************************/
3057 md5_append(&MD, key1, 16);
3058 md5_append(&MD, engineID, engineLength);
3059 md5_append(&MD, key1, 16);
3060 md5_finish(&MD, key);
3069 SHA1 Password to Key Algorithm COPIED from RFC 3414 A.2.2
3073 snmp_usm_password_to_key_sha1(const guint8 *password, guint passwordlen,
3074 const guint8 *engineID, guint engineLength,
3078 guint8 *cp, password_buf[64];
3079 guint32 password_index = 0;
3080 guint32 count = 0, i;
3082 sha1_starts(&SH); /* initialize SHA */
3084 /**********************************************/
3085 /* Use while loop until we've done 1 Megabyte */
3086 /**********************************************/
3087 while (count < 1048576) {
3089 for (i = 0; i < 64; i++) {
3090 /*************************************************/
3091 /* Take the next octet of the password, wrapping */
3092 /* to the beginning of the password as necessary.*/
3093 /*************************************************/
3094 *cp++ = password[password_index++ % passwordlen];
3096 sha1_update (&SH, password_buf, 64);
3099 sha1_finish(&SH, key);
3101 /*****************************************************/
3102 /* Now localize the key with the engineID and pass */
3103 /* through SHA to produce final key */
3104 /* We ignore invalid engineLengths here. More strict */
3105 /* checking is done in snmp_users_update_cb. */
3106 /*****************************************************/
3109 sha1_update(&SH, key, 20);
3110 sha1_update(&SH, engineID, engineLength);
3111 sha1_update(&SH, key, 20);
3112 sha1_finish(&SH, key);
3123 snmp_users_copy_cb(void* dest, const void* orig, size_t len _U_)
3125 const snmp_ue_assoc_t* o = orig;
3126 snmp_ue_assoc_t* d = dest;
3128 d->auth_model = o->auth_model;
3129 d->user.authModel = auth_models[o->auth_model];
3131 d->priv_proto = o->priv_proto;
3132 d->user.privProtocol = priv_protos[o->priv_proto];
3134 d->user.userName.data = g_memdup(o->user.userName.data,o->user.userName.len);
3135 d->user.userName.len = o->user.userName.len;
3137 d->user.authPassword.data = o->user.authPassword.data ? g_memdup(o->user.authPassword.data,o->user.authPassword.len) : NULL;
3138 d->user.authPassword.len = o->user.authPassword.len;
3140 d->user.privPassword.data = o->user.privPassword.data ? g_memdup(o->user.privPassword.data,o->user.privPassword.len) : NULL;
3141 d->user.privPassword.len = o->user.privPassword.len;
3143 d->engine.len = o->engine.len;
3144 if (o->engine.data) {
3145 d->engine.data = g_memdup(o->engine.data,o->engine.len);
3148 d->user.authKey.data = o->user.authKey.data ? g_memdup(o->user.authKey.data,o->user.authKey.len) : NULL;
3149 d->user.authKey.len = o->user.authKey.len;
3151 d->user.privKey.data = o->user.privKey.data ? g_memdup(o->user.privKey.data,o->user.privKey.len) : NULL;
3152 d->user.privKey.len = o->user.privKey.len;
3158 snmp_users_free_cb(void* p)
3160 snmp_ue_assoc_t* ue = p;
3161 g_free(ue->user.userName.data);
3162 g_free(ue->user.authPassword.data);
3163 g_free(ue->user.privPassword.data);
3164 g_free(ue->user.authKey.data);
3165 g_free(ue->user.privKey.data);
3166 g_free(ue->engine.data);
3170 snmp_users_update_cb(void* p _U_, const char** err)
3172 snmp_ue_assoc_t* ue = p;
3173 GString* es = g_string_new("");
3179 /* Nothing to update */
3182 if (! ue->user.userName.len)
3183 g_string_append_printf(es,"no userName\n");
3185 for (i=0; i<num_ueas-1; i++) {
3186 snmp_ue_assoc_t* u = &(ueas[i]);
3188 /* RFC 3411 section 5 */
3189 if (u->engine.len < 5 || u->engine.len > 32) {
3190 g_string_append_printf(es, "Invalid engineId length (%u). Must be between 5 and 32 (10 and 64 hex digits)\n", u->engine.len);
3194 if ( u->user.userName.len == ue->user.userName.len
3195 && u->engine.len == ue->engine.len ) {
3197 if (u->engine.len > 0 && memcmp( u->engine.data, ue->engine.data, u->engine.len ) == 0) {
3198 if ( memcmp( u->user.userName.data, ue->user.userName.data, ue->user.userName.len ) == 0 ) {
3199 /* XXX: make a string for the engineId */
3200 g_string_append_printf(es,"Duplicate key (userName='%s')\n",ue->user.userName.data);
3204 if (u->engine.len == 0) {
3205 if ( memcmp( u->user.userName.data, ue->user.userName.data, ue->user.userName.len ) == 0 ) {
3206 g_string_append_printf(es,"Duplicate key (userName='%s' engineId=NONE)\n",ue->user.userName.data);
3213 g_string_truncate(es,es->len-1);
3214 *err = ep_strdup(es->str);
3217 g_string_free(es,TRUE);
3223 UAT_LSTRING_CB_DEF(snmp_users,userName,snmp_ue_assoc_t,user.userName.data,user.userName.len)
3224 UAT_LSTRING_CB_DEF(snmp_users,authPassword,snmp_ue_assoc_t,user.authPassword.data,user.authPassword.len)
3225 UAT_LSTRING_CB_DEF(snmp_users,privPassword,snmp_ue_assoc_t,user.privPassword.data,user.privPassword.len)
3226 UAT_BUFFER_CB_DEF(snmp_users,engine_id,snmp_ue_assoc_t,engine.data,engine.len)
3227 UAT_VS_DEF(snmp_users,auth_model,snmp_ue_assoc_t,0,"MD5")
3228 UAT_VS_DEF(snmp_users,priv_proto,snmp_ue_assoc_t,0,"DES")
3231 snmp_specific_trap_copy_cb(void *dest, const void *orig, size_t len _U_)
3233 snmp_st_assoc_t *u = dest;
3234 const snmp_st_assoc_t *o = orig;
3236 u->enterprise = g_strdup(o->enterprise);
3238 u->desc = g_strdup(o->desc);
3244 snmp_specific_trap_free_cb(void *r)
3246 snmp_st_assoc_t *u = r;
3248 g_free(u->enterprise);
3252 UAT_CSTRING_CB_DEF(specific_traps, enterprise, snmp_st_assoc_t)
3253 UAT_DEC_CB_DEF(specific_traps, trap, snmp_st_assoc_t)
3254 UAT_CSTRING_CB_DEF(specific_traps, desc, snmp_st_assoc_t)
3256 /*--- proto_register_snmp -------------------------------------------*/
3257 void proto_register_snmp(void) {
3258 /* List of fields */
3259 static hf_register_info hf[] = {
3260 { &hf_snmp_v3_flags_auth,
3261 { "Authenticated", "snmp.v3.flags.auth", FT_BOOLEAN, 8,
3262 TFS(&tfs_set_notset), TH_AUTH, NULL, HFILL }},
3263 { &hf_snmp_v3_flags_crypt,
3264 { "Encrypted", "snmp.v3.flags.crypt", FT_BOOLEAN, 8,
3265 TFS(&tfs_set_notset), TH_CRYPT, NULL, HFILL }},
3266 { &hf_snmp_v3_flags_report,
3267 { "Reportable", "snmp.v3.flags.report", FT_BOOLEAN, 8,
3268 TFS(&tfs_set_notset), TH_REPORT, NULL, HFILL }},
3269 { &hf_snmp_engineid_conform, {
3270 "Engine ID Conformance", "snmp.engineid.conform", FT_BOOLEAN, 8,
3271 TFS(&tfs_snmp_engineid_conform), F_SNMP_ENGINEID_CONFORM, "Engine ID RFC3411 Conformance", HFILL }},
3272 { &hf_snmp_engineid_enterprise, {
3273 "Engine Enterprise ID", "snmp.engineid.enterprise", FT_UINT32, BASE_DEC|BASE_EXT_STRING,
3274 &sminmpec_values_ext, 0, NULL, HFILL }},
3275 { &hf_snmp_engineid_format, {
3276 "Engine ID Format", "snmp.engineid.format", FT_UINT8, BASE_DEC,
3277 VALS(snmp_engineid_format_vals), 0, NULL, HFILL }},
3278 { &hf_snmp_engineid_ipv4, {
3279 "Engine ID Data: IPv4 address", "snmp.engineid.ipv4", FT_IPv4, BASE_NONE,
3280 NULL, 0, NULL, HFILL }},
3281 { &hf_snmp_engineid_ipv6, {
3282 "Engine ID Data: IPv6 address", "snmp.engineid.ipv6", FT_IPv6, BASE_NONE,
3283 NULL, 0, NULL, HFILL }},
3284 { &hf_snmp_engineid_cisco_type, {
3285 "Engine ID Data: Cisco type", "snmp.engineid.cisco.type", FT_UINT8, BASE_NONE,
3286 VALS(snmp_engineid_cisco_type_vals), 0, NULL, HFILL }},
3287 { &hf_snmp_engineid_mac, {
3288 "Engine ID Data: MAC address", "snmp.engineid.mac", FT_ETHER, BASE_NONE,
3289 NULL, 0, NULL, HFILL }},
3290 { &hf_snmp_engineid_text, {
3291 "Engine ID Data: Text", "snmp.engineid.text", FT_STRING, BASE_NONE,
3292 NULL, 0, NULL, HFILL }},
3293 { &hf_snmp_engineid_time, {
3294 "Engine ID Data: Creation Time", "snmp.engineid.time", FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL,
3295 NULL, 0, NULL, HFILL }},
3296 { &hf_snmp_engineid_data, {
3297 "Engine ID Data", "snmp.engineid.data", FT_BYTES, BASE_NONE,
3298 NULL, 0, NULL, HFILL }},
3299 { &hf_snmp_msgAuthentication, {
3300 "Authentication", "snmp.v3.auth", FT_BOOLEAN, BASE_NONE,
3301 TFS(&auth_flags), 0, NULL, HFILL }},
3302 { &hf_snmp_decryptedPDU, {
3303 "Decrypted ScopedPDU", "snmp.decrypted_pdu", FT_BYTES, BASE_NONE,
3304 NULL, 0, "Decrypted PDU", HFILL }},
3305 { &hf_snmp_noSuchObject, {
3306 "noSuchObject", "snmp.noSuchObject", FT_NONE, BASE_NONE,
3307 NULL, 0, NULL, HFILL }},
3308 { &hf_snmp_noSuchInstance, {
3309 "noSuchInstance", "snmp.noSuchInstance", FT_NONE, BASE_NONE,
3310 NULL, 0, NULL, HFILL }},
3311 { &hf_snmp_endOfMibView, {
3312 "endOfMibView", "snmp.endOfMibView", FT_NONE, BASE_NONE,
3313 NULL, 0, NULL, HFILL }},
3314 { &hf_snmp_unSpecified, {
3315 "unSpecified", "snmp.unSpecified", FT_NONE, BASE_NONE,
3316 NULL, 0, NULL, HFILL }},
3318 { &hf_snmp_integer32_value, {
3319 "Value (Integer32)", "snmp.value.int", FT_INT64, BASE_DEC,
3320 NULL, 0, NULL, HFILL }},
3321 { &hf_snmp_octetstring_value, {
3322 "Value (OctetString)", "snmp.value.octets", FT_BYTES, BASE_NONE,
3323 NULL, 0, NULL, HFILL }},
3324 { &hf_snmp_oid_value, {
3325 "Value (OID)", "snmp.value.oid", FT_OID, BASE_NONE,
3326 NULL, 0, NULL, HFILL }},
3327 { &hf_snmp_null_value, {
3328 "Value (Null)", "snmp.value.null", FT_NONE, BASE_NONE,
3329 NULL, 0, NULL, HFILL }},
3330 { &hf_snmp_ipv4_value, {
3331 "Value (IpAddress)", "snmp.value.ipv4", FT_IPv4, BASE_NONE,
3332 NULL, 0, NULL, HFILL }},
3333 { &hf_snmp_ipv6_value, {
3334 "Value (IpAddress)", "snmp.value.ipv6", FT_IPv6, BASE_NONE,
3335 NULL, 0, NULL, HFILL }},
3336 { &hf_snmp_anyaddress_value, {
3337 "Value (IpAddress)", "snmp.value.addr", FT_BYTES, BASE_NONE,
3338 NULL, 0, NULL, HFILL }},
3339 { &hf_snmp_unsigned32_value, {
3340 "Value (Unsigned32)", "snmp.value.u32", FT_INT64, BASE_DEC,
3341 NULL, 0, NULL, HFILL }},
3342 { &hf_snmp_gauge32_value, {
3343 "Value (Gauge32)", "snmp.value.g32", FT_INT64, BASE_DEC,
3344 NULL, 0, NULL, HFILL }},
3345 { &hf_snmp_unknown_value, {
3346 "Value (Unknown)", "snmp.value.unk", FT_BYTES, BASE_NONE,
3347 NULL, 0, NULL, HFILL }},
3348 { &hf_snmp_counter_value, {
3349 "Value (Counter32)", "snmp.value.counter", FT_UINT64, BASE_DEC,
3350 NULL, 0, NULL, HFILL }},
3351 { &hf_snmp_big_counter_value, {
3352 "Value (Counter64)", "snmp.value.counter", FT_UINT64, BASE_DEC,
3353 NULL, 0, NULL, HFILL }},
3354 { &hf_snmp_nsap_value, {
3355 "Value (NSAP)", "snmp.value.nsap", FT_UINT64, BASE_DEC,
3356 NULL, 0, NULL, HFILL }},
3357 { &hf_snmp_timeticks_value, {
3358 "Value (Timeticks)", "snmp.value.timeticks", FT_UINT64, BASE_DEC,
3359 NULL, 0, NULL, HFILL }},
3360 { &hf_snmp_opaque_value, {
3361 "Value (Opaque)", "snmp.value.opaque", FT_BYTES, BASE_NONE,
3362 NULL, 0, NULL, HFILL }},
3363 { &hf_snmp_objectname, {
3364 "Object Name", "snmp.name", FT_OID, BASE_NONE,
3365 NULL, 0, NULL, HFILL }},
3366 { &hf_snmp_scalar_instance_index, {
3367 "Scalar Instance Index", "snmp.name.index", FT_UINT64, BASE_DEC,
3368 NULL, 0, NULL, HFILL }},
3372 /*--- Included file: packet-snmp-hfarr.c ---*/
3373 #line 1 "../../asn1/snmp/packet-snmp-hfarr.c"
3374 { &hf_snmp_SMUX_PDUs_PDU,
3375 { "SMUX-PDUs", "snmp.SMUX_PDUs",
3376 FT_UINT32, BASE_DEC, VALS(snmp_SMUX_PDUs_vals), 0,
3379 { "version", "snmp.version",
3380 FT_INT32, BASE_DEC, VALS(snmp_Version_vals), 0,
3382 { &hf_snmp_community,
3383 { "community", "snmp.community",
3384 FT_STRING, BASE_NONE, NULL, 0,
3387 { "data", "snmp.data",
3388 FT_UINT32, BASE_DEC, VALS(snmp_PDUs_vals), 0,
3390 { &hf_snmp_parameters,
3391 { "parameters", "snmp.parameters",
3392 FT_BYTES, BASE_NONE, NULL, 0,
3393 "OCTET_STRING", HFILL }},
3395 { "datav2u", "snmp.datav2u",
3396 FT_UINT32, BASE_DEC, VALS(snmp_T_datav2u_vals), 0,
3398 { &hf_snmp_v2u_plaintext,
3399 { "plaintext", "snmp.plaintext",
3400 FT_UINT32, BASE_DEC, VALS(snmp_PDUs_vals), 0,
3402 { &hf_snmp_encrypted,
3403 { "encrypted", "snmp.encrypted",
3404 FT_BYTES, BASE_NONE, NULL, 0,
3405 "OCTET_STRING", HFILL }},
3406 { &hf_snmp_msgAuthoritativeEngineID,
3407 { "msgAuthoritativeEngineID", "snmp.msgAuthoritativeEngineID",
3408 FT_BYTES, BASE_NONE, NULL, 0,
3410 { &hf_snmp_msgAuthoritativeEngineBoots,
3411 { "msgAuthoritativeEngineBoots", "snmp.msgAuthoritativeEngineBoots",
3412 FT_UINT32, BASE_DEC, NULL, 0,
3414 { &hf_snmp_msgAuthoritativeEngineTime,
3415 { "msgAuthoritativeEngineTime", "snmp.msgAuthoritativeEngineTime",
3416 FT_UINT32, BASE_DEC, NULL, 0,
3418 { &hf_snmp_msgUserName,
3419 { "msgUserName", "snmp.msgUserName",
3420 FT_STRING, BASE_NONE, NULL, 0,
3422 { &hf_snmp_msgAuthenticationParameters,
3423 { "msgAuthenticationParameters", "snmp.msgAuthenticationParameters",
3424 FT_BYTES, BASE_NONE, NULL, 0,
3426 { &hf_snmp_msgPrivacyParameters,
3427 { "msgPrivacyParameters", "snmp.msgPrivacyParameters",
3428 FT_BYTES, BASE_NONE, NULL, 0,
3430 { &hf_snmp_msgVersion,
3431 { "msgVersion", "snmp.msgVersion",
3432 FT_INT32, BASE_DEC, VALS(snmp_Version_vals), 0,
3433 "Version", HFILL }},
3434 { &hf_snmp_msgGlobalData,
3435 { "msgGlobalData", "snmp.msgGlobalData",
3436 FT_NONE, BASE_NONE, NULL, 0,
3437 "HeaderData", HFILL }},
3438 { &hf_snmp_msgSecurityParameters,
3439 { "msgSecurityParameters", "snmp.msgSecurityParameters",
3440 FT_BYTES, BASE_NONE, NULL, 0,
3443 { "msgData", "snmp.msgData",
3444 FT_UINT32, BASE_DEC, VALS(snmp_ScopedPduData_vals), 0,
3445 "ScopedPduData", HFILL }},
3447 { "msgID", "snmp.msgID",
3448 FT_UINT32, BASE_DEC, NULL, 0,
3449 "INTEGER_0_2147483647", HFILL }},
3450 { &hf_snmp_msgMaxSize,
3451 { "msgMaxSize", "snmp.msgMaxSize",
3452 FT_UINT32, BASE_DEC, NULL, 0,
3453 "INTEGER_484_2147483647", HFILL }},
3454 { &hf_snmp_msgFlags,
3455 { "msgFlags", "snmp.msgFlags",
3456 FT_BYTES, BASE_NONE, NULL, 0,
3458 { &hf_snmp_msgSecurityModel,
3459 { "msgSecurityModel", "snmp.msgSecurityModel",
3460 FT_UINT32, BASE_DEC, VALS(sec_models), 0,
3462 { &hf_snmp_plaintext,
3463 { "plaintext", "snmp.plaintext",
3464 FT_NONE, BASE_NONE, NULL, 0,
3465 "ScopedPDU", HFILL }},
3466 { &hf_snmp_encryptedPDU,
3467 { "encryptedPDU", "snmp.encryptedPDU",
3468 FT_BYTES, BASE_NONE, NULL, 0,
3470 { &hf_snmp_contextEngineID,
3471 { "contextEngineID", "snmp.contextEngineID",
3472 FT_BYTES, BASE_NONE, NULL, 0,
3473 "SnmpEngineID", HFILL }},
3474 { &hf_snmp_contextName,
3475 { "contextName", "snmp.contextName",
3476 FT_BYTES, BASE_NONE, NULL, 0,
3477 "OCTET_STRING", HFILL }},
3478 { &hf_snmp_get_request,
3479 { "get-request", "snmp.get_request",
3480 FT_NONE, BASE_NONE, NULL, 0,
3481 "GetRequest_PDU", HFILL }},
3482 { &hf_snmp_get_next_request,
3483 { "get-next-request", "snmp.get_next_request",
3484 FT_NONE, BASE_NONE, NULL, 0,
3485 "GetNextRequest_PDU", HFILL }},
3486 { &hf_snmp_get_response,
3487 { "get-response", "snmp.get_response",
3488 FT_NONE, BASE_NONE, NULL, 0,
3489 "GetResponse_PDU", HFILL }},
3490 { &hf_snmp_set_request,
3491 { "set-request", "snmp.set_request",
3492 FT_NONE, BASE_NONE, NULL, 0,
3493 "SetRequest_PDU", HFILL }},
3495 { "trap", "snmp.trap",
3496 FT_NONE, BASE_NONE, NULL, 0,
3497 "Trap_PDU", HFILL }},
3498 { &hf_snmp_getBulkRequest,
3499 { "getBulkRequest", "snmp.getBulkRequest",
3500 FT_NONE, BASE_NONE, NULL, 0,
3501 "GetBulkRequest_PDU", HFILL }},
3502 { &hf_snmp_informRequest,
3503 { "informRequest", "snmp.informRequest",
3504 FT_NONE, BASE_NONE, NULL, 0,
3505 "InformRequest_PDU", HFILL }},
3506 { &hf_snmp_sNMPv2_Trap,
3507 { "sNMPv2-Trap", "snmp.sNMPv2_Trap",
3508 FT_NONE, BASE_NONE, NULL, 0,
3509 "SNMPv2_Trap_PDU", HFILL }},
3511 { "report", "snmp.report",
3512 FT_NONE, BASE_NONE, NULL, 0,
3513 "Report_PDU", HFILL }},
3514 { &hf_snmp_request_id,
3515 { "request-id", "snmp.request_id",
3516 FT_INT32, BASE_DEC, NULL, 0,
3517 "INTEGER", HFILL }},
3518 { &hf_snmp_error_status,
3519 { "error-status", "snmp.error_status",
3520 FT_INT32, BASE_DEC, VALS(snmp_T_error_status_vals), 0,
3522 { &hf_snmp_error_index,
3523 { "error-index", "snmp.error_index",
3524 FT_INT32, BASE_DEC, NULL, 0,
3525 "INTEGER", HFILL }},
3526 { &hf_snmp_variable_bindings,
3527 { "variable-bindings", "snmp.variable_bindings",
3528 FT_UINT32, BASE_DEC, NULL, 0,
3529 "VarBindList", HFILL }},
3530 { &hf_snmp_bulkPDU_request_id,
3531 { "request-id", "snmp.request_id",
3532 FT_INT32, BASE_DEC, NULL, 0,
3533 "Integer32", HFILL }},
3534 { &hf_snmp_non_repeaters,
3535 { "non-repeaters", "snmp.non_repeaters",
3536 FT_UINT32, BASE_DEC, NULL, 0,
3537 "INTEGER_0_2147483647", HFILL }},
3538 { &hf_snmp_max_repetitions,
3539 { "max-repetitions", "snmp.max_repetitions",
3540 FT_UINT32, BASE_DEC, NULL, 0,
3541 "INTEGER_0_2147483647", HFILL }},
3542 { &hf_snmp_enterprise,
3543 { "enterprise", "snmp.enterprise",
3544 FT_OID, BASE_NONE, NULL, 0,
3545 "EnterpriseOID", HFILL }},
3546 { &hf_snmp_agent_addr,
3547 { "agent-addr", "snmp.agent_addr",
3548 FT_IPv4, BASE_NONE, NULL, 0,
3549 "NetworkAddress", HFILL }},
3550 { &hf_snmp_generic_trap,
3551 { "generic-trap", "snmp.generic_trap",
3552 FT_INT32, BASE_DEC, VALS(snmp_GenericTrap_vals), 0,
3553 "GenericTrap", HFILL }},
3554 { &hf_snmp_specific_trap,
3555 { "specific-trap", "snmp.specific_trap",
3556 FT_INT32, BASE_DEC, NULL, 0,
3557 "SpecificTrap", HFILL }},
3558 { &hf_snmp_time_stamp,
3559 { "time-stamp", "snmp.time_stamp",
3560 FT_UINT32, BASE_DEC, NULL, 0,
3561 "TimeTicks", HFILL }},
3563 { "name", "snmp.name",
3564 FT_OID, BASE_NONE, NULL, 0,
3565 "ObjectName", HFILL }},
3566 { &hf_snmp_valueType,
3567 { "valueType", "snmp.valueType",
3568 FT_NONE, BASE_NONE, NULL, 0,
3570 { &hf_snmp_VarBindList_item,
3571 { "VarBind", "snmp.VarBind",
3572 FT_NONE, BASE_NONE, NULL, 0,
3575 { "open", "snmp.open",
3576 FT_UINT32, BASE_DEC, VALS(snmp_OpenPDU_vals), 0,
3577 "OpenPDU", HFILL }},
3579 { "close", "snmp.close",
3580 FT_INT32, BASE_DEC, VALS(snmp_ClosePDU_U_vals), 0,
3581 "ClosePDU", HFILL }},
3582 { &hf_snmp_registerRequest,
3583 { "registerRequest", "snmp.registerRequest",
3584 FT_NONE, BASE_NONE, NULL, 0,
3585 "RReqPDU", HFILL }},
3586 { &hf_snmp_registerResponse,
3587 { "registerResponse", "snmp.registerResponse",
3588 FT_UINT32, BASE_DEC, VALS(snmp_RegisterResponse_vals), 0,
3590 { &hf_snmp_commitOrRollback,
3591 { "commitOrRollback", "snmp.commitOrRollback",
3592 FT_INT32, BASE_DEC, VALS(snmp_SOutPDU_U_vals), 0,
3593 "SOutPDU", HFILL }},
3595 { "rRspPDU", "snmp.rRspPDU",
3596 FT_INT32, BASE_DEC, VALS(snmp_RRspPDU_U_vals), 0,
3599 { "pDUs", "snmp.pDUs",
3600 FT_UINT32, BASE_DEC, VALS(snmp_PDUs_vals), 0,
3602 { &hf_snmp_smux_simple,
3603 { "smux-simple", "snmp.smux_simple",
3604 FT_NONE, BASE_NONE, NULL, 0,
3605 "SimpleOpen", HFILL }},
3606 { &hf_snmp_smux_version,
3607 { "smux-version", "snmp.smux_version",
3608 FT_INT32, BASE_DEC, VALS(snmp_T_smux_version_vals), 0,
3610 { &hf_snmp_identity,
3611 { "identity", "snmp.identity",
3612 FT_OID, BASE_NONE, NULL, 0,
3613 "OBJECT_IDENTIFIER", HFILL }},
3614 { &hf_snmp_description,
3615 { "description", "snmp.description",
3616 FT_BYTES, BASE_NONE, NULL, 0,
3617 "DisplayString", HFILL }},
3618 { &hf_snmp_password,
3619 { "password", "snmp.password",
3620 FT_BYTES, BASE_NONE, NULL, 0,
3621 "OCTET_STRING", HFILL }},
3623 { "subtree", "snmp.subtree",
3624 FT_OID, BASE_NONE, NULL, 0,
3625 "ObjectName", HFILL }},
3626 { &hf_snmp_priority,
3627 { "priority", "snmp.priority",
3628 FT_INT32, BASE_DEC, NULL, 0,
3629 "INTEGER_M1_2147483647", HFILL }},
3630 { &hf_snmp_operation,
3631 { "operation", "snmp.operation",
3632 FT_INT32, BASE_DEC, VALS(snmp_T_operation_vals), 0,
3635 /*--- End of included file: packet-snmp-hfarr.c ---*/
3636 #line 2148 "../../asn1/snmp/packet-snmp-template.c"
3639 /* List of subtrees */
3640 static gint *ett[] = {
3646 &ett_authParameters,
3651 &ett_decoding_error,
3653 /*--- Included file: packet-snmp-ettarr.c ---*/
3654 #line 1 "../../asn1/snmp/packet-snmp-ettarr.c"
3656 &ett_snmp_Messagev2u,
3657 &ett_snmp_T_datav2u,
3658 &ett_snmp_UsmSecurityParameters,
3659 &ett_snmp_SNMPv3Message,
3660 &ett_snmp_HeaderData,
3661 &ett_snmp_ScopedPduData,
3662 &ett_snmp_ScopedPDU,
3666 &ett_snmp_Trap_PDU_U,
3668 &ett_snmp_VarBindList,
3669 &ett_snmp_SMUX_PDUs,
3670 &ett_snmp_RegisterResponse,
3672 &ett_snmp_SimpleOpen_U,
3673 &ett_snmp_RReqPDU_U,
3675 /*--- End of included file: packet-snmp-ettarr.c ---*/
3676 #line 2164 "../../asn1/snmp/packet-snmp-template.c"
3678 module_t *snmp_module;
3680 static uat_field_t users_fields[] = {
3681 UAT_FLD_BUFFER(snmp_users,engine_id,"Engine ID","Engine-id for this entry (empty = any)"),
3682 UAT_FLD_LSTRING(snmp_users,userName,"Username","The username"),
3683 UAT_FLD_VS(snmp_users,auth_model,"Authentication model",auth_types,"Algorithm to be used for authentication."),
3684 UAT_FLD_LSTRING(snmp_users,authPassword,"Password","The password used for authenticating packets for this entry"),
3685 UAT_FLD_VS(snmp_users,priv_proto,"Privacy protocol",priv_types,"Algorithm to be used for privacy."),
3686 UAT_FLD_LSTRING(snmp_users,privPassword,"Privacy password","The password used for encrypting packets for this entry"),
3690 uat_t *assocs_uat = uat_new("SNMP Users",
3691 sizeof(snmp_ue_assoc_t),
3697 "ChSNMPUsersSection",
3699 snmp_users_update_cb,
3704 static uat_field_t specific_traps_flds[] = {
3705 UAT_FLD_CSTRING(specific_traps,enterprise,"Enterprise OID","Enterprise Object Identifier"),
3706 UAT_FLD_DEC(specific_traps,trap,"Trap Id","The specific-trap value"),
3707 UAT_FLD_CSTRING(specific_traps,desc,"Description","Trap type description"),
3711 uat_t* specific_traps_uat = uat_new("SNMP Enterprise Specific Trap Types",
3712 sizeof(snmp_st_assoc_t),
3713 "snmp_specific_traps",
3715 (void*) &specific_traps,
3716 &num_specific_traps,
3718 "ChSNMPEnterpriseSpecificTrapTypes",
3719 snmp_specific_trap_copy_cb,
3721 snmp_specific_trap_free_cb,
3723 specific_traps_flds);
3725 /* Register protocol */
3726 proto_snmp = proto_register_protocol(PNAME, PSNAME, PFNAME);
3727 new_register_dissector("snmp", dissect_snmp, proto_snmp);
3729 /* Register fields and subtrees */
3730 proto_register_field_array(proto_snmp, hf, array_length(hf));
3731 proto_register_subtree_array(ett, array_length(ett));
3734 /* Register configuration preferences */
3735 snmp_module = prefs_register_protocol(proto_snmp, process_prefs);
3736 prefs_register_bool_preference(snmp_module, "display_oid",
3737 "Show SNMP OID in info column",
3738 "Whether the SNMP OID should be shown in the info column",
3741 prefs_register_obsolete_preference(snmp_module, "mib_modules");
3742 prefs_register_obsolete_preference(snmp_module, "users_file");
3744 prefs_register_bool_preference(snmp_module, "desegment",
3745 "Reassemble SNMP-over-TCP messages\nspanning multiple TCP segments",
3746 "Whether the SNMP dissector should reassemble messages spanning multiple TCP segments."
3747 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
3750 prefs_register_bool_preference(snmp_module, "var_in_tree",
3751 "Display dissected variables inside SNMP tree",
3752 "ON - display dissected variables inside SNMP tree, OFF - display dissected variables in root tree after SNMP",
3755 prefs_register_uat_preference(snmp_module, "users_table",
3757 "Table of engine-user associations used for authentication and decryption",
3760 prefs_register_uat_preference(snmp_module, "specific_traps_table",
3761 "Enterprise Specific Trap Types",
3762 "Table of enterprise specific-trap type descriptions",
3763 specific_traps_uat);
3766 prefs_register_static_text_preference(snmp_module, "info_mibs",
3767 "MIB settings can be changed in the Name Resolution preferences",
3768 "MIB settings can be changed in the Name Resolution preferences");
3771 value_sub_dissectors_table = register_dissector_table("snmp.variable_oid","SNMP Variable OID", FT_STRING, BASE_NONE);
3773 register_init_routine(renew_ue_cache);
3775 register_ber_syntax_dissector("SNMP", proto_snmp, dissect_snmp_tcp);
3779 /*--- proto_reg_handoff_snmp ---------------------------------------*/
3780 void proto_reg_handoff_snmp(void) {
3781 dissector_handle_t snmp_tcp_handle;
3783 snmp_handle = find_dissector("snmp");
3785 dissector_add_uint("udp.port", UDP_PORT_SNMP, snmp_handle);
3786 dissector_add_uint("udp.port", UDP_PORT_SNMP_TRAP, snmp_handle);
3787 dissector_add_uint("udp.port", UDP_PORT_SNMP_PATROL, snmp_handle);
3788 dissector_add_uint("ethertype", ETHERTYPE_SNMP, snmp_handle);
3789 dissector_add_uint("ipx.socket", IPX_SOCKET_SNMP_AGENT, snmp_handle);
3790 dissector_add_uint("ipx.socket", IPX_SOCKET_SNMP_SINK, snmp_handle);
3791 dissector_add_uint("hpext.dxsap", HPEXT_SNMP, snmp_handle);
3793 snmp_tcp_handle = create_dissector_handle(dissect_snmp_tcp, proto_snmp);
3794 dissector_add_uint("tcp.port", TCP_PORT_SNMP, snmp_tcp_handle);
3795 dissector_add_uint("tcp.port", TCP_PORT_SNMP_TRAP, snmp_tcp_handle);
3797 data_handle = find_dissector("data");
3800 * Process preference settings.
3802 * We can't do this in the register routine, as preferences aren't
3803 * read until all dissector register routines have been called (so
3804 * that all dissector preferences have been registered).
3811 proto_register_smux(void)
3813 static hf_register_info hf[] = {
3815 { "Version", "smux.version", FT_UINT8, BASE_DEC, NULL,
3816 0x0, NULL, HFILL }},
3818 { "PDU type", "smux.pdutype", FT_UINT8, BASE_DEC, VALS(smux_types),
3819 0x0, NULL, HFILL }},
3821 static gint *ett[] = {
3825 proto_smux = proto_register_protocol("SNMP Multiplex Protocol",
3827 proto_register_field_array(proto_smux, hf, array_length(hf));
3828 proto_register_subtree_array(ett, array_length(ett));
3833 proto_reg_handoff_smux(void)
3835 dissector_handle_t smux_handle;
3837 smux_handle = create_dissector_handle(dissect_smux, proto_smux);
3838 dissector_add_uint("tcp.port", TCP_PORT_SMUX, smux_handle);