forked from osmocom/wireshark
Introduce col_add_lstr(), use it instead of slower col_add_fstr.
We have callgrind benchmarks which shows that col_add_fstr() takes 5% of Ir count cause of formatting done in g_vsnprintf(). New col_add_lstr() can be used in few dissectors without much ugliness, and it should be a little faster. Change-Id: Ifddd951063dfd3a27c2a7da4dafce9b242c0472c Reviewed-on: https://code.wireshark.org/review/1629 Reviewed-by: Evan Huus <eapache@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
This commit is contained in:
parent
24082972a3
commit
ea95c837fe
|
@ -557,9 +557,55 @@ col_set_str(column_info *cinfo, const gint el, const gchar* str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
col_add_lstr(column_info *cinfo, const gint el, const gchar *str, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
int i;
|
||||||
|
int pos;
|
||||||
|
int max_len;
|
||||||
|
|
||||||
|
if (!CHECK_COL(cinfo, el))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (el == COL_INFO)
|
||||||
|
max_len = COL_MAX_INFO_LEN;
|
||||||
|
else
|
||||||
|
max_len = COL_MAX_LEN;
|
||||||
|
|
||||||
|
for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) {
|
||||||
|
if (cinfo->fmt_matx[i][el]) {
|
||||||
|
pos = cinfo->col_fence[i];
|
||||||
|
if (pos != 0) {
|
||||||
|
/*
|
||||||
|
* We will append the string after the fence.
|
||||||
|
* First arrange that we can append, if necessary.
|
||||||
|
*/
|
||||||
|
COL_CHECK_APPEND(cinfo, i, max_len);
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* There's no fence, so we can just write to the string.
|
||||||
|
*/
|
||||||
|
cinfo->col_data[i] = cinfo->col_buf[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
va_start(ap, str);
|
||||||
|
do {
|
||||||
|
if G_UNLIKELY(str == NULL)
|
||||||
|
str = "(null)";
|
||||||
|
|
||||||
|
pos += g_strlcpy(&cinfo->col_buf[i][pos], str, max_len - pos);
|
||||||
|
|
||||||
|
} while (pos < max_len && (str = va_arg(ap, const char *)) != COL_ADD_LSTR_TERMINATOR);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Adds a vararg list to a packet info string. */
|
/* Adds a vararg list to a packet info string. */
|
||||||
void
|
void
|
||||||
col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...) {
|
col_add_fstr(column_info *cinfo, const gint el, const gchar *format, ...)
|
||||||
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int i;
|
int i;
|
||||||
int fence;
|
int fence;
|
||||||
|
|
|
@ -228,6 +228,10 @@ WS_DLL_PUBLIC void col_set_str(column_info *cinfo, const gint col, const gchar *
|
||||||
*/
|
*/
|
||||||
WS_DLL_PUBLIC void col_add_str(column_info *cinfo, const gint col, const gchar *str);
|
WS_DLL_PUBLIC void col_add_str(column_info *cinfo, const gint col, const gchar *str);
|
||||||
|
|
||||||
|
/* terminator argument for col_add_lstr() function */
|
||||||
|
#define COL_ADD_LSTR_TERMINATOR (const char *) -1
|
||||||
|
WS_DLL_PUBLIC void col_add_lstr(column_info *cinfo, const gint el, const gchar *str, ...);
|
||||||
|
|
||||||
/** Add (replace) the text of a column element, the text will be formatted and copied.
|
/** Add (replace) the text of a column element, the text will be formatted and copied.
|
||||||
*
|
*
|
||||||
* Same function as col_add_str() but using a printf-like format string.
|
* Same function as col_add_str() but using a printf-like format string.
|
||||||
|
|
|
@ -2435,17 +2435,20 @@ dissect_sip_common(tvbuff_t *tvb, int offset, int remaining_length, packet_info
|
||||||
case REQUEST_LINE:
|
case REQUEST_LINE:
|
||||||
is_known_request = sip_is_known_request(tvb, offset, token_1_len, ¤t_method_idx);
|
is_known_request = sip_is_known_request(tvb, offset, token_1_len, ¤t_method_idx);
|
||||||
descr = is_known_request ? "Request" : "Unknown request";
|
descr = is_known_request ? "Request" : "Unknown request";
|
||||||
col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %s",
|
col_add_lstr(pinfo->cinfo, COL_INFO,
|
||||||
descr,
|
descr, ": ",
|
||||||
tvb_format_text(tvb, offset, linelen - SIP2_HDR_LEN - 1));
|
tvb_format_text(tvb, offset, linelen - SIP2_HDR_LEN - 1),
|
||||||
|
COL_ADD_LSTR_TERMINATOR);
|
||||||
DPRINT(("got %s: %s", descr,
|
DPRINT(("got %s: %s", descr,
|
||||||
tvb_format_text(tvb, offset, linelen - SIP2_HDR_LEN - 1)));
|
tvb_format_text(tvb, offset, linelen - SIP2_HDR_LEN - 1)));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STATUS_LINE:
|
case STATUS_LINE:
|
||||||
descr = "Status";
|
descr = "Status";
|
||||||
col_add_fstr(pinfo->cinfo, COL_INFO, "Status: %s",
|
col_add_lstr(pinfo->cinfo, COL_INFO,
|
||||||
tvb_format_text(tvb, offset + SIP2_HDR_LEN + 1, linelen - SIP2_HDR_LEN - 1));
|
"Status: ",
|
||||||
|
tvb_format_text(tvb, offset + SIP2_HDR_LEN + 1, linelen - SIP2_HDR_LEN - 1),
|
||||||
|
COL_ADD_LSTR_TERMINATOR);
|
||||||
stat_info->reason_phrase = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + SIP2_HDR_LEN + 5,
|
stat_info->reason_phrase = tvb_get_string_enc(wmem_packet_scope(), tvb, offset + SIP2_HDR_LEN + 5,
|
||||||
linelen - (SIP2_HDR_LEN + 5),ENC_UTF_8|ENC_NA);
|
linelen - (SIP2_HDR_LEN + 5),ENC_UTF_8|ENC_NA);
|
||||||
DPRINT(("got Response: %s",
|
DPRINT(("got Response: %s",
|
||||||
|
|
|
@ -541,8 +541,11 @@ dissect_stun_message(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gboole
|
||||||
msg_class_str = val_to_str_const(msg_type_class, classes, "Unknown");
|
msg_class_str = val_to_str_const(msg_type_class, classes, "Unknown");
|
||||||
msg_method_str = val_to_str_const(msg_type_method, methods, "Unknown");
|
msg_method_str = val_to_str_const(msg_type_method, methods, "Unknown");
|
||||||
|
|
||||||
col_add_fstr(pinfo->cinfo, COL_INFO, "%s %s",
|
col_add_lstr(pinfo->cinfo, COL_INFO,
|
||||||
msg_method_str, msg_class_str);
|
msg_method_str,
|
||||||
|
" ",
|
||||||
|
msg_class_str,
|
||||||
|
COL_ADD_LSTR_TERMINATOR);
|
||||||
|
|
||||||
ti = proto_tree_add_item(tree, proto_stun, tvb, 0, -1, ENC_NA);
|
ti = proto_tree_add_item(tree, proto_stun, tvb, 0, -1, ENC_NA);
|
||||||
|
|
||||||
|
|
|
@ -4145,8 +4145,12 @@ dissect_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||||
|
|
||||||
tcph->th_sport = tvb_get_ntohs(tvb, offset);
|
tcph->th_sport = tvb_get_ntohs(tvb, offset);
|
||||||
tcph->th_dport = tvb_get_ntohs(tvb, offset + 2);
|
tcph->th_dport = tvb_get_ntohs(tvb, offset + 2);
|
||||||
col_add_fstr(pinfo->cinfo, COL_INFO, "%s \xe2\x86\x92 %s", /* UTF8_RIGHTWARDS_ARROW */
|
col_add_lstr(pinfo->cinfo, COL_INFO,
|
||||||
ep_tcp_port_to_display(tcph->th_sport), ep_tcp_port_to_display(tcph->th_dport));
|
ep_tcp_port_to_display(tcph->th_sport),
|
||||||
|
"\xe2\x86\x92", /* UTF8_RIGHTWARDS_ARROW */
|
||||||
|
ep_tcp_port_to_display(tcph->th_dport),
|
||||||
|
COL_ADD_LSTR_TERMINATOR);
|
||||||
|
|
||||||
if (tree) {
|
if (tree) {
|
||||||
if (tcp_summary_in_tree) {
|
if (tcp_summary_in_tree) {
|
||||||
ti = proto_tree_add_protocol_format(tree, proto_tcp, tvb, 0, -1,
|
ti = proto_tree_add_protocol_format(tree, proto_tcp, tvb, 0, -1,
|
||||||
|
|
|
@ -458,8 +458,10 @@ dissect(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 ip_proto)
|
||||||
udph->uh_sport=tvb_get_ntohs(tvb, offset);
|
udph->uh_sport=tvb_get_ntohs(tvb, offset);
|
||||||
udph->uh_dport=tvb_get_ntohs(tvb, offset+2);
|
udph->uh_dport=tvb_get_ntohs(tvb, offset+2);
|
||||||
|
|
||||||
col_add_fstr(pinfo->cinfo, COL_INFO, "Source port: %s Destination port: %s",
|
col_add_lstr(pinfo->cinfo, COL_INFO,
|
||||||
ep_udp_port_to_display(udph->uh_sport), ep_udp_port_to_display(udph->uh_dport));
|
"Source port: ", ep_udp_port_to_display(udph->uh_sport), " "
|
||||||
|
"Destination port: ", ep_udp_port_to_display(udph->uh_dport),
|
||||||
|
COL_ADD_LSTR_TERMINATOR);
|
||||||
|
|
||||||
if (tree) {
|
if (tree) {
|
||||||
if (udp_summary_in_tree) {
|
if (udp_summary_in_tree) {
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include "packet-vlan.h"
|
#include "packet-vlan.h"
|
||||||
#include <epan/etypes.h>
|
#include <epan/etypes.h>
|
||||||
#include <epan/prefs.h>
|
#include <epan/prefs.h>
|
||||||
|
#include <epan/to_str.h>
|
||||||
|
|
||||||
void proto_register_vlan(void);
|
void proto_register_vlan(void);
|
||||||
void proto_reg_handoff_vlan(void);
|
void proto_reg_handoff_vlan(void);
|
||||||
|
@ -117,6 +118,23 @@ capture_vlan(const guchar *pd, int offset, int len, packet_counts *ld ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
columns_set_vlan(column_info *cinfo, guint16 tci)
|
||||||
|
{
|
||||||
|
static const char fast_str[][2] = { "0", "1", "2", "3", "4", "5", "6", "7" };
|
||||||
|
|
||||||
|
char id_str[16];
|
||||||
|
|
||||||
|
guint32_to_str_buf(tci & 0xFFF, id_str, sizeof(id_str));
|
||||||
|
|
||||||
|
col_add_lstr(cinfo, COL_INFO,
|
||||||
|
"PRI: ", fast_str[(tci >> 13) & 7], " "
|
||||||
|
"CFI: ", fast_str[(tci >> 12) & 1], " "
|
||||||
|
"ID: ", id_str,
|
||||||
|
COL_ADD_LSTR_TERMINATOR);
|
||||||
|
col_add_str(cinfo, COL_8021Q_VLAN_ID, id_str);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||||
{
|
{
|
||||||
|
@ -131,9 +149,7 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
|
||||||
|
|
||||||
tci = tvb_get_ntohs( tvb, 0 );
|
tci = tvb_get_ntohs( tvb, 0 );
|
||||||
|
|
||||||
col_add_fstr(pinfo->cinfo, COL_INFO, "PRI: %u CFI: %u ID: %u",
|
columns_set_vlan(pinfo->cinfo, tci);
|
||||||
(tci >> 13), ((tci >> 12) & 1), (tci & 0xFFF));
|
|
||||||
col_add_fstr(pinfo->cinfo, COL_8021Q_VLAN_ID, "%u", (tci & 0xFFF));
|
|
||||||
|
|
||||||
vlan_tree = NULL;
|
vlan_tree = NULL;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue