Skip to content

Commit

Permalink
chore: simplify ebpf redirect check for ipv4 tcp connections (#314)
Browse files Browse the repository at this point in the history
Signed-off-by: Matheus Pimenta <[email protected]>
  • Loading branch information
matheuscscp authored Feb 5, 2025
1 parent 640ce65 commit f8a9cd8
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions ebpf/redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
#include <bpf/bpf_tracing.h>
#include <bpf/bpf_helpers.h>


#define AF_INET 2 // IPv4 family
// IPv4 family
#define AF_INET 2

struct Config {
__u32 emulator_ip;
Expand All @@ -44,16 +44,12 @@ struct {
__type(value, struct Config);
} map_config SEC(".maps");


// Hooks to connect() syscalls. Redirects connections targeting
// the GKE metadata server to the emulator.
SEC("cgroup/connect4")
int redirect_connect4(struct bpf_sock_addr *ctx) {
// Only forward IPv4 TCP connections
if (ctx->user_family != AF_INET) {
return 1;
}
if (ctx->protocol != IPPROTO_TCP) {
// We only care about IPv4 TCP connections
if (ctx->user_family != AF_INET || ctx->protocol != IPPROTO_TCP) {
return 1;
}

Expand Down

0 comments on commit f8a9cd8

Please sign in to comment.