forked from osmocom/wireshark
Add a helper function to load tags, handle IP and port tags and
copy packet comments. svn path=/trunk/; revision=49184
This commit is contained in:
parent
880fc1ba7f
commit
1ab65e7146
|
@ -36,9 +36,13 @@ void proto_reg_handoff_exported_pdu(void);
|
|||
static gint exported_pdu_tap = -1;
|
||||
|
||||
static int proto_exported_pdu = -1;
|
||||
static int proto_exported_pdu_tag = -1;
|
||||
static int proto_exported_pdu_tag_len = -1;
|
||||
static int proto_exported_pdu_prot_name = -1;
|
||||
static int hf_exported_pdu_tag = -1;
|
||||
static int hf_exported_pdu_tag_len = -1;
|
||||
static int hf_exported_pdu_prot_name = -1;
|
||||
static int hf_exported_pdu_ipv4_src = -1;
|
||||
static int hf_exported_pdu_ipv4_dst = -1;
|
||||
static int hf_exported_pdu_src_port = -1;
|
||||
static int hf_exported_pdu_dst_port = -1;
|
||||
|
||||
|
||||
/* Initialize the subtree pointers */
|
||||
|
@ -81,6 +85,7 @@ dissect_exported_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
int tag_len;
|
||||
int next_proto_type = -1;
|
||||
char *proto_name = NULL;
|
||||
const guchar *src_addr, *dst_addr;
|
||||
|
||||
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Exported PDU");
|
||||
|
||||
|
@ -90,9 +95,9 @@ dissect_exported_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
exported_pdu_tree = proto_item_add_subtree(ti, ett_exported_pdu);
|
||||
|
||||
tag = tvb_get_ntohs(tvb, offset);
|
||||
proto_tree_add_item(exported_pdu_tree, proto_exported_pdu_tag, tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_tag, tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
offset+=2;
|
||||
proto_tree_add_item(exported_pdu_tree, proto_exported_pdu_tag_len, tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_tag_len, tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
tag_len = tvb_get_ntohs(tvb, offset);
|
||||
offset+=2;
|
||||
while(tag != 0){
|
||||
|
@ -100,16 +105,36 @@ dissect_exported_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
|||
case EXP_PDU_TAG_PROTO_NAME:
|
||||
next_proto_type = EXPORTED_PDU_NEXT_PROTO_STR;
|
||||
proto_name = tvb_get_ephemeral_string(tvb, offset, tag_len);
|
||||
proto_tree_add_item(exported_pdu_tree, proto_exported_pdu_prot_name, tvb, offset, tag_len, ENC_BIG_ENDIAN);
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_prot_name, tvb, offset, tag_len, ENC_BIG_ENDIAN);
|
||||
break;
|
||||
case EXP_PDU_TAG_IPV4_SRC:
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_ipv4_src, tvb, offset, 4, ENC_BIG_ENDIAN);
|
||||
src_addr = tvb_get_ptr(tvb, offset, 4);
|
||||
SET_ADDRESS(&pinfo->net_src, AT_IPv4, 4, src_addr);
|
||||
SET_ADDRESS(&pinfo->src, AT_IPv4, 4, src_addr);
|
||||
break;
|
||||
case EXP_PDU_TAG_IPV4_DST:
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_ipv4_dst, tvb, offset, 4, ENC_BIG_ENDIAN);
|
||||
dst_addr = tvb_get_ptr(tvb, offset, 4);
|
||||
SET_ADDRESS(&pinfo->net_dst, AT_IPv4, 4, dst_addr);
|
||||
SET_ADDRESS(&pinfo->dst, AT_IPv4, 4, dst_addr);
|
||||
break;
|
||||
case EXP_PDU_TAG_SRC_PORT:
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_src_port, tvb, offset, 4, ENC_BIG_ENDIAN);
|
||||
pinfo->srcport = tvb_get_ntohl(tvb,offset);
|
||||
break;
|
||||
case EXP_PDU_TAG_DST_PORT:
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_dst_port, tvb, offset, 4, ENC_BIG_ENDIAN);
|
||||
pinfo->destport = tvb_get_ntohl(tvb,offset);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
break;
|
||||
};
|
||||
offset = offset + tag_len;
|
||||
proto_tree_add_item(exported_pdu_tree, proto_exported_pdu_tag, tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_tag, tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
tag = tvb_get_ntohs(tvb, offset);
|
||||
offset+=2;
|
||||
proto_tree_add_item(exported_pdu_tree, proto_exported_pdu_tag_len, tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
proto_tree_add_item(exported_pdu_tree, hf_exported_pdu_tag_len, tvb, offset, 2, ENC_BIG_ENDIAN);
|
||||
tag_len = tvb_get_ntohs(tvb, offset);
|
||||
offset+=2;
|
||||
}
|
||||
|
@ -136,21 +161,41 @@ proto_register_exported_pdu(void)
|
|||
/*module_t *exported_pdu_module;*/
|
||||
|
||||
static hf_register_info hf[] = {
|
||||
{ &proto_exported_pdu_tag,
|
||||
{ &hf_exported_pdu_tag,
|
||||
{ "Tag", "exported_pdu.tag",
|
||||
FT_UINT16, BASE_DEC, VALS(exported_pdu_tag_vals), 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &proto_exported_pdu_tag_len,
|
||||
{ &hf_exported_pdu_tag_len,
|
||||
{ "Length", "exported_pdu.tag_len",
|
||||
FT_UINT16, BASE_DEC, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &proto_exported_pdu_prot_name,
|
||||
{ &hf_exported_pdu_prot_name,
|
||||
{ "Protocol name", "exported_pdu.prot_name",
|
||||
FT_STRING, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_exported_pdu_ipv4_src,
|
||||
{ "IPv4 SRC", "exported_pdu.ipv4_src",
|
||||
FT_IPv4, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_exported_pdu_ipv4_dst,
|
||||
{ "IPv4 DST", "exported_pdu.ipv4_dst",
|
||||
FT_IPv4, BASE_NONE, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_exported_pdu_src_port,
|
||||
{ "Src Port", "exported_pdu.src_port",
|
||||
FT_UINT16, BASE_DEC, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
{ &hf_exported_pdu_dst_port,
|
||||
{ "Dst Port", "exported_pdu.dst_port",
|
||||
FT_UINT16, BASE_DEC, NULL, 0,
|
||||
NULL, HFILL }
|
||||
},
|
||||
};
|
||||
|
||||
/* Setup protocol subtree array */
|
||||
|
|
|
@ -968,6 +968,7 @@ sip_init_protocol(void)
|
|||
static void
|
||||
export_sip_pdu(packet_info *pinfo, tvbuff_t *tvb)
|
||||
{
|
||||
#if 0
|
||||
exp_pdu_data_t *exp_pdu_data;
|
||||
|
||||
exp_pdu_data = (exp_pdu_data_t *)g_malloc(sizeof(exp_pdu_data_t));
|
||||
|
@ -993,6 +994,17 @@ export_sip_pdu(packet_info *pinfo, tvbuff_t *tvb)
|
|||
exp_pdu_data->tlv_buffer[9] = 0;
|
||||
exp_pdu_data->tlv_buffer[10] = 0;
|
||||
exp_pdu_data->tlv_buffer[11] = 0;
|
||||
#endif
|
||||
exp_pdu_data_t *exp_pdu_data;
|
||||
guint32 tags_bit_field;
|
||||
|
||||
tags_bit_field = EXP_PDU_TAG_IP_SRC_BIT + EXP_PDU_TAG_IP_DST_BIT + EXP_PDU_TAG_SRC_PORT_BIT+
|
||||
EXP_PDU_TAG_DST_PORT_BIT;
|
||||
|
||||
exp_pdu_data = load_export_pdu_tags(pinfo, "sip", -1, tags_bit_field);
|
||||
|
||||
exp_pdu_data->tvb_length = tvb_length(tvb);
|
||||
exp_pdu_data->pdu_tvb = tvb;
|
||||
|
||||
tap_queue_packet(exported_pdu_tap, pinfo, exp_pdu_data);
|
||||
|
||||
|
|
|
@ -0,0 +1,188 @@
|
|||
/*
|
||||
* exported_pdu.c
|
||||
* exported_pdu helper functions
|
||||
* Copyright 2013, Anders Broman <anders-broman@ericsson.com>
|
||||
*
|
||||
* $Id$
|
||||
*
|
||||
* Wireshark - Network traffic analyzer
|
||||
* By Gerald Combs <gerald@wireshark.org>
|
||||
* Copyright 1998 Gerald Combs
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <glib.h>
|
||||
|
||||
#include <epan/packet.h>
|
||||
#include <epan/exported_pdu.h>
|
||||
|
||||
/**
|
||||
* Allcotates and fills the exp_pdu_data_t struct according to the wanted_exp_tags
|
||||
* bit_fileld, if proto_name is != NULL, wtap_encap must be -1 or viceversa
|
||||
*/
|
||||
exp_pdu_data_t *
|
||||
load_export_pdu_tags(packet_info *pinfo, const char* proto_name, int wtap_encap, guint32 tags_bit_field)
|
||||
{
|
||||
exp_pdu_data_t *exp_pdu_data;
|
||||
int tag_buf_size = 0;
|
||||
int str_len = 0;
|
||||
int tag_str_len = 0;
|
||||
int i = 0;
|
||||
guint32 padding = 0;
|
||||
|
||||
exp_pdu_data = (exp_pdu_data_t *)g_malloc(sizeof(exp_pdu_data_t));
|
||||
|
||||
/* If we have a protocol name, calculate the buffersize needed including padding and tag + length */
|
||||
if(proto_name){
|
||||
str_len = (int)strlen(proto_name);
|
||||
|
||||
/* Add padding if needed */
|
||||
if(str_len % 4){
|
||||
tag_str_len = str_len + (4 - str_len % 4);
|
||||
}
|
||||
/* Add Tag + length */
|
||||
tag_buf_size = tag_str_len + 4;
|
||||
}
|
||||
|
||||
|
||||
if((tags_bit_field & EXP_PDU_TAG_IP_SRC_BIT) == EXP_PDU_TAG_IP_SRC_BIT){
|
||||
/* tag+length */
|
||||
tag_buf_size+=4;
|
||||
if(pinfo->net_src.type == AT_IPv4){
|
||||
tag_buf_size = tag_buf_size + EXP_PDU_TAG_IPV4_SRC_LEN;
|
||||
}else{
|
||||
tag_buf_size = tag_buf_size + EXP_PDU_TAG_IPV6_SRC_LEN;
|
||||
}
|
||||
}
|
||||
|
||||
if((tags_bit_field & EXP_PDU_TAG_IP_DST_BIT) == EXP_PDU_TAG_IP_DST_BIT){
|
||||
/* tag+length */
|
||||
tag_buf_size+=4;
|
||||
if(pinfo->net_src.type == AT_IPv4){
|
||||
tag_buf_size = tag_buf_size + EXP_PDU_TAG_IPV4_DST_LEN;
|
||||
}else{
|
||||
tag_buf_size = tag_buf_size + EXP_PDU_TAG_IPV6_DST_LEN;
|
||||
}
|
||||
}
|
||||
|
||||
if((tags_bit_field & EXP_PDU_TAG_SRC_PORT_BIT) == EXP_PDU_TAG_SRC_PORT_BIT){
|
||||
tag_buf_size= tag_buf_size + EXP_PDU_TAG_SRC_PORT_LEN + 4;
|
||||
}
|
||||
|
||||
if((tags_bit_field & EXP_PDU_TAG_DST_PORT_BIT) == EXP_PDU_TAG_DST_PORT_BIT){
|
||||
tag_buf_size= tag_buf_size + EXP_PDU_TAG_DST_PORT_LEN + 4;
|
||||
}
|
||||
|
||||
/* Add end of options length */
|
||||
tag_buf_size+=4;
|
||||
|
||||
exp_pdu_data->tlv_buffer = (guint8 *)g_malloc0(tag_buf_size);
|
||||
exp_pdu_data->tlv_buffer_len = tag_buf_size;
|
||||
|
||||
if(proto_name){
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_PROTO_NAME;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = tag_str_len; /* tag length */
|
||||
i++;
|
||||
memcpy(exp_pdu_data->tlv_buffer+i, proto_name, str_len);
|
||||
i = i + tag_str_len;
|
||||
|
||||
}
|
||||
|
||||
if((tags_bit_field & EXP_PDU_TAG_IP_SRC_BIT) == EXP_PDU_TAG_IP_SRC_BIT){
|
||||
if(pinfo->net_src.type == AT_IPv4){
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV4_SRC;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV4_SRC_LEN; /* tag length */
|
||||
i++;
|
||||
}else{
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV6_SRC;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV6_SRC_LEN; /* tag length */
|
||||
i++;
|
||||
}
|
||||
|
||||
memcpy(exp_pdu_data->tlv_buffer+i, pinfo->net_src.data, pinfo->net_src.len);
|
||||
i = i + pinfo->net_src.len;
|
||||
}
|
||||
|
||||
if((tags_bit_field & EXP_PDU_TAG_IP_DST_BIT) == EXP_PDU_TAG_IP_DST_BIT){
|
||||
if(pinfo->net_dst.type == AT_IPv4){
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV4_DST;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV4_DST_LEN; /* tag length */
|
||||
i++;
|
||||
}else{
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV6_DST;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_IPV6_DST_LEN; /* tag length */
|
||||
i++;
|
||||
}
|
||||
|
||||
memcpy(exp_pdu_data->tlv_buffer+i, pinfo->net_dst.data, pinfo->net_dst.len);
|
||||
i = i + pinfo->net_src.len;
|
||||
}
|
||||
|
||||
if((tags_bit_field & EXP_PDU_TAG_SRC_PORT_BIT) == EXP_PDU_TAG_SRC_PORT_BIT){
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_SRC_PORT;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_SRC_PORT_LEN; /* tag length */
|
||||
i++;
|
||||
memcpy(exp_pdu_data->tlv_buffer+i, &pinfo->srcport, EXP_PDU_TAG_SRC_PORT_LEN);
|
||||
i = i +EXP_PDU_TAG_SRC_PORT_LEN;
|
||||
}
|
||||
|
||||
if((tags_bit_field & EXP_PDU_TAG_DST_PORT_BIT) == EXP_PDU_TAG_DST_PORT_BIT){
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_DST_PORT;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = 0;
|
||||
i++;
|
||||
exp_pdu_data->tlv_buffer[i] = EXP_PDU_TAG_DST_PORT_LEN; /* tag length */
|
||||
i++;
|
||||
memcpy(exp_pdu_data->tlv_buffer+i, &pinfo->destport, EXP_PDU_TAG_DST_PORT_LEN);
|
||||
i = i +EXP_PDU_TAG_DST_PORT_LEN;
|
||||
}
|
||||
|
||||
return exp_pdu_data;
|
||||
|
||||
}
|
|
@ -78,7 +78,11 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, co
|
|||
pkthdr.pkt_encap = exp_pdu_tap_data->pkt_encap;
|
||||
pkthdr.interface_id = 0;
|
||||
pkthdr.presence_flags = 0;
|
||||
pkthdr.opt_comment = NULL;
|
||||
if(pinfo->fd->opt_comment == NULL){
|
||||
pkthdr.opt_comment = NULL;
|
||||
}else{
|
||||
pkthdr.opt_comment = g_strdup(pinfo->fd->opt_comment);
|
||||
}
|
||||
pkthdr.drop_count = 0;
|
||||
pkthdr.pack_flags = 0;
|
||||
pkthdr.presence_flags = WTAP_HAS_CAP_LEN|WTAP_HAS_INTERFACE_ID|WTAP_HAS_TS|WTAP_HAS_PACK_FLAGS;
|
||||
|
@ -86,6 +90,7 @@ export_pdu_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_, co
|
|||
wtap_dump(exp_pdu_tap_data->wdh, &pkthdr, packet_buf, &err);
|
||||
|
||||
g_free(packet_buf);
|
||||
g_free(pkthdr.opt_comment);
|
||||
|
||||
return FALSE; /* Do not redraw */
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue