Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP: rework state machine #1966

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/include/ndpi_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ struct ndpi_flow_tcp_struct {
u_int32_t usenet_stage:2;

/* NDPI_PROTOCOL_HTTP */
u_int32_t http_stage:2;
u_int32_t http_stage:3;

/* NDPI_PROTOCOL_GNUTELLA */
u_int32_t gnutella_stage:2; // 0 - 2
Expand Down Expand Up @@ -1581,9 +1581,6 @@ struct ndpi_flow_struct {
u_int8_t bittorrent_stage; // can be 0 - 255
u_int8_t bt_check_performed : 1;

/* NDPI_PROTOCOL_HTTP */
u_int8_t http_detected:1;

/* NDPI_PROTOCOL_RTSP */
u_int8_t rtsprdt_stage:2;

Expand Down
14 changes: 0 additions & 14 deletions src/lib/ndpi_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7183,20 +7183,6 @@ void ndpi_parse_single_packet_line(struct ndpi_detection_module_struct *ndpi_str
packet->http_response.ptr = &packet->line[0].ptr[NDPI_STATICSTRING_LEN("HTTP/1.1 ")];
packet->http_response.len = packet->line[0].len - NDPI_STATICSTRING_LEN("HTTP/1.1 ");
packet->http_num_headers++;

/* Set server HTTP response code */
if(packet->payload_packet_len >= 12) {
char buf[4];

/* Set server HTTP response code */
strncpy(buf, (char *) &packet->payload[9], 3);
buf[3] = '\0';

flow->http.response_status_code = atoi(buf);
/* https://en.wikipedia.org/wiki/List_of_HTTP_status_codes */
if((flow->http.response_status_code < 100) || (flow->http.response_status_code > 509))
flow->http.response_status_code = 0; /* Out of range */
}
}

if((packet->parsed_lines == 0) && (packet->line[0].len > 0)) {
Expand Down
10 changes: 10 additions & 0 deletions src/lib/protocols/gnutella.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ static void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struc
/* this case works asymmetrically */
if (packet->payload_packet_len > 17 && memcmp(packet->payload, "GNUTELLA CONNECT/", 17) == 0) {
ndpi_int_gnutella_add_connection(ndpi_struct, flow, NDPI_CONFIDENCE_DPI);
/* Extract some metadata HTTP-like */
ndpi_parse_packet_line_info(ndpi_struct, flow);
if(packet->user_agent_line.ptr != NULL)
ndpi_user_agent_set(flow, packet->user_agent_line.ptr, packet->user_agent_line.len);
return;
}

Expand All @@ -73,6 +77,9 @@ static void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struc
|| (packet->line[c].len > 36 && memcmp(packet->line[c].ptr,
"Content-Type: application/x-gnutella-", 37) == 0)) {
ndpi_int_gnutella_add_connection(ndpi_struct, flow, NDPI_CONFIDENCE_DPI);
/* Extract some metadata HTTP-like */
if(packet->user_agent_line.ptr != NULL)
ndpi_user_agent_set(flow, packet->user_agent_line.ptr, packet->user_agent_line.len);
return;
}
}
Expand All @@ -84,6 +91,9 @@ static void ndpi_search_gnutella(struct ndpi_detection_module_struct *ndpi_struc
|| (packet->accept_line.ptr != NULL && packet->accept_line.len > 24
&& memcmp(packet->accept_line.ptr, "application n/x-gnutella", 24) == 0)) {
ndpi_int_gnutella_add_connection(ndpi_struct, flow, NDPI_CONFIDENCE_DPI);
/* Extract some metadata HTTP-like */
if(packet->user_agent_line.ptr != NULL)
ndpi_user_agent_set(flow, packet->user_agent_line.ptr, packet->user_agent_line.len);
}

}
Expand Down
Loading