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.
Showing the changes to include/uapi (1 of 8 files). Show all
Unified · Split
| @@ -5325,11 +5325,17 @@ union bpf_attr { · 5324 unmodified lines | |||
| 5325 | * Description | 5325 | * Description |
| 5326 | * Write *len* bytes from *src* into *dst*, starting from *offset* | 5326 | * Write *len* bytes from *src* into *dst*, starting from *offset* |
| 5327 | * into *dst*. | 5327 | * 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**\ (). | ||
| 5329 | * Return | 5334 | * Return |
| 5330 | * 0 on success, -E2BIG if *offset* + *len* exceeds the length | 5335 | * 0 on success, -E2BIG if *offset* + *len* exceeds the length |
| 5331 | * of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst* | 5336 | * 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**\ (). | ||
| 5333 | * | 5339 | * |
| 5334 | * void *bpf_dynptr_data(const struct bpf_dynptr *ptr, u32 offset, u32 len) | 5340 | * void *bpf_dynptr_data(const struct bpf_dynptr *ptr, u32 offset, u32 len) |
| 5335 | * Description | 5341 | * Description |
| @@ -5337,6 +5343,9 @@ union bpf_attr { · 1 unmodified line | |||
| 5337 | * | 5343 | * |
| 5338 | * *len* must be a statically known value. The returned data slice | 5344 | * *len* must be a statically known value. The returned data slice |
| 5339 | * is invalidated whenever the dynptr is invalidated. | 5345 | * 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. | ||
| 5340 | * Return | 5349 | * Return |
| 5341 | * Pointer to the underlying dynptr data, NULL if the dynptr is | 5350 | * Pointer to the underlying dynptr data, NULL if the dynptr is |
| 5342 | * read-only, if the dynptr is invalid, or if the offset and length | 5351 | * read-only, if the dynptr is invalid, or if the offset and length |