Fix some bugs & do extensive cleanup;

Bugs fixed:
 - Calling col_...() fcns or dissectors under 'if (tree)'
 - Potential buffer overflows (if bad data)
 - Misc incorrect data display issues
Cleanup including;
 - Remove unneeded #includes
 - Fix excessive use of value_strings
 - Use extended value_strings & val_to_str_(ext_)const as appropriate
 - Optimize repeated fetches of the same data from a tvb
 - Do general code simplification
 - Remove or #if 0 unused code;
 - Add XXX comments for code which may be incorrect
 - Remove unneeded prefs callback to proto_reg_handoff...()
 - Remove unneeded use of check_col()
 - Define several functions as static
 - Move proto_reg_handoff...() to the end of the file
 - Fix whitespace (including "4 space tabs")
 - ...

svn path=/trunk/; revision=43129
This commit is contained in:
Bill Meier 2012-06-06 04:54:47 +00:00
parent e63f70cfc2
commit 57c6467b81
6 changed files with 7175 additions and 7064 deletions

File diff suppressed because it is too large Load Diff

View File

@ -27,150 +27,146 @@
#include "config.h"
#endif
#include <glib.h>
#include "epan/packet.h"
#include "epan/prefs.h"
#include "epan/tap.h"
#include "epan/value_string.h"
#include "epan/dissectors/packet-rtp.h"
#include "epan/dissectors/packet-rtcp.h"
#include <string.h>
#include "packet-uaudp.h"
/*-----------------------------------------------------------------------------
GLOBALS
---------------------------------------------------------------------------*/
static int proto_ua_msg = -1;
static gint ett_ua_msg = -1;
#if 0
static dissector_table_t ua_opcode_dissector_table;
#endif
static int proto_ua_msg = -1;
static gint ett_ua_msg = -1;
e_ua_direction message_direction; /* Uses to determine UA3G messages */
static gboolean setup_conversations_enabled = TRUE;
static dissector_handle_t rtp_handle = NULL;
static dissector_handle_t rtcp_handle = NULL;
static dissector_handle_t noe_handle;
static dissector_handle_t ua3g_handle;
extern gint find_terminal_port(guint port);
extern void dhs2ua(char *p, const char *ptr, int opcode, int length);
extern void ua2dhs(char *p, const char *ptr, int opcode, int length);
static void uadecode(e_ua_direction direction,
proto_tree *tree,
packet_info *pinfo,
tvbuff_t *tvb,
gint offset,
gint opcode,
gint length)
static void uadecode(e_ua_direction direction,
proto_tree *tree,
packet_info *pinfo,
tvbuff_t *tvb,
gint offset,
gint opcode,
gint length)
{
message_direction = direction;
message_direction = direction;
switch(opcode & 0x7f) /* suppression of the CP bit */
{
case 0x15:
case 0x16:
{
call_dissector(find_dissector("noe"),
tvb_new_subset(tvb, offset, length, length),
pinfo,
tree);
break;
}
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07: /* Only UA NOE */
case 0x08: /* Only UA NOE */
case 0x09:
case 0x0A:
case 0x0B:
case 0x0C:
case 0x0D:
case 0x0E:
case 0x0F:
case 0x11:
case 0x12:
case 0x13:
case 0x14:
case 0x17:
case 0x18:
case 0x1F: /* case 0x9F */
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24: /* Only IP NOE */
case 0x25: /* Only IP NOE */
case 0x26:
case 0x27:
case 0x28:
case 0x29:
case 0x2A:
case 0x2B: /* Only UA NOE */
case 0x2C:
case 0x2D:
case 0x2E:
case 0x30:
case 0x31:
case 0x32: /* Only UA NOE */
case 0x33:
case 0x35:
case 0x36: /* IP Phone */
case 0x38:
case 0x39:
case 0x3A:
case 0x3B:
case 0x3C:
case 0x3D:
case 0x3E:
case 0x3F:
case 0x40:
case 0x41:
case 0x42:
case 0x43:
case 0x44:
case 0x45:
case 0x46:
case 0x47:
case 0x48:
case 0x49:
case 0x4A:
case 0x4B:
case 0x4C:
case 0x4D:
case 0x4E:
case 0x4F:
case 0x50: /* Only UA NOE */
{
call_dissector(find_dissector("ua3g"),
tvb_new_subset(tvb, offset, length, length),
pinfo,
tree);
break;
}
default:
{
/* add text to the frame "INFO" column */
if (check_col(pinfo->cinfo, COL_INFO))
col_append_fstr(pinfo->cinfo, COL_INFO, " - UA3G Message ERR: Opcode Unknown");
switch (opcode & 0x7f) /* suppression of the CP bit */
{
case 0x15:
case 0x16:
{
call_dissector(noe_handle,
tvb_new_subset(tvb, offset, length, length),
pinfo,
tree);
break;
}
case 0x00:
case 0x01:
case 0x02:
case 0x03:
case 0x04:
case 0x05:
case 0x06:
case 0x07: /* Only UA NOE */
case 0x08: /* Only UA NOE */
case 0x09:
case 0x0A:
case 0x0B:
case 0x0C:
case 0x0D:
case 0x0E:
case 0x0F:
case 0x11:
case 0x12:
case 0x13:
case 0x14:
case 0x17:
case 0x18:
case 0x1F: /* case 0x9F */
case 0x20:
case 0x21:
case 0x22:
case 0x23:
case 0x24: /* Only IP NOE */
case 0x25: /* Only IP NOE */
case 0x26:
case 0x27:
case 0x28:
case 0x29:
case 0x2A:
case 0x2B: /* Only UA NOE */
case 0x2C:
case 0x2D:
case 0x2E:
case 0x30:
case 0x31:
case 0x32: /* Only UA NOE */
case 0x33:
case 0x35:
case 0x36: /* IP Phone */
case 0x38:
case 0x39:
case 0x3A:
case 0x3B:
case 0x3C:
case 0x3D:
case 0x3E:
case 0x3F:
case 0x40:
case 0x41:
case 0x42:
case 0x43:
case 0x44:
case 0x45:
case 0x46:
case 0x47:
case 0x48:
case 0x49:
case 0x4A:
case 0x4B:
case 0x4C:
case 0x4D:
case 0x4E:
case 0x4F:
case 0x50: /* Only UA NOE */
{
call_dissector(ua3g_handle,
tvb_new_subset(tvb, offset, length, length),
pinfo,
tree);
break;
}
default:
{
/* add text to the frame "INFO" column */
if (check_col(pinfo->cinfo, COL_INFO))
col_append_fstr(pinfo->cinfo, COL_INFO, " - UA3G Message ERR: Opcode Unknown");
proto_tree_add_text(tree,
tvb,
offset,
length,
"Opcode Unknown 0x%02x",
tvb_get_guint8(tvb, (offset + 2)));
break;
}
}
proto_tree_add_text(tree,
tvb,
offset,
length,
"Opcode Unknown 0x%02x",
tvb_get_guint8(tvb, (offset + 2)));
break;
}
}
}
@ -178,100 +174,93 @@ static void uadecode(e_ua_direction direction,
/*-----------------------------------------------------------------------------
UA DISSECTOR
---------------------------------------------------------------------------*/
static void _dissect_ua_msg(tvbuff_t *tvb,
packet_info *pinfo,
proto_tree *tree,
e_ua_direction direction)
static void _dissect_ua_msg(tvbuff_t *tvb,
packet_info *pinfo,
proto_tree *tree,
e_ua_direction direction)
{
proto_item *ua_msg_item = NULL;
proto_tree *ua_msg_tree = NULL;
gint offset = 0;
gint length = 0;
gint opcode = 0;
gint suboffset = 0;
address remote_rtp_addr;
guint32 remote_rtp_port = 0;
gint offset = 0;
proto_item *ua_msg_item;
proto_tree *ua_msg_tree;
if(tree)
{
ua_msg_item = proto_tree_add_protocol_format(tree, proto_ua_msg, tvb, 0, -1,
"Universal Alcatel Protocol, %s",
((direction == SYS_TO_TERM) ?
"System -> Terminal" : "Terminal -> System"));
ua_msg_item = proto_tree_add_protocol_format(tree, proto_ua_msg, tvb, 0, -1,
"Universal Alcatel Protocol, %s",
((direction == SYS_TO_TERM) ?
"System -> Terminal" : "Terminal -> System"));
ua_msg_tree = proto_item_add_subtree(ua_msg_item, ett_ua_msg);
ua_msg_tree = proto_item_add_subtree(ua_msg_item, ett_ua_msg);
while (tvb_offset_exists(tvb, offset))
{
length = (tvb_get_guint8(tvb, offset+0) +
tvb_get_guint8(tvb, offset+1) * 256) + 2;
while (tvb_offset_exists(tvb, offset))
{
gint length;
gint opcode;
opcode = tvb_get_guint8(tvb, offset+2);
length = tvb_get_letohs(tvb, offset) + 2;
opcode = tvb_get_guint8(tvb, offset+2);
/* RTP/RTCP conversation setup */
if(setup_conversations_enabled && opcode==0x13 && tvb_get_guint8(tvb, offset+3)==0x01)
{
/* StartRTP */
suboffset = offset+5;
remote_rtp_addr.data = NULL;
/* RTP/RTCP conversation setup */
if (setup_conversations_enabled && (opcode==0x13) && (tvb_get_guint8(tvb, offset+3)==0x01))
{
address remote_rtp_addr;
guint32 remote_rtp_port;
gint suboffset;
while(suboffset < offset+length)
{
switch(tvb_get_guint8(tvb, suboffset))
{
case 0x00: /* local port */
{
/*local_rtp_port = tvb_get_ntohs(tvb, suboffset+2);*/
break;
}
case 0x01: /* remote IP */
{
remote_rtp_addr.type=AT_IPv4;
remote_rtp_addr.len=4;
remote_rtp_addr.data=tvb_get_ptr(tvb, suboffset+2, 4);
break;
}
case 0x02: /* remote port */
{
remote_rtp_port = tvb_get_ntohs(tvb, suboffset+2);
break;
}
}
remote_rtp_addr.data = NULL;
remote_rtp_port = 0;
suboffset += tvb_get_guint8(tvb, suboffset+1) + 2;
}
/* StartRTP */
suboffset = offset + 5;
if(remote_rtp_addr.data!=NULL && remote_rtp_port!=0)
{
if(rtp_handle)
{
rtp_add_address(pinfo, &remote_rtp_addr, remote_rtp_port, 0,
"UA", pinfo->fd->num, 0, NULL);
}
if(rtcp_handle)
{
rtcp_add_address(pinfo, &remote_rtp_addr, remote_rtp_port+1, 0,
"UA", pinfo->fd->num);
}
}
}
while (suboffset < offset+length)
{
switch (tvb_get_guint8(tvb, suboffset))
{
case 0x00: /* local port */
{
/*local_rtp_port = tvb_get_ntohs(tvb, suboffset+2);*/
break;
}
case 0x01: /* remote IP */
{
remote_rtp_addr.type = AT_IPv4;
remote_rtp_addr.len = 4;
remote_rtp_addr.data = tvb_get_ptr(tvb, suboffset+2, 4);
break;
}
case 0x02: /* remote port */
{
remote_rtp_port = tvb_get_ntohs(tvb, suboffset+2);
break;
}
}
uadecode(direction, ua_msg_tree, pinfo, tvb, offset, opcode, length);
suboffset += tvb_get_guint8(tvb, suboffset+1) + 2;
}
offset += length;
}
}
if ((remote_rtp_addr.data != NULL) && (remote_rtp_port != 0))
{
rtp_add_address(pinfo, &remote_rtp_addr, remote_rtp_port, 0,
"UA", pinfo->fd->num, 0, NULL);
rtcp_add_address(pinfo, &remote_rtp_addr, remote_rtp_port+1, 0,
"UA", pinfo->fd->num);
}
}
uadecode(direction, ua_msg_tree, pinfo, tvb, offset, opcode, length);
offset += length;
}
}
static void dissect_ua_sys_to_term(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
_dissect_ua_msg(tvb, pinfo, tree, SYS_TO_TERM);
_dissect_ua_msg(tvb, pinfo, tree, SYS_TO_TERM);
}
static void dissect_ua_term_to_sys(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
_dissect_ua_msg(tvb, pinfo, tree, TERM_TO_SYS);
_dissect_ua_msg(tvb, pinfo, tree, TERM_TO_SYS);
}
@ -279,56 +268,56 @@ static void dissect_ua_term_to_sys(tvbuff_t *tvb, packet_info *pinfo, proto_tree
DISSECTORS REGISTRATION FUNCTIONS
---------------------------------------------------------------------------*/
void proto_reg_handoff_ua_msg(void)
{
static gboolean prefs_initialized = FALSE;
dissector_handle_t handle_ua_msg;
if(!prefs_initialized)
{
/* hooking of UA on UAUDP */
register_dissector_table("uaudp.opcode",
"UAUDP opcode",
FT_UINT8,
BASE_DEC);
handle_ua_msg = find_dissector("ua_sys_to_term");
dissector_add_uint("uaudp.opcode", UAUDP_DATA, handle_ua_msg);
handle_ua_msg = find_dissector("ua_term_to_sys");
dissector_add_uint("uaudp.opcode", UAUDP_DATA, handle_ua_msg);
prefs_initialized = TRUE;
}
}
void proto_register_ua_msg(void)
{
module_t *ua_msg_module;
module_t *ua_msg_module;
static gint *ett[] =
{
&ett_ua_msg,
};
static gint *ett[] =
{
&ett_ua_msg,
};
/* used for StartRTP conversation setup */
rtp_handle = find_dissector("rtp");
rtcp_handle = find_dissector("rtcp");
/* UA dissector registration */
proto_ua_msg = proto_register_protocol("Universal Alcatel Protocol", "UA", "ua");
/* UA dissector registration */
proto_ua_msg = proto_register_protocol("Universal Alcatel Protocol", "UA", "ua");
register_dissector("ua_sys_to_term", dissect_ua_sys_to_term, proto_ua_msg);
register_dissector("ua_term_to_sys", dissect_ua_term_to_sys, proto_ua_msg);
register_dissector("ua_sys_to_term", dissect_ua_sys_to_term, proto_ua_msg);
register_dissector("ua_term_to_sys", dissect_ua_term_to_sys, proto_ua_msg);
/* Common subtree array registration */
proto_register_subtree_array(ett, array_length(ett));
/* Common subtree array registration */
proto_register_subtree_array(ett, array_length(ett));
/* Register preferences */
ua_msg_module = prefs_register_protocol(proto_ua_msg, NULL);
prefs_register_bool_preference(ua_msg_module, "setup_conversations",
"Setup RTP/RTCP conversations on Start RTP",
"Setup RTP/RTCP conversations when parsing Start RTP messages",
&setup_conversations_enabled);
}
void proto_reg_handoff_ua_msg(void)
{
#if 0 /* Future */
dissector_handle_t handle_ua_msg;
/* hooking of UA on UAUDP */
/* XXX: The following is NG since the same 'pattern' is added twice */
handle_ua_msg = find_dissector("ua_sys_to_term");
dissector_add_uint("uaudp.opcode", UAUDP_DATA, handle_ua_msg);
handle_ua_msg = find_dissector("ua_term_to_sys");
dissector_add_uint("uaudp.opcode", UAUDP_DATA, handle_ua_msg);
/* For hooking dissectors to UA */
ua_opcode_dissector_table =
register_dissector_table("ua.opcode",
"ua.opcode",
FT_UINT8,
BASE_HEX);
#endif
noe_handle = find_dissector("noe");
ua3g_handle = find_dissector("ua3g");
/* Register preferences */
ua_msg_module = prefs_register_protocol(proto_ua_msg, proto_reg_handoff_ua_msg);
prefs_register_bool_preference(ua_msg_module, "setup_conversations",
"Setup RTP/RTCP conversations on Start RTP",
"Setup RTP/RTCP conversations when parsing Start RTP messages",
&setup_conversations_enabled);
}

File diff suppressed because it is too large Load Diff

View File

@ -27,548 +27,500 @@
# include "config.h"
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#include "packet-uaudp.h"
#include <string.h>
#include <glib.h>
#include "epan/packet.h"
#include "epan/prefs.h"
#include "epan/tap.h"
#include "epan/value_string.h"
#include "packet-uaudp.h"
void proto_reg_handoff_uasip(void);
gboolean str_to_ipaddr(const gchar *addr, guint8 *ad);
static tap_struct_uaudp ua_tap_info;
static int uasip_tap = -1;
static int proto_uasip = -1;
static int hf_uasip_opcode = -1;
static int hf_uasip_version = -1;
static int hf_uasip_window_size = -1;
static int hf_uasip_mtu = -1;
static int hf_uasip_udp_lost = -1;
static int hf_uasip_udp_lost_reinit = -1;
static int hf_uasip_keepalive = -1;
static int hf_uasip_qos_ip_tos = -1;
static int hf_uasip_qos_8021_vlid = -1;
static int hf_uasip_qos_8021_pri = -1;
static int hf_uasip_expseq = -1;
static int hf_uasip_sntseq = -1;
static gint ett_uasip = -1;
#if 0
static int uasip_tap = -1;
#endif
static int proto_uasip = -1;
static int hf_uasip_opcode = -1;
static int hf_uasip_version = -1;
static int hf_uasip_window_size = -1;
static int hf_uasip_mtu = -1;
static int hf_uasip_udp_lost = -1;
static int hf_uasip_udp_lost_reinit = -1;
static int hf_uasip_keepalive = -1;
static int hf_uasip_qos_ip_tos = -1;
static int hf_uasip_qos_8021_vlid = -1;
static int hf_uasip_qos_8021_pri = -1;
static int hf_uasip_expseq = -1;
static int hf_uasip_sntseq = -1;
static gint ett_uasip = -1;
static guint8 proxy_ipaddr[4];
static const char* pref_proxy_ipaddr_s = NULL;
static gboolean use_proxy_ipaddr = FALSE;
static gboolean noesip_enabled = FALSE;
#define UAUDP_CONNECT_VERSION 0x00
#define UAUDP_CONNECT_WINDOW_SIZE 0x01
#define UAUDP_CONNECT_MTU 0x02
#define UAUDP_CONNECT_UDP_LOST 0x03
#define UAUDP_CONNECT_UDP_LOST_REINIT 0x04
#define UAUDP_CONNECT_KEEPALIVE 0x05
#define UAUDP_CONNECT_QOS_IP_TOS 0x06
#define UAUDP_CONNECT_QOS_8021_VLID 0x07
#define UAUDP_CONNECT_QOS_8021_PRI 0x08
static const value_string uasip_opcode_str[] =
{
{ UAUDP_CONNECT, "Connect" },
{ UAUDP_CONNECT_ACK, "Connect ACK" },
{ UAUDP_RELEASE, "Release" },
{ UAUDP_RELEASE_ACK, "Release ACK" },
{ UAUDP_KEEPALIVE, "Keepalive" },
{ UAUDP_KEEPALIVE_ACK, "Keepalive ACK" },
{ UAUDP_NACK, "NACK" },
{ UAUDP_DATA, "DATA" },
{ 0, NULL }
};
static const value_string uasip_connect_vals[] =
{
{ UAUDP_CONNECT_VERSION, "Version" },
{ UAUDP_CONNECT_WINDOW_SIZE, "Window Size" },
{ UAUDP_CONNECT_MTU, "MTU" },
{ UAUDP_CONNECT_UDP_LOST, "UDP lost" },
{ UAUDP_CONNECT_UDP_LOST_REINIT, "UDP lost reinit" },
{ UAUDP_CONNECT_KEEPALIVE, "Keepalive" },
{ UAUDP_CONNECT_QOS_IP_TOS, "QoS IP TOS" },
{ UAUDP_CONNECT_QOS_8021_VLID, "QoS 802.1 VLID" },
{ UAUDP_CONNECT_QOS_8021_PRI, "QoS 802.1 PRI"},
{ 0, NULL }
};
static gboolean noesip_enabled = FALSE;
static dissector_handle_t ua_sys_to_term_handle;
static dissector_handle_t ua_term_to_sys_handle;
gboolean str_to_ipaddr(const gchar *addr, guint8 *ad)
/* XXX: Presumably there's a util function for this */
static gboolean str_to_ipaddr(const gchar *addr, guint8 *ad)
{
int i = 0;
const gchar *p = addr;
guint32 value;
int i = 0;
const gchar *p = addr;
guint32 value;
if (addr == NULL)
{
return FALSE;
}
for (i = 0; i < 4; i++)
{
value = 0;
while (*p != '.' && *p != '\0')
{
value = value * 10 + (*p - '0');
p++;
}
if(value > 255)
{
return FALSE;
}
ad[i] = value;
p++;
}
if (addr == NULL)
{
return FALSE;
}
return TRUE;
for (i = 0; i < 4; i++)
{
value = 0;
while (*p != '.' && *p != '\0')
{
value = value * 10 + (*p - '0');
p++;
}
if (value > 255)
{
return FALSE;
}
ad[i] = value;
p++;
}
return TRUE;
}
static void rTLV(proto_tree *tree, int *V, tvbuff_t *tvb, gint offset, gint8 L)
{
switch(L)
{
case 1:
proto_tree_add_uint(tree, *V, tvb, offset, L+2, tvb_get_guint8(tvb, offset+2));
break;
case 2:
proto_tree_add_uint(tree, *V, tvb, offset, L+2, tvb_get_ntohs(tvb, offset+2));
break;
case 3:
proto_tree_add_uint(tree, *V, tvb, offset, L+2, tvb_get_ntoh24(tvb, offset+2));
break;
case 4:
proto_tree_add_uint(tree, *V, tvb, offset, L+2, tvb_get_ntohl(tvb, offset+2));
break;
default:
break;
}
switch (L)
{
case 1:
proto_tree_add_uint(tree, *V, tvb, offset, L+2, tvb_get_guint8(tvb, offset+2));
break;
case 2:
proto_tree_add_uint(tree, *V, tvb, offset, L+2, tvb_get_ntohs(tvb, offset+2));
break;
case 3:
proto_tree_add_uint(tree, *V, tvb, offset, L+2, tvb_get_ntoh24(tvb, offset+2));
break;
case 4:
proto_tree_add_uint(tree, *V, tvb, offset, L+2, tvb_get_ntohl(tvb, offset+2));
break;
default:
break;
}
}
static void _dissect_uasip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, e_ua_direction direction)
{
proto_item *uasip_item = NULL;
proto_tree *uasip_tree = NULL;
gint offset = 0;
guint8 opcode = 0;
proto_item *uasip_item;
proto_tree *uasip_tree;
guint8 opcode;
gint offset = 0;
if (noesip_enabled)
{
if (check_col(pinfo->cinfo, COL_PROTOCOL))
{
col_append_str(pinfo->cinfo, COL_PROTOCOL, "/NOE");
}
}
else
{
if (check_col(pinfo->cinfo, COL_PROTOCOL))
{
col_append_str(pinfo->cinfo, COL_PROTOCOL, "/DL");
}
}
if (noesip_enabled)
{
col_append_str(pinfo->cinfo, COL_PROTOCOL, "/NOE");
}
else
{
col_append_str(pinfo->cinfo, COL_PROTOCOL, "/DL");
}
opcode = tvb_get_guint8(tvb, offset);
offset++;
opcode = tvb_get_guint8(tvb, offset);
offset++;
ua_tap_info.opcode = opcode;
ua_tap_info.expseq = 0;
ua_tap_info.sntseq = 0;
ua_tap_info.opcode = opcode;
ua_tap_info.expseq = 0;
ua_tap_info.sntseq = 0;
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str(opcode, uasip_opcode_str, "unknown (0x%02x)"));
}
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_fstr(pinfo->cinfo, COL_INFO, "%s", val_to_str_ext(opcode, &uaudp_opcode_str_ext, "unknown (0x%02x)"));
}
uasip_item = proto_tree_add_protocol_format(tree, proto_uasip, tvb, 0, 5, "SIP/NOE Protocol, %s", val_to_str(opcode, uasip_opcode_str, "unknown (0x%02x)"));
uasip_tree = proto_item_add_subtree(uasip_item, ett_uasip);
proto_tree_add_uint(uasip_tree, hf_uasip_opcode, tvb, 0, 1, opcode);
uasip_item = proto_tree_add_protocol_format(tree, proto_uasip, tvb, 0, 5,
"SIP/NOE Protocol, %s",
val_to_str_ext(opcode, &uaudp_opcode_str_ext, "unknown (0x%02x)"));
uasip_tree = proto_item_add_subtree(uasip_item, ett_uasip);
proto_tree_add_uint(uasip_tree, hf_uasip_opcode, tvb, 0, 1, opcode);
switch(opcode)
{
case UAUDP_CONNECT:
{
while(tvb_offset_exists(tvb, offset))
{
guint8 T = tvb_get_guint8(tvb, offset+0);
guint8 L = tvb_get_guint8(tvb, offset+1);
switch(opcode)
{
case UAUDP_CONNECT:
{
if (!tree)
break;
while(tvb_offset_exists(tvb, offset))
{
guint8 T = tvb_get_guint8(tvb, offset+0);
guint8 L = tvb_get_guint8(tvb, offset+1);
switch(T)
{
case UAUDP_CONNECT_VERSION:
rTLV(uasip_tree, &hf_uasip_version, tvb, offset, L);
break;
case UAUDP_CONNECT_WINDOW_SIZE:
rTLV(uasip_tree, &hf_uasip_window_size, tvb, offset, L);
break;
case UAUDP_CONNECT_MTU:
rTLV(uasip_tree, &hf_uasip_mtu, tvb, offset, L);
break;
case UAUDP_CONNECT_UDP_LOST:
rTLV(uasip_tree, &hf_uasip_udp_lost, tvb, offset, L);
break;
case UAUDP_CONNECT_UDP_LOST_REINIT:
rTLV(uasip_tree, &hf_uasip_udp_lost_reinit, tvb, offset, L);
break;
case UAUDP_CONNECT_KEEPALIVE:
rTLV(uasip_tree, &hf_uasip_keepalive, tvb, offset, L);
break;
case UAUDP_CONNECT_QOS_IP_TOS:
rTLV(uasip_tree, &hf_uasip_qos_ip_tos, tvb, offset, L);
break;
case UAUDP_CONNECT_QOS_8021_VLID:
rTLV(uasip_tree, &hf_uasip_qos_8021_vlid, tvb, offset, L);
break;
case UAUDP_CONNECT_QOS_8021_PRI:
rTLV(uasip_tree, &hf_uasip_qos_8021_pri, tvb, offset, L);
break;
default:
break;
}
offset += (2 + L);
}
}
break;
switch(T)
{
case UAUDP_CONNECT_VERSION:
rTLV(uasip_tree, &hf_uasip_version, tvb, offset, L);
break;
case UAUDP_NACK:
{
proto_tree_add_uint(uasip_tree, hf_uasip_expseq, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
ua_tap_info.expseq = tvb_get_ntohs(tvb, offset+0);
/*Fix Clang Warning*/
/*offset += 2;*/
if (noesip_enabled)
{
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_fstr(pinfo->cinfo, COL_INFO, "NACK");
}
}
else
{
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_fstr(pinfo->cinfo, COL_INFO, "NACK exp:%d", ua_tap_info.expseq);
}
}
}
break;
case UAUDP_CONNECT_WINDOW_SIZE:
rTLV(uasip_tree, &hf_uasip_window_size, tvb, offset, L);
break;
case UAUDP_DATA:
{
int datalen;
case UAUDP_CONNECT_MTU:
rTLV(uasip_tree, &hf_uasip_mtu, tvb, offset, L);
break;
proto_tree_add_uint(uasip_tree, hf_uasip_expseq, tvb, offset+0, 2, tvb_get_ntohs(tvb, offset+0));
proto_tree_add_uint(uasip_tree, hf_uasip_sntseq, tvb, offset+2, 2, tvb_get_ntohs(tvb, offset+2));
ua_tap_info.expseq = tvb_get_ntohs(tvb, offset+0);
ua_tap_info.sntseq = tvb_get_ntohs(tvb, offset+2);
offset += 4;
datalen = (tvb_length(tvb) - offset);
case UAUDP_CONNECT_UDP_LOST:
rTLV(uasip_tree, &hf_uasip_udp_lost, tvb, offset, L);
break;
if (noesip_enabled)
{
if (datalen > 0)
{
if (direction == SYS_TO_TERM)
{
call_dissector(ua_sys_to_term_handle, tvb_new_subset(tvb, offset, datalen, datalen), pinfo, tree);
}
else if (direction == TERM_TO_SYS)
{
call_dissector(ua_term_to_sys_handle, tvb_new_subset(tvb, offset, datalen, datalen), pinfo, tree);
}
else
{
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_str(pinfo->cinfo, COL_INFO, "DATA - Couldn't resolve direction.");
}
}
}
else
{
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_str(pinfo->cinfo, COL_INFO, "ACK");
}
}
}
else
{
if (datalen > 0)
{
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_fstr(pinfo->cinfo, COL_INFO, "DATA exp:%d", ua_tap_info.expseq);
col_append_fstr(pinfo->cinfo, COL_INFO, " snt:%d", ua_tap_info.sntseq);
}
}
else
{
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_fstr(pinfo->cinfo, COL_INFO, "ACK exp:%d", ua_tap_info.expseq);
col_append_fstr(pinfo->cinfo, COL_INFO, " snt:%d", ua_tap_info.sntseq);
}
}
}
}
break;
default:
break;
}
tap_queue_packet(uasip_tap, pinfo, &ua_tap_info);
case UAUDP_CONNECT_UDP_LOST_REINIT:
rTLV(uasip_tree, &hf_uasip_udp_lost_reinit, tvb, offset, L);
break;
case UAUDP_CONNECT_KEEPALIVE:
rTLV(uasip_tree, &hf_uasip_keepalive, tvb, offset, L);
break;
case UAUDP_CONNECT_QOS_IP_TOS:
rTLV(uasip_tree, &hf_uasip_qos_ip_tos, tvb, offset, L);
break;
case UAUDP_CONNECT_QOS_8021_VLID:
rTLV(uasip_tree, &hf_uasip_qos_8021_vlid, tvb, offset, L);
break;
case UAUDP_CONNECT_QOS_8021_PRI:
rTLV(uasip_tree, &hf_uasip_qos_8021_pri, tvb, offset, L);
break;
default:
break;
}
offset += (2 + L);
}
}
break;
case UAUDP_NACK:
{
proto_tree_add_uint(uasip_tree, hf_uasip_expseq, tvb, offset, 2, tvb_get_ntohs(tvb, offset));
ua_tap_info.expseq = tvb_get_ntohs(tvb, offset+0);
/*offset += 2;*/
if (noesip_enabled)
{
col_add_fstr(pinfo->cinfo, COL_INFO, "NACK");
}
else
{
col_add_fstr(pinfo->cinfo, COL_INFO, "NACK exp:%d", ua_tap_info.expseq);
}
}
break;
case UAUDP_DATA:
{
int datalen;
proto_tree_add_uint(uasip_tree, hf_uasip_expseq, tvb, offset+0, 2, tvb_get_ntohs(tvb, offset+0));
proto_tree_add_uint(uasip_tree, hf_uasip_sntseq, tvb, offset+2, 2, tvb_get_ntohs(tvb, offset+2));
ua_tap_info.expseq = tvb_get_ntohs(tvb, offset+0);
ua_tap_info.sntseq = tvb_get_ntohs(tvb, offset+2);
offset += 4;
datalen = (tvb_length(tvb) - offset);
if (noesip_enabled)
{
if (datalen > 0)
{
if (direction == SYS_TO_TERM)
{
call_dissector(ua_sys_to_term_handle, tvb_new_subset(tvb, offset, datalen, datalen), pinfo, tree);
}
else if (direction == TERM_TO_SYS)
{
call_dissector(ua_term_to_sys_handle, tvb_new_subset(tvb, offset, datalen, datalen), pinfo, tree);
}
else
{
col_add_str(pinfo->cinfo, COL_INFO, "DATA - Couldn't resolve direction.");
}
}
else
{
col_add_str(pinfo->cinfo, COL_INFO, "ACK");
}
}
else
{
if (datalen > 0)
{
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_fstr(pinfo->cinfo, COL_INFO, "DATA exp:%d", ua_tap_info.expseq);
col_append_fstr(pinfo->cinfo, COL_INFO, " snt:%d", ua_tap_info.sntseq);
}
}
else
{
if (check_col(pinfo->cinfo, COL_INFO))
{
col_add_fstr(pinfo->cinfo, COL_INFO, "ACK exp:%d", ua_tap_info.expseq);
col_append_fstr(pinfo->cinfo, COL_INFO, " snt:%d", ua_tap_info.sntseq);
}
}
}
}
break;
default:
break;
}
#if 0
tap_queue_packet(uasip_tap, pinfo, &ua_tap_info);
#endif
}
static void dissect_uasip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
if (use_proxy_ipaddr)
{
if (memcmp((pinfo->src).data, proxy_ipaddr, 4*sizeof(guint8)) == 0)
{
_dissect_uasip(tvb, pinfo, tree, SYS_TO_TERM);
return;
}
else if (memcmp((pinfo->dst).data, proxy_ipaddr, 4*sizeof(guint8)) == 0)
{
_dissect_uasip(tvb, pinfo, tree, TERM_TO_SYS);
return;
}
}
_dissect_uasip(tvb, pinfo, tree, DIR_UNKNOWN);
if (use_proxy_ipaddr)
{
if (memcmp((pinfo->src).data, proxy_ipaddr, 4*sizeof(guint8)) == 0)
{
_dissect_uasip(tvb, pinfo, tree, SYS_TO_TERM);
return;
}
else if (memcmp((pinfo->dst).data, proxy_ipaddr, 4*sizeof(guint8)) == 0)
{
_dissect_uasip(tvb, pinfo, tree, TERM_TO_SYS);
return;
}
}
_dissect_uasip(tvb, pinfo, tree, DIR_UNKNOWN);
}
void proto_register_uasip(void)
{
module_t *uasip_module;
module_t *uasip_module;
static hf_register_info hf_uasip[] =
{
{
&hf_uasip_opcode,
{
"Opcode",
"uasip.opcode",
FT_UINT8,
BASE_DEC,
VALS(uasip_opcode_str),
0x0,
"UA/SIP Opcode",
HFILL
}
},
{
&hf_uasip_version,
{
"Version",
"uasip.version",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Version",
HFILL
}
},
{
&hf_uasip_window_size,
{
"Window Size",
"uasip.window_size",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Window Size",
HFILL
}
},
{
&hf_uasip_mtu,
{
"MTU",
"uasip.mtu",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP MTU",
HFILL
}
},
{
&hf_uasip_udp_lost,
{
"UDP Lost",
"uasip.udp_lost",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Lost",
HFILL
}
},
{
&hf_uasip_udp_lost_reinit,
{
"UDP lost reinit",
"uasip.udp_lost_reinit",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Lost Re-Init",
HFILL
}
},
{
&hf_uasip_keepalive,
{
"Keepalive",
"uasip.keepalive",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Keepalive",
HFILL
}
},
{
&hf_uasip_qos_ip_tos,
{
"QoS IP TOS",
"uasip.qos_ip_tos",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP QoS IP TOS",
HFILL
}
},
{
&hf_uasip_qos_8021_vlid,
{
"QoS 802.1 VLID",
"uasip.qos_8021_vlid",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP QoS 802.1 VLID",
HFILL
}
},
{
&hf_uasip_qos_8021_pri,
{
"QoS 802.1 PRI",
"uasip.qos_8021_pri",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP QoS 802.1 PRI",
HFILL
}
},
{
&hf_uasip_expseq,
{
"Sequence Number (expected)",
"uasip.expseq",
FT_UINT16,
BASE_DEC,
NULL,
0x0,
"UA/SIP Expected Sequence Number",
HFILL
}
},
{
&hf_uasip_sntseq,
{
"Sequence Number (sent)",
"uasip.sntseq",
FT_UINT16,
BASE_DEC,
NULL,
0x0,
"UA/SIP Sent Sequence Number",
HFILL
}
},
};
static hf_register_info hf_uasip[] = {
{
&hf_uasip_opcode,
{
"Opcode",
"uasip.opcode",
FT_UINT8,
BASE_DEC | BASE_EXT_STRING,
&uaudp_opcode_str_ext,
0x0,
"UA/SIP Opcode",
HFILL
}
},
{
&hf_uasip_version,
{
"Version",
"uasip.version",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Version",
HFILL
}
},
{
&hf_uasip_window_size,
{
"Window Size",
"uasip.window_size",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Window Size",
HFILL
}
},
{
&hf_uasip_mtu,
{
"MTU",
"uasip.mtu",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP MTU",
HFILL
}
},
{
&hf_uasip_udp_lost,
{
"UDP Lost",
"uasip.udp_lost",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Lost",
HFILL
}
},
{
&hf_uasip_udp_lost_reinit,
{
"UDP lost reinit",
"uasip.udp_lost_reinit",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Lost Re-Init",
HFILL
}
},
{
&hf_uasip_keepalive,
{
"Keepalive",
"uasip.keepalive",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP Keepalive",
HFILL
}
},
{
&hf_uasip_qos_ip_tos,
{
"QoS IP TOS",
"uasip.qos_ip_tos",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP QoS IP TOS",
HFILL
}
},
{
&hf_uasip_qos_8021_vlid,
{
"QoS 802.1 VLID",
"uasip.qos_8021_vlid",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP QoS 802.1 VLID",
HFILL
}
},
{
&hf_uasip_qos_8021_pri,
{
"QoS 802.1 PRI",
"uasip.qos_8021_pri",
FT_UINT8,
BASE_DEC,
NULL,
0x0,
"UA/SIP QoS 802.1 PRI",
HFILL
}
},
{
&hf_uasip_expseq,
{
"Sequence Number (expected)",
"uasip.expseq",
FT_UINT16,
BASE_DEC,
NULL,
0x0,
"UA/SIP Expected Sequence Number",
HFILL
}
},
{
&hf_uasip_sntseq,
{
"Sequence Number (sent)",
"uasip.sntseq",
FT_UINT16,
BASE_DEC,
NULL,
0x0,
"UA/SIP Sent Sequence Number",
HFILL
}
},
};
static gint *ett[] =
{
&ett_uasip,
};
static gint *ett[] =
{
&ett_uasip,
};
proto_uasip = proto_register_protocol("UA/SIP Protocol", "UASIP", "uasip");
register_dissector("uasip", dissect_uasip, proto_uasip);
proto_uasip = proto_register_protocol("UA/SIP Protocol", "UASIP", "uasip");
register_dissector("uasip", dissect_uasip, proto_uasip);
proto_register_field_array(proto_uasip, hf_uasip, array_length(hf_uasip));
proto_register_subtree_array(ett, array_length(ett));
proto_register_field_array(proto_uasip, hf_uasip, array_length(hf_uasip));
proto_register_subtree_array(ett, array_length(ett));
uasip_module = prefs_register_protocol(proto_uasip, proto_reg_handoff_uasip);
prefs_register_bool_preference(uasip_module, "noesip", "Try to decode SIP NOE", "NOE SIP Protocol", &noesip_enabled);
prefs_register_string_preference(uasip_module, "proxy_ipaddr", "Proxy IP Address", "IPv4 address of the proxy", &pref_proxy_ipaddr_s);
/* uasip_tap = register_tap("uasip");*/
uasip_module = prefs_register_protocol(proto_uasip, proto_reg_handoff_uasip);
prefs_register_bool_preference(uasip_module, "noesip", "Try to decode SIP NOE", "NOE SIP Protocol", &noesip_enabled);
prefs_register_string_preference(uasip_module, "proxy_ipaddr", "Proxy IP Address",
"IPv4 address of the proxy", &pref_proxy_ipaddr_s);
#if 0
uasip_tap = register_tap("uasip");
#endif
}
void proto_reg_handoff_uasip(void)
{
static gboolean prefs_initialized = FALSE;
static dissector_handle_t uasip_handle;
dissector_handle_t uasip_handle;
static gboolean prefs_initialized = FALSE;
if(!prefs_initialized)
{
uasip_handle = create_dissector_handle(dissect_uasip, proto_uasip);
ua_sys_to_term_handle = find_dissector("ua_sys_to_term");
ua_term_to_sys_handle = find_dissector("ua_term_to_sys");
prefs_initialized = TRUE;
}
else
{
if (str_to_ipaddr(pref_proxy_ipaddr_s, proxy_ipaddr))
{
use_proxy_ipaddr = TRUE;
}
else
{
use_proxy_ipaddr = FALSE;
pref_proxy_ipaddr_s = g_strdup("");
}
}
dissector_add_string("media_type", "application/octet-stream", uasip_handle);
if (!prefs_initialized)
{
uasip_handle = create_dissector_handle(dissect_uasip, proto_uasip);
dissector_add_string("media_type", "application/octet-stream", uasip_handle);
ua_sys_to_term_handle = find_dissector("ua_sys_to_term");
ua_term_to_sys_handle = find_dissector("ua_term_to_sys");
prefs_initialized = TRUE;
}
if (str_to_ipaddr(pref_proxy_ipaddr_s, proxy_ipaddr))
{
use_proxy_ipaddr = TRUE;
}
else
{
use_proxy_ipaddr = FALSE;
pref_proxy_ipaddr_s = g_strdup("");
}
}

