mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-02-07 21:50:55 +00:00
Fix documentation: correct comm() usage, XDP types, copyright year, and add uv support
Co-authored-by: r41k0u <76248539+r41k0u@users.noreply.github.com>
This commit is contained in:
@ -43,8 +43,14 @@ The `llvm` package provides `llc`, the LLVM compiler that is used to compile LLV
|
||||
|
||||
### From PyPI (Recommended)
|
||||
|
||||
The easiest way to install PythonBPF is using pip:
|
||||
The easiest way to install PythonBPF is using uv or pip:
|
||||
|
||||
**Using uv (recommended):**
|
||||
```bash
|
||||
uv pip install pythonbpf pylibbpf
|
||||
```
|
||||
|
||||
**Using pip:**
|
||||
```bash
|
||||
pip install pythonbpf pylibbpf
|
||||
```
|
||||
@ -73,6 +79,13 @@ source .venv/bin/activate # On Windows: .venv\Scripts\activate
|
||||
|
||||
3. Install in development mode:
|
||||
|
||||
**Using uv (recommended):**
|
||||
```bash
|
||||
uv pip install -e .
|
||||
uv pip install pylibbpf
|
||||
```
|
||||
|
||||
**Using pip:**
|
||||
```bash
|
||||
pip install -e .
|
||||
pip install pylibbpf
|
||||
@ -88,6 +101,14 @@ make install
|
||||
|
||||
If you want to build the documentation locally:
|
||||
|
||||
**Using uv (recommended):**
|
||||
```bash
|
||||
uv pip install pythonbpf[docs]
|
||||
# Or from the repository root:
|
||||
uv pip install -e .[docs]
|
||||
```
|
||||
|
||||
**Using pip:**
|
||||
```bash
|
||||
pip install pythonbpf[docs]
|
||||
# Or from the repository root:
|
||||
@ -100,6 +121,12 @@ Some examples require access to kernel data structures. To use these features, y
|
||||
|
||||
1. Install additional dependencies:
|
||||
|
||||
**Using uv (recommended):**
|
||||
```bash
|
||||
uv pip install ctypeslib2
|
||||
```
|
||||
|
||||
**Using pip:**
|
||||
```bash
|
||||
pip install ctypeslib2
|
||||
```
|
||||
@ -151,8 +178,8 @@ If you get errors about `llc` or `clang` not being found:
|
||||
If Python can't find the `pythonbpf` module:
|
||||
|
||||
* Make sure you've activated your virtual environment
|
||||
* Verify installation with `pip list | grep pythonbpf`
|
||||
* Try reinstalling: `pip install --force-reinstall pythonbpf`
|
||||
* Verify installation with `uv pip list | grep pythonbpf` or `pip list | grep pythonbpf`
|
||||
* Try reinstalling: `uv pip install --force-reinstall pythonbpf` or `pip install --force-reinstall pythonbpf`
|
||||
|
||||
## Next Steps
|
||||
|
||||
|
||||
@ -120,15 +120,14 @@ Let's make a more interesting program that tracks which processes are being crea
|
||||
|
||||
```python
|
||||
from pythonbpf import bpf, section, bpfglobal, BPF, trace_pipe
|
||||
from pythonbpf.helper import pid, comm
|
||||
from pythonbpf.helper import pid
|
||||
from ctypes import c_void_p, c_int64
|
||||
|
||||
@bpf
|
||||
@section("tracepoint/syscalls/sys_enter_execve")
|
||||
def track_exec(ctx: c_void_p) -> c_int64:
|
||||
process_id = pid()
|
||||
process_name = comm()
|
||||
print(f"Process {process_name} (PID: {process_id}) is starting")
|
||||
print(f"Process with PID: {process_id} is starting")
|
||||
return c_int64(0)
|
||||
|
||||
@bpf
|
||||
@ -145,7 +144,6 @@ trace_pipe()
|
||||
This program uses BPF helper functions:
|
||||
|
||||
* `pid()` - Gets the current process ID
|
||||
* `comm()` - Gets the current process command name
|
||||
|
||||
Run it with `sudo python3 track_exec.py` and watch processes being created!
|
||||
|
||||
@ -182,12 +180,11 @@ def trace_open(ctx: c_void_p) -> c_int64:
|
||||
For network packet processing:
|
||||
|
||||
```python
|
||||
from ctypes import c_uint32
|
||||
from pythonbpf.helper import XDP_PASS
|
||||
|
||||
@section("xdp")
|
||||
def xdp_pass(ctx: c_void_p) -> c_uint32:
|
||||
# XDP_PASS = 2
|
||||
return c_uint32(2)
|
||||
def xdp_pass(ctx: c_void_p) -> c_int64:
|
||||
return XDP_PASS
|
||||
```
|
||||
|
||||
## Best Practices
|
||||
|
||||
Reference in New Issue
Block a user