Coverage Report

Created: 2025-04-03 08:45

/src/wireshark/epan/oids.h
Line
Count
Source (jump to first uncovered line)
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
13
#ifndef __OIDS_H__
14
#define __OIDS_H__
15
16
#include <epan/ftypes/ftypes.h>
17
#include <epan/prefs.h>
18
#include <epan/wmem_scopes.h>
19
#include "ws_symbol_export.h"
20
21
#ifdef __cplusplus
22
extern "C" {
23
#endif /* __cplusplus */
24
25
/**
26
 *@file
27
 */
28
0
#define BER_TAG_ANY -1
29
30
struct _oid_bit_t {
31
    unsigned offset;
32
    int hfid;
33
};
34
35
typedef struct _oid_bits_info_t {
36
    unsigned num;
37
    int ett;
38
    struct _oid_bit_t* data;
39
} oid_bits_info_t;
40
41
typedef enum _oid_key_type_t {
42
    OID_KEY_TYPE_WRONG,
43
    OID_KEY_TYPE_INTEGER,
44
    OID_KEY_TYPE_OID,
45
    OID_KEY_TYPE_STRING,
46
    OID_KEY_TYPE_BYTES,
47
    OID_KEY_TYPE_NSAP,
48
    OID_KEY_TYPE_IPADDR,
49
    OID_KEY_TYPE_IMPLIED_OID,
50
    OID_KEY_TYPE_IMPLIED_STRING,
51
    OID_KEY_TYPE_IMPLIED_BYTES,
52
    OID_KEY_TYPE_ETHER,
53
    OID_KEY_TYPE_DATE_AND_TIME
54
} oid_key_type_t;
55
56
typedef struct _oid_value_type_t {
57
    enum ftenum ft_type;
58
    int display;
59
    int8_t ber_class;
60
    int32_t ber_tag;
61
    int min_len;
62
    int max_len;
63
    oid_key_type_t keytype;
64
    int keysize;
65
} oid_value_type_t;
66
67
typedef enum _oid_kind_t {
68
    OID_KIND_UNKNOWN = 0,
69
    OID_KIND_NODE,
70
    OID_KIND_SCALAR,
71
    OID_KIND_TABLE,
72
    OID_KIND_ROW,
73
    OID_KIND_COLUMN,
74
    OID_KIND_NOTIFICATION,
75
    OID_KIND_GROUP,
76
    OID_KIND_COMPLIANCE,
77
    OID_KIND_CAPABILITIES
78
} oid_kind_t;
79
80
typedef struct _oid_key_t {
81
    char* name;
82
    uint32_t num_subids;
83
    oid_key_type_t key_type;
84
    int hfid;
85
    enum ftenum ft_type;
86
    int display;
87
    struct _oid_key_t* next;
88
} oid_key_t;
89
90
typedef struct _oid_info_t {
91
    uint32_t subid;
92
    char* name;
93
    oid_kind_t kind;
94
    wmem_tree_t* children;
95
    const oid_value_type_t* value_type;
96
    int value_hfid;
97
    oid_key_t* key;
98
    oid_bits_info_t* bits;
99
    struct _oid_info_t* parent;
100
} oid_info_t;
101
102
/** init function called from prefs.c */
103
WS_DLL_PUBLIC void oids_init(void);
104
extern void oid_pref_init(module_t *nameres);
105
106
/** init function called from epan.h */
107
WS_DLL_PUBLIC void oids_cleanup(void);
108
109
/*
110
 * The objects returned by all these functions are all allocated with a
111
 * packet lifetime and do not have to be freed.
112
 * However, take into account that when the packet dissection
113
 * completes, these buffers will be automatically reclaimed/freed.
114
 * If you need the buffer to remain for a longer scope than packet lifetime
115
 * you must copy the content to an wmem_file_scope() buffer.
116
 */
117
118
/*
119
 * These functions convert through the various formats:
120
 * string: is  like "0.1.3.4.5.30" (not resolved)
121
 * encoded: is BER encoded (as per X.690 section 8.19)
122
 * subids: is an array of uint32_t
123
 */
124
125
/* return length of encoded buffer */
126
WS_DLL_PUBLIC
127
unsigned oid_subid2encoded(wmem_allocator_t *scope, unsigned len, uint32_t* subids, uint8_t** encoded_p);
128
WS_DLL_PUBLIC
129
unsigned oid_string2encoded(wmem_allocator_t *scope, const char *oid_str, uint8_t** encoded_p);
130
131
/* return length of subid array */
132
WS_DLL_PUBLIC
133
unsigned oid_encoded2subid(wmem_allocator_t *scope, const uint8_t *oid, int len, uint32_t** subids_p);
134
WS_DLL_PUBLIC
135
unsigned oid_encoded2subid_sub(wmem_allocator_t *scope, const uint8_t *oid_bytes, int oid_len, uint32_t** subids_pi,
136
                bool is_first);
137
WS_DLL_PUBLIC
138
unsigned oid_string2subid(wmem_allocator_t *scope, const char *oid_str, uint32_t** subids_p);
139
140
WS_DLL_PUBLIC char* oid_encoded2string(wmem_allocator_t *scope, const uint8_t* encoded, unsigned len);
141
WS_DLL_PUBLIC char* rel_oid_encoded2string(wmem_allocator_t *scope, const uint8_t* encoded, unsigned len);
142
WS_DLL_PUBLIC char* oid_subid2string(wmem_allocator_t *scope, uint32_t *subids, unsigned len);
143
WS_DLL_PUBLIC char* rel_oid_subid2string(wmem_allocator_t *scope, uint32_t *subids, unsigned len, bool is_absolute);
144
145
/* these return a formated string as human readable as possible */
146
WS_DLL_PUBLIC char *oid_resolved(wmem_allocator_t *scope, unsigned len, uint32_t *subids);
147
WS_DLL_PUBLIC char *oid_resolved_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int len);
148
WS_DLL_PUBLIC char *rel_oid_resolved_from_encoded(wmem_allocator_t *scope, const uint8_t *oid, int len);
149
WS_DLL_PUBLIC char *oid_resolved_from_string(wmem_allocator_t *scope, const char *oid_str);
150
151
/* these yield two formated strings one resolved and one numeric */
152
WS_DLL_PUBLIC void oid_both(wmem_allocator_t *scope, unsigned oid_len, uint32_t *subids, char** resolved_p, char** numeric_p);
153
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);
154
WS_DLL_PUBLIC void oid_both_from_string(wmem_allocator_t *scope, const char *oid_str, char** resolved_p, char** numeric_p);
155
156
/*
157
 * These return the info for the best match.
158
 *  *matched_p will be set to the number of nodes used by the returned oid
159
 *  *left_p will be set to the number of remaining unresolved subids
160
 */
