1996-08-19 20:34:12 +00:00
|
|
|
/*
|
1998-09-15 19:36:32 +00:00
|
|
|
* Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
|
2002-06-21 00:43:23 +00:00
|
|
|
* John Robert LoVerso. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1996-08-19 20:34:12 +00:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* This implementation has been influenced by the CMU SNMP release,
|
|
|
|
* by Steve Waldbusser. However, this shares no code with that system.
|
|
|
|
* Additional ASN.1 insight gained from Marshall T. Rose's _The_Open_Book_.
|
|
|
|
* Earlier forms of this implementation were derived and/or inspired by an
|
|
|
|
* awk script originally written by C. Philip Wood of LANL (but later
|
|
|
|
* heavily modified by John Robert LoVerso). The copyright notice for
|
|
|
|
* that work is preserved below, even though it may not rightly apply
|
|
|
|
* to this file.
|
|
|
|
*
|
2000-01-30 00:45:58 +00:00
|
|
|
* Support for SNMPv2c/SNMPv3 and the ability to link the module against
|
|
|
|
* the libsmi was added by J. Schoenwaelder, Copyright (c) 1999.
|
|
|
|
*
|
1996-08-19 20:34:12 +00:00
|
|
|
* This started out as a very simple program, but the incremental decoding
|
|
|
|
* (into the BE structure) complicated things.
|
|
|
|
*
|
|
|
|
# Los Alamos National Laboratory
|
|
|
|
#
|
1998-09-15 19:36:32 +00:00
|
|
|
# Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
|
1996-08-19 20:34:12 +00:00
|
|
|
# This software was produced under a U.S. Government contract
|
|
|
|
# (W-7405-ENG-36) by Los Alamos National Laboratory, which is
|
|
|
|
# operated by the University of California for the U.S. Department
|
|
|
|
# of Energy. The U.S. Government is licensed to use, reproduce,
|
|
|
|
# and distribute this software. Permission is granted to the
|
|
|
|
# public to copy and use this software without charge, provided
|
|
|
|
# that this Notice and any statement of authorship are reproduced
|
|
|
|
# on all copies. Neither the Government nor the University makes
|
|
|
|
# any warranty, express or implied, or assumes any liability or
|
|
|
|
# responsibility for the use of this software.
|
|
|
|
# @(#)snmp.awk.x 1.1 (LANL) 1/15/90
|
|
|
|
*/
|
1997-05-27 02:11:31 +00:00
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
/* \summary: Simple Network Management Protocol (SNMP) printer */
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2023-05-10 15:02:34 +00:00
|
|
|
#include <config.h>
|
1996-08-19 20:34:12 +00:00
|
|
|
#endif
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
#include "netdissect-stdinc.h"
|
1996-08-19 20:34:12 +00:00
|
|
|
|
1998-09-15 19:36:32 +00:00
|
|
|
#include <stdio.h>
|
1996-08-19 20:34:12 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
#ifdef USE_LIBSMI
|
2000-01-30 00:45:58 +00:00
|
|
|
#include <smi.h>
|
|
|
|
#endif
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
#include "netdissect-ctype.h"
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
#include "netdissect.h"
|
2023-05-10 15:02:34 +00:00
|
|
|
#include "extract.h"
|
1996-08-19 20:34:12 +00:00
|
|
|
|
2005-05-29 18:17:16 +00:00
|
|
|
#undef OPAQUE /* defined in <wingdi.h> */
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
|
1996-08-19 20:34:12 +00:00
|
|
|
/*
|
|
|
|
* Universal ASN.1 types
|
|
|
|
* (we only care about the tag values for those allowed in the Internet SMI)
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *Universal[] = {
|
1996-08-19 20:34:12 +00:00
|
|
|
"U-0",
|
|
|
|
"Boolean",
|
|
|
|
"Integer",
|
|
|
|
#define INTEGER 2
|
|
|
|
"Bitstring",
|
|
|
|
"String",
|
|
|
|
#define STRING 4
|
|
|
|
"Null",
|
|
|
|
#define ASN_NULL 5
|
|
|
|
"ObjID",
|
|
|
|
#define OBJECTID 6
|
|
|
|
"ObjectDes",
|
|
|
|
"U-8","U-9","U-10","U-11", /* 8-11 */
|
|
|
|
"U-12","U-13","U-14","U-15", /* 12-15 */
|
|
|
|
"Sequence",
|
|
|
|
#define SEQUENCE 16
|
|
|
|
"Set"
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Application-wide ASN.1 types from the Internet SMI and their tags
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *Application[] = {
|
1996-08-19 20:34:12 +00:00
|
|
|
"IpAddress",
|
|
|
|
#define IPADDR 0
|
|
|
|
"Counter",
|
|
|
|
#define COUNTER 1
|
|
|
|
"Gauge",
|
|
|
|
#define GAUGE 2
|
|
|
|
"TimeTicks",
|
|
|
|
#define TIMETICKS 3
|
2000-01-30 00:45:58 +00:00
|
|
|
"Opaque",
|
|
|
|
#define OPAQUE 4
|
|
|
|
"C-5",
|
|
|
|
"Counter64"
|
|
|
|
#define COUNTER64 6
|
1996-08-19 20:34:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Context-specific ASN.1 types for the SNMP PDUs and their tags
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *Context[] = {
|
1996-08-19 20:34:12 +00:00
|
|
|
"GetRequest",
|
|
|
|
#define GETREQ 0
|
|
|
|
"GetNextRequest",
|
|
|
|
#define GETNEXTREQ 1
|
|
|
|
"GetResponse",
|
|
|
|
#define GETRESP 2
|
|
|
|
"SetRequest",
|
|
|
|
#define SETREQ 3
|
2000-01-30 00:45:58 +00:00
|
|
|
"Trap",
|
1996-08-19 20:34:12 +00:00
|
|
|
#define TRAP 4
|
2000-01-30 00:45:58 +00:00
|
|
|
"GetBulk",
|
|
|
|
#define GETBULKREQ 5
|
|
|
|
"Inform",
|
|
|
|
#define INFORMREQ 6
|
|
|
|
"V2Trap",
|
|
|
|
#define V2TRAP 7
|
|
|
|
"Report"
|
|
|
|
#define REPORT 8
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NOTIFY_CLASS(x) (x == TRAP || x == V2TRAP || x == INFORMREQ)
|
|
|
|
#define READ_CLASS(x) (x == GETREQ || x == GETNEXTREQ || x == GETBULKREQ)
|
|
|
|
#define WRITE_CLASS(x) (x == SETREQ)
|
|
|
|
#define RESPONSE_CLASS(x) (x == GETRESP)
|
|
|
|
#define INTERNAL_CLASS(x) (x == REPORT)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Context-specific ASN.1 types for the SNMP Exceptions and their tags
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *Exceptions[] = {
|
2000-01-30 00:45:58 +00:00
|
|
|
"noSuchObject",
|
|
|
|
#define NOSUCHOBJECT 0
|
|
|
|
"noSuchInstance",
|
|
|
|
#define NOSUCHINSTANCE 1
|
|
|
|
"endOfMibView",
|
|
|
|
#define ENDOFMIBVIEW 2
|
1996-08-19 20:34:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private ASN.1 types
|
|
|
|
* The Internet SMI does not specify any
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *Private[] = {
|
1996-08-19 20:34:12 +00:00
|
|
|
"P-0"
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* error-status values for any SNMP PDU
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *ErrorStatus[] = {
|
1996-08-19 20:34:12 +00:00
|
|
|
"noError",
|
|
|
|
"tooBig",
|
|
|
|
"noSuchName",
|
|
|
|
"badValue",
|
|
|
|
"readOnly",
|
2000-01-30 00:45:58 +00:00
|
|
|
"genErr",
|
|
|
|
"noAccess",
|
|
|
|
"wrongType",
|
|
|
|
"wrongLength",
|
|
|
|
"wrongEncoding",
|
|
|
|
"wrongValue",
|
|
|
|
"noCreation",
|
|
|
|
"inconsistentValue",
|
|
|
|
"resourceUnavailable",
|
|
|
|
"commitFailed",
|
|
|
|
"undoFailed",
|
|
|
|
"authorizationError",
|
|
|
|
"notWritable",
|
|
|
|
"inconsistentName"
|
1996-08-19 20:34:12 +00:00
|
|
|
};
|
|
|
|
#define DECODE_ErrorStatus(e) \
|
2004-03-31 09:17:26 +00:00
|
|
|
( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \
|
2001-04-03 07:45:48 +00:00
|
|
|
? ErrorStatus[e] \
|
|
|
|
: (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf))
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* generic-trap values in the SNMP Trap-PDU
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *GenericTrap[] = {
|
1996-08-19 20:34:12 +00:00
|
|
|
"coldStart",
|
|
|
|
"warmStart",
|
|
|
|
"linkDown",
|
|
|
|
"linkUp",
|
|
|
|
"authenticationFailure",
|
|
|
|
"egpNeighborLoss",
|
|
|
|
"enterpriseSpecific"
|
2004-03-31 09:17:26 +00:00
|
|
|
#define GT_ENTERPRISE 6
|
1996-08-19 20:34:12 +00:00
|
|
|
};
|
|
|
|
#define DECODE_GenericTrap(t) \
|
2004-03-31 09:17:26 +00:00
|
|
|
( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \
|
2001-04-03 07:45:48 +00:00
|
|
|
? GenericTrap[t] \
|
|
|
|
: (snprintf(buf, sizeof(buf), "gt=%d", t), buf))
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ASN.1 type class table
|
|
|
|
* Ties together the preceding Universal, Application, Context, and Private
|
|
|
|
* type definitions.
|
|
|
|
*/
|
|
|
|
#define defineCLASS(x) { "x", x, sizeof(x)/sizeof(x[0]) } /* not ANSI-C */
|
2015-01-06 19:03:11 +00:00
|
|
|
static const struct {
|
2004-03-31 09:17:26 +00:00
|
|
|
const char *name;
|
|
|
|
const char **Id;
|
1996-08-19 20:34:12 +00:00
|
|
|
int numIDs;
|
|
|
|
} Class[] = {
|
|
|
|
defineCLASS(Universal),
|
|
|
|
#define UNIVERSAL 0
|
|
|
|
defineCLASS(Application),
|
|
|
|
#define APPLICATION 1
|
|
|
|
defineCLASS(Context),
|
|
|
|
#define CONTEXT 2
|
|
|
|
defineCLASS(Private),
|
|
|
|
#define PRIVATE 3
|
2000-01-30 00:45:58 +00:00
|
|
|
defineCLASS(Exceptions),
|
|
|
|
#define EXCEPTIONS 4
|
1996-08-19 20:34:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* defined forms for ASN.1 types
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *Form[] = {
|
1996-08-19 20:34:12 +00:00
|
|
|
"Primitive",
|
|
|
|
#define PRIMITIVE 0
|
|
|
|
"Constructed",
|
|
|
|
#define CONSTRUCTED 1
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A structure for the OID tree for the compiled-in MIB.
|
|
|
|
* This is stored as a general-order tree.
|
|
|
|
*/
|
2017-01-31 19:17:06 +00:00
|
|
|
static struct obj {
|
2004-03-31 09:17:26 +00:00
|
|
|
const char *desc; /* name of object */
|
1996-08-19 20:34:12 +00:00
|
|
|
u_char oid; /* sub-id following parent */
|
|
|
|
u_char type; /* object type (unused) */
|
|
|
|
struct obj *child, *next; /* child and next sibling pointers */
|
|
|
|
} *objp = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Include the compiled in SNMP MIB. "mib.h" is produced by feeding
|
|
|
|
* RFC-1156 format files into "makemib". "mib.h" MUST define at least
|
|
|
|
* a value for `mibroot'.
|
|
|
|
*
|
|
|
|
* In particular, this is gross, as this is including initialized structures,
|
|
|
|
* and by right shouldn't be an "include" file.
|
|
|
|
*/
|
|
|
|
#include "mib.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This defines a list of OIDs which will be abbreviated on output.
|
|
|
|
* Currently, this includes the prefixes for the Internet MIB, the
|
|
|
|
* private enterprises tree, and the experimental tree.
|
|
|
|
*/
|
2017-01-31 19:17:06 +00:00
|
|
|
#define OID_FIRST_OCTET(x, y) (((x)*40) + (y)) /* X.690 8.19.4 */
|
|
|
|
|
|
|
|
#ifndef NO_ABREV_MIB
|
|
|
|
static const uint8_t mib_oid[] = { OID_FIRST_OCTET(1, 3), 6, 1, 2, 1 };
|
|
|
|
#endif
|
|
|
|
#ifndef NO_ABREV_ENTER
|
|
|
|
static const uint8_t enterprises_oid[] = { OID_FIRST_OCTET(1, 3), 6, 1, 4, 1 };
|
|
|
|
#endif
|
|
|
|
#ifndef NO_ABREV_EXPERI
|
|
|
|
static const uint8_t experimental_oid[] = { OID_FIRST_OCTET(1, 3), 6, 1, 3 };
|
|
|
|
#endif
|
|
|
|
#ifndef NO_ABBREV_SNMPMODS
|
|
|
|
static const uint8_t snmpModules_oid[] = { OID_FIRST_OCTET(1, 3), 6, 1, 6, 3 };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define OBJ_ABBREV_ENTRY(prefix, obj) \
|
|
|
|
{ prefix, &_ ## obj ## _obj, obj ## _oid, sizeof (obj ## _oid) }
|
2015-01-06 19:03:11 +00:00
|
|
|
static const struct obj_abrev {
|
2004-03-31 09:17:26 +00:00
|
|
|
const char *prefix; /* prefix for this abrev */
|
1996-08-19 20:34:12 +00:00
|
|
|
struct obj *node; /* pointer into object table */
|
2017-01-31 19:17:06 +00:00
|
|
|
const uint8_t *oid; /* ASN.1 encoded OID */
|
|
|
|
size_t oid_len; /* length of OID */
|
1996-08-19 20:34:12 +00:00
|
|
|
} obj_abrev_list[] = {
|
|
|
|
#ifndef NO_ABREV_MIB
|
|
|
|
/* .iso.org.dod.internet.mgmt.mib */
|
2017-01-31 19:17:06 +00:00
|
|
|
OBJ_ABBREV_ENTRY("", mib),
|
1996-08-19 20:34:12 +00:00
|
|
|
#endif
|
|
|
|
#ifndef NO_ABREV_ENTER
|
|
|
|
/* .iso.org.dod.internet.private.enterprises */
|
2017-01-31 19:17:06 +00:00
|
|
|
OBJ_ABBREV_ENTRY("E:", enterprises),
|
1996-08-19 20:34:12 +00:00
|
|
|
#endif
|
|
|
|
#ifndef NO_ABREV_EXPERI
|
|
|
|
/* .iso.org.dod.internet.experimental */
|
2017-01-31 19:17:06 +00:00
|
|
|
OBJ_ABBREV_ENTRY("X:", experimental),
|
2000-01-30 00:45:58 +00:00
|
|
|
#endif
|
|
|
|
#ifndef NO_ABBREV_SNMPMODS
|
|
|
|
/* .iso.org.dod.internet.snmpV2.snmpModules */
|
2017-01-31 19:17:06 +00:00
|
|
|
OBJ_ABBREV_ENTRY("S:", snmpModules),
|
1996-08-19 20:34:12 +00:00
|
|
|
#endif
|
2017-01-31 19:17:06 +00:00
|
|
|
{ 0,0,0,0 }
|
1996-08-19 20:34:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is used in the OID print routine to walk down the object tree
|
|
|
|
* rooted at `mibroot'.
|
|
|
|
*/
|
|
|
|
#define OBJ_PRINT(o, suppressdot) \
|
|
|
|
{ \
|
|
|
|
if (objp) { \
|
|
|
|
do { \
|
|
|
|
if ((o) == objp->oid) \
|
|
|
|
break; \
|
|
|
|
} while ((objp = objp->next) != NULL); \
|
|
|
|
} \
|
|
|
|
if (objp) { \
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(suppressdot?"%s":".%s", objp->desc); \
|
1996-08-19 20:34:12 +00:00
|
|
|
objp = objp->child; \
|
|
|
|
} else \
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(suppressdot?"%u":".%u", (o)); \
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the definition for the Any-Data-Type storage used purely for
|
|
|
|
* temporary internal representation while decoding an ASN.1 data stream.
|
|
|
|
*/
|
|
|
|
struct be {
|
2015-01-06 19:03:11 +00:00
|
|
|
uint32_t asnlen;
|
1996-08-19 20:34:12 +00:00
|
|
|
union {
|
2017-01-31 19:17:06 +00:00
|
|
|
const uint8_t *raw;
|
1996-08-19 20:34:12 +00:00
|
|
|
int32_t integer;
|
2015-01-06 19:03:11 +00:00
|
|
|
uint32_t uns;
|
1996-08-19 20:34:12 +00:00
|
|
|
const u_char *str;
|
2017-01-31 19:17:06 +00:00
|
|
|
uint64_t uns64;
|
1996-08-19 20:34:12 +00:00
|
|
|
} data;
|
|
|
|
u_short id;
|
|
|
|
u_char form, class; /* tag info */
|
|
|
|
u_char type;
|
|
|
|
#define BE_ANY 255
|
|
|
|
#define BE_NONE 0
|
|
|
|
#define BE_NULL 1
|
|
|
|
#define BE_OCTET 2
|
|
|
|
#define BE_OID 3
|
|
|
|
#define BE_INT 4
|
|
|
|
#define BE_UNS 5
|
|
|
|
#define BE_STR 6
|
|
|
|
#define BE_SEQ 7
|
|
|
|
#define BE_INETADDR 8
|
|
|
|
#define BE_PDU 9
|
2000-01-30 00:45:58 +00:00
|
|
|
#define BE_UNS64 10
|
|
|
|
#define BE_NOSUCHOBJECT 128
|
|
|
|
#define BE_NOSUCHINST 129
|
|
|
|
#define BE_ENDOFMIBVIEW 130
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SNMP versions recognized by this module
|
|
|
|
*/
|
2015-01-06 19:03:11 +00:00
|
|
|
static const char *SnmpVersion[] = {
|
2000-01-30 00:45:58 +00:00
|
|
|
"SNMPv1",
|
|
|
|
#define SNMP_VERSION_1 0
|
|
|
|
"SNMPv2c",
|
|
|
|
#define SNMP_VERSION_2 1
|
|
|
|
"SNMPv2u",
|
|
|
|
#define SNMP_VERSION_2U 2
|
|
|
|
"SNMPv3"
|
|
|
|
#define SNMP_VERSION_3 3
|
1996-08-19 20:34:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Defaults for SNMP PDU components
|
|
|
|
*/
|
|
|
|
#define DEF_COMMUNITY "public"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* constants for ASN.1 decoding
|
|
|
|
*/
|
|
|
|
#define OIDMUX 40
|
|
|
|
#define ASNLEN_INETADDR 4
|
|
|
|
#define ASN_SHIFT7 7
|
|
|
|
#define ASN_SHIFT8 8
|
|
|
|
#define ASN_BIT8 0x80
|
|
|
|
#define ASN_LONGLEN 0x80
|
|
|
|
|
|
|
|
#define ASN_ID_BITS 0x1f
|
|
|
|
#define ASN_FORM_BITS 0x20
|
|
|
|
#define ASN_FORM_SHIFT 5
|
|
|
|
#define ASN_CLASS_BITS 0xc0
|
|
|
|
#define ASN_CLASS_SHIFT 6
|
|
|
|
|
|
|
|
#define ASN_ID_EXT 0x1f /* extension ID in tag field */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This decodes the next ASN.1 object in the stream pointed to by "p"
|
|
|
|
* (and of real-length "len") and stores the intermediate data in the
|
|
|
|
* provided BE object.
|
|
|
|
*
|
|
|
|
* This returns -l if it fails (i.e., the ASN.1 stream is not valid).
|
|
|
|
* O/w, this returns the number of bytes parsed from "p".
|
|
|
|
*/
|
|
|
|
static int
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_parse(netdissect_options *ndo,
|
2023-05-10 15:02:34 +00:00
|
|
|
const u_char *p, u_int len, struct be *elem)
|
1996-08-19 20:34:12 +00:00
|
|
|
{
|
|
|
|
u_char form, class, id;
|
2023-05-10 15:02:34 +00:00
|
|
|
u_int i, hdr;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
elem->asnlen = 0;
|
|
|
|
elem->type = BE_ANY;
|
|
|
|
if (len < 1) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[nothing to parse]");
|
1996-08-19 20:34:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* it would be nice to use a bit field, but you can't depend on them.
|
|
|
|
* +---+---+---+---+---+---+---+---+
|
|
|
|
* + class |frm| id |
|
|
|
|
* +---+---+---+---+---+---+---+---+
|
|
|
|
* 7 6 5 4 3 2 1 0
|
|
|
|
*/
|
2023-05-10 15:02:34 +00:00
|
|
|
id = GET_U_1(p) & ASN_ID_BITS; /* lower 5 bits, range 00-1f */
|
1996-08-19 20:34:12 +00:00
|
|
|
#ifdef notdef
|
2023-05-10 15:02:34 +00:00
|
|
|
form = (GET_U_1(p) & 0xe0) >> 5; /* move upper 3 bits to lower 3 */
|
1996-08-19 20:34:12 +00:00
|
|
|
class = form >> 1; /* bits 7&6 -> bits 1&0, range 0-3 */
|
|
|
|
form &= 0x1; /* bit 5 -> bit 0, range 0-1 */
|
|
|
|
#else
|
2023-05-10 15:02:34 +00:00
|
|
|
form = (u_char)(GET_U_1(p) & ASN_FORM_BITS) >> ASN_FORM_SHIFT;
|
|
|
|
class = (u_char)(GET_U_1(p) & ASN_CLASS_BITS) >> ASN_CLASS_SHIFT;
|
1996-08-19 20:34:12 +00:00
|
|
|
#endif
|
|
|
|
elem->form = form;
|
|
|
|
elem->class = class;
|
|
|
|
elem->id = id;
|
|
|
|
p++; len--; hdr = 1;
|
|
|
|
/* extended tag field */
|
|
|
|
if (id == ASN_ID_EXT) {
|
2005-05-29 18:17:16 +00:00
|
|
|
/*
|
|
|
|
* The ID follows, as a sequence of octets with the
|
|
|
|
* 8th bit set and the remaining 7 bits being
|
|
|
|
* the next 7 bits of the value, terminated with
|
|
|
|
* an octet with the 8th bit not set.
|
|
|
|
*
|
|
|
|
* First, assemble all the octets with the 8th
|
|
|
|
* bit set. XXX - this doesn't handle a value
|
|
|
|
* that won't fit in 32 bits.
|
|
|
|
*/
|
2017-01-31 19:17:06 +00:00
|
|
|
id = 0;
|
2023-05-10 15:02:34 +00:00
|
|
|
while (GET_U_1(p) & ASN_BIT8) {
|
2005-05-29 18:17:16 +00:00
|
|
|
if (len < 1) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[Xtagfield?]");
|
2005-05-29 18:17:16 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
id = (id << 7) | (GET_U_1(p) & ~ASN_BIT8);
|
2017-01-31 19:17:06 +00:00
|
|
|
len--;
|
|
|
|
hdr++;
|
|
|
|
p++;
|
2005-05-29 18:17:16 +00:00
|
|
|
}
|
|
|
|
if (len < 1) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[Xtagfield?]");
|
1996-08-19 20:34:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
elem->id = id = (id << 7) | GET_U_1(p);
|
1996-08-19 20:34:12 +00:00
|
|
|
--len;
|
|
|
|
++hdr;
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
if (len < 1) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[no asnlen]");
|
1996-08-19 20:34:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
elem->asnlen = GET_U_1(p);
|
1996-08-19 20:34:12 +00:00
|
|
|
p++; len--; hdr++;
|
|
|
|
if (elem->asnlen & ASN_BIT8) {
|
2015-01-06 19:03:11 +00:00
|
|
|
uint32_t noct = elem->asnlen % ASN_BIT8;
|
1996-08-19 20:34:12 +00:00
|
|
|
elem->asnlen = 0;
|
|
|
|
if (len < noct) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[asnlen? %d<%d]", len, noct);
|
1996-08-19 20:34:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_TCHECK_LEN(p, noct);
|
|
|
|
for (; noct != 0; len--, hdr++, noct--) {
|
|
|
|
elem->asnlen = (elem->asnlen << ASN_SHIFT8) | GET_U_1(p);
|
|
|
|
p++;
|
|
|
|
}
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
if (len < elem->asnlen) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[len%d<asnlen%u]", len, elem->asnlen);
|
2005-05-29 18:17:16 +00:00
|
|
|
return -1;
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
if (form >= sizeof(Form)/sizeof(Form[0])) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[form?%d]", form);
|
1996-08-19 20:34:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (class >= sizeof(Class)/sizeof(Class[0])) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[class?%c/%d]", *Form[form], class);
|
1996-08-19 20:34:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
1997-05-27 02:11:31 +00:00
|
|
|
if ((int)id >= Class[class].numIDs) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[id?%c/%s/%d]", *Form[form], Class[class].name, id);
|
1996-08-19 20:34:12 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_TCHECK_LEN(p, elem->asnlen);
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
switch (form) {
|
|
|
|
case PRIMITIVE:
|
|
|
|
switch (class) {
|
|
|
|
case UNIVERSAL:
|
|
|
|
switch (id) {
|
|
|
|
case STRING:
|
|
|
|
elem->type = BE_STR;
|
|
|
|
elem->data.str = p;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INTEGER: {
|
2023-05-10 15:02:34 +00:00
|
|
|
int32_t data;
|
1996-08-19 20:34:12 +00:00
|
|
|
elem->type = BE_INT;
|
|
|
|
data = 0;
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
if (elem->asnlen == 0) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[asnlen=0]");
|
2017-01-31 19:17:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
if (GET_U_1(p) & ASN_BIT8) /* negative */
|
1996-08-19 20:34:12 +00:00
|
|
|
data = -1;
|
2023-05-10 15:02:34 +00:00
|
|
|
for (i = elem->asnlen; i != 0; p++, i--)
|
|
|
|
data = (data << ASN_SHIFT8) | GET_U_1(p);
|
1996-08-19 20:34:12 +00:00
|
|
|
elem->data.integer = data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OBJECTID:
|
|
|
|
elem->type = BE_OID;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ASN_NULL:
|
|
|
|
elem->type = BE_NULL;
|
|
|
|
elem->data.raw = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
elem->type = BE_OCTET;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[P/U/%s]", Class[class].Id[id]);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APPLICATION:
|
|
|
|
switch (id) {
|
|
|
|
case IPADDR:
|
|
|
|
elem->type = BE_INETADDR;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COUNTER:
|
|
|
|
case GAUGE:
|
|
|
|
case TIMETICKS: {
|
2023-05-10 15:02:34 +00:00
|
|
|
uint32_t data;
|
1996-08-19 20:34:12 +00:00
|
|
|
elem->type = BE_UNS;
|
|
|
|
data = 0;
|
2023-05-10 15:02:34 +00:00
|
|
|
for (i = elem->asnlen; i != 0; p++, i--)
|
|
|
|
data = (data << 8) + GET_U_1(p);
|
1996-08-19 20:34:12 +00:00
|
|
|
elem->data.uns = data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
case COUNTER64: {
|
2023-05-10 15:02:34 +00:00
|
|
|
uint64_t data64;
|
2000-01-30 00:45:58 +00:00
|
|
|
elem->type = BE_UNS64;
|
2017-01-31 19:17:06 +00:00
|
|
|
data64 = 0;
|
2023-05-10 15:02:34 +00:00
|
|
|
for (i = elem->asnlen; i != 0; p++, i--)
|
|
|
|
data64 = (data64 << 8) + GET_U_1(p);
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.uns64 = data64;
|
2000-01-30 00:45:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1996-08-19 20:34:12 +00:00
|
|
|
default:
|
|
|
|
elem->type = BE_OCTET;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[P/A/%s]",
|
|
|
|
Class[class].Id[id]);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
case CONTEXT:
|
|
|
|
switch (id) {
|
|
|
|
case NOSUCHOBJECT:
|
|
|
|
elem->type = BE_NOSUCHOBJECT;
|
|
|
|
elem->data.raw = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case NOSUCHINSTANCE:
|
|
|
|
elem->type = BE_NOSUCHINST;
|
|
|
|
elem->data.raw = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ENDOFMIBVIEW:
|
|
|
|
elem->type = BE_ENDOFMIBVIEW;
|
|
|
|
elem->data.raw = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1996-08-19 20:34:12 +00:00
|
|
|
default:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[P/%s/%s]", Class[class].name, Class[class].Id[id]);
|
2005-05-29 18:17:16 +00:00
|
|
|
elem->type = BE_OCTET;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONSTRUCTED:
|
|
|
|
switch (class) {
|
|
|
|
case UNIVERSAL:
|
|
|
|
switch (id) {
|
|
|
|
case SEQUENCE:
|
|
|
|
elem->type = BE_SEQ;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
elem->type = BE_OCTET;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("C/U/%s", Class[class].Id[id]);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTEXT:
|
|
|
|
elem->type = BE_PDU;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
elem->type = BE_OCTET;
|
2017-01-31 19:17:06 +00:00
|
|
|
elem->data.raw = (const uint8_t *)p;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("C/%s/%s", Class[class].name, Class[class].Id[id]);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p += elem->asnlen;
|
|
|
|
len -= elem->asnlen;
|
|
|
|
return elem->asnlen + hdr;
|
2005-05-29 18:17:16 +00:00
|
|
|
|
|
|
|
trunc:
|
2023-05-10 15:02:34 +00:00
|
|
|
nd_print_trunc(ndo);
|
2005-05-29 18:17:16 +00:00
|
|
|
return -1;
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
static int
|
|
|
|
asn1_print_octets(netdissect_options *ndo, struct be *elem)
|
|
|
|
{
|
|
|
|
const u_char *p = (const u_char *)elem->data.raw;
|
|
|
|
uint32_t asnlen = elem->asnlen;
|
|
|
|
uint32_t i;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_TCHECK_LEN(p, asnlen);
|
|
|
|
for (i = asnlen; i != 0; p++, i--)
|
|
|
|
ND_PRINT("_%.2x", GET_U_1(p));
|
2017-01-31 19:17:06 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
trunc:
|
2023-05-10 15:02:34 +00:00
|
|
|
nd_print_trunc(ndo);
|
2017-01-31 19:17:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
asn1_print_string(netdissect_options *ndo, struct be *elem)
|
|
|
|
{
|
2023-05-10 15:02:34 +00:00
|
|
|
int printable = 1, first = 1;
|
2017-01-31 19:17:06 +00:00
|
|
|
const u_char *p;
|
|
|
|
uint32_t asnlen = elem->asnlen;
|
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
p = elem->data.str;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_TCHECK_LEN(p, asnlen);
|
|
|
|
for (i = asnlen; printable && i != 0; p++, i--)
|
|
|
|
printable = ND_ASCII_ISPRINT(GET_U_1(p));
|
2017-01-31 19:17:06 +00:00
|
|
|
p = elem->data.str;
|
|
|
|
if (printable) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("\"");
|
|
|
|
if (nd_printn(ndo, p, asnlen, ndo->ndo_snapend)) {
|
|
|
|
ND_PRINT("\"");
|
2017-01-31 19:17:06 +00:00
|
|
|
goto trunc;
|
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("\"");
|
2017-01-31 19:17:06 +00:00
|
|
|
} else {
|
2023-05-10 15:02:34 +00:00
|
|
|
for (i = asnlen; i != 0; p++, i--) {
|
|
|
|
ND_PRINT(first ? "%.2x" : "_%.2x", GET_U_1(p));
|
2017-01-31 19:17:06 +00:00
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
trunc:
|
2023-05-10 15:02:34 +00:00
|
|
|
nd_print_trunc(ndo);
|
2017-01-31 19:17:06 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
1996-08-19 20:34:12 +00:00
|
|
|
/*
|
|
|
|
* Display the ASN.1 object represented by the BE object.
|
|
|
|
* This used to be an integral part of asn1_parse() before the intermediate
|
|
|
|
* BE form was added.
|
|
|
|
*/
|
2005-05-29 18:17:16 +00:00
|
|
|
static int
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(netdissect_options *ndo,
|
|
|
|
struct be *elem)
|
1996-08-19 20:34:12 +00:00
|
|
|
{
|
2017-01-31 19:17:06 +00:00
|
|
|
const u_char *p;
|
2015-01-06 19:03:11 +00:00
|
|
|
uint32_t asnlen = elem->asnlen;
|
|
|
|
uint32_t i;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
switch (elem->type) {
|
|
|
|
|
|
|
|
case BE_OCTET:
|
2017-01-31 19:17:06 +00:00
|
|
|
if (asn1_print_octets(ndo, elem) == -1)
|
|
|
|
return -1;
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_NULL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_OID: {
|
2017-01-31 19:17:06 +00:00
|
|
|
int o = 0, first = -1;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
p = (const u_char *)elem->data.raw;
|
|
|
|
i = asnlen;
|
|
|
|
if (!ndo->ndo_nflag && asnlen > 2) {
|
2015-01-06 19:03:11 +00:00
|
|
|
const struct obj_abrev *a = &obj_abrev_list[0];
|
1996-08-19 20:34:12 +00:00
|
|
|
for (; a->node; a++) {
|
2017-01-31 19:17:06 +00:00
|
|
|
if (i < a->oid_len)
|
|
|
|
continue;
|
2023-05-10 15:02:34 +00:00
|
|
|
if (!ND_TTEST_LEN(p, a->oid_len))
|
2017-01-31 19:17:06 +00:00
|
|
|
continue;
|
|
|
|
if (memcmp(a->oid, p, a->oid_len) == 0) {
|
1996-08-19 20:34:12 +00:00
|
|
|
objp = a->node->child;
|
2017-01-31 19:17:06 +00:00
|
|
|
i -= a->oid_len;
|
|
|
|
p += a->oid_len;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%s", a->prefix);
|
1996-08-19 20:34:12 +00:00
|
|
|
first = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
for (; i != 0; p++, i--) {
|
|
|
|
o = (o << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
|
|
|
|
if (GET_U_1(p) & ASN_LONGLEN)
|
2000-01-30 00:45:58 +00:00
|
|
|
continue;
|
2004-03-31 09:17:26 +00:00
|
|
|
|
1996-08-19 20:34:12 +00:00
|
|
|
/*
|
2017-01-31 19:17:06 +00:00
|
|
|
* first subitem encodes two items with
|
|
|
|
* 1st*OIDMUX+2nd
|
2003-03-02 08:22:26 +00:00
|
|
|
* (see X.690:1997 clause 8.19 for the details)
|
1996-08-19 20:34:12 +00:00
|
|
|
*/
|
|
|
|
if (first < 0) {
|
2003-03-02 08:22:26 +00:00
|
|
|
int s;
|
2015-01-06 19:03:11 +00:00
|
|
|
if (!ndo->ndo_nflag)
|
1996-08-19 20:34:12 +00:00
|
|
|
objp = mibroot;
|
|
|
|
first = 0;
|
2003-03-02 08:22:26 +00:00
|
|
|
s = o / OIDMUX;
|
|
|
|
if (s > 2) s = 2;
|
|
|
|
OBJ_PRINT(s, first);
|
|
|
|
o -= s * OIDMUX;
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
OBJ_PRINT(o, first);
|
|
|
|
if (--first < 0)
|
|
|
|
first = 0;
|
|
|
|
o = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BE_INT:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%d", elem->data.integer);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_UNS:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%u", elem->data.uns);
|
2000-01-30 00:45:58 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
case BE_UNS64:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%" PRIu64, elem->data.uns64);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
case BE_STR:
|
|
|
|
if (asn1_print_string(ndo, elem) == -1)
|
|
|
|
return -1;
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_SEQ:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("Seq(%u)", elem->asnlen);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
case BE_INETADDR:
|
1996-08-19 20:34:12 +00:00
|
|
|
if (asnlen != ASNLEN_INETADDR)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[inetaddr len!=%d]", ASNLEN_INETADDR);
|
2017-01-31 19:17:06 +00:00
|
|
|
p = (const u_char *)elem->data.raw;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_TCHECK_LEN(p, asnlen);
|
|
|
|
for (i = asnlen; i != 0; p++, i--) {
|
|
|
|
ND_PRINT((i == asnlen) ? "%u" : ".%u", GET_U_1(p));
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
break;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
case BE_NOSUCHOBJECT:
|
|
|
|
case BE_NOSUCHINST:
|
|
|
|
case BE_ENDOFMIBVIEW:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[%s]", Class[EXCEPTIONS].Id[elem->id]);
|
2000-01-30 00:45:58 +00:00
|
|
|
break;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
case BE_PDU:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%s(%u)", Class[CONTEXT].Id[elem->id], elem->asnlen);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_ANY:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[BE_ANY!?]");
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[be!?]");
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-05-29 18:17:16 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
trunc:
|
2023-05-10 15:02:34 +00:00
|
|
|
nd_print_trunc(ndo);
|
2005-05-29 18:17:16 +00:00
|
|
|
return -1;
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef notdef
|
|
|
|
/*
|
|
|
|
* This is a brute force ASN.1 printer: recurses to dump an entire structure.
|
|
|
|
* This will work for any ASN.1 stream, not just an SNMP PDU.
|
|
|
|
*
|
|
|
|
* By adding newlines and spaces at the correct places, this would print in
|
|
|
|
* Rose-Normal-Form.
|
|
|
|
*
|
|
|
|
* This is not currently used.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
asn1_decode(u_char *p, u_int length)
|
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (i >= 0 && length > 0) {
|
2015-01-06 19:03:11 +00:00
|
|
|
i = asn1_parse(ndo, p, length, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
if (i >= 0) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
2015-01-06 19:03:11 +00:00
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2005-05-29 18:17:16 +00:00
|
|
|
return;
|
1996-08-19 20:34:12 +00:00
|
|
|
if (elem.type == BE_SEQ || elem.type == BE_PDU) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" {");
|
1996-08-19 20:34:12 +00:00
|
|
|
asn1_decode(elem.data.raw, elem.asnlen);
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" }");
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
length -= i;
|
|
|
|
p += i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
#ifdef USE_LIBSMI
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
struct smi2be {
|
|
|
|
SmiBasetype basetype;
|
|
|
|
int be;
|
|
|
|
};
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
static const struct smi2be smi2betab[] = {
|
2000-01-30 00:45:58 +00:00
|
|
|
{ SMI_BASETYPE_INTEGER32, BE_INT },
|
|
|
|
{ SMI_BASETYPE_OCTETSTRING, BE_STR },
|
|
|
|
{ SMI_BASETYPE_OCTETSTRING, BE_INETADDR },
|
|
|
|
{ SMI_BASETYPE_OBJECTIDENTIFIER, BE_OID },
|
|
|
|
{ SMI_BASETYPE_UNSIGNED32, BE_UNS },
|
|
|
|
{ SMI_BASETYPE_INTEGER64, BE_NONE },
|
|
|
|
{ SMI_BASETYPE_UNSIGNED64, BE_UNS64 },
|
|
|
|
{ SMI_BASETYPE_FLOAT32, BE_NONE },
|
|
|
|
{ SMI_BASETYPE_FLOAT64, BE_NONE },
|
|
|
|
{ SMI_BASETYPE_FLOAT128, BE_NONE },
|
|
|
|
{ SMI_BASETYPE_ENUM, BE_INT },
|
|
|
|
{ SMI_BASETYPE_BITS, BE_STR },
|
|
|
|
{ SMI_BASETYPE_UNKNOWN, BE_NONE }
|
|
|
|
};
|
|
|
|
|
2005-05-29 18:17:16 +00:00
|
|
|
static int
|
2015-01-06 19:03:11 +00:00
|
|
|
smi_decode_oid(netdissect_options *ndo,
|
|
|
|
struct be *elem, unsigned int *oid,
|
|
|
|
unsigned int oidsize, unsigned int *oidlen)
|
2000-01-30 00:45:58 +00:00
|
|
|
{
|
2017-01-31 19:17:06 +00:00
|
|
|
const u_char *p = (const u_char *)elem->data.raw;
|
2015-01-06 19:03:11 +00:00
|
|
|
uint32_t asnlen = elem->asnlen;
|
2023-05-10 15:02:34 +00:00
|
|
|
uint32_t i = asnlen;
|
|
|
|
int o = 0, first = -1;
|
2015-01-06 19:03:11 +00:00
|
|
|
unsigned int firstval;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
for (*oidlen = 0; i != 0; p++, i--) {
|
|
|
|
o = (o << ASN_SHIFT7) + (GET_U_1(p) & ~ASN_BIT8);
|
|
|
|
if (GET_U_1(p) & ASN_LONGLEN)
|
2000-01-30 00:45:58 +00:00
|
|
|
continue;
|
2004-03-31 09:17:26 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
/*
|
|
|
|
* first subitem encodes two items with 1st*OIDMUX+2nd
|
2003-03-02 08:22:26 +00:00
|
|
|
* (see X.690:1997 clause 8.19 for the details)
|
2000-01-30 00:45:58 +00:00
|
|
|
*/
|
|
|
|
if (first < 0) {
|
2023-05-10 15:02:34 +00:00
|
|
|
first = 0;
|
2015-01-06 19:03:11 +00:00
|
|
|
firstval = o / OIDMUX;
|
|
|
|
if (firstval > 2) firstval = 2;
|
|
|
|
o -= firstval * OIDMUX;
|
2002-06-21 00:43:23 +00:00
|
|
|
if (*oidlen < oidsize) {
|
2015-01-06 19:03:11 +00:00
|
|
|
oid[(*oidlen)++] = firstval;
|
2002-06-21 00:43:23 +00:00
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
2002-06-21 00:43:23 +00:00
|
|
|
if (*oidlen < oidsize) {
|
2003-03-02 08:22:26 +00:00
|
|
|
oid[(*oidlen)++] = o;
|
2002-06-21 00:43:23 +00:00
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
o = 0;
|
|
|
|
}
|
2005-05-29 18:17:16 +00:00
|
|
|
return 0;
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int smi_check_type(SmiBasetype basetype, int be)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; smi2betab[i].basetype != SMI_BASETYPE_UNKNOWN; i++) {
|
|
|
|
if (smi2betab[i].basetype == basetype && smi2betab[i].be == be) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smi_check_a_range(SmiType *smiType, SmiRange *smiRange,
|
|
|
|
struct be *elem)
|
|
|
|
{
|
2001-04-03 07:45:48 +00:00
|
|
|
int ok = 1;
|
2004-03-31 09:17:26 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
switch (smiType->basetype) {
|
|
|
|
case SMI_BASETYPE_OBJECTIDENTIFIER:
|
|
|
|
case SMI_BASETYPE_OCTETSTRING:
|
|
|
|
if (smiRange->minValue.value.unsigned32
|
|
|
|
== smiRange->maxValue.value.unsigned32) {
|
|
|
|
ok = (elem->asnlen == smiRange->minValue.value.unsigned32);
|
|
|
|
} else {
|
|
|
|
ok = (elem->asnlen >= smiRange->minValue.value.unsigned32
|
|
|
|
&& elem->asnlen <= smiRange->maxValue.value.unsigned32);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SMI_BASETYPE_INTEGER32:
|
|
|
|
ok = (elem->data.integer >= smiRange->minValue.value.integer32
|
|
|
|
&& elem->data.integer <= smiRange->maxValue.value.integer32);
|
|
|
|
break;
|
2004-03-31 09:17:26 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
case SMI_BASETYPE_UNSIGNED32:
|
|
|
|
ok = (elem->data.uns >= smiRange->minValue.value.unsigned32
|
|
|
|
&& elem->data.uns <= smiRange->maxValue.value.unsigned32);
|
|
|
|
break;
|
2004-03-31 09:17:26 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
case SMI_BASETYPE_UNSIGNED64:
|
|
|
|
/* XXX */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* case SMI_BASETYPE_INTEGER64: SMIng */
|
|
|
|
/* case SMI_BASETYPE_FLOAT32: SMIng */
|
|
|
|
/* case SMI_BASETYPE_FLOAT64: SMIng */
|
|
|
|
/* case SMI_BASETYPE_FLOAT128: SMIng */
|
|
|
|
|
|
|
|
case SMI_BASETYPE_ENUM:
|
|
|
|
case SMI_BASETYPE_BITS:
|
|
|
|
case SMI_BASETYPE_UNKNOWN:
|
|
|
|
ok = 1;
|
|
|
|
break;
|
2005-05-29 18:17:16 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
ok = 0;
|
|
|
|
break;
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smi_check_range(SmiType *smiType, struct be *elem)
|
|
|
|
{
|
|
|
|
SmiRange *smiRange;
|
|
|
|
int ok = 1;
|
|
|
|
|
2001-04-03 07:45:48 +00:00
|
|
|
for (smiRange = smiGetFirstRange(smiType);
|
2000-01-30 00:45:58 +00:00
|
|
|
smiRange;
|
|
|
|
smiRange = smiGetNextRange(smiRange)) {
|
|
|
|
|
|
|
|
ok = smi_check_a_range(smiType, smiRange, elem);
|
2001-04-03 07:45:48 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
if (ok) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-21 00:43:23 +00:00
|
|
|
if (ok) {
|
2000-01-30 00:45:58 +00:00
|
|
|
SmiType *parentType;
|
2001-04-03 07:45:48 +00:00
|
|
|
parentType = smiGetParentType(smiType);
|
2000-01-30 00:45:58 +00:00
|
|
|
if (parentType) {
|
|
|
|
ok = smi_check_range(parentType, elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
static SmiNode *
|
|
|
|
smi_print_variable(netdissect_options *ndo,
|
|
|
|
struct be *elem, int *status)
|
2000-01-30 00:45:58 +00:00
|
|
|
{
|
|
|
|
unsigned int oid[128], oidlen;
|
|
|
|
SmiNode *smiNode = NULL;
|
2005-05-29 18:17:16 +00:00
|
|
|
unsigned int i;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
2017-01-31 19:17:06 +00:00
|
|
|
if (!nd_smi_module_loaded) {
|
|
|
|
*status = asn1_print(ndo, elem);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
*status = smi_decode_oid(ndo, elem, oid, sizeof(oid) / sizeof(unsigned int),
|
2005-05-29 18:17:16 +00:00
|
|
|
&oidlen);
|
|
|
|
if (*status < 0)
|
|
|
|
return NULL;
|
2000-01-30 00:45:58 +00:00
|
|
|
smiNode = smiGetNodeByOID(oidlen, oid);
|
|
|
|
if (! smiNode) {
|
2015-01-06 19:03:11 +00:00
|
|
|
*status = asn1_print(ndo, elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%s::", smiGetNodeModule(smiNode)->name);
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%s", smiNode->name);
|
2000-01-30 00:45:58 +00:00
|
|
|
if (smiNode->oidlen < oidlen) {
|
2015-01-06 19:03:11 +00:00
|
|
|
for (i = smiNode->oidlen; i < oidlen; i++) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(".%u", oid[i]);
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
2005-05-29 18:17:16 +00:00
|
|
|
*status = 0;
|
2000-01-30 00:45:58 +00:00
|
|
|
return smiNode;
|
|
|
|
}
|
|
|
|
|
2005-05-29 18:17:16 +00:00
|
|
|
static int
|
2015-01-06 19:03:11 +00:00
|
|
|
smi_print_value(netdissect_options *ndo,
|
2017-01-31 19:17:06 +00:00
|
|
|
SmiNode *smiNode, u_short pduid, struct be *elem)
|
2000-01-30 00:45:58 +00:00
|
|
|
{
|
2005-05-29 18:17:16 +00:00
|
|
|
unsigned int i, oid[128], oidlen;
|
2000-01-30 00:45:58 +00:00
|
|
|
SmiType *smiType;
|
|
|
|
SmiNamedNumber *nn;
|
2005-05-29 18:17:16 +00:00
|
|
|
int done = 0;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
if (! smiNode || ! (smiNode->nodekind
|
|
|
|
& (SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN))) {
|
2015-01-06 19:03:11 +00:00
|
|
|
return asn1_print(ndo, elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
2001-04-03 07:45:48 +00:00
|
|
|
if (elem->type == BE_NOSUCHOBJECT
|
|
|
|
|| elem->type == BE_NOSUCHINST
|
|
|
|
|| elem->type == BE_ENDOFMIBVIEW) {
|
2015-01-06 19:03:11 +00:00
|
|
|
return asn1_print(ndo, elem);
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
if (NOTIFY_CLASS(pduid) && smiNode->access < SMI_ACCESS_NOTIFY) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[notNotifyable]");
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (READ_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_ONLY) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[notReadable]");
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (WRITE_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_WRITE) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[notWritable]");
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (RESPONSE_CLASS(pduid)
|
|
|
|
&& smiNode->access == SMI_ACCESS_NOT_ACCESSIBLE) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[noAccess]");
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
2001-04-03 07:45:48 +00:00
|
|
|
smiType = smiGetNodeType(smiNode);
|
2000-01-30 00:45:58 +00:00
|
|
|
if (! smiType) {
|
2015-01-06 19:03:11 +00:00
|
|
|
return asn1_print(ndo, elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
2001-04-03 07:45:48 +00:00
|
|
|
if (! smi_check_type(smiType->basetype, elem->type)) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[wrongType]");
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
if (! smi_check_range(smiType, elem)) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[outOfRange]");
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* resolve bits to named bits */
|
|
|
|
|
|
|
|
/* check whether instance identifier is valid */
|
|
|
|
|
|
|
|
/* apply display hints (integer, octetstring) */
|
|
|
|
|
|
|
|
/* convert instance identifier to index type values */
|
2004-03-31 09:17:26 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
switch (elem->type) {
|
|
|
|
case BE_OID:
|
2001-04-03 07:45:48 +00:00
|
|
|
if (smiType->basetype == SMI_BASETYPE_BITS) {
|
2000-01-30 00:45:58 +00:00
|
|
|
/* print bit labels */
|
|
|
|
} else {
|
2017-01-31 19:17:06 +00:00
|
|
|
if (nd_smi_module_loaded &&
|
|
|
|
smi_decode_oid(ndo, elem, oid,
|
|
|
|
sizeof(oid)/sizeof(unsigned int),
|
|
|
|
&oidlen) == 0) {
|
|
|
|
smiNode = smiGetNodeByOID(oidlen, oid);
|
|
|
|
if (smiNode) {
|
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%s::", smiGetNodeModule(smiNode)->name);
|
2017-01-31 19:17:06 +00:00
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%s", smiNode->name);
|
2017-01-31 19:17:06 +00:00
|
|
|
if (smiNode->oidlen < oidlen) {
|
|
|
|
for (i = smiNode->oidlen;
|
|
|
|
i < oidlen; i++) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(".%u", oid[i]);
|
2017-01-31 19:17:06 +00:00
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
2017-01-31 19:17:06 +00:00
|
|
|
done++;
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_INT:
|
2001-04-03 07:45:48 +00:00
|
|
|
if (smiType->basetype == SMI_BASETYPE_ENUM) {
|
|
|
|
for (nn = smiGetFirstNamedNumber(smiType);
|
2000-01-30 00:45:58 +00:00
|
|
|
nn;
|
|
|
|
nn = smiGetNextNamedNumber(nn)) {
|
|
|
|
if (nn->value.value.integer32
|
|
|
|
== elem->data.integer) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("%s", nn->name);
|
|
|
|
ND_PRINT("(%d)", elem->data.integer);
|
2000-01-30 00:45:58 +00:00
|
|
|
done++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! done) {
|
2015-01-06 19:03:11 +00:00
|
|
|
return asn1_print(ndo, elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
2005-05-29 18:17:16 +00:00
|
|
|
return 0;
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1996-08-19 20:34:12 +00:00
|
|
|
/*
|
|
|
|
* General SNMP header
|
|
|
|
* SEQUENCE {
|
|
|
|
* version INTEGER {version-1(0)},
|
|
|
|
* community OCTET STRING,
|
|
|
|
* data ANY -- PDUs
|
|
|
|
* }
|
|
|
|
* PDUs for all but Trap: (see rfc1157 from page 15 on)
|
|
|
|
* SEQUENCE {
|
|
|
|
* request-id INTEGER,
|
|
|
|
* error-status INTEGER,
|
|
|
|
* error-index INTEGER,
|
|
|
|
* varbindlist SEQUENCE OF
|
|
|
|
* SEQUENCE {
|
|
|
|
* name ObjectName,
|
|
|
|
* value ObjectValue
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* PDU for Trap:
|
|
|
|
* SEQUENCE {
|
|
|
|
* enterprise OBJECT IDENTIFIER,
|
|
|
|
* agent-addr NetworkAddress,
|
|
|
|
* generic-trap INTEGER,
|
|
|
|
* specific-trap INTEGER,
|
|
|
|
* time-stamp TimeTicks,
|
|
|
|
* varbindlist SEQUENCE OF
|
|
|
|
* SEQUENCE {
|
|
|
|
* name ObjectName,
|
|
|
|
* value ObjectValue
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMP varBind
|
|
|
|
*/
|
|
|
|
static void
|
2015-01-06 19:03:11 +00:00
|
|
|
varbind_print(netdissect_options *ndo,
|
2017-01-31 19:17:06 +00:00
|
|
|
u_short pduid, const u_char *np, u_int length)
|
1996-08-19 20:34:12 +00:00
|
|
|
{
|
|
|
|
struct be elem;
|
2023-05-10 15:02:34 +00:00
|
|
|
int count = 0;
|
2015-01-06 19:03:11 +00:00
|
|
|
#ifdef USE_LIBSMI
|
2000-01-30 00:45:58 +00:00
|
|
|
SmiNode *smiNode = NULL;
|
|
|
|
#endif
|
2005-05-29 18:17:16 +00:00
|
|
|
int status;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/* Sequence of varBind */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[!SEQ of varbind]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-31 09:17:26 +00:00
|
|
|
if ((u_int)count < length)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[%d extra after SEQ of varbind]", length - count);
|
1996-08-19 20:34:12 +00:00
|
|
|
/* descend */
|
|
|
|
length = elem.asnlen;
|
2017-01-31 19:17:06 +00:00
|
|
|
np = (const u_char *)elem.data.raw;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
while (length) {
|
1996-08-19 20:34:12 +00:00
|
|
|
const u_char *vbend;
|
|
|
|
u_int vblength;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/* Sequence */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[!varbind]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
vbend = np + count;
|
|
|
|
vblength = length - count;
|
|
|
|
/* descend */
|
|
|
|
length = elem.asnlen;
|
2017-01-31 19:17:06 +00:00
|
|
|
np = (const u_char *)elem.data.raw;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/* objName (OID) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_OID) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[objName!=OID]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
#ifdef USE_LIBSMI
|
|
|
|
smiNode = smi_print_variable(ndo, &elem, &status);
|
2000-01-30 00:45:58 +00:00
|
|
|
#else
|
2015-01-06 19:03:11 +00:00
|
|
|
status = asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
#endif
|
2005-05-29 18:17:16 +00:00
|
|
|
if (status < 0)
|
|
|
|
return;
|
1996-08-19 20:34:12 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
if (pduid != GETREQ && pduid != GETNEXTREQ
|
|
|
|
&& pduid != GETBULKREQ)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("=");
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/* objVal (ANY) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
2000-01-30 00:45:58 +00:00
|
|
|
if (pduid == GETREQ || pduid == GETNEXTREQ
|
|
|
|
|| pduid == GETBULKREQ) {
|
1996-08-19 20:34:12 +00:00
|
|
|
if (elem.type != BE_NULL) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[objVal!=NULL]");
|
2015-01-06 19:03:11 +00:00
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2005-05-29 18:17:16 +00:00
|
|
|
return;
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
} else {
|
|
|
|
if (elem.type != BE_NULL) {
|
2015-01-06 19:03:11 +00:00
|
|
|
#ifdef USE_LIBSMI
|
|
|
|
status = smi_print_value(ndo, smiNode, pduid, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
#else
|
2015-01-06 19:03:11 +00:00
|
|
|
status = asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
#endif
|
|
|
|
}
|
2005-05-29 18:17:16 +00:00
|
|
|
if (status < 0)
|
|
|
|
return;
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
1996-08-19 20:34:12 +00:00
|
|
|
length = vblength;
|
|
|
|
np = vbend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-01-30 00:45:58 +00:00
|
|
|
* Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, SetRequest,
|
|
|
|
* GetBulk, Inform, V2Trap, and Report
|
1996-08-19 20:34:12 +00:00
|
|
|
*/
|
|
|
|
static void
|
2015-01-06 19:03:11 +00:00
|
|
|
snmppdu_print(netdissect_options *ndo,
|
|
|
|
u_short pduid, const u_char *np, u_int length)
|
1996-08-19 20:34:12 +00:00
|
|
|
{
|
|
|
|
struct be elem;
|
2017-01-31 19:17:06 +00:00
|
|
|
int count = 0, error_status;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/* reqId (Integer) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[reqId!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("R=%d ", elem.data.integer);
|
1996-08-19 20:34:12 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* errorStatus (Integer) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[errorStatus!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-01-31 19:17:06 +00:00
|
|
|
error_status = 0;
|
2000-01-30 00:45:58 +00:00
|
|
|
if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ
|
|
|
|
|| pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT)
|
1996-08-19 20:34:12 +00:00
|
|
|
&& elem.data.integer != 0) {
|
2005-07-11 03:54:22 +00:00
|
|
|
char errbuf[20];
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[errorStatus(%s)!=0]",
|
|
|
|
DECODE_ErrorStatus(elem.data.integer));
|
2000-01-30 00:45:58 +00:00
|
|
|
} else if (pduid == GETBULKREQ) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" N=%d", elem.data.integer);
|
1996-08-19 20:34:12 +00:00
|
|
|
} else if (elem.data.integer != 0) {
|
2005-07-11 03:54:22 +00:00
|
|
|
char errbuf[20];
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" %s", DECODE_ErrorStatus(elem.data.integer));
|
2017-01-31 19:17:06 +00:00
|
|
|
error_status = elem.data.integer;
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* errorIndex (Integer) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[errorIndex!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ
|
|
|
|
|| pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT)
|
1996-08-19 20:34:12 +00:00
|
|
|
&& elem.data.integer != 0)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[errorIndex(%d)!=0]", elem.data.integer);
|
2000-01-30 00:45:58 +00:00
|
|
|
else if (pduid == GETBULKREQ)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" M=%d", elem.data.integer);
|
1996-08-19 20:34:12 +00:00
|
|
|
else if (elem.data.integer != 0) {
|
2017-01-31 19:17:06 +00:00
|
|
|
if (!error_status)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[errorIndex(%d) w/o errorStatus]", elem.data.integer);
|
2017-01-31 19:17:06 +00:00
|
|
|
else
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("@%d", elem.data.integer);
|
2017-01-31 19:17:06 +00:00
|
|
|
} else if (error_status) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[errorIndex==0]");
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
varbind_print(ndo, pduid, np, length);
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMP Trap PDU
|
|
|
|
*/
|
|
|
|
static void
|
2015-01-06 19:03:11 +00:00
|
|
|
trappdu_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length)
|
1996-08-19 20:34:12 +00:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0, generic;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/* enterprise (oid) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_OID) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[enterprise!=OID]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2005-05-29 18:17:16 +00:00
|
|
|
return;
|
1996-08-19 20:34:12 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/* agent-addr (inetaddr) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INETADDR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[agent-addr!=INETADDR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2005-05-29 18:17:16 +00:00
|
|
|
return;
|
1996-08-19 20:34:12 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* generic-trap (Integer) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[generic-trap!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
generic = elem.data.integer;
|
|
|
|
{
|
2005-07-11 03:54:22 +00:00
|
|
|
char buf[20];
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" %s", DECODE_GenericTrap(generic));
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* specific-trap (Integer) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[specific-trap!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (generic != GT_ENTERPRISE) {
|
|
|
|
if (elem.data.integer != 0)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[specific-trap(%d)!=0]", elem.data.integer);
|
1996-08-19 20:34:12 +00:00
|
|
|
} else
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" s=%d", elem.data.integer);
|
1996-08-19 20:34:12 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
1996-08-19 20:34:12 +00:00
|
|
|
|
|
|
|
/* time-stamp (TimeTicks) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_UNS) { /* XXX */
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[time-stamp!=TIMETICKS]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2005-05-29 18:17:16 +00:00
|
|
|
return;
|
1996-08-19 20:34:12 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
varbind_print(ndo, TRAP, np, length);
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2000-01-30 00:45:58 +00:00
|
|
|
* Decode arbitrary SNMP PDUs.
|
1996-08-19 20:34:12 +00:00
|
|
|
*/
|
2000-01-30 00:45:58 +00:00
|
|
|
static void
|
2015-01-06 19:03:11 +00:00
|
|
|
pdu_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length, int version)
|
1996-08-19 20:34:12 +00:00
|
|
|
{
|
2000-01-30 00:45:58 +00:00
|
|
|
struct be pdu;
|
1996-08-19 20:34:12 +00:00
|
|
|
int count = 0;
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
/* PDU (Context) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &pdu)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (pdu.type != BE_PDU) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[no PDU]");
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-31 09:17:26 +00:00
|
|
|
if ((u_int)count < length)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[%d extra after PDU]", length - count);
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("{ ");
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (asn1_print(ndo, &pdu) < 0)
|
2005-05-29 18:17:16 +00:00
|
|
|
return;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
2000-01-30 00:45:58 +00:00
|
|
|
/* descend into PDU */
|
|
|
|
length = pdu.asnlen;
|
2017-01-31 19:17:06 +00:00
|
|
|
np = (const u_char *)pdu.data.raw;
|
1996-08-19 20:34:12 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
if (version == SNMP_VERSION_1 &&
|
2004-03-31 09:17:26 +00:00
|
|
|
(pdu.id == GETBULKREQ || pdu.id == INFORMREQ ||
|
2000-01-30 00:45:58 +00:00
|
|
|
pdu.id == V2TRAP || pdu.id == REPORT)) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[v2 PDU in v1 message]");
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
if (version == SNMP_VERSION_2 && pdu.id == TRAP) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[v1 PDU in v2 message]");
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
1996-08-19 20:34:12 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
switch (pdu.id) {
|
|
|
|
case TRAP:
|
2015-01-06 19:03:11 +00:00
|
|
|
trappdu_print(ndo, np, length);
|
2000-01-30 00:45:58 +00:00
|
|
|
break;
|
|
|
|
case GETREQ:
|
|
|
|
case GETNEXTREQ:
|
|
|
|
case GETRESP:
|
|
|
|
case SETREQ:
|
|
|
|
case GETBULKREQ:
|
|
|
|
case INFORMREQ:
|
|
|
|
case V2TRAP:
|
|
|
|
case REPORT:
|
2015-01-06 19:03:11 +00:00
|
|
|
snmppdu_print(ndo, pdu.id, np, length);
|
2000-01-30 00:45:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-04-03 07:45:48 +00:00
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" } ");
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode a scoped SNMP PDU.
|
|
|
|
*/
|
|
|
|
static void
|
2015-01-06 19:03:11 +00:00
|
|
|
scopedpdu_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length, int version)
|
2000-01-30 00:45:58 +00:00
|
|
|
{
|
|
|
|
struct be elem;
|
2017-01-31 19:17:06 +00:00
|
|
|
int count = 0;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
/* Sequence */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[!scoped PDU]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length = elem.asnlen;
|
2017-01-31 19:17:06 +00:00
|
|
|
np = (const u_char *)elem.data.raw;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
/* contextEngineID (OCTET STRING) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
2000-01-30 00:45:58 +00:00
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[contextEngineID!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("E=");
|
2017-01-31 19:17:06 +00:00
|
|
|
if (asn1_print_octets(ndo, &elem) == -1)
|
|
|
|
return;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
/* contextName (OCTET STRING) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[contextName!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("C=");
|
2017-01-31 19:17:06 +00:00
|
|
|
if (asn1_print_string(ndo, &elem) == -1)
|
|
|
|
return;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
2000-01-30 00:45:58 +00:00
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
pdu_print(ndo, np, length, version);
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMP Community Header (SNMPv1 and SNMPv2c)
|
|
|
|
*/
|
|
|
|
static void
|
2015-01-06 19:03:11 +00:00
|
|
|
community_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length, int version)
|
2000-01-30 00:45:58 +00:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0;
|
|
|
|
|
1996-08-19 20:34:12 +00:00
|
|
|
/* Community (String) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[comm!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* default community */
|
2003-03-02 08:22:26 +00:00
|
|
|
if (!(elem.asnlen == sizeof(DEF_COMMUNITY) - 1 &&
|
2017-01-31 19:17:06 +00:00
|
|
|
strncmp((const char *)elem.data.str, DEF_COMMUNITY,
|
|
|
|
sizeof(DEF_COMMUNITY) - 1) == 0)) {
|
1996-08-19 20:34:12 +00:00
|
|
|
/* ! "public" */
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("C=");
|
2017-01-31 19:17:06 +00:00
|
|
|
if (asn1_print_string(ndo, &elem) == -1)
|
|
|
|
return;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
2017-01-31 19:17:06 +00:00
|
|
|
}
|
1996-08-19 20:34:12 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
pdu_print(ndo, np, length, version);
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMPv3 User-based Security Message Header (SNMPv3)
|
|
|
|
*/
|
|
|
|
static void
|
2015-01-06 19:03:11 +00:00
|
|
|
usm_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length)
|
2000-01-30 00:45:58 +00:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
/* Sequence */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
2000-01-30 00:45:58 +00:00
|
|
|
if (elem.type != BE_SEQ) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[!usm]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length = elem.asnlen;
|
2017-01-31 19:17:06 +00:00
|
|
|
np = (const u_char *)elem.data.raw;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
/* msgAuthoritativeEngineID (OCTET STRING) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgAuthoritativeEngineID!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgAuthoritativeEngineBoots (INTEGER) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgAuthoritativeEngineBoots!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("B=%d ", elem.data.integer);
|
2000-01-30 00:45:58 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgAuthoritativeEngineTime (INTEGER) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgAuthoritativeEngineTime!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("T=%d ", elem.data.integer);
|
2000-01-30 00:45:58 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgUserName (OCTET STRING) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgUserName!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
1996-08-19 20:34:12 +00:00
|
|
|
return;
|
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("U=");
|
2017-01-31 19:17:06 +00:00
|
|
|
if (asn1_print_string(ndo, &elem) == -1)
|
|
|
|
return;
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT(" ");
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
/* msgAuthenticationParameters (OCTET STRING) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgAuthenticationParameters!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgPrivacyParameters (OCTET STRING) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgPrivacyParameters!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2004-03-31 09:17:26 +00:00
|
|
|
if ((u_int)count < length)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[%d extra after usm SEQ]", length - count);
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
1996-08-19 20:34:12 +00:00
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
/*
|
|
|
|
* Decode SNMPv3 Message Header (SNMPv3)
|
|
|
|
*/
|
|
|
|
static void
|
2015-01-06 19:03:11 +00:00
|
|
|
v3msg_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length)
|
2000-01-30 00:45:58 +00:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0;
|
|
|
|
u_char flags;
|
|
|
|
int model;
|
|
|
|
const u_char *xnp = np;
|
|
|
|
int xlength = length;
|
|
|
|
|
|
|
|
/* Sequence */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[!message]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length = elem.asnlen;
|
2017-01-31 19:17:06 +00:00
|
|
|
np = (const u_char *)elem.data.raw;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("{ ");
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
/* msgID (INTEGER) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgID!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgMaxSize (INTEGER) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgMaxSize!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgFlags (OCTET STRING) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgFlags!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (elem.asnlen != 1) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgFlags size %d]", elem.asnlen);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2023-05-10 15:02:34 +00:00
|
|
|
flags = GET_U_1(elem.data.str);
|
2004-03-31 09:17:26 +00:00
|
|
|
if (flags != 0x00 && flags != 0x01 && flags != 0x03
|
2000-01-30 00:45:58 +00:00
|
|
|
&& flags != 0x04 && flags != 0x05 && flags != 0x07) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgFlags=0x%02X]", flags);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("F=%s%s%s ",
|
2015-01-06 19:03:11 +00:00
|
|
|
flags & 0x01 ? "a" : "",
|
|
|
|
flags & 0x02 ? "p" : "",
|
2023-05-10 15:02:34 +00:00
|
|
|
flags & 0x04 ? "r" : "");
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
/* msgSecurityModel (INTEGER) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgSecurityModel!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
model = elem.data.integer;
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2004-03-31 09:17:26 +00:00
|
|
|
if ((u_int)count < length)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[%d extra after message SEQ]", length - count);
|
2000-01-30 00:45:58 +00:00
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("} ");
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
|
|
|
|
2000-01-30 00:45:58 +00:00
|
|
|
if (model == 3) {
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("{ USM ");
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
} else {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[security model %d]", model);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
np = xnp + (np - xnp);
|
|
|
|
length = xlength - (np - xnp);
|
|
|
|
|
|
|
|
/* msgSecurityParameters (OCTET STRING) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[msgSecurityParameters!=STR]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
if (model == 3) {
|
2015-01-06 19:03:11 +00:00
|
|
|
usm_print(ndo, elem.data.str, elem.asnlen);
|
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("} ");
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("{ ScopedPDU ");
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
scopedpdu_print(ndo, np, length, 3);
|
2001-04-03 07:45:48 +00:00
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("} ");
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
2000-01-30 00:45:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMP header and pass on to PDU printing routines
|
|
|
|
*/
|
|
|
|
void
|
2015-01-06 19:03:11 +00:00
|
|
|
snmp_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length)
|
2000-01-30 00:45:58 +00:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0;
|
|
|
|
int version = 0;
|
|
|
|
|
2023-05-10 15:02:34 +00:00
|
|
|
ndo->ndo_protocol = "snmp";
|
|
|
|
ND_PRINT(" ");
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
/* initial Sequence */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[!init SEQ]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-03-31 09:17:26 +00:00
|
|
|
if ((u_int)count < length)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[%d extra after iSEQ]", length - count);
|
2000-01-30 00:45:58 +00:00
|
|
|
/* descend */
|
|
|
|
length = elem.asnlen;
|
2017-01-31 19:17:06 +00:00
|
|
|
np = (const u_char *)elem.data.raw;
|
2000-01-30 00:45:58 +00:00
|
|
|
|
|
|
|
/* Version (INTEGER) */
|
2015-01-06 19:03:11 +00:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[version!=INT]");
|
2015-01-06 19:03:11 +00:00
|
|
|
asn1_print(ndo, &elem);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (elem.data.integer) {
|
|
|
|
case SNMP_VERSION_1:
|
|
|
|
case SNMP_VERSION_2:
|
|
|
|
case SNMP_VERSION_3:
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag)
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("{ %s ", SnmpVersion[elem.data.integer]);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
2000-01-30 00:45:58 +00:00
|
|
|
default:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("SNMP [version = %d]", elem.data.integer);
|
2000-01-30 00:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
version = elem.data.integer;
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
switch (version) {
|
|
|
|
case SNMP_VERSION_1:
|
|
|
|
case SNMP_VERSION_2:
|
2015-01-06 19:03:11 +00:00
|
|
|
community_print(ndo, np, length, version);
|
2000-01-30 00:45:58 +00:00
|
|
|
break;
|
|
|
|
case SNMP_VERSION_3:
|
2015-01-06 19:03:11 +00:00
|
|
|
v3msg_print(ndo, np, length);
|
2000-01-30 00:45:58 +00:00
|
|
|
break;
|
|
|
|
default:
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("[version = %d]", elem.data.integer);
|
1996-08-19 20:34:12 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-04-03 07:45:48 +00:00
|
|
|
|
2015-01-06 19:03:11 +00:00
|
|
|
if (ndo->ndo_vflag) {
|
2023-05-10 15:02:34 +00:00
|
|
|
ND_PRINT("} ");
|
2001-04-03 07:45:48 +00:00
|
|
|
}
|
1996-08-19 20:34:12 +00:00
|
|
|
}
|