Skip to content

Commit 1966153

Browse files
committed
Migrate to mkdocs
Signed-off-by: Dave Tucker <[email protected]>
1 parent 8f6a7c3 commit 1966153

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+11209
-4686
lines changed

.github/workflows/ci.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,23 @@ jobs:
3535

3636
- uses: Swatinem/rust-cache@v1
3737

38-
- name: Install Dependencies
39-
run: cargo install mdbook
38+
- name: Set up Python
39+
uses: actions/setup-python@v3
4040

41-
- name: Run tests
42-
run: mdbook build && mdbook test
41+
- name: Install python dependencies
42+
run: |
43+
python -m pip install --upgrade pip
44+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
45+
46+
- name: Build docs
47+
run: mkdocs build
4348

4449
- name: Check Examples
4550
run: |
46-
for example in "aya-gen" "myapp-01" "myapp-02" "myapp-03"; do
51+
for example in "aya-gen" "myapp-01" "myapp-02" "myapp-03" "lsm-nice"; do
4752
pushd "examples/${example}"
4853
echo "Example: ${example}."
4954
cargo xtask build-ebpf
5055
cargo build
5156
popd
5257
done
53-
54-
- name: Deploy 🚀
55-
uses: JamesIves/[email protected]
56-
if: github.ref == 'refs/heads/main'
57-
with:
58-
branch: gh-pages
59-
folder: book

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
book
1+
.venv
2+
site

.vscode/settings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"yaml.schemas": {
3+
"https://squidfunk.github.io/mkdocs-material/schema.json": "mkdocs.yml"
4+
}
5+
}

book.toml

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Using aya-gen
22

