diff options
author | etxrab <etxrab@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-11-09 06:01:18 +0000 |
---|---|---|
committer | etxrab <etxrab@f5534014-38df-0310-8fa8-9805f1628bb7> | 2007-11-09 06:01:18 +0000 |
commit | 52c22485f76e560bd64b369273b601b5bfa0f3b9 (patch) | |
tree | 874c9902e9d5e87aeda6b3c11e76dd35b41312f0 | |
parent | 58b59b69930f7d89d1fec724f4de0832835175aa (diff) |
Apply yet another set of the optimization patches:
When offset parameter is 0 replace tvb_bytes_exist() with the faster tvb_length().
On the other hand
if (tvb_bytes_exist(tvb, 0, 20)
is more readable than
if (tvb_length(tvb) >= 20
so only do it in heuristic function
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@23412 f5534014-38df-0310-8fa8-9805f1628bb7
-rw-r--r-- | epan/dissectors/packet-bittorrent.c | 3 | ||||
-rw-r--r-- | epan/dissectors/packet-cigi.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-dccp.c | 4 | ||||
-rw-r--r-- | epan/dissectors/packet-dcerpc.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-pktgen.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-rmt-norm.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-ses.c | 6 | ||||
-rw-r--r-- | epan/dissectors/packet-smb.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-smb2.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-stun.c | 13 | ||||
-rw-r--r-- | epan/dissectors/packet-stun2.c | 21 | ||||
-rw-r--r-- | epan/dissectors/packet-tds.c | 2 | ||||
-rw-r--r-- | epan/dissectors/packet-yhoo.c | 2 | ||||
-rw-r--r-- | plugins/ciscosm/packet-sm.c | 38 |
14 files changed, 58 insertions, 43 deletions
diff --git a/epan/dissectors/packet-bittorrent.c b/epan/dissectors/packet-bittorrent.c index 71215f3dd5..ec73e179e4 100644 --- a/epan/dissectors/packet-bittorrent.c +++ b/epan/dissectors/packet-bittorrent.c @@ -761,9 +761,10 @@ static gboolean test_bittorrent_packet (tvbuff_t *tvb, packet_info *pinfo, { conversation_t *conversation; - if (tvb_bytes_exist(tvb, 0, 20) && + if (tvb_length(tvb) >= 20 && tvb_get_guint8(tvb, 0) == 19 && tvb_memeql(tvb, 1, "BitTorrent protocol", 19) == 0) { + /* XXXX why new ? */ conversation = conversation_new (pinfo->fd->num, &pinfo->src, &pinfo->dst, pinfo->ptype, pinfo->srcport, pinfo->destport, 0); conversation_set_dissector(conversation, dissector_handle); diff --git a/epan/dissectors/packet-cigi.c b/epan/dissectors/packet-cigi.c index fa123158a6..d0db7ef365 100644 --- a/epan/dissectors/packet-cigi.c +++ b/epan/dissectors/packet-cigi.c @@ -1875,7 +1875,7 @@ packet_is_cigi(tvbuff_t *tvb) guint8 reserved; - if (!tvb_bytes_exist(tvb, 0, 3)) { + if (tvb_length(tvb) < 3) { /* Not enough data available to check */ return FALSE; } diff --git a/epan/dissectors/packet-dccp.c b/epan/dissectors/packet-dccp.c index 3119adb32f..be1aea1bd5 100644 --- a/epan/dissectors/packet-dccp.c +++ b/epan/dissectors/packet-dccp.c @@ -223,7 +223,7 @@ dissect_dccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } /* get at least a full packet structure */ - if ( !tvb_bytes_exist(tvb, 0, sizeof(DCC_HDR)) ) { + if ( tvb_length(tvb) < sizeof(DCC_HDR) ) { /* Doesn't have enough bytes to contain packet header. */ return FALSE; } @@ -251,7 +251,7 @@ dissect_dccp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree_add_item(dccp_tree, hf_dccp_len, tvb, offset, 2, FALSE); - if ( !tvb_bytes_exist(tvb, 0, tvb_get_ntohs(tvb, offset))) { + if ( tvb_length(tvb) < tvb_get_ntohs(tvb, offset)) { /* Doesn't have number of bytes that header claims. */ proto_tree_add_text(dccp_tree, tvb, offset, 2, "Error - packet is shorter than header claims!"); } diff --git a/epan/dissectors/packet-dcerpc.c b/epan/dissectors/packet-dcerpc.c index 95af4b7e40..7c62a1196b 100644 --- a/epan/dissectors/packet-dcerpc.c +++ b/epan/dissectors/packet-dcerpc.c @@ -4741,7 +4741,7 @@ dissect_dcerpc_dg (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * have an 80 byte header on them. Which starts with * version (4), pkt_type. */ - if (!tvb_bytes_exist (tvb, 0, sizeof (hdr))) { + if (tvb_length (tvb) < sizeof (hdr)) { return FALSE; } diff --git a/epan/dissectors/packet-pktgen.c b/epan/dissectors/packet-pktgen.c index 1b67ead2db..3bb06ff98f 100644 --- a/epan/dissectors/packet-pktgen.c +++ b/epan/dissectors/packet-pktgen.c @@ -73,7 +73,7 @@ static gboolean dissect_pktgen(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tr nstime_t tstamp; /* check for min size */ - if(!tvb_bytes_exist(tvb, 0, 16)) { /* Not a PKTGEN packet. */ + if(tvb_length(tvb) < 16) { /* Not a PKTGEN packet. */ return FALSE; } diff --git a/epan/dissectors/packet-rmt-norm.c b/epan/dissectors/packet-rmt-norm.c index 0f68c40006..b66de790db 100644 --- a/epan/dissectors/packet-rmt-norm.c +++ b/epan/dissectors/packet-rmt-norm.c @@ -655,7 +655,7 @@ dissect_norm_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) guint8 byte1; if (!global_norm_heur) return FALSE; - if (!tvb_bytes_exist(tvb, 0, 2)) + if (tvb_length(tvb) < 2) return FALSE; /* not enough to check */ byte1 = tvb_get_guint8(tvb, 0); diff --git a/epan/dissectors/packet-ses.c b/epan/dissectors/packet-ses.c index c10cc0beac..d492aaa176 100644 --- a/epan/dissectors/packet-ses.c +++ b/epan/dissectors/packet-ses.c @@ -1805,7 +1805,7 @@ dissect_ses_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) guint16 len; /* first, check do we have at least 4 bytes (type+length) */ - if (!tvb_bytes_exist(tvb, 0, 2)) + if (tvb_length(tvb) < 2) return FALSE; /* no */ /* can we recognize session PDU ? Return FALSE if not */ @@ -1833,7 +1833,7 @@ dissect_ses_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) * misinterpreted as SES. * the starter in this case is fixed to 0x32 (SES_MINOR_SYNC_ACK for SES), * so if the parameter type is unknown, it's probably SIMATIC */ - if(type == 0x32 && tvb_bytes_exist(tvb, 0, 3)) { + if(type == 0x32 && tvb_length(tvb) >= 3) { type = tvb_get_guint8(tvb, offset+2); if (match_strval(type, param_vals) == NULL) { return FALSE; /* it's probably a SIMATIC protocol */ @@ -1847,7 +1847,7 @@ dissect_ses_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) /* add header length */ len+=len_len; /* do we have enough bytes ? */ - if (!tvb_bytes_exist(tvb, 0, len)) + if (tvb_length(tvb) < len) return FALSE; /* no */ dissect_ses(tvb, pinfo, parent_tree); diff --git a/epan/dissectors/packet-smb.c b/epan/dissectors/packet-smb.c index 982daa9c76..db7ae3f765 100644 --- a/epan/dissectors/packet-smb.c +++ b/epan/dissectors/packet-smb.c @@ -16508,7 +16508,7 @@ static gboolean dissect_smb_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) { /* must check that this really is a smb packet */ - if (!tvb_bytes_exist(tvb, 0, 4)) + if (tvb_length(tvb) < 4) return FALSE; if( (tvb_get_guint8(tvb, 0) != 0xff) diff --git a/epan/dissectors/packet-smb2.c b/epan/dissectors/packet-smb2.c index e65fdb6aa4..4666f10aa3 100644 --- a/epan/dissectors/packet-smb2.c +++ b/epan/dissectors/packet-smb2.c @@ -4560,7 +4560,7 @@ dissect_smb2_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree) int offset = 0; /* must check that this really is a smb2 packet */ - if (!tvb_bytes_exist(tvb, 0, 4)) + if (tvb_length(tvb) < 4) return FALSE; if( (tvb_get_guint8(tvb, 0) != 0xfe) diff --git a/epan/dissectors/packet-stun.c b/epan/dissectors/packet-stun.c index c3318ebb9d..f59c371d91 100644 --- a/epan/dissectors/packet-stun.c +++ b/epan/dissectors/packet-stun.c @@ -129,7 +129,7 @@ static gint ett_stun_att = -1; #define TCP_PORT_STUN 3478 -#define STUN_HDR_LEN 20 /* STUN message header length */ +#define STUN_HDR_LEN ((guint)20) /* STUN message header length */ #define ATTR_HDR_LEN 4 /* STUN attribute header length */ @@ -208,14 +208,15 @@ dissect_stun(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) guint16 att_type; guint16 att_length; guint16 offset; + guint len; guint i; /* * First check if the frame is really meant for us. */ - + len = tvb_length(tvb); /* First, make sure we have enough data to do the check. */ - if (!tvb_bytes_exist(tvb, 0, STUN_HDR_LEN)) + if (len < STUN_HDR_LEN) return 0; msg_type = tvb_get_ntohs(tvb, 0); @@ -228,11 +229,7 @@ dissect_stun(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) msg_length = tvb_get_ntohs(tvb, 2); /* check if payload enough */ - if (!tvb_bytes_exist(tvb, 0, STUN_HDR_LEN+msg_length)) - return 0; - - /* Check if too much payload */ - if (tvb_bytes_exist(tvb, 0, STUN_HDR_LEN+msg_length+1)) + if (len != STUN_HDR_LEN+msg_length) return 0; /* The message seems to be a valid STUN message! */ diff --git a/epan/dissectors/packet-stun2.c b/epan/dissectors/packet-stun2.c index bcdcd0268b..6ec2afee34 100644 --- a/epan/dissectors/packet-stun2.c +++ b/epan/dissectors/packet-stun2.c @@ -104,7 +104,7 @@ static gint ett_stun2_att = -1; #define UDP_PORT_STUN2 3478 #define TCP_PORT_STUN2 3478 -#define STUN2_HDR_LEN 20 /* STUN2 message header length */ +#define STUN2_HDR_LEN ((guint)20) /* STUN2 message header length */ #define ATTR_HDR_LEN 4 /* STUN2 attribute header length */ @@ -165,13 +165,15 @@ dissect_stun2_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) guint16 offset; guint i; guint transaction_id_first_word; + guint len; /* * First check if the frame is really meant for us. */ + len = tvb_length(tvb); /* First, make sure we have enough data to do the check. */ - if (!tvb_bytes_exist(tvb, 0, STUN2_HDR_LEN)) + if (len < STUN2_HDR_LEN) return; msg_type = tvb_get_ntohs(tvb, 0); @@ -182,11 +184,7 @@ dissect_stun2_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) return; /* check if payload enough */ - if (!tvb_bytes_exist(tvb, 0, STUN2_HDR_LEN+msg_length)) - return; - - /* Check if too much payload */ - if (tvb_bytes_exist(tvb, 0, STUN2_HDR_LEN+msg_length+1)) + if (len != STUN2_HDR_LEN+msg_length) return; /* The message seems to be a valid STUN2 message! */ @@ -404,9 +402,11 @@ dissect_stun2_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) { guint16 msg_type; guint16 msg_length; + guint len; /* First, make sure we have enough data to do the check. */ - if (!tvb_bytes_exist(tvb, 0, STUN2_HDR_LEN)) + len = tvb_length(tvb); + if (len < STUN2_HDR_LEN) return FALSE; msg_type = tvb_get_ntohs(tvb, 0); @@ -417,12 +417,9 @@ dissect_stun2_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) return FALSE; /* check if payload enough */ - if (!tvb_bytes_exist(tvb, 0, STUN2_HDR_LEN+msg_length)) + if (len != STUN2_HDR_LEN+msg_length) return FALSE; - /* Check if too much payload */ - if (tvb_bytes_exist(tvb, 0, STUN2_HDR_LEN+msg_length+1)) - return FALSE; dissect_stun2_message(tvb, pinfo, tree); return TRUE; } diff --git a/epan/dissectors/packet-tds.c b/epan/dissectors/packet-tds.c index 8f04cfaa69..3eaf53ac9b 100644 --- a/epan/dissectors/packet-tds.c +++ b/epan/dissectors/packet-tds.c @@ -1888,7 +1888,7 @@ dissect_tds_tcp_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) * If we don't have even enough data for a Netlib header, * just say it's not TDS. */ - if (!tvb_bytes_exist(tvb, offset, 8)) + if (tvb_length(tvb) < 8) return FALSE; /* diff --git a/epan/dissectors/packet-yhoo.c b/epan/dissectors/packet-yhoo.c index f747e89f57..16ab6bbfdb 100644 --- a/epan/dissectors/packet-yhoo.c +++ b/epan/dissectors/packet-yhoo.c @@ -185,7 +185,7 @@ dissect_yhoo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } /* get at least a full packet structure */ - if ( !tvb_bytes_exist(tvb, 0, sizeof(struct yahoo_rawpacket)) ) { + if ( tvb_length(tvb) < sizeof(struct yahoo_rawpacket) ) { /* Not enough data captured; maybe it is a Yahoo Messenger packet, but it contains too little data to tell. */ diff --git a/plugins/ciscosm/packet-sm.c b/plugins/ciscosm/packet-sm.c index 1081da89c2..dfd2280472 100644 --- a/plugins/ciscosm/packet-sm.c +++ b/plugins/ciscosm/packet-sm.c @@ -122,6 +122,8 @@ static int hf_sm_channel = -1; static int hf_sm_bearer = -1; static int hf_sm_len = -1; static int hf_sm_ip_addr = -1; +static int hf_sm_context = -1; +static int hf_sm_eisup_msg_id = -1; static int hf_sm_tag = -1; /* Initialize the subtree pointers */ @@ -166,7 +168,12 @@ dissect_sm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) offset = offset + 2; switch(protocol){ case SM_PROTOCOL_X101: - /* XXX Reveres enginered so this may not be correct!!! */ + /* XXX Reveres enginered so this may not be correct!!! + * EISUP - used between Cisco HSI and Cisco PGW devices, + * uses RUDP with default port number 8003. + * Protocol stack is RUDP->Cisco SM->SDP. + * This implementation is PROPRIETARY + */ proto_tree_add_item(sm_tree, hf_sm_len, tvb, offset, 2, FALSE); length = tvb_get_ntohs(tvb,offset); offset = offset + 2; @@ -174,10 +181,12 @@ dissect_sm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* The next stuff seems to be IP addr */ proto_tree_add_item(sm_tree, hf_sm_ip_addr, tvb, offset, 4, FALSE); offset = offset + 4; - proto_tree_add_item(sm_tree, hf_sm_tag, tvb, offset, 2, FALSE); - offset = offset +2; - proto_tree_add_text(sm_tree, tvb, offset,3,"[unknown]"); - offset = offset + 3; + /* This part looks to be the same per session */ + proto_tree_add_item(sm_tree, hf_sm_context, tvb, offset, 4, FALSE); + offset = offset +4; + /* Some sort of message type? */ + proto_tree_add_item(sm_tree, hf_sm_eisup_msg_id, tvb, offset, 1, FALSE); + offset = offset + 1; /* XXX Problem are tags 1 or two bytes???*/ proto_tree_add_item(sm_tree, hf_sm_tag, tvb, offset, 2, FALSE); @@ -203,10 +212,11 @@ dissect_sm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* The next stuff seems to be IP addr */ proto_tree_add_item(sm_tree, hf_sm_ip_addr, tvb, offset, 4, FALSE); offset = offset + 4; - proto_tree_add_item(sm_tree, hf_sm_tag, tvb, offset, 2, FALSE); - offset = offset +2; - proto_tree_add_text(sm_tree, tvb, offset,3,"[unknown]"); - offset = offset + 3; + proto_tree_add_item(sm_tree, hf_sm_context, tvb, offset, 4, FALSE); + offset = offset +4; + /* Some sort of message type? */ + proto_tree_add_item(sm_tree, hf_sm_eisup_msg_id, tvb, offset, 1, FALSE); + offset = offset + 1; /* XXX Problem are tags 1 or two bytes???*/ proto_tree_add_item(sm_tree, hf_sm_tag, tvb, offset, 2, FALSE); @@ -298,6 +308,16 @@ proto_register_sm(void) FT_IPv4,BASE_NONE, NULL, 0x0, "IPv4 address", HFILL } }, + { &hf_sm_context, + { "Context","sm.context", + FT_UINT32, BASE_DEC, NULL, 0x0, + "Context(guesswork!)", HFILL } + }, + { &hf_sm_eisup_msg_id, + { "Message id","sm.eisup_message_id", + FT_UINT8, BASE_DEC, NULL, 0x0, + "Message id(guesswork!)", HFILL } + }, { &hf_sm_tag, { "Tag","sm.tag", FT_UINT16, BASE_DEC, NULL, 0x0, |