GRPC: Fix the bug of GRPC-WEB decompression failure over HTTP1.1

1. Passing header name/value map to sub-dissector in packet-http.c.
   Headers can also be used by dissectors other than grpc in the future.

2. Try to get the grpc-encoding header value in packet-grpc.c.
   This header contains decompression algorithm.
This commit is contained in:
Huang Qiangxiong 2022-07-06 22:52:16 +08:00 committed by John Thacker
parent 1c89a14117
commit a618fe72a2
3 changed files with 15 additions and 4 deletions

View File

@ -434,6 +434,9 @@ dissect_grpc(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree, void* data)
grpc_ctx.is_request = (http_msg_info->type == HTTP_REQUEST);
grpc_ctx.path = http_conv->request_uri;
grpc_ctx.content_type = pinfo->match_string; /* only for grpc-web(-text) over http1.1 */
if (http_msg_info->data) {
grpc_ctx.encoding = (const gchar*)wmem_map_lookup((wmem_map_t *)http_msg_info->data, HTTP2_HEADER_GRPC_ENCODING);
}
}
else {
/* unexpected protocol error */

View File

@ -332,7 +332,7 @@ static void process_header(tvbuff_t *tvb, int offset, int next_offset,
const guchar *line, int linelen, int colon_offset,
packet_info *pinfo, proto_tree *tree,
headers_t *eh_ptr, http_conv_t *conv_data,
http_type_t http_type);
http_type_t http_type, wmem_map_t *header_value_map);
static gint find_header_hf_value(tvbuff_t *tvb, int offset, guint header_len);
static gboolean check_auth_ntlmssp(proto_item *hdr_item, tvbuff_t *tvb,
packet_info *pinfo, gchar *value);
@ -1125,6 +1125,7 @@ dissect_http_message(tvbuff_t *tvb, int offset, packet_info *pinfo,
guint16 word;
gboolean leading_crlf = FALSE;
http_message_info_t message_info;
wmem_map_t *header_value_map = wmem_map_new(wmem_packet_scope(), g_str_hash, g_str_equal);
reported_length = tvb_reported_length_remaining(tvb, offset);
if (reported_length < 1) {
@ -1447,7 +1448,7 @@ dissect_http_message(tvbuff_t *tvb, int offset, packet_info *pinfo,
*/
process_header(tvb, offset, next_offset, line, linelen,
colon_offset, pinfo, http_tree, &headers, conv_data,
http_type);
http_type, header_value_map);
}
offset = next_offset;
}
@ -1928,6 +1929,7 @@ dissect_http_message(tvbuff_t *tvb, int offset, packet_info *pinfo,
message_info.type = http_type;
message_info.media_str = media_str;
message_info.data = header_value_map;
if (handle != NULL) {
/*
* We have a subdissector - call it.
@ -3029,7 +3031,7 @@ static void
process_header(tvbuff_t *tvb, int offset, int next_offset,
const guchar *line, int linelen, int colon_offset,
packet_info *pinfo, proto_tree *tree, headers_t *eh_ptr,
http_conv_t *conv_data, http_type_t http_type)
http_conv_t *conv_data, http_type_t http_type, wmem_map_t *header_value_map)
{
int len;
int line_end_offset;
@ -3121,6 +3123,10 @@ process_header(tvbuff_t *tvb, int offset, int next_offset,
memcpy(value, &line[value_offset - offset], value_len);
value[value_len] = '\0';
if (header_value_map) {
wmem_map_insert(header_value_map, header_name, value);
}
if (hf_index == -1) {
/*
* Not a header we know anything about.

View File

@ -91,7 +91,9 @@ typedef struct _http_message_info_t {
http_type_t type; /**< Message type; may be HTTP_OTHERS if not called by HTTP */
const char *media_str; /**< Content-Type parameters */
const char *content_id; /**< Content-ID parameter */
void *data; /**< The http_type is used to indicate the data transported */
/** In http1.0/1.1, data contains the header name/value mappings, valid only within the packet scope.
In other protocols, the http_type is used to indicate the data transported. */
void *data;
} http_message_info_t;
#endif /* __PACKET_HTTP_H__ */