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

Unable to run bpf program as non root

I am trying to run a simple bpf program that I wrote. But I am not able to run it as non root user. Below is the program I am trying to load, It basically gets the pointer to my map whose fd is map_fd (I am not showing the code where I create the…
user40061
  • 85
  • 2
  • 5
3
votes
1 answer

How to share a ebpf map between interfaces

Is it possible to share an ebpf Map between two network interfaces. I want to write an XDP program and hook it on two devices namely eth0 and eth1. The implementation requires that they both use the same map. Is it possible to load the same program,…
WIOUW
  • 113
  • 1
  • 2
  • 7
3
votes
1 answer

BPF filter fails

Can anyone suggest why this (classic) BPF program sometimes lets non-DHCP-response packets through: # Load the Ethertype field BPF_LD | BPF_H | BPF_ABS 12 # And reject the packet if it's not 0x0800 (IPv4) BPF_JMP | BPF_JEQ | BPF_K 0x0800 0 …
Tom
  • 7,269
  • 1
  • 42
  • 69
3
votes
1 answer

Was: How does BPF calculate number of CPU for PERCPU_ARRAY?

I have encountered an interesting issue where a PERCPU_ARRAY created on one system with 2 processors creates an array with 2 per-CPU elements and on another system with 2 processors, an array with 128 per-CPU elements. The latter was rather…
Dmitri
  • 479
  • 3
  • 10
3
votes
2 answers

bcc: ImportError cannot import name BPF

I am getting the following error when trying run the example hello_world.py. Traceback (most recent call last): File "/usr/share/bcc/examples/hello_world.py", line 9, in from bcc import BPF ImportError: cannot import name BPF I…
Sagar Rakshe
  • 2,682
  • 1
  • 20
  • 25
3
votes
1 answer

BPF Ring Buffer Invalid Argument (-22)?

I wanted to use eBPF's latest map, BPF_MAP_TYPE_RINGBUF, but I can't find much information online on how I can use it, so I am just doing some trial-and-error here. I defined and used it like this: struct bpf_map_def SEC("maps") r_buf = { .type…
vanbastelaer
  • 368
  • 2
  • 15
3
votes
1 answer

Generate a executable from bcc python script

bcc uses python to compile ebpf programs, is there any convenient way to generate a executable file from these python scripts so that I can run these tracing programs on servers where clang and llvm environment are not installed?
Cauchy Schwarz
  • 747
  • 3
  • 10
  • 27
3
votes
1 answer

XDP program ip link error: Prog section rejected: Operation not permitted

I try to get into XDP, for this I have this very small program: // SPDX-License-Identifier: GPL-2.0 #include #include "bpf/bpf_helpers.h" #include "xdpsock.h" struct { __uint(type, BPF_MAP_TYPE_ARRAY); __uint(max_entries,…
binaryBigInt
  • 1,526
  • 2
  • 18
  • 44
3
votes
1 answer

Why I don't receive any packets using BPF with udp socket?

GOAL: write a BPF filter which allow just UDP packets from a specific src address and attach it to and UDP socket. PROBLEM: if I execute the program and I try to send udp packets from a VM which has the correct src IP I don't receive none of…
Maicake
  • 1,046
  • 10
  • 34
3
votes
2 answers

Is there any tooling for bpfilter allowing to configure a firewall?

I'd like to know about bpfilter. I can't use netfilter (too slow), nftables (doesn't have my feature set). Kernel says: CONFIG_BPFILTER: …
Stefan Brudny
  • 31
  • 1
  • 2
3
votes
1 answer

golang, ebpf and functions duration

I'm playing with gobpf and have got an issue with calculating a duration of traced user-space function. I use bpf_ktime_get_ns() to read time and then trying to calculate delta, but got enormous numbers, though traced function sleeps just 1…
lesovsky
  • 326
  • 2
  • 14
3
votes
1 answer

eBPF implicit declaration of BPF Helper

I'm having an issue with compiling an eBPF program that I'm installing with TC. At the moment, it is only performing some basic mangling, which requires recalculating the IP checksum. I noticed in the BPF helpers, there is a function…
gsm
  • 389
  • 2
  • 10
3
votes
1 answer

Linux TC eBPF and concurency

Is there a limit to how much instances of an eBPF programs the kernel can run simultaneously on several CPUs (similar to the python GIL problem) In particular can eBPF tc programs work on multiple CPU simultaneously? How is locking of kernel…
Eric
  • 1,138
  • 11
  • 24
3
votes
1 answer

ebpf: intercepting function calls

I am reading about kprobes BPF program type, and am wondering if it is possible to not just intercept a function call for tracing purposes or collect some low-level information (registers, stack etc.), but substitute a call and execute instead of…
Mark
  • 6,052
  • 8
  • 61
  • 129
3
votes
0 answers

How to use trace(one of eBPF toolkits) to probe OpenJDK HotSpot code?

trace is one of the eBPF bcc toolkits. In this example Using the trace multi-tool to watch login requests, by instrumenting the pam library: # trace 'pam:pam_start "%s: %s", arg1, arg2' TIME PID COMM FUNC - 17:49:45 5558 …
skytree
  • 1,060
  • 2
  • 13
  • 38