3+
!!! example "Source Code"
4+
5+
Full code for the example in this chapter is availble [here](https://github.com/aya-rs/book/tree/main/examples/aya-gen)
6+
37
Very often you will need to use type definitions that your running Linux kernel
48
uses in its source code. For example, you might need a definition of
59
[task_struct](https://elixir.bootlin.com/linux/v5.15.3/source/include/linux/sched.h#L723),
@@ -13,16 +17,16 @@ bindings for specific kernel structures.
1317

1418
It can be installed with the following command:
1519

16-
```bash
17-
cargo install --git https://github.com/aya-rs/aya -- aya-gen
20+
```console
21+
$ cargo install --git https://github.com/aya-rs/aya -- aya-gen
1822
```
1923

2024
Ensure that you have `bpftool` installed in your system, `aya-gen` is not going
2125
to work without it.
2226

2327
The syntax of the command is:
2428

25-
```bash
29+
```console
2630
$ aya-gen
2731
aya-gen 0.1.0
2832

@@ -44,28 +48,26 @@ Let's also assume that your project is called `myapp`. Your userspace part is
4448
in `myapp` subdirectory, your eBPF part is in `myapp-ebpf`. We need to generate
4549
the bindings for the eBPF part, which can be done with:
4650

47-
```bash
48-
aya-gen generate task_struct > myapp-ebpf/src/vmlinux.rs
51+
```console
52+
$ aya-gen generate task_struct > myapp-ebpf/src/vmlinux.rs
4953
```
5054

51-
> 💡 **HINT: Generating for multiple types**
52-
>
53-
> You can also specify multiple types to generate, for example:
54-
>
55-
> ```bash
56-
> aya-gen generate task_struct dentry > vmlinux.rs
57-
> ```
58-
>
59-
> But in the following example, we will focus only on `task_struct`.
55+
!!! tip "Generating for multiple types"
56+
57+
You can also specify multiple types to generate, for example:
58+
```console
59+
$ aya-gen generate task_struct dentry > vmlinux.rs
60+
```
61+
But in the following example, we will focus only on `task_struct`.
6062

6163
Then we can use `vmlinux` as a module with `mod vmlinux` in our eBPF program,
6264
like here:
6365

64-
```rust,ignore
65-
{{#rustdoc_include ../../examples/aya-gen/myapp-ebpf/src/main.rs }}
66+
```rust linenums="1" title="myapp-ebpf/src/main.rs"
67+
--8<-- "examples/aya-gen/myapp-ebpf/src/main.rs"
6668
```
6769

68-
## Potability and different kernel versions
70+
## Portability and different kernel versions
6971

7072
Structures generated by aya-gen are portable across different Linux kernel
7173
versions thanks to mechanism called
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Using aya-log
22

3-
This page is a work in progress, please feel free to open a Pull Request!
3+
This page is a work in progress, please feel free to open a Pull Request!
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Reading Values From A Context
22

3-
This page is a work in progress, please feel free to open a Pull Request!
3+
This page is a work in progress, please feel free to open a Pull Request!
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Working With Aya
22

3-
This page is a work in progress, please feel free to open a Pull Request!
3+
This page is a work in progress, please feel free to open a Pull Request!
Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Introduction
1+
# Getting Started
22

3-
Welcome to Building eBPF Programs with Aya: An introductory book about using the Rust
3+
This getting started guide will help you use the Rust
44
Programming Language and Aya library to build extended Berkley Packet Filter (eBPF)
55
programs.
66

@@ -9,34 +9,34 @@ programs.
99
Rust is proving to be a popular systems programming language because of its
1010
safety features and excellent C interoperability. The safety features are less
1111
important in the context of eBPF as programs often need to read kernel memory, which
12-
is considered unsafe. However, what Rust combined with Aya does offer is a fast and
12+
is considered unsafe. However, what Rust combined with Aya does offer is a fast and
1313
efficient development experience:
1414

1515
- Cargo for project scaffolding, build, test and debugging
1616
- Generation of Rust bindings to Kernel Headers with Compile-Once, Run-Everywhere (CO-RE) support
1717
- Easy code sharing between user-space and eBPF programs
1818
- Fast compile times
19-
- No runtime dependency on LLVM or BCC
19+
- No runtime dependency on LLVM, BCC or libbpf
2020

2121
## Scope
2222

23-
The goals of this book are:
23+
The goals of this guide are:
2424

2525
* Get developers up to speed with eBPF Rust development. i.e. How to set
2626
up a development environment.
2727

2828
* Share *current* best practices about using Rust for eBPF
2929

3030

31-
## Who This Book is For
31+
## Who This Guide is For
3232

33-
This book caters towards people with either some eBPF or some Rust background. For those without any prior knowledge we suggest you read the "Assumptions and Prerequisites" section first. You can check out the "Other Resources" section to find resources on topics you might want to read up on.
33+
This guide caters towards people with either some eBPF or some Rust background. For those without any prior knowledge we suggest you read the "Assumptions and Prerequisites" section first. You can check out the "Other Resources" section to find resources on topics you might want to read up on.
3434

3535
### Assumptions and Prerequisites
3636

3737
* You are comfortable using the Rust Programming Language, and have written,
3838
run, and debugged Rust applications on a desktop environment. You should also
39-
be familiar with the idioms of the [2021 edition] as this book targets
39+
be familiar with the idioms of the [2021 edition] as this guide targets
4040
Rust 2021.
4141

4242
[2021 edition]: https://doc.rust-lang.org/edition-guide/
@@ -45,21 +45,33 @@ This book caters towards people with either some eBPF or some Rust background. F
4545

4646
### Other Resources
4747

48-
If you are unfamiliar with anything mentioned above or if you want more information about a specific topic mentioned in this book you might find some of these resources helpful.
48+
If you are unfamiliar with anything mentioned above or if you want more information about a specific topic mentioned in this guide you might find some of these resources helpful.
4949

5050
| Topic | Resource | Description |
5151
|--------------|----------|-------------|
5252
| Rust | [Rust Book](https://doc.rust-lang.org/book/) | If you are not yet comfortable with Rust, we highly suggest reading this book. |
5353
| eBPF | [Cilium BPF and XDP Reference Guide](https://docs.cilium.io/en/stable/bpf/) | If you are not yet comfortable with eBPF, this guide is excellent. |
5454

55-
## How to Use This Book
55+
## How to Use This Guide
5656

57-
This book generally assumes that you’re reading it front-to-back. Later
57+
This guide generally assumes that you’re reading it front-to-back. Later
5858
chapters build on concepts in earlier chapters, and earlier chapters may
5959
not dig into details on a topic, revisiting the topic in a later chapter.
6060

61-
## Source Code
61+
## eBPF Program Constraints
6262

63-
The source files from which this book is generated can be found on [GitHub][github].
63+
The eBPF Virtual Machine, where our eBPF programs will be run, is a constrained runtime environment:
6464

65-
[github]: https://github.com/aya-rs/book
65+
- There is only 512 bytes of stack (or 256 bytes if we are using tail calls).
66+
- There is no access to heap space and data must instead be written to maps.
67+
68+
Even applications written in C are restricted to a subset of language features, and we have similar
69+
constraints in Rust:
70+
71+
- We may not use the standard library. We use `core` instead.
72+
- `core::fmt` may not be used and neither can traits that rely on it, for example `Display` and `Debug`
73+
- As there is no heap, we cannot use `alloc` or `collections`.
74+
- We must not `panic` as the eBPF VM does not support stack unwinding, or the `abort` instruction.
75+
- There is no `main` function
76+
77+
Alongside this, a lot of the code that we write is `unsafe`, as we are reading directly from kernel memory.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Cgroups
22

3-
This page is a work in progress, please feel free to open a Pull Request!
3+
This page is a work in progress, please feel free to open a Pull Request!

0 commit comments

Comments
 (0)