-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add Program Types/XDP documentation #155
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for aya-rs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this 🙏 Left some comments, but I will review again later today.
docs/book/programs/xdp.md
Outdated
|
||
## What is XBP in eBPF? | ||
|
||
XBP (eXpress Data Path) is a type of eBPF program that attaches to the network interface. It allows for the processing of network packets as soon as they are received from the network driver, even before they enter the networking stack. XDP enables efficient packet filtering, manipulation and redirection at the earliest possible stage, resulting in low-latency and high-throughput. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we stick to 80-100 character limit per line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we stick to 80-100 character limit per line?
Not sure what you mean per line, you want to break to a newline after max 100 chars?
On my side I don't see the lines go further than > 100 chars, it's always around 90 chars max per line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I want to break to a new line after max 100 characters.
This exact sentence which I commented exceeds this limit and it's quite hard to read in some editors. The whole line 10 has 317 characters:
~> python3 04/30/24 13:30:49 PM
Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> len("XDP (eXpress Data Path) is a type of eBPF program that attaches to the network interface. It enables filtering, manipulation and refirection of network packets as soon as they are received from the network driver, even before they enter the Linux kernel networking stack, resulting in low latency and high throughput.")
317
We should probably introduce some markdown linter to catch stuff like that, but for now can we just split the obviously too large lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I want to break to a new line after max 100 characters.
This exact sentence which I commented exceeds this limit and it's quite hard to read in some editors. The whole line 10 has 317 characters:
~> python3 04/30/24 13:30:49 PM Python 3.11.5 (main, Aug 24 2023, 15:09:45) [Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> len("XDP (eXpress Data Path) is a type of eBPF program that attaches to the network interface. It enables filtering, manipulation and refirection of network packets as soon as they are received from the network driver, even before they enter the Linux kernel networking stack, resulting in low latency and high throughput.") 317
We should probably introduce some markdown linter to catch stuff like that, but for now can we just split the obviously too large lines?
Sure, makes sense, the only thing I'm worried about is that it may be less nice to read on bigger screens or on the site directly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, on a bigger screen/on the site, it would look like:
Maybe it's just me but I find it harder to read with all the line breaks here
@vadorovsky Any news? I don't mind adding the line breaks, just thought it would make sense to reconsider it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I had no idea that breaking the lines even with a single \n
makes it being rendered on the website. Let me test myself. If that's really the case, let's leave the long lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I had no idea that breaking the lines even with a single
\n
makes it being rendered on the website. Let me test myself. If that's really the case, let's leave the long lines.
my bad, I tried with <br>
for line breaks (for some reason I thought you'd also like to render those on the website), going to try with single \n
, it shouldn't render on the website.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vadorovsky indeed it doesn't change anything on the website when adding single \n
, I have added some line breaks for bigger sentences, let me know if I should change anything else 👍
Co-authored-by: Michal Rostecki <vadorovsky@protonmail.com>
Co-authored-by: Michal Rostecki <vadorovsky@protonmail.com>
Applied your reviews, also corrected some typos |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for very late review!
Unfortunately I'm still nitpicking few things. After addressing them it should be good to go.
!!! example "Source Code" | ||
|
||
Full code for the example in this chapter is available [here](https://github.com/aya-rs/book/tree/main/examples/xdp-drop) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we stick to having one empty line, not multiple?
Full code for the example in this chapter is available [here](https://github.com/aya-rs/book/tree/main/examples/xdp-drop) | ||
|
||
|
||
## What is XDP in eBPF? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let's add empty lines after headers.
## What is XDP in eBPF? | |
## What is XDP in eBPF? | |
* `XDP_REDIRECT`: redirect the packet to another NIC or user space socket via the | ||
[`AF_XDP`](https://www.kernel.org/doc/html/latest/networking/af_xdp.html) address family | ||
|
||
## AF_XDP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
## AF_XDP | |
## AF_XDP | |
If you want a more extensive explanation about `AF_XDP`, | ||
you can find it in the [kernel documentation](https://www.kernel.org/doc/html/latest/networking/af_xdp.html). | ||
|
||
## XDP Operation Modes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally not a big fan of using the title case (capitalizing all nouns, regardless of whether they're proper nouns or common nouns). As far as I remember, @alessandrod doesn't like it either.
The reasons being:
- I Find it Quite Difficult to Read. 😛
- In all seriousness, I like the opposite style - sentence case capitalization - because it highlights the important words. When reading technical documentation, I prefer the names of specific technologies or projects (XDP, Linux etc.) to stand out from the rest of the title.
- Title case is not really standardized, there are multiple styles and rules. I find sentence case capitalization much more obvious, since everyone is using it on daily basis.
- In Aya book, even though there are some places using title case, it's not being used consistently. It's also not being used consistently here. 😅 It would be easier to convert all existing title cases to sentence cases - I would be happy to see an another PR doing that.
Therefore,
## XDP Operation Modes | |
## XDP operation modes | |
## XDP Operation Modes | ||
You can connect an XDP program to an interface using the following modes: | ||
|
||
### Generic XDP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Generic XDP | |
### Generic XDP | |
Logging is initialized using [`env_logger::init()`](https://docs.rs/env_logger/latest/env_logger/fn.init.html), | ||
we will make use of the environment logger later in our code. | ||
|
||
##### Loading the eBPF program |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
##### Loading the eBPF program | |
##### Loading the eBPF program | |
The eBPF program is loaded using `Bpf::load()`, choosing the debug or | ||
release version based on the build configuration (`debug_assertions`). | ||
|
||
##### Loading and attaching our XDP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
##### Loading and attaching our XDP | |
##### Loading and attaching our XDP | |
we defined earlier using `bpf.program_mut()`. | ||
The XDP program is then loaded and attached to our network interface. | ||
|
||
##### Setting up the ip blocklist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"IP" should be all upper-case:
##### Setting up the ip blocklist | |
##### Setting up the IP blocklist | |
The IP blocklist (`BLOCKLIST` map) is loaded from the eBPF program and converted to a `HashMap`. | ||
The IP `1.1.1.1` is added to the blocklist. | ||
|
||
##### Waiting for the exit signal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
##### Waiting for the exit signal | |
##### Waiting for the exit signal | |
} | ||
``` | ||
|
||
### Running our program! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Running our program! | |
### Running our program! | |
Added documentation for https://aya-rs.dev/book/programs/xdp/
Feel free to make reviews and suggest improvements.