Skip to content
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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

shard77
Copy link

@shard77 shard77 commented Apr 24, 2024

Added documentation for https://aya-rs.dev/book/programs/xdp/
Feel free to make reviews and suggest improvements.

Copy link

netlify bot commented Apr 24, 2024

Deploy Preview for aya-rs ready!

Name Link
🔨 Latest commit 471d5b4
🔍 Latest deploy log https://app.netlify.com/sites/aya-rs/deploys/6658c95d68cf450008d7e950
😎 Deploy Preview https://deploy-preview-155--aya-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@vadorovsky vadorovsky left a 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.


## 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.
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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?

Copy link
Author

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

Copy link
Author

@shard77 shard77 Apr 30, 2024

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:

image

Maybe it's just me but I find it harder to read with all the line breaks here

Copy link
Author

@shard77 shard77 May 7, 2024

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:

image

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.

Copy link
Member

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.

Copy link
Author

@shard77 shard77 May 30, 2024

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.

Copy link
Author

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 👍

docs/book/programs/xdp.md Outdated Show resolved Hide resolved
docs/book/programs/xdp.md Outdated Show resolved Hide resolved
docs/book/programs/xdp.md Outdated Show resolved Hide resolved
shard77 and others added 5 commits April 30, 2024 09:32
Co-authored-by: Michal Rostecki <vadorovsky@protonmail.com>
Co-authored-by: Michal Rostecki <vadorovsky@protonmail.com>
@shard77
Copy link
Author

shard77 commented Apr 30, 2024

Applied your reviews, also corrected some typos

Copy link
Member

@vadorovsky vadorovsky left a 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)

Copy link
Member

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?

Suggested change

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?
Copy link
Member

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.

Suggested change
## 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## 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
Copy link
Member

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,

Suggested change
## XDP Operation Modes
## XDP operation modes

## XDP Operation Modes
You can connect an XDP program to an interface using the following modes:

### Generic XDP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### 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
Copy link
Member

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:

Suggested change
##### 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
##### Waiting for the exit signal
##### Waiting for the exit signal

}
```

### Running our program!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
### Running our program!
### Running our program!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants