aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorlego <lego@f5534014-38df-0310-8fa8-9805f1628bb7>2007-08-27 17:05:11 +0000
committerlego <lego@f5534014-38df-0310-8fa8-9805f1628bb7>2007-08-27 17:05:11 +0000
commit301dd89b9d90e73abf705f472b6c75f7141fb7dc (patch)
treeb020e2abdcf24639a60999cb375827c810c8242a /epan
parent48f000893f49c9071e210057194b68f2b611ef3c (diff)
- packet-snmp(-template).c
- reimplement the "snmp.variable_oid" dissector table - oids.[ch] - get rid of keytype_implicit in oid_value_type_t we won't use it. - have the windows base path for mibs be consistent to where we've put the mibs - oid_get_from_encoded() and oid_get_from_string(): have the subids array being computed in a prior statement of where the side-effected argument is going to be used... worked on gcc, not on windows... I deserve "have daemons flying out of my nose" for that :-). git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@22684 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/packet-snmp.c50
-rw-r--r--epan/oids.c140
-rw-r--r--epan/oids.h13
3 files changed, 140 insertions, 63 deletions
diff --git a/epan/dissectors/packet-snmp.c b/epan/dissectors/packet-snmp.c
index 543e6b6b2f..7154747736 100644
--- a/epan/dissectors/packet-snmp.c
+++ b/epan/dissectors/packet-snmp.c
@@ -395,6 +395,9 @@ static const value_string smux_types[] = {
#define SERR_NSI 1
#define SERR_EOM 2
+
+dissector_table_t value_sub_dissectors_table;
+
/*
* dissect_snmp_VarBind
* this routine dissects variable bindings, looking for the oid information in our oid reporsitory
@@ -461,6 +464,7 @@ static const value_string smux_types[] = {
}
*/
+
extern int dissect_snmp_VarBind(gboolean implicit_tag _U_,
tvbuff_t *tvb,
int offset,
@@ -485,7 +489,8 @@ extern int dissect_snmp_VarBind(gboolean implicit_tag _U_,
int hfid = -1;
int min_len = 0, max_len = 0;
gboolean oid_info_is_ok;
-
+ dissector_handle_t subdissector = NULL;
+ const char* oid_string;
seq_offset = offset;
/* first have the VarBind's sequence header */
@@ -543,9 +548,6 @@ extern int dissect_snmp_VarBind(gboolean implicit_tag _U_,
/* Now, we know where everithing is */
- /* fetch ObjectName and its relative oid_info */
- oid_bytes = ep_tvb_memdup(tvb, name_offset, name_len);
- oid_info = oid_get_from_encoded(oid_bytes, name_len, &subids, &oid_matched, &oid_left);
/* we add the varbind tree root with a dummy label we'll fill later on */
@@ -556,6 +558,8 @@ extern int dissect_snmp_VarBind(gboolean implicit_tag _U_,
pi_name = proto_tree_add_item(pt_varbind,hf_snmp_objectname,tvb,name_offset,name_len,FALSE);
pt_name = proto_item_add_subtree(pi_name,ett_name);
+
+
if (ber_class == BER_CLASS_CON) {
/* if we have an error value just add it and get out the way ASAP */
proto_item* pi;
@@ -590,6 +594,22 @@ extern int dissect_snmp_VarBind(gboolean implicit_tag _U_,
goto set_label;
}
+ /* fetch ObjectName and its relative oid_info */
+ oid_bytes = ep_tvb_memdup(tvb, name_offset, name_len);
+ oid_info = oid_get_from_encoded(oid_bytes, name_len, &subids, &oid_matched, &oid_left);
+
+ add_oid_debug_subtree(oid_info,pt_name);
+
+ if (oid_matched+oid_left) {
+ oid_string = oid_subid2string(subids,oid_matched+oid_left);
+ subdissector = dissector_get_string_handle(value_sub_dissectors_table, oid_string);
+ } else {
+ oid_string = ".";
+ }
+
+
+
+
/* now we'll try to figure out which are the indexing sub-oids and whether the oid we know about is the one oid we have to use */
switch (oid_info->kind) {
case OID_KIND_SCALAR:
@@ -649,7 +669,7 @@ extern int dissect_snmp_VarBind(gboolean implicit_tag _U_,
proto_tree_add_int(pt_name,k->hfid,tvb,name_offset,name_len,(guint)subids[key_start]);
key_start++;
key_len--;
- continue; /* k->next*/
+ continue; /* k->next */
}
case OID_KEY_TYPE_OID: {
guint suboid_len = subids[key_start++];
@@ -669,7 +689,7 @@ extern int dissect_snmp_VarBind(gboolean implicit_tag _U_,
key_start += suboid_len;
key_len -= suboid_len + 1;
- continue; /* k->next*/
+ continue; /* k->next */
}
default: {
guint8* buf;
@@ -742,6 +762,14 @@ extern int dissect_snmp_VarBind(gboolean implicit_tag _U_,
}
indexing_done:
+ if (value_len > 0 && subdissector) {
+ tvbuff_t* sub_tvb = tvb_new_subset(tvb, value_offset, value_len, value_len);
+
+ call_dissector(subdissector, tvb, actx->pinfo, pt_varbind);
+
+ return seq_offset + seq_len;
+ }
+
if (oid_info_is_ok) {
if (ber_class == BER_CLASS_UNI && tag == BER_UNI_TAG_NULL) {
pi_value = proto_tree_add_item(pt_varbind,hf_snmp_unSpecified,tvb,value_offset,value_len,FALSE);
@@ -837,7 +865,7 @@ set_label:
oid_subid2string(subids,oid_matched));
}
} else {
- repr = ep_strdup_printf("%s", oid_subid2string(subids,oid_matched+oid_left));
+ repr = ep_strdup_printf("%s", oid_string);
}
valstr = strstr(label,": ");
@@ -2765,7 +2793,7 @@ static void dissect_SMUX_PDUs_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, pro
/*--- End of included file: packet-snmp-fn.c ---*/
-#line 1330 "packet-snmp-template.c"
+#line 1358 "packet-snmp-template.c"
guint
@@ -3541,7 +3569,7 @@ void proto_register_snmp(void) {
"snmp.T_operation", HFILL }},
/*--- End of included file: packet-snmp-hfarr.c ---*/
-#line 1841 "packet-snmp-template.c"
+#line 1869 "packet-snmp-template.c"
};
/* List of subtrees */
@@ -3580,7 +3608,7 @@ void proto_register_snmp(void) {
&ett_snmp_RReqPDU,
/*--- End of included file: packet-snmp-ettarr.c ---*/
-#line 1856 "packet-snmp-template.c"
+#line 1884 "packet-snmp-template.c"
};
module_t *snmp_module;
static uat_field_t users_fields[] = {
@@ -3638,6 +3666,8 @@ void proto_register_snmp(void) {
assocs_uat);
+ value_sub_dissectors_table = register_dissector_table("snmp.variable_oid","SNMP Variable OID", FT_STRING, BASE_NONE);
+
register_init_routine(renew_ue_cache);
}
diff --git a/epan/oids.c b/epan/oids.c
index 8302d7a0e6..22fba0b1d0 100644
--- a/epan/oids.c
+++ b/epan/oids.c
@@ -36,6 +36,7 @@
#include "emem.h"
#include "uat-int.h"
#include "prefs.h"
+#include "proto.h"
#include "packet.h"
#include "report_err.h"
#include "filesystem.h"
@@ -51,22 +52,22 @@
static int debuglevel = 0;
-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, 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, OID_KEY_TYPE_WRONG, 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, 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, OID_KEY_TYPE_IPADDR, 4};
-static const oid_value_type_t counter32_type = { FT_UINT32, BASE_DEC, BER_CLASS_APP, 1, 1, 4, OID_KEY_TYPE_INTEGER, OID_KEY_TYPE_INTEGER, 1};
-static const oid_value_type_t unsigned32_type = { FT_UINT32, BASE_DEC, BER_CLASS_APP, 2, 1, 4, OID_KEY_TYPE_INTEGER, OID_KEY_TYPE_INTEGER, 1};
-static const oid_value_type_t timeticks_type = { FT_UINT32, BASE_DEC, BER_CLASS_APP, 3, 1, 4, OID_KEY_TYPE_INTEGER, OID_KEY_TYPE_INTEGER, 1};
-static const oid_value_type_t opaque_type = { FT_BYTES, BASE_NONE, BER_CLASS_APP, 4, 1, 4, OID_KEY_TYPE_BYTES, OID_KEY_TYPE_WRONG, 0};
-static const oid_value_type_t nsap_type = { FT_BYTES, BASE_NONE, BER_CLASS_APP, 5, 8, 8, OID_KEY_TYPE_NSAP, OID_KEY_TYPE_NSAP, 0};
-static const oid_value_type_t counter64_type = { FT_UINT64, BASE_NONE, BER_CLASS_APP, 6, 8, 8, OID_KEY_TYPE_INTEGER, OID_KEY_TYPE_INTEGER, 1};
-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, OID_KEY_TYPE_FIXED_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, 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, OID_KEY_TYPE_WRONG, 0};
-static const oid_value_type_t ether_type = { FT_ETHER, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 6, 6, OID_KEY_TYPE_BYTES, OID_KEY_TYPE_FIXED_BYTES, 6};
-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, OID_KEY_TYPE_WRONG, 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, OID_KEY_TYPE_WRONG, 0};
+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};
+static const oid_value_type_t counter32_type = { FT_UINT32, BASE_DEC, BER_CLASS_APP, 1, 1, 4, OID_KEY_TYPE_INTEGER, 1};
+static const oid_value_type_t unsigned32_type = { FT_UINT32, BASE_DEC, BER_CLASS_APP, 2, 1, 4, OID_KEY_TYPE_INTEGER, 1};
+static const oid_value_type_t timeticks_type = { FT_UINT32, BASE_DEC, BER_CLASS_APP, 3, 1, 4, OID_KEY_TYPE_INTEGER, 1};
+static const oid_value_type_t opaque_type = { FT_BYTES, BASE_NONE, BER_CLASS_APP, 4, 1, 4, OID_KEY_TYPE_BYTES, 0};
+static const oid_value_type_t nsap_type = { FT_BYTES, BASE_NONE, BER_CLASS_APP, 5, 8, 8, OID_KEY_TYPE_NSAP, 0};
+static const oid_value_type_t counter64_type = { FT_UINT64, BASE_NONE, BER_CLASS_APP, 6, 8, 8, OID_KEY_TYPE_INTEGER, 1};
+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};
+static const oid_value_type_t ether_type = { FT_ETHER, BASE_NONE, BER_CLASS_UNI, BER_UNI_TAG_OCTETSTRING, 6, 6, OID_KEY_TYPE_BYTES, 6};
+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};
static oid_info_t oid_root = { 0, NULL, OID_KIND_UNKNOWN, NULL, &unknown_type, -2, NULL, NULL, NULL};
@@ -397,7 +398,8 @@ static inline oid_kind_t smikind(SmiNode* sN, oid_key_t** key_p) {
kl = k;
}
-
+
+#if 0
if (sN->implied) {
if (typedata) {
kl->key_type = typedata->keytype_implicit;
@@ -415,6 +417,7 @@ static inline oid_kind_t smikind(SmiNode* sN, oid_key_t** key_p) {
}
}
+#endif
return OID_KIND_ROW;
}
case SMI_NODEKIND_NODE: return OID_KIND_NODE;
@@ -435,8 +438,12 @@ static inline oid_kind_t smikind(SmiNode* sN, oid_key_t** key_p) {
#ifdef WIN32
#define PATH_SEPARATOR ";"
+#define DEFAULT_PATH_FMT "%s;%s"
+#define DEFAULT_PATH_ARGS get_datafile_path("snmp\\mibs"), get_persconffile_path("snmp\\mibs", FALSE)
#else
#define PATH_SEPARATOR ":"
+#define DEFAULT_PATH_FMT "%s"
+#define DEFAULT_PATH_ARGS smiGetPath()
#endif
void register_mibs(void) {
@@ -499,10 +506,8 @@ void register_mibs(void) {
return;
}
- path_str = g_string_new(smiGetPath());
- g_string_sprintfa(path_str, PATH_SEPARATOR "%s" PATH_SEPARATOR "%s",
- get_datafile_path("mibs"),
- get_persconffile_path("mibs", FALSE));
+ path_str = g_string_new("");
+ g_string_sprintfa(path_str, DEFAULT_PATH_FMT, DEFAULT_PATH_ARGS);
for(i=0;i<num_smi_paths;i++) {
if (!( smi_paths[i].name && *smi_paths[i].name))
@@ -824,11 +829,13 @@ done:
oid_info_t* oid_get_from_encoded(const guint8 *bytes, gint byteslen, guint32** subids_p, guint* matched_p, guint* left_p) {
- return oid_get(oid_encoded2subid(bytes, byteslen, subids_p), *subids_p, matched_p, left_p);
+ guint subids_len = oid_encoded2subid(bytes, byteslen, subids_p);
+ return oid_get(subids_len, *subids_p, matched_p, left_p);
}
oid_info_t* oid_get_from_string(const gchar *oid_str, guint32** subids_p, guint* matched, guint* left) {
- return oid_get(oid_string2subid(oid_str, subids_p), *subids_p, matched, left);
+ guint subids_len = oid_string2subid(oid_str, subids_p);
+ return oid_get(subids_len, *subids_p, matched, left);
}
const gchar *oid_resolved_from_encoded(const guint8 *oid, gint oid_len) {
@@ -942,35 +949,6 @@ const gchar *oid_resolved_from_string(const gchar *oid_str) {
return oid_resolved(subid_oid_length, subid_oid);
}
-extern char* oid_test_a2b(guint32 num_subids, guint32* subids);
-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);
-
- 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) : "-"
- );
-}
-
const gchar *oid_resolved(guint32 num_subids, guint32* subids) {
guint matched;
guint left;
@@ -1016,3 +994,61 @@ extern void oid_both_from_string(const gchar *oid_str, char** resolved_p, char**
*numeric_p = (void*)oid_subid2string(subids,subids_len);
}
+#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);
+
+ 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) : "-"
+ );
+}
+
+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"
+ );
+ };
+
+ 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);
+ }
+}
+#endif \ No newline at end of file
diff --git a/epan/oids.h b/epan/oids.h
index 42da0972ca..c80ad0d453 100644
--- a/epan/oids.h
+++ b/epan/oids.h
@@ -60,7 +60,6 @@ typedef struct _oid_value_type_t {
int min_len;
int max_len;
oid_key_type_t keytype;
- oid_key_type_t keytype_implicit;
int keysize;
} oid_value_type_t;
@@ -172,4 +171,16 @@ extern void oid_add_from_string(const char* name, const gchar *oid_str);
#define subid_t guint32
+
+
+#ifdef DEBUG_OIDS
+extern char* oid_test_a2b(guint32 num_subids, guint32* subids);
+extern void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree);
+#else
+#define add_oid_debug_subtree(a,b) ((void)0)
+#endif
+
#endif
+
+
+