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
25062506 * Return
25072507 * 0 if iph and th are a valid SYN cookie ACK, or a negative error
25082508 * 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).
25092525 */
25102526 #define __BPF_FUNC_MAPPER(FN) \
25112527 FN(unspec), \
@@ -2608,7 +2624,8 @@ union bpf_attr { · 96 unmodified lines
26082624 FN(skb_ecn_set_ce), \
26092625 FN(get_listener_sock), \
26102626 FN(skc_lookup_tcp), \
2611− FN(tcp_check_syncookie),
2627+ FN(tcp_check_syncookie), \
2628+ FN(sysctl_get_name),
26122629
26132630 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
26142631 * function eBPF program intends to call
@@ -2681,6 +2698,9 @@ enum bpf_func_id { · 66 unmodified lines
26812698 BPF_ADJ_ROOM_ENCAP_L2_MASK) \
26822699 << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
26832700
2701+/* BPF_FUNC_sysctl_get_name flags. */
2702+#define BPF_F_SYSCTL_BASE_NAME (1ULL << 0)
2703+
26842704 /* Mode for BPF_FUNC_skb_adjust_room helper. */
26852705 enum bpf_adj_room_mode {
26862706 BPF_ADJ_ROOM_NET,