3 * exported_pdu helper functions
4 * Copyright 2013, Anders Broman <anders-broman@ericsson.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with this program; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/packet.h>
29 #include <epan/exported_pdu.h>
31 #include <epan/dissectors/packet-mtp3.h>
32 #include <epan/dissectors/packet-dvbci.h>
34 GSList *export_pdu_tap_name_list = NULL;
37 * Allocates and fills the exp_pdu_data_t struct according to the wanted_exp_tags
38 * bit field of wanted_exp_tags_len bytes length
39 * tag_type should be either EXP_PDU_TAG_PROTO_NAME or EXP_PDU_TAG_HEUR_PROTO_NAME
40 * proto_name interpretation depends on tag_type value
42 * The tags in the tag buffer SHOULD be added in numerical order.
45 load_export_pdu_tags(packet_info *pinfo, guint tag_type, const char* proto_name,
46 guint8 *wanted_exp_tags, guint16 wanted_exp_tags_len)
48 exp_pdu_data_t *exp_pdu_data;
53 gboolean port_type_defined = FALSE;
55 exp_pdu_data = (exp_pdu_data_t *)g_malloc(sizeof(exp_pdu_data_t));
57 /* If we have a protocol name, calculate the buffer size needed including padding and tag + length */
59 str_len = (int)strlen(proto_name);
61 /* Ensure that tag length is a multiple of 4 bytes */
62 tag_str_len = (str_len + 3) & 0xfffffffc;
63 /* Add Tag + length */
64 tag_buf_size = tag_str_len + 4;
67 /* Check first byte of optional tags bitmap */
68 if (wanted_exp_tags_len >= 1) {
69 if((wanted_exp_tags[0] & EXP_PDU_TAG_IP_SRC_BIT) == EXP_PDU_TAG_IP_SRC_BIT){
70 if(pinfo->net_src.type == AT_IPv4){
71 tag_buf_size += 4 + EXP_PDU_TAG_IPV4_SRC_LEN;
72 }else if(pinfo->net_src.type == AT_IPv6){
73 tag_buf_size += 4 + EXP_PDU_TAG_IPV6_SRC_LEN;
77 if((wanted_exp_tags[0] & EXP_PDU_TAG_IP_DST_BIT) == EXP_PDU_TAG_IP_DST_BIT){
78 if(pinfo->net_dst.type == AT_IPv4){
79 tag_buf_size += 4 + EXP_PDU_TAG_IPV4_DST_LEN;
80 }else if(pinfo->net_dst.type == AT_IPv6){
81 tag_buf_size += 4 + EXP_PDU_TAG_IPV6_DST_LEN;
85 if((wanted_exp_tags[0] & EXP_PDU_TAG_SRC_PORT_BIT) == EXP_PDU_TAG_SRC_PORT_BIT){
86 if (!port_type_defined) {
87 tag_buf_size= tag_buf_size + EXP_PDU_TAG_PORT_TYPE_LEN + 4;
88 port_type_defined = TRUE;
90 tag_buf_size= tag_buf_size + EXP_PDU_TAG_SRC_PORT_LEN + 4;
93 if((wanted_exp_tags[0] & EXP_PDU_TAG_DST_PORT_BIT) == EXP_PDU_TAG_DST_PORT_BIT){
94 if (!port_type_defined) {
95 tag_buf_size= tag_buf_size + EXP_PDU_TAG_PORT_TYPE_LEN + 4;
97 tag_buf_size= tag_buf_size + EXP_PDU_TAG_DST_PORT_LEN + 4;
100 if((wanted_exp_tags[0] & EXP_PDU_TAG_SS7_OPC_BIT) == EXP_PDU_TAG_SS7_OPC_BIT){
101 if(pinfo->src.type == AT_SS7PC){
102 tag_buf_size += 4 + EXP_PDU_TAG_SS7_OPC_LEN;
106 if((wanted_exp_tags[0] & EXP_PDU_TAG_SS7_DPC_BIT) == EXP_PDU_TAG_SS7_DPC_BIT){
107 if(pinfo->dst.type == AT_SS7PC){
108 tag_buf_size += 4 + EXP_PDU_TAG_SS7_DPC_LEN;
112 if((wanted_exp_tags[0] & EXP_PDU_TAG_ORIG_FNO_BIT) == EXP_PDU_TAG_ORIG_FNO_BIT){
113 tag_buf_size= tag_buf_size + EXP_PDU_TAG_ORIG_FNO_LEN + 4;
117 /* Check second byte of optional tags bitmap */
118 if (wanted_exp_tags_len >= 2) {
119 if((wanted_exp_tags[1] & EXP_PDU_TAG_DVBCI_EVT_BIT) == EXP_PDU_TAG_DVBCI_EVT_BIT){
120 tag_buf_size= tag_buf_size + EXP_PDU_TAG_DVBCI_EVT_LEN + 4;
124 /* Add end of options length */
127 exp_pdu_data->tlv_buffer = (guint8 *)g_malloc0(tag_buf_size);
128 exp_pdu_data->tlv_buffer_len = tag_buf_size;
129 port_type_defined = FALSE;
132 exp_pdu_data->tlv_buffer[i] = 0;
134 exp_pdu_data->tlv_buffer[i] = tag_type;
136 exp_pdu_data->tlv_buffer[i] = 0;
138 exp_pdu_data->tlv_buffer[i] = tag_str_len; /* tag length */
140 memcpy(exp_pdu_data->tlv_buffer+i, proto_name, str_len);
145 /* Check first byte of optional tags bitmap */
146 if (wanted_exp_tags_len >= 1) {
147 if((wanted_exp_tags[0] & EXP_PDU_TAG_IP_SRC_BIT) == EXP_PDU_TAG_IP_SRC_BIT){
148 if(pinfo->net_src.type == AT_IPv4){
149 exp_pdu_data->tlv_buffer[i] = 0;
151 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV4_SRC;
153 exp_pdu_data->tlv_buffer[i] = 0;
155 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV4_SRC_LEN; /* tag length */
157 memcpy(exp_pdu_data->tlv_buffer+i, pinfo->net_src.data, EXP_PDU_TAG_IPV4_SRC_LEN);
158 i += EXP_PDU_TAG_IPV4_SRC_LEN;
159 }else if(pinfo->net_src.type == AT_IPv6){
160 exp_pdu_data->tlv_buffer[i] = 0;
162 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV6_SRC;
164 exp_pdu_data->tlv_buffer[i] = 0;
166 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV6_SRC_LEN; /* tag length */
168 memcpy(exp_pdu_data->tlv_buffer+i, pinfo->net_src.data, EXP_PDU_TAG_IPV6_SRC_LEN);
169 i += EXP_PDU_TAG_IPV6_SRC_LEN;
173 if((wanted_exp_tags[0] & EXP_PDU_TAG_IP_DST_BIT) == EXP_PDU_TAG_IP_DST_BIT){
174 if(pinfo->net_dst.type == AT_IPv4){
175 exp_pdu_data->tlv_buffer[i] = 0;
177 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV4_DST;
179 exp_pdu_data->tlv_buffer[i] = 0;
181 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV4_DST_LEN; /* tag length */
183 memcpy(exp_pdu_data->tlv_buffer+i, pinfo->net_dst.data, EXP_PDU_TAG_IPV4_DST_LEN);
184 i += EXP_PDU_TAG_IPV4_DST_LEN;
185 }else if(pinfo->net_dst.type == AT_IPv6){
186 exp_pdu_data->tlv_buffer[i] = 0;
188 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV6_DST;
190 exp_pdu_data->tlv_buffer[i] = 0;
192 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV6_DST_LEN; /* tag length */
194 memcpy(exp_pdu_data->tlv_buffer+i, pinfo->net_dst.data, EXP_PDU_TAG_IPV6_DST_LEN);
195 i += EXP_PDU_TAG_IPV6_DST_LEN;
199 if((wanted_exp_tags[0] & EXP_PDU_TAG_SRC_PORT_BIT) == EXP_PDU_TAG_SRC_PORT_BIT){
200 if (!port_type_defined) {
201 exp_pdu_data->tlv_buffer[i] = 0;
203 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_PORT_TYPE;
205 exp_pdu_data->tlv_buffer[i] = 0;
207 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_PORT_TYPE_LEN; /* tag length */
209 exp_pdu_data->tlv_buffer[i] = (pinfo->ptype & 0xff000000) >> 24;
210 exp_pdu_data->tlv_buffer[i+1] = (pinfo->ptype & 0x00ff0000) >> 16;
211 exp_pdu_data->tlv_buffer[i+2] = (pinfo->ptype & 0x0000ff00) >> 8;
212 exp_pdu_data->tlv_buffer[i+3] = (pinfo->ptype & 0x000000ff);
213 i = i +EXP_PDU_TAG_PORT_TYPE_LEN;
214 port_type_defined = TRUE;
216 exp_pdu_data->tlv_buffer[i] = 0;
218 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_SRC_PORT;
220 exp_pdu_data->tlv_buffer[i] = 0;
222 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_SRC_PORT_LEN; /* tag length */
224 exp_pdu_data->tlv_buffer[i] = (pinfo->srcport & 0xff000000) >> 24;
225 exp_pdu_data->tlv_buffer[i+1] = (pinfo->srcport & 0x00ff0000) >> 16;
226 exp_pdu_data->tlv_buffer[i+2] = (pinfo->srcport & 0x0000ff00) >> 8;
227 exp_pdu_data->tlv_buffer[i+3] = (pinfo->srcport & 0x000000ff);
228 i = i +EXP_PDU_TAG_SRC_PORT_LEN;
231 if((wanted_exp_tags[0] & EXP_PDU_TAG_DST_PORT_BIT) == EXP_PDU_TAG_DST_PORT_BIT){
232 if (!port_type_defined) {
233 exp_pdu_data->tlv_buffer[i] = 0;
235 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_PORT_TYPE;
237 exp_pdu_data->tlv_buffer[i] = 0;
239 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_PORT_TYPE_LEN; /* tag length */
241 exp_pdu_data->tlv_buffer[i] = (pinfo->ptype & 0xff000000) >> 24;
242 exp_pdu_data->tlv_buffer[i+1] = (pinfo->ptype & 0x00ff0000) >> 16;
243 exp_pdu_data->tlv_buffer[i+2] = (pinfo->ptype & 0x0000ff00) >> 8;
244 exp_pdu_data->tlv_buffer[i+3] = (pinfo->ptype & 0x000000ff);
245 i = i +EXP_PDU_TAG_PORT_TYPE_LEN;
247 exp_pdu_data->tlv_buffer[i] = 0;
249 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_DST_PORT;
251 exp_pdu_data->tlv_buffer[i] = 0;
253 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_DST_PORT_LEN; /* tag length */
255 exp_pdu_data->tlv_buffer[i] = (pinfo->destport & 0xff000000) >> 24;
256 exp_pdu_data->tlv_buffer[i+1] = (pinfo->destport & 0x00ff0000) >> 16;
257 exp_pdu_data->tlv_buffer[i+2] = (pinfo->destport & 0x0000ff00) >> 8;
258 exp_pdu_data->tlv_buffer[i+3] = (pinfo->destport & 0x000000ff);
259 i = i +EXP_PDU_TAG_DST_PORT_LEN;
262 if((wanted_exp_tags[0] & EXP_PDU_TAG_SS7_OPC_BIT) == EXP_PDU_TAG_SS7_OPC_BIT){
263 if(pinfo->src.type == AT_SS7PC){
264 const mtp3_addr_pc_t *mtp3_addr = (const mtp3_addr_pc_t *)(pinfo->src.data);
265 exp_pdu_data->tlv_buffer[i] = 0;
267 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_SS7_OPC;
269 exp_pdu_data->tlv_buffer[i] = 0;
271 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_SS7_OPC_LEN; /* tag length */
273 exp_pdu_data->tlv_buffer[i] = (mtp3_addr->pc & 0xff000000) >> 24;
274 exp_pdu_data->tlv_buffer[i+1] = (mtp3_addr->pc & 0x00ff0000) >> 16;
275 exp_pdu_data->tlv_buffer[i+2] = (mtp3_addr->pc & 0x0000ff00) >> 8;
276 exp_pdu_data->tlv_buffer[i+3] = (mtp3_addr->pc & 0x000000ff);
277 exp_pdu_data->tlv_buffer[i+4] = (mtp3_addr->type & 0xff00) >> 8;
278 exp_pdu_data->tlv_buffer[i+5] = (mtp3_addr->type & 0x00ff);
279 exp_pdu_data->tlv_buffer[i+6] = mtp3_addr->ni;
280 i += EXP_PDU_TAG_SS7_OPC_LEN;
284 if((wanted_exp_tags[0] & EXP_PDU_TAG_SS7_DPC_BIT) == EXP_PDU_TAG_SS7_DPC_BIT){
285 if(pinfo->dst.type == AT_SS7PC){
286 const mtp3_addr_pc_t *mtp3_addr = (const mtp3_addr_pc_t *)(pinfo->dst.data);
287 exp_pdu_data->tlv_buffer[i] = 0;
289 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_SS7_DPC;
291 exp_pdu_data->tlv_buffer[i] = 0;
293 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_SS7_DPC_LEN; /* tag length */
295 exp_pdu_data->tlv_buffer[i] = (mtp3_addr->pc & 0xff000000) >> 24;
296 exp_pdu_data->tlv_buffer[i+1] = (mtp3_addr->pc & 0x00ff0000) >> 16;
297 exp_pdu_data->tlv_buffer[i+2] = (mtp3_addr->pc & 0x0000ff00) >> 8;
298 exp_pdu_data->tlv_buffer[i+3] = (mtp3_addr->pc & 0x000000ff);
299 exp_pdu_data->tlv_buffer[i+4] = (mtp3_addr->type & 0xff00) >> 8;
300 exp_pdu_data->tlv_buffer[i+5] = (mtp3_addr->type & 0x00ff);
301 exp_pdu_data->tlv_buffer[i+6] = mtp3_addr->ni;
302 i += EXP_PDU_TAG_SS7_DPC_LEN;
306 if((wanted_exp_tags[0] & EXP_PDU_TAG_ORIG_FNO_BIT) == EXP_PDU_TAG_ORIG_FNO_BIT){
307 exp_pdu_data->tlv_buffer[i] = 0;
309 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_ORIG_FNO;
311 exp_pdu_data->tlv_buffer[i] = 0;
313 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_ORIG_FNO_LEN; /* tag length */
315 exp_pdu_data->tlv_buffer[i] = (pinfo->fd->num & 0xff000000) >> 24;
316 exp_pdu_data->tlv_buffer[i+1] = (pinfo->fd->num & 0x00ff0000) >> 16;
317 exp_pdu_data->tlv_buffer[i+2] = (pinfo->fd->num & 0x0000ff00) >> 8;
318 exp_pdu_data->tlv_buffer[i+3] = (pinfo->fd->num & 0x000000ff);
319 /*i = i +EXP_PDU_TAG_ORIG_FNO_LEN;*/
323 if (wanted_exp_tags_len >= 2) {
324 if((wanted_exp_tags[1] & EXP_PDU_TAG_DVBCI_EVT_BIT) == EXP_PDU_TAG_DVBCI_EVT_BIT){
325 exp_pdu_data->tlv_buffer[i] = 0;
327 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_DVBCI_EVT;
329 exp_pdu_data->tlv_buffer[i] = 0;
331 exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_DVBCI_EVT_LEN;
333 exp_pdu_data->tlv_buffer[i] = dvbci_get_evt_from_addrs(pinfo);
341 register_export_pdu_tap(const char *name)
343 gchar *tap_name = g_strdup(name);
344 export_pdu_tap_name_list = g_slist_prepend(export_pdu_tap_name_list, tap_name);
345 return register_tap(tap_name);
349 gint sort_pdu_tap_name_list(gconstpointer a, gconstpointer b)
351 return g_strcmp0((const char *)a, (const char*)b);
355 get_export_pdu_tap_list(void)
357 export_pdu_tap_name_list = g_slist_sort(export_pdu_tap_name_list, sort_pdu_tap_name_list);
358 return export_pdu_tap_name_list;
362 * Editor modelines - http://www.wireshark.org/tools/modelines.html
367 * indent-tabs-mode: t
370 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
371 * :indentSize=8:tabSize=8:noTabs=false: