2007-08-15 19:52:44 +00:00
|
|
|
/* oids.c
|
2007-08-26 21:37:11 +00:00
|
|
|
* Object IDentifier Support
|
2007-08-15 19:52:44 +00:00
|
|
|
*
|
2008-08-05 21:03:46 +00:00
|
|
|
* (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
|
2007-08-15 19:52:44 +00:00
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2007-08-15 19:52:44 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 01:48:30 +00:00
|
|
|
#include "config.h"
|
2007-08-15 19:52:44 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
|
|
|
|
#include "emem.h"
|
2007-08-28 15:18:32 +00:00
|
|
|
#include "uat.h"
|
2007-08-21 21:32:00 +00:00
|
|
|
#include "prefs.h"
|
2007-08-27 17:05:11 +00:00
|
|
|
#include "proto.h"
|
2007-08-15 19:52:44 +00:00
|
|
|
#include "packet.h"
|
|
|
|
#include "report_err.h"
|
2007-08-21 21:32:00 +00:00
|
|
|
#include "filesystem.h"
|
2007-08-19 23:00:47 +00:00
|
|
|
#include "dissectors/packet-ber.h"
|
2007-08-15 19:52:44 +00:00
|
|
|
|
2007-08-25 20:27:58 +00:00
|
|
|
#ifdef HAVE_LIBSMI
|
2007-08-15 19:52:44 +00:00
|
|
|
#include <smi.h>
|
2010-03-03 17:19:30 +00:00
|
|
|
|
|
|
|
static gboolean oids_init_done = FALSE;
|
2012-07-06 04:48:36 +00:00
|
|
|
static gboolean load_smi_modules = FALSE;
|
|
|
|
static gboolean suppress_smi_errors = FALSE;
|
2007-08-15 19:52:44 +00:00
|
|
|
#endif
|
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
#define D(level,args) do if (debuglevel >= level) { printf args; printf("\n"); fflush(stdout); } while(0)
|
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
#include "oids.h"
|
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
static int debuglevel = 0;
|
|
|
|
|
2011-01-20 20:04:39 +00:00
|
|
|
/*
|
|
|
|
* From SNMPv2-SMI and X.690
|
|
|
|
*
|
|
|
|
* Counter32 ::= [APPLICATION 1] IMPLICIT INTEGER (0..4294967295)
|
|
|
|
* Gauge32 ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295)
|
|
|
|
* Unsigned32 ::= [APPLICATION 2] IMPLICIT INTEGER (0..4294967295) (alias of Gauge32)
|
|
|
|
* TimeTicks ::= [APPLICATION 3] IMPLICIT INTEGER (0..4294967295)
|
|
|
|
*
|
|
|
|
* If the BER encoding should not have the top bit set as to not become a negative number
|
|
|
|
* the BER encoding may take 5 octets to encode.
|
|
|
|
*/
|
|
|
|
|
2007-08-27 17:05:11 +00:00
|
|
|
static const oid_value_type_t integer_type = { FT_INT32, BASE_DEC, BER_CLASS_UNI, BER_UNI_TAG_INTEGER, 1, 4, OID_KEY_TYPE_INTEGER, 1};
|
|
|
|
static const oid_value_type_t bytes_type = { FT_BYTES, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 0, -1, OID_KEY_TYPE_BYTES, 0};
|
|
|
|
static const oid_value_type_t oid_type = { FT_OID, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OID, 1, -1, OID_KEY_TYPE_OID, 0};
|
|
|
|
static const oid_value_type_t ipv4_type = { FT_IPv4, BASE_NONE, BER_CLASS_APP, 0, 4, 4, OID_KEY_TYPE_IPADDR, 4};
|
2008-04-22 19:31:03 +00:00
|
|
|
static const oid_value_type_t counter32_type = { FT_UINT64, BASE_DEC, BER_CLASS_APP, 1, 1, 5, OID_KEY_TYPE_INTEGER, 1};
|
2011-01-20 20:04:39 +00:00
|
|
|
static const oid_value_type_t unsigned32_type = { FT_UINT64, BASE_DEC, BER_CLASS_APP, 2, 1, 5, OID_KEY_TYPE_INTEGER, 1};
|
2008-04-21 18:38:01 +00:00
|
|
|
static const oid_value_type_t timeticks_type = { FT_UINT64, BASE_DEC, BER_CLASS_APP, 3, 1, 5, OID_KEY_TYPE_INTEGER, 1};
|
2007-08-27 17:05:11 +00:00
|
|
|
static const oid_value_type_t opaque_type = { FT_BYTES, BASE_NONE, BER_CLASS_APP, 4, 1, 4, OID_KEY_TYPE_BYTES, 0};
|
2007-09-13 16:49:51 +00:00
|
|
|
static const oid_value_type_t nsap_type = { FT_BYTES, BASE_NONE, BER_CLASS_APP, 5, 0, -1, OID_KEY_TYPE_NSAP, 0};
|
|
|
|
static const oid_value_type_t counter64_type = { FT_UINT64, BASE_DEC, BER_CLASS_APP, 6, 1, 8, OID_KEY_TYPE_INTEGER, 1};
|
2007-08-27 17:05:11 +00:00
|
|
|
static const oid_value_type_t ipv6_type = { FT_IPv6, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 16, 16, OID_KEY_TYPE_BYTES, 16};
|
|
|
|
static const oid_value_type_t float_type = { FT_FLOAT, BASE_DEC, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 4, 4, OID_KEY_TYPE_WRONG, 0};
|
|
|
|
static const oid_value_type_t double_type = { FT_DOUBLE, BASE_DEC, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 8, 8, OID_KEY_TYPE_WRONG, 0};
|
2008-11-10 20:25:38 +00:00
|
|
|
static const oid_value_type_t ether_type = { FT_ETHER, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 6, 6, OID_KEY_TYPE_ETHER, 6};
|
2007-08-27 17:05:11 +00:00
|
|
|
static const oid_value_type_t string_type = { FT_STRING, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 0, -1, OID_KEY_TYPE_STRING, 0};
|
|
|
|
static const oid_value_type_t unknown_type = { FT_BYTES, BASE_NONE, BER_CLASS_ANY, BER_TAG_ANY, 0, -1, OID_KEY_TYPE_WRONG, 0};
|
2007-08-22 22:56:36 +00:00
|
|
|
|
|
|
|
static oid_info_t oid_root = { 0, NULL, OID_KIND_UNKNOWN, NULL, &unknown_type, -2, NULL, NULL, NULL};
|
2007-08-15 19:52:44 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
static oid_info_t* add_oid(const char* name, oid_kind_t kind, const oid_value_type_t* type, oid_key_t* key, guint oid_len, guint32 *subids) {
|
2007-08-15 19:52:44 +00:00
|
|
|
guint i = 0;
|
|
|
|
oid_info_t* c = &oid_root;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
if (!oid_root.children) {
|
|
|
|
char* debug_env = getenv("WIRESHARK_DEBUG_MIBS");
|
2007-08-25 17:29:55 +00:00
|
|
|
guint32 subid;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2012-12-26 05:57:06 +00:00
|
|
|
debuglevel = debug_env ? (int)strtoul(debug_env,NULL,10) : 0;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
oid_root.children = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK,"oid_root");
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 17:29:55 +00:00
|
|
|
/*
|
|
|
|
* make sure we got strings at least in the three root-children oids
|
|
|
|
* that way oid_resolved() will always have a string to print
|
|
|
|
*/
|
|
|
|
subid = 0; oid_add("itu-t",1,&subid);
|
|
|
|
subid = 1; oid_add("iso",1,&subid);
|
|
|
|
subid = 2; oid_add("joint-iso-itu-t",1,&subid);
|
2007-08-25 01:14:24 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
oid_len--;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
do {
|
|
|
|
oid_info_t* n = emem_tree_lookup32(c->children,subids[i]);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
if(n) {
|
|
|
|
if (i == oid_len) {
|
2007-08-25 01:14:24 +00:00
|
|
|
if (n->name) {
|
2007-08-28 15:18:32 +00:00
|
|
|
if (!g_str_equal(n->name,name)) {
|
2007-12-07 18:47:03 +00:00
|
|
|
D(2,("Renaming Oid from: %s -> %s, this means the same oid is registered more than once",n->name,name));
|
2007-08-28 15:18:32 +00:00
|
|
|
}
|
2012-10-27 21:01:41 +00:00
|
|
|
/* There used to be a comment here that claimed we couldn't free
|
|
|
|
* n->name since it may be part of an hf_register_info struct
|
|
|
|
* that has been appended to the hfa GArray. I think that comment
|
|
|
|
* was wrong, because we only ever create oid_info_t's in this
|
|
|
|
* function, and we are always careful here to g_strdup the name.
|
|
|
|
* All that to justify freeing n->name in the next line, since
|
|
|
|
* doing so fixes some memory leaks. */
|
|
|
|
g_free(n->name);
|
2007-08-21 21:32:00 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
n->name = g_strdup(name);
|
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
if (! n->value_type) {
|
2007-08-15 19:52:44 +00:00
|
|
|
n->value_type = type;
|
2007-08-19 23:00:47 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
return n;
|
2007-08-21 21:32:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
2007-08-19 23:00:47 +00:00
|
|
|
n = g_malloc(sizeof(oid_info_t));
|
|
|
|
n->subid = subids[i];
|
2007-08-22 22:56:36 +00:00
|
|
|
n->kind = kind;
|
2007-08-19 23:00:47 +00:00
|
|
|
n->children = pe_tree_create(EMEM_TREE_TYPE_RED_BLACK,"oid_children");
|
2007-08-21 21:32:00 +00:00
|
|
|
n->value_hfid = -2;
|
2007-08-22 22:56:36 +00:00
|
|
|
n->key = key;
|
2007-08-19 23:00:47 +00:00
|
|
|
n->parent = c;
|
|
|
|
n->bits = NULL;
|
2007-08-15 19:52:44 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
emem_tree_insert32(c->children,n->subid,n);
|
2007-08-15 19:52:44 +00:00
|
|
|
|
|
|
|
if (i == oid_len) {
|
2007-08-19 23:00:47 +00:00
|
|
|
n->name = g_strdup(name);
|
|
|
|
n->value_type = type;
|
2007-08-23 19:45:31 +00:00
|
|
|
n->kind = kind;
|
2007-08-19 23:00:47 +00:00
|
|
|
return n;
|
2007-08-15 19:52:44 +00:00
|
|
|
} else {
|
2007-08-25 01:14:24 +00:00
|
|
|
n->name = NULL;
|
2007-08-19 23:00:47 +00:00
|
|
|
n->value_type = NULL;
|
2007-08-23 19:45:31 +00:00
|
|
|
n->kind = OID_KIND_UNKNOWN;
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-19 23:00:47 +00:00
|
|
|
c = n;
|
2007-08-15 19:52:44 +00:00
|
|
|
} while(++i);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
g_assert_not_reached();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
void oid_add(const char* name, guint oid_len, guint32 *subids) {
|
2007-08-25 17:29:55 +00:00
|
|
|
g_assert(subids && *subids <= 2);
|
2007-08-25 01:14:24 +00:00
|
|
|
if (oid_len) {
|
|
|
|
D(3,("\tOid (from subids): %s %s ",name?name:"NULL", oid_subid2string(subids,oid_len)));
|
|
|
|
add_oid(name,OID_KIND_UNKNOWN,NULL,NULL,oid_len,subids);
|
|
|
|
} else {
|
|
|
|
D(1,("Failed to add Oid: %s (from subids)",name?name:"NULL"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void oid_add_from_string(const char* name, const gchar *oid_str) {
|
|
|
|
guint32* subids;
|
2007-12-04 18:43:40 +00:00
|
|
|
guint oid_len = oid_string2subid(oid_str, &subids);
|
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
if (oid_len) {
|
|
|
|
D(3,("\tOid (from string): %s %s ",name?name:"NULL", oid_subid2string(subids,oid_len)));
|
|
|
|
add_oid(name,OID_KIND_UNKNOWN,NULL,NULL,oid_len,subids);
|
|
|
|
} else {
|
|
|
|
D(1,("Failed to add Oid: %s %s ",name?name:"NULL", oid_str?oid_str:NULL));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void oid_add_from_encoded(const char* name, const guint8 *oid, gint oid_len) {
|
|
|
|
guint32* subids;
|
|
|
|
guint subids_len = oid_encoded2subid(oid, oid_len, &subids);
|
|
|
|
|
|
|
|
if (subids_len) {
|
|
|
|
D(3,("\tOid (from encoded): %s %s ",name, oid_subid2string(subids,subids_len)));
|
|
|
|
add_oid(name,OID_KIND_UNKNOWN,NULL,NULL,subids_len,subids);
|
|
|
|
} else {
|
|
|
|
D(1,("Failed to add Oid: %s [%d]%s ",name?name:"NULL", oid_len,bytestring_to_str(oid, oid_len, ':')));
|
|
|
|
}
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
|
|
|
|
2007-08-25 20:27:58 +00:00
|
|
|
#ifdef HAVE_LIBSMI
|
2008-03-19 21:09:31 +00:00
|
|
|
/* de-allocate storage mallocated by libsmi */
|
|
|
|
/* */
|
2009-03-17 15:34:18 +00:00
|
|
|
/* XXX: libsmi provides access to smiFree as of libsmi v 0.4.8. */
|
|
|
|
/* On Windows: Wireshark 1.01 and later is built and distributed */
|
|
|
|
/* with libsmi 0.4.8 (or newer). */
|
|
|
|
/* On non-Windows systems, free() should be OK for libsmi */
|
|
|
|
/* versions older than 0.4.8. */
|
2008-03-19 21:09:31 +00:00
|
|
|
|
|
|
|
static void smi_free(void *ptr) {
|
2009-03-17 15:34:18 +00:00
|
|
|
|
|
|
|
#if (SMI_VERSION_MAJOR >= 0) && (SMI_VERSION_MINOR >= 4) && (SMI_VERSION_PATCHLEVEL >= 8)
|
|
|
|
smiFree(ptr);
|
|
|
|
#else
|
|
|
|
#ifdef _WIN32
|
|
|
|
#error Invalid Windows libsmi version ?? !!
|
|
|
|
#endif
|
|
|
|
#define xx_free free /* hack so checkAPIs.pl doesn't complain */
|
|
|
|
xx_free(ptr);
|
2008-03-19 21:09:31 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
typedef struct smi_module_t {
|
|
|
|
char* name;
|
|
|
|
} smi_module_t;
|
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
static smi_module_t* smi_paths = NULL;
|
|
|
|
static guint num_smi_paths = 0;
|
2008-01-30 22:50:55 +00:00
|
|
|
static uat_t* smi_paths_uat = NULL;
|
2007-08-21 21:32:00 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
static smi_module_t* smi_modules = NULL;
|
|
|
|
static guint num_smi_modules = 0;
|
2008-01-30 22:50:55 +00:00
|
|
|
static uat_t* smi_modules_uat = NULL;
|
2007-08-15 19:52:44 +00:00
|
|
|
|
2007-08-28 19:07:39 +00:00
|
|
|
static GString* smi_errors;
|
|
|
|
|
2011-09-20 10:15:09 +00:00
|
|
|
UAT_DIRECTORYNAME_CB_DEF(smi_mod,name,smi_module_t)
|
2007-08-15 19:52:44 +00:00
|
|
|
|
2007-08-28 19:07:39 +00:00
|
|
|
static void smi_error_handler(char *path, int line, int severity, char *msg, char *tag) {
|
2008-05-05 20:38:27 +00:00
|
|
|
g_string_append_printf(smi_errors,"%s:%d %d %s %s\n",
|
2007-08-28 19:07:39 +00:00
|
|
|
path ? path : "-",
|
|
|
|
line, severity,
|
|
|
|
tag ? tag : "-",
|
|
|
|
msg ? msg : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-10-29 21:11:33 +00:00
|
|
|
static void* smi_mod_copy_cb(void* dest, const void* orig, size_t len _U_) {
|
2007-08-15 19:52:44 +00:00
|
|
|
const smi_module_t* m = orig;
|
|
|
|
smi_module_t* d = dest;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
d->name = g_strdup(m->name);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
return d;
|
2007-12-04 18:43:40 +00:00
|
|
|
}
|
2007-08-15 19:52:44 +00:00
|
|
|
|
|
|
|
static void smi_mod_free_cb(void* p) {
|
|
|
|
smi_module_t* m = p;
|
2009-03-13 22:06:48 +00:00
|
|
|
g_free(m->name);
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char* alnumerize(const char* name) {
|
|
|
|
char* s = g_strdup(name);
|
|
|
|
char* r = s;
|
|
|
|
char* w = r;
|
|
|
|
char c;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
for (;(c = *r); r++) {
|
|
|
|
if (isalnum(c) || c == '_' || c == '-' || c == '.') {
|
|
|
|
*(w++) = c;
|
|
|
|
} else if (c == ':' && r[1] == ':') {
|
|
|
|
*(w++) = '.';
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
*w = '\0';
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2009-10-18 20:13:06 +00:00
|
|
|
static const oid_value_type_t* get_typedata(SmiType* smiType) {
|
2007-08-28 23:55:49 +00:00
|
|
|
/*
|
|
|
|
* There has to be a better way to know if a given
|
|
|
|
* OCTETSTRING type is actually human readable text,
|
|
|
|
* an address of some type or some moe specific FT_
|
|
|
|
* Until that is found, this is the mappping between
|
2007-12-04 18:43:40 +00:00
|
|
|
* SNMP Types and our FT_s
|
2007-08-28 23:55:49 +00:00
|
|
|
*/
|
2007-08-22 22:56:36 +00:00
|
|
|
static const struct _type_mapping_t {
|
2011-06-16 17:17:55 +00:00
|
|
|
const char* name;
|
2007-08-22 22:56:36 +00:00
|
|
|
SmiBasetype base;
|
|
|
|
const oid_value_type_t* type;
|
|
|
|
} types[] = {
|
2007-08-19 23:00:47 +00:00
|
|
|
{"IpAddress", SMI_BASETYPE_UNKNOWN, &ipv4_type},
|
|
|
|
{"InetAddressIPv4",SMI_BASETYPE_UNKNOWN,&ipv4_type},
|
|
|
|
{"InetAddressIPv6",SMI_BASETYPE_UNKNOWN,&ipv6_type},
|
|
|
|
{"NetworkAddress",SMI_BASETYPE_UNKNOWN,&ipv4_type},
|
|
|
|
{"MacAddress",SMI_BASETYPE_UNKNOWN,ðer_type},
|
|
|
|
{"TimeTicks",SMI_BASETYPE_UNKNOWN,&timeticks_type},
|
|
|
|
{"Ipv6Address",SMI_BASETYPE_UNKNOWN,&ipv6_type},
|
2008-04-21 18:23:23 +00:00
|
|
|
{"TimeStamp",SMI_BASETYPE_UNKNOWN,&timeticks_type},
|
2007-08-19 23:00:47 +00:00
|
|
|
{"DisplayString",SMI_BASETYPE_UNKNOWN,&string_type},
|
2007-08-28 23:55:49 +00:00
|
|
|
{"SnmpAdminString",SMI_BASETYPE_UNKNOWN,&string_type},
|
2007-08-19 23:00:47 +00:00
|
|
|
{"DateAndTime",SMI_BASETYPE_UNKNOWN,&string_type},
|
2007-08-21 21:32:00 +00:00
|
|
|
{"Counter",SMI_BASETYPE_UNKNOWN,&counter32_type},
|
2007-08-19 23:00:47 +00:00
|
|
|
{"Counter32",SMI_BASETYPE_UNKNOWN,&counter32_type},
|
|
|
|
{"Unsigned32",SMI_BASETYPE_UNKNOWN,&unsigned32_type},
|
2007-08-21 21:32:00 +00:00
|
|
|
{"Gauge",SMI_BASETYPE_UNKNOWN,&unsigned32_type},
|
2007-08-19 23:00:47 +00:00
|
|
|
{"Gauge32",SMI_BASETYPE_UNKNOWN,&unsigned32_type},
|
2007-08-22 22:56:36 +00:00
|
|
|
{"NsapAddress",SMI_BASETYPE_UNKNOWN,&nsap_type},
|
2007-08-19 23:00:47 +00:00
|
|
|
{"i32",SMI_BASETYPE_INTEGER32,&integer_type},
|
|
|
|
{"octets",SMI_BASETYPE_OCTETSTRING,&bytes_type},
|
|
|
|
{"oid",SMI_BASETYPE_OBJECTIDENTIFIER,&oid_type},
|
|
|
|
{"u32",SMI_BASETYPE_UNSIGNED32,&unsigned32_type},
|
|
|
|
{"u64",SMI_BASETYPE_UNSIGNED64,&counter64_type},
|
|
|
|
{"f32",SMI_BASETYPE_FLOAT32,&float_type},
|
|
|
|
{"f64",SMI_BASETYPE_FLOAT64,&double_type},
|
|
|
|
{"f128",SMI_BASETYPE_FLOAT128,&bytes_type},
|
|
|
|
{"enum",SMI_BASETYPE_ENUM,&integer_type},
|
|
|
|
{"bits",SMI_BASETYPE_BITS,&bytes_type},
|
2007-08-21 21:32:00 +00:00
|
|
|
{"unk",SMI_BASETYPE_UNKNOWN,&unknown_type},
|
2007-08-19 23:00:47 +00:00
|
|
|
{NULL,0,NULL}
|
2007-08-16 06:48:51 +00:00
|
|
|
};
|
2007-08-22 22:56:36 +00:00
|
|
|
const struct _type_mapping_t* t;
|
2007-08-16 06:48:51 +00:00
|
|
|
SmiType* sT = smiType;
|
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
if (!smiType) return NULL;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-16 06:48:51 +00:00
|
|
|
do {
|
2007-08-19 23:00:47 +00:00
|
|
|
for (t = types; t->type ; t++ ) {
|
2008-03-05 20:55:56 +00:00
|
|
|
char* name = smiRenderType(sT, SMI_RENDER_NAME);
|
2007-08-19 23:00:47 +00:00
|
|
|
if (name && t->name && g_str_equal(name, t->name )) {
|
2008-03-19 21:09:31 +00:00
|
|
|
smi_free(name);
|
2007-08-19 23:00:47 +00:00
|
|
|
return t->type;
|
2007-08-16 06:48:51 +00:00
|
|
|
}
|
2008-03-05 20:55:56 +00:00
|
|
|
if (name) {
|
2008-03-19 21:09:31 +00:00
|
|
|
smi_free (name);
|
2008-03-05 20:55:56 +00:00
|
|
|
}
|
2007-08-16 06:48:51 +00:00
|
|
|
}
|
|
|
|
} while(( sT = smiGetParentType(sT) ));
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
for (t = types; t->type ; t++ ) {
|
|
|
|
if(smiType->basetype == t->base) {
|
|
|
|
return t->type;
|
2007-08-16 06:48:51 +00:00
|
|
|
}
|
|
|
|
}
|
2007-08-19 23:00:47 +00:00
|
|
|
|
|
|
|
return &unknown_type;
|
2007-08-16 06:48:51 +00:00
|
|
|
}
|
|
|
|
|
2007-08-25 23:49:09 +00:00
|
|
|
static guint get_non_implicit_size(SmiType* sT) {
|
2007-08-28 05:59:09 +00:00
|
|
|
SmiRange *sR;
|
|
|
|
guint size = 0xffffffff;
|
|
|
|
|
|
|
|
switch (sT->basetype) {
|
2007-08-25 23:49:09 +00:00
|
|
|
case SMI_BASETYPE_OCTETSTRING:
|
|
|
|
case SMI_BASETYPE_OBJECTIDENTIFIER:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
2007-08-28 05:59:09 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 23:49:09 +00:00
|
|
|
for ( ; sT; sT = smiGetParentType(sT) ) {
|
|
|
|
for (sR = smiGetFirstRange(sT); sR ; sR = smiGetNextRange(sR)) {
|
|
|
|
if (size == 0xffffffff) {
|
|
|
|
if (sR->minValue.value.unsigned32 == sR->maxValue.value.unsigned32) {
|
2012-12-26 05:57:06 +00:00
|
|
|
size = (guint32)sR->minValue.value.unsigned32;
|
2007-08-25 23:49:09 +00:00
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (sR->minValue.value.unsigned32 != size || sR->maxValue.value.unsigned32 != size) {
|
|
|
|
return 0;
|
2007-12-04 18:43:40 +00:00
|
|
|
}
|
2007-08-25 23:49:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 23:49:09 +00:00
|
|
|
return size == 0xffffffff ? 0 : size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
static inline oid_kind_t smikind(SmiNode* sN, oid_key_t** key_p) {
|
|
|
|
*key_p = NULL;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
switch(sN->nodekind) {
|
|
|
|
case SMI_NODEKIND_ROW: {
|
|
|
|
SmiElement* sE;
|
|
|
|
oid_key_t* kl = NULL;
|
2007-08-24 00:26:30 +00:00
|
|
|
const oid_value_type_t* typedata = NULL;
|
2007-09-13 16:49:51 +00:00
|
|
|
gboolean implied;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
switch (sN->indexkind) {
|
|
|
|
case SMI_INDEX_INDEX:
|
|
|
|
break;
|
|
|
|
case SMI_INDEX_AUGMENT:
|
|
|
|
case SMI_INDEX_REORDER:
|
|
|
|
case SMI_INDEX_SPARSE:
|
|
|
|
case SMI_INDEX_EXPAND:
|
2007-09-13 16:49:51 +00:00
|
|
|
sN = smiGetRelatedNode(sN);
|
|
|
|
break;
|
|
|
|
case SMI_INDEX_UNKNOWN:
|
2007-08-22 22:56:36 +00:00
|
|
|
return OID_KIND_UNKNOWN;
|
|
|
|
};
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-09-13 16:49:51 +00:00
|
|
|
implied = sN->implied;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
for (sE = smiGetFirstElement(sN); sE; sE = smiGetNextElement(sE)) {
|
|
|
|
SmiNode* elNode = smiGetElementNode(sE) ;
|
|
|
|
SmiType* elType = smiGetNodeType(elNode);
|
|
|
|
oid_key_t* k;
|
2007-08-25 01:14:24 +00:00
|
|
|
guint non_implicit_size = 0;
|
2008-03-05 20:55:56 +00:00
|
|
|
char *oid1, *oid2;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
if (elType) {
|
2007-08-25 23:49:09 +00:00
|
|
|
non_implicit_size = get_non_implicit_size(elType);
|
2007-08-25 01:14:24 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-24 00:26:30 +00:00
|
|
|
typedata = get_typedata(elType);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
k = g_malloc(sizeof(oid_key_t));
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2008-03-05 20:55:56 +00:00
|
|
|
oid1 = smiRenderOID(sN->oidlen, sN->oid, SMI_RENDER_QUALIFIED);
|
|
|
|
oid2 = smiRenderOID(elNode->oidlen, elNode->oid, SMI_RENDER_NAME);
|
|
|
|
k->name = g_strdup_printf("%s.%s", oid1, oid2);
|
2008-03-19 21:09:31 +00:00
|
|
|
smi_free (oid1);
|
|
|
|
smi_free (oid2);
|
2008-03-17 17:06:33 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
k->hfid = -2;
|
|
|
|
k->ft_type = typedata ? typedata->ft_type : FT_BYTES;
|
2007-08-23 19:45:31 +00:00
|
|
|
k->display = typedata ? typedata->display : BASE_NONE;
|
2007-08-22 22:56:36 +00:00
|
|
|
k->next = NULL;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
if (typedata) {
|
2007-08-24 00:26:30 +00:00
|
|
|
k->key_type = typedata->keytype;
|
2007-08-22 22:56:36 +00:00
|
|
|
k->num_subids = typedata->keysize;
|
|
|
|
} else {
|
|
|
|
if (elType) {
|
|
|
|
switch (elType->basetype) {
|
|
|
|
case SMI_BASETYPE_BITS:
|
2007-08-25 01:14:24 +00:00
|
|
|
case SMI_BASETYPE_OCTETSTRING: {
|
2007-08-24 00:26:30 +00:00
|
|
|
k->key_type = OID_KEY_TYPE_BYTES;
|
2007-12-04 18:43:40 +00:00
|
|
|
k->num_subids = non_implicit_size;
|
2007-08-22 22:56:36 +00:00
|
|
|
break;
|
2007-12-04 18:43:40 +00:00
|
|
|
}
|
2007-08-22 22:56:36 +00:00
|
|
|
case SMI_BASETYPE_ENUM:
|
|
|
|
case SMI_BASETYPE_OBJECTIDENTIFIER:
|
|
|
|
case SMI_BASETYPE_INTEGER32:
|
|
|
|
case SMI_BASETYPE_UNSIGNED32:
|
|
|
|
case SMI_BASETYPE_INTEGER64:
|
|
|
|
case SMI_BASETYPE_UNSIGNED64:
|
|
|
|
k->key_type = OID_KEY_TYPE_INTEGER;
|
|
|
|
k->num_subids = 1;
|
|
|
|
break;
|
2007-12-04 18:43:40 +00:00
|
|
|
default:
|
2007-08-22 22:56:36 +00:00
|
|
|
k->key_type = OID_KEY_TYPE_WRONG;
|
|
|
|
k->num_subids = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
k->key_type = OID_KEY_TYPE_WRONG;
|
|
|
|
k->num_subids = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
if (!*key_p) *key_p = k;
|
|
|
|
if (kl) kl->next = k;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
kl = k;
|
|
|
|
}
|
2007-08-27 17:05:11 +00:00
|
|
|
|
2009-09-29 06:52:51 +00:00
|
|
|
if (implied && kl) {
|
2007-08-28 23:55:49 +00:00
|
|
|
switch (kl->key_type) {
|
2007-09-13 16:49:51 +00:00
|
|
|
case OID_KEY_TYPE_BYTES: kl->key_type = OID_KEY_TYPE_IMPLIED_BYTES; break;
|
|
|
|
case OID_KEY_TYPE_STRING: kl->key_type = OID_KEY_TYPE_IMPLIED_STRING; break;
|
|
|
|
case OID_KEY_TYPE_OID: kl->key_type = OID_KEY_TYPE_IMPLIED_OID; break;
|
|
|
|
default: break;
|
2007-08-24 00:26:30 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-13 16:49:51 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
return OID_KIND_ROW;
|
|
|
|
}
|
|
|
|
case SMI_NODEKIND_NODE: return OID_KIND_NODE;
|
|
|
|
case SMI_NODEKIND_SCALAR: return OID_KIND_SCALAR;
|
|
|
|
case SMI_NODEKIND_TABLE: return OID_KIND_TABLE;
|
|
|
|
case SMI_NODEKIND_COLUMN: return OID_KIND_COLUMN;
|
|
|
|
case SMI_NODEKIND_NOTIFICATION: return OID_KIND_NOTIFICATION;
|
|
|
|
case SMI_NODEKIND_GROUP: return OID_KIND_GROUP;
|
|
|
|
case SMI_NODEKIND_COMPLIANCE: return OID_KIND_COMPLIANCE;
|
|
|
|
case SMI_NODEKIND_CAPABILITIES: return OID_KIND_CAPABILITIES;
|
|
|
|
default: return OID_KIND_UNKNOWN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
#define IS_ENUMABLE(ft) ( (ft == FT_UINT8) || (ft == FT_UINT16) || (ft == FT_UINT24) || (ft == FT_UINT32) \
|
2007-08-15 19:52:44 +00:00
|
|
|
|| (ft == FT_INT8) || (ft == FT_INT16) || (ft == FT_INT24) || (ft == FT_INT32) \
|
2007-08-21 21:32:00 +00:00
|
|
|
|| (ft == FT_UINT64) || (ft == FT_INT64) )
|
2007-08-15 19:52:44 +00:00
|
|
|
|
2010-03-03 17:19:30 +00:00
|
|
|
static void unregister_mibs(void) {
|
|
|
|
/* TODO: Unregister "MIBs" proto and clean up field array and subtree array.
|
|
|
|
* Wireshark does not support that yet. :-( */
|
|
|
|
|
|
|
|
/* smiExit(); */
|
|
|
|
}
|
|
|
|
|
2010-03-05 19:33:07 +00:00
|
|
|
static void restart_needed_warning(void) {
|
|
|
|
if (oids_init_done)
|
|
|
|
report_failure("Wireshark needs to be restarted for these changes to take effect");
|
|
|
|
}
|
|
|
|
|
2011-05-17 21:28:07 +00:00
|
|
|
static void register_mibs(void) {
|
2007-08-15 19:52:44 +00:00
|
|
|
SmiModule *smiModule;
|
2007-08-28 05:59:09 +00:00
|
|
|
SmiNode *smiNode;
|
2007-08-15 19:52:44 +00:00
|
|
|
guint i;
|
2007-08-21 21:32:00 +00:00
|
|
|
int proto_mibs = -1;
|
2007-08-15 19:52:44 +00:00
|
|
|
GArray* hfa = g_array_new(FALSE,TRUE,sizeof(hf_register_info));
|
|
|
|
GArray* etta = g_array_new(FALSE,TRUE,sizeof(gint*));
|
2007-12-04 18:43:40 +00:00
|
|
|
gchar* path_str;
|
|
|
|
|
2012-07-06 04:48:36 +00:00
|
|
|
if (!load_smi_modules) {
|
2010-03-03 17:19:30 +00:00
|
|
|
D(1,("OID resolution not enabled"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TODO: Remove this workaround when unregistration of "MIBs" proto is solved.
|
|
|
|
* Wireshark does not support that yet. :-( */
|
|
|
|
if (oids_init_done) {
|
|
|
|
D(1,("Exiting register_mibs() to avoid double registration of MIBs proto."));
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
oids_init_done = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
smiInit(NULL);
|
|
|
|
|
2009-11-13 17:55:55 +00:00
|
|
|
smi_errors = g_string_new("");
|
|
|
|
smiSetErrorHandler(smi_error_handler);
|
|
|
|
|
2007-12-04 18:43:40 +00:00
|
|
|
path_str = oid_get_default_mib_path();
|
|
|
|
D(1,("SMI Path: '%s'",path_str));
|
|
|
|
|
|
|
|
smiSetPath(path_str);
|
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
for(i=0;i<num_smi_modules;i++) {
|
|
|
|
if (!smi_modules[i].name) continue;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
if (smiIsLoaded(smi_modules[i].name)) {
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
char* mod_name = smiLoadModule(smi_modules[i].name);
|
2007-12-04 18:43:40 +00:00
|
|
|
if (mod_name)
|
2007-08-22 22:56:36 +00:00
|
|
|
D(2,("Loaded: '%s'[%d] as %s",smi_modules[i].name,i,mod_name ));
|
2007-12-04 18:43:40 +00:00
|
|
|
else
|
2007-08-22 22:56:36 +00:00
|
|
|
D(1,("Failed to load: '%s'[%d]",smi_modules[i].name,i));
|
2007-08-21 21:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-28 19:07:39 +00:00
|
|
|
if (smi_errors->len) {
|
2012-07-06 04:48:36 +00:00
|
|
|
if (!suppress_smi_errors) {
|
2010-03-03 17:19:30 +00:00
|
|
|
report_failure("The following errors were found while loading the MIBS:\n%s\n\n"
|
2009-12-12 01:41:32 +00:00
|
|
|
"The Current Path is: %s\n\nYou can avoid this error message "
|
|
|
|
"by removing the missing MIB modules at Edit -> Preferences"
|
|
|
|
" -> Name Resolution -> SMI (MIB and PIB) modules or by "
|
|
|
|
"installing them.\n" , smi_errors->str , path_str);
|
2010-03-03 17:19:30 +00:00
|
|
|
}
|
2007-08-28 19:07:39 +00:00
|
|
|
D(1,("Errors while loading:\n%s\n",smi_errors->str));
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
|
|
|
g_free(path_str);
|
2007-08-28 19:07:39 +00:00
|
|
|
g_string_free(smi_errors,TRUE);
|
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
for (smiModule = smiGetFirstModule();
|
|
|
|
smiModule;
|
|
|
|
smiModule = smiGetNextModule(smiModule)) {
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
D(3,("\tModule: %s", smiModule->name));
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2010-02-25 19:28:58 +00:00
|
|
|
/* TODO: Check libsmi version at compile time and disable this
|
|
|
|
* workaround for libsmi versions where this problem is fixed.
|
|
|
|
* Currently there is no such version. :-(
|
|
|
|
*/
|
2010-09-29 15:46:35 +00:00
|
|
|
if (smiModule->conformance == 1) {
|
2012-07-06 04:48:36 +00:00
|
|
|
if (!suppress_smi_errors) {
|
2010-03-03 17:19:30 +00:00
|
|
|
report_failure("Stopped processing module %s due to "
|
|
|
|
"error(s) to prevent potential crash in libsmi.\n"
|
|
|
|
"Module's conformance level: %d.\n"
|
|
|
|
"See details at: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=560325\n",
|
|
|
|
smiModule->name, smiModule->conformance);
|
|
|
|
}
|
2010-02-25 19:28:58 +00:00
|
|
|
continue;
|
2010-09-29 15:46:35 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
for (smiNode = smiGetFirstNode(smiModule, SMI_NODEKIND_ANY);
|
2007-08-15 19:52:44 +00:00
|
|
|
smiNode;
|
|
|
|
smiNode = smiGetNextNode(smiNode, SMI_NODEKIND_ANY)) {
|
2007-08-22 22:56:36 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
SmiType* smiType = smiGetNodeType(smiNode);
|
2007-08-19 23:00:47 +00:00
|
|
|
const oid_value_type_t* typedata = get_typedata(smiType);
|
2007-08-22 22:56:36 +00:00
|
|
|
oid_key_t* key;
|
|
|
|
oid_kind_t kind = smikind(smiNode,&key);
|
2008-03-05 20:55:56 +00:00
|
|
|
char *oid = smiRenderOID(smiNode->oidlen, smiNode->oid, SMI_RENDER_QUALIFIED);
|
|
|
|
oid_info_t* oid_data = add_oid(oid,
|
|
|
|
kind,
|
|
|
|
typedata,
|
|
|
|
key,
|
|
|
|
smiNode->oidlen,
|
|
|
|
smiNode->oid);
|
2008-03-19 21:09:31 +00:00
|
|
|
smi_free (oid);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-24 00:26:30 +00:00
|
|
|
D(4,("\t\tNode: kind=%d oid=%s name=%s ",
|
|
|
|
oid_data->kind, oid_subid2string(smiNode->oid, smiNode->oidlen), oid_data->name ));
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
if ( typedata && oid_data->value_hfid == -2 ) {
|
2007-12-04 18:43:40 +00:00
|
|
|
SmiNamedNumber* smiEnum;
|
|
|
|
hf_register_info hf = { &(oid_data->value_hfid), {
|
2007-08-19 23:00:47 +00:00
|
|
|
oid_data->name,
|
|
|
|
alnumerize(oid_data->name),
|
|
|
|
typedata->ft_type,
|
|
|
|
typedata->display,
|
|
|
|
NULL,
|
|
|
|
0,
|
2008-03-05 20:55:56 +00:00
|
|
|
smiRenderOID(smiNode->oidlen, smiNode->oid, SMI_RENDER_ALL),
|
2007-08-19 23:00:47 +00:00
|
|
|
HFILL }};
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2009-07-08 08:00:55 +00:00
|
|
|
/* Don't allow duplicate blurb/name */
|
|
|
|
if (strcmp(hf.hfinfo.blurb, hf.hfinfo.name) == 0) {
|
|
|
|
smi_free((void *) hf.hfinfo.blurb);
|
|
|
|
hf.hfinfo.blurb = NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
oid_data->value_hfid = -1;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
if ( IS_ENUMABLE(hf.hfinfo.type) && (smiEnum = smiGetFirstNamedNumber(smiType))) {
|
|
|
|
GArray* vals = g_array_new(TRUE,TRUE,sizeof(value_string));
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
for(;smiEnum; smiEnum = smiGetNextNamedNumber(smiEnum)) {
|
|
|
|
if (smiEnum->name) {
|
2012-12-26 05:57:06 +00:00
|
|
|
value_string val = {(guint32)smiEnum->value.value.integer32,g_strdup(smiEnum->name)};
|
2007-08-15 19:52:44 +00:00
|
|
|
g_array_append_val(vals,val);
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2011-04-25 16:19:07 +00:00
|
|
|
hf.hfinfo.strings = vals->data;
|
2007-08-15 19:52:44 +00:00
|
|
|
g_array_free(vals,FALSE);
|
2007-08-21 21:32:00 +00:00
|
|
|
}
|
2008-03-19 21:09:31 +00:00
|
|
|
#if 0 /* packet-snmp does not handle bits yet */
|
2007-08-22 22:56:36 +00:00
|
|
|
} else if (smiType->basetype == SMI_BASETYPE_BITS && ( smiEnum = smiGetFirstNamedNumber(smiType) )) {
|
|
|
|
guint n = 0;
|
|
|
|
oid_bits_info_t* bits = g_malloc(sizeof(oid_bits_info_t));
|
|
|
|
gint* ettp = &(bits->ett);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
bits->num = 0;
|
|
|
|
bits->ett = -1;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
g_array_append_val(etta,ettp);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
for(;smiEnum; smiEnum = smiGetNextNamedNumber(smiEnum), bits->num++);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
bits->data = g_malloc(sizeof(struct _oid_bit_t)*bits->num);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
for(smiEnum = smiGetFirstNamedNumber(smiType),n=0;
|
|
|
|
smiEnum;
|
|
|
|
smiEnum = smiGetNextNamedNumber(smiEnum),n++) {
|
|
|
|
guint mask = 1 << (smiEnum->value.value.integer32 % 8);
|
|
|
|
char* base = alnumerize(oid_data->name);
|
|
|
|
char* ext = alnumerize(smiEnum->name);
|
2009-06-24 02:17:12 +00:00
|
|
|
hf_register_info hf2 = { &(bits->data[n].hfid), { NULL, NULL, FT_UINT8, BASE_HEX, NULL, mask, NULL, HFILL }};
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
bits->data[n].hfid = -1;
|
|
|
|
bits->data[n].offset = smiEnum->value.value.integer32 / 8;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
hf2.hfinfo.name = g_strdup_printf("%s:%s",oid_data->name,smiEnum->name);
|
|
|
|
hf2.hfinfo.abbrev = g_strdup_printf("%s.%s",base,ext);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
g_free(base);
|
|
|
|
g_free(ext);
|
|
|
|
g_array_append_val(hfa,hf2);
|
|
|
|
}
|
|
|
|
#endif /* packet-snmp does not use this yet */
|
|
|
|
g_array_append_val(hfa,hf);
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
if ((key = oid_data->key)) {
|
2007-12-04 18:43:40 +00:00
|
|
|
for(; key; key = key->next) {
|
|
|
|
hf_register_info hf = { &(key->hfid), {
|
2007-08-22 22:56:36 +00:00
|
|
|
key->name,
|
|
|
|
alnumerize(key->name),
|
|
|
|
key->ft_type,
|
|
|
|
key->display,
|
|
|
|
NULL,
|
|
|
|
0,
|
2009-06-24 02:17:12 +00:00
|
|
|
NULL,
|
2007-08-22 22:56:36 +00:00
|
|
|
HFILL }};
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
D(5,("\t\t\tIndex: name=%s subids=%d key_type=%d",
|
|
|
|
key->name, key->num_subids, key->key_type ));
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-22 22:56:36 +00:00
|
|
|
if (key->hfid == -2) {
|
|
|
|
g_array_append_val(hfa,hf);
|
|
|
|
key->hfid = -1;
|
|
|
|
} else {
|
|
|
|
g_free((void*)hf.hfinfo.abbrev);
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
proto_mibs = proto_register_protocol("MIBs", "MIBS", "mibs");
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2011-04-25 16:29:16 +00:00
|
|
|
proto_register_field_array(proto_mibs, (hf_register_info*)(void*)hfa->data, hfa->len);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2011-04-25 16:29:16 +00:00
|
|
|
proto_register_subtree_array((gint**)(void*)etta->data, etta->len);
|
2007-08-21 21:32:00 +00:00
|
|
|
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
g_array_free(etta,TRUE);
|
2007-08-15 19:52:44 +00:00
|
|
|
g_array_free(hfa,FALSE);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-06 04:48:36 +00:00
|
|
|
void oid_pref_init(module_t *nameres)
|
|
|
|
{
|
2012-07-06 07:24:22 +00:00
|
|
|
#ifdef HAVE_LIBSMI
|
2012-07-06 04:48:36 +00:00
|
|
|
static uat_field_t smi_fields[] = {
|
|
|
|
UAT_FLD_CSTRING(smi_mod,name,"Module name","The module's name"),
|
|
|
|
UAT_END_FIELDS
|
|
|
|
};
|
|
|
|
static uat_field_t smi_paths_fields[] = {
|
|
|
|
UAT_FLD_DIRECTORYNAME(smi_mod,name,"Directory path","The directory name"),
|
|
|
|
UAT_END_FIELDS
|
|
|
|
};
|
|
|
|
|
|
|
|
prefs_register_bool_preference(nameres, "load_smi_modules",
|
|
|
|
"Enable OID resolution",
|
|
|
|
"You must restart Wireshark for this change to take effect",
|
|
|
|
&load_smi_modules);
|
|
|
|
|
|
|
|
prefs_register_bool_preference(nameres, "suppress_smi_errors",
|
|
|
|
"Suppress SMI errors",
|
|
|
|
"Some errors can be ignored. If unsure, set to false.",
|
|
|
|
&suppress_smi_errors);
|
|
|
|
|
UATs could be put into "categories". The categories were defined only
implicitly by the #define name and string they were defined to; not all
UATs neatly fit into any of the categories, so some of them were put
into categories that weren't obviously correct for them, and one - the
display filter macro UAT - wasn't put into any category at all (which
caused crashes when editing them, as the GUI code that handled UAT
changes from a dialog assumed the category field was non-null).
The category was, in practice, used only to decide, in the
aforementioned GUI code, whether the packet summary pane needed to be
updated or not. It also offered no option of "don't update the packet
summary pane *and* don't redissect anything", which is what would be
appropriate for the display filter macro UAT.
Replace the category with a set of fields indicating what the UAT
affects; we currently offer "dissection", which applies to most UATs
(any UAT in libwireshark presumably affects dissection at a minimum) and
"the set of named fields that exist". Changing any UAT that affects
dissection requires a redissection; changing any UAT that affects the
set of named fields that exist requires a redissection *and* rebuilding
the packet summary pane.
Perhaps we also need "filtering", so that if you change a display filter
macro, we re-filter, in case the display is currently filtered with a
display filter that uses a macro that changed.
svn path=/trunk/; revision=43603
2012-07-08 01:00:46 +00:00
|
|
|
smi_paths_uat = uat_new("SMI Paths",
|
|
|
|
sizeof(smi_module_t),
|
|
|
|
"smi_paths",
|
|
|
|
FALSE,
|
|
|
|
(void*)&smi_paths,
|
|
|
|
&num_smi_paths,
|
|
|
|
/* affects dissection of packets (as the MIBs and PIBs affect the
|
|
|
|
interpretation of e.g. SNMP variable bindings), but not set of
|
|
|
|
named fields
|
|
|
|
|
|
|
|
XXX - if named fields are generated from the MIBs and PIBs
|
|
|
|
for particular variable bindings, this *does* affect the set
|
|
|
|
of named fields! */
|
|
|
|
UAT_AFFECTS_DISSECTION,
|
|
|
|
"ChSNMPSMIPaths",
|
|
|
|
smi_mod_copy_cb,
|
|
|
|
NULL,
|
|
|
|
smi_mod_free_cb,
|
|
|
|
restart_needed_warning,
|
|
|
|
smi_paths_fields);
|
|
|
|
|
|
|
|
prefs_register_uat_preference(nameres,
|
|
|
|
"smi_paths",
|
|
|
|
"SMI (MIB and PIB) paths",
|
|
|
|
"Search paths for SMI (MIB and PIB) modules. You must\n"
|
|
|
|
"restart Wireshark for these changes to take effect.",
|
|
|
|
smi_paths_uat);
|
|
|
|
|
|
|
|
smi_modules_uat = uat_new("SMI Modules",
|
|
|
|
sizeof(smi_module_t),
|
|
|
|
"smi_modules",
|
|
|
|
FALSE,
|
|
|
|
(void*)&smi_modules,
|
|
|
|
&num_smi_modules,
|
|
|
|
/* affects dissection of packets (as the MIBs and PIBs affect the
|
|
|
|
interpretation of e.g. SNMP variable bindings), but not set of
|
|
|
|
named fields
|
|
|
|
|
|
|
|
XXX - if named fields are generated from the MIBs and PIBs
|
|
|
|
for particular variable bindings, would this affect the set
|
|
|
|
of named fields? */
|
|
|
|
UAT_AFFECTS_DISSECTION,
|
|
|
|
"ChSNMPSMIModules",
|
|
|
|
smi_mod_copy_cb,
|
|
|
|
NULL,
|
|
|
|
smi_mod_free_cb,
|
|
|
|
restart_needed_warning,
|
|
|
|
smi_fields);
|
|
|
|
|
|
|
|
prefs_register_uat_preference(nameres,
|
|
|
|
"smi_modules",
|
|
|
|
"SMI (MIB and PIB) modules",
|
|
|
|
"List of enabled SMI (MIB and PIB) modules. You must\n"
|
|
|
|
"restart Wireshark for these changes to take effect.",
|
|
|
|
smi_modules_uat);
|
2012-07-06 04:48:36 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
prefs_register_static_text_preference(nameres, "load_smi_modules_static",
|
|
|
|
"Enable OID resolution: N/A",
|
2012-07-08 01:31:48 +00:00
|
|
|
"Support for OID resolution was not compiled into this version of Wireshark");
|
2012-07-06 04:48:36 +00:00
|
|
|
|
|
|
|
prefs_register_static_text_preference(nameres, "suppress_smi_errors_static",
|
|
|
|
"Suppress SMI errors: N/A",
|
2012-07-08 01:31:48 +00:00
|
|
|
"Support for OID resolution was not compiled into this version of Wireshark");
|
2012-07-06 04:48:36 +00:00
|
|
|
|
|
|
|
prefs_register_static_text_preference(nameres, "smi_module_path",
|
|
|
|
"SMI (MIB and PIB) modules and paths: N/A",
|
2012-07-08 01:31:48 +00:00
|
|
|
"Support for OID resolution was not compiled into this version of Wireshark");
|
2012-07-06 04:48:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
2007-08-15 19:52:44 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
void oids_init(void) {
|
2007-08-25 20:27:58 +00:00
|
|
|
#ifdef HAVE_LIBSMI
|
2007-08-15 19:52:44 +00:00
|
|
|
register_mibs();
|
2007-08-25 01:14:24 +00:00
|
|
|
#else
|
|
|
|
D(1,("libsmi disabled oid resolution not enabled"));
|
2007-08-15 19:52:44 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2010-03-03 17:19:30 +00:00
|
|
|
void oids_cleanup(void) {
|
|
|
|
#ifdef HAVE_LIBSMI
|
2012-07-06 07:24:22 +00:00
|
|
|
unregister_mibs();
|
2010-03-03 17:19:30 +00:00
|
|
|
#else
|
2012-07-06 07:24:22 +00:00
|
|
|
D(1,("libsmi disabled oid resolution not enabled"));
|
2010-03-03 17:19:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
const char* oid_subid2string(guint32* subids, guint len) {
|
2007-08-27 19:14:30 +00:00
|
|
|
char* s = ep_alloc0(((len)*11)+1);
|
2007-08-19 23:00:47 +00:00
|
|
|
char* w = s;
|
2007-08-27 19:14:30 +00:00
|
|
|
|
2007-08-27 21:29:20 +00:00
|
|
|
if(!subids)
|
|
|
|
return "*** Empty OID ***";
|
2007-08-25 17:29:55 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
do {
|
2009-03-17 15:34:18 +00:00
|
|
|
w += g_snprintf(w,12,"%u.",*subids++);
|
2007-08-15 19:52:44 +00:00
|
|
|
} while(--len);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-27 19:14:30 +00:00
|
|
|
if (w!=s) *(w-1) = '\0'; else *(s) = '\0';
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2011-05-17 23:33:23 +00:00
|
|
|
static guint check_num_oid(const char* str) {
|
2007-08-15 19:52:44 +00:00
|
|
|
const char* r = str;
|
2013-01-14 07:43:14 +00:00
|
|
|
char c = '.';
|
2007-08-15 19:52:44 +00:00
|
|
|
guint n = 0;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
D(8,("check_num_oid: '%s'",str));
|
2013-01-14 07:43:14 +00:00
|
|
|
if (!r) return 0;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
do {
|
2007-08-25 01:14:24 +00:00
|
|
|
D(9,("\tcheck_num_oid: '%c' %d",*r,n));
|
|
|
|
switch(*r) {
|
2013-01-14 07:43:14 +00:00
|
|
|
case '.': case '\0':
|
2007-08-15 19:52:44 +00:00
|
|
|
n++;
|
2007-12-04 18:43:40 +00:00
|
|
|
if (c == '.') return 0;
|
2013-01-14 07:43:14 +00:00
|
|
|
break;
|
2007-12-04 18:43:40 +00:00
|
|
|
case '1' : case '2' : case '3' : case '4' : case '5' :
|
2007-08-19 23:00:47 +00:00
|
|
|
case '6' : case '7' : case '8' : case '9' : case '0' :
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
return 0;
|
2007-12-04 18:43:40 +00:00
|
|
|
}
|
2007-08-25 01:14:24 +00:00
|
|
|
} while((c = *r++));
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint oid_string2subid(const char* str, guint32** subids_p) {
|
|
|
|
const char* r = str;
|
|
|
|
guint32* subids;
|
2007-08-25 14:15:56 +00:00
|
|
|
guint32* subids_overflow;
|
2007-08-19 23:00:47 +00:00
|
|
|
guint n = check_num_oid(str);
|
2007-08-27 19:14:30 +00:00
|
|
|
/*
|
|
|
|
* we cannot handle sub-ids greater than 32bytes
|
2007-12-04 18:43:40 +00:00
|
|
|
* keep a pilot subid of 64 bytes to check the limit
|
2007-08-27 19:14:30 +00:00
|
|
|
*/
|
|
|
|
guint64 subid = 0;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
D(6,("oid_string2subid: str='%s'",str));
|
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
if (!n) {
|
|
|
|
*subids_p = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-08-25 01:14:24 +00:00
|
|
|
|
2007-08-25 14:15:56 +00:00
|
|
|
*subids_p = subids = ep_alloc0(sizeof(guint32)*n);
|
|
|
|
subids_overflow = subids + n;
|
2007-08-15 19:52:44 +00:00
|
|
|
do switch(*r) {
|
|
|
|
case '.':
|
2007-08-27 19:14:30 +00:00
|
|
|
subid = 0;
|
2007-08-15 19:52:44 +00:00
|
|
|
subids++;
|
|
|
|
continue;
|
2007-12-04 18:43:40 +00:00
|
|
|
case '1' : case '2' : case '3' : case '4' : case '5' :
|
2007-08-15 19:52:44 +00:00
|
|
|
case '6' : case '7' : case '8' : case '9' : case '0' :
|
2007-08-27 19:14:30 +00:00
|
|
|
subid *= 10;
|
|
|
|
subid += *r - '0';
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-27 21:29:20 +00:00
|
|
|
if( subids >= subids_overflow || subid > 0xffffffff) {
|
|
|
|
*subids_p=NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
*(subids) *= 10;
|
|
|
|
*(subids) += *r - '0';
|
|
|
|
continue;
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
2007-08-25 01:14:24 +00:00
|
|
|
} while(*r++);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
guint oid_encoded2subid(const guint8 *oid_bytes, gint oid_len, guint32** subids_p) {
|
|
|
|
gint i;
|
|
|
|
guint n = 1;
|
|
|
|
gboolean is_first = TRUE;
|
|
|
|
guint32* subids;
|
2007-08-25 14:15:56 +00:00
|
|
|
guint32* subid_overflow;
|
2007-08-27 19:14:30 +00:00
|
|
|
/*
|
|
|
|
* we cannot handle sub-ids greater than 32bytes
|
2007-12-04 18:43:40 +00:00
|
|
|
* have the subid in 64 bytes to be able to check the limit
|
2007-08-27 19:14:30 +00:00
|
|
|
*/
|
|
|
|
guint64 subid = 0;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
for (i=0; i<oid_len; i++) { if (! (oid_bytes[i] & 0x80 )) n++; }
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
*subids_p = subids = ep_alloc(sizeof(guint32)*n);
|
2007-08-25 14:15:56 +00:00
|
|
|
subid_overflow = subids+n;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2012-08-12 21:04:39 +00:00
|
|
|
/* If n is 1 then we found no bytes in the OID with first bit cleared,
|
|
|
|
* so initialize our one byte to zero and return. This *seems* to be
|
|
|
|
* the right thing to do in this situation, and at the very least it
|
|
|
|
* avoids uninitialized memory errors that would otherwise occur. */
|
|
|
|
if (n == 1) {
|
|
|
|
*subids = 0;
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
for (i=0; i<oid_len; i++){
|
|
|
|
guint8 byte = oid_bytes[i];
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
subid <<= 7;
|
|
|
|
subid |= byte & 0x7F;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
if (byte & 0x80) {
|
|
|
|
continue;
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
if (is_first) {
|
|
|
|
guint32 subid0 = 0;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
if (subid >= 40) { subid0++; subid-=40; }
|
|
|
|
if (subid >= 40) { subid0++; subid-=40; }
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
*subids++ = subid0;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
is_first = FALSE;
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-27 21:29:20 +00:00
|
|
|
if( subids >= subid_overflow || subid > 0xffffffff) {
|
|
|
|
*subids_p=NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-27 19:37:48 +00:00
|
|
|
*subids++ = (guint32)subid;
|
2007-08-15 19:52:44 +00:00
|
|
|
subid = 0;
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
oid_info_t* oid_get(guint len, guint32* subids, guint* matched, guint* left) {
|
|
|
|
oid_info_t* curr_oid = &oid_root;
|
|
|
|
guint i;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-27 21:29:20 +00:00
|
|
|
if(!(subids && *subids <= 2)) {
|
|
|
|
*matched = 0;
|
|
|
|
*left = len;
|
|
|
|
return curr_oid;
|
|
|
|
}
|
2007-08-25 17:29:55 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
for( i=0; i < len; i++) {
|
|
|
|
oid_info_t* next_oid = emem_tree_lookup32(curr_oid->children,subids[i]);
|
|
|
|
if (next_oid) {
|
|
|
|
curr_oid = next_oid;
|
|
|
|
} else {
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done:
|
|
|
|
*matched = i;
|
|
|
|
*left = len - i;
|
|
|
|
return curr_oid;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
oid_info_t* oid_get_from_encoded(const guint8 *bytes, gint byteslen, guint32** subids_p, guint* matched_p, guint* left_p) {
|
2007-08-27 17:05:11 +00:00
|
|
|
guint subids_len = oid_encoded2subid(bytes, byteslen, subids_p);
|
|
|
|
return oid_get(subids_len, *subids_p, matched_p, left_p);
|
2007-12-04 18:43:40 +00:00
|
|
|
}
|
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
oid_info_t* oid_get_from_string(const gchar *oid_str, guint32** subids_p, guint* matched, guint* left) {
|
2007-08-27 17:05:11 +00:00
|
|
|
guint subids_len = oid_string2subid(oid_str, subids_p);
|
|
|
|
return oid_get(subids_len, *subids_p, matched, left);
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *oid_resolved_from_encoded(const guint8 *oid, gint oid_len) {
|
|
|
|
guint32 *subid_oid;
|
|
|
|
guint subid_oid_length = oid_encoded2subid(oid, oid_len, &subid_oid);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
return oid_resolved(subid_oid_length, subid_oid);
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
guint oid_subid2encoded(guint subids_len, guint32* subids, guint8** bytes_p) {
|
|
|
|
guint bytelen = 0;
|
|
|
|
guint i;
|
|
|
|
guint32 subid;
|
|
|
|
guint8* b;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-09-13 16:49:51 +00:00
|
|
|
if ( !subids || subids_len <= 0) {
|
2007-08-19 23:00:47 +00:00
|
|
|
*bytes_p = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
subid = (subids[0] * 40) + subids[1];
|
|
|
|
i = 2;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
do {
|
|
|
|
if (subid <= 0x0000007F) {
|
|
|
|
bytelen += 1;
|
|
|
|
} else if (subid <= 0x00003FFF ) {
|
2007-08-15 19:52:44 +00:00
|
|
|
bytelen += 2;
|
2007-08-19 23:00:47 +00:00
|
|
|
} else if (subid <= 0x001FFFFF ) {
|
|
|
|
bytelen += 3;
|
|
|
|
} else if (subid <= 0x0FFFFFFF ) {
|
|
|
|
bytelen += 4;
|
2007-08-15 19:52:44 +00:00
|
|
|
} else {
|
2007-08-19 23:00:47 +00:00
|
|
|
bytelen += 5;
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
subid = subids[i];
|
|
|
|
} while ( i++ < subids_len );
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2009-09-29 19:16:00 +00:00
|
|
|
*bytes_p = b = ep_alloc(bytelen);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
subid = (subids[0] * 40) + subids[1];
|
|
|
|
i = 2;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
do {
|
|
|
|
guint len;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
if ((subid <= 0x0000007F )) len = 1;
|
|
|
|
else if ((subid <= 0x00003FFF )) len = 2;
|
|
|
|
else if ((subid <= 0x001FFFFF )) len = 3;
|
|
|
|
else if ((subid <= 0x0FFFFFFF )) len = 4;
|
|
|
|
else len = 5;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
switch(len) {
|
2007-08-27 21:29:20 +00:00
|
|
|
default: *bytes_p=NULL; return 0;
|
2011-03-21 18:58:48 +00:00
|
|
|
case 5: *(b++) = ((subid & 0xF0000000) >> 28) | 0x80;
|
|
|
|
case 4: *(b++) = ((subid & 0x0FE00000) >> 21) | 0x80;
|
|
|
|
case 3: *(b++) = ((subid & 0x001FC000) >> 14) | 0x80;
|
|
|
|
case 2: *(b++) = ((subid & 0x00003F10) >> 7) | 0x80;
|
|
|
|
case 1: *(b++) = subid & 0x0000007F ; break;
|
2007-08-19 23:00:47 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
subid = subids[i];
|
|
|
|
} while ( i++ < subids_len);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
return bytelen;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar* oid_encoded2string(const guint8* encoded, guint len) {
|
|
|
|
guint32* subids;
|
|
|
|
guint subids_len = oid_encoded2subid(encoded, len, &subids);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
if (subids_len) {
|
|
|
|
return oid_subid2string(subids,subids_len);
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guint oid_string2encoded(const char *oid_str, guint8 **bytes) {
|
|
|
|
guint32* subids;
|
|
|
|
guint32 subids_len;
|
|
|
|
guint byteslen;
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-15 19:52:44 +00:00
|
|
|
if ( ( subids_len = oid_string2subid(oid_str, &subids) )
|
2007-12-04 18:43:40 +00:00
|
|
|
&&
|
2007-08-15 19:52:44 +00:00
|
|
|
( byteslen = oid_subid2encoded(subids_len, subids, bytes) ) ) {
|
|
|
|
return byteslen;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *oid_resolved_from_string(const gchar *oid_str) {
|
2007-08-25 01:14:24 +00:00
|
|
|
guint32 *subid_oid;
|
|
|
|
guint subid_oid_length = oid_string2subid(oid_str, &subid_oid);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
return oid_resolved(subid_oid_length, subid_oid);
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const gchar *oid_resolved(guint32 num_subids, guint32* subids) {
|
|
|
|
guint matched;
|
|
|
|
guint left;
|
2007-08-25 17:29:55 +00:00
|
|
|
oid_info_t* oid;
|
|
|
|
|
2007-12-04 18:43:40 +00:00
|
|
|
if(! (subids && *subids <= 2 ))
|
2007-08-27 21:29:20 +00:00
|
|
|
return "*** Malformed OID ***";
|
2007-08-25 17:29:55 +00:00
|
|
|
|
|
|
|
oid = oid_get(num_subids, subids, &matched, &left);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-19 23:00:47 +00:00
|
|
|
while (! oid->name ) {
|
|
|
|
if (!(oid = oid->parent)) {
|
|
|
|
return oid_subid2string(subids,num_subids);
|
|
|
|
}
|
|
|
|
left++;
|
|
|
|
matched--;
|
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-21 21:32:00 +00:00
|
|
|
if (left) {
|
|
|
|
return ep_strdup_printf("%s.%s",
|
2008-03-05 20:55:56 +00:00
|
|
|
oid->name ? oid->name : oid_subid2string(subids,matched),
|
|
|
|
oid_subid2string(&(subids[matched]),left));
|
2007-08-21 21:32:00 +00:00
|
|
|
} else {
|
2007-08-25 01:14:24 +00:00
|
|
|
return oid->name ? oid->name : oid_subid2string(subids,matched);
|
2007-08-21 21:32:00 +00:00
|
|
|
}
|
2007-08-15 19:52:44 +00:00
|
|
|
}
|
|
|
|
|
2007-08-25 01:14:24 +00:00
|
|
|
extern void oid_both(guint oid_len, guint32 *subids, char** resolved_p, char** numeric_p) {
|
|
|
|
*resolved_p = (void*)oid_resolved(oid_len,subids);
|
|
|
|
*numeric_p = (void*)oid_subid2string(subids,oid_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void oid_both_from_encoded(const guint8 *oid, gint oid_len, char** resolved_p, char** numeric_p) {
|
|
|
|
guint32* subids;
|
|
|
|
guint subids_len = oid_encoded2subid(oid, oid_len, &subids);
|
|
|
|
*resolved_p = (void*)oid_resolved(subids_len,subids);
|
|
|
|
*numeric_p = (void*)oid_subid2string(subids,subids_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
extern void oid_both_from_string(const gchar *oid_str, char** resolved_p, char** numeric_p) {
|
|
|
|
guint32* subids;
|
|
|
|
guint subids_len = oid_string2subid(oid_str, &subids);
|
|
|
|
*resolved_p = (void*)oid_resolved(subids_len,subids);
|
|
|
|
*numeric_p = (void*)oid_subid2string(subids,subids_len);
|
|
|
|
}
|
|
|
|
|
2007-12-04 18:43:40 +00:00
|
|
|
/**
|
|
|
|
* Fetch the default OID path.
|
|
|
|
*/
|
|
|
|
extern gchar *
|
2007-12-04 19:39:09 +00:00
|
|
|
oid_get_default_mib_path(void) {
|
2008-03-17 17:06:33 +00:00
|
|
|
#ifdef HAVE_LIBSMI
|
2007-12-04 18:43:40 +00:00
|
|
|
GString* path_str;
|
|
|
|
gchar *path_ret;
|
2008-03-05 20:55:56 +00:00
|
|
|
char *path;
|
2007-12-04 18:43:40 +00:00
|
|
|
guint i;
|
|
|
|
|
|
|
|
path_str = g_string_new("");
|
2010-03-17 13:26:07 +00:00
|
|
|
|
2012-07-06 04:48:36 +00:00
|
|
|
if (!load_smi_modules) {
|
2010-03-17 13:26:07 +00:00
|
|
|
D(1,("OID resolution not enabled"));
|
|
|
|
return path_str->str;
|
|
|
|
}
|
2008-03-19 21:09:31 +00:00
|
|
|
#ifdef _WIN32
|
2008-03-05 20:55:56 +00:00
|
|
|
#define PATH_SEPARATOR ";"
|
|
|
|
path = get_datafile_path("snmp\\mibs");
|
2008-05-05 20:38:27 +00:00
|
|
|
g_string_append_printf(path_str, "%s;", path);
|
2008-03-05 20:55:56 +00:00
|
|
|
g_free (path);
|
|
|
|
|
|
|
|
path = get_persconffile_path("snmp\\mibs", FALSE, FALSE);
|
2008-05-05 20:38:27 +00:00
|
|
|
g_string_append_printf(path_str, "%s", path);
|
2008-03-05 20:55:56 +00:00
|
|
|
g_free (path);
|
|
|
|
#else
|
|
|
|
#define PATH_SEPARATOR ":"
|
|
|
|
path = smiGetPath();
|
2009-11-13 17:55:55 +00:00
|
|
|
g_string_append(path_str, "/usr/share/snmp/mibs");
|
|
|
|
if (strlen(path) > 0 ) {
|
|
|
|
g_string_append(path_str, PATH_SEPARATOR);
|
|
|
|
}
|
2008-05-05 20:38:27 +00:00
|
|
|
g_string_append_printf(path_str, "%s", path);
|
2008-03-05 20:55:56 +00:00
|
|
|
free (path);
|
|
|
|
#endif
|
2007-12-04 18:43:40 +00:00
|
|
|
|
|
|
|
for(i=0;i<num_smi_paths;i++) {
|
|
|
|
if (!( smi_paths[i].name && *smi_paths[i].name))
|
|
|
|
continue;
|
|
|
|
|
2008-05-05 20:38:27 +00:00
|
|
|
g_string_append_printf(path_str,PATH_SEPARATOR "%s",smi_paths[i].name);
|
2007-12-04 18:43:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
path_ret = path_str->str;
|
|
|
|
g_string_free(path_str, FALSE);
|
|
|
|
return path_ret;
|
2008-03-17 17:06:33 +00:00
|
|
|
#else /* HAVE_LIBSMI */
|
|
|
|
return g_strdup("");
|
2007-12-04 19:39:09 +00:00
|
|
|
#endif
|
2008-03-17 17:06:33 +00:00
|
|
|
}
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-27 17:05:11 +00:00
|
|
|
#ifdef DEBUG_OIDS
|
|
|
|
char* oid_test_a2b(guint32 num_subids, guint32* subids) {
|
|
|
|
guint8* sub2enc;
|
|
|
|
guint8* str2enc;
|
|
|
|
guint32* enc2sub;
|
|
|
|
guint32* str2sub;
|
|
|
|
const char* sub2str = oid_subid2string(subids, num_subids);
|
|
|
|
guint sub2enc_len = oid_subid2encoded(num_subids, subids,&sub2enc);
|
|
|
|
guint enc2sub_len = oid_encoded2subid(sub2enc, sub2enc_len, &enc2sub);
|
|
|
|
const char* enc2str = oid_encoded2string(sub2enc, sub2enc_len);
|
|
|
|
guint str2enc_len = oid_string2encoded(sub2str,&str2enc);
|
|
|
|
guint str2sub_len = oid_string2subid(sub2str,&str2sub);
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-27 17:05:11 +00:00
|
|
|
return ep_strdup_printf(
|
|
|
|
"oid_subid2string=%s \n"
|
|
|
|
"oid_subid2encoded=[%d]%s \n"
|
|
|
|
"oid_encoded2subid=%s \n "
|
|
|
|
"oid_encoded2string=%s \n"
|
|
|
|
"oid_string2encoded=[%d]%s \n"
|
|
|
|
"oid_string2subid=%s \n "
|
|
|
|
,sub2str
|
|
|
|
,sub2enc_len,bytestring_to_str(sub2enc, sub2enc_len, ':')
|
|
|
|
,enc2sub ? oid_subid2string(enc2sub,enc2sub_len) : "-"
|
|
|
|
,enc2str
|
|
|
|
,str2enc_len,bytestring_to_str(str2enc, str2enc_len, ':')
|
|
|
|
,str2sub ? oid_subid2string(str2sub,str2sub_len) : "-"
|
2007-12-04 18:43:40 +00:00
|
|
|
);
|
2007-08-27 17:05:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree) {
|
|
|
|
static const char* oid_kinds[] = { "Unknown", "Node", "Scalar", "Table", "Row", "Column", "Notification", "Group", "Compliance", "Capabilities"};
|
|
|
|
static const char* key_types[] = {"OID_KEY_TYPE_WRONG","OID_KEY_TYPE_INTEGER",
|
|
|
|
"OID_KEY_TYPE_FIXED_STRING","OID_KEY_TYPE_FIXED_BYTES","OID_KEY_TYPE_STRING",
|
|
|
|
"OID_KEY_TYPE_BYTES","OID_KEY_TYPE_NSAP","OID_KEY_TYPE_OID","OID_KEY_TYPE_IPADDR"};
|
|
|
|
proto_item* pi = proto_tree_add_text(tree,NULL,0,0,
|
|
|
|
"OidInfo: Name='%s' sub-id=%u kind=%s hfid=%d",
|
|
|
|
oid_info->name ? oid_info->name : "",
|
|
|
|
oid_info->subid,
|
|
|
|
oid_info->kind <= OID_KIND_CAPABILITIES ? oid_kinds[oid_info->kind] : "BROKEN",
|
|
|
|
oid_info->value_hfid);
|
|
|
|
proto_tree* pt = proto_item_add_subtree(pi,0);
|
|
|
|
oid_key_t* key;
|
|
|
|
|
|
|
|
for(key = oid_info->key; key; key = key->next) {
|
|
|
|
proto_tree_add_text(pt,NULL,0,0,
|
|
|
|
"Key: name='%s' num_subids=%d type=%s",
|
|
|
|
key->name,
|
|
|
|
key->key_type <= OID_KEY_TYPE_IPADDR ? key_types[key->key_type] : "BROKEN"
|
|
|
|
);
|
|
|
|
};
|
2007-12-04 18:43:40 +00:00
|
|
|
|
2007-08-27 17:05:11 +00:00
|
|
|
if (oid_info->parent) {
|
|
|
|
pi = proto_tree_add_text(pt,NULL,0,0,"Parent:");
|
|
|
|
pt = proto_item_add_subtree(pi,0);
|
|
|
|
add_oid_debug_subtree(oid_info->parent, pt);
|
|
|
|
}
|
|
|
|
}
|
2007-08-27 18:44:55 +00:00
|
|
|
#endif
|
2007-12-04 18:43:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Editor modelines
|
|
|
|
*
|
|
|
|
* Local Variables:
|
|
|
|
* c-basic-offset: 8
|
|
|
|
* tab-width: 8
|
2008-09-02 11:17:03 +00:00
|
|
|
* indent-tabs-mode: t
|
2007-12-04 18:43:40 +00:00
|
|
|
* End:
|
|
|
|
*
|
2011-09-21 17:49:11 +00:00
|
|
|
* ex: set shiftwidth=8 tabstop=8 noexpandtab:
|
2007-12-04 18:43:40 +00:00
|
|
|
* :indentSize=8:tabSize=8:noTabs=false:
|
|
|
|
*/
|
|
|
|
|