From c7c936a32d2422916797cdd2f39a93c3829b8ea5 Mon Sep 17 00:00:00 2001 From: Michael Mann Date: Tue, 5 Jan 2016 22:28:48 -0500 Subject: Have all TCP flags in the structure that is passed to subdissectors. Have subdissectors do the bit math checking for particular flag bits. Change-Id: Ie6350e316f79af879be9fc512ce215f24449a7e5 Reviewed-on: https://code.wireshark.org/review/13071 Reviewed-by: Michael Mann Petri-Dish: Michael Mann Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- epan/dissectors/packet-http.c | 2 +- epan/dissectors/packet-rlogin.c | 4 ++-- epan/dissectors/packet-tcp.c | 7 ++----- epan/dissectors/packet-tcp.h | 6 ++++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/epan/dissectors/packet-http.c b/epan/dissectors/packet-http.c index 0cfe31a704..d024dd52f0 100644 --- a/epan/dissectors/packet-http.c +++ b/epan/dissectors/packet-http.c @@ -824,7 +824,7 @@ dissect_http_message(tvbuff_t *tvb, int offset, packet_info *pinfo, */ gboolean try_desegment_body = (http_desegment_body && (!(conv_data->request_method && g_str_equal(conv_data->request_method, "HEAD"))) && - ((tcpinfo == NULL) || (tcpinfo->fin == FALSE))); + ((tcpinfo == NULL) || (!IS_TH_FIN(tcpinfo->flags)))); if (!req_resp_hdrs_do_reassembly(tvb, offset, pinfo, http_desegment_headers, try_desegment_body)) { /* diff --git a/epan/dissectors/packet-rlogin.c b/epan/dissectors/packet-rlogin.c index c20fcea2eb..feebee70ff 100644 --- a/epan/dissectors/packet-rlogin.c +++ b/epan/dissectors/packet-rlogin.c @@ -204,7 +204,7 @@ static void rlogin_display(rlogin_hash_entry_t *hash_info, * to something past this segment, we'd have to remember the urgent * pointer setting for this conversation. */ - if (tcpinfo && tcpinfo->urgent && /* if urgent pointer set */ + if (tcpinfo && IS_TH_URG(tcpinfo->flags) && /* if urgent pointer set */ length >= tcpinfo->urgent_pointer) /* and it's in this frame */ { /* Get urgent byte into Temp */ @@ -428,7 +428,7 @@ dissect_rlogin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data) "Startup info received"); } else - if (tcpinfo && tcpinfo->urgent && length >= tcpinfo->urgent_pointer) + if (tcpinfo && IS_TH_URG(tcpinfo->flags) && length >= tcpinfo->urgent_pointer) { /* Urgent pointer inside current data represents a control message */ col_append_str(pinfo->cinfo, COL_INFO, "Control Message"); diff --git a/epan/dissectors/packet-tcp.c b/epan/dissectors/packet-tcp.c index 7386eda7f3..fa124015a3 100644 --- a/epan/dissectors/packet-tcp.c +++ b/epan/dissectors/packet-tcp.c @@ -4946,7 +4946,7 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) tcph->th_seq = tvb_get_ntohl(tvb, offset + 4); tcph->th_ack = tvb_get_ntohl(tvb, offset + 8); th_off_x2 = tvb_get_guint8(tvb, offset + 12); - tcph->th_flags = tvb_get_ntohs(tvb, offset + 12) & 0x0FFF; + tcpinfo.flags = tcph->th_flags = tvb_get_ntohs(tvb, offset + 12) & TH_MASK; tcph->th_win = tvb_get_ntohs(tvb, offset + 14); real_window = tcph->th_win; tcph->th_hlen = hi_nibble(th_off_x2) * 4; /* TCP header length, in bytes */ @@ -5216,7 +5216,6 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) if(tcph->th_flags & TH_FIN) { /* XXX - find a way to know the server port and output only that one */ expert_add_info(pinfo, tf_fin, &ei_tcp_connection_fin); - tcpinfo.fin = TRUE; } if(tcph->th_flags & TH_RST) /* XXX - find a way to know the server port and output only that one */ @@ -5396,14 +5395,12 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) item = proto_tree_add_item_ret_uint(tcp_tree, hf_tcp_urgent_pointer, tvb, offset + 18, 2, ENC_BIG_ENDIAN, &th_urp); - if (tcph->th_flags & TH_URG) { + if (IS_TH_URG(tcph->th_flags)) { /* Export the urgent pointer, for the benefit of protocols such as rlogin. */ - tcpinfo.urgent = TRUE; tcpinfo.urgent_pointer = (guint16)th_urp; tcp_info_append_uint(pinfo, "Urg", th_urp); } else { - tcpinfo.urgent = FALSE; if (th_urp) { /* Note if the urgent pointer field is non-zero */ expert_add_info(pinfo, item, &ei_tcp_urgent_pointer_non_zero); diff --git a/epan/dissectors/packet-tcp.h b/epan/dissectors/packet-tcp.h index 55711f0291..876a4b68ed 100644 --- a/epan/dissectors/packet-tcp.h +++ b/epan/dissectors/packet-tcp.h @@ -44,6 +44,9 @@ extern "C" { #define TH_RES 0x0E00 /* 3 reserved bits */ #define TH_MASK 0x0FFF +#define IS_TH_FIN(x) (x & TH_FIN) +#define IS_TH_URG(x) (x & TH_URG) + /* Idea for gt: either x > y, or y is much bigger (assume wrap) */ #define GT_SEQ(x, y) ((gint32)((y) - (x)) < 0) #define LT_SEQ(x, y) ((gint32)((x) - (y)) < 0) @@ -106,8 +109,7 @@ struct tcpinfo { guint32 nxtseq; /* Sequence number of first byte after data */ guint32 lastackseq; /* Sequence number of last ack */ gboolean is_reassembled; /* This is reassembled data. */ - gboolean fin; /* TRUE if FIN flag bit is set */ - gboolean urgent; /* TRUE if "urgent_pointer" is valid */ + guint16 flags; /* TCP flags */ guint16 urgent_pointer; /* Urgent pointer value for the current packet. */ }; -- cgit v1.2.1