161
WS_DLL_PUBLIC oid_info_t* oid_get(unsigned oid_len, uint32_t *subids, unsigned* matched_p, unsigned* left_p);
162
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);
163
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);
164
165
/* these are used to add oids to the collection */
166
WS_DLL_PUBLIC void oid_add(const char* name, unsigned oid_len, uint32_t *subids);
167
WS_DLL_PUBLIC void oid_add_from_encoded(const char* name, const uint8_t *oid, int oid_len);
168
WS_DLL_PUBLIC void oid_add_from_string(const char* name, const char *oid_str);
169
170
/**
171
 * Fetch the default MIB/PIB path
172
 *
173
 * @return A string containing the default MIB/PIB path.  It must be
174
 * g_free()d by the caller.
175
 */
176
WS_DLL_PUBLIC char *oid_get_default_mib_path(void);
177
178
/* macros for legacy oid functions */
179
#define subid_t uint32_t
180
181
182
183
#ifdef DEBUG_OIDS
184
extern char* oid_test_a2b(uint32_t num_subids, uint32_t* subids);
185
extern void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree);
186
#else
187
0
#define add_oid_debug_subtree(a,b) ((void)0)
188
#endif
189
190
#ifdef __cplusplus
191
}
192
#endif /* __cplusplus */
193
194
#endif  /* __OIDS_H__ */
195
196
/*
197
 * Editor modelines
198
 *
199
 * Local Variables:
200
 * c-basic-offset: 4
201
 * tab-width: 8
202
 * indent-tabs-mode: nil
203
 * End:
204
 *
205
 * ex: set shiftwidth=4 tabstop=8 expandtab:
206
 * :indentSize=4:tabSize=8:noTabs=true:
207
 */