mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2026-12-06 01:48:35 +00:00
Docs: Document the GPL default for programs without a LICENSE
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@ -96,9 +96,10 @@ def LICENSE() -> str:
|
||||
return "GPL"
|
||||
```
|
||||
|
||||
* The Linux kernel requires BPF programs to declare a license
|
||||
* The Linux kernel reads a license from every BPF program
|
||||
* Most kernel features require GPL-compatible licenses
|
||||
* This is defined as a BPF global variable
|
||||
* If you leave it out, PythonBPF uses `"GPL"` and logs a warning saying so
|
||||
|
||||
### Compilation and Execution
|
||||
|
||||
@ -197,7 +198,7 @@ def xdp_pass(ctx: c_void_p) -> c_int64:
|
||||
|
||||
## Best Practices
|
||||
|
||||
1. **Always include a LICENSE** - Required by the kernel
|
||||
1. **Declare a LICENSE** - Without one, PythonBPF defaults to `"GPL"` and warns
|
||||
2. **Use type hints** - Required by PythonBPF to generate correct code
|
||||
3. **Return the correct type** - Match the expected return type for your program type
|
||||
4. **Test incrementally** - Start simple and add complexity gradually
|
||||
|
||||
@ -281,9 +281,10 @@ BPF global variables are values that:
|
||||
|
||||
### Common Global Variables
|
||||
|
||||
#### LICENSE (Required)
|
||||
#### LICENSE
|
||||
|
||||
Every BPF program must declare a license:
|
||||
Every BPF program carries a license, which the kernel reads when the program is
|
||||
loaded. Declare it as a string global:
|
||||
|
||||
```python
|
||||
@bpf
|
||||
@ -292,14 +293,24 @@ def LICENSE() -> str:
|
||||
return "GPL"
|
||||
```
|
||||
|
||||
Valid licenses include:
|
||||
If a program defines no `LICENSE`, PythonBPF uses `"GPL"`, the kernel's own
|
||||
license, and logs a warning:
|
||||
|
||||
```text
|
||||
No LICENSE defined; defaulting to "GPL". Define @bpf @bpfglobal def LICENSE() -> str to choose another license.
|
||||
```
|
||||
|
||||
Define `LICENSE` yourself to choose a different license or to silence the
|
||||
warning. The kernel treats these as GPL-compatible:
|
||||
* `"GPL"` - GNU General Public License
|
||||
* `"GPL v2"` - GPL version 2
|
||||
* `"GPL and additional rights"`
|
||||
* `"Dual BSD/GPL"` - Dual licensed
|
||||
* `"Dual MIT/GPL"` - Dual licensed
|
||||
* `"Dual MPL/GPL"` - Dual licensed
|
||||
|
||||
```{warning}
|
||||
Many BPF features require a GPL-compatible license. Using a non-GPL license may prevent your program from loading or accessing certain kernel features.
|
||||
Many BPF features require a GPL-compatible license. A program with any other license may not call GPL-only helpers, including `bpf_trace_printk`, which `print()` uses; the verifier rejects it with "cannot call GPL-restricted function from non-GPL compatible program".
|
||||
```
|
||||
|
||||
#### Custom Global Variables
|
||||
|
||||
Reference in New Issue
Block a user