History

bpf: Introduce bpf_sysctl_get_name helper

Add bpf_sysctl_get_name() helper to copy sysctl name (/proc/sys/ entry) into provided by BPF_PROG_TYPE_CGROUP_SYSCTL program buffer. By default full name (w/o /proc/sys/) is copied, e.g. "net/ipv4/tcp_mem". If BPF_F_SYSCTL_BASE_NAME flag is set, only base name will be copied, e.g. "tcp_mem". Documentation for the new helper is provided in bpf.h UAPI.

Andrey Ignatov committed 7 years ago

Commit 808649f1 parent 7b146ce2 files · +90 −2Browse files

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

Unified · Split

include/uapi/linux/bpf.h+21−1
@@ -2506,6 +2506,22 @@ union bpf_attr { · 2505 unmodified lines
2506 * Return2506 * Return
2507 * 0 if iph and th are a valid SYN cookie ACK, or a negative error2507 * 0 if iph and th are a valid SYN cookie ACK, or a negative error
2508 * otherwise.2508 * otherwise.
2509 *
2510 * int bpf_sysctl_get_name(struct bpf_sysctl *ctx, char *buf, size_t buf_len, u64 flags)
2511 * Description
2512 * Get name of sysctl in /proc/sys/ and copy it into provided by
2513 * program buffer *buf* of size *buf_len*.
2514 *
2515 * The buffer is always NUL terminated, unless it's zero-sized.
2516 *
2517 * If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is
2518 * copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name
2519 * only (e.g. "tcp_mem").
2520 * Return
2521 * Number of character copied (not including the trailing NUL).
2522 *
2523 * **-E2BIG** if the buffer wasn't big enough (*buf* will contain
2524 * truncated name in this case).
2509 */2525 */
2510#define __BPF_FUNC_MAPPER(FN) \2526#define __BPF_FUNC_MAPPER(FN) \
2511 FN(unspec), \2527 FN(unspec), \
@@ -2608,7 +2624,8 @@ union bpf_attr { · 96 unmodified lines
2608 FN(skb_ecn_set_ce), \2624 FN(skb_ecn_set_ce), \
2609 FN(get_listener_sock), \2625 FN(get_listener_sock), \
2610 FN(skc_lookup_tcp), \2626 FN(skc_lookup_tcp), \
2611 FN(tcp_check_syncookie),2627 FN(tcp_check_syncookie), \
2628 FN(sysctl_get_name),
2612 2629
2613/* integer value in 'imm' field of BPF_CALL instruction selects which helper2630/* integer value in 'imm' field of BPF_CALL instruction selects which helper
2614 * function eBPF program intends to call2631 * function eBPF program intends to call
@@ -2681,6 +2698,9 @@ enum bpf_func_id { · 66 unmodified lines
2681 BPF_ADJ_ROOM_ENCAP_L2_MASK) \2698 BPF_ADJ_ROOM_ENCAP_L2_MASK) \
2682 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)2699 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
2683 2700
2701/* BPF_FUNC_sysctl_get_name flags. */
2702#define BPF_F_SYSCTL_BASE_NAME (1ULL << 0)
2703
2684/* Mode for BPF_FUNC_skb_adjust_room helper. */2704/* Mode for BPF_FUNC_skb_adjust_room helper. */
2685enum bpf_adj_room_mode {2705enum bpf_adj_room_mode {
2686 BPF_ADJ_ROOM_NET,2706 BPF_ADJ_ROOM_NET,