2 * Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
3 * John Robert LoVerso. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * This implementation has been influenced by the CMU SNMP release,
29 * by Steve Waldbusser. However, this shares no code with that system.
30 * Additional ASN.1 insight gained from Marshall T. Rose's _The_Open_Book_.
31 * Earlier forms of this implementation were derived and/or inspired by an
32 * awk script originally written by C. Philip Wood of LANL (but later
33 * heavily modified by John Robert LoVerso). The copyright notice for
34 * that work is preserved below, even though it may not rightly apply
37 * Support for SNMPv2c/SNMPv3 and the ability to link the module against
38 * the libsmi was added by J. Schoenwaelder, Copyright (c) 1999.
40 * This started out as a very simple program, but the incremental decoding
41 * (into the BE structure) complicated things.
43 # Los Alamos National Laboratory
45 # Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
46 # This software was produced under a U.S. Government contract
47 # (W-7405-ENG-36) by Los Alamos National Laboratory, which is
48 # operated by the University of California for the U.S. Department
49 # of Energy. The U.S. Government is licensed to use, reproduce,
50 # and distribute this software. Permission is granted to the
51 # public to copy and use this software without charge, provided
52 # that this Notice and any statement of authorship are reproduced
53 # on all copies. Neither the Government nor the University makes
54 # any warranty, express or implied, or assumes any liability or
55 # responsibility for the use of this software.
56 # @(#)snmp.awk.x 1.1 (LANL) 1/15/90
59 /* \summary: Simple Network Management Protocol (SNMP) printer */
65 #include <netdissect-stdinc.h>
74 #include "netdissect.h"
76 #undef OPAQUE /* defined in <wingdi.h> */
78 static const char tstr
[] = "[|snmp]";
81 * Universal ASN.1 types
82 * (we only care about the tag values for those allowed in the Internet SMI)
84 static const char *Universal
[] = {
97 "U-8","U-9","U-10","U-11", /* 8-11 */
98 "U-12","U-13","U-14","U-15", /* 12-15 */
105 * Application-wide ASN.1 types from the Internet SMI and their tags
107 static const char *Application
[] = {
124 * Context-specific ASN.1 types for the SNMP PDUs and their tags
126 static const char *Context
[] = {
147 #define NOTIFY_CLASS(x) (x == TRAP || x == V2TRAP || x == INFORMREQ)
148 #define READ_CLASS(x) (x == GETREQ || x == GETNEXTREQ || x == GETBULKREQ)
149 #define WRITE_CLASS(x) (x == SETREQ)
150 #define RESPONSE_CLASS(x) (x == GETRESP)
151 #define INTERNAL_CLASS(x) (x == REPORT)
154 * Context-specific ASN.1 types for the SNMP Exceptions and their tags
156 static const char *Exceptions
[] = {
158 #define NOSUCHOBJECT 0
160 #define NOSUCHINSTANCE 1
162 #define ENDOFMIBVIEW 2
166 * Private ASN.1 types
167 * The Internet SMI does not specify any
169 static const char *Private
[] = {
174 * error-status values for any SNMP PDU
176 static const char *ErrorStatus
[] = {
190 "resourceUnavailable",
193 "authorizationError",
197 #define DECODE_ErrorStatus(e) \
198 ( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \
200 : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf))
203 * generic-trap values in the SNMP Trap-PDU
205 static const char *GenericTrap
[] = {
210 "authenticationFailure",
213 #define GT_ENTERPRISE 6
215 #define DECODE_GenericTrap(t) \
216 ( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \
218 : (snprintf(buf, sizeof(buf), "gt=%d", t), buf))
221 * ASN.1 type class table
222 * Ties together the preceding Universal, Application, Context, and Private
225 #define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */
226 static const struct {
231 defineCLASS(Universal
),
233 defineCLASS(Application
),
234 #define APPLICATION 1
235 defineCLASS(Context
),
237 defineCLASS(Private
),
239 defineCLASS(Exceptions
),
244 * defined forms for ASN.1 types
246 static const char *Form
[] = {
250 #define CONSTRUCTED 1
254 * A structure for the OID tree for the compiled-in MIB.
255 * This is stored as a general-order tree.
258 const char *desc
; /* name of object */
259 u_char oid
; /* sub-id following parent */
260 u_char type
; /* object type (unused) */
261 struct obj
*child
, *next
; /* child and next sibling pointers */
265 * Include the compiled in SNMP MIB. "mib.h" is produced by feeding
266 * RFC-1156 format files into "makemib". "mib.h" MUST define at least
267 * a value for `mibroot'.
269 * In particular, this is gross, as this is including initialized structures,
270 * and by right shouldn't be an "include" file.
275 * This defines a list of OIDs which will be abbreviated on output.
276 * Currently, this includes the prefixes for the Internet MIB, the
277 * private enterprises tree, and the experimental tree.
279 static const struct obj_abrev
{
280 const char *prefix
; /* prefix for this abrev */
281 struct obj
*node
; /* pointer into object table */
282 const char *oid
; /* ASN.1 encoded OID */
283 } obj_abrev_list
[] = {
285 /* .iso.org.dod.internet.mgmt.mib */
286 { "", &_mib_obj
, "\53\6\1\2\1" },
288 #ifndef NO_ABREV_ENTER
289 /* .iso.org.dod.internet.private.enterprises */
290 { "E:", &_enterprises_obj
, "\53\6\1\4\1" },
292 #ifndef NO_ABREV_EXPERI
293 /* .iso.org.dod.internet.experimental */
294 { "X:", &_experimental_obj
, "\53\6\1\3" },
296 #ifndef NO_ABBREV_SNMPMODS
297 /* .iso.org.dod.internet.snmpV2.snmpModules */
298 { "S:", &_snmpModules_obj
, "\53\6\1\6\3" },
304 * This is used in the OID print routine to walk down the object tree
305 * rooted at `mibroot'.
307 #define OBJ_PRINT(o, suppressdot) \
311 if ((o) == objp->oid) \
313 } while ((objp = objp->next) != NULL); \
316 ND_PRINT((ndo, suppressdot?"%s":".%s", objp->desc)); \
317 objp = objp->child; \
319 ND_PRINT((ndo, suppressdot?"%u":".%u", (o))); \
323 * This is the definition for the Any-Data-Type storage used purely for
324 * temporary internal representation while decoding an ASN.1 data stream.
339 u_char form
, class; /* tag info */
350 #define BE_INETADDR 8
353 #define BE_NOSUCHOBJECT 128
354 #define BE_NOSUCHINST 129
355 #define BE_ENDOFMIBVIEW 130
359 * SNMP versions recognized by this module
361 static const char *SnmpVersion
[] = {
363 #define SNMP_VERSION_1 0
365 #define SNMP_VERSION_2 1
367 #define SNMP_VERSION_2U 2
369 #define SNMP_VERSION_3 3
373 * Defaults for SNMP PDU components
375 #define DEF_COMMUNITY "public"
378 * constants for ASN.1 decoding
381 #define ASNLEN_INETADDR 4
384 #define ASN_BIT8 0x80
385 #define ASN_LONGLEN 0x80
387 #define ASN_ID_BITS 0x1f
388 #define ASN_FORM_BITS 0x20
389 #define ASN_FORM_SHIFT 5
390 #define ASN_CLASS_BITS 0xc0
391 #define ASN_CLASS_SHIFT 6
393 #define ASN_ID_EXT 0x1f /* extension ID in tag field */
396 * This decodes the next ASN.1 object in the stream pointed to by "p"
397 * (and of real-length "len") and stores the intermediate data in the
398 * provided BE object.
400 * This returns -l if it fails (i.e., the ASN.1 stream is not valid).
401 * O/w, this returns the number of bytes parsed from "p".
404 asn1_parse(netdissect_options
*ndo
,
405 register const u_char
*p
, u_int len
, struct be
*elem
)
407 u_char form
, class, id
;
413 ND_PRINT((ndo
, "[nothing to parse]"));
419 * it would be nice to use a bit field, but you can't depend on them.
420 * +---+---+---+---+---+---+---+---+
422 * +---+---+---+---+---+---+---+---+
425 id
= *p
& ASN_ID_BITS
; /* lower 5 bits, range 00-1f */
427 form
= (*p
& 0xe0) >> 5; /* move upper 3 bits to lower 3 */
428 class = form
>> 1; /* bits 7&6 -> bits 1&0, range 0-3 */
429 form
&= 0x1; /* bit 5 -> bit 0, range 0-1 */
431 form
= (u_char
)(*p
& ASN_FORM_BITS
) >> ASN_FORM_SHIFT
;
432 class = (u_char
)(*p
& ASN_CLASS_BITS
) >> ASN_CLASS_SHIFT
;
438 /* extended tag field */
439 if (id
== ASN_ID_EXT
) {
441 * The ID follows, as a sequence of octets with the
442 * 8th bit set and the remaining 7 bits being
443 * the next 7 bits of the value, terminated with
444 * an octet with the 8th bit not set.
446 * First, assemble all the octets with the 8th
447 * bit set. XXX - this doesn't handle a value
448 * that won't fit in 32 bits.
452 while (*p
& ASN_BIT8
) {
454 ND_PRINT((ndo
, "[Xtagfield?]"));
457 id
= (id
<< 7) | (*p
& ~ASN_BIT8
);
464 ND_PRINT((ndo
, "[Xtagfield?]"));
468 elem
->id
= id
= (id
<< 7) | *p
;
474 ND_PRINT((ndo
, "[no asnlen]"));
480 if (elem
->asnlen
& ASN_BIT8
) {
481 uint32_t noct
= elem
->asnlen
% ASN_BIT8
;
484 ND_PRINT((ndo
, "[asnlen? %d<%d]", len
, noct
));
487 ND_TCHECK2(*p
, noct
);
488 for (; noct
-- > 0; len
--, hdr
++)
489 elem
->asnlen
= (elem
->asnlen
<< ASN_SHIFT8
) | *p
++;
491 if (len
< elem
->asnlen
) {
492 ND_PRINT((ndo
, "[len%d<asnlen%u]", len
, elem
->asnlen
));
495 if (form
>= sizeof(Form
)/sizeof(Form
[0])) {
496 ND_PRINT((ndo
, "[form?%d]", form
));
499 if (class >= sizeof(Class
)/sizeof(Class
[0])) {
500 ND_PRINT((ndo
, "[class?%c/%d]", *Form
[form
], class));
503 if ((int)id
>= Class
[class].numIDs
) {
504 ND_PRINT((ndo
, "[id?%c/%s/%d]", *Form
[form
], Class
[class].name
, id
));
519 register int32_t data
;
523 ND_TCHECK2(*p
, elem
->asnlen
);
524 if (*p
& ASN_BIT8
) /* negative */
526 for (i
= elem
->asnlen
; i
-- > 0; p
++)
527 data
= (data
<< ASN_SHIFT8
) | *p
;
528 elem
->data
.integer
= data
;
534 elem
->data
.raw
= (const uint8_t *)p
;
538 elem
->type
= BE_NULL
;
539 elem
->data
.raw
= NULL
;
543 elem
->type
= BE_OCTET
;
544 elem
->data
.raw
= (const uint8_t *)p
;
545 ND_PRINT((ndo
, "[P/U/%s]", Class
[class].Id
[id
]));
553 elem
->type
= BE_INETADDR
;
554 elem
->data
.raw
= (const uint8_t *)p
;
560 register uint32_t data
;
561 ND_TCHECK2(*p
, elem
->asnlen
);
564 for (i
= elem
->asnlen
; i
-- > 0; p
++)
565 data
= (data
<< 8) + *p
;
566 elem
->data
.uns
= data
;
571 register uint32_t high
, low
;
572 ND_TCHECK2(*p
, elem
->asnlen
);
573 elem
->type
= BE_UNS64
;
575 for (i
= elem
->asnlen
; i
-- > 0; p
++) {
577 ((low
& 0xFF000000) >> 24);
578 low
= (low
<< 8) | *p
;
580 elem
->data
.uns64
.high
= high
;
581 elem
->data
.uns64
.low
= low
;
586 elem
->type
= BE_OCTET
;
587 elem
->data
.raw
= (const uint8_t *)p
;
588 ND_PRINT((ndo
, "[P/A/%s]",
589 Class
[class].Id
[id
]));
597 elem
->type
= BE_NOSUCHOBJECT
;
598 elem
->data
.raw
= NULL
;
602 elem
->type
= BE_NOSUCHINST
;
603 elem
->data
.raw
= NULL
;
607 elem
->type
= BE_ENDOFMIBVIEW
;
608 elem
->data
.raw
= NULL
;
614 ND_PRINT((ndo
, "[P/%s/%s]", Class
[class].name
, Class
[class].Id
[id
]));
615 ND_TCHECK2(*p
, elem
->asnlen
);
616 elem
->type
= BE_OCTET
;
617 elem
->data
.raw
= (const uint8_t *)p
;
628 elem
->data
.raw
= (const uint8_t *)p
;
632 elem
->type
= BE_OCTET
;
633 elem
->data
.raw
= (const uint8_t *)p
;
634 ND_PRINT((ndo
, "C/U/%s", Class
[class].Id
[id
]));
641 elem
->data
.raw
= (const uint8_t *)p
;
645 elem
->type
= BE_OCTET
;
646 elem
->data
.raw
= (const uint8_t *)p
;
647 ND_PRINT((ndo
, "C/%s/%s", Class
[class].name
, Class
[class].Id
[id
]));
654 return elem
->asnlen
+ hdr
;
657 ND_PRINT((ndo
, "%s", tstr
));
662 asn1_print_octets(netdissect_options
*ndo
, struct be
*elem
)
664 const u_char
*p
= (const u_char
*)elem
->data
.raw
;
665 uint32_t asnlen
= elem
->asnlen
;
668 ND_TCHECK2(*p
, asnlen
);
669 for (i
= asnlen
; i
-- > 0; p
++)
670 ND_PRINT((ndo
, "_%.2x", *p
));
674 ND_PRINT((ndo
, "%s", tstr
));
679 asn1_print_string(netdissect_options
*ndo
, struct be
*elem
)
681 register int printable
= 1, first
= 1;
683 uint32_t asnlen
= elem
->asnlen
;
687 ND_TCHECK2(*p
, asnlen
);
688 for (i
= asnlen
; printable
&& i
-- > 0; p
++)
689 printable
= ND_ISPRINT(*p
);
692 ND_PRINT((ndo
, "\""));
693 if (fn_printn(ndo
, p
, asnlen
, ndo
->ndo_snapend
)) {
694 ND_PRINT((ndo
, "\""));
697 ND_PRINT((ndo
, "\""));
699 for (i
= asnlen
; i
-- > 0; p
++) {
700 ND_PRINT((ndo
, first
? "%.2x" : "_%.2x", *p
));
707 ND_PRINT((ndo
, "%s", tstr
));
712 * Display the ASN.1 object represented by the BE object.
713 * This used to be an integral part of asn1_parse() before the intermediate
717 asn1_print(netdissect_options
*ndo
,
720 const u_char
*p
= (const u_char
*)elem
->data
.raw
;
721 uint32_t asnlen
= elem
->asnlen
;
724 switch (elem
->type
) {
727 if (asn1_print_octets(ndo
, elem
) == -1)
735 int o
= 0, first
= -1;
738 if (!nd_smi_module_loaded
) {
739 if (!ndo
->ndo_nflag
&& asnlen
> 2) {
740 const struct obj_abrev
*a
= &obj_abrev_list
[0];
741 size_t a_len
= strlen(a
->oid
);
742 for (; a
->node
; a
++) {
743 ND_TCHECK2(*p
, a_len
);
744 if (memcmp(a
->oid
, p
, a_len
) == 0) {
745 objp
= a
->node
->child
;
748 ND_PRINT((ndo
, "%s", a
->prefix
));
755 for (; i
-- > 0; p
++) {
757 o
= (o
<< ASN_SHIFT7
) + (*p
& ~ASN_BIT8
);
758 if (*p
& ASN_LONGLEN
)
762 * first subitem encodes two items with
764 * (see X.690:1997 clause 8.19 for the details)
786 ND_PRINT((ndo
, "%d", elem
->data
.integer
));
790 ND_PRINT((ndo
, "%u", elem
->data
.uns
));
793 case BE_UNS64
: { /* idea borrowed from by Marshall Rose */
796 char *cpf
, *cpl
, last
[6], first
[30];
797 if (elem
->data
.uns64
.high
== 0) {
798 ND_PRINT((ndo
, "%u", elem
->data
.uns64
.low
));
801 d
= elem
->data
.uns64
.high
* 4294967296.0; /* 2^32 */
802 if (elem
->data
.uns64
.high
<= 0x1fffff) {
803 d
+= elem
->data
.uns64
.low
;
804 #if 0 /*is looks illegal, but what is the intention?*/
805 ND_PRINT((ndo
, "%.f", d
));
807 ND_PRINT((ndo
, "%f", d
));
811 d
+= (elem
->data
.uns64
.low
& 0xfffff000);
812 #if 0 /*is looks illegal, but what is the intention?*/
813 snprintf(first
, sizeof(first
), "%.f", d
);
815 snprintf(first
, sizeof(first
), "%f", d
);
817 snprintf(last
, sizeof(last
), "%5.5d",
818 elem
->data
.uns64
.low
& 0xfff);
819 for (carry
= 0, cpf
= first
+strlen(first
)-1, cpl
= last
+4;
822 j
= carry
+ (*cpf
- '0') + (*cpl
- '0');
831 ND_PRINT((ndo
, "%s", first
));
836 if (asn1_print_string(ndo
, elem
) == -1)
841 ND_PRINT((ndo
, "Seq(%u)", elem
->asnlen
));
845 if (asnlen
!= ASNLEN_INETADDR
)
846 ND_PRINT((ndo
, "[inetaddr len!=%d]", ASNLEN_INETADDR
));
847 ND_TCHECK2(*p
, asnlen
);
848 for (i
= asnlen
; i
-- != 0; p
++) {
849 ND_PRINT((ndo
, (i
== asnlen
-1) ? "%u" : ".%u", *p
));
853 case BE_NOSUCHOBJECT
:
855 case BE_ENDOFMIBVIEW
:
856 ND_PRINT((ndo
, "[%s]", Class
[EXCEPTIONS
].Id
[elem
->id
]));
860 ND_PRINT((ndo
, "%s(%u)", Class
[CONTEXT
].Id
[elem
->id
], elem
->asnlen
));
864 ND_PRINT((ndo
, "[BE_ANY!?]"));
868 ND_PRINT((ndo
, "[be!?]"));
874 ND_PRINT((ndo
, "%s", tstr
));
880 * This is a brute force ASN.1 printer: recurses to dump an entire structure.
881 * This will work for any ASN.1 stream, not just an SNMP PDU.
883 * By adding newlines and spaces at the correct places, this would print in
886 * This is not currently used.
889 asn1_decode(u_char
*p
, u_int length
)
894 while (i
>= 0 && length
> 0) {
895 i
= asn1_parse(ndo
, p
, length
, &elem
);
897 ND_PRINT((ndo
, " "));
898 if (asn1_print(ndo
, &elem
) < 0)
900 if (elem
.type
== BE_SEQ
|| elem
.type
== BE_PDU
) {
901 ND_PRINT((ndo
, " {"));
902 asn1_decode(elem
.data
.raw
, elem
.asnlen
);
903 ND_PRINT((ndo
, " }"));
915 SmiBasetype basetype
;
919 static const struct smi2be smi2betab
[] = {
920 { SMI_BASETYPE_INTEGER32
, BE_INT
},
921 { SMI_BASETYPE_OCTETSTRING
, BE_STR
},
922 { SMI_BASETYPE_OCTETSTRING
, BE_INETADDR
},
923 { SMI_BASETYPE_OBJECTIDENTIFIER
, BE_OID
},
924 { SMI_BASETYPE_UNSIGNED32
, BE_UNS
},
925 { SMI_BASETYPE_INTEGER64
, BE_NONE
},
926 { SMI_BASETYPE_UNSIGNED64
, BE_UNS64
},
927 { SMI_BASETYPE_FLOAT32
, BE_NONE
},
928 { SMI_BASETYPE_FLOAT64
, BE_NONE
},
929 { SMI_BASETYPE_FLOAT128
, BE_NONE
},
930 { SMI_BASETYPE_ENUM
, BE_INT
},
931 { SMI_BASETYPE_BITS
, BE_STR
},
932 { SMI_BASETYPE_UNKNOWN
, BE_NONE
}
936 smi_decode_oid(netdissect_options
*ndo
,
937 struct be
*elem
, unsigned int *oid
,
938 unsigned int oidsize
, unsigned int *oidlen
)
940 const u_char
*p
= (const u_char
*)elem
->data
.raw
;
941 uint32_t asnlen
= elem
->asnlen
;
942 int o
= 0, first
= -1, i
= asnlen
;
943 unsigned int firstval
;
945 if (nd_smi_module_loaded
) {
946 for (*oidlen
= 0; i
-- > 0; p
++) {
948 o
= (o
<< ASN_SHIFT7
) + (*p
& ~ASN_BIT8
);
949 if (*p
& ASN_LONGLEN
)
953 * first subitem encodes two items with 1st*OIDMUX+2nd
954 * (see X.690:1997 clause 8.19 for the details)
958 firstval
= o
/ OIDMUX
;
959 if (firstval
> 2) firstval
= 2;
960 o
-= firstval
* OIDMUX
;
961 if (*oidlen
< oidsize
) {
962 oid
[(*oidlen
)++] = firstval
;
965 if (*oidlen
< oidsize
) {
966 oid
[(*oidlen
)++] = o
;
974 ND_PRINT((ndo
, "%s", tstr
));
978 static int smi_check_type(SmiBasetype basetype
, int be
)
982 for (i
= 0; smi2betab
[i
].basetype
!= SMI_BASETYPE_UNKNOWN
; i
++) {
983 if (smi2betab
[i
].basetype
== basetype
&& smi2betab
[i
].be
== be
) {
991 static int smi_check_a_range(SmiType
*smiType
, SmiRange
*smiRange
,
996 switch (smiType
->basetype
) {
997 case SMI_BASETYPE_OBJECTIDENTIFIER
:
998 case SMI_BASETYPE_OCTETSTRING
:
999 if (smiRange
->minValue
.value
.unsigned32
1000 == smiRange
->maxValue
.value
.unsigned32
) {
1001 ok
= (elem
->asnlen
== smiRange
->minValue
.value
.unsigned32
);
1003 ok
= (elem
->asnlen
>= smiRange
->minValue
.value
.unsigned32
1004 && elem
->asnlen
<= smiRange
->maxValue
.value
.unsigned32
);
1008 case SMI_BASETYPE_INTEGER32
:
1009 ok
= (elem
->data
.integer
>= smiRange
->minValue
.value
.integer32
1010 && elem
->data
.integer
<= smiRange
->maxValue
.value
.integer32
);
1013 case SMI_BASETYPE_UNSIGNED32
:
1014 ok
= (elem
->data
.uns
>= smiRange
->minValue
.value
.unsigned32
1015 && elem
->data
.uns
<= smiRange
->maxValue
.value
.unsigned32
);
1018 case SMI_BASETYPE_UNSIGNED64
:
1022 /* case SMI_BASETYPE_INTEGER64: SMIng */
1023 /* case SMI_BASETYPE_FLOAT32: SMIng */
1024 /* case SMI_BASETYPE_FLOAT64: SMIng */
1025 /* case SMI_BASETYPE_FLOAT128: SMIng */
1027 case SMI_BASETYPE_ENUM
:
1028 case SMI_BASETYPE_BITS
:
1029 case SMI_BASETYPE_UNKNOWN
:
1041 static int smi_check_range(SmiType
*smiType
, struct be
*elem
)
1046 for (smiRange
= smiGetFirstRange(smiType
);
1048 smiRange
= smiGetNextRange(smiRange
)) {
1050 ok
= smi_check_a_range(smiType
, smiRange
, elem
);
1058 SmiType
*parentType
;
1059 parentType
= smiGetParentType(smiType
);
1061 ok
= smi_check_range(parentType
, elem
);
1069 smi_print_variable(netdissect_options
*ndo
,
1070 struct be
*elem
, int *status
)
1072 unsigned int oid
[128], oidlen
;
1073 SmiNode
*smiNode
= NULL
;
1076 *status
= smi_decode_oid(ndo
, elem
, oid
, sizeof(oid
) / sizeof(unsigned int),
1080 smiNode
= smiGetNodeByOID(oidlen
, oid
);
1082 *status
= asn1_print(ndo
, elem
);
1085 if (ndo
->ndo_vflag
) {
1086 ND_PRINT((ndo
, "%s::", smiGetNodeModule(smiNode
)->name
));
1088 ND_PRINT((ndo
, "%s", smiNode
->name
));
1089 if (smiNode
->oidlen
< oidlen
) {
1090 for (i
= smiNode
->oidlen
; i
< oidlen
; i
++) {
1091 ND_PRINT((ndo
, ".%u", oid
[i
]));
1099 smi_print_value(netdissect_options
*ndo
,
1100 SmiNode
*smiNode
, u_short pduid
, struct be
*elem
)
1102 unsigned int i
, oid
[128], oidlen
;
1107 if (! smiNode
|| ! (smiNode
->nodekind
1108 & (SMI_NODEKIND_SCALAR
| SMI_NODEKIND_COLUMN
))) {
1109 return asn1_print(ndo
, elem
);
1112 if (elem
->type
== BE_NOSUCHOBJECT
1113 || elem
->type
== BE_NOSUCHINST
1114 || elem
->type
== BE_ENDOFMIBVIEW
) {
1115 return asn1_print(ndo
, elem
);
1118 if (NOTIFY_CLASS(pduid
) && smiNode
->access
< SMI_ACCESS_NOTIFY
) {
1119 ND_PRINT((ndo
, "[notNotifyable]"));
1122 if (READ_CLASS(pduid
) && smiNode
->access
< SMI_ACCESS_READ_ONLY
) {
1123 ND_PRINT((ndo
, "[notReadable]"));
1126 if (WRITE_CLASS(pduid
) && smiNode
->access
< SMI_ACCESS_READ_WRITE
) {
1127 ND_PRINT((ndo
, "[notWritable]"));
1130 if (RESPONSE_CLASS(pduid
)
1131 && smiNode
->access
== SMI_ACCESS_NOT_ACCESSIBLE
) {
1132 ND_PRINT((ndo
, "[noAccess]"));
1135 smiType
= smiGetNodeType(smiNode
);
1137 return asn1_print(ndo
, elem
);
1140 if (! smi_check_type(smiType
->basetype
, elem
->type
)) {
1141 ND_PRINT((ndo
, "[wrongType]"));
1144 if (! smi_check_range(smiType
, elem
)) {
1145 ND_PRINT((ndo
, "[outOfRange]"));
1148 /* resolve bits to named bits */
1150 /* check whether instance identifier is valid */
1152 /* apply display hints (integer, octetstring) */
1154 /* convert instance identifier to index type values */
1156 switch (elem
->type
) {
1158 if (smiType
->basetype
== SMI_BASETYPE_BITS
) {
1159 /* print bit labels */
1161 smi_decode_oid(ndo
, elem
, oid
,
1162 sizeof(oid
)/sizeof(unsigned int),
1164 smiNode
= smiGetNodeByOID(oidlen
, oid
);
1166 if (ndo
->ndo_vflag
) {
1167 ND_PRINT((ndo
, "%s::", smiGetNodeModule(smiNode
)->name
));
1169 ND_PRINT((ndo
, "%s", smiNode
->name
));
1170 if (smiNode
->oidlen
< oidlen
) {
1171 for (i
= smiNode
->oidlen
;
1173 ND_PRINT((ndo
, ".%u", oid
[i
]));
1182 if (smiType
->basetype
== SMI_BASETYPE_ENUM
) {
1183 for (nn
= smiGetFirstNamedNumber(smiType
);
1185 nn
= smiGetNextNamedNumber(nn
)) {
1186 if (nn
->value
.value
.integer32
1187 == elem
->data
.integer
) {
1188 ND_PRINT((ndo
, "%s", nn
->name
));
1189 ND_PRINT((ndo
, "(%d)", elem
->data
.integer
));
1199 return asn1_print(ndo
, elem
);
1206 * General SNMP header
1208 * version INTEGER {version-1(0)},
1209 * community OCTET STRING,
1212 * PDUs for all but Trap: (see rfc1157 from page 15 on)
1214 * request-id INTEGER,
1215 * error-status INTEGER,
1216 * error-index INTEGER,
1217 * varbindlist SEQUENCE OF
1225 * enterprise OBJECT IDENTIFIER,
1226 * agent-addr NetworkAddress,
1227 * generic-trap INTEGER,
1228 * specific-trap INTEGER,
1229 * time-stamp TimeTicks,
1230 * varbindlist SEQUENCE OF
1239 * Decode SNMP varBind
1242 varbind_print(netdissect_options
*ndo
,
1243 u_short pduid
, const u_char
*np
, u_int length
)
1248 SmiNode
*smiNode
= NULL
;
1252 /* Sequence of varBind */
1253 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1255 if (elem
.type
!= BE_SEQ
) {
1256 ND_PRINT((ndo
, "[!SEQ of varbind]"));
1257 asn1_print(ndo
, &elem
);
1260 if ((u_int
)count
< length
)
1261 ND_PRINT((ndo
, "[%d extra after SEQ of varbind]", length
- count
));
1263 length
= elem
.asnlen
;
1264 np
= (const u_char
*)elem
.data
.raw
;
1266 for (ind
= 1; length
> 0; ind
++) {
1267 const u_char
*vbend
;
1270 ND_PRINT((ndo
, " "));
1273 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1275 if (elem
.type
!= BE_SEQ
) {
1276 ND_PRINT((ndo
, "[!varbind]"));
1277 asn1_print(ndo
, &elem
);
1281 vblength
= length
- count
;
1283 length
= elem
.asnlen
;
1284 np
= (const u_char
*)elem
.data
.raw
;
1287 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1289 if (elem
.type
!= BE_OID
) {
1290 ND_PRINT((ndo
, "[objName!=OID]"));
1291 asn1_print(ndo
, &elem
);
1295 smiNode
= smi_print_variable(ndo
, &elem
, &status
);
1297 status
= asn1_print(ndo
, &elem
);
1304 if (pduid
!= GETREQ
&& pduid
!= GETNEXTREQ
1305 && pduid
!= GETBULKREQ
)
1306 ND_PRINT((ndo
, "="));
1309 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1311 if (pduid
== GETREQ
|| pduid
== GETNEXTREQ
1312 || pduid
== GETBULKREQ
) {
1313 if (elem
.type
!= BE_NULL
) {
1314 ND_PRINT((ndo
, "[objVal!=NULL]"));
1315 if (asn1_print(ndo
, &elem
) < 0)
1319 if (elem
.type
!= BE_NULL
) {
1321 status
= smi_print_value(ndo
, smiNode
, pduid
, &elem
);
1323 status
= asn1_print(ndo
, &elem
);
1335 * Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, SetRequest,
1336 * GetBulk, Inform, V2Trap, and Report
1339 snmppdu_print(netdissect_options
*ndo
,
1340 u_short pduid
, const u_char
*np
, u_int length
)
1343 int count
= 0, error_status
;
1345 /* reqId (Integer) */
1346 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1348 if (elem
.type
!= BE_INT
) {
1349 ND_PRINT((ndo
, "[reqId!=INT]"));
1350 asn1_print(ndo
, &elem
);
1354 ND_PRINT((ndo
, "R=%d ", elem
.data
.integer
));
1358 /* errorStatus (Integer) */
1359 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1361 if (elem
.type
!= BE_INT
) {
1362 ND_PRINT((ndo
, "[errorStatus!=INT]"));
1363 asn1_print(ndo
, &elem
);
1367 if ((pduid
== GETREQ
|| pduid
== GETNEXTREQ
|| pduid
== SETREQ
1368 || pduid
== INFORMREQ
|| pduid
== V2TRAP
|| pduid
== REPORT
)
1369 && elem
.data
.integer
!= 0) {
1371 ND_PRINT((ndo
, "[errorStatus(%s)!=0]",
1372 DECODE_ErrorStatus(elem
.data
.integer
)));
1373 } else if (pduid
== GETBULKREQ
) {
1374 ND_PRINT((ndo
, " N=%d", elem
.data
.integer
));
1375 } else if (elem
.data
.integer
!= 0) {
1377 ND_PRINT((ndo
, " %s", DECODE_ErrorStatus(elem
.data
.integer
)));
1378 error_status
= elem
.data
.integer
;
1383 /* errorIndex (Integer) */
1384 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1386 if (elem
.type
!= BE_INT
) {
1387 ND_PRINT((ndo
, "[errorIndex!=INT]"));
1388 asn1_print(ndo
, &elem
);
1391 if ((pduid
== GETREQ
|| pduid
== GETNEXTREQ
|| pduid
== SETREQ
1392 || pduid
== INFORMREQ
|| pduid
== V2TRAP
|| pduid
== REPORT
)
1393 && elem
.data
.integer
!= 0)
1394 ND_PRINT((ndo
, "[errorIndex(%d)!=0]", elem
.data
.integer
));
1395 else if (pduid
== GETBULKREQ
)
1396 ND_PRINT((ndo
, " M=%d", elem
.data
.integer
));
1397 else if (elem
.data
.integer
!= 0) {
1399 ND_PRINT((ndo
, "[errorIndex(%d) w/o errorStatus]", elem
.data
.integer
));
1401 ND_PRINT((ndo
, "@%d", elem
.data
.integer
));
1402 } else if (error_status
) {
1403 ND_PRINT((ndo
, "[errorIndex==0]"));
1408 varbind_print(ndo
, pduid
, np
, length
);
1413 * Decode SNMP Trap PDU
1416 trappdu_print(netdissect_options
*ndo
,
1417 const u_char
*np
, u_int length
)
1420 int count
= 0, generic
;
1422 ND_PRINT((ndo
, " "));
1424 /* enterprise (oid) */
1425 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1427 if (elem
.type
!= BE_OID
) {
1428 ND_PRINT((ndo
, "[enterprise!=OID]"));
1429 asn1_print(ndo
, &elem
);
1432 if (asn1_print(ndo
, &elem
) < 0)
1437 ND_PRINT((ndo
, " "));
1439 /* agent-addr (inetaddr) */
1440 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1442 if (elem
.type
!= BE_INETADDR
) {
1443 ND_PRINT((ndo
, "[agent-addr!=INETADDR]"));
1444 asn1_print(ndo
, &elem
);
1447 if (asn1_print(ndo
, &elem
) < 0)
1452 /* generic-trap (Integer) */
1453 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1455 if (elem
.type
!= BE_INT
) {
1456 ND_PRINT((ndo
, "[generic-trap!=INT]"));
1457 asn1_print(ndo
, &elem
);
1460 generic
= elem
.data
.integer
;
1463 ND_PRINT((ndo
, " %s", DECODE_GenericTrap(generic
)));
1468 /* specific-trap (Integer) */
1469 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1471 if (elem
.type
!= BE_INT
) {
1472 ND_PRINT((ndo
, "[specific-trap!=INT]"));
1473 asn1_print(ndo
, &elem
);
1476 if (generic
!= GT_ENTERPRISE
) {
1477 if (elem
.data
.integer
!= 0)
1478 ND_PRINT((ndo
, "[specific-trap(%d)!=0]", elem
.data
.integer
));
1480 ND_PRINT((ndo
, " s=%d", elem
.data
.integer
));
1484 ND_PRINT((ndo
, " "));
1486 /* time-stamp (TimeTicks) */
1487 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1489 if (elem
.type
!= BE_UNS
) { /* XXX */
1490 ND_PRINT((ndo
, "[time-stamp!=TIMETICKS]"));
1491 asn1_print(ndo
, &elem
);
1494 if (asn1_print(ndo
, &elem
) < 0)
1499 varbind_print(ndo
, TRAP
, np
, length
);
1504 * Decode arbitrary SNMP PDUs.
1507 pdu_print(netdissect_options
*ndo
,
1508 const u_char
*np
, u_int length
, int version
)
1514 if ((count
= asn1_parse(ndo
, np
, length
, &pdu
)) < 0)
1516 if (pdu
.type
!= BE_PDU
) {
1517 ND_PRINT((ndo
, "[no PDU]"));
1520 if ((u_int
)count
< length
)
1521 ND_PRINT((ndo
, "[%d extra after PDU]", length
- count
));
1522 if (ndo
->ndo_vflag
) {
1523 ND_PRINT((ndo
, "{ "));
1525 if (asn1_print(ndo
, &pdu
) < 0)
1527 ND_PRINT((ndo
, " "));
1528 /* descend into PDU */
1529 length
= pdu
.asnlen
;
1530 np
= (const u_char
*)pdu
.data
.raw
;
1532 if (version
== SNMP_VERSION_1
&&
1533 (pdu
.id
== GETBULKREQ
|| pdu
.id
== INFORMREQ
||
1534 pdu
.id
== V2TRAP
|| pdu
.id
== REPORT
)) {
1535 ND_PRINT((ndo
, "[v2 PDU in v1 message]"));
1539 if (version
== SNMP_VERSION_2
&& pdu
.id
== TRAP
) {
1540 ND_PRINT((ndo
, "[v1 PDU in v2 message]"));
1546 trappdu_print(ndo
, np
, length
);
1556 snmppdu_print(ndo
, pdu
.id
, np
, length
);
1560 if (ndo
->ndo_vflag
) {
1561 ND_PRINT((ndo
, " } "));
1566 * Decode a scoped SNMP PDU.
1569 scopedpdu_print(netdissect_options
*ndo
,
1570 const u_char
*np
, u_int length
, int version
)
1576 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1578 if (elem
.type
!= BE_SEQ
) {
1579 ND_PRINT((ndo
, "[!scoped PDU]"));
1580 asn1_print(ndo
, &elem
);
1583 length
= elem
.asnlen
;
1584 np
= (const u_char
*)elem
.data
.raw
;
1586 /* contextEngineID (OCTET STRING) */
1587 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1589 if (elem
.type
!= BE_STR
) {
1590 ND_PRINT((ndo
, "[contextEngineID!=STR]"));
1591 asn1_print(ndo
, &elem
);
1597 ND_PRINT((ndo
, "E="));
1598 if (asn1_print_octets(ndo
, &elem
) == -1)
1600 ND_PRINT((ndo
, " "));
1602 /* contextName (OCTET STRING) */
1603 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1605 if (elem
.type
!= BE_STR
) {
1606 ND_PRINT((ndo
, "[contextName!=STR]"));
1607 asn1_print(ndo
, &elem
);
1613 ND_PRINT((ndo
, "C="));
1614 if (asn1_print_string(ndo
, &elem
) == -1)
1616 ND_PRINT((ndo
, " "));
1618 pdu_print(ndo
, np
, length
, version
);
1622 * Decode SNMP Community Header (SNMPv1 and SNMPv2c)
1625 community_print(netdissect_options
*ndo
,
1626 const u_char
*np
, u_int length
, int version
)
1631 /* Community (String) */
1632 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1634 if (elem
.type
!= BE_STR
) {
1635 ND_PRINT((ndo
, "[comm!=STR]"));
1636 asn1_print(ndo
, &elem
);
1639 /* default community */
1640 if (!(elem
.asnlen
== sizeof(DEF_COMMUNITY
) - 1 &&
1641 strncmp((const char *)elem
.data
.str
, DEF_COMMUNITY
,
1642 sizeof(DEF_COMMUNITY
) - 1) == 0)) {
1644 ND_PRINT((ndo
, "C="));
1645 if (asn1_print_string(ndo
, &elem
) == -1)
1647 ND_PRINT((ndo
, " "));
1652 pdu_print(ndo
, np
, length
, version
);
1656 * Decode SNMPv3 User-based Security Message Header (SNMPv3)
1659 usm_print(netdissect_options
*ndo
,
1660 const u_char
*np
, u_int length
)
1666 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1668 if (elem
.type
!= BE_SEQ
) {
1669 ND_PRINT((ndo
, "[!usm]"));
1670 asn1_print(ndo
, &elem
);
1673 length
= elem
.asnlen
;
1674 np
= (const u_char
*)elem
.data
.raw
;
1676 /* msgAuthoritativeEngineID (OCTET STRING) */
1677 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1679 if (elem
.type
!= BE_STR
) {
1680 ND_PRINT((ndo
, "[msgAuthoritativeEngineID!=STR]"));
1681 asn1_print(ndo
, &elem
);
1687 /* msgAuthoritativeEngineBoots (INTEGER) */
1688 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1690 if (elem
.type
!= BE_INT
) {
1691 ND_PRINT((ndo
, "[msgAuthoritativeEngineBoots!=INT]"));
1692 asn1_print(ndo
, &elem
);
1696 ND_PRINT((ndo
, "B=%d ", elem
.data
.integer
));
1700 /* msgAuthoritativeEngineTime (INTEGER) */
1701 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1703 if (elem
.type
!= BE_INT
) {
1704 ND_PRINT((ndo
, "[msgAuthoritativeEngineTime!=INT]"));
1705 asn1_print(ndo
, &elem
);
1709 ND_PRINT((ndo
, "T=%d ", elem
.data
.integer
));
1713 /* msgUserName (OCTET STRING) */
1714 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1716 if (elem
.type
!= BE_STR
) {
1717 ND_PRINT((ndo
, "[msgUserName!=STR]"));
1718 asn1_print(ndo
, &elem
);
1724 ND_PRINT((ndo
, "U="));
1725 if (asn1_print_string(ndo
, &elem
) == -1)
1727 ND_PRINT((ndo
, " "));
1729 /* msgAuthenticationParameters (OCTET STRING) */
1730 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1732 if (elem
.type
!= BE_STR
) {
1733 ND_PRINT((ndo
, "[msgAuthenticationParameters!=STR]"));
1734 asn1_print(ndo
, &elem
);
1740 /* msgPrivacyParameters (OCTET STRING) */
1741 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1743 if (elem
.type
!= BE_STR
) {
1744 ND_PRINT((ndo
, "[msgPrivacyParameters!=STR]"));
1745 asn1_print(ndo
, &elem
);
1751 if ((u_int
)count
< length
)
1752 ND_PRINT((ndo
, "[%d extra after usm SEQ]", length
- count
));
1756 * Decode SNMPv3 Message Header (SNMPv3)
1759 v3msg_print(netdissect_options
*ndo
,
1760 const u_char
*np
, u_int length
)
1766 const u_char
*xnp
= np
;
1767 int xlength
= length
;
1770 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1772 if (elem
.type
!= BE_SEQ
) {
1773 ND_PRINT((ndo
, "[!message]"));
1774 asn1_print(ndo
, &elem
);
1777 length
= elem
.asnlen
;
1778 np
= (const u_char
*)elem
.data
.raw
;
1780 if (ndo
->ndo_vflag
) {
1781 ND_PRINT((ndo
, "{ "));
1784 /* msgID (INTEGER) */
1785 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1787 if (elem
.type
!= BE_INT
) {
1788 ND_PRINT((ndo
, "[msgID!=INT]"));
1789 asn1_print(ndo
, &elem
);
1795 /* msgMaxSize (INTEGER) */
1796 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1798 if (elem
.type
!= BE_INT
) {
1799 ND_PRINT((ndo
, "[msgMaxSize!=INT]"));
1800 asn1_print(ndo
, &elem
);
1806 /* msgFlags (OCTET STRING) */
1807 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1809 if (elem
.type
!= BE_STR
) {
1810 ND_PRINT((ndo
, "[msgFlags!=STR]"));
1811 asn1_print(ndo
, &elem
);
1814 if (elem
.asnlen
!= 1) {
1815 ND_PRINT((ndo
, "[msgFlags size %d]", elem
.asnlen
));
1818 flags
= elem
.data
.str
[0];
1819 if (flags
!= 0x00 && flags
!= 0x01 && flags
!= 0x03
1820 && flags
!= 0x04 && flags
!= 0x05 && flags
!= 0x07) {
1821 ND_PRINT((ndo
, "[msgFlags=0x%02X]", flags
));
1827 ND_PRINT((ndo
, "F=%s%s%s ",
1828 flags
& 0x01 ? "a" : "",
1829 flags
& 0x02 ? "p" : "",
1830 flags
& 0x04 ? "r" : ""));
1832 /* msgSecurityModel (INTEGER) */
1833 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1835 if (elem
.type
!= BE_INT
) {
1836 ND_PRINT((ndo
, "[msgSecurityModel!=INT]"));
1837 asn1_print(ndo
, &elem
);
1840 model
= elem
.data
.integer
;
1844 if ((u_int
)count
< length
)
1845 ND_PRINT((ndo
, "[%d extra after message SEQ]", length
- count
));
1847 if (ndo
->ndo_vflag
) {
1848 ND_PRINT((ndo
, "} "));
1852 if (ndo
->ndo_vflag
) {
1853 ND_PRINT((ndo
, "{ USM "));
1856 ND_PRINT((ndo
, "[security model %d]", model
));
1860 np
= xnp
+ (np
- xnp
);
1861 length
= xlength
- (np
- xnp
);
1863 /* msgSecurityParameters (OCTET STRING) */
1864 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1866 if (elem
.type
!= BE_STR
) {
1867 ND_PRINT((ndo
, "[msgSecurityParameters!=STR]"));
1868 asn1_print(ndo
, &elem
);
1875 usm_print(ndo
, elem
.data
.str
, elem
.asnlen
);
1876 if (ndo
->ndo_vflag
) {
1877 ND_PRINT((ndo
, "} "));
1881 if (ndo
->ndo_vflag
) {
1882 ND_PRINT((ndo
, "{ ScopedPDU "));
1885 scopedpdu_print(ndo
, np
, length
, 3);
1887 if (ndo
->ndo_vflag
) {
1888 ND_PRINT((ndo
, "} "));
1893 * Decode SNMP header and pass on to PDU printing routines
1896 snmp_print(netdissect_options
*ndo
,
1897 const u_char
*np
, u_int length
)
1903 ND_PRINT((ndo
, " "));
1905 /* initial Sequence */
1906 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1908 if (elem
.type
!= BE_SEQ
) {
1909 ND_PRINT((ndo
, "[!init SEQ]"));
1910 asn1_print(ndo
, &elem
);
1913 if ((u_int
)count
< length
)
1914 ND_PRINT((ndo
, "[%d extra after iSEQ]", length
- count
));
1916 length
= elem
.asnlen
;
1917 np
= (const u_char
*)elem
.data
.raw
;
1919 /* Version (INTEGER) */
1920 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1922 if (elem
.type
!= BE_INT
) {
1923 ND_PRINT((ndo
, "[version!=INT]"));
1924 asn1_print(ndo
, &elem
);
1928 switch (elem
.data
.integer
) {
1929 case SNMP_VERSION_1
:
1930 case SNMP_VERSION_2
:
1931 case SNMP_VERSION_3
:
1933 ND_PRINT((ndo
, "{ %s ", SnmpVersion
[elem
.data
.integer
]));
1936 ND_PRINT((ndo
, "[version = %d]", elem
.data
.integer
));
1939 version
= elem
.data
.integer
;
1944 case SNMP_VERSION_1
:
1945 case SNMP_VERSION_2
:
1946 community_print(ndo
, np
, length
, version
);
1948 case SNMP_VERSION_3
:
1949 v3msg_print(ndo
, np
, length
);
1952 ND_PRINT((ndo
, "[version = %d]", elem
.data
.integer
));
1956 if (ndo
->ndo_vflag
) {
1957 ND_PRINT((ndo
, "} "));