-
Notifications
You must be signed in to change notification settings - Fork 116
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
Fix http parsing for duplicate HTTP #887
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
|
||
#define MIN_HTTP_SIZE 12 // HTTP/1.1 CCC is the smallest valid request we can have | ||
#define RESPONSE_STATUS_POS 9 // HTTP/1.1 <-- | ||
#define MAX_HTTP_STATUS 599 | ||
|
||
#define PACKET_TYPE_REQUEST 1 | ||
#define PACKET_TYPE_RESPONSE 2 | ||
|
@@ -105,8 +106,8 @@ static __always_inline u8 is_http(unsigned char *p, u32 len, u8 *packet_type) { | |
if (len < MIN_HTTP_SIZE) { | ||
return 0; | ||
} | ||
//HTTP | ||
if ((p[0] == 'H') && (p[1] == 'T') && (p[2] == 'T') && (p[3] == 'P')) { | ||
//HTTP/1.x | ||
if ((p[0] == 'H') && (p[1] == 'T') && (p[2] == 'T') && (p[3] == 'P') && (p[4] == '/') && (p[5] == '1') && (p[6] == '.')) { | ||
*packet_type = PACKET_TYPE_RESPONSE; | ||
return 1; | ||
} else if ( | ||
|
@@ -337,6 +338,9 @@ static __always_inline void process_http_response(http_info_t *info, unsigned ch | |
info->status += (buf[RESPONSE_STATUS_POS] - '0') * 100; | ||
info->status += (buf[RESPONSE_STATUS_POS + 1] - '0') * 10; | ||
info->status += (buf[RESPONSE_STATUS_POS + 2] - '0'); | ||
if (info->status > MAX_HTTP_STATUS) { // we read something invalid | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defensive measure to at reset the status if we parsed something incorrect, allowing us to potentially find the correct response (or at least set 0). |
||
info->status = 0; | ||
} | ||
} | ||
|
||
static __always_inline http_connection_metadata_t *connection_meta(pid_connection_info_t *pid_conn, u8 direction, u8 packet_type) { | ||
|
@@ -593,7 +597,7 @@ static __always_inline void handle_buf_with_connection(pid_connection_info_t *pi | |
|
||
bpf_dbg_printk("=== http_buffer_event len=%d pid=%d still_reading=%d ===", bytes_len, pid_from_pid_tgid(bpf_get_current_pid_tgid()), still_reading(info)); | ||
|
||
if (packet_type == PACKET_TYPE_REQUEST && (info->status == 0)) { | ||
if (packet_type == PACKET_TYPE_REQUEST && (info->status == 0) && (info->start_monotime_ns == 0)) { | ||
http_connection_metadata_t *meta = connection_meta(pid_conn, direction, PACKET_TYPE_REQUEST); | ||
|
||
get_or_create_trace_info(meta, pid_conn->pid, &pid_conn->conn, u_buf, bytes_len, capture_header_buffer); | ||
|
@@ -625,7 +629,7 @@ static __always_inline void handle_buf_with_connection(pid_connection_info_t *pi | |
// incomplete trace info in user space. | ||
bpf_probe_read(info->buf, FULL_BUF_SIZE, u_buf); | ||
process_http_request(info, bytes_len, meta, direction); | ||
} else if (packet_type == PACKET_TYPE_RESPONSE) { | ||
} else if ((packet_type == PACKET_TYPE_RESPONSE) && (info->status == 0)) { | ||
handle_http_response(small_buf, pid_conn, info, bytes_len, direction, ssl); | ||
} else if (still_reading(info)) { | ||
info->len += bytes_len; | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be more specific on what you are looking for, HTTP is not enough.