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
0
votes
1 answer

How to compile tool and samples from within the kernel source tree? (e.g. bpftool, bpf samples)

GOAL: compile samples/bpf, compile bpf/bpftool and use them. PROBLEM: on a VM with Ubuntu 18.04 bionic with a kernel 4.18.0-25-generic I've installed kernel src code executing apt install linux-source-4.18.0. Now I cd into…
Maicake
  • 1,046
  • 10
  • 34
0
votes
0 answers

Is it possible to use BPF as a library in your own program?

It seems like the debugging tools and the way instrumetnation is done should be quite general. Is it possible to have all the benefits of safe JIT'ed code in your program for, basically, the same purpose: performance monitoring and doing hot patches…
wvxvw
  • 8,089
  • 10
  • 32
  • 61
0
votes
1 answer

Why this program which use BPF and RAW SOCKET just hangs?

GOAL: write a simple packet filter using BPF. The packet filter should allow you to choose the interface. PROBLEM: if I uncomment the third to last instruction in the code (where there is a call to recvfrom, the execution just hangs and I can't see…
Maicake
  • 1,046
  • 10
  • 34
0
votes
1 answer

Error compiling eBPF C code out of kernel tree

I'm trying to build a BPF program written in C into the bpf bytecode needed to load it. I used this post to try to start me off: https://blogs.oracle.com/linux/notes-on-bpf-4 I do not want to use BCC due to the library dependency. I'm using ubuntu…
shaddow
  • 405
  • 1
  • 4
  • 19
0
votes
0 answers

Why does adding an established TCP socket to a BPF_MAP_TYPE_SOCKMAP map break SSL?

I have the following BPF program: #include #include #include "bpf_helpers.h" #include "bpf_map.h" struct bpf_map_def SEC("maps/sock_ops") sock_ops = { .type = BPF_MAP_TYPE_SOCKMAP, .key_size =…
dippynark
  • 2,743
  • 20
  • 58
0
votes
1 answer

How can I work out the meaning of the return codes for BPF helper functions?

I am writing a BPF_PROG_TYPE_SOCKET_OPS program and I am seeing the following in /sys/kernel/debug/tracing/trace_pipe: <...>-12586 [001] .... 6972.409111: 0: update err: -95 when I load it due to the following snippet: ret =…
dippynark
  • 2,743
  • 20
  • 58
0
votes
1 answer

bpf/bcc reports error when trying to access `struct rq`

This is my bpf program to profile a kernel function pick_next_task_fiar. #include #include #include #include struct rq; // forward declaration struct val_t { …
Chen Wei
  • 392
  • 2
  • 12
0
votes
1 answer

Classic BPF -- simple stats not available?

I was playing with the classic BPF to filter something on a netlink socket and found that there's no simple stats available to verify if the packet has been dropped or allowed. So I looked at…
Mark
  • 6,052
  • 8
  • 61
  • 129
0
votes
0 answers

bpf_asm returns single ' on compile

I am new to Berkeley Packet Filter . I am trying to learn how to hand roll my own bpf code and then compile it using the bpf_asm. I am working on ubuntu 16.04 with kernel 4.4.0-137. I have downloaded the source code and I am working my way through …
joshu
  • 463
  • 8
  • 18
0
votes
1 answer

outside header file not found during compilation

I'm trying to compile the bpf samples, outside the tree. Here's my folder: . ├── bpf_load.c ├── bpf_load.h ├── bpf_load.o ├── libbpf.h ├── Makefile ├── xdp1 ├── xdp1_kern.c ├── xdp1_kern.o ├── xdp1_user.c ├── xdp2_kern.c └── xdp2_user.c And this is…
Bob Sacamano
  • 699
  • 15
  • 39
0
votes
0 answers

bcc tools memleak for userspacel wide memory leak detection

Is there anyone who has used the memleak tool from bcc to profile userspace memory allocations? I've been trying to adapt it to do that, but it seems highly unreliable, ie the first batch of outstanding allocations seems fine when tested with a…
0
votes
0 answers

How to use tracepoints in Kernel Module

I have started to learn these things recently. Regarding this matter, I came across plenty of resources regarding kprobes, BPF, eBPF, tracepoints and perf. I wanted to test some irq events in the kernel (before it arrived to the device driver).…
cooshal
  • 758
  • 8
  • 21
0
votes
1 answer

Reading BPF Assembly

I'm trying to read some BPF syntax for a filter to try and figure out what it does. One thing I cannot find is where the "byte offset starts". Meaning, that if we have the following assembler code: 0000: 0x28 0x00 0x00 0x00000004 ldh $data[4] …
0
votes
0 answers

How can I retrieve the current task's session ID in a BPF program?

The BPF helper function bpf_get_current_task returns a pointer to the current task's task_struct. How can I use this in a BPF program to retrieve the current task's session ID?
dippynark
  • 2,743
  • 20
  • 58
0
votes
1 answer

Always get 0 session ID in BPF program

I am trying to write a BPF program that examines the session ID of any process that calls the tty_write kernel function. I am trying to do this by retrieving a field from the current task_struct struct. My code is as follows:…
dippynark
  • 2,743
  • 20
  • 58