History

Add a helper function to get socket cookie in eBPF

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.

Chenbo Feng committed 9 years ago

Commit 91b82701 parent 16ae1f25 files · +29 −3Browse files

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

Unified · Split

include/uapi/linux/bpf.h+8−1
@@ -459,6 +459,12 @@ union bpf_attr { · 458 unmodified lines
459459 * Return:
460460 * > 0 length of the string including the trailing NUL on success
461461 * < 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
462468 */
463469 #define __BPF_FUNC_MAPPER(FN) \
464470 FN(unspec), \
@@ -506,7 +512,8 @@ union bpf_attr { · 41 unmodified lines
506512 FN(get_numa_node_id), \
507513 FN(skb_change_head), \
508514 FN(xdp_adjust_head), \
509− FN(probe_read_str),
515+ FN(probe_read_str), \
516+ FN(get_socket_cookie),
510517
511518 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
512519 * function eBPF program intends to call