Questions tagged [bpf]

The Berkeley Packet Filter (BPF, or cBPF) was initially introduced to provide a raw interface to data link layers in a protocol independent fashion, on BSD systems and then on Linux. More recently, it has been reworked on Linux to give birth to the extended BPF, or eBPF. The latter can be used for network processing at several levels, as well as for security applications, or even tracing and monitoring use cases. This tag is for all cBPF/eBPF questions.

The Berkeley Packet Filter was initially introduced to provide a raw interface to data link layers in a protocol independent fashion, first on BSD systems in the early 90s, then on Linux a few years later. All packets on the network, even those destined for other hosts, would be accessible through this mechanism.

Since 2013, the older BPF subsystem (or cBPF, for classic BPF) has led to the creation to an extended BPF version, or eBPF, on Linux. eBPF has a different architecture. It is more efficient, more flexible, introduces new features (maps, tail calls, helper functions from kernel, etc.). And programs can be attached to a variety of hooks in the kernel, for networking (sockets, as before, but also TC (traffic control) interface, XDP…), for security (cgroups) or for tracing and monitoring the kernel (kprobes, tracepoints, …).

449 questions
2
votes
1 answer

write and read netfilter connectrack using eBPF/XDP

i'm working on a NAT server in pure XDP. but to have a robust nat functionality i wanted to track the connection (storing and fetching tracking data) and i was thinking about using the already exist netfilter conntrack data structure and functions…
walid barakat
  • 455
  • 1
  • 6
  • 17
2
votes
1 answer

Problem with sending data from userspace to bpf program with maps

I have problem with my bpf program. I getting error while loading this program. my bpf program is: #include #include #include #include #include #include…
Redwan
  • 97
  • 6
2
votes
3 answers

ebpf: drop ICMP packet in socket filter program on lo interface

Consider a very simple ebpf code of BPF_PROG_TYPE_SOCKET_FILTER type: struct bpf_insn prog[] = { BPF_MOV64_IMM(BPF_REG_0, -1), BPF_EXIT_INSN(), }; The code snippets below from net/core/filter.c and net/core/sock/c show how the filter will be…
Mark
  • 6,052
  • 8
  • 61
  • 129
2
votes
1 answer

ebpf: where verifier prints its messages?

Where does the verifier print its messages? I have a simple code embedded in struct bpf_insn which I load and attach as BPF_PROG_TYPE_SOCKET_FILTER type: struct bpf_insn prog[] = { BPF_MOV64_REG(BPF_REG_6, BPF_REG_1), BPF_EXIT_INSN(), }; This…
Mark
  • 6,052
  • 8
  • 61
  • 129
2
votes
1 answer

ebpf: bpf_prog_load() vs bpf_object__load()

I have not used libbpf in a while. Now, when I'm looking at the source code and examples, it looks to me that all API now is built around bpf_object while before it was based on program FD (at least on the user-facing level). I believe that fd is…
Mark
  • 6,052
  • 8
  • 61
  • 129
2
votes
0 answers

Instrument functions called in eBPF program using eBPF

I would like to write an eBPF program in order to track the functions being called in a separate running eBPF program. Also, I would like to count the number of times the respective functions have been called. Is this possible? And if so, could…
b0gd4n
  • 39
  • 2
2
votes
1 answer

Sharing a map between two BPF programs

I know this question is asked before, but I failed to find any post that has an example on how to do it. Specifically, one BPF program defines a map, and the other BPF program accesses that map. Note that it is Not one BPF program defines a map, and…
pyang
  • 109
  • 7
2
votes
1 answer

Scapy BPF filter for TLS client hello and TCP SYN

I'm trying to write a BPF filter for scapy's sniff() to capture packets that are TLSClientHello packets OR TCP SYN packets. Here's what I have: sniff(filter="tcp dst port 443 and ((tcp[((tcp[12] & 0xf0) >> 2)] = 0x16) or (tcp[13] & 0x02 = 1))",…
2
votes
1 answer

Debugging bpf and bpf jit

I wrote some bpf programs. I've enabled echo "2" > /proc/sys/net/core/bpf_jit_enable so it outputs the generated jitted code in logs, but I don't have bpf_jit_disasm inside the qemu environment in which I generated the jitted code. The qemu…
user40061
  • 85
  • 2
  • 5
2
votes
1 answer

Using bcc python to detach probe

I am searching for a counterpart function with attach_kprobe(), which can detach the probe we insert previously. If it doesn't exist, are there any possible to detach inserted probe in same program using Python? Any suggestion will be appreciated!
Steven
  • 811
  • 4
  • 23
2
votes
2 answers

How to modify userspace memory using eBPF?

I'm trying to write a sample code and see how it works practically. As said here and discussed here. If everything is correct the output should be: $ cat foo1 this is foo1 content $ cat foo2 this is foo2 content $ sudo bcc_mangle_open.py & [1]…
avsr
  • 143
  • 3
  • 15
2
votes
1 answer

Attaching eBPF to KPROBE?

I wrote a simple program to attach to execve system call with a kprobe, but I am unable to see the relevant output. Here is my one.c (BPF program): #include #include #include #include #include…
avsr
  • 143
  • 3
  • 15
2
votes
0 answers

Missing/unknown symbols when printing stack traces with BPF in Rust

I am using the memleak BCC tool to trace memory allocations in my Rust code but I notice a lot of my stack traces seem either incomplete or have missing symbol names. Reading Brendan Gregg's BPF Performance Tools book, it seems the two common causes…
adelbertc
  • 7,270
  • 11
  • 47
  • 70
2
votes
2 answers

Capturing PTP packets with Linux raw socket

I want to implement a C program that captures all the Precision-Time-Protocol (PTP) frames on the Ethernet, so I created a raw socket and attached a filter for PTP, I use recvmsg() to read data from the socket. The first issue is that I wasn't…
2
votes
1 answer

ebpf program loading error: unknown func bpf_l4_csum_replace#11

I am testing a nat program using ebpf. But the ebpf prog loader throws a error message: 221: (85) call bpf_l4_csum_replace#11 unknown func bpf_l4_csum_replace#11 What does it mean ? How to solve it ? Thanks.
lrouter
  • 349
  • 1
  • 5
  • 20