1999-10-08 07:47:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
|
2001-09-18 06:16:52 +08: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.
|
1999-10-08 07:47:09 +08: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.
|
|
|
|
*
|
1999-12-14 02:06:13 +08:00
|
|
|
* Support for SNMPv2c/SNMPv3 and the ability to link the module against
|
|
|
|
* the libsmi was added by J. Schoenwaelder, Copyright (c) 1999.
|
|
|
|
*
|
1999-10-08 07:47:09 +08:00
|
|
|
* This started out as a very simple program, but the incremental decoding
|
|
|
|
* (into the BE structure) complicated things.
|
|
|
|
*
|
|
|
|
# Los Alamos National Laboratory
|
|
|
|
#
|
|
|
|
# Copyright (c) 1990, 1991, 1993, 1994, 1995, 1996, 1997
|
|
|
|
# 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
|
|
|
|
*/
|
|
|
|
|
1999-11-21 17:36:43 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
1999-10-08 07:47:09 +08:00
|
|
|
#endif
|
|
|
|
|
2002-08-01 16:52:55 +08:00
|
|
|
#include <tcpdump-stdinc.h>
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
Clean up configure check for libsmi.
First, check for smi.h. If we don't have it, don't check for anything
else.
If we do have it, check for libsmi containing smiInit. If we don't have
it, don't check for anything else.
If we do have it, check, with our test program, whether we can use it.
If that succeeds, prepend -lsmi to LIBS, and set USE_LIBSMI. Otherwise,
don't do either of those.
Check, in source, *only* for USE_LIBSMI. If it's set, use libsmi,
otherwise don't - don't even include smi.h, even if we happened to have
found it, and don't print the libsmi version string.
2014-09-01 02:57:04 +08:00
|
|
|
#ifdef USE_LIBSMI
|
1999-12-14 02:06:13 +08:00
|
|
|
#include <smi.h>
|
|
|
|
#endif
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
#include "interface.h"
|
|
|
|
|
2004-11-04 15:53:56 +08:00
|
|
|
#undef OPAQUE /* defined in <wingdi.h> */
|
|
|
|
|
2013-12-26 22:08:06 +08:00
|
|
|
static const char tstr[] = "[|snmp]";
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
/*
|
|
|
|
* Universal ASN.1 types
|
|
|
|
* (we only care about the tag values for those allowed in the Internet SMI)
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *Universal[] = {
|
1999-10-08 07:47:09 +08: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
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *Application[] = {
|
1999-10-08 07:47:09 +08:00
|
|
|
"IpAddress",
|
|
|
|
#define IPADDR 0
|
|
|
|
"Counter",
|
|
|
|
#define COUNTER 1
|
|
|
|
"Gauge",
|
|
|
|
#define GAUGE 2
|
|
|
|
"TimeTicks",
|
|
|
|
#define TIMETICKS 3
|
1999-10-18 06:18:00 +08:00
|
|
|
"Opaque",
|
|
|
|
#define OPAQUE 4
|
|
|
|
"C-5",
|
|
|
|
"Counter64"
|
|
|
|
#define COUNTER64 6
|
1999-10-08 07:47:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Context-specific ASN.1 types for the SNMP PDUs and their tags
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *Context[] = {
|
1999-10-08 07:47:09 +08:00
|
|
|
"GetRequest",
|
|
|
|
#define GETREQ 0
|
|
|
|
"GetNextRequest",
|
|
|
|
#define GETNEXTREQ 1
|
|
|
|
"GetResponse",
|
|
|
|
#define GETRESP 2
|
|
|
|
"SetRequest",
|
|
|
|
#define SETREQ 3
|
1999-10-18 06:18:00 +08:00
|
|
|
"Trap",
|
1999-10-08 07:47:09 +08:00
|
|
|
#define TRAP 4
|
1999-10-18 06:18:00 +08:00
|
|
|
"GetBulk",
|
|
|
|
#define GETBULKREQ 5
|
|
|
|
"Inform",
|
|
|
|
#define INFORMREQ 6
|
|
|
|
"V2Trap",
|
|
|
|
#define V2TRAP 7
|
|
|
|
"Report"
|
|
|
|
#define REPORT 8
|
|
|
|
};
|
|
|
|
|
1999-12-14 02:06:13 +08:00
|
|
|
#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)
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
/*
|
|
|
|
* Context-specific ASN.1 types for the SNMP Exceptions and their tags
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *Exceptions[] = {
|
1999-10-18 06:18:00 +08:00
|
|
|
"noSuchObject",
|
|
|
|
#define NOSUCHOBJECT 0
|
|
|
|
"noSuchInstance",
|
|
|
|
#define NOSUCHINSTANCE 1
|
|
|
|
"endOfMibView",
|
|
|
|
#define ENDOFMIBVIEW 2
|
1999-10-08 07:47:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private ASN.1 types
|
|
|
|
* The Internet SMI does not specify any
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *Private[] = {
|
1999-10-08 07:47:09 +08:00
|
|
|
"P-0"
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* error-status values for any SNMP PDU
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *ErrorStatus[] = {
|
1999-10-08 07:47:09 +08:00
|
|
|
"noError",
|
|
|
|
"tooBig",
|
|
|
|
"noSuchName",
|
|
|
|
"badValue",
|
|
|
|
"readOnly",
|
1999-10-18 06:18:00 +08:00
|
|
|
"genErr",
|
|
|
|
"noAccess",
|
|
|
|
"wrongType",
|
|
|
|
"wrongLength",
|
|
|
|
"wrongEncoding",
|
|
|
|
"wrongValue",
|
|
|
|
"noCreation",
|
|
|
|
"inconsistentValue",
|
|
|
|
"resourceUnavailable",
|
|
|
|
"commitFailed",
|
|
|
|
"undoFailed",
|
|
|
|
"authorizationError",
|
|
|
|
"notWritable",
|
|
|
|
"inconsistentName"
|
1999-10-08 07:47:09 +08:00
|
|
|
};
|
|
|
|
#define DECODE_ErrorStatus(e) \
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
( e >= 0 && (size_t)e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \
|
2000-01-17 14:24:23 +08:00
|
|
|
? ErrorStatus[e] \
|
|
|
|
: (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf))
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* generic-trap values in the SNMP Trap-PDU
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *GenericTrap[] = {
|
1999-10-08 07:47:09 +08:00
|
|
|
"coldStart",
|
|
|
|
"warmStart",
|
|
|
|
"linkDown",
|
|
|
|
"linkUp",
|
|
|
|
"authenticationFailure",
|
|
|
|
"egpNeighborLoss",
|
|
|
|
"enterpriseSpecific"
|
2004-03-23 14:59:15 +08:00
|
|
|
#define GT_ENTERPRISE 6
|
1999-10-08 07:47:09 +08:00
|
|
|
};
|
|
|
|
#define DECODE_GenericTrap(t) \
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
( t >= 0 && (size_t)t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \
|
2000-01-17 14:24:23 +08:00
|
|
|
? GenericTrap[t] \
|
|
|
|
: (snprintf(buf, sizeof(buf), "gt=%d", t), buf))
|
1999-10-08 07:47:09 +08: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 */
|
2013-12-19 18:05:59 +08:00
|
|
|
static const struct {
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
const char *name;
|
|
|
|
const char **Id;
|
1999-10-08 07:47:09 +08:00
|
|
|
int numIDs;
|
|
|
|
} Class[] = {
|
|
|
|
defineCLASS(Universal),
|
|
|
|
#define UNIVERSAL 0
|
|
|
|
defineCLASS(Application),
|
|
|
|
#define APPLICATION 1
|
|
|
|
defineCLASS(Context),
|
|
|
|
#define CONTEXT 2
|
|
|
|
defineCLASS(Private),
|
|
|
|
#define PRIVATE 3
|
1999-10-18 06:18:00 +08:00
|
|
|
defineCLASS(Exceptions),
|
|
|
|
#define EXCEPTIONS 4
|
1999-10-08 07:47:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* defined forms for ASN.1 types
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *Form[] = {
|
1999-10-08 07:47:09 +08: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.
|
|
|
|
*/
|
|
|
|
struct obj {
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
const char *desc; /* name of object */
|
1999-10-08 07:47:09 +08: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.
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const struct obj_abrev {
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
const char *prefix; /* prefix for this abrev */
|
1999-10-08 07:47:09 +08:00
|
|
|
struct obj *node; /* pointer into object table */
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
const char *oid; /* ASN.1 encoded OID */
|
1999-10-08 07:47:09 +08:00
|
|
|
} obj_abrev_list[] = {
|
|
|
|
#ifndef NO_ABREV_MIB
|
|
|
|
/* .iso.org.dod.internet.mgmt.mib */
|
|
|
|
{ "", &_mib_obj, "\53\6\1\2\1" },
|
|
|
|
#endif
|
|
|
|
#ifndef NO_ABREV_ENTER
|
|
|
|
/* .iso.org.dod.internet.private.enterprises */
|
|
|
|
{ "E:", &_enterprises_obj, "\53\6\1\4\1" },
|
|
|
|
#endif
|
|
|
|
#ifndef NO_ABREV_EXPERI
|
|
|
|
/* .iso.org.dod.internet.experimental */
|
|
|
|
{ "X:", &_experimental_obj, "\53\6\1\3" },
|
1999-10-18 06:18:00 +08:00
|
|
|
#endif
|
|
|
|
#ifndef NO_ABBREV_SNMPMODS
|
|
|
|
/* .iso.org.dod.internet.snmpV2.snmpModules */
|
|
|
|
{ "S:", &_snmpModules_obj, "\53\6\1\6\3" },
|
1999-10-08 07:47:09 +08:00
|
|
|
#endif
|
|
|
|
{ 0,0,0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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) { \
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, suppressdot?"%s":".%s", objp->desc)); \
|
1999-10-08 07:47:09 +08:00
|
|
|
objp = objp->child; \
|
|
|
|
} else \
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, suppressdot?"%u":".%u", (o))); \
|
1999-10-08 07:47:09 +08: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 {
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t asnlen;
|
1999-10-08 07:47:09 +08:00
|
|
|
union {
|
|
|
|
caddr_t raw;
|
|
|
|
int32_t integer;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t uns;
|
1999-10-08 07:47:09 +08:00
|
|
|
const u_char *str;
|
1999-10-18 06:18:00 +08:00
|
|
|
struct {
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t high;
|
|
|
|
uint32_t low;
|
1999-10-18 06:18:00 +08:00
|
|
|
} uns64;
|
1999-10-08 07:47:09 +08: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
|
1999-10-18 06:18:00 +08:00
|
|
|
#define BE_UNS64 10
|
|
|
|
#define BE_NOSUCHOBJECT 128
|
|
|
|
#define BE_NOSUCHINST 129
|
|
|
|
#define BE_ENDOFMIBVIEW 130
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SNMP versions recognized by this module
|
|
|
|
*/
|
2013-12-19 18:05:59 +08:00
|
|
|
static const char *SnmpVersion[] = {
|
1999-10-18 06:18:00 +08: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
|
1999-10-08 07:47:09 +08: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
|
2014-03-29 19:39:31 +08:00
|
|
|
asn1_parse(netdissect_options *ndo,
|
|
|
|
register const u_char *p, u_int len, struct be *elem)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
|
|
|
u_char form, class, id;
|
|
|
|
int i, hdr;
|
|
|
|
|
|
|
|
elem->asnlen = 0;
|
|
|
|
elem->type = BE_ANY;
|
|
|
|
if (len < 1) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[nothing to parse]"));
|
1999-10-08 07:47:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK(*p);
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
id = *p & ASN_ID_BITS; /* lower 5 bits, range 00-1f */
|
|
|
|
#ifdef notdef
|
|
|
|
form = (*p & 0xe0) >> 5; /* move upper 3 bits to lower 3 */
|
|
|
|
class = form >> 1; /* bits 7&6 -> bits 1&0, range 0-3 */
|
|
|
|
form &= 0x1; /* bit 5 -> bit 0, range 0-1 */
|
|
|
|
#else
|
|
|
|
form = (u_char)(*p & ASN_FORM_BITS) >> ASN_FORM_SHIFT;
|
|
|
|
class = (u_char)(*p & ASN_CLASS_BITS) >> ASN_CLASS_SHIFT;
|
|
|
|
#endif
|
|
|
|
elem->form = form;
|
|
|
|
elem->class = class;
|
|
|
|
elem->id = id;
|
|
|
|
p++; len--; hdr = 1;
|
|
|
|
/* extended tag field */
|
|
|
|
if (id == ASN_ID_EXT) {
|
2004-12-28 06:14:12 +08: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.
|
|
|
|
*/
|
|
|
|
for (id = 0; *p & ASN_BIT8; len--, hdr++, p++) {
|
|
|
|
if (len < 1) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[Xtagfield?]"));
|
2004-12-28 06:14:12 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK(*p);
|
1999-10-08 07:47:09 +08:00
|
|
|
id = (id << 7) | (*p & ~ASN_BIT8);
|
2004-12-28 06:14:12 +08:00
|
|
|
}
|
|
|
|
if (len < 1) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[Xtagfield?]"));
|
1999-10-08 07:47:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK(*p);
|
1999-10-08 07:47:09 +08:00
|
|
|
elem->id = id = (id << 7) | *p;
|
|
|
|
--len;
|
|
|
|
++hdr;
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
if (len < 1) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[no asnlen]"));
|
1999-10-08 07:47:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK(*p);
|
1999-10-08 07:47:09 +08:00
|
|
|
elem->asnlen = *p;
|
|
|
|
p++; len--; hdr++;
|
|
|
|
if (elem->asnlen & ASN_BIT8) {
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t noct = elem->asnlen % ASN_BIT8;
|
1999-10-08 07:47:09 +08:00
|
|
|
elem->asnlen = 0;
|
|
|
|
if (len < noct) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[asnlen? %d<%d]", len, noct));
|
1999-10-08 07:47:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK2(*p, noct);
|
2001-03-22 10:06:43 +08:00
|
|
|
for (; noct-- > 0; len--, hdr++)
|
1999-10-08 07:47:09 +08:00
|
|
|
elem->asnlen = (elem->asnlen << ASN_SHIFT8) | *p++;
|
|
|
|
}
|
|
|
|
if (len < elem->asnlen) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[len%d<asnlen%u]", len, elem->asnlen));
|
2004-12-28 06:14:12 +08:00
|
|
|
return -1;
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
if (form >= sizeof(Form)/sizeof(Form[0])) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[form?%d]", form));
|
1999-10-08 07:47:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (class >= sizeof(Class)/sizeof(Class[0])) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[class?%c/%d]", *Form[form], class));
|
1999-10-08 07:47:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if ((int)id >= Class[class].numIDs) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[id?%c/%s/%d]", *Form[form], Class[class].name, id));
|
1999-10-08 07:47:09 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (form) {
|
|
|
|
case PRIMITIVE:
|
|
|
|
switch (class) {
|
|
|
|
case UNIVERSAL:
|
|
|
|
switch (id) {
|
|
|
|
case STRING:
|
|
|
|
elem->type = BE_STR;
|
|
|
|
elem->data.str = p;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case INTEGER: {
|
|
|
|
register int32_t data;
|
|
|
|
elem->type = BE_INT;
|
|
|
|
data = 0;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK2(*p, elem->asnlen);
|
1999-10-08 07:47:09 +08:00
|
|
|
if (*p & ASN_BIT8) /* negative */
|
|
|
|
data = -1;
|
|
|
|
for (i = elem->asnlen; i-- > 0; p++)
|
|
|
|
data = (data << ASN_SHIFT8) | *p;
|
|
|
|
elem->data.integer = data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case OBJECTID:
|
|
|
|
elem->type = BE_OID;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ASN_NULL:
|
|
|
|
elem->type = BE_NULL;
|
|
|
|
elem->data.raw = NULL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
elem->type = BE_OCTET;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[P/U/%s]", Class[class].Id[id]));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case APPLICATION:
|
|
|
|
switch (id) {
|
|
|
|
case IPADDR:
|
|
|
|
elem->type = BE_INETADDR;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COUNTER:
|
|
|
|
case GAUGE:
|
|
|
|
case TIMETICKS: {
|
2014-04-23 15:20:40 +08:00
|
|
|
register uint32_t data;
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK2(*p, elem->asnlen);
|
1999-10-08 07:47:09 +08:00
|
|
|
elem->type = BE_UNS;
|
|
|
|
data = 0;
|
|
|
|
for (i = elem->asnlen; i-- > 0; p++)
|
|
|
|
data = (data << 8) + *p;
|
|
|
|
elem->data.uns = data;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
case COUNTER64: {
|
2014-04-23 15:20:40 +08:00
|
|
|
register uint32_t high, low;
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK2(*p, elem->asnlen);
|
1999-10-18 06:18:00 +08:00
|
|
|
elem->type = BE_UNS64;
|
|
|
|
high = 0, low = 0;
|
|
|
|
for (i = elem->asnlen; i-- > 0; p++) {
|
2002-06-12 01:08:37 +08:00
|
|
|
high = (high << 8) |
|
1999-10-18 06:18:00 +08:00
|
|
|
((low & 0xFF000000) >> 24);
|
|
|
|
low = (low << 8) | *p;
|
|
|
|
}
|
|
|
|
elem->data.uns64.high = high;
|
|
|
|
elem->data.uns64.low = low;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
default:
|
|
|
|
elem->type = BE_OCTET;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[P/A/%s]",
|
|
|
|
Class[class].Id[id]));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-10-18 06:18:00 +08: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;
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
default:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[P/%s/%s]", Class[class].name, Class[class].Id[id]));
|
|
|
|
ND_TCHECK2(*p, elem->asnlen);
|
2004-12-28 06:14:12 +08:00
|
|
|
elem->type = BE_OCTET;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONSTRUCTED:
|
|
|
|
switch (class) {
|
|
|
|
case UNIVERSAL:
|
|
|
|
switch (id) {
|
|
|
|
case SEQUENCE:
|
|
|
|
elem->type = BE_SEQ;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
elem->type = BE_OCTET;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "C/U/%s", Class[class].Id[id]));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTEXT:
|
|
|
|
elem->type = BE_PDU;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
elem->type = BE_OCTET;
|
|
|
|
elem->data.raw = (caddr_t)p;
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "C/%s/%s", Class[class].name, Class[class].Id[id]));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p += elem->asnlen;
|
|
|
|
len -= elem->asnlen;
|
|
|
|
return elem->asnlen + hdr;
|
2004-12-28 06:14:12 +08:00
|
|
|
|
|
|
|
trunc:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s", tstr));
|
2004-12-28 06:14:12 +08:00
|
|
|
return -1;
|
1999-10-08 07:47:09 +08: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.
|
|
|
|
*/
|
2004-12-28 06:14:12 +08:00
|
|
|
static int
|
2014-03-29 19:39:31 +08:00
|
|
|
asn1_print(netdissect_options *ndo,
|
|
|
|
struct be *elem)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
|
|
|
u_char *p = (u_char *)elem->data.raw;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t asnlen = elem->asnlen;
|
|
|
|
uint32_t i;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
switch (elem->type) {
|
|
|
|
|
|
|
|
case BE_OCTET:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK2(*p, asnlen);
|
2000-10-06 13:54:50 +08:00
|
|
|
for (i = asnlen; i-- > 0; p++)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "_%.2x", *p));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_NULL:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_OID: {
|
2004-12-28 06:14:12 +08:00
|
|
|
int o = 0, first = -1, i = asnlen;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
if (!ndo->ndo_sflag && !ndo->ndo_nflag && asnlen > 2) {
|
2013-12-19 18:05:59 +08:00
|
|
|
const struct obj_abrev *a = &obj_abrev_list[0];
|
2004-12-28 06:14:12 +08:00
|
|
|
size_t a_len = strlen(a->oid);
|
1999-10-08 07:47:09 +08:00
|
|
|
for (; a->node; a++) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK2(*p, a_len);
|
2004-12-28 06:14:12 +08:00
|
|
|
if (memcmp(a->oid, (char *)p, a_len) == 0) {
|
1999-10-08 07:47:09 +08:00
|
|
|
objp = a->node->child;
|
|
|
|
i -= strlen(a->oid);
|
|
|
|
p += strlen(a->oid);
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s", a->prefix));
|
1999-10-08 07:47:09 +08:00
|
|
|
first = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-12-14 02:06:13 +08:00
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
for (; !ndo->ndo_sflag && i-- > 0; p++) {
|
|
|
|
ND_TCHECK(*p);
|
1999-10-08 07:47:09 +08:00
|
|
|
o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8);
|
|
|
|
if (*p & ASN_LONGLEN)
|
1999-12-14 02:06:13 +08:00
|
|
|
continue;
|
2002-06-12 01:08:37 +08:00
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
/*
|
|
|
|
* first subitem encodes two items with 1st*OIDMUX+2nd
|
2002-05-07 15:39:05 +08:00
|
|
|
* (see X.690:1997 clause 8.19 for the details)
|
1999-10-08 07:47:09 +08:00
|
|
|
*/
|
|
|
|
if (first < 0) {
|
2002-05-07 15:39:05 +08:00
|
|
|
int s;
|
2014-03-29 19:39:31 +08:00
|
|
|
if (!ndo->ndo_nflag)
|
1999-10-08 07:47:09 +08:00
|
|
|
objp = mibroot;
|
|
|
|
first = 0;
|
2002-05-07 15:39:05 +08:00
|
|
|
s = o / OIDMUX;
|
|
|
|
if (s > 2) s = 2;
|
|
|
|
OBJ_PRINT(s, first);
|
|
|
|
o -= s * OIDMUX;
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
OBJ_PRINT(o, first);
|
|
|
|
if (--first < 0)
|
|
|
|
first = 0;
|
|
|
|
o = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BE_INT:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%d", elem->data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_UNS:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%u", elem->data.uns));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
case BE_UNS64: { /* idea borrowed from by Marshall Rose */
|
|
|
|
double d;
|
|
|
|
int j, carry;
|
|
|
|
char *cpf, *cpl, last[6], first[30];
|
|
|
|
if (elem->data.uns64.high == 0) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%u", elem->data.uns64.low));
|
|
|
|
break;
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
|
|
|
d = elem->data.uns64.high * 4294967296.0; /* 2^32 */
|
2002-06-12 01:08:37 +08:00
|
|
|
if (elem->data.uns64.high <= 0x1fffff) {
|
1999-10-18 06:18:00 +08:00
|
|
|
d += elem->data.uns64.low;
|
2001-03-17 12:41:49 +08:00
|
|
|
#if 0 /*is looks illegal, but what is the intention?*/
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%.f", d));
|
1999-12-22 14:27:19 +08:00
|
|
|
#else
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%f", d));
|
1999-12-22 14:27:19 +08:00
|
|
|
#endif
|
1999-10-18 06:18:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
d += (elem->data.uns64.low & 0xfffff000);
|
2001-03-17 12:41:49 +08:00
|
|
|
#if 0 /*is looks illegal, but what is the intention?*/
|
2000-01-17 14:24:23 +08:00
|
|
|
snprintf(first, sizeof(first), "%.f", d);
|
1999-12-22 14:27:19 +08:00
|
|
|
#else
|
2000-01-17 14:24:23 +08:00
|
|
|
snprintf(first, sizeof(first), "%f", d);
|
1999-12-22 14:27:19 +08:00
|
|
|
#endif
|
2000-01-17 14:24:23 +08:00
|
|
|
snprintf(last, sizeof(last), "%5.5d",
|
|
|
|
elem->data.uns64.low & 0xfff);
|
1999-10-18 06:18:00 +08:00
|
|
|
for (carry = 0, cpf = first+strlen(first)-1, cpl = last+4;
|
|
|
|
cpl >= last;
|
|
|
|
cpf--, cpl--) {
|
|
|
|
j = carry + (*cpf - '0') + (*cpl - '0');
|
|
|
|
if (j > 9) {
|
|
|
|
j -= 10;
|
|
|
|
carry = 1;
|
|
|
|
} else {
|
|
|
|
carry = 0;
|
|
|
|
}
|
|
|
|
*cpf = j + '0';
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s", first));
|
1999-10-18 06:18:00 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
case BE_STR: {
|
|
|
|
register int printable = 1, first = 1;
|
|
|
|
const u_char *p = elem->data.str;
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_TCHECK2(*p, asnlen);
|
1999-10-08 07:47:09 +08:00
|
|
|
for (i = asnlen; printable && i-- > 0; p++)
|
2014-02-03 07:17:06 +08:00
|
|
|
printable = ND_ISPRINT(*p);
|
1999-10-08 07:47:09 +08:00
|
|
|
p = elem->data.str;
|
|
|
|
if (printable) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "\""));
|
2014-04-14 14:53:46 +08:00
|
|
|
if (fn_printn(ndo, p, asnlen, ndo->ndo_snapend)) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "\""));
|
2005-05-06 15:56:51 +08:00
|
|
|
goto trunc;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "\""));
|
1999-10-08 07:47:09 +08:00
|
|
|
} else
|
|
|
|
for (i = asnlen; i-- > 0; p++) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, first ? "%.2x" : "_%.2x", *p));
|
1999-10-08 07:47:09 +08:00
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BE_SEQ:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "Seq(%u)", elem->asnlen));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
1999-12-14 02:06:13 +08:00
|
|
|
case BE_INETADDR:
|
1999-10-08 07:47:09 +08:00
|
|
|
if (asnlen != ASNLEN_INETADDR)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[inetaddr len!=%d]", ASNLEN_INETADDR));
|
|
|
|
ND_TCHECK2(*p, asnlen);
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
for (i = asnlen; i-- != 0; p++) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, (i == asnlen-1) ? "%u" : ".%u", *p));
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
case BE_NOSUCHOBJECT:
|
|
|
|
case BE_NOSUCHINST:
|
|
|
|
case BE_ENDOFMIBVIEW:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[%s]", Class[EXCEPTIONS].Id[elem->id]));
|
1999-10-18 06:18:00 +08:00
|
|
|
break;
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
case BE_PDU:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s(%u)", Class[CONTEXT].Id[elem->id], elem->asnlen));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_ANY:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[BE_ANY!?]"));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[be!?]"));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
}
|
2004-12-28 06:14:12 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
trunc:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s", tstr));
|
2004-12-28 06:14:12 +08:00
|
|
|
return -1;
|
1999-10-08 07:47:09 +08: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) {
|
2014-03-29 19:39:31 +08:00
|
|
|
i = asn1_parse(ndo, p, length, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
if (i >= 0) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " "));
|
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2004-12-28 06:14:12 +08:00
|
|
|
return;
|
1999-10-08 07:47:09 +08:00
|
|
|
if (elem.type == BE_SEQ || elem.type == BE_PDU) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " {"));
|
1999-10-08 07:47:09 +08:00
|
|
|
asn1_decode(elem.data.raw, elem.asnlen);
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " }"));
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
length -= i;
|
|
|
|
p += i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
Clean up configure check for libsmi.
First, check for smi.h. If we don't have it, don't check for anything
else.
If we do have it, check for libsmi containing smiInit. If we don't have
it, don't check for anything else.
If we do have it, check, with our test program, whether we can use it.
If that succeeds, prepend -lsmi to LIBS, and set USE_LIBSMI. Otherwise,
don't do either of those.
Check, in source, *only* for USE_LIBSMI. If it's set, use libsmi,
otherwise don't - don't even include smi.h, even if we happened to have
found it, and don't print the libsmi version string.
2014-09-01 02:57:04 +08:00
|
|
|
#ifdef USE_LIBSMI
|
1999-12-14 02:06:13 +08:00
|
|
|
|
|
|
|
struct smi2be {
|
|
|
|
SmiBasetype basetype;
|
|
|
|
int be;
|
|
|
|
};
|
|
|
|
|
2013-12-19 18:05:59 +08:00
|
|
|
static const struct smi2be smi2betab[] = {
|
1999-12-14 02:06:13 +08: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 }
|
|
|
|
};
|
|
|
|
|
2004-12-28 06:14:12 +08:00
|
|
|
static int
|
2014-03-30 14:48:43 +08:00
|
|
|
smi_decode_oid(netdissect_options *ndo,
|
|
|
|
struct be *elem, unsigned int *oid,
|
|
|
|
unsigned int oidsize, unsigned int *oidlen)
|
1999-12-14 02:06:13 +08:00
|
|
|
{
|
|
|
|
u_char *p = (u_char *)elem->data.raw;
|
2014-04-23 15:20:40 +08:00
|
|
|
uint32_t asnlen = elem->asnlen;
|
1999-12-14 02:06:13 +08:00
|
|
|
int o = 0, first = -1, i = asnlen;
|
2014-07-08 18:23:09 +08:00
|
|
|
unsigned int firstval;
|
1999-12-14 02:06:13 +08:00
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
for (*oidlen = 0; ndo->ndo_sflag && i-- > 0; p++) {
|
|
|
|
ND_TCHECK(*p);
|
1999-12-14 02:06:13 +08:00
|
|
|
o = (o << ASN_SHIFT7) + (*p & ~ASN_BIT8);
|
|
|
|
if (*p & ASN_LONGLEN)
|
|
|
|
continue;
|
2002-06-12 01:08:37 +08:00
|
|
|
|
1999-12-14 02:06:13 +08:00
|
|
|
/*
|
|
|
|
* first subitem encodes two items with 1st*OIDMUX+2nd
|
2002-05-07 15:39:05 +08:00
|
|
|
* (see X.690:1997 clause 8.19 for the details)
|
1999-12-14 02:06:13 +08:00
|
|
|
*/
|
|
|
|
if (first < 0) {
|
|
|
|
first = 0;
|
2014-07-08 18:23:09 +08:00
|
|
|
firstval = o / OIDMUX;
|
|
|
|
if (firstval > 2) firstval = 2;
|
2014-07-08 18:26:18 +08:00
|
|
|
o -= firstval * OIDMUX;
|
2001-04-24 03:29:21 +08:00
|
|
|
if (*oidlen < oidsize) {
|
2014-07-08 18:26:18 +08:00
|
|
|
oid[(*oidlen)++] = firstval;
|
2001-04-24 03:29:21 +08:00
|
|
|
}
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
2001-04-24 03:29:21 +08:00
|
|
|
if (*oidlen < oidsize) {
|
2002-05-07 15:39:05 +08:00
|
|
|
oid[(*oidlen)++] = o;
|
2001-04-24 03:29:21 +08:00
|
|
|
}
|
1999-12-14 02:06:13 +08:00
|
|
|
o = 0;
|
|
|
|
}
|
2004-12-28 06:14:12 +08:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
trunc:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s", tstr));
|
2004-12-28 06:14:12 +08:00
|
|
|
return -1;
|
1999-12-14 02:06:13 +08: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)
|
|
|
|
{
|
2000-11-11 01:34:10 +08:00
|
|
|
int ok = 1;
|
2002-06-12 01:08:37 +08:00
|
|
|
|
1999-12-14 02:06:13 +08: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;
|
2002-06-12 01:08:37 +08:00
|
|
|
|
1999-12-14 02:06:13 +08:00
|
|
|
case SMI_BASETYPE_UNSIGNED32:
|
|
|
|
ok = (elem->data.uns >= smiRange->minValue.value.unsigned32
|
|
|
|
&& elem->data.uns <= smiRange->maxValue.value.unsigned32);
|
|
|
|
break;
|
2002-06-12 01:08:37 +08:00
|
|
|
|
1999-12-14 02:06:13 +08: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;
|
2004-11-04 15:53:56 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
ok = 0;
|
|
|
|
break;
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smi_check_range(SmiType *smiType, struct be *elem)
|
|
|
|
{
|
|
|
|
SmiRange *smiRange;
|
|
|
|
int ok = 1;
|
|
|
|
|
2000-11-05 06:50:23 +08:00
|
|
|
for (smiRange = smiGetFirstRange(smiType);
|
1999-12-14 02:06:13 +08:00
|
|
|
smiRange;
|
|
|
|
smiRange = smiGetNextRange(smiRange)) {
|
|
|
|
|
|
|
|
ok = smi_check_a_range(smiType, smiRange, elem);
|
2000-11-05 06:50:23 +08:00
|
|
|
|
1999-12-14 02:06:13 +08:00
|
|
|
if (ok) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-25 05:50:58 +08:00
|
|
|
if (ok) {
|
1999-12-14 02:06:13 +08:00
|
|
|
SmiType *parentType;
|
2000-11-05 06:50:23 +08:00
|
|
|
parentType = smiGetParentType(smiType);
|
1999-12-14 02:06:13 +08:00
|
|
|
if (parentType) {
|
|
|
|
ok = smi_check_range(parentType, elem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
}
|
|
|
|
|
2014-03-30 14:48:43 +08:00
|
|
|
static SmiNode *
|
|
|
|
smi_print_variable(netdissect_options *ndo,
|
|
|
|
struct be *elem, int *status)
|
1999-12-14 02:06:13 +08:00
|
|
|
{
|
|
|
|
unsigned int oid[128], oidlen;
|
|
|
|
SmiNode *smiNode = NULL;
|
2005-01-05 12:05:04 +08:00
|
|
|
unsigned int i;
|
1999-12-14 02:06:13 +08:00
|
|
|
|
2014-03-30 14:48:43 +08:00
|
|
|
*status = smi_decode_oid(ndo, elem, oid, sizeof(oid) / sizeof(unsigned int),
|
2004-12-28 06:14:12 +08:00
|
|
|
&oidlen);
|
|
|
|
if (*status < 0)
|
|
|
|
return NULL;
|
1999-12-14 02:06:13 +08:00
|
|
|
smiNode = smiGetNodeByOID(oidlen, oid);
|
|
|
|
if (! smiNode) {
|
2014-03-29 19:39:31 +08:00
|
|
|
*status = asn1_print(ndo, elem);
|
1999-12-14 02:06:13 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "%s::", smiGetNodeModule(smiNode)->name));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s", smiNode->name));
|
1999-12-14 02:06:13 +08:00
|
|
|
if (smiNode->oidlen < oidlen) {
|
2014-03-29 19:39:31 +08:00
|
|
|
for (i = smiNode->oidlen; i < oidlen; i++) {
|
|
|
|
ND_PRINT((ndo, ".%u", oid[i]));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
}
|
2004-12-28 06:14:12 +08:00
|
|
|
*status = 0;
|
1999-12-14 02:06:13 +08:00
|
|
|
return smiNode;
|
|
|
|
}
|
|
|
|
|
2004-12-28 06:14:12 +08:00
|
|
|
static int
|
2014-03-30 14:48:43 +08:00
|
|
|
smi_print_value(netdissect_options *ndo,
|
|
|
|
SmiNode *smiNode, u_char pduid, struct be *elem)
|
1999-12-14 02:06:13 +08:00
|
|
|
{
|
2005-01-05 12:05:04 +08:00
|
|
|
unsigned int i, oid[128], oidlen;
|
1999-12-14 02:06:13 +08:00
|
|
|
SmiType *smiType;
|
|
|
|
SmiNamedNumber *nn;
|
2005-01-05 12:05:04 +08:00
|
|
|
int done = 0;
|
1999-12-14 02:06:13 +08:00
|
|
|
|
|
|
|
if (! smiNode || ! (smiNode->nodekind
|
|
|
|
& (SMI_NODEKIND_SCALAR | SMI_NODEKIND_COLUMN))) {
|
2014-03-29 19:39:31 +08:00
|
|
|
return asn1_print(ndo, elem);
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
|
2000-11-11 01:34:10 +08:00
|
|
|
if (elem->type == BE_NOSUCHOBJECT
|
|
|
|
|| elem->type == BE_NOSUCHINST
|
|
|
|
|| elem->type == BE_ENDOFMIBVIEW) {
|
2014-03-29 19:39:31 +08:00
|
|
|
return asn1_print(ndo, elem);
|
2000-11-11 01:34:10 +08:00
|
|
|
}
|
|
|
|
|
1999-12-14 02:06:13 +08:00
|
|
|
if (NOTIFY_CLASS(pduid) && smiNode->access < SMI_ACCESS_NOTIFY) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[notNotifyable]"));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (READ_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_ONLY) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[notReadable]"));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (WRITE_CLASS(pduid) && smiNode->access < SMI_ACCESS_READ_WRITE) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[notWritable]"));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (RESPONSE_CLASS(pduid)
|
|
|
|
&& smiNode->access == SMI_ACCESS_NOT_ACCESSIBLE) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[noAccess]"));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
|
2000-11-05 06:50:23 +08:00
|
|
|
smiType = smiGetNodeType(smiNode);
|
1999-12-14 02:06:13 +08:00
|
|
|
if (! smiType) {
|
2014-03-29 19:39:31 +08:00
|
|
|
return asn1_print(ndo, elem);
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
|
2000-11-05 06:50:23 +08:00
|
|
|
if (! smi_check_type(smiType->basetype, elem->type)) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[wrongType]"));
|
2000-11-05 06:50:23 +08:00
|
|
|
}
|
|
|
|
|
1999-12-14 02:06:13 +08:00
|
|
|
if (! smi_check_range(smiType, elem)) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[outOfRange]"));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* resolve bits to named bits */
|
|
|
|
|
|
|
|
/* check whether instance identifier is valid */
|
|
|
|
|
|
|
|
/* apply display hints (integer, octetstring) */
|
|
|
|
|
|
|
|
/* convert instance identifier to index type values */
|
2002-06-12 01:08:37 +08:00
|
|
|
|
1999-12-14 02:06:13 +08:00
|
|
|
switch (elem->type) {
|
|
|
|
case BE_OID:
|
2000-11-05 06:50:23 +08:00
|
|
|
if (smiType->basetype == SMI_BASETYPE_BITS) {
|
1999-12-14 02:06:13 +08:00
|
|
|
/* print bit labels */
|
|
|
|
} else {
|
2014-03-30 14:48:43 +08:00
|
|
|
smi_decode_oid(ndo, elem, oid,
|
2001-04-24 03:29:21 +08:00
|
|
|
sizeof(oid)/sizeof(unsigned int),
|
|
|
|
&oidlen);
|
1999-12-14 02:06:13 +08:00
|
|
|
smiNode = smiGetNodeByOID(oidlen, oid);
|
|
|
|
if (smiNode) {
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "%s::", smiGetNodeModule(smiNode)->name));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s", smiNode->name));
|
1999-12-14 02:06:13 +08:00
|
|
|
if (smiNode->oidlen < oidlen) {
|
2002-06-12 01:08:37 +08:00
|
|
|
for (i = smiNode->oidlen;
|
1999-12-14 02:06:13 +08:00
|
|
|
i < oidlen; i++) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, ".%u", oid[i]));
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
done++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BE_INT:
|
2000-11-05 06:50:23 +08:00
|
|
|
if (smiType->basetype == SMI_BASETYPE_ENUM) {
|
|
|
|
for (nn = smiGetFirstNamedNumber(smiType);
|
1999-12-14 02:06:13 +08:00
|
|
|
nn;
|
|
|
|
nn = smiGetNextNamedNumber(nn)) {
|
|
|
|
if (nn->value.value.integer32
|
|
|
|
== elem->data.integer) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "%s", nn->name));
|
|
|
|
ND_PRINT((ndo, "(%d)", elem->data.integer));
|
1999-12-14 02:06:13 +08:00
|
|
|
done++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! done) {
|
2014-03-29 19:39:31 +08:00
|
|
|
return asn1_print(ndo, elem);
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
2004-12-28 06:14:12 +08:00
|
|
|
return 0;
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-10-08 07:47:09 +08: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
|
2014-03-29 19:39:31 +08:00
|
|
|
varbind_print(netdissect_options *ndo,
|
|
|
|
u_char pduid, const u_char *np, u_int length)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0, ind;
|
Clean up configure check for libsmi.
First, check for smi.h. If we don't have it, don't check for anything
else.
If we do have it, check for libsmi containing smiInit. If we don't have
it, don't check for anything else.
If we do have it, check, with our test program, whether we can use it.
If that succeeds, prepend -lsmi to LIBS, and set USE_LIBSMI. Otherwise,
don't do either of those.
Check, in source, *only* for USE_LIBSMI. If it's set, use libsmi,
otherwise don't - don't even include smi.h, even if we happened to have
found it, and don't print the libsmi version string.
2014-09-01 02:57:04 +08:00
|
|
|
#ifdef USE_LIBSMI
|
1999-12-14 02:06:13 +08:00
|
|
|
SmiNode *smiNode = NULL;
|
|
|
|
#endif
|
2004-12-28 06:14:12 +08:00
|
|
|
int status;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/* Sequence of varBind */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[!SEQ of varbind]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
if ((u_int)count < length)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[%d extra after SEQ of varbind]", length - count));
|
1999-10-08 07:47:09 +08:00
|
|
|
/* descend */
|
|
|
|
length = elem.asnlen;
|
|
|
|
np = (u_char *)elem.data.raw;
|
|
|
|
|
|
|
|
for (ind = 1; length > 0; ind++) {
|
|
|
|
const u_char *vbend;
|
|
|
|
u_int vblength;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " "));
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/* Sequence */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[!varbind]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
vbend = np + count;
|
|
|
|
vblength = length - count;
|
|
|
|
/* descend */
|
|
|
|
length = elem.asnlen;
|
|
|
|
np = (u_char *)elem.data.raw;
|
|
|
|
|
|
|
|
/* objName (OID) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_OID) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[objName!=OID]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
Clean up configure check for libsmi.
First, check for smi.h. If we don't have it, don't check for anything
else.
If we do have it, check for libsmi containing smiInit. If we don't have
it, don't check for anything else.
If we do have it, check, with our test program, whether we can use it.
If that succeeds, prepend -lsmi to LIBS, and set USE_LIBSMI. Otherwise,
don't do either of those.
Check, in source, *only* for USE_LIBSMI. If it's set, use libsmi,
otherwise don't - don't even include smi.h, even if we happened to have
found it, and don't print the libsmi version string.
2014-09-01 02:57:04 +08:00
|
|
|
#ifdef USE_LIBSMI
|
2014-03-30 14:48:43 +08:00
|
|
|
smiNode = smi_print_variable(ndo, &elem, &status);
|
1999-12-14 02:06:13 +08:00
|
|
|
#else
|
2014-03-29 19:39:31 +08:00
|
|
|
status = asn1_print(ndo, &elem);
|
1999-12-14 02:06:13 +08:00
|
|
|
#endif
|
2004-12-28 06:14:12 +08:00
|
|
|
if (status < 0)
|
|
|
|
return;
|
1999-10-08 07:47:09 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
if (pduid != GETREQ && pduid != GETNEXTREQ
|
1999-12-14 02:06:13 +08:00
|
|
|
&& pduid != GETBULKREQ)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "="));
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/* objVal (ANY) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
1999-10-18 06:18:00 +08:00
|
|
|
if (pduid == GETREQ || pduid == GETNEXTREQ
|
|
|
|
|| pduid == GETBULKREQ) {
|
1999-10-08 07:47:09 +08:00
|
|
|
if (elem.type != BE_NULL) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[objVal!=NULL]"));
|
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2004-12-28 06:14:12 +08:00
|
|
|
return;
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
1999-12-14 02:06:13 +08:00
|
|
|
} else {
|
|
|
|
if (elem.type != BE_NULL) {
|
Clean up configure check for libsmi.
First, check for smi.h. If we don't have it, don't check for anything
else.
If we do have it, check for libsmi containing smiInit. If we don't have
it, don't check for anything else.
If we do have it, check, with our test program, whether we can use it.
If that succeeds, prepend -lsmi to LIBS, and set USE_LIBSMI. Otherwise,
don't do either of those.
Check, in source, *only* for USE_LIBSMI. If it's set, use libsmi,
otherwise don't - don't even include smi.h, even if we happened to have
found it, and don't print the libsmi version string.
2014-09-01 02:57:04 +08:00
|
|
|
#ifdef USE_LIBSMI
|
2014-03-30 14:48:43 +08:00
|
|
|
status = smi_print_value(ndo, smiNode, pduid, &elem);
|
1999-12-14 02:06:13 +08:00
|
|
|
#else
|
2014-03-29 19:39:31 +08:00
|
|
|
status = asn1_print(ndo, &elem);
|
1999-12-14 02:06:13 +08:00
|
|
|
#endif
|
|
|
|
}
|
2004-12-28 06:14:12 +08:00
|
|
|
if (status < 0)
|
|
|
|
return;
|
1999-12-14 02:06:13 +08:00
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
length = vblength;
|
|
|
|
np = vbend;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-10-18 06:18:00 +08:00
|
|
|
* Decode SNMP PDUs: GetRequest, GetNextRequest, GetResponse, SetRequest,
|
|
|
|
* GetBulk, Inform, V2Trap, and Report
|
1999-10-08 07:47:09 +08:00
|
|
|
*/
|
|
|
|
static void
|
2014-03-29 19:39:31 +08:00
|
|
|
snmppdu_print(netdissect_options *ndo,
|
|
|
|
u_short pduid, const u_char *np, u_int length)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0, error;
|
|
|
|
|
|
|
|
/* reqId (Integer) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[reqId!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag)
|
|
|
|
ND_PRINT((ndo, "R=%d ", elem.data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* errorStatus (Integer) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[errorStatus!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
error = 0;
|
1999-10-18 06:18:00 +08:00
|
|
|
if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ
|
|
|
|
|| pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT)
|
1999-10-08 07:47:09 +08:00
|
|
|
&& elem.data.integer != 0) {
|
2005-04-18 08:07:31 +08:00
|
|
|
char errbuf[20];
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[errorStatus(%s)!=0]",
|
|
|
|
DECODE_ErrorStatus(elem.data.integer)));
|
1999-10-18 06:18:00 +08:00
|
|
|
} else if (pduid == GETBULKREQ) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " N=%d", elem.data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
} else if (elem.data.integer != 0) {
|
2005-04-18 08:07:31 +08:00
|
|
|
char errbuf[20];
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " %s", DECODE_ErrorStatus(elem.data.integer)));
|
1999-10-08 07:47:09 +08:00
|
|
|
error = elem.data.integer;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* errorIndex (Integer) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[errorIndex!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-10-18 06:18:00 +08:00
|
|
|
if ((pduid == GETREQ || pduid == GETNEXTREQ || pduid == SETREQ
|
|
|
|
|| pduid == INFORMREQ || pduid == V2TRAP || pduid == REPORT)
|
1999-10-08 07:47:09 +08:00
|
|
|
&& elem.data.integer != 0)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[errorIndex(%d)!=0]", elem.data.integer));
|
1999-10-18 06:18:00 +08:00
|
|
|
else if (pduid == GETBULKREQ)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " M=%d", elem.data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
else if (elem.data.integer != 0) {
|
|
|
|
if (!error)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[errorIndex(%d) w/o errorStatus]", elem.data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
else {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "@%d", elem.data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
error = elem.data.integer;
|
|
|
|
}
|
|
|
|
} else if (error) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[errorIndex==0]"));
|
1999-10-08 07:47:09 +08:00
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
varbind_print(ndo, pduid, np, length);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMP Trap PDU
|
|
|
|
*/
|
|
|
|
static void
|
2014-03-29 19:39:31 +08:00
|
|
|
trappdu_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0, generic;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " "));
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/* enterprise (oid) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_OID) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[enterprise!=OID]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2004-12-28 06:14:12 +08:00
|
|
|
return;
|
1999-10-08 07:47:09 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " "));
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/* agent-addr (inetaddr) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INETADDR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[agent-addr!=INETADDR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2004-12-28 06:14:12 +08:00
|
|
|
return;
|
1999-10-08 07:47:09 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* generic-trap (Integer) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[generic-trap!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
generic = elem.data.integer;
|
|
|
|
{
|
2005-04-18 08:07:31 +08:00
|
|
|
char buf[20];
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " %s", DECODE_GenericTrap(generic)));
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* specific-trap (Integer) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[specific-trap!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (generic != GT_ENTERPRISE) {
|
|
|
|
if (elem.data.integer != 0)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[specific-trap(%d)!=0]", elem.data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
} else
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " s=%d", elem.data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " "));
|
1999-10-08 07:47:09 +08:00
|
|
|
|
|
|
|
/* time-stamp (TimeTicks) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_UNS) { /* XXX */
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[time-stamp!=TIMETICKS]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
if (asn1_print(ndo, &elem) < 0)
|
2004-12-28 06:14:12 +08:00
|
|
|
return;
|
1999-10-08 07:47:09 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
varbind_print(ndo, TRAP, np, length);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1999-10-18 06:18:00 +08:00
|
|
|
* Decode arbitrary SNMP PDUs.
|
1999-10-08 07:47:09 +08:00
|
|
|
*/
|
1999-10-18 06:18:00 +08:00
|
|
|
static void
|
2014-03-29 19:39:31 +08:00
|
|
|
pdu_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length, int version)
|
1999-10-08 07:47:09 +08:00
|
|
|
{
|
1999-10-18 06:18:00 +08:00
|
|
|
struct be pdu;
|
1999-10-08 07:47:09 +08:00
|
|
|
int count = 0;
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
/* PDU (Context) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &pdu)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (pdu.type != BE_PDU) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[no PDU]"));
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
if ((u_int)count < length)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[%d extra after PDU]", length - count));
|
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "{ "));
|
2000-11-11 01:34:10 +08:00
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
if (asn1_print(ndo, &pdu) < 0)
|
2004-12-28 06:14:12 +08:00
|
|
|
return;
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " "));
|
1999-10-18 06:18:00 +08:00
|
|
|
/* descend into PDU */
|
|
|
|
length = pdu.asnlen;
|
|
|
|
np = (u_char *)pdu.data.raw;
|
1999-10-08 07:47:09 +08:00
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
if (version == SNMP_VERSION_1 &&
|
2002-06-12 01:08:37 +08:00
|
|
|
(pdu.id == GETBULKREQ || pdu.id == INFORMREQ ||
|
1999-10-18 06:18:00 +08:00
|
|
|
pdu.id == V2TRAP || pdu.id == REPORT)) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[v2 PDU in v1 message]"));
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
if (version == SNMP_VERSION_2 && pdu.id == TRAP) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[v1 PDU in v2 message]"));
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
switch (pdu.id) {
|
|
|
|
case TRAP:
|
2014-03-29 19:39:31 +08:00
|
|
|
trappdu_print(ndo, np, length);
|
1999-10-18 06:18:00 +08:00
|
|
|
break;
|
|
|
|
case GETREQ:
|
|
|
|
case GETNEXTREQ:
|
|
|
|
case GETRESP:
|
|
|
|
case SETREQ:
|
|
|
|
case GETBULKREQ:
|
|
|
|
case INFORMREQ:
|
|
|
|
case V2TRAP:
|
|
|
|
case REPORT:
|
2014-03-29 19:39:31 +08:00
|
|
|
snmppdu_print(ndo, pdu.id, np, length);
|
1999-10-18 06:18:00 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-11-11 01:34:10 +08:00
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, " } "));
|
2000-11-11 01:34:10 +08:00
|
|
|
}
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode a scoped SNMP PDU.
|
|
|
|
*/
|
|
|
|
static void
|
2014-03-29 19:39:31 +08:00
|
|
|
scopedpdu_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length, int version)
|
1999-10-18 06:18:00 +08:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int i, count = 0;
|
|
|
|
|
|
|
|
/* Sequence */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[!scoped PDU]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length = elem.asnlen;
|
|
|
|
np = (u_char *)elem.data.raw;
|
1999-10-18 06:18:00 +08:00
|
|
|
|
|
|
|
/* contextEngineID (OCTET STRING) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
1999-10-18 06:18:00 +08:00
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[contextEngineID!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-10-18 06:18:00 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "E= "));
|
1999-10-18 06:18:00 +08:00
|
|
|
for (i = 0; i < (int)elem.asnlen; i++) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "0x%02X", elem.data.str[i]));
|
|
|
|
}
|
|
|
|
ND_PRINT((ndo, " "));
|
1999-10-18 06:18:00 +08:00
|
|
|
|
|
|
|
/* contextName (OCTET STRING) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[contextName!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "C=%.*s ", (int)elem.asnlen, elem.data.str));
|
1999-10-18 06:18:00 +08:00
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
pdu_print(ndo, np, length, version);
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMP Community Header (SNMPv1 and SNMPv2c)
|
|
|
|
*/
|
|
|
|
static void
|
2014-03-29 19:39:31 +08:00
|
|
|
community_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length, int version)
|
1999-10-18 06:18:00 +08:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0;
|
|
|
|
|
1999-10-08 07:47:09 +08:00
|
|
|
/* Community (String) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[comm!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* default community */
|
2002-07-21 07:31:18 +08:00
|
|
|
if (!(elem.asnlen == sizeof(DEF_COMMUNITY) - 1 &&
|
|
|
|
strncmp((char *)elem.data.str, DEF_COMMUNITY,
|
|
|
|
sizeof(DEF_COMMUNITY) - 1) == 0))
|
1999-10-08 07:47:09 +08:00
|
|
|
/* ! "public" */
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "C=%.*s ", (int)elem.asnlen, elem.data.str));
|
1999-10-08 07:47:09 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
pdu_print(ndo, np, length, version);
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMPv3 User-based Security Message Header (SNMPv3)
|
|
|
|
*/
|
|
|
|
static void
|
2014-03-29 19:39:31 +08:00
|
|
|
usm_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length)
|
1999-10-18 06:18:00 +08:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
/* Sequence */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
1999-10-18 06:18:00 +08:00
|
|
|
if (elem.type != BE_SEQ) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[!usm]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length = elem.asnlen;
|
|
|
|
np = (u_char *)elem.data.raw;
|
|
|
|
|
|
|
|
/* msgAuthoritativeEngineID (OCTET STRING) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgAuthoritativeEngineID!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgAuthoritativeEngineBoots (INTEGER) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgAuthoritativeEngineBoots!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag)
|
|
|
|
ND_PRINT((ndo, "B=%d ", elem.data.integer));
|
1999-10-18 06:18:00 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgAuthoritativeEngineTime (INTEGER) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgAuthoritativeEngineTime!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag)
|
|
|
|
ND_PRINT((ndo, "T=%d ", elem.data.integer));
|
1999-10-18 06:18:00 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgUserName (OCTET STRING) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgUserName!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "U=%.*s ", (int)elem.asnlen, elem.data.str));
|
1999-10-18 06:18:00 +08:00
|
|
|
|
|
|
|
/* msgAuthenticationParameters (OCTET STRING) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgAuthenticationParameters!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgPrivacyParameters (OCTET STRING) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgPrivacyParameters!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-08 07:47:09 +08:00
|
|
|
return;
|
|
|
|
}
|
1999-10-18 06:18:00 +08:00
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
if ((u_int)count < length)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[%d extra after usm SEQ]", length - count));
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
/*
|
|
|
|
* Decode SNMPv3 Message Header (SNMPv3)
|
|
|
|
*/
|
|
|
|
static void
|
2014-03-29 19:39:31 +08:00
|
|
|
v3msg_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length)
|
1999-10-18 06:18:00 +08:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0;
|
|
|
|
u_char flags;
|
|
|
|
int model;
|
|
|
|
const u_char *xnp = np;
|
|
|
|
int xlength = length;
|
|
|
|
|
|
|
|
/* Sequence */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[!message]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length = elem.asnlen;
|
|
|
|
np = (u_char *)elem.data.raw;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "{ "));
|
2000-11-11 01:34:10 +08:00
|
|
|
}
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
/* msgID (INTEGER) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgID!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgMaxSize (INTEGER) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgMaxSize!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
/* msgFlags (OCTET STRING) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgFlags!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (elem.asnlen != 1) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgFlags size %d]", elem.asnlen));
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
flags = elem.data.str[0];
|
2002-06-12 01:08:37 +08:00
|
|
|
if (flags != 0x00 && flags != 0x01 && flags != 0x03
|
1999-10-18 06:18:00 +08:00
|
|
|
&& flags != 0x04 && flags != 0x05 && flags != 0x07) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgFlags=0x%02X]", flags));
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "F=%s%s%s ",
|
|
|
|
flags & 0x01 ? "a" : "",
|
|
|
|
flags & 0x02 ? "p" : "",
|
|
|
|
flags & 0x04 ? "r" : ""));
|
1999-10-18 06:18:00 +08:00
|
|
|
|
|
|
|
/* msgSecurityModel (INTEGER) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgSecurityModel!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
model = elem.data.integer;
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
if ((u_int)count < length)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[%d extra after message SEQ]", length - count));
|
1999-10-18 06:18:00 +08:00
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "} "));
|
2000-11-11 01:34:10 +08:00
|
|
|
}
|
|
|
|
|
1999-10-18 06:18:00 +08:00
|
|
|
if (model == 3) {
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "{ USM "));
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
|
|
|
} else {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[security model %d]", model));
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
np = xnp + (np - xnp);
|
|
|
|
length = xlength - (np - xnp);
|
|
|
|
|
|
|
|
/* msgSecurityParameters (OCTET STRING) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_STR) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[msgSecurityParameters!=STR]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
if (model == 3) {
|
2014-03-29 19:39:31 +08:00
|
|
|
usm_print(ndo, elem.data.str, elem.asnlen);
|
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "} "));
|
2000-11-11 01:34:10 +08:00
|
|
|
}
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "{ ScopedPDU "));
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
scopedpdu_print(ndo, np, length, 3);
|
2000-11-11 01:34:10 +08:00
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "} "));
|
2000-11-11 01:34:10 +08:00
|
|
|
}
|
1999-10-18 06:18:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decode SNMP header and pass on to PDU printing routines
|
|
|
|
*/
|
|
|
|
void
|
2014-03-29 19:39:31 +08:00
|
|
|
snmp_print(netdissect_options *ndo,
|
|
|
|
const u_char *np, u_int length)
|
1999-10-18 06:18:00 +08:00
|
|
|
{
|
|
|
|
struct be elem;
|
|
|
|
int count = 0;
|
|
|
|
int version = 0;
|
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, " "));
|
1999-10-18 06:18:00 +08:00
|
|
|
|
|
|
|
/* initial Sequence */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_SEQ) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[!init SEQ]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
Add a few more GCC warnings on GCC >= 2 for ".devel" builds.
From Neil T. Spring: fixes for many of those warnings:
addrtoname.c, configure.in: Linux needs netinet/ether.h for
ether_ntohost
print-*.c: change char *foo = "bar" to const char *foo = "bar"
to appease -Wwrite-strings; should affect no run-time behavior.
print-*.c: make some variables unsigned.
print-bgp.c: plen ('prefix len') is unsigned, no reason to
validate by comparing to zero.
print-cnfp.c, print-rx.c: use intoa, provided by addrtoname,
instead of inet_ntoa.
print-domain.c: unsigned int l; (l=foo()) < 0 is guaranteed to
be false, so check for (u_int)-1, which represents failure,
explicitly.
print-isakmp.c: complete initialization of attrmap objects.
print-lwres.c: "if(x); print foo;" seemed much more likely to be
intended to be "if(x) { print foo; }".
print-smb.c: complete initialization of some structures.
In addition, add some fixes for the signed vs. unsigned comparison
warnings:
extract.h: cast the result of the byte-extraction-and-combining,
as, at least for the 16-bit version, C's integral promotions
will turn "u_int16_t" into "int" if there are other "int"s
nearby.
print-*.c: make some more variables unsigned, or add casts to an
unsigned type of signed values known not to be negative, or add
casts to "int" of unsigned values known to fit in an "int", and
make other changes needed to handle the aforementioned variables
now being unsigned.
print-isakmp.c: clean up the handling of error/status indicators
in notify messages.
print-ppp.c: get rid of a check that an unsigned quantity is >=
0.
print-radius.c: clean up some of the bounds checking.
print-smb.c: extract the word count into a "u_int" to avoid the
aforementioned problems with C's integral promotions.
print-snmp.c: change a check that an unsigned variable is >= 0
to a check that it's != 0.
Also, fix some formats to use "%u" rather than "%d" for unsigned
quantities.
2002-09-05 08:00:07 +08:00
|
|
|
if ((u_int)count < length)
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[%d extra after iSEQ]", length - count));
|
1999-10-18 06:18:00 +08:00
|
|
|
/* descend */
|
|
|
|
length = elem.asnlen;
|
|
|
|
np = (u_char *)elem.data.raw;
|
|
|
|
|
|
|
|
/* Version (INTEGER) */
|
2014-03-29 19:39:31 +08:00
|
|
|
if ((count = asn1_parse(ndo, np, length, &elem)) < 0)
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
if (elem.type != BE_INT) {
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[version!=INT]"));
|
|
|
|
asn1_print(ndo, &elem);
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (elem.data.integer) {
|
|
|
|
case SNMP_VERSION_1:
|
|
|
|
case SNMP_VERSION_2:
|
|
|
|
case SNMP_VERSION_3:
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag)
|
|
|
|
ND_PRINT((ndo, "{ %s ", SnmpVersion[elem.data.integer]));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
1999-10-18 06:18:00 +08:00
|
|
|
default:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[version = %d]", elem.data.integer));
|
1999-10-18 06:18:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
version = elem.data.integer;
|
|
|
|
length -= count;
|
|
|
|
np += count;
|
|
|
|
|
|
|
|
switch (version) {
|
|
|
|
case SNMP_VERSION_1:
|
|
|
|
case SNMP_VERSION_2:
|
2014-03-29 19:39:31 +08:00
|
|
|
community_print(ndo, np, length, version);
|
1999-10-18 06:18:00 +08:00
|
|
|
break;
|
|
|
|
case SNMP_VERSION_3:
|
2014-03-29 19:39:31 +08:00
|
|
|
v3msg_print(ndo, np, length);
|
1999-10-18 06:18:00 +08:00
|
|
|
break;
|
|
|
|
default:
|
2014-03-29 19:39:31 +08:00
|
|
|
ND_PRINT((ndo, "[version = %d]", elem.data.integer));
|
1999-10-08 07:47:09 +08:00
|
|
|
break;
|
|
|
|
}
|
2000-11-11 01:34:10 +08:00
|
|
|
|
2014-03-29 19:39:31 +08:00
|
|
|
if (ndo->ndo_vflag) {
|
|
|
|
ND_PRINT((ndo, "} "));
|
2000-11-11 01:34:10 +08:00
|
|
|
}
|
1999-10-08 07:47:09 +08:00
|
|
|
}
|