File diff suppressed because it is too large Load Diff

View File

@ -26,8 +26,6 @@
#ifndef _PACKET_UAUDP_H_
#define _PACKET_UAUDP_H_
#include <gmodule.h>
#define UAUDP_CONNECT 0
#define UAUDP_CONNECT_ACK 1
#define UAUDP_RELEASE 2
@ -37,6 +35,21 @@
#define UAUDP_NACK 6
#define UAUDP_DATA 7
#define UAUDP_CONNECT_VERSION 0x00
#define UAUDP_CONNECT_WINDOW_SIZE 0x01
#define UAUDP_CONNECT_MTU 0x02
#define UAUDP_CONNECT_UDP_LOST 0x03
#define UAUDP_CONNECT_UDP_LOST_REINIT 0x04
#define UAUDP_CONNECT_KEEPALIVE 0x05
#define UAUDP_CONNECT_QOS_IP_TOS 0x06
#define UAUDP_CONNECT_QOS_8021_VLID 0x07
#define UAUDP_CONNECT_QOS_8021_PRI 0x08
extern value_string_ext uaudp_opcode_str_ext;
#if 0
extern value_string_ext uaudp_connect_vals_ext;
#endif
typedef enum _e_ua_direction {
SYS_TO_TERM, /* system -> terminal */
TERM_TO_SYS, /* terminal -> system */