Coverage Report

Created: 2026-09-28 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-f5ethtrailer.h
Line
Count
Source
1
/* packet-f5ethtrailer.h
2
 *
3
 * F5 Ethernet Trailer Copyright 2008-2018 F5 Networks
4
 *
5
 * SPDX-License-Identifier: GPL-2.0-or-later
6
 */
7
8
/* How to use the fileinfo version tap
9
 *
10
 * Captures taken on an F5 device in versions 11.2.0 and later contain an
11
 * initial packet that has information about how the capture was taken and
12
 * about the device it was taken on (tcpdump command line, platform, version,
13
 * etc.).  This tap allows other dissectors to obtain the version of BIG-IP
14
 * software (if it is available).
15
 *
16
 * There are two functions defined in this header file (f5fileinfo_tap_reset()
17
 * and f5fileinfo_tap_pkt()).  These functions are registered with the tap and
18
 * will populate a structure provided by you with the version information.
19
 *
20
 * Step 1: Define a static variable of type "struct f5fileinfo".  This is where
21
 * the version information will be stored.
22
 *   static struct f5fileinfo myver = F5FILEINFO_TAP_DATA_INIT;
23
 *
24
 * Step 2: Register with the tap listener using the macro provided in your
25
 * proto_reg_handoff function:
26
 *   F5FILEINFO_TAP_LISTEN(&myver);
27
 *
28
 * Step 3: Use the version information in other parts of your code.
29
 *   if(myver.ver[0] == 11) {
30
 *      ...
31
 *   }
32
 *
33
 * If you need to do something additional when you run into a version, you can
34
 * define the F5FILEINFO_TAP_POST_FUNC macro before including this header file
35
 * to be the name of a fuction to call at the end of the tap function.  This
36
 * function must have a prototype of
37
 *   static void F5FILEINFO_TAP_POST_FUNC(struct f5fileinfo_tap_data *);
38
 * Note that this function also gets called with version of all zeroes when the
39
 * tap gets reset (reload file).
40
 * Note that this function does not get called if the version number does not
41
 * change.
42
 * Example:
43
 *   #define F5FILEINFO_TAP_POST_FUNC f5info_tap_local
44
 *   #include <epan/dissectors/packet-f5ethtrailer.h>
45
 *   ...
46
 *   static void f5info_tap_local(struct f5fileinfo_tap_data *tap_data)
47
 *   {
48
 *       ...
49
 *   }
50
 */
51
52
#ifndef _PACKETH_F5ETHTRAILER_H_
53
#define _PACKETH_F5ETHTRAILER_H_
54
55
98
#define F5ETH_TAP_TMM_MAX   UINT16_MAX
56
#define F5ETH_TAP_TMM_BITS  16
57
95
#define F5ETH_TAP_SLOT_MAX  UINT16_MAX
58
#define F5ETH_TAP_SLOT_BITS 16
59
60
/** Magic number for Ethernet trailer tap data to ensure that any tap and the dissector were both
61
 *  compiled from the same source.  No need to htonl this since the dissector and the tap should
62
 *  both be compiled on the same platform.
63
 *
64
 *  Increment this value when the struct f5eth_tap_data (below) is changed.
65
 */
66
92
#define F5ETH_TAP_MAGIC     0x68744521
67
68
/** Data structure to hold data returned by the f5ethtrailer tap.  Magic has to be first. */
69
typedef struct f5eth_tap_data {
70
    uint32_t magic;        /**< Verify proper version of dissector */
71
    uint32_t trailer_len;  /**< Overall length of the F5 trailer */
72
    /* 64 bit align */
73
    uint64_t flow;         /**< Flow ID */
74
    uint64_t peer_flow;    /**< Peer Flow ID */
75
    /* 64 bit align */
76
    char   *virtual_name; /**< Virtual server name */
77
    uint16_t slot;         /**< The slot the handled the packet (F5ETH_TAP_TMM_MAX == unknown) */
78
    uint16_t tmm;          /**< The tmm that handled the packet (F5ETH_TAP_sLOT_MAX == unknown) */
79
    uint8_t noise_low:1;  /**< If the frame has low noise(1) or not(0) */
80
    uint8_t noise_med:1;  /**< If the frame has medium noise(1) or not(0) */
81
    uint8_t noise_high:1; /**< If the frame has high noise(1) or not(0) */
82
    uint8_t flows_set:1;  /**< If the frame has flow/peerflow fields(1) or not(0) */
83
    uint8_t ingress:2;    /**< Whether the packet was ingress(1), egress(0) or unknown(3) */
84
} f5eth_tap_data_t;
85
86
/** \brief Tap data version matches compiled version
87
 *
88
 *  @param tdata Pointer to tapdata from f5ethtrailer
89
 *  @return 1 if the version of the tapdata matches the compiled version of the tap. 0 otherwise.
90
 *
91
 *  Use this function to ensure that the data from the f5ethtrailer tap is the same as the
92
 *  structure used when your tap was compiled.  Use this to protect your tap from running against
93
 *  a newer/older version of the f5ethtrailer dissector.
94
 *
95
 *  For example, at the top of your tap packet function, you can use:
96
 *    if(check_f5eth_tap_magic(tdata) == 0) return 0;
97
 */
98
inline static int check_f5eth_tap_magic(f5eth_tap_data_t *tdata)
99
0
{
100
0
    return(tdata->magic == F5ETH_TAP_MAGIC ? 1 : 0);
101
0
} /* check_f5eth_tap_magic() */
102
103
0
#define F5FILEINFO_TAP_MAGIC 0x46350001
104
105
/** Data structure to hold data returned by the f5fileinfo tap. */
106
struct f5fileinfo_tap_data {
107
    uint32_t magic;  /**< Just to make sure that we have the same version. */
108
    uint32_t ver[6]; /**< Array for version and build elements. */
109
};
110
111
#define F5FILEINFO_TAP_DATA_INIT { 0, { 0, 0, 0, 0, 0, 0 } }
112
113
#define F5VER_KNOWN(v) ((v)->ver[0] > 0)
114
115
116
#define F5VER_GE_11_2(v) (((v)->ver[0] > 11) \
117
    || ((v)->ver[0] == 11 && (v)->ver[1] >= 2))
