Skip to content

segevfiner/pybpf_asm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

45e2a13 · Nov 2, 2024
Oct 29, 2024
Oct 29, 2024
Feb 9, 2022
Feb 6, 2022
Feb 6, 2022
Feb 6, 2022
Nov 2, 2024
Feb 8, 2022
Feb 6, 2022
Sep 12, 2023
Oct 31, 2024
Oct 29, 2024

Repository files navigation

pybpf_asm

PyPI Build & Test Docs

Python BPF Assembler.

Based on the BPF assembler in Linux sources.

Installations

Wheels are available.

To build from source you need a relatively recent Flex & Bison:

  • On Windows, you can use winflexbison.
  • On macOS (and sometimes on Linux, on older distributions), you can install them from Homebrew. Note that you might have to add Homebrew's version to the front of the PATH, e.g. PATH="$(brew --prefix)/opt/flex/bin:$(brew --prefix)/opt/bison/bin:$PATH".

Usage

import bpf_asm


ASM = """\
    ldh [12]
    jeq #0x800, accept, drop
accept:
    ret #65536
drop:
    ret #0
"""

print(bpf_asm.assemble(ASM))

Or use the pybpf_asm script. See pybpf_asm --help for usage.

License

GPL-2.0-only.