LightBPF: Pure-Python Berkeley Packet Filter (cBPF) Engine
LightBPF is a standalone, pure-Python Berkeley Packet Filter engine for packet sniffing, inspection, and network security applications. It tokenizes, parses, compiles, disassembles, and emulates classic BPF (cBPF / pcap-filter) bytecode with zero native C dependencies.
+------------------+ +------------------+ +----------------------+
| Filter Text | | Token Stream | | Abstract Syntax Tree |
| "tcp port 80" | -----> | [IP-PROTO, tcp], | -----> | KeywordFilterNode |
| | (Lexer) | [KEYWORD, port] | (Parser)| (port=80, tcp) |
+------------------+ +------------------+ +----------------------+
|
| (Compiler)
v
+----------------------+
| cBPF Machine Code |
| (List[Instruction]) |
+----------------------+
/ \
/ \
v v
+------------------+ +-------------------+
| Linux Raw Socket | | Pure-Python VM |
| SO_ATTACH_FILTER | | (BpfEmulator) |
+------------------+ +-------------------+
Table of Contents
- Key Features
- Quick Start Guide
- Supported Filter Syntax Cheat Sheet
- Architecture & Pipeline
- Developer Deep-Dive: Stage 1 — Lexer (
Lexer.py) - Developer Deep-Dive: Stage 2 — Parser (
Parser.py) - Developer Deep-Dive: Stage 3 — Compiler (
Compiler.py) - Worked Examples & Disassembly Traces
- Verification & Testing
- Opcode & Constant Reference
Key Features
- 100% Pure Python: Runs everywhere without needing
libpcap,gcc, or external tools installed. - Full cBPF Instruction Coverage: Complete support for classes, addressing modes, arithmetic/bitwise operations, and jump branches.
- Dual-Stack Networking: Handles both IPv4 (with dynamic IHL header offsets) and IPv6 (multi-word 128-bit checks).
- Rich Protocol & Filter Support: Protocols (
tcp,udp,icmp,arp,vlan,mpls), network filters (host,net,port,portrange), byte access (tcp[13],ip[2:2]), and pseudo-fields (tcpflags,icmptype). - Scratch Memory Spilling: Uses cBPF registers
M[0..15]to compile nested mathematical expressions on both sides of comparisons. - Peephole Jump Optimization: Automatically flattens jump chains via jump threading.
- Integrated VM Emulator: Execute BPF filters on raw byte packets in unit tests or user-space applications without root privileges.
- Standard Serialization: Export to Linux kernel
struct sock_fprogor 8-byte raw machine instruction streams.
Installation
From our PyPi image (wheel)
pip install lightbpf
From our github (source)
git clone https://github.com/Light-Projects/LightBPF
Quick Start Guide
Compiling a Filter
from LightBPF.CompilerSet.Compiler import BpfCompiler
# Compile a classic filter string directly into cBPF bytecode
instructions = BpfCompiler.compile_str("tcp port 80 and src host 192.168.1.10")
print(f"Compiled into {len(instructions)} BPF instructions:")
for i, insn in enumerate(instructions):
print(f" [{i:02d}] {insn}")
Offline Packet Filtering (BpfEmulator)
You can execute filters directly on raw bytes in Python:
from LightBPF.CompilerSet.Compiler import BpfCompiler
from LightBPF.CompilerSet.Emulator import BpfEmulator
filter_code = BpfCompiler.compile_str("tcp[tcpflags] & tcp-syn != 0")
raw_packet = b"..." # raw Ethernet frame bytes
# Returns captured length (> 0) if matched, 0 if rejected
match_len = BpfEmulator.execute(filter_code, raw_packet)
if match_len > 0:
print(f"Matched! Captured {match_len} bytes.")
else:
print("Rejected.")
Attaching to Linux Raw Sockets
Attach compiled filters straight to a Linux AF_PACKET raw socket with SO_ATTACH_FILTER:
import socket
from LightBPF.CompilerSet.Compiler import BpfCompiler
from LightBPF.CompilerSet.Fprog import to_fprog
# 1. Open raw socket
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x0003))
sock.bind(("eth0", 0))
# 2. Compile and package into ctypes sock_fprog
instructions = BpfCompiler.compile_str("tcp and port 443")
fprog = to_fprog(instructions)
# 3. Attach in kernel space
SO_ATTACH_FILTER = 26
sock.setsockopt(socket.SOL_SOCKET, SO_ATTACH_FILTER, fprog)
Disassembling Bytecode
Print human-readable cBPF assembly formatted like tcpdump -d:
from LightBPF.CompilerSet.Compiler import BpfCompiler
from LightBPF.CompilerSet.Disassembler import disassemble
insns = BpfCompiler.compile_str("ip and (port 80 or port 443)")
print(disassemble(insns))
Supported Filter Syntax Cheat Sheet
| Category | Filter Examples | Description |
|---|---|---|
| Protocols | ip, ip6, tcp, udp, icmp, arp, vlan, mpls, ether |
Standalone protocol verification |
| Hosts | host 192.168.1.1src host 10.0.0.1dst host fe80::1ether host aa:bb:cc:dd:ee:ff |
Match IPv4, IPv6 (4 words), or MAC address |
| Networks | net 10.0.0.0/8src net 192.168.1.0/24net 10.0.0.0 mask 255.0.0.0ip6 net 2001:db8::/32 |
CIDR and netmask matching |
| Ports | port 80tcp dst port 443udp port 53src port httpportrange 1000-2000 |
Port, port range, and service name resolution |
| Byte Access | tcp[13] & 2 != 0ip[2:2] > 500ether[12:2] == 0x0800tcp[tcpflags] & tcp-syn != 0 |
Arbitrary byte/half/word extraction |
| Header Length | (ip[0] & 0xf) * 4 > 20 |
Dynamic IPv4 IHL calculations |
| Packet Size | len > 100, less 64, greater 1500 |
Frame size checks via BPF_LEN |
| Broadcast / Multicast | broadcastmulticast |
Ethernet broadcast and multicast bit checks |
| VLAN / MPLS | vlan, vlan 100mpls, mpls 500 |
Tag presence and ID/label extraction |
| Protocol Numbers | ip proto 6, ip proto tcp, ether proto 0x0800 |
Layer 3/4 protocol inspection |
| Boolean Logic | tcp and port 80tcp or udpnot port 22(tcp or udp) and not dst port 53 |
Short-circuit boolean combinations |
Architecture & Pipeline
The Classic BPF (cBPF) Virtual Machine
cBPF is a 32-bit register machine designed specifically for in-kernel packet filtering:
+----------------------------------------------------------------+
| cBPF Virtual Machine Registers |
| |
| [ Register A ] (32-bit Accumulator) |
| - Holds results of packet loads, arithmetic, and tests |
| |
| [ Register X ] (32-bit Index Register) |
| - Used for indexed packet addressing: packet[X + k] |
| - Second operand for ALU operations |
| |
| [ Memory M[0..15] ] (16 Scratch Words) |
| - Register spill space for complex nested expressions |
| |
| [ Program Counter (PC) ] |
+----------------------------------------------------------------+
Instruction Structure (struct bpf_insn)
Every instruction is exactly 8 bytes:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| code (16) | jt (8) | jf (8) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| k (32) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
code(16 bits): Opcode encoding class, size modifier, and addressing mode/ALU operator.jt(8 bits): Jump-true relative offset (number of instructions to skip forward if comparison succeeds).jf(8 bits): Jump-false relative offset (number of instructions to skip forward if comparison fails).k(32 bits): Multi-purpose value (packet offset, immediate constant, or scratch index).
Developer Deep-Dive: Stage 1 — Lexer (Lexer.py)
The BpfLexer turns a raw filter string into a list of typed Token tuples: (type, value).
Tokenizer Mechanics
- Regex Ordering: The tokenizer runs a single compiled regex with named groups. Specific tokens (such as MAC addresses and IPv6 with colons) take precedence over general words and symbols.
- Normalization: Operators like
&&,||, and!are normalized directly intoand,or, andnot. - Named Constants: TCP flags (
tcp-syn,tcp-ack,tcp-fin) and ICMP types (icmp-echo,icmp-echoreply) are resolved directly into integerNUMBERtokens at lex time.
Token Reference Table
| Token Type | Examples | Produced From |
|---|---|---|
NUMBER |
'80', '2048', '2' |
Integer digits, hex (0x0800), named constants (tcp-syn $\rightarrow$ 2) |
IPV4 |
'192.168.1.1' |
Standard dotted-quad IPv4 |
IPV4_CIDR |
'10.0.0.0/8' |
Dotted-quad with prefix |
IPV6 |
'fe80::1' |
Colon-delimited hex address |
IPV6_CIDR |
'2001:db8::/32' |
Colon-hex with prefix |
MAC |
'aa:bb:cc:dd:ee:ff' |
6 hex pairs with colons |
RANGE |
'1000-2000' |
Port range syntax |
IP-PROTOCOL |
'tcp', 'udp', 'icmp', 'gre' |
IP protocol names |
ETHERTYPE |
'ip', 'ip6', 'arp', 'vlan' |
Link-layer protocol names |
KEYWORD |
'host', 'port', 'net', 'src', 'dst' |
Filter keywords |
FIELD |
'tcpflags', 'icmptype' |
Named protocol fields |
REL_OP |
'==', '!=', '>', '>=', '<', '<=' |
Comparison operators |
MATH_OP |
'+', '-', '*', '/', '%', '&', '|', '^', '<<', '>>' |
Arithmetic and bitwise operators |
Developer Deep-Dive: Stage 2 — Parser (Parser.py)
The BpfParser implements a recursive descent parser that turns the token stream into an Abstract Syntax Tree (AST).
Grammar & Operator Precedence
Precedence is enforced through tiered grammar methods (lowest to highest):
expr_or := expr_and ( 'or' expr_and )*
expr_and := expr_not ( 'and' expr_not )*
expr_not := 'not' expr_not | expr_primary
expr_primary := '(' expr_or ')' | qualifier_rule | expr_relation
expr_relation := expr_bitor ( REL_OP expr_bitor )?
expr_bitor := expr_bitxor ( '|' expr_bitxor )*
expr_bitxor := expr_bitand ( '^' expr_bitand )*
expr_bitand := expr_shift ( '&' expr_shift )*
expr_shift := expr_add ( ('<<'|'>>') expr_add )*
expr_add := expr_mult ( ('+'|'-') expr_mult )*
expr_mult := expr_atom ( ('*'|'/'|'%') expr_atom )*
Abstract Syntax Tree (AST) Reference
# Boolean Operations
BinaryOpNode(left: ASTNode, op: str, right: ASTNode)
UnaryOpNode(op: str, expr: ASTNode)
# Protocols & Qualifiers
ProtocolNode(name: str, proto_num: Optional[int] = None)
KeywordFilterNode(
keyword: str,
value: Any = None,
direction: Optional[str] = None, # 'src' | 'dst' | 'src or dst' | 'src and dst'
protocol: Optional[str] = None, # 'tcp' | 'ip6' | 'ether' ...
value_type: Optional[str] = None, # 'ipv4' | 'ipv6' | 'mac' | 'cidr4' | 'cidr6' | 'number' | 'range' | 'name'
mask: Optional[str] = None # for 'net X mask Y'
)
# Packet Access & Values
ByteAccessNode(protocol: str, offset: ASTNode, size: int = 1)
LengthNode() # 'len' operand
NumberNode(value: int)
LiteralNode(value: str, kind: str)
FieldNode(name: str) # 'tcpflags', 'icmptype'
Developer Deep-Dive: Stage 3 — Compiler (Compiler.py)
The BpfCompiler walks the AST and emits classic BPF instructions.
Short-Circuit Boolean Control Flow
All boolean sub-expressions compile with two symbolic jump targets: true_target and false_target.
A and B:Acompiles withtrue_target = label_Bandfalse_target = overall_false. IfApasses, it falls intoB. IfAfails, it immediately jumps tooverall_false.A or B:Acompiles withtrue_target = overall_trueandfalse_target = label_B. IfApasses, it immediately short-circuits tooverall_true.not A: Swaps the true and false branch targets ofA.
Relative Jump Resolution & Jump Threading
In cBPF, relative jump offsets specify how many instructions to skip past the next instruction:
Before computing final numeric offsets, the compiler executes Jump Threading (Peephole Optimization):
If a jump target points to an unconditional jump (ja target_2), the compiler rewrites the jump to target target_2 directly, eliminating wasted jump hops.
Register Spilling via Scratch Memory (M[0..15])
cBPF only has two general registers: Accumulator A and Index X. When compiling complex binary operations where both the left and right operands are expressions (e.g. (ip[0] & 0xf) * 4 == (tcp[12] >> 4) * 4):
- Right operand compiles into Register
A. - Emits
st M[scratch]to store the right operand in scratch memory. - Left operand compiles into Register
A. - Emits
ldx M[scratch]to load the right operand into RegisterX. - Emits the ALU or comparison operation using Register
X(BPF_X).
Dynamic IPv4 IHL Tracking (BPF_MSH)
IPv4 headers can vary in length between 20 and 60 bytes due to optional fields. To locate transport-layer headers (TCP/UDP) reliably without hardcoding an offset:
self._emit(Instruction(BPF_LDX | BPF_B | BPF_MSH, 0, 0, 14))
The BPF_MSH opcode computes:
storing the exact byte length of the IPv4 header into Register X.
Subsequent transport-layer loads use indexed addressing (BPF_IND):
- Source Port:
ldh [x + 14] - Destination Port:
ldh [x + 16]
VLAN 802.1Q Handling
An 802.1Q tagged frame has the following layout:
Byte 12..13: TPID (0x8100)
Byte 14..15: TCI (Bits 15-13: Priority, Bit 12: DEI, Bits 11-0: 12-bit VLAN ID)
For vlan 100:
ldh [12]$\rightarrow$ Verify EtherType is0x8100.ldh [14]$\rightarrow$ Load 16-bit TCI.and #0x0fff$\rightarrow$ Mask out Priority and DEI to isolate the 12-bit VLAN ID.jeq #100$\rightarrow$ Match target VLAN ID.
Bitmask Optimization (BPF_JSET)
When testing specific bitflags (e.g. tcp[13] & 2 != 0 or tcp[tcpflags] & tcp-syn != 0), the compiler optimizes this pattern into a single BPF_JSET jump instruction:
ldb [x + 27] ; Load TCP flags byte
jset #2 jt ACCEPT jf REJECT
This tests (A & 2) != 0 in a single hardware cycle.
Worked Examples & Disassembly Traces
Example 1: tcp and port 80
insns = BpfCompiler.compile_str("tcp and port 80")
print(disassemble(insns))
(000) ldh [12] ; Load EtherType
(001) jeq #0x800 jt 2 jf 9 ; Is IPv4?
(002) ldb [23] ; Load IP Protocol byte
(003) jeq #6 jt 4 jf 9 ; Is TCP (6)?
(004) ldxb 4*([14]&0xf) ; Load IPv4 Header Length into X
(005) ldh [x + 14] ; Load TCP Source Port
(006) jeq #80 jt 8 jf 7 ; Is src port 80? (If yes, accept)
(007) ldh [x + 16] ; Load TCP Destination Port
(008) jeq #80 jt 10 jf 9 ; Is dst port 80? (If yes, accept; else reject)
(009) ret #0 ; REJECT (Return 0)
(010) ret #262144 ; ACCEPT (Return max buffer)
Example 2: tcp[13] & 2 != 0 (TCP SYN)
insns = BpfCompiler.compile_str("tcp[13] & 2 != 0")
print(disassemble(insns))
(000) ldxb 4*([14]&0xf) ; X = IPv4 IHL
(001) ldb [x + 27] ; Load byte 13 of TCP (14 + 13 = 27)
(002) jset #2 jt 4 jf 3 ; Test bit 2 (SYN flag)
(003) ret #0 ; REJECT
(004) ret #262144 ; ACCEPT
Example 3: host 192.168.1.1
insns = BpfCompiler.compile_str("host 192.168.1.1")
print(disassemble(insns))
(000) ldh [12] ; Load EtherType
(001) jeq #0x800 jt 2 jf 5 ; Is IPv4?
(002) ld [26] ; Load Source IP
(003) jeq #0xc0a80101 jt 6 jf 4 ; Matches 192.168.1.1?
(004) ld [30] ; Load Destination IP
(005) jeq #0xc0a80101 jt 6 jf 5 ; Matches 192.168.1.1?
(006) ret #0 ; REJECT
(007) ret #262144 ; ACCEPT
Example 4: vlan 100
insns = BpfCompiler.compile_str("vlan 100")
print(disassemble(insns))
(000) ldh [12] ; Load EtherType
(001) jeq #0x8100 jt 2 jf 5 ; Is 802.1Q VLAN?
(002) ldh [14] ; Load TCI (Tag Control Information)
(003) and #0xfff ; Mask out Priority & DEI to get 12-bit VID
(004) jeq #100 jt 6 jf 5 ; Is VID == 100?
(005) ret #0 ; REJECT
(006) ret #262144 ; ACCEPT
Example 5: (ip[0] & 0xf) * 4 > 20
Checks if the IPv4 packet contains IP Options (IHL > 20 bytes):
insns = BpfCompiler.compile_str("(ip[0] & 0xf) * 4 > 20")
print(disassemble(insns))
(000) ldb [14] ; Load byte 0 of IP header
(001) and #15 ; Mask lower 4 bits (IHL)
(002) mul #4 ; Multiply by 4 (header length in bytes)
(003) jgt #20 jt 5 jf 4 ; Is header length > 20?
(004) ret #0 ; REJECT
(005) ret #262144 ; ACCEPT
Opcode & Constant Reference
Instruction Classes (code & 0x07)
| Constant | Hex | Description |
|---|---|---|
BPF_LD |
0x00 |
Load into Register A |
BPF_LDX |
0x01 |
Load into Register X |
BPF_ST |
0x02 |
Store Register A into M[k] |
BPF_STX |
0x03 |
Store Register X into M[k] |
BPF_ALU |
0x04 |
Arithmetic or Bitwise operation on A |
BPF_JMP |
0x05 |
Jump operation |
BPF_RET |
0x06 |
Return from filter |
BPF_MISC |
0x07 |
Register transfer (tax, txa) |
Addressing Modes (code & 0xe0)
| Constant | Hex | Description |
|---|---|---|
BPF_IMM |
0x00 |
Immediate constant k |
BPF_ABS |
0x20 |
Absolute packet byte offset packet[k] |
BPF_IND |
0x40 |
Indexed packet offset packet[X + k] |
BPF_MEM |
0x60 |
Scratch memory word M[k] |
BPF_LEN |
0x80 |
Packet length |
BPF_MSH |
0xa0 |
Load $4 \times (\text{packet}[k] \ & \ \text{0x0F})$ into X |
ALU Operations (code & 0xf0)
| Constant | Hex | Operation |
|---|---|---|
BPF_ADD |
0x00 |
A = A + operand |
BPF_SUB |
0x10 |
A = A - operand |
BPF_MUL |
0x20 |
A = A * operand |
BPF_DIV |
0x30 |
A = A / operand |
BPF_OR |
0x40 |
A = A | operand |
BPF_AND |
0x50 |
A = A & operand |
BPF_LSH |
0x60 |
A = A << operand |
BPF_RSH |
0x70 |
A = A >> operand |
BPF_NEG |
0x80 |
A = -A |
BPF_MOD |
0x90 |
A = A % operand |
BPF_XOR |
0xa0 |
A = A ^ operand |
Jump Operations (code & 0xf0)
| Constant | Hex | Jump Condition |
|---|---|---|
BPF_JA |
0x00 |
Unconditional jump |
BPF_JEQ |
0x10 |
Jump if A == operand |
BPF_JGT |
0x20 |
Jump if A > operand |
BPF_JGE |
0x30 |
Jump if A >= operand |
BPF_JSET |
0x40 |
Jump if (A & operand) != 0 |
v1.1 Compiler Fixes
This release combines correctness fixes, a full package reorganisation, and two new optimization passes. The Lexer and Parser are byte-for-byte unchanged; every change lives inside LightBPF/Compiler/ or its sibling modules.
The single largest behavioural change is the completion of false-target threading: every byte-access expression (tcp[13], ip[0], icmp[icmptype], …) now routes protocol-mismatch through the enclosing boolean's reject target, instead of fabricating a 0 value that only happened to be correct for bitmask tests.
Verification target: the following filters compile to bytecode that matches tcpdump -d semantics and round-trip correctly through BpfEmulator on real IPv4, IPv6, ARP, VLAN, and MPLS frames: tcp and port 80, tcp[13] & 2 != 0, host fe80::1, udp port 53, net 10.0.0.0, ip[2:2] > 500, (tcp or udp) and not dst port 53, ip[0] != 5 (ARP frame → reject).
Package Split
The single Compiler.py file is now nine modules organised by concern. The public import path is unchanged — existing callers continue to work:
from LightPacket.LightBPF.CompilerSet.Compiler import BpfCompiler
LightBPF/
├── Lexer.py # tokenizer
├── Parser.py # ast tree
├── README.md # package documentation
├── Ethertype.py # ethertypes dict
├── Constants.py # constants vars
└── CompilerSet/ # new package
├── Opcode.py # BPF_* constants + bitfield accessors
├── Instruction.py # code/jt/jf/k dataclass + serialisation
├── Fprog.py # ctypes sock_fprog / bpf_insn / bpf_struct
├── Peephole.py # instruction-level optimizer (runs after backpatch)
├── Compiler.py # BpfCompiler main class
├── Disassembler.py # disassemble(), c_str_style()
├── Shortcut.py # str shortcuts optimization
├── Emulator.py # BpfEmulator VM
└── LinkLayers/ # datalink-types dir/
├── Ethernet.py # ethernet class
└── BaseLinkType.py # base class
LightBPF 1.2.1
Release Notes & Architecture Upgrades
Overview: Version 1.2.1 is a massive leap forward. It introduces true BSD kernel support, PPPoE encapsulation, strict mathematical AST optimization, and resolves deep compiler state-bleed bugs.
1. BSD Kernel Support NEW
LightBPF is no longer just a user-space emulator. You can now compile cBPF programs and attach them directly to the FreeBSD, NetBSD, OpenBSD, and macOS kernels.
to_bpf_struct()
Added to Fprog.py. While Linux uses struct sock_fprog (with a 16-bit length field), BSDs use struct bpf_program (with a 32-bit length field). This function safely packs your compiled instructions into the exact C-struct layout BSD requires, avoiding memory garbage collection (GC) crashes.
from LightBPF.CompilerSet.Fprog import to_bpf_struct
# Compile a filter
insns = BpfCompiler.compile_str("tcp port 80")
# Pack it for BSD BIOCSETF
bsd_prog = to_bpf_struct(insns)
# Ready for fcntl.ioctl(fd, BIOCSETF, bsd_prog)
2. PPPoE & PPP Protocol Support NEW
Added full support for Point-to-Point Protocol over Ethernet (PPPoE), crucial for capturing ISP traffic.
PPP_PROTOCOLS: A massive new dictionary mapping RFC 1661 PPP protocol numbers (IPv4, IPv6, LCP, CHAP, etc.).compile_pppoes(): The compiler now handles thepppoeskeyword. It correctly verifies the session EtherType (0x8864), checks the session ID (if provided), and shifts all subsequent header offsets by 8 bytes to account for the PPPoE header.
# Compile a PPPoE encapsulated IPv6 TCP port 80
BpfCompiler.compile_str("pppoes and ip6 and tcp port 80")
3. AST Algebraic Optimization OPTIMIZED
The compiler now performs algebraic math on the AST to strip out redundant checks, producing bytecode that is smaller and faster than legacy compilers like tcpdump.
_flatten_and()
Recursively flattens deeply nested and trees (e.g., ((A and B) and C)) into a single list [A, B, C] so the compiler can analyze the entire logic chain at once.
Dropping Dual-Stack Checks
If you write (ip or ip6) and tcp port 80, the compiler is smart enough to know that tcp inherently enforces IP. It will completely drop the (ip or ip6) check, saving 3 instructions and properly routing the TCP header check to both IPv4 and IPv6.
# LightBPF Automatically optimizes this:
"(ip or ip6) and tcp port 22"
# Into this:
"tcp port 22"
4. Compiler State Isolation FIX
The Bug: In previous versions, using vlan inside an or statement caused "State Bleed". The VLAN offset shift would leak into the right side of the or branch, causing the compiler to read the wrong byte offsets.
The Fix: Added save_state() and restore_state() to the BaseLinkType and EthernetLinkType classes. Before compiling the left side of an or, the compiler takes a snapshot. Before compiling the right side, it restores the snapshot.
# This now compiles with mathematically perfect state isolation:
"vlan and (ip or ip6)"
5. Enhanced Strictness
LightBPF 1.2.1 deliberately chooses mathematical strictness over mimicking the 30-year-old tcpdump grammar quirks.
ip or ip6 and tcp port 22means exactly what it says in boolean logic.ip6andtcp port 22are bound together, whileipremains independent.- To distribute a TCP check across both stacks, you just use parentheses:
(ip or ip6) and tcp port 22.
Metadata
Release files for LightBPF 1.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lightbpf-1.2.1.tar.gz | 63.2 kB | Without provenance | Details for lightbpf-1.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lightbpf-1.2.1-py3-none-any.whl | Python 3 | none | any | Details for lightbpf-1.2.1-py3-none-any.whl |
Total release size: 124.7 kB
Release files / lightbpf-1.2.1.tar.gz
| Download URL | lightbpf-1.2.1.tar.gz |
|---|---|
| Size | 63.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2a2b7970e4eb420192f7e0fb15f5e40df2f95828f60cb4f5cfa61e00eb3f6f5a
|
|
BLAKE2b-256 checksum How to use checksums |
94c92a098afedb561819d4a9d29ba026252c3873043746da3e2794955e93f427
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / lightbpf-1.2.1-py3-none-any.whl
| Download URL | lightbpf-1.2.1-py3-none-any.whl |
|---|---|
| Size | 61.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35860a36e76c2803f55152d19125ac1c71f12d0a3f3339d95931bdec3dfa53fc
|
|
BLAKE2b-256 checksum How to use checksums |
5fb1a3bc42709a1eea903d1efbc0d1d217fc229054fd85a73f09330dff6eb137
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for LightBPF 1.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.