118
119
#define F5VER_GE_11_2_1(v) (((v)->ver[0] > 11) \
120
    || ((v)->ver[0] == 11 && (v)->ver[1] > 2) \
121
    || ((v)->ver[0] == 11 && (v)->ver[1] == 2 && (v)->ver[2] >= 1))
122
123
#define F5VER_GE_11_3(v) (((v)->ver[0] > 11) \
124
    || ((v)->ver[0] == 11 && (v)->ver[1] >= 3))
125
126
#define F5VER_GE_11_4(v) (((v)->ver[0] > 11) \
127
    || ((v)->ver[0] == 11 && (v)->ver[1] >= 4))
128
129
#define F5VER_GE_11_4_1(v) (((v)->ver[0] > 11) \
130
    || ((v)->ver[0] == 11 && (v)->ver[1] > 4) \
131
    || ((v)->ver[0] == 11 && (v)->ver[1] == 4 && (v)->ver[2] >= 1))
132
133
#define F5VER_GE_11_5(v) (((v)->ver[0] > 11) \
134
    || ((v)->ver[0] == 11 && (v)->ver[1] >= 5))
135
136
#define F5VER_GE_11_5_1(v) (((v)->ver[0] > 11) \
137
    || ((v)->ver[0] == 11 && (v)->ver[1] > 5) \
138
    || ((v)->ver[0] == 11 && (v)->ver[1] == 5 && (v)->ver[2] >= 1))
139
140
#define F5VER_GE_11_6(v) (((v)->ver[0] > 11) \
141
    || ((v)->ver[0] == 11 && (v)->ver[1] >= 6))
142
143
#define F5VER_GE_12_0(v) (((v)->ver[0] >= 12))
144
145
146
#ifndef F5FILEINFOTAP_SRC
147
148
#ifdef F5FILEINFO_TAP_POST_FUNC
149
static void F5FILEINFO_TAP_POST_FUNC(struct f5fileinfo_tap_data *);
150
#endif
151
152
static void f5fileinfo_tap_reset(void *p)
153
{
154
    struct f5fileinfo_tap_data *s;
155
156
    s = (struct f5fileinfo_tap_data *)p;
157
    s->ver[0] = 0;
158
    s->ver[1] = 0;
159
    s->ver[2] = 0;
160
    s->ver[3] = 0;
161
    s->ver[4] = 0;
162
    s->ver[5] = 0;
163
#   ifdef F5FILEINFO_TAP_POST_FUNC
164
        F5FILEINFO_TAP_POST_FUNC(s);
165
#   endif
166
} /* f5fileinfo_tap_reset() */
167
168
static tap_packet_status f5fileinfo_tap_pkt(
169
    void *tapdata,
170
    packet_info *pinfo _U_,
171
    epan_dissect_t *edt _U_,
172
    const void *data,
173
    tap_flags_t flags _U_
174
) {
175
    struct f5fileinfo_tap_data *s;
176
    struct f5fileinfo_tap_data *fromtap;
177
178
    s = (struct f5fileinfo_tap_data *)tapdata;
179
    fromtap = (struct f5fileinfo_tap_data *)data;
180
    if(fromtap->magic != F5FILEINFO_TAP_MAGIC) {
181
        /* Magic numbers do not match.  f5ethtrailer plugin was compiled from
182
         * different source than this plugin. */
183
        return(TAP_PACKET_DONT_REDRAW);
184
    }
185
    if (s->ver[0] == fromtap->ver[0] &&
186
        s->ver[1] == fromtap->ver[1] &&
187
        s->ver[2] == fromtap->ver[2] &&
188
        s->ver[3] == fromtap->ver[3] &&
189
        s->ver[4] == fromtap->ver[4] &&
190
        s->ver[5] == fromtap->ver[5])
191
    {
192
        return(TAP_PACKET_DONT_REDRAW);
193
    }
194
    s->ver[0] = fromtap->ver[0];
195
    s->ver[1] = fromtap->ver[1];
196
    s->ver[2] = fromtap->ver[2];
197
    s->ver[3] = fromtap->ver[3];
198
    s->ver[4] = fromtap->ver[4];
199
    s->ver[5] = fromtap->ver[5];
200
#   ifdef F5FILEINFO_TAP_POST_FUNC
201
        F5FILEINFO_TAP_POST_FUNC(s);
202
#   endif
203
    return(TAP_PACKET_REDRAW);
204
} /* f5fileinfo_tap_pkt() */
205
206
207
#define F5FILEINFO_TAP_LISTEN(a) \
208
    register_tap_listener("f5fileinfo", (a), NULL, TL_REQUIRES_NOTHING, f5fileinfo_tap_reset, f5fileinfo_tap_pkt, NULL, NULL)
209
210
211
#endif /* ifndef F5INFOTAP_SRC */
212
213
214
#endif /* ifndef _PACKETH_F5ETHTRAILER_H_ */
215
216
/*
217
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
218
 *
219
 * Local variables:
220
 * c-basic-offset: 4
221
 * tab-width: 8
222
 * indent-tabs-mode: nil
223
 * End:
224
 *
225
 * vi: set shiftwidth=4 tabstop=8 expandtab:
226
 * :indentSize=4:tabSize=8:noTabs=true:
227
 */