← Back to list

cBPF: The Classic Berkeley Packet Filter Explained

cBPF (classic Berkeley Packet Filter) is a packet filtering mechanism used in networking to efficiently capture or filter packets within…

Charles Wan · 2024-12-21 15:49 · 0 claps · 2.0 min read
#cbpf #ebpf #networking #monitoring #observability
Open on Medium ↗

cBPF: The Classic Berkeley Packet Filter Explained

Photo by Abhishek Kirloskar on Unsplash

Photo by Abhishek Kirloskar on Unsplash

cBPF (classic Berkeley Packet Filter) is a packet filtering mechanism used in networking to efficiently capture or filter packets within the kernel. It originated from the Berkeley Packet Filter (BPF) system, introduced in Unix systems to provide a high-performance mechanism for user-space applications (like tcpdump) to filter packets without requiring all network traffic to be copied to user space.

cBPF stands for classic Berkeley Packet Filter. It is an earlier, simpler version of the Berkeley Packet Filter (BPF), a mechanism that allows filtering packets in network traffic. It was originally designed in the 1990s to improve packet filtering performance in Unix-like operating systems.

Purpose

cBPF provides a way to efficiently filter packets directly in the kernel without having to copy all packets to user space for inspection. This reduces overhead and improves performance for network monitoring and traffic analysis tools like tcpdump and Wireshark.

Design

  • Instruction Set: cBPF uses a minimalistic, stack-based virtual machine instruction set. It defines a sequence of instructions that the kernel executes to determine whether a packet matches the filter criteria.
  • Simplicity: The design is relatively simple, making it lightweight but less flexible compared to modern eBPF (extended BPF).

Limitations

  • Static and Limited: cBPF programs are static and cannot be dynamically extended or modified after they are loaded.
  • Performance: While it was efficient for its time, cBPF is less optimized compared to newer technologies like eBPF.
  • Flexibility: cBPF’s capabilities are limited to basic filtering tasks.

Key Features of cBPF:

  1. Virtual Machine Model:
  • cBPF uses a simple virtual machine model with its own instruction set to process packet data. Programs written in cBPF are bytecode instructions executed by this virtual machine.
  1. Efficient Filtering:
  • Packet filtering is performed in the kernel space, reducing the need to copy unnecessary packets to user space, thereby improving performance.
  1. Portability:
  • The bytecode format makes cBPF programs portable across different architectures.
  1. Integration:
  • cBPF is used by tools like tcpdump, libpcap, and network filtering features in Unix-like operating systems.

Modern Evolution:

cBPF has largely been superseded by eBPF (extended BPF), which provides:

  • Providing a more robust instruction set.
  • Better performance.
  • Enhanced capabilities, including interaction with kernel data structures and performing arbitrary computations.
  • Supporting dynamic updates.
  • Enabling use cases beyond packet filtering, such as security, performance monitoring, and network observability.

eBPF also includes a JIT (Just-In-Time) compiler, allowing its programs to be compiled into native machine code for additional speed.

For most modern networking and observability tasks, eBPF is preferred due to its flexibility and power. However, cBPF remains relevant in legacy systems and specific scenarios where simplicity is a priority.

Usage

Despite its limitations, cBPF is still supported for backward compatibility in Linux. It’s commonly associated with tools like tcpdump that generate cBPF filters from human-readable filter expressions.


메타데이터
post_id
429bd40dbfcd
slug
cbpf-the-classic-berkeley-packet-filter-explained-429bd40dbfcd
url
https://medium.com/@charleswan111/cbpf-the-classic-berkeley-packet-filter-explained-429bd40dbfcd
canonical_url
https://medium.com/@charleswan111/cbpf-the-classic-berkeley-packet-filter-explained-429bd40dbfcd
author_url
https://medium.com/@charleswan111
status
ok
fetched_at
2026-06-26 21:52:29