Skip to content

Commit

Permalink
Use TC_ACT_UNSPEC instead of TC_ACT_OK
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelroquetto committed Dec 13, 2024
1 parent 7e782d2 commit 47d4d52
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 34 deletions.
3 changes: 1 addition & 2 deletions bpf/flow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
#define __FLOW_H__

#include "vmlinux.h"
#include "tc_act.h"

#define TC_ACT_OK 0
#define TC_ACT_SHOT 2
#define IP_MAX_LEN 16

#define ETH_ALEN 6 /* Octets in one ethernet addr */
Expand Down
6 changes: 3 additions & 3 deletions bpf/flows.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static inline int fill_ethhdr(struct ethhdr *eth, void *data_end, flow_id *id, u
static inline int flow_monitor(struct __sk_buff *skb) {
// If sampling is defined, will only parse 1 out of "sampling" flows
if (sampling != 0 && (bpf_get_prandom_u32() % sampling) != 0) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}
void *data_end = (void *)(long)skb->data_end;
void *data = (void *)(long)skb->data;
Expand All @@ -157,7 +157,7 @@ static inline int flow_monitor(struct __sk_buff *skb) {
struct ethhdr *eth = (struct ethhdr *)data;
u16 flags = 0;
if (fill_ethhdr(eth, data_end, &id, &flags) == DISCARD) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}
id.if_index = skb->ifindex;

Expand Down Expand Up @@ -261,7 +261,7 @@ static inline int flow_monitor(struct __sk_buff *skb) {
if (flags & FIN_FLAG || flags & RST_FLAG || flags & FIN_ACK_FLAG || flags & RST_ACK_FLAG) {
bpf_map_delete_elem(&flow_directions, &id);
}
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

SEC("tc_ingress")
Expand Down
8 changes: 4 additions & 4 deletions bpf/flows_sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,19 @@ SEC("socket/http_filter")
int beyla_socket__http_filter(struct __sk_buff *skb) {
// If sampling is defined, will only parse 1 out of "sampling" flows
if (sampling != 0 && (bpf_get_prandom_u32() % sampling) != 0) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

u16 flags = 0;
flow_id id;
__builtin_memset(&id, 0, sizeof(id));
if (!read_sk_buff(skb, &id, &flags)) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

// ignore traffic that's not egress or ingress
if (same_ip(id.src_ip.s6_addr, id.dst_ip.s6_addr)) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

u64 current_time = bpf_ktime_get_ns();
Expand Down Expand Up @@ -296,7 +296,7 @@ int beyla_socket__http_filter(struct __sk_buff *skb) {
if (flags & FIN_FLAG || flags & RST_FLAG) {
bpf_map_delete_elem(&flow_directions, &id);
}
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

// Force emitting structs into the ELF for automatic creation of Golang struct
Expand Down
17 changes: 17 additions & 0 deletions bpf/tc_act.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef TC_ACT_H
#define TC_ACT_H

enum tc_act {
TC_ACT_UNSPEC = -1,
TC_ACT_OK = 0,
TC_ACT_RECLASSIFY = 1,
TC_ACT_SHOT = 2,
TC_ACT_PIPE = 3,
TC_ACT_STOLEN = 4,
TC_ACT_QUEUED = 5,
TC_ACT_REPEAT = 6,
TC_ACT_REDIRECT = 7,
TC_ACT_JUMP = 0x10000000
};

#endif
18 changes: 9 additions & 9 deletions bpf/tc_http_tp.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "http_types.h"
#include "tcp_info.h"
#include "tracing.h"
#include "tc_act.h"
#include "tc_common.h"

char __license[] SEC("license") = "Dual MIT/GPL";

enum { TC_ACT_OK = 0, TC_ACT_RECLASSIFY = 1, TC_ACT_SHOT = 2 };
enum { MAX_IP_PACKET_SIZE = 0x7fff };

enum connection_state { ESTABLISHED, FIN_WAIT_1, FIN_WAIT_2, CLOSING, CLOSE_WAIT, LAST_ACK };
Expand Down Expand Up @@ -586,7 +586,7 @@ int beyla_tc_http_egress(struct __sk_buff *ctx) {
struct tcphdr *tcp = tcp_header(ctx);

if (!tcp) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

const u16 src_port = bpf_ntohs(tcp->source);
Expand All @@ -607,7 +607,7 @@ int beyla_tc_http_egress(struct __sk_buff *ctx) {
} else if (tcp->rst) {
// we are aborting, dispatch the packet and call it a day
delete_http_ctx(key);
return TC_ACT_OK;
return TC_ACT_UNSPEC;
} else {
update_conn_state_egress(tcp, http_ctx, key);
}
Expand All @@ -623,11 +623,11 @@ int beyla_tc_http_egress(struct __sk_buff *ctx) {
tp_info_pid_t *tp_info_pid = bpf_map_lookup_elem(&outgoing_trace_map, &e_key);

if (!tp_info_pid) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

if (!is_http_request(ctx)) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

tc_l7_args_t *args = l7_args();
Expand All @@ -639,15 +639,15 @@ int beyla_tc_http_egress(struct __sk_buff *ctx) {
bpf_tail_call(ctx, &tc_l7_jump_table, L7_TC_TAIL_PROTOCOL_HTTP);
}

return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

SEC("tc_ingress")
int beyla_tc_http_ingress(struct __sk_buff *ctx) {
struct tcphdr *tcp = tcp_header(ctx);

if (!tcp) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

const u16 dst_port = bpf_ntohs(tcp->dest);
Expand All @@ -656,7 +656,7 @@ int beyla_tc_http_ingress(struct __sk_buff *ctx) {
struct tc_http_ctx *http_ctx = bpf_map_lookup_elem(&tc_http_ctx_map, &key);

if (!http_ctx) {
return TC_ACT_OK;
return TC_ACT_UNSPEC;
}

u32 ack_seq = bpf_ntohl(tcp->ack_seq);
Expand All @@ -666,5 +666,5 @@ int beyla_tc_http_ingress(struct __sk_buff *ctx) {

update_conn_state_ingress(tcp, http_ctx, key);

return TC_ACT_OK;
return TC_ACT_UNSPEC;
}
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/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 47d4d52

Please sign in to comment.