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
63 #include <netdissect-stdinc.h>
72 #include "netdissect.h"
74 #undef OPAQUE /* defined in <wingdi.h> */
76 static const char tstr
[] = "[|snmp]";
79 * Universal ASN.1 types
80 * (we only care about the tag values for those allowed in the Internet SMI)
82 static const char *Universal
[] = {
95 "U-8","U-9","U-10","U-11", /* 8-11 */
96 "U-12","U-13","U-14","U-15", /* 12-15 */
103 * Application-wide ASN.1 types from the Internet SMI and their tags
105 static const char *Application
[] = {
122 * Context-specific ASN.1 types for the SNMP PDUs and their tags
124 static const char *Context
[] = {
145 #define NOTIFY_CLASS(x) (x == TRAP || x == V2TRAP || x == INFORMREQ)
146 #define READ_CLASS(x) (x == GETREQ || x == GETNEXTREQ || x == GETBULKREQ)
147 #define WRITE_CLASS(x) (x == SETREQ)
148 #define RESPONSE_CLASS(x) (x == GETRESP)
149 #define INTERNAL_CLASS(x) (x == REPORT)
152 * Context-specific ASN.1 types for the SNMP Exceptions and their tags
154 static const char *Exceptions
[] = {
156 #define NOSUCHOBJECT 0
158 #define NOSUCHINSTANCE 1
160 #define ENDOFMIBVIEW 2
164 * Private ASN.1 types
165 * The Internet SMI does not specify any
167 static const char *Private
[] = {
172 * error-status values for any SNMP PDU
174 static const char *ErrorStatus
[] = {
188 "resourceUnavailable",
191 "authorizationError",
195 #define DECODE_ErrorStatus(e) \
196 ( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \
198 : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf))
201 * generic-trap values in the SNMP Trap-PDU
203 static const char *GenericTrap
[] = {
208 "authenticationFailure",
211 #define GT_ENTERPRISE 6
213 #define DECODE_GenericTrap(t) \
214 ( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \
216 : (snprintf(buf, sizeof(buf), "gt=%d", t), buf))
219 * ASN.1 type class table
220 * Ties together the preceding Universal, Application, Context, and Private
223 #define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */
224 static const struct {
229 defineCLASS(Universal
),
231 defineCLASS(Application
),
232 #define APPLICATION 1
233 defineCLASS(Context
),
235 defineCLASS(Private
),
237 defineCLASS(Exceptions
),
242 * defined forms for ASN.1 types
244 static const char *Form
[] = {
248 #define CONSTRUCTED 1
252 * A structure for the OID tree for the compiled-in MIB.
253 * This is stored as a general-order tree.
256 const char *desc
; /* name of object */
257 u_char oid
; /* sub-id following parent */
258 u_char type
; /* object type (unused) */
259 struct obj
*child
, *next
; /* child and next sibling pointers */
263 * Include the compiled in SNMP MIB. "mib.h" is produced by feeding
264 * RFC-1156 format files into "makemib". "mib.h" MUST define at least
265 * a value for `mibroot'.
267 * In particular, this is gross, as this is including initialized structures,
268 * and by right shouldn't be an "include" file.
273 * This defines a list of OIDs which will be abbreviated on output.
274 * Currently, this includes the prefixes for the Internet MIB, the
275 * private enterprises tree, and the experimental tree.
277 static const struct obj_abrev
{
278 const char *prefix
; /* prefix for this abrev */
279 struct obj
*node
; /* pointer into object table */
280 const char *oid
; /* ASN.1 encoded OID */
281 } obj_abrev_list
[] = {
283 /* .iso.org.dod.internet.mgmt.mib */
284 { "", &_mib_obj
, "\53\6\1\2\1" },
286 #ifndef NO_ABREV_ENTER
287 /* .iso.org.dod.internet.private.enterprises */
288 { "E:", &_enterprises_obj
, "\53\6\1\4\1" },
290 #ifndef NO_ABREV_EXPERI
291 /* .iso.org.dod.internet.experimental */
292 { "X:", &_experimental_obj
, "\53\6\1\3" },
294 #ifndef NO_ABBREV_SNMPMODS
295 /* .iso.org.dod.internet.snmpV2.snmpModules */
296 { "S:", &_snmpModules_obj
, "\53\6\1\6\3" },
302 * This is used in the OID print routine to walk down the object tree
303 * rooted at `mibroot'.
305 #define OBJ_PRINT(o, suppressdot) \
309 if ((o) == objp->oid) \
311 } while ((objp = objp->next) != NULL); \
314 ND_PRINT((ndo, suppressdot?"%s":".%s", objp->desc)); \
315 objp = objp->child; \
317 ND_PRINT((ndo, suppressdot?"%u":".%u", (o))); \
321 * This is the definition for the Any-Data-Type storage used purely for
322 * temporary internal representation while decoding an ASN.1 data stream.
337 u_char form
, class; /* tag info */
348 #define BE_INETADDR 8
351 #define BE_NOSUCHOBJECT 128
352 #define BE_NOSUCHINST 129
353 #define BE_ENDOFMIBVIEW 130
357 * SNMP versions recognized by this module
359 static const char *SnmpVersion
[] = {
361 #define SNMP_VERSION_1 0
363 #define SNMP_VERSION_2 1
365 #define SNMP_VERSION_2U 2
367 #define SNMP_VERSION_3 3
371 * Defaults for SNMP PDU components
373 #define DEF_COMMUNITY "public"
376 * constants for ASN.1 decoding
379 #define ASNLEN_INETADDR 4
382 #define ASN_BIT8 0x80
383 #define ASN_LONGLEN 0x80
385 #define ASN_ID_BITS 0x1f
386 #define ASN_FORM_BITS 0x20
387 #define ASN_FORM_SHIFT 5
388 #define ASN_CLASS_BITS 0xc0
389 #define ASN_CLASS_SHIFT 6
391 #define ASN_ID_EXT 0x1f /* extension ID in tag field */
394 * This decodes the next ASN.1 object in the stream pointed to by "p"
395 * (and of real-length "len") and stores the intermediate data in the
396 * provided BE object.
398 * This returns -l if it fails (i.e., the ASN.1 stream is not valid).
399 * O/w, this returns the number of bytes parsed from "p".
402 asn1_parse(netdissect_options
*ndo
,
403 register const u_char
*p
, u_int len
, struct be
*elem
)
405 u_char form
, class, id
;
411 ND_PRINT((ndo
, "[nothing to parse]"));
417 * it would be nice to use a bit field, but you can't depend on them.
418 * +---+---+---+---+---+---+---+---+
420 * +---+---+---+---+---+---+---+---+
423 id
= *p
& ASN_ID_BITS
; /* lower 5 bits, range 00-1f */
425 form
= (*p
& 0xe0) >> 5; /* move upper 3 bits to lower 3 */
426 class = form
>> 1; /* bits 7&6 -> bits 1&0, range 0-3 */
427 form
&= 0x1; /* bit 5 -> bit 0, range 0-1 */
429 form
= (u_char
)(*p
& ASN_FORM_BITS
) >> ASN_FORM_SHIFT
;
430 class = (u_char
)(*p
& ASN_CLASS_BITS
) >> ASN_CLASS_SHIFT
;
436 /* extended tag field */
437 if (id
== ASN_ID_EXT
) {
439 * The ID follows, as a sequence of octets with the
440 * 8th bit set and the remaining 7 bits being
441 * the next 7 bits of the value, terminated with
442 * an octet with the 8th bit not set.
444 * First, assemble all the octets with the 8th
445 * bit set. XXX - this doesn't handle a value
446 * that won't fit in 32 bits.
448 for (id
= 0; *p
& ASN_BIT8
; len
--, hdr
++, p
++) {
450 ND_PRINT((ndo
, "[Xtagfield?]"));
454 id
= (id
<< 7) | (*p
& ~ASN_BIT8
);
457 ND_PRINT((ndo
, "[Xtagfield?]"));
461 elem
->id
= id
= (id
<< 7) | *p
;
467 ND_PRINT((ndo
, "[no asnlen]"));
473 if (elem
->asnlen
& ASN_BIT8
) {
474 uint32_t noct
= elem
->asnlen
% ASN_BIT8
;
477 ND_PRINT((ndo
, "[asnlen? %d<%d]", len
, noct
));
480 ND_TCHECK2(*p
, noct
);
481 for (; noct
-- > 0; len
--, hdr
++)
482 elem
->asnlen
= (elem
->asnlen
<< ASN_SHIFT8
) | *p
++;
484 if (len
< elem
->asnlen
) {
485 ND_PRINT((ndo
, "[len%d<asnlen%u]", len
, elem
->asnlen
));
488 if (form
>= sizeof(Form
)/sizeof(Form
[0])) {
489 ND_PRINT((ndo
, "[form?%d]", form
));
492 if (class >= sizeof(Class
)/sizeof(Class
[0])) {
493 ND_PRINT((ndo
, "[class?%c/%d]", *Form
[form
], class));
496 if ((int)id
>= Class
[class].numIDs
) {
497 ND_PRINT((ndo
, "[id?%c/%s/%d]", *Form
[form
], Class
[class].name
, id
));
512 register int32_t data
;
516 ND_TCHECK2(*p
, elem
->asnlen
);
517 if (*p
& ASN_BIT8
) /* negative */
519 for (i
= elem
->asnlen
; i
-- > 0; p
++)
520 data
= (data
<< ASN_SHIFT8
) | *p
;
521 elem
->data
.integer
= data
;
527 elem
->data
.raw
= (const uint8_t *)p
;
531 elem
->type
= BE_NULL
;
532 elem
->data
.raw
= NULL
;
536 elem
->type
= BE_OCTET
;
537 elem
->data
.raw
= (const uint8_t *)p
;
538 ND_PRINT((ndo
, "[P/U/%s]", Class
[class].Id
[id
]));
546 elem
->type
= BE_INETADDR
;
547 elem
->data
.raw
= (const uint8_t *)p
;
553 register uint32_t data
;
554 ND_TCHECK2(*p
, elem
->asnlen
);
557 for (i
= elem
->asnlen
; i
-- > 0; p
++)
558 data
= (data
<< 8) + *p
;
559 elem
->data
.uns
= data
;
564 register uint32_t high
, low
;
565 ND_TCHECK2(*p
, elem
->asnlen
);
566 elem
->type
= BE_UNS64
;
568 for (i
= elem
->asnlen
; i
-- > 0; p
++) {
570 ((low
& 0xFF000000) >> 24);
571 low
= (low
<< 8) | *p
;
573 elem
->data
.uns64
.high
= high
;
574 elem
->data
.uns64
.low
= low
;
579 elem
->type
= BE_OCTET
;
580 elem
->data
.raw
= (const uint8_t *)p
;
581 ND_PRINT((ndo
, "[P/A/%s]",
582 Class
[class].Id
[id
]));
590 elem
->type
= BE_NOSUCHOBJECT
;
591 elem
->data
.raw
= NULL
;
595 elem
->type
= BE_NOSUCHINST
;
596 elem
->data
.raw
= NULL
;
600 elem
->type
= BE_ENDOFMIBVIEW
;
601 elem
->data
.raw
= NULL
;
607 ND_PRINT((ndo
, "[P/%s/%s]", Class
[class].name
, Class
[class].Id
[id
]));
608 ND_TCHECK2(*p
, elem
->asnlen
);
609 elem
->type
= BE_OCTET
;
610 elem
->data
.raw
= (const uint8_t *)p
;
621 elem
->data
.raw
= (const uint8_t *)p
;
625 elem
->type
= BE_OCTET
;
626 elem
->data
.raw
= (const uint8_t *)p
;
627 ND_PRINT((ndo
, "C/U/%s", Class
[class].Id
[id
]));
634 elem
->data
.raw
= (const uint8_t *)p
;
638 elem
->type
= BE_OCTET
;
639 elem
->data
.raw
= (const uint8_t *)p
;
640 ND_PRINT((ndo
, "C/%s/%s", Class
[class].name
, Class
[class].Id
[id
]));
647 return elem
->asnlen
+ hdr
;
650 ND_PRINT((ndo
, "%s", tstr
));
655 * Display the ASN.1 object represented by the BE object.
656 * This used to be an integral part of asn1_parse() before the intermediate
660 asn1_print(netdissect_options
*ndo
,
663 const u_char
*p
= (const u_char
*)elem
->data
.raw
;
664 uint32_t asnlen
= elem
->asnlen
;
667 switch (elem
->type
) {
670 ND_TCHECK2(*p
, asnlen
);
671 for (i
= asnlen
; i
-- > 0; p
++)
672 ND_PRINT((ndo
, "_%.2x", *p
));
679 int o
= 0, first
= -1;
682 if (!ndo
->ndo_mflag
&& !ndo
->ndo_nflag
&& asnlen
> 2) {
683 const struct obj_abrev
*a
= &obj_abrev_list
[0];
684 size_t a_len
= strlen(a
->oid
);
685 for (; a
->node
; a
++) {
686 ND_TCHECK2(*p
, a_len
);
687 if (memcmp(a
->oid
, p
, a_len
) == 0) {
688 objp
= a
->node
->child
;
691 ND_PRINT((ndo
, "%s", a
->prefix
));
698 for (; !ndo
->ndo_mflag
&& i
-- > 0; p
++) {
700 o
= (o
<< ASN_SHIFT7
) + (*p
& ~ASN_BIT8
);
701 if (*p
& ASN_LONGLEN
)
705 * first subitem encodes two items with 1st*OIDMUX+2nd
706 * (see X.690:1997 clause 8.19 for the details)
727 ND_PRINT((ndo
, "%d", elem
->data
.integer
));
731 ND_PRINT((ndo
, "%u", elem
->data
.uns
));
734 case BE_UNS64
: { /* idea borrowed from by Marshall Rose */
737 char *cpf
, *cpl
, last
[6], first
[30];
738 if (elem
->data
.uns64
.high
== 0) {
739 ND_PRINT((ndo
, "%u", elem
->data
.uns64
.low
));
742 d
= elem
->data
.uns64
.high
* 4294967296.0; /* 2^32 */
743 if (elem
->data
.uns64
.high
<= 0x1fffff) {
744 d
+= elem
->data
.uns64
.low
;
745 #if 0 /*is looks illegal, but what is the intention?*/
746 ND_PRINT((ndo
, "%.f", d
));
748 ND_PRINT((ndo
, "%f", d
));
752 d
+= (elem
->data
.uns64
.low
& 0xfffff000);
753 #if 0 /*is looks illegal, but what is the intention?*/
754 snprintf(first
, sizeof(first
), "%.f", d
);
756 snprintf(first
, sizeof(first
), "%f", d
);
758 snprintf(last
, sizeof(last
), "%5.5d",
759 elem
->data
.uns64
.low
& 0xfff);
760 for (carry
= 0, cpf
= first
+strlen(first
)-1, cpl
= last
+4;
763 j
= carry
+ (*cpf
- '0') + (*cpl
- '0');
772 ND_PRINT((ndo
, "%s", first
));
777 register int printable
= 1, first
= 1;
780 ND_TCHECK2(*p
, asnlen
);
781 for (i
= asnlen
; printable
&& i
-- > 0; p
++)
782 printable
= ND_ISPRINT(*p
);
785 ND_PRINT((ndo
, "\""));
786 if (fn_printn(ndo
, p
, asnlen
, ndo
->ndo_snapend
)) {
787 ND_PRINT((ndo
, "\""));
790 ND_PRINT((ndo
, "\""));
792 for (i
= asnlen
; i
-- > 0; p
++) {
793 ND_PRINT((ndo
, first
? "%.2x" : "_%.2x", *p
));
800 ND_PRINT((ndo
, "Seq(%u)", elem
->asnlen
));
804 if (asnlen
!= ASNLEN_INETADDR
)
805 ND_PRINT((ndo
, "[inetaddr len!=%d]", ASNLEN_INETADDR
));
806 ND_TCHECK2(*p
, asnlen
);
807 for (i
= asnlen
; i
-- != 0; p
++) {
808 ND_PRINT((ndo
, (i
== asnlen
-1) ? "%u" : ".%u", *p
));
812 case BE_NOSUCHOBJECT
:
814 case BE_ENDOFMIBVIEW
:
815 ND_PRINT((ndo
, "[%s]", Class
[EXCEPTIONS
].Id
[elem
->id
]));
819 ND_PRINT((ndo
, "%s(%u)", Class
[CONTEXT
].Id
[elem
->id
], elem
->asnlen
));
823 ND_PRINT((ndo
, "[BE_ANY!?]"));
827 ND_PRINT((ndo
, "[be!?]"));
833 ND_PRINT((ndo
, "%s", tstr
));
839 * This is a brute force ASN.1 printer: recurses to dump an entire structure.
840 * This will work for any ASN.1 stream, not just an SNMP PDU.
842 * By adding newlines and spaces at the correct places, this would print in
845 * This is not currently used.
848 asn1_decode(u_char
*p
, u_int length
)
853 while (i
>= 0 && length
> 0) {
854 i
= asn1_parse(ndo
, p
, length
, &elem
);
856 ND_PRINT((ndo
, " "));
857 if (asn1_print(ndo
, &elem
) < 0)
859 if (elem
.type
== BE_SEQ
|| elem
.type
== BE_PDU
) {
860 ND_PRINT((ndo
, " {"));
861 asn1_decode(elem
.data
.raw
, elem
.asnlen
);
862 ND_PRINT((ndo
, " }"));
874 SmiBasetype basetype
;
878 static const struct smi2be smi2betab
[] = {
879 { SMI_BASETYPE_INTEGER32
, BE_INT
},
880 { SMI_BASETYPE_OCTETSTRING
, BE_STR
},
881 { SMI_BASETYPE_OCTETSTRING
, BE_INETADDR
},
882 { SMI_BASETYPE_OBJECTIDENTIFIER
, BE_OID
},
883 { SMI_BASETYPE_UNSIGNED32
, BE_UNS
},
884 { SMI_BASETYPE_INTEGER64
, BE_NONE
},
885 { SMI_BASETYPE_UNSIGNED64
, BE_UNS64
},
886 { SMI_BASETYPE_FLOAT32
, BE_NONE
},
887 { SMI_BASETYPE_FLOAT64
, BE_NONE
},
888 { SMI_BASETYPE_FLOAT128
, BE_NONE
},
889 { SMI_BASETYPE_ENUM
, BE_INT
},
890 { SMI_BASETYPE_BITS
, BE_STR
},
891 { SMI_BASETYPE_UNKNOWN
, BE_NONE
}
895 smi_decode_oid(netdissect_options
*ndo
,
896 struct be
*elem
, unsigned int *oid
,
897 unsigned int oidsize
, unsigned int *oidlen
)
899 const u_char
*p
= (const u_char
*)elem
->data
.raw
;
900 uint32_t asnlen
= elem
->asnlen
;
901 int o
= 0, first
= -1, i
= asnlen
;
902 unsigned int firstval
;
904 for (*oidlen
= 0; ndo
->ndo_mflag
&& i
-- > 0; p
++) {
906 o
= (o
<< ASN_SHIFT7
) + (*p
& ~ASN_BIT8
);
907 if (*p
& ASN_LONGLEN
)
911 * first subitem encodes two items with 1st*OIDMUX+2nd
912 * (see X.690:1997 clause 8.19 for the details)
916 firstval
= o
/ OIDMUX
;
917 if (firstval
> 2) firstval
= 2;
918 o
-= firstval
* OIDMUX
;
919 if (*oidlen
< oidsize
) {
920 oid
[(*oidlen
)++] = firstval
;
923 if (*oidlen
< oidsize
) {
924 oid
[(*oidlen
)++] = o
;
931 ND_PRINT((ndo
, "%s", tstr
));
935 static int smi_check_type(SmiBasetype basetype
, int be
)
939 for (i
= 0; smi2betab
[i
].basetype
!= SMI_BASETYPE_UNKNOWN
; i
++) {
940 if (smi2betab
[i
].basetype
== basetype
&& smi2betab
[i
].be
== be
) {
948 static int smi_check_a_range(SmiType
*smiType
, SmiRange
*smiRange
,
953 switch (smiType
->basetype
) {
954 case SMI_BASETYPE_OBJECTIDENTIFIER
:
955 case SMI_BASETYPE_OCTETSTRING
:
956 if (smiRange
->minValue
.value
.unsigned32
957 == smiRange
->maxValue
.value
.unsigned32
) {
958 ok
= (elem
->asnlen
== smiRange
->minValue
.value
.unsigned32
);
960 ok
= (elem
->asnlen
>= smiRange
->minValue
.value
.unsigned32
961 && elem
->asnlen
<= smiRange
->maxValue
.value
.unsigned32
);
965 case SMI_BASETYPE_INTEGER32
:
966 ok
= (elem
->data
.integer
>= smiRange
->minValue
.value
.integer32
967 && elem
->data
.integer
<= smiRange
->maxValue
.value
.integer32
);
970 case SMI_BASETYPE_UNSIGNED32
:
971 ok
= (elem
->data
.uns
>= smiRange
->minValue
.value
.unsigned32
972 && elem
->data
.uns
<= smiRange
->maxValue
.value
.unsigned32
);
975 case SMI_BASETYPE_UNSIGNED64
:
979 /* case SMI_BASETYPE_INTEGER64: SMIng */
980 /* case SMI_BASETYPE_FLOAT32: SMIng */
981 /* case SMI_BASETYPE_FLOAT64: SMIng */
982 /* case SMI_BASETYPE_FLOAT128: SMIng */
984 case SMI_BASETYPE_ENUM
:
985 case SMI_BASETYPE_BITS
:
986 case SMI_BASETYPE_UNKNOWN
:
998 static int smi_check_range(SmiType
*smiType
, struct be
*elem
)
1003 for (smiRange
= smiGetFirstRange(smiType
);
1005 smiRange
= smiGetNextRange(smiRange
)) {
1007 ok
= smi_check_a_range(smiType
, smiRange
, elem
);
1015 SmiType
*parentType
;
1016 parentType
= smiGetParentType(smiType
);
1018 ok
= smi_check_range(parentType
, elem
);
1026 smi_print_variable(netdissect_options
*ndo
,
1027 struct be
*elem
, int *status
)
1029 unsigned int oid
[128], oidlen
;
1030 SmiNode
*smiNode
= NULL
;
1033 *status
= smi_decode_oid(ndo
, elem
, oid
, sizeof(oid
) / sizeof(unsigned int),
1037 smiNode
= smiGetNodeByOID(oidlen
, oid
);
1039 *status
= asn1_print(ndo
, elem
);
1042 if (ndo
->ndo_vflag
) {
1043 ND_PRINT((ndo
, "%s::", smiGetNodeModule(smiNode
)->name
));
1045 ND_PRINT((ndo
, "%s", smiNode
->name
));
1046 if (smiNode
->oidlen
< oidlen
) {
1047 for (i
= smiNode
->oidlen
; i
< oidlen
; i
++) {
1048 ND_PRINT((ndo
, ".%u", oid
[i
]));
1056 smi_print_value(netdissect_options
*ndo
,
1057 SmiNode
*smiNode
, u_short pduid
, struct be
*elem
)
1059 unsigned int i
, oid
[128], oidlen
;
1064 if (! smiNode
|| ! (smiNode
->nodekind
1065 & (SMI_NODEKIND_SCALAR
| SMI_NODEKIND_COLUMN
))) {
1066 return asn1_print(ndo
, elem
);
1069 if (elem
->type
== BE_NOSUCHOBJECT
1070 || elem
->type
== BE_NOSUCHINST
1071 || elem
->type
== BE_ENDOFMIBVIEW
) {
1072 return asn1_print(ndo
, elem
);
1075 if (NOTIFY_CLASS(pduid
) && smiNode
->access
< SMI_ACCESS_NOTIFY
) {
1076 ND_PRINT((ndo
, "[notNotifyable]"));
1079 if (READ_CLASS(pduid
) && smiNode
->access
< SMI_ACCESS_READ_ONLY
) {
1080 ND_PRINT((ndo
, "[notReadable]"));
1083 if (WRITE_CLASS(pduid
) && smiNode
->access
< SMI_ACCESS_READ_WRITE
) {
1084 ND_PRINT((ndo
, "[notWritable]"));
1087 if (RESPONSE_CLASS(pduid
)
1088 && smiNode
->access
== SMI_ACCESS_NOT_ACCESSIBLE
) {
1089 ND_PRINT((ndo
, "[noAccess]"));
1092 smiType
= smiGetNodeType(smiNode
);
1094 return asn1_print(ndo
, elem
);
1097 if (! smi_check_type(smiType
->basetype
, elem
->type
)) {
1098 ND_PRINT((ndo
, "[wrongType]"));
1101 if (! smi_check_range(smiType
, elem
)) {
1102 ND_PRINT((ndo
, "[outOfRange]"));
1105 /* resolve bits to named bits */
1107 /* check whether instance identifier is valid */
1109 /* apply display hints (integer, octetstring) */
1111 /* convert instance identifier to index type values */
1113 switch (elem
->type
) {
1115 if (smiType
->basetype
== SMI_BASETYPE_BITS
) {
1116 /* print bit labels */
1118 smi_decode_oid(ndo
, elem
, oid
,
1119 sizeof(oid
)/sizeof(unsigned int),
1121 smiNode
= smiGetNodeByOID(oidlen
, oid
);
1123 if (ndo
->ndo_vflag
) {
1124 ND_PRINT((ndo
, "%s::", smiGetNodeModule(smiNode
)->name
));
1126 ND_PRINT((ndo
, "%s", smiNode
->name
));
1127 if (smiNode
->oidlen
< oidlen
) {
1128 for (i
= smiNode
->oidlen
;
1130 ND_PRINT((ndo
, ".%u", oid
[i
]));
1139 if (smiType
->basetype
== SMI_BASETYPE_ENUM
) {
1140 for (nn
= smiGetFirstNamedNumber(smiType
);
1142 nn
= smiGetNextNamedNumber(nn
)) {
1143 if (nn
->value
.value
.integer32
1144 == elem
->data
.integer
) {
1145 ND_PRINT((ndo
, "%s", nn
->name
));
1146 ND_PRINT((ndo
, "(%d)", elem
->data
.integer
));
1156 return asn1_print(ndo
, elem
);
1163 * General SNMP header
1165 * version INTEGER {version-1(0)},
1166 * community OCTET STRING,
1169 * PDUs for all but Trap: (see rfc1157 from page 15 on)
1171 * request-id INTEGER,
1172 * error-status INTEGER,
1173 * error-index INTEGER,
1174 * varbindlist SEQUENCE OF
1182 * enterprise OBJECT IDENTIFIER,
1183 * agent-addr NetworkAddress,
1184 * generic-trap INTEGER,
1185 * specific-trap INTEGER,
1186 * time-stamp TimeTicks,
1187 * varbindlist SEQUENCE OF
1196 * Decode SNMP varBind
1199 varbind_print(netdissect_options
*ndo
,
1200 u_short pduid
, const u_char
*np
, u_int length
)
1205 SmiNode
*smiNode
= NULL
;
1209 /* Sequence of varBind */
1210 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1212 if (elem
.type
!= BE_SEQ
) {
1213 ND_PRINT((ndo
, "[!SEQ of varbind]"));
1214 asn1_print(ndo
, &elem
);
1217 if ((u_int
)count
< length
)
1218 ND_PRINT((ndo
, "[%d extra after SEQ of varbind]", length
- count
));
1220 length
= elem
.asnlen
;
1221 np
= (const u_char
*)elem
.data
.raw
;
1223 for (ind
= 1; length
> 0; ind
++) {
1224 const u_char
*vbend
;
1227 ND_PRINT((ndo
, " "));
1230 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1232 if (elem
.type
!= BE_SEQ
) {
1233 ND_PRINT((ndo
, "[!varbind]"));
1234 asn1_print(ndo
, &elem
);
1238 vblength
= length
- count
;
1240 length
= elem
.asnlen
;
1241 np
= (const u_char
*)elem
.data
.raw
;
1244 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1246 if (elem
.type
!= BE_OID
) {
1247 ND_PRINT((ndo
, "[objName!=OID]"));
1248 asn1_print(ndo
, &elem
);
1252 smiNode
= smi_print_variable(ndo
, &elem
, &status
);
1254 status
= asn1_print(ndo
, &elem
);
1261 if (pduid
!= GETREQ
&& pduid
!= GETNEXTREQ
1262 && pduid
!= GETBULKREQ
)
1263 ND_PRINT((ndo
, "="));
1266 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1268 if (pduid
== GETREQ
|| pduid
== GETNEXTREQ
1269 || pduid
== GETBULKREQ
) {
1270 if (elem
.type
!= BE_NULL
) {
1271 ND_PRINT((ndo
, "[objVal!=NULL]"));
1272 if (asn1_print(ndo
, &elem
) < 0)
1276 if (elem
.type
!= BE_NULL
) {
1278 status
= smi_print_value(ndo
, smiNode
, pduid
, &elem
);
1280 status
= asn1_print(ndo
, &elem
);
1292 * Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, SetRequest,
1293 * GetBulk, Inform, V2Trap, and Report
1296 snmppdu_print(netdissect_options
*ndo
,
1297 u_short pduid
, const u_char
*np
, u_int length
)
1300 int count
= 0, error_status
;
1302 /* reqId (Integer) */
1303 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1305 if (elem
.type
!= BE_INT
) {
1306 ND_PRINT((ndo
, "[reqId!=INT]"));
1307 asn1_print(ndo
, &elem
);
1311 ND_PRINT((ndo
, "R=%d ", elem
.data
.integer
));
1315 /* errorStatus (Integer) */
1316 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1318 if (elem
.type
!= BE_INT
) {
1319 ND_PRINT((ndo
, "[errorStatus!=INT]"));
1320 asn1_print(ndo
, &elem
);
1324 if ((pduid
== GETREQ
|| pduid
== GETNEXTREQ
|| pduid
== SETREQ
1325 || pduid
== INFORMREQ
|| pduid
== V2TRAP
|| pduid
== REPORT
)
1326 && elem
.data
.integer
!= 0) {
1328 ND_PRINT((ndo
, "[errorStatus(%s)!=0]",
1329 DECODE_ErrorStatus(elem
.data
.integer
)));
1330 } else if (pduid
== GETBULKREQ
) {
1331 ND_PRINT((ndo
, " N=%d", elem
.data
.integer
));
1332 } else if (elem
.data
.integer
!= 0) {
1334 ND_PRINT((ndo
, " %s", DECODE_ErrorStatus(elem
.data
.integer
)));
1335 error_status
= elem
.data
.integer
;
1340 /* errorIndex (Integer) */
1341 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1343 if (elem
.type
!= BE_INT
) {
1344 ND_PRINT((ndo
, "[errorIndex!=INT]"));
1345 asn1_print(ndo
, &elem
);
1348 if ((pduid
== GETREQ
|| pduid
== GETNEXTREQ
|| pduid
== SETREQ
1349 || pduid
== INFORMREQ
|| pduid
== V2TRAP
|| pduid
== REPORT
)
1350 && elem
.data
.integer
!= 0)
1351 ND_PRINT((ndo
, "[errorIndex(%d)!=0]", elem
.data
.integer
));
1352 else if (pduid
== GETBULKREQ
)
1353 ND_PRINT((ndo
, " M=%d", elem
.data
.integer
));
1354 else if (elem
.data
.integer
!= 0) {
1356 ND_PRINT((ndo
, "[errorIndex(%d) w/o errorStatus]", elem
.data
.integer
));
1358 ND_PRINT((ndo
, "@%d", elem
.data
.integer
));
1359 } else if (error_status
) {
1360 ND_PRINT((ndo
, "[errorIndex==0]"));
1365 varbind_print(ndo
, pduid
, np
, length
);
1370 * Decode SNMP Trap PDU
1373 trappdu_print(netdissect_options
*ndo
,
1374 const u_char
*np
, u_int length
)
1377 int count
= 0, generic
;
1379 ND_PRINT((ndo
, " "));
1381 /* enterprise (oid) */
1382 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1384 if (elem
.type
!= BE_OID
) {
1385 ND_PRINT((ndo
, "[enterprise!=OID]"));
1386 asn1_print(ndo
, &elem
);
1389 if (asn1_print(ndo
, &elem
) < 0)
1394 ND_PRINT((ndo
, " "));
1396 /* agent-addr (inetaddr) */
1397 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1399 if (elem
.type
!= BE_INETADDR
) {
1400 ND_PRINT((ndo
, "[agent-addr!=INETADDR]"));
1401 asn1_print(ndo
, &elem
);
1404 if (asn1_print(ndo
, &elem
) < 0)
1409 /* generic-trap (Integer) */
1410 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1412 if (elem
.type
!= BE_INT
) {
1413 ND_PRINT((ndo
, "[generic-trap!=INT]"));
1414 asn1_print(ndo
, &elem
);
1417 generic
= elem
.data
.integer
;
1420 ND_PRINT((ndo
, " %s", DECODE_GenericTrap(generic
)));
1425 /* specific-trap (Integer) */
1426 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1428 if (elem
.type
!= BE_INT
) {
1429 ND_PRINT((ndo
, "[specific-trap!=INT]"));
1430 asn1_print(ndo
, &elem
);
1433 if (generic
!= GT_ENTERPRISE
) {
1434 if (elem
.data
.integer
!= 0)
1435 ND_PRINT((ndo
, "[specific-trap(%d)!=0]", elem
.data
.integer
));
1437 ND_PRINT((ndo
, " s=%d", elem
.data
.integer
));
1441 ND_PRINT((ndo
, " "));
1443 /* time-stamp (TimeTicks) */
1444 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1446 if (elem
.type
!= BE_UNS
) { /* XXX */
1447 ND_PRINT((ndo
, "[time-stamp!=TIMETICKS]"));
1448 asn1_print(ndo
, &elem
);
1451 if (asn1_print(ndo
, &elem
) < 0)
1456 varbind_print(ndo
, TRAP
, np
, length
);
1461 * Decode arbitrary SNMP PDUs.
1464 pdu_print(netdissect_options
*ndo
,
1465 const u_char
*np
, u_int length
, int version
)
1471 if ((count
= asn1_parse(ndo
, np
, length
, &pdu
)) < 0)
1473 if (pdu
.type
!= BE_PDU
) {
1474 ND_PRINT((ndo
, "[no PDU]"));
1477 if ((u_int
)count
< length
)
1478 ND_PRINT((ndo
, "[%d extra after PDU]", length
- count
));
1479 if (ndo
->ndo_vflag
) {
1480 ND_PRINT((ndo
, "{ "));
1482 if (asn1_print(ndo
, &pdu
) < 0)
1484 ND_PRINT((ndo
, " "));
1485 /* descend into PDU */
1486 length
= pdu
.asnlen
;
1487 np
= (const u_char
*)pdu
.data
.raw
;
1489 if (version
== SNMP_VERSION_1
&&
1490 (pdu
.id
== GETBULKREQ
|| pdu
.id
== INFORMREQ
||
1491 pdu
.id
== V2TRAP
|| pdu
.id
== REPORT
)) {
1492 ND_PRINT((ndo
, "[v2 PDU in v1 message]"));
1496 if (version
== SNMP_VERSION_2
&& pdu
.id
== TRAP
) {
1497 ND_PRINT((ndo
, "[v1 PDU in v2 message]"));
1503 trappdu_print(ndo
, np
, length
);
1513 snmppdu_print(ndo
, pdu
.id
, np
, length
);
1517 if (ndo
->ndo_vflag
) {
1518 ND_PRINT((ndo
, " } "));
1523 * Decode a scoped SNMP PDU.
1526 scopedpdu_print(netdissect_options
*ndo
,
1527 const u_char
*np
, u_int length
, int version
)
1533 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1535 if (elem
.type
!= BE_SEQ
) {
1536 ND_PRINT((ndo
, "[!scoped PDU]"));
1537 asn1_print(ndo
, &elem
);
1540 length
= elem
.asnlen
;
1541 np
= (const u_char
*)elem
.data
.raw
;
1543 /* contextEngineID (OCTET STRING) */
1544 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1546 if (elem
.type
!= BE_STR
) {
1547 ND_PRINT((ndo
, "[contextEngineID!=STR]"));
1548 asn1_print(ndo
, &elem
);
1554 ND_PRINT((ndo
, "E= "));
1555 for (i
= 0; i
< (int)elem
.asnlen
; i
++) {
1556 ND_PRINT((ndo
, "0x%02X", elem
.data
.str
[i
]));
1558 ND_PRINT((ndo
, " "));
1560 /* contextName (OCTET STRING) */
1561 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1563 if (elem
.type
!= BE_STR
) {
1564 ND_PRINT((ndo
, "[contextName!=STR]"));
1565 asn1_print(ndo
, &elem
);
1571 ND_PRINT((ndo
, "C=%.*s ", (int)elem
.asnlen
, elem
.data
.str
));
1573 pdu_print(ndo
, np
, length
, version
);
1577 * Decode SNMP Community Header (SNMPv1 and SNMPv2c)
1580 community_print(netdissect_options
*ndo
,
1581 const u_char
*np
, u_int length
, int version
)
1586 /* Community (String) */
1587 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1589 if (elem
.type
!= BE_STR
) {
1590 ND_PRINT((ndo
, "[comm!=STR]"));
1591 asn1_print(ndo
, &elem
);
1594 /* default community */
1595 if (!(elem
.asnlen
== sizeof(DEF_COMMUNITY
) - 1 &&
1596 strncmp((const char *)elem
.data
.str
, DEF_COMMUNITY
,
1597 sizeof(DEF_COMMUNITY
) - 1) == 0))
1599 ND_PRINT((ndo
, "C=%.*s ", (int)elem
.asnlen
, elem
.data
.str
));
1603 pdu_print(ndo
, np
, length
, version
);
1607 * Decode SNMPv3 User-based Security Message Header (SNMPv3)
1610 usm_print(netdissect_options
*ndo
,
1611 const u_char
*np
, u_int length
)
1617 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1619 if (elem
.type
!= BE_SEQ
) {
1620 ND_PRINT((ndo
, "[!usm]"));
1621 asn1_print(ndo
, &elem
);
1624 length
= elem
.asnlen
;
1625 np
= (const u_char
*)elem
.data
.raw
;
1627 /* msgAuthoritativeEngineID (OCTET STRING) */
1628 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1630 if (elem
.type
!= BE_STR
) {
1631 ND_PRINT((ndo
, "[msgAuthoritativeEngineID!=STR]"));
1632 asn1_print(ndo
, &elem
);
1638 /* msgAuthoritativeEngineBoots (INTEGER) */
1639 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1641 if (elem
.type
!= BE_INT
) {
1642 ND_PRINT((ndo
, "[msgAuthoritativeEngineBoots!=INT]"));
1643 asn1_print(ndo
, &elem
);
1647 ND_PRINT((ndo
, "B=%d ", elem
.data
.integer
));
1651 /* msgAuthoritativeEngineTime (INTEGER) */
1652 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1654 if (elem
.type
!= BE_INT
) {
1655 ND_PRINT((ndo
, "[msgAuthoritativeEngineTime!=INT]"));
1656 asn1_print(ndo
, &elem
);
1660 ND_PRINT((ndo
, "T=%d ", elem
.data
.integer
));
1664 /* msgUserName (OCTET STRING) */
1665 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1667 if (elem
.type
!= BE_STR
) {
1668 ND_PRINT((ndo
, "[msgUserName!=STR]"));
1669 asn1_print(ndo
, &elem
);
1675 ND_PRINT((ndo
, "U=%.*s ", (int)elem
.asnlen
, elem
.data
.str
));
1677 /* msgAuthenticationParameters (OCTET STRING) */
1678 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1680 if (elem
.type
!= BE_STR
) {
1681 ND_PRINT((ndo
, "[msgAuthenticationParameters!=STR]"));
1682 asn1_print(ndo
, &elem
);
1688 /* msgPrivacyParameters (OCTET STRING) */
1689 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1691 if (elem
.type
!= BE_STR
) {
1692 ND_PRINT((ndo
, "[msgPrivacyParameters!=STR]"));
1693 asn1_print(ndo
, &elem
);
1699 if ((u_int
)count
< length
)
1700 ND_PRINT((ndo
, "[%d extra after usm SEQ]", length
- count
));
1704 * Decode SNMPv3 Message Header (SNMPv3)
1707 v3msg_print(netdissect_options
*ndo
,
1708 const u_char
*np
, u_int length
)
1714 const u_char
*xnp
= np
;
1715 int xlength
= length
;
1718 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1720 if (elem
.type
!= BE_SEQ
) {
1721 ND_PRINT((ndo
, "[!message]"));
1722 asn1_print(ndo
, &elem
);
1725 length
= elem
.asnlen
;
1726 np
= (const u_char
*)elem
.data
.raw
;
1728 if (ndo
->ndo_vflag
) {
1729 ND_PRINT((ndo
, "{ "));
1732 /* msgID (INTEGER) */
1733 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1735 if (elem
.type
!= BE_INT
) {
1736 ND_PRINT((ndo
, "[msgID!=INT]"));
1737 asn1_print(ndo
, &elem
);
1743 /* msgMaxSize (INTEGER) */
1744 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1746 if (elem
.type
!= BE_INT
) {
1747 ND_PRINT((ndo
, "[msgMaxSize!=INT]"));
1748 asn1_print(ndo
, &elem
);
1754 /* msgFlags (OCTET STRING) */
1755 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1757 if (elem
.type
!= BE_STR
) {
1758 ND_PRINT((ndo
, "[msgFlags!=STR]"));
1759 asn1_print(ndo
, &elem
);
1762 if (elem
.asnlen
!= 1) {
1763 ND_PRINT((ndo
, "[msgFlags size %d]", elem
.asnlen
));
1766 flags
= elem
.data
.str
[0];
1767 if (flags
!= 0x00 && flags
!= 0x01 && flags
!= 0x03
1768 && flags
!= 0x04 && flags
!= 0x05 && flags
!= 0x07) {
1769 ND_PRINT((ndo
, "[msgFlags=0x%02X]", flags
));
1775 ND_PRINT((ndo
, "F=%s%s%s ",
1776 flags
& 0x01 ? "a" : "",
1777 flags
& 0x02 ? "p" : "",
1778 flags
& 0x04 ? "r" : ""));
1780 /* msgSecurityModel (INTEGER) */
1781 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1783 if (elem
.type
!= BE_INT
) {
1784 ND_PRINT((ndo
, "[msgSecurityModel!=INT]"));
1785 asn1_print(ndo
, &elem
);
1788 model
= elem
.data
.integer
;
1792 if ((u_int
)count
< length
)
1793 ND_PRINT((ndo
, "[%d extra after message SEQ]", length
- count
));
1795 if (ndo
->ndo_vflag
) {
1796 ND_PRINT((ndo
, "} "));
1800 if (ndo
->ndo_vflag
) {
1801 ND_PRINT((ndo
, "{ USM "));
1804 ND_PRINT((ndo
, "[security model %d]", model
));
1808 np
= xnp
+ (np
- xnp
);
1809 length
= xlength
- (np
- xnp
);
1811 /* msgSecurityParameters (OCTET STRING) */
1812 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1814 if (elem
.type
!= BE_STR
) {
1815 ND_PRINT((ndo
, "[msgSecurityParameters!=STR]"));
1816 asn1_print(ndo
, &elem
);
1823 usm_print(ndo
, elem
.data
.str
, elem
.asnlen
);
1824 if (ndo
->ndo_vflag
) {
1825 ND_PRINT((ndo
, "} "));
1829 if (ndo
->ndo_vflag
) {
1830 ND_PRINT((ndo
, "{ ScopedPDU "));
1833 scopedpdu_print(ndo
, np
, length
, 3);
1835 if (ndo
->ndo_vflag
) {
1836 ND_PRINT((ndo
, "} "));
1841 * Decode SNMP header and pass on to PDU printing routines
1844 snmp_print(netdissect_options
*ndo
,
1845 const u_char
*np
, u_int length
)
1851 ND_PRINT((ndo
, " "));
1853 /* initial Sequence */
1854 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1856 if (elem
.type
!= BE_SEQ
) {
1857 ND_PRINT((ndo
, "[!init SEQ]"));
1858 asn1_print(ndo
, &elem
);
1861 if ((u_int
)count
< length
)
1862 ND_PRINT((ndo
, "[%d extra after iSEQ]", length
- count
));
1864 length
= elem
.asnlen
;
1865 np
= (const u_char
*)elem
.data
.raw
;
1867 /* Version (INTEGER) */
1868 if ((count
= asn1_parse(ndo
, np
, length
, &elem
)) < 0)
1870 if (elem
.type
!= BE_INT
) {
1871 ND_PRINT((ndo
, "[version!=INT]"));
1872 asn1_print(ndo
, &elem
);
1876 switch (elem
.data
.integer
) {
1877 case SNMP_VERSION_1
:
1878 case SNMP_VERSION_2
:
1879 case SNMP_VERSION_3
:
1881 ND_PRINT((ndo
, "{ %s ", SnmpVersion
[elem
.data
.integer
]));
1884 ND_PRINT((ndo
, "[version = %d]", elem
.data
.integer
));
1887 version
= elem
.data
.integer
;
1892 case SNMP_VERSION_1
:
1893 case SNMP_VERSION_2
:
1894 community_print(ndo
, np
, length
, version
);
1896 case SNMP_VERSION_3
:
1897 v3msg_print(ndo
, np
, length
);
1900 ND_PRINT((ndo
, "[version = %d]", elem
.data
.integer
));
1904 if (ndo
->ndo_vflag
) {
1905 ND_PRINT((ndo
, "} "));