Wireshark 4.7.0
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 <[email protected]>
5 *
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <[email protected]>
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
19extern "C" {
20#endif /* __cplusplus */
21
25#define BER_TAG_ANY -1
26
27struct _oid_bit_t {
28 unsigned offset;
29 int hfid;
30};
31
32typedef struct _oid_bits_info_t {
33 unsigned num;
34 int ett;
35 struct _oid_bit_t* data;
37
38typedef enum _oid_key_type_t {
39 OID_KEY_TYPE_WRONG,
40 OID_KEY_TYPE_INTEGER,
41 OID_KEY_TYPE_OID,
42 OID_KEY_TYPE_STRING,
43 OID_KEY_TYPE_BYTES,
44 OID_KEY_TYPE_NSAP,
45 OID_KEY_TYPE_IPADDR,
46 OID_KEY_TYPE_IMPLIED_OID,
47 OID_KEY_TYPE_IMPLIED_STRING,
48 OID_KEY_TYPE_IMPLIED_BYTES,
49 OID_KEY_TYPE_ETHER,
50 OID_KEY_TYPE_DATE_AND_TIME
51} oid_key_type_t;
52
53typedef struct _oid_value_type_t {
54 enum ftenum ft_type;
55 int display;
56 int8_t ber_class;
57 int32_t ber_tag;
58 int min_len;
59 int max_len;
60 oid_key_type_t keytype;
61 int keysize;
63
64typedef enum _oid_kind_t {
65 OID_KIND_UNKNOWN = 0,
66 OID_KIND_NODE,
67 OID_KIND_SCALAR,
68 OID_KIND_TABLE,
69 OID_KIND_ROW,
70 OID_KIND_COLUMN,
71 OID_KIND_NOTIFICATION,
72 OID_KIND_GROUP,
73 OID_KIND_COMPLIANCE,
74 OID_KIND_CAPABILITIES
75} oid_kind_t;
76
77typedef struct _oid_key_t {
78 char* name;
79 uint32_t num_subids;
80 oid_key_type_t key_type;
81 int hfid;
82 enum ftenum ft_type;
83 int display;
84 struct _oid_key_t* next;
85} oid_key_t;
86
87typedef struct _oid_info_t {
88 uint32_t subid;
89 char* name;
90 oid_kind_t kind;
91 wmem_tree_t* children;
92 const oid_value_type_t* value_type;
93 int value_hfid;
94 oid_key_t* key;
95 oid_bits_info_t* bits;
96 struct _oid_info_t* parent;
98
105WS_DLL_PUBLIC void oids_init(const char* app_env_var_prefix);
106
107extern void oid_pref_init(module_t *nameres);
108
113WS_DLL_PUBLIC void oids_cleanup(void);
114
115/*
116 * The objects returned by all these functions are all allocated with a
117 * packet lifetime and do not have to be freed.
118 * However, take into account that when the packet dissection
119 * completes, these buffers will be automatically reclaimed/freed.
120 * If you need the buffer to remain for a longer scope than packet lifetime
121 * you must copy the content to an wmem_file_scope() buffer.
122 */
123
124/*
125 * These functions convert through the various formats:
126 * string: is like "0.1.3.4.5.30" (not resolved)
127 * encoded: is BER encoded (as per X.690 section 8.19)
128 * subids: is an array of uint32_t
129 */
130
131/* return length of encoded buffer */
132WS_DLL_PUBLIC
133unsigned oid_subid2encoded(wmem_allocator_t *scope, unsigned len, uint32_t* subids, uint8_t** encoded_p);
134WS_DLL_PUBLIC
135unsigned oid_string2encoded(wmem_allocator_t *scope, const char *oid_str, uint8_t** encoded_p);
136
137/* return length of subid array */
138WS_DLL_PUBLIC
139unsigned oid_encoded2subid(wmem_allocator_t *scope, const uint8_t *oid, int len, uint32_t** subids_p);
140WS_DLL_PUBLIC
141unsigned oid_encoded2subid_sub(wmem_allocator_t *scope, const uint8_t *oid_bytes, int oid_len, uint32_t** subids_pi,
142 bool is_first);
143WS_DLL_PUBLIC
144unsigned oid_string2subid(wmem_allocator_t *scope, const char *oid_str, uint32_t** subids_p);
145
146WS_DLL_PUBLIC char* oid_encoded2string(wmem_allocator_t *scope, const uint8_t* encoded, unsigned len);
147WS_DLL_PUBLIC char* rel_oid_encoded2string(wmem_allocator_t *scope, const uint8_t* encoded, unsigned len);
148
157WS_DLL_PUBLIC char* oid_subid2string(wmem_allocator_t *scope, uint32_t *subids, unsigned len);
158
168WS_DLL_PUBLIC char* rel_oid_subid2string(wmem_allocator_t *scope, uint32_t *subids, unsigned len, bool is_absolute);
169
170/* these return a formated string as human readable as possible */
179WS_DLL_PUBLIC char *oid_resolved(wmem_allocator_t *scope, unsigned len, uint32_t *subids);
180
181WS_DLL_PUBLIC char *oid_resolved_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int len);
182
191WS_DLL_PUBLIC char *rel_oid_resolved_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int len);
192
200WS_DLL_PUBLIC char *oid_resolved_from_string(wmem_allocator_t *scope, const char *oid_str);
201
202/* these yield two formated strings one resolved and one numeric */
203
213WS_DLL_PUBLIC void oid_both(wmem_allocator_t *scope, unsigned oid_len, uint32_t *subids, char** resolved_p, char** numeric_p);
214
224WS_DLL_PUBLIC void oid_both_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int oid_len, char** resolved_p, char** numeric_p);
225
234WS_DLL_PUBLIC void oid_both_from_string(wmem_allocator_t *scope, const char *oid_str, char** resolved_p, char** numeric_p);
235
236/*
237 * These return the info for the best match.
238 * *matched_p will be set to the number of nodes used by the returned oid
239 * *left_p will be set to the number of remaining unresolved subids
240 */
241WS_DLL_PUBLIC oid_info_t* oid_get(unsigned oid_len, uint32_t *subids, unsigned* matched_p, unsigned* left_p);
242
254WS_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);
255
266WS_DLL_PUBLIC oid_info_t* oid_get_from_string(wmem_allocator_t *scope, const char *oid_str, uint32_t **subids, unsigned* matched, unsigned* left);
267
268/* these are used to add oids to the collection */
269WS_DLL_PUBLIC void oid_add(const char* name, unsigned oid_len, uint32_t *subids);
270WS_DLL_PUBLIC void oid_add_from_encoded(const char* name, const uint8_t *oid, int oid_len);
271WS_DLL_PUBLIC void oid_add_from_string(const char* name, const char *oid_str);
272
280WS_DLL_PUBLIC char *oid_get_default_mib_path(const char* app_env_var_prefix);
281
282/* macros for legacy oid functions */
283#define subid_t uint32_t
284
285
286
287#ifdef DEBUG_OIDS
288extern char* oid_test_a2b(uint32_t num_subids, uint32_t* subids);
289extern void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree);
290#else
291#define add_oid_debug_subtree(a,b) ((void)0)
292#endif
293
294#ifdef __cplusplus
295}
296#endif /* __cplusplus */
297
298/*
299 * Editor modelines
300 *
301 * Local Variables:
302 * c-basic-offset: 4
303 * tab-width: 8
304 * indent-tabs-mode: nil
305 * End:
306 *
307 * ex: set shiftwidth=4 tabstop=8 expandtab:
308 * :indentSize=4:tabSize=8:noTabs=true:
309 */
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:878
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:1097
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:1265
WS_DLL_PUBLIC void oids_init(const char *app_env_var_prefix)
Initialize OID resolution and register related preferences.
WS_DLL_PUBLIC char * oid_resolved(wmem_allocator_t *scope, unsigned len, uint32_t *subids)
Resolve an OID to its human-readable name.
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:1252
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:1207
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:1257
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:1077
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:1082
WS_DLL_PUBLIC char * oid_get_default_mib_path(const char *app_env_var_prefix)
Fetch the default MIB/PIB path.
WS_DLL_PUBLIC void oids_cleanup(void)
Clean up OID-related resources.
Definition oids.c:870
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:881
Definition oids.h:27
Definition oids.h:32
Definition oids.h:87
Definition oids.h:77
Definition oids.h:53
Definition proto.h:902
Internal memory allocator interface used by the wmem subsystem.
Definition wmem_allocator.h:34
Internal representation of a wmem balanced tree.
Definition wmem_tree-int.h:81
Definition prefs-int.h:24