diff options
author | Jeff Morriss <jeff.morriss.ws@gmail.com> | 2015-08-12 13:57:20 -0400 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2015-08-21 04:53:04 +0000 |
commit | b4762a043458e5205090282a099184980fb555ea (patch) | |
tree | 8237d3b0571fc8f17121d989ec7aff2177208616 | |
parent | dc4e9605c990779aaaca02bcdec5ca79c25a6509 (diff) | |
download | wireshark-b4762a043458e5205090282a099184980fb555ea.tar.gz |
Generate Diameter's expert info's even when there's no tree so that they show
up in the Expert Infos dialog.
Push the if(tree) check down into the basic type dissectors since we can't
generate/fill the label (which won't be used anyway) when we're not building
the tree (since the proto_item will be faked/NULL).
Change-Id: Ie4f1f6856cfad0dabc7c58cdee2c16c8fc032c6d
Reviewed-on: https://code.wireshark.org/review/10001
Petri-Dish: Jeff Morriss <jeff.morriss.ws@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | epan/dissectors/packet-diameter.c | 210 |
1 files changed, 122 insertions, 88 deletions
diff --git a/epan/dissectors/packet-diameter.c b/epan/dissectors/packet-diameter.c index 8d4ddb978b..8c6f93a4fb 100644 --- a/epan/dissectors/packet-diameter.c +++ b/epan/dissectors/packet-diameter.c @@ -473,11 +473,12 @@ dissect_diameter_3gpp2_exp_res(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree return 0; diam_sub_dis = (diam_sub_dis_t*)data; - pi = proto_tree_add_item(tree, hf_diameter_3gpp2_exp_res, tvb, 0, 4, ENC_BIG_ENDIAN); - diam_sub_dis->avp_str = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item_fill_label(PITEM_FINFO(pi), diam_sub_dis->avp_str); - diam_sub_dis->avp_str = strstr(diam_sub_dis->avp_str,": ")+2; - + if (tree) { + pi = proto_tree_add_item(tree, hf_diameter_3gpp2_exp_res, tvb, 0, 4, ENC_BIG_ENDIAN); + diam_sub_dis->avp_str = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), diam_sub_dis->avp_str); + diam_sub_dis->avp_str = strstr(diam_sub_dis->avp_str,": ")+2; + } return 4; } @@ -784,9 +785,9 @@ dissect_diameter_avp(diam_ctx_t *c, tvbuff_t *tvb, int offset, diam_sub_dis_t *d call_avp_subdissector(vendorid, code, subtvb, c->pinfo, avp_tree, diam_sub_dis_inf); /* Let the subdissector have precedence filling in the avp_item string */ - if(diam_sub_dis_inf->avp_str){ + if (diam_sub_dis_inf->avp_str) { proto_item_append_text(avp_item," val=%s", diam_sub_dis_inf->avp_str); - }else if (avp_str){ + } else if (avp_str) { proto_item_append_text(avp_item," val=%s", avp_str); } @@ -809,7 +810,7 @@ dissect_diameter_avp(diam_ctx_t *c, tvbuff_t *tvb, int offset, diam_sub_dis_t *d static const char * address_rfc_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + char *label = NULL; address_avp_t *t = (address_avp_t *)a->type_data; gint len = tvb_reported_length(tvb); proto_item *pi = proto_tree_add_item(c->tree, a->hf_value, tvb, 0, len, ENC_BIG_ENDIAN); @@ -838,8 +839,12 @@ address_rfc_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *dia break; } - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } + return label; } @@ -870,7 +875,7 @@ static const char * time_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { int len = tvb_reported_length(tvb); - char *label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + char *label = NULL; proto_item *pi; if ( len != 4 ) { @@ -879,16 +884,21 @@ time_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_d return "[Malformed]"; } - pi = proto_tree_add_item(c->tree, (a->hf_value), tvb, 0, 4, ENC_TIME_NTP|ENC_BIG_ENDIAN); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + pi = proto_tree_add_item(c->tree, (a->hf_value), tvb, 0, 4, ENC_TIME_NTP|ENC_BIG_ENDIAN); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } + return label; } static const char * address_v16_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + char *label = NULL; + address_avp_t *t = (address_avp_t *)a->type_data; proto_item *pi = proto_tree_add_item(c->tree,a->hf_value,tvb,0,tvb_reported_length(tvb),ENC_BIG_ENDIAN); proto_tree *pt = proto_item_add_subtree(pi,t->ett); @@ -909,44 +919,60 @@ address_v16_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *dia break; } - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } + return label; } static const char * simple_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item *pi = proto_tree_add_item(c->tree,a->hf_value,tvb,0,tvb_reported_length(tvb),ENC_BIG_ENDIAN); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + char *label = NULL; + + if (c->tree) { + proto_item *pi = proto_tree_add_item(c->tree,a->hf_value,tvb,0,tvb_reported_length(tvb),ENC_BIG_ENDIAN); + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } + return label; } static const char * utf8_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item *pi = proto_tree_add_item(c->tree,a->hf_value,tvb,0,tvb_reported_length(tvb),ENC_UTF_8|ENC_BIG_ENDIAN); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + char *label = NULL; + + if (c->tree) { + proto_item *pi = proto_tree_add_item(c->tree,a->hf_value,tvb,0,tvb_reported_length(tvb),ENC_UTF_8|ENC_BIG_ENDIAN); + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } + return label; } static const char * integer32_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label; + char *label = NULL; proto_item *pi; /* Verify length before adding */ gint length = tvb_reported_length(tvb); if (length == 4) { - pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); - label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } } else { pi = proto_tree_add_bytes_format(c->tree, hf_diameter_avp_data_wrong_length, @@ -955,24 +981,26 @@ integer32_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_ expert_add_info_format(c->pinfo, pi, &ei_diameter_avp_len, "Bad Integer32 Length (%u)", length); PROTO_ITEM_SET_GENERATED(pi); - label = NULL; } + return label; } static const char * integer64_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label; + char *label = NULL; proto_item *pi; /* Verify length before adding */ gint length = tvb_reported_length(tvb); if (length == 8) { - pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); - label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } } else { pi = proto_tree_add_bytes_format(c->tree, hf_diameter_avp_data_wrong_length, @@ -981,24 +1009,26 @@ integer64_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_ expert_add_info_format(c->pinfo, pi, &ei_diameter_avp_len, "Bad Integer64 Length (%u)", length); PROTO_ITEM_SET_GENERATED(pi); - label = NULL; } + return label; } static const char * unsigned32_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label; + char *label = NULL; proto_item *pi; /* Verify length before adding */ gint length = tvb_reported_length(tvb); if (length == 4) { - pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); - label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } } else { pi = proto_tree_add_bytes_format(c->tree, hf_diameter_avp_data_wrong_length, @@ -1007,24 +1037,26 @@ unsigned32_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam expert_add_info_format(c->pinfo, pi, &ei_diameter_avp_len, "Bad Unsigned32 Length (%u)", length); PROTO_ITEM_SET_GENERATED(pi); - label = NULL; } + return label; } static const char * unsigned64_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label; + char *label = NULL; proto_item *pi; /* Verify length before adding */ gint length = tvb_reported_length(tvb); if (length == 8) { - pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); - label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } } else { pi = proto_tree_add_bytes_format(c->tree, hf_diameter_avp_data_wrong_length, @@ -1033,24 +1065,26 @@ unsigned64_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam expert_add_info_format(c->pinfo, pi, &ei_diameter_avp_len, "Bad Unsigned64 Length (%u)", length); PROTO_ITEM_SET_GENERATED(pi); - label = NULL; } + return label; } static const char * float32_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label; + char *label = NULL; proto_item *pi; /* Verify length before adding */ gint length = tvb_reported_length(tvb); if (length == 4) { - pi= proto_tree_add_item(c->tree,a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); - label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + pi= proto_tree_add_item(c->tree,a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } } else { pi = proto_tree_add_bytes_format(c->tree, hf_diameter_avp_data_wrong_length, @@ -1059,24 +1093,26 @@ float32_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_su expert_add_info_format(c->pinfo, pi, &ei_diameter_avp_len, "Bad Float32 Length (%u)", length); PROTO_ITEM_SET_GENERATED(pi); - label = NULL; } + return label; } static const char * float64_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_sub_dis_inf _U_) { - char *label; + char *label = NULL; proto_item *pi; /* Verify length before adding */ gint length = tvb_reported_length(tvb); if (length == 8) { - pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); - label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); - proto_item_fill_label(PITEM_FINFO(pi), label); - label = strstr(label,": ")+2; + if (c->tree) { + pi= proto_tree_add_item(c->tree, a->hf_value, tvb, 0, length, ENC_BIG_ENDIAN); + label = (char *)wmem_alloc(wmem_packet_scope(), ITEM_LABEL_LENGTH+1); + proto_item_fill_label(PITEM_FINFO(pi), label); + label = strstr(label,": ")+2; + } } else { pi = proto_tree_add_bytes_format(c->tree, hf_diameter_avp_data_wrong_length, @@ -1085,8 +1121,8 @@ float64_avp(diam_ctx_t *c, diam_avp_t *a, tvbuff_t *tvb, diam_sub_dis_t *diam_su expert_add_info_format(c->pinfo, pi, &ei_diameter_avp_len, "Bad Float64 Length (%u)", length); PROTO_ITEM_SET_GENERATED(pi); - label = NULL; } + return label; } @@ -1319,36 +1355,34 @@ dissect_diameter_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, voi } diameter_pair->processing_request=(flags_bits & DIAM_FLAGS_R)!= 0; - if (tree){ - /* print state tracking info in the tree */ - if (flags_bits & DIAM_FLAGS_R) { - /* This is a request */ - if (diameter_pair->ans_frame) { - it = proto_tree_add_uint(diam_tree, hf_diameter_answer_in, - tvb, 0, 0, diameter_pair->ans_frame); - PROTO_ITEM_SET_GENERATED(it); - } - } else { - /* This is an answer */ - if (diameter_pair->req_frame) { - it = proto_tree_add_uint(diam_tree, hf_diameter_answer_to, - tvb, 0, 0, diameter_pair->req_frame); - PROTO_ITEM_SET_GENERATED(it); - - nstime_delta(&ns, &pinfo->fd->abs_ts, &diameter_pair->req_time); - diameter_pair->srt_time = ns; - it = proto_tree_add_time(diam_tree, hf_diameter_answer_time, tvb, 0, 0, &ns); - PROTO_ITEM_SET_GENERATED(it); - /* TODO: Populate result_code in tap record from AVP 268 */ - } + /* print state tracking info in the tree */ + if (flags_bits & DIAM_FLAGS_R) { + /* This is a request */ + if (diameter_pair->ans_frame) { + it = proto_tree_add_uint(diam_tree, hf_diameter_answer_in, + tvb, 0, 0, diameter_pair->ans_frame); + PROTO_ITEM_SET_GENERATED(it); + } + } else { + /* This is an answer */ + if (diameter_pair->req_frame) { + it = proto_tree_add_uint(diam_tree, hf_diameter_answer_to, + tvb, 0, 0, diameter_pair->req_frame); + PROTO_ITEM_SET_GENERATED(it); + + nstime_delta(&ns, &pinfo->fd->abs_ts, &diameter_pair->req_time); + diameter_pair->srt_time = ns; + it = proto_tree_add_time(diam_tree, hf_diameter_answer_time, tvb, 0, 0, &ns); + PROTO_ITEM_SET_GENERATED(it); + /* TODO: Populate result_code in tap record from AVP 268 */ } + } - offset = 20; + offset = 20; - /* Dissect AVPs until the end of the packet is reached */ - while (offset < packet_len) { - offset += dissect_diameter_avp(c, tvb, offset, diam_sub_dis_inf); - } + /* Dissect AVPs until the end of the packet is reached */ + while (offset < packet_len) { + offset += dissect_diameter_avp(c, tvb, offset, diam_sub_dis_inf); } /* Handle requests for which no answers were found and |