History

bpf: Add skb dynptrs

Add skb dynptrs, which are dynptrs whose underlying pointer points to a skb. The dynptr acts on skb data. skb dynptrs have two main benefits. One is that they allow operations on sizes that are not statically known at compile-time (eg variable-sized accesses). Another is that parsing the packet data through dynptrs (instead of through direct access of skb->data and skb->data_end) can be more ergonomic and less brittle (eg does not need manual if checking for being within bounds of data_end). For bpf prog types that don't support writes on skb data, the dynptr is read-only (bpf_dynptr_write() will return an error) For reads and writes through the bpf_dynptr_read() and bpf_dynptr_write() interfaces, reading and writing from/to data in the head as well as from/to non-linear paged buffers is supported. Data slices through the bpf_dynptr_data API are not supported; instead bpf_dynptr_slice() and bpf_dynptr_slice_rdwr() (added in subsequent commit) should be used. For examples of how skb dynptrs can be used, please see the attached selftests.

Joanne Koong committed 3 years ago

Commit b5964b91 parent d96d9378 files · +261 −19Browse files

Showing the changes to include/uapi (1 of 8 files). Show all

Unified · Split

include/uapi/linux/bpf.h+11−2
@@ -5325,11 +5325,17 @@ union bpf_attr { · 5324 unmodified lines
53255325 * Description
53265326 * Write *len* bytes from *src* into *dst*, starting from *offset*
53275327 * into *dst*.
5328− * *flags* is currently unused.
5328+ *
5329+ * *flags* must be 0 except for skb-type dynptrs.
5330+ *
5331+ * For skb-type dynptrs:
5332+ * * For *flags*, please see the flags accepted by
5333+ * **bpf_skb_store_bytes**\ ().
53295334 * Return
53305335 * 0 on success, -E2BIG if *offset* + *len* exceeds the length
53315336 * of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
5332− * is a read-only dynptr or if *flags* is not 0.
5337+ * is a read-only dynptr or if *flags* is not correct. For skb-type dynptrs,
5338+ * other errors correspond to errors returned by **bpf_skb_store_bytes**\ ().
53335339 *
53345340 * void *bpf_dynptr_data(const struct bpf_dynptr *ptr, u32 offset, u32 len)
53355341 * Description
@@ -5337,6 +5343,9 @@ union bpf_attr { · 1 unmodified line
53375343 *
53385344 * *len* must be a statically known value. The returned data slice
53395345 * is invalidated whenever the dynptr is invalidated.
5346+ *
5347+ * skb type dynptrs may not use bpf_dynptr_data. They should
5348+ * instead use bpf_dynptr_slice and bpf_dynptr_slice_rdwr.
53405349 * Return
53415350 * Pointer to the underlying dynptr data, NULL if the dynptr is
53425351 * read-only, if the dynptr is invalid, or if the offset and length

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t