| Wireshark 4.7.3 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
oids.h
Go to the documentation of this file.
1/* oids.h
2 * Object IDentifier Support
3 *
4 * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
9 *
10 * SPDX-License-Identifier: GPL-2.0-or-later
11 */
12#pragma once
13#include <epan/ftypes/ftypes.h>
14#include <epan/prefs.h>
15#include <epan/wmem_scopes.h>
16#include "ws_symbol_export.h"
17
18#ifdef __cplusplus
19 extern "C" {
20#endif /* __cplusplus */
21
25#define BER_TAG_ANY -1
26
30 struct _oid_bit_t {
31 unsigned offset;
32 int hfid;
33};
34
38 typedef struct _oid_bits_info_t {
39 unsigned num;
40 int ett;
41 struct _oid_bit_t *data;
42} oid_bits_info_t;
43
47 typedef enum _oid_key_type_t {
48 OID_KEY_TYPE_WRONG,
49 OID_KEY_TYPE_INTEGER,
50 OID_KEY_TYPE_OID,
51 OID_KEY_TYPE_STRING,
52 OID_KEY_TYPE_BYTES,
53 OID_KEY_TYPE_NSAP,
54 OID_KEY_TYPE_IPADDR,
55 OID_KEY_TYPE_IMPLIED_OID,
56 OID_KEY_TYPE_IMPLIED_STRING,
57 OID_KEY_TYPE_IMPLIED_BYTES,
58 OID_KEY_TYPE_ETHER,
59 OID_KEY_TYPE_DATE_AND_TIME
60} oid_key_type_t;
61
65 typedef struct _oid_value_type_t {
66 enum ftenum ft_type;
67 int display;
68 int8_t ber_class;
69 int32_t ber_tag;
70 int min_len;
71 int max_len;
72 oid_key_type_t keytype;
73 int keysize;
74} oid_value_type_t;
75
79 typedef enum _oid_kind_t {
80 OID_KIND_UNKNOWN = 0,
81 OID_KIND_NODE,
82 OID_KIND_SCALAR,
83 OID_KIND_TABLE,
84 OID_KIND_ROW,
85 OID_KIND_COLUMN,
86 OID_KIND_NOTIFICATION,
87 OID_KIND_GROUP,
88 OID_KIND_COMPLIANCE,
89 OID_KIND_CAPABILITIES
90} oid_kind_t;
91
95 typedef struct _oid_key_t {
96 char *name;
97 uint32_t num_subids;
98 oid_key_type_t key_type;
99 int hfid;
100 enum ftenum ft_type;
101 int display;
102 struct _oid_key_t *next;
103} oid_key_t;
104
108 typedef struct _oid_info_t {
109 uint32_t subid;
110 char *name;
111 oid_kind_t kind;
112 wmem_tree_t *children;
113 const oid_value_type_t *value_type;
114 int value_hfid;
115 oid_key_t *key;
116 oid_bits_info_t *bits;
117 struct _oid_info_t *parent;
118} oid_info_t;
119
126WS_DLL_PUBLIC void oids_init(const char* app_env_var_prefix);
127
133 extern void oid_pref_init(module_t *nameres);
134
139WS_DLL_PUBLIC void oids_cleanup(void);
140
141/*
142 * The objects returned by all these functions are all allocated with a
143 * packet lifetime and do not have to be freed.
144 * However, take into account that when the packet dissection
145 * completes, these buffers will be automatically reclaimed/freed.
146 * If you need the buffer to remain for a longer scope than packet lifetime
147 * you must copy the content to an wmem_file_scope() buffer.
148 */
149
150/*
151 * These functions convert through the various formats:
152 * string: is like "0.1.3.4.5.30" (not resolved)
153 * encoded: is BER encoded (as per X.690 section 8.19)
154 * subids: is an array of uint32_t
155 */
156
166WS_DLL_PUBLIC
167 unsigned oid_subid2encoded(wmem_allocator_t *scope, unsigned len, uint32_t* subids, uint8_t** encoded_p);
168
177WS_DLL_PUBLIC
178 unsigned oid_string2encoded(wmem_allocator_t *scope, const char *oid_str, uint8_t** encoded_p);
179
189WS_DLL_PUBLIC
190 unsigned oid_encoded2subid(wmem_allocator_t *scope, const uint8_t *oid, int len, uint32_t** subids_p);
191
203WS_DLL_PUBLIC
204 unsigned oid_encoded2subid_sub(wmem_allocator_t *scope, const uint8_t *oid_bytes, int oid_len, uint32_t** subids_pi,
205 bool is_first);
206
215WS_DLL_PUBLIC
216 unsigned oid_string2subid(wmem_allocator_t *scope, const char *oid_str, uint32_t** subids_p);
217
226WS_DLL_PUBLIC char* oid_encoded2string(wmem_allocator_t *scope, const uint8_t* encoded, unsigned len);
227
236WS_DLL_PUBLIC char* rel_oid_encoded2string(wmem_allocator_t *scope, const uint8_t* encoded, unsigned len);
237
246WS_DLL_PUBLIC char* oid_subid2string(wmem_allocator_t *scope, uint32_t *subids, unsigned len);
247
257WS_DLL_PUBLIC char* rel_oid_subid2string(wmem_allocator_t *scope, uint32_t *subids, unsigned len, bool is_absolute);
258
259/* these return a formated string as human readable as possible */
268WS_DLL_PUBLIC char *oid_resolved(wmem_allocator_t *scope, unsigned len, uint32_t *subids);
269
278WS_DLL_PUBLIC char *oid_resolved_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int len);
279
288WS_DLL_PUBLIC char *rel_oid_resolved_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int len);
289
297WS_DLL_PUBLIC char *oid_resolved_from_string(wmem_allocator_t *scope, const char *oid_str);
298
299/* these yield two formated strings one resolved and one numeric */
300
310WS_DLL_PUBLIC void oid_both(wmem_allocator_t *scope, unsigned oid_len, uint32_t *subids, char** resolved_p, char** numeric_p);
311
321WS_DLL_PUBLIC void oid_both_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int oid_len, char** resolved_p, char** numeric_p);
322
331WS_DLL_PUBLIC void oid_both_from_string(wmem_allocator_t *scope, const char *oid_str, char** resolved_p, char** numeric_p);
332
333/*
334 * These return the info for the best match.
335 * *matched_p will be set to the number of nodes used by the returned oid
336 * *left_p will be set to the number of remaining unresolved subids
337 */
338
348WS_DLL_PUBLIC oid_info_t* oid_get(unsigned oid_len, uint32_t *subids, unsigned* matched_p, unsigned* left_p);
349
361WS_DLL_PUBLIC oid_info_t* oid_get_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int oid_len, uint32_t **subids, unsigned* matched, unsigned* left);
362
373WS_DLL_PUBLIC oid_info_t* oid_get_from_string(wmem_allocator_t *scope, const char *oid_str, uint32_t **subids, unsigned* matched, unsigned* left);
374
375/* these are used to add oids to the collection */
383WS_DLL_PUBLIC void oid_add(const char* name, unsigned oid_len, uint32_t *subids);
384
392WS_DLL_PUBLIC void oid_add_from_encoded(const char* name, const uint8_t *oid, int oid_len);
393
400WS_DLL_PUBLIC void oid_add_from_string(const char* name, const char *oid_str);
401
409WS_DLL_PUBLIC char *oid_get_default_mib_path(const char* app_env_var_prefix);
410
411/* macros for legacy oid functions */
412#define subid_t uint32_t
413
414
415
416#ifdef DEBUG_OIDS
425 extern char* oid_test_a2b(uint32_t num_subids, uint32_t* subids);
426
433 extern void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree);
434#else
435#define add_oid_debug_subtree(a,b) ((void)0)
436#endif
437
438#ifdef __cplusplus
439}
440#endif /* __cplusplus */
441
442/*
443 * Editor modelines
444 *
445 * Local Variables:
446 * c-basic-offset: 4
447 * tab-width: 8
448 * indent-tabs-mode: nil
449 * End:
450 *
451 * ex: set shiftwidth=4 tabstop=8 expandtab:
452 * :indentSize=4:tabSize=8:noTabs=true:
453 */
ftypes.h
ftenum
ftenum
Fundamental field value types used throughout the Wireshark dissector framework.
Definition ftypes.h:26
wmem_tree_t
struct _wmem_tree_t wmem_tree_t
Opaque type representing a red-black tree in the wmem system.
Definition wmem_tree.h:49
wmem_allocator_t
struct _wmem_allocator_t wmem_allocator_t
Definition wmem_core.h:44
oid_value_type_t
struct _oid_value_type_t oid_value_type_t
Describes the value syntax and BER encoding of an OID leaf node.
oid_string2subid
WS_DLL_PUBLIC unsigned oid_string2subid(wmem_allocator_t *scope, const char *oid_str, uint32_t **subids_p)
Return the number of sub-identifiers in a decoded OID string.
Definition oids.c:943
oid_key_t
struct _oid_key_t oid_key_t
Describes a single index key component used to identify rows in an OID-indexed table.
rel_oid_encoded2string
WS_DLL_PUBLIC char * rel_oid_encoded2string(wmem_allocator_t *scope, const uint8_t *encoded, unsigned len)
Return the string representation of an encoded relative OID.
Definition oids.c:1189
oid_pref_init
void oid_pref_init(module_t *nameres)
Initialize OID-related preferences.
Definition oids.c:773
oid_info_t
struct _oid_info_t oid_info_t
A node in the OID registry tree, representing one arc of an object identifier.
oid_encoded2subid_sub
WS_DLL_PUBLIC unsigned oid_encoded2subid_sub(wmem_allocator_t *scope, const uint8_t *oid_bytes, int oid_len, uint32_t **subids_pi, bool is_first)
Return the number of sub-identifiers in a decoded OID, with support for partial (sub-) OID decoding.
Definition oids.c:995
oid_get
WS_DLL_PUBLIC oid_info_t * oid_get(unsigned oid_len, uint32_t *subids, unsigned *matched_p, unsigned *left_p)
Retrieves an OID information structure from its encoded form.
Definition oids.c:1063
oid_encoded2string
WS_DLL_PUBLIC char * oid_encoded2string(wmem_allocator_t *scope, const uint8_t *encoded, unsigned len)
Return the string representation of an encoded OID.
Definition oids.c:1174
oid_encoded2subid
WS_DLL_PUBLIC unsigned oid_encoded2subid(wmem_allocator_t *scope, const uint8_t *oid, int len, uint32_t **subids_p)
Return the number of sub-identifiers in a decoded OID.
Definition oids.c:992
oid_add_from_string
WS_DLL_PUBLIC void oid_add_from_string(const char *name, const char *oid_str)
Add an OID to the OID database from a string.
Definition oids.c:178
oid_subid2encoded
WS_DLL_PUBLIC unsigned oid_subid2encoded(wmem_allocator_t *scope, unsigned len, uint32_t *subids, uint8_t **encoded_p)
Return length of encoded buffer.
Definition oids.c:1119
oid_subid2string
WS_DLL_PUBLIC char * oid_subid2string(wmem_allocator_t *scope, uint32_t *subids, unsigned len)
Convert a sequence of OID sub-identifiers to a human-readable string.
Definition oids.c:889
rel_oid_resolved_from_encoded
WS_DLL_PUBLIC char * rel_oid_resolved_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int len)
Resolve an OID from its encoded form.
Definition oids.c:1108
oid_kind_t
enum _oid_kind_t oid_kind_t
Semantic role of an OID node within a MIB or SMI object hierarchy.
oid_both_from_string
WS_DLL_PUBLIC void oid_both_from_string(wmem_allocator_t *scope, const char *oid_str, char **resolved_p, char **numeric_p)
Resolve and convert an OID from its string representation to both resolved and numeric forms.
Definition oids.c:1276
oids_init
WS_DLL_PUBLIC void oids_init(const char *app_env_var_prefix)
Initialize OID resolution and register related preferences.
oid_key_type_t
enum _oid_key_type_t oid_key_type_t
Encoding type of a key sub-identifier in an OID index.
oid_resolved
WS_DLL_PUBLIC char * oid_resolved(wmem_allocator_t *scope, unsigned len, uint32_t *subids)
Resolve an OID to its human-readable name.
oid_both
WS_DLL_PUBLIC void oid_both(wmem_allocator_t *scope, unsigned oid_len, uint32_t *subids, char **resolved_p, char **numeric_p)
Resolve and convert an OID to both resolved and numeric representations.
Definition oids.c:1263
oid_resolved_from_string
WS_DLL_PUBLIC char * oid_resolved_from_string(wmem_allocator_t *scope, const char *oid_str)
Resolves an OID string to its resolved form.
Definition oids.c:1218
oid_both_from_encoded
WS_DLL_PUBLIC void oid_both_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int oid_len, char **resolved_p, char **numeric_p)
Resolve and convert an OID from its encoded form to both resolved and numeric representations.
Definition oids.c:1268
oid_bits_info_t
struct _oid_bits_info_t oid_bits_info_t
Describes the full set of named bit fields within a BITS-syntax OID value.
oid_add_from_encoded
WS_DLL_PUBLIC void oid_add_from_encoded(const char *name, const uint8_t *oid, int oid_len)
Add an OID to the OID database from an encoded buffer.
Definition oids.c:191
oid_get_from_encoded
WS_DLL_PUBLIC oid_info_t * oid_get_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int oid_len, uint32_t **subids, unsigned *matched, unsigned *left)
Retrieves an OID information structure from its encoded form.
Definition oids.c:1088
oid_resolved_from_encoded
WS_DLL_PUBLIC char * oid_resolved_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int len)
Resolve an OID from its encoded form.
Definition oids.c:1098
oid_string2encoded
WS_DLL_PUBLIC unsigned oid_string2encoded(wmem_allocator_t *scope, const char *oid_str, uint8_t **encoded_p)
Return length of encoded buffer.
Definition oids.c:1204
oid_get_from_string
WS_DLL_PUBLIC oid_info_t * oid_get_from_string(wmem_allocator_t *scope, const char *oid_str, uint32_t **subids, unsigned *matched, unsigned *left)
Retrieves an OID information structure from a string representation.
Definition oids.c:1093
_oid_kind_t
_oid_kind_t
Semantic role of an OID node within a MIB or SMI object hierarchy.
Definition oids.h:79
OID_KIND_ROW
@ OID_KIND_ROW
Definition oids.h:84
OID_KIND_SCALAR
@ OID_KIND_SCALAR
Definition oids.h:82
OID_KIND_GROUP
@ OID_KIND_GROUP
Definition oids.h:87
OID_KIND_TABLE
@ OID_KIND_TABLE
Definition oids.h:83
OID_KIND_NODE
@ OID_KIND_NODE
Definition oids.h:81
OID_KIND_UNKNOWN
@ OID_KIND_UNKNOWN
Definition oids.h:80
OID_KIND_NOTIFICATION
@ OID_KIND_NOTIFICATION
Definition oids.h:86
OID_KIND_COMPLIANCE
@ OID_KIND_COMPLIANCE
Definition oids.h:88
OID_KIND_CAPABILITIES
@ OID_KIND_CAPABILITIES
Definition oids.h:89
OID_KIND_COLUMN
@ OID_KIND_COLUMN
Definition oids.h:85
oid_get_default_mib_path
WS_DLL_PUBLIC char * oid_get_default_mib_path(const char *app_env_var_prefix)
Fetch the default MIB/PIB path.
oids_cleanup
WS_DLL_PUBLIC void oids_cleanup(void)
Clean up OID-related resources.
Definition oids.c:881
oid_add
WS_DLL_PUBLIC void oid_add(const char *name, unsigned oid_len, uint32_t *subids)
Add an OID to the OID database.
Definition oids.c:168
_oid_key_type_t
_oid_key_type_t
Encoding type of a key sub-identifier in an OID index.
Definition oids.h:47
OID_KEY_TYPE_IMPLIED_STRING
@ OID_KEY_TYPE_IMPLIED_STRING
Definition oids.h:56
OID_KEY_TYPE_IPADDR
@ OID_KEY_TYPE_IPADDR
Definition oids.h:54
OID_KEY_TYPE_BYTES
@ OID_KEY_TYPE_BYTES
Definition oids.h:52
OID_KEY_TYPE_IMPLIED_OID
@ OID_KEY_TYPE_IMPLIED_OID
Definition oids.h:55
OID_KEY_TYPE_STRING
@ OID_KEY_TYPE_STRING
Definition oids.h:51
OID_KEY_TYPE_NSAP
@ OID_KEY_TYPE_NSAP
Definition oids.h:53
OID_KEY_TYPE_INTEGER
@ OID_KEY_TYPE_INTEGER
Definition oids.h:49
OID_KEY_TYPE_DATE_AND_TIME
@ OID_KEY_TYPE_DATE_AND_TIME
Definition oids.h:59
OID_KEY_TYPE_IMPLIED_BYTES
@ OID_KEY_TYPE_IMPLIED_BYTES
Definition oids.h:57
OID_KEY_TYPE_WRONG
@ OID_KEY_TYPE_WRONG
Definition oids.h:48
OID_KEY_TYPE_ETHER
@ OID_KEY_TYPE_ETHER
Definition oids.h:58
OID_KEY_TYPE_OID
@ OID_KEY_TYPE_OID
Definition oids.h:50
rel_oid_subid2string
WS_DLL_PUBLIC char * rel_oid_subid2string(wmem_allocator_t *scope, uint32_t *subids, unsigned len, bool is_absolute)
Convert a sequence of OID subidentifiers to a human-readable string.
Definition oids.c:892
prefs.h
_oid_bit_t
Maps a single bit offset within an OID value to a protocol tree field.
Definition oids.h:30
_oid_bit_t::hfid
int hfid
Definition oids.h:32
_oid_bit_t::offset
unsigned offset
Definition oids.h:31
_oid_bits_info_t
Describes the full set of named bit fields within a BITS-syntax OID value.
Definition oids.h:38
_oid_bits_info_t::num
unsigned num
Definition oids.h:39
_oid_bits_info_t::data
struct _oid_bit_t * data
Definition oids.h:41
_oid_bits_info_t::ett
int ett
Definition oids.h:40
_oid_info_t
A node in the OID registry tree, representing one arc of an object identifier.
Definition oids.h:108
_oid_info_t::children
wmem_tree_t * children
Definition oids.h:112
_oid_info_t::name
char * name
Definition oids.h:110
_oid_info_t::parent
struct _oid_info_t * parent
Definition oids.h:117
_oid_info_t::bits
oid_bits_info_t * bits
Definition oids.h:116
_oid_info_t::value_type
const oid_value_type_t * value_type
Definition oids.h:113
_oid_info_t::key
oid_key_t * key
Definition oids.h:115
_oid_info_t::value_hfid
int value_hfid
Definition oids.h:114
_oid_info_t::subid
uint32_t subid
Definition oids.h:109
_oid_info_t::kind
oid_kind_t kind
Definition oids.h:111
_oid_key_t
Describes a single index key component used to identify rows in an OID-indexed table.
Definition oids.h:95
_oid_key_t::display
int display
Definition oids.h:101
_oid_key_t::next
struct _oid_key_t * next
Definition oids.h:102
_oid_key_t::ft_type
enum ftenum ft_type
Definition oids.h:100
_oid_key_t::key_type
oid_key_type_t key_type
Definition oids.h:98
_oid_key_t::hfid
int hfid
Definition oids.h:99
_oid_key_t::num_subids
uint32_t num_subids
Definition oids.h:97
_oid_key_t::name
char * name
Definition oids.h:96
_oid_value_type_t
Describes the value syntax and BER encoding of an OID leaf node.
Definition oids.h:65
_oid_value_type_t::ft_type
enum ftenum ft_type
Definition oids.h:66
_oid_value_type_t::max_len
int max_len
Definition oids.h:71
_oid_value_type_t::min_len
int min_len
Definition oids.h:70
_oid_value_type_t::keytype
oid_key_type_t keytype
Definition oids.h:72
_oid_value_type_t::display
int display
Definition oids.h:67
_oid_value_type_t::ber_class
int8_t ber_class
Definition oids.h:68
_oid_value_type_t::ber_tag
int32_t ber_tag
Definition oids.h:69
_oid_value_type_t::keysize
int keysize
Definition oids.h:73
wmem_scopes.h