Retrieve the socket cookie generated by sock_gen_cookie() from a sk_buff with a known socket. Generates a new cookie if one was not yet set.If the socket pointer inside sk_buff is NULL, 0 is returned. The helper function coud be useful in monitoring per socket networking traffic statistics and provide a unique socket identifier per namespace.
Showing the changes to include/uapi/linux (1 of 5 files). Show all
Unified · Split
| @@ -459,6 +459,12 @@ union bpf_attr { · 458 unmodified lines | ||
| 459 | 459 | * Return: |
| 460 | 460 | * > 0 length of the string including the trailing NUL on success |
| 461 | 461 | * < 0 error |
| 462 | + * | |
| 463 | + * u64 bpf_bpf_get_socket_cookie(skb) | |
| 464 | + * Get the cookie for the socket stored inside sk_buff. | |
| 465 | + * @skb: pointer to skb | |
| 466 | + * Return: 8 Bytes non-decreasing number on success or 0 if the socket | |
| 467 | + * field is missing inside sk_buff | |
| 462 | 468 | */ |
| 463 | 469 | #define __BPF_FUNC_MAPPER(FN) \ |
| 464 | 470 | FN(unspec), \ |
| @@ -506,7 +512,8 @@ union bpf_attr { · 41 unmodified lines | ||
| 506 | 512 | FN(get_numa_node_id), \ |
| 507 | 513 | FN(skb_change_head), \ |
| 508 | 514 | FN(xdp_adjust_head), \ |
| 509 | − FN(probe_read_str), | |
| 515 | + FN(probe_read_str), \ | |
| 516 | + FN(get_socket_cookie), | |
| 510 | 517 | |
| 511 | 518 | /* integer value in 'imm' field of BPF_CALL instruction selects which helper |
| 512 | 519 | * function eBPF program intends to call |