Skip to content

Commit

Permalink
Fix direct packet access (#1575)
Browse files Browse the repository at this point in the history
* Pull skb data before direct access

* Const-correctness for TP_BUF

* Update object files
  • Loading branch information
rafaelroquetto authored Jan 24, 2025
1 parent 9e3697b commit c50edf4
Show file tree
Hide file tree
Showing 38 changed files with 80 additions and 79 deletions.
3 changes: 2 additions & 1 deletion bpf/tc_tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ int beyla_app_egress(struct __sk_buff *skb) {

if (ctx) {
bpf_dbg_printk("No trace-map info, filling up the hole setup by sk_msg");
write_traceparent(skb, &tcp, &e_key, ctx, (unsigned char *)INV_TP);
bpf_skb_pull_data(skb, skb->len);
write_traceparent(skb, &tcp, &e_key, ctx, INV_TP);
}
}

Expand Down
12 changes: 6 additions & 6 deletions bpf/tc_tracer_l7.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ static __always_inline int buf_memcpy(char *dest, char *src, s32 size, void *end
return 0;
}

static __always_inline unsigned char *tp_buf_mem(tp_info_t *tp) {
static __always_inline const char *tp_buf_mem(tp_info_t *tp) {
int zero = 0;
tp_buf_data_t *val = (tp_buf_data_t *)bpf_map_lookup_elem(&tp_buf_memory, &zero);

Expand All @@ -106,7 +106,7 @@ static __always_inline unsigned char *tp_buf_mem(tp_info_t *tp) {
__builtin_memcpy(val->buf, TP, EXTEND_SIZE);
make_tp_string(val->buf + TP_PREFIX_SIZE, tp);

return val->buf;
return (const char *)val->buf;
}

static __always_inline void l7_app_ctx_cleanup(egress_key_t *e_key) {
Expand Down Expand Up @@ -134,7 +134,7 @@ static __always_inline int write_traceparent(struct __sk_buff *skb,
protocol_info_t *tcp,
egress_key_t *e_key,
tc_http_ctx_t *ctx,
unsigned char *tp_buf) {
const char *tp_buf) {
u32 tot_len = (u64)ctx_data_end(skb) - (u64)ctx_data(skb);
u32 packet_size = tot_len - tcp->hdr_len;
bpf_dbg_printk("Writing traceparent packet_size %d, offset %d, tot_len %d",
Expand Down Expand Up @@ -290,10 +290,10 @@ static __always_inline int l7_app_egress(struct __sk_buff *skb,

bpf_dbg_printk("egress, s_port %d, data_start %d", conn->s_port, tcp->hdr_len);

unsigned char *tp_buf = tp_buf_mem(&tp->tp);
const char *tp_buf = tp_buf_mem(&tp->tp);

if (!tp_buf) {
tp_buf = (unsigned char *)TP;
tp_buf = TP;
}

// This is where the writing of the 'Traceparent: ...' field happens at L7.
Expand All @@ -309,4 +309,4 @@ static __always_inline int l7_app_egress(struct __sk_buff *skb,
return 0;
}

#endif // _TC_TRACER_L7
#endif // _TC_TRACER_L7
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_tp_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_tp_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_tp_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_tp_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/generictracer/bpf_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_tp_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_tp_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_tp_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_tp_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gotracer/bpf_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gpuevent/bpf_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gpuevent/bpf_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gpuevent/bpf_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/gpuevent/bpf_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/httptracer/bpf_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/httptracer/bpf_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/httptracer/bpf_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/httptracer/bpf_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/tctracer/bpf_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/tctracer/bpf_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/tctracer/bpf_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/tctracer/bpf_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/watcher/bpf_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/watcher/bpf_debug_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/watcher/bpf_debug_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/ebpf/watcher/bpf_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/netolly/ebpf/net_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/netolly/ebpf/net_x86_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/netolly/ebpf/netsk_arm64_bpfel.o
Git LFS file not shown
4 changes: 2 additions & 2 deletions pkg/internal/netolly/ebpf/netsk_x86_bpfel.o
Git LFS file not shown

0 comments on commit c50edf4

Please sign in to comment.