opensnitch/ebpf_prog/common_defs.h
Gustavo Iñiguez Goia 56b2d28b66
ebpf: added support for ipv6 tunnels
In order to intercept UDP tunnels traffic, we use iptunnel_xmit for IPv4
connections. The equivalent of IPv6 would be ip6tunnel_xmit, but
unfortunately it's not public.

So instead of ip6tunnel_xmit, we'll use udp_tunnel6_xmit_skb.

This function receives two parameters besides the struct sock*, in6_addr
*saddr and in6_addr *daddr. If these addresses are not set, usually the
connection is a localhost connection.

On the other hand, this function is defined in the module
ip6_udp_tunnel. If this module is not loaded when the daemon starts,
we'll fail to intercept the connections.

Closes: #1250
2025-05-05 00:34:25 +02:00

39 lines
845 B
C

#ifndef OPENSNITCH_COMMON_DEFS_H
#define OPENSNITCH_COMMON_DEFS_H
#include <linux/sched.h>
#include <linux/ptrace.h>
#include <linux/byteorder/generic.h>
#include <uapi/linux/bpf.h>
#include "bpf_headers/bpf_helpers.h"
#include "bpf_headers/bpf_tracing.h"
//#include <bpf/bpf_core_read.h>
#define BUF_SIZE_MAP_NS 256
#define MAPSIZE 12000
#ifndef htonll
#define htonll(x) cpu_to_be64(x)
#endif
#define debug(fmt, ...) \
( \
{ \
char __fmt[] = fmt; \
bpf_trace_printk(__fmt, sizeof(__fmt), ##__VA_ARGS__); \
})
// even though we only need 32 bits of pid, on x86_32 ebpf verifier complained when pid type was set to u32
typedef u64 pid_size_t;
typedef u64 uid_size_t;
enum bpf_pin_type {
PIN_NONE = 0,
PIN_OBJECT_NS,
PIN_GLOBAL_NS,
PIN_CUSTOM_NS,
};
//-----------------------------------
#endif