-
Notifications
You must be signed in to change notification settings - Fork 97
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
Split tc programs from generic tracer #1267
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
482d0b0
Tracer: remove code duplication
rafaelroquetto 3d91a35
Move http maps to common location
rafaelroquetto c09c8da
Clean up unused header
rafaelroquetto e4f2d54
yank tc from k_tracer
rafaelroquetto ff0c68d
Ensure threads are properly joined for graceful exit
rafaelroquetto 896f002
Regenerate ebpf objects
rafaelroquetto 538f800
Test capabilities and ensure tracer is only instantiated when required
rafaelroquetto 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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef HTTP_MAPS_H | ||
#define HTTP_MAPS_H | ||
|
||
#include "vmlinux.h" | ||
#include "bpf_helpers.h" | ||
#include "http_types.h" | ||
|
||
// Keeps track of the ongoing http connections we match for request/response | ||
struct { | ||
__uint(type, BPF_MAP_TYPE_LRU_HASH); | ||
__type(key, pid_connection_info_t); | ||
__type(value, http_info_t); | ||
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS); | ||
__uint(pinning, BEYLA_PIN_INTERNAL); | ||
} ongoing_http SEC(".maps"); | ||
|
||
struct { | ||
__uint(type, BPF_MAP_TYPE_LRU_HASH); | ||
__type(key, connection_info_t); | ||
__type(value, http_info_t); | ||
__uint(max_entries, 1024); | ||
__uint(pinning, BEYLA_PIN_INTERNAL); | ||
} ongoing_http_fallback SEC(".maps"); | ||
|
||
#endif |
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
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "vmlinux.h" | ||
#include "bpf_helpers.h" | ||
#include "bpf_dbg.h" | ||
|
||
#include "http_maps.h" | ||
#include "http_types.h" | ||
#include "tc_ip.h" | ||
#include "tcp_info.h" | ||
|
||
char __license[] SEC("license") = "Dual MIT/GPL"; | ||
|
||
SEC("tc_ingress") | ||
int app_ingress(struct __sk_buff *skb) { | ||
//bpf_printk("ingress"); | ||
|
||
protocol_info_t tcp = {}; | ||
connection_info_t conn = {}; | ||
|
||
if (!read_sk_buff(skb, &tcp, &conn)) { | ||
return 0; | ||
} | ||
|
||
if (tcp_ack(&tcp)) { // ack field must be set, which means we are looking at non SYN packet | ||
// assumes we are the only ones that added options, this can be improved | ||
if (tcp.h_proto == ETH_P_IP && tcp.ip_len == MIN_IP_LEN + MAX_TC_TP_LEN) { | ||
parse_ip_options_ipv4(skb, &conn, &tcp); | ||
} else if (tcp.h_proto == ETH_P_IPV6 && | ||
tcp.l4_proto == IP_V6_DEST_OPTS) { // Destination options used | ||
parse_ip_options_ipv6(skb, &conn, &tcp); | ||
} | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static __always_inline void | ||
update_outgoing_request_span_id(connection_info_t *conn, protocol_info_t *tcp, tp_info_pid_t *tp) { | ||
pid_connection_info_t p_conn = {}; | ||
__builtin_memcpy(&p_conn.conn, conn, sizeof(connection_info_t)); | ||
p_conn.pid = tp->pid; | ||
|
||
http_info_t *h_info = bpf_map_lookup_elem(&ongoing_http, &p_conn); | ||
if (h_info && tp->valid) { | ||
bpf_printk("Found HTTP info, resetting the span id to %x%x", tcp->seq, tcp->ack); | ||
*((u32 *)(&h_info->tp.span_id[0])) = tcp->seq; | ||
*((u32 *)(&h_info->tp.span_id[4])) = tcp->ack; | ||
} | ||
} | ||
|
||
static __always_inline void encode_data_in_ip_options(struct __sk_buff *skb, | ||
connection_info_t *conn, | ||
protocol_info_t *tcp, | ||
tp_info_pid_t *tp) { | ||
// Handling IPv4 | ||
// We only do this if the IP header doesn't have any options, this can be improved if needed | ||
if (tcp->h_proto == ETH_P_IP && tcp->ip_len == MIN_IP_LEN) { | ||
bpf_printk("Adding the trace_id in the IP Options"); | ||
|
||
if (inject_tc_ip_options_ipv4(skb, conn, tcp, tp)) { | ||
update_outgoing_request_span_id(conn, tcp, tp); | ||
} | ||
|
||
bpf_map_delete_elem(&outgoing_trace_map, conn); | ||
} else if (tcp->h_proto == ETH_P_IPV6 && tcp->l4_proto == IPPROTO_TCP) { // Handling IPv6 | ||
bpf_printk("Found IPv6 header"); | ||
|
||
if (inject_tc_ip_options_ipv6(skb, conn, tcp, tp)) { | ||
update_outgoing_request_span_id(conn, tcp, tp); | ||
} | ||
|
||
bpf_map_delete_elem(&outgoing_trace_map, conn); | ||
} | ||
} | ||
|
||
SEC("tc_egress") | ||
int app_egress(struct __sk_buff *skb) { | ||
//bpf_printk("egress"); | ||
|
||
protocol_info_t tcp = {}; | ||
connection_info_t conn = {}; | ||
|
||
if (!read_sk_buff(skb, &tcp, &conn)) { | ||
return 0; | ||
} | ||
|
||
sort_connection_info(&conn); | ||
|
||
tp_info_pid_t *tp = bpf_map_lookup_elem(&outgoing_trace_map, &conn); | ||
|
||
if (tp) { | ||
bpf_printk("egress flags %x, sequence %x", tcp.flags, tcp.seq); | ||
print_http_connection_info(&conn); | ||
|
||
encode_data_in_ip_options(skb, &conn, &tcp, tp); | ||
} | ||
|
||
return 0; | ||
} |
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
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
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
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
Oops, something went wrong.
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.
This needs to be done here, because simply not calling
tctracer.SetupTC()
is not enough. The mere attempt to load the ebpf program (as inebpf.LoadAndAssign()
), which happens way beforeSetupTC()
is called, will trigger the kernel verifier in case CAP_NET_ADMIN is not present (which may be a legitmate case when UseLinuxTC is false).This also keeps the logic giving it visibility where it belongs IMHO.