mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 07:12:09 +00:00
bpf: Introduce bpf_sysctl_get_current_value helper
Add bpf_sysctl_get_current_value() helper to copy current sysctl value into provided by BPF_PROG_TYPE_CGROUP_SYSCTL program buffer. It provides same string as user space can see by reading corresponding file in /proc/sys/, including new line, etc. Documentation for the new helper is provided in bpf.h UAPI. Since current value is kept in ctl_table->data in a parsed form, ctl_table->proc_handler() with write=0 is called to read that data and convert it to a string. Such a string can later be parsed by a program using helpers that will be introduced separately. Unfortunately it's not trivial to provide API to access parsed data due to variety of data representations (string, intvec, uintvec, ulongvec, custom structures, even NULL, etc). Instead it's assumed that user know how to handle specific sysctl they're interested in and appropriate helpers can be used. Since ctl_table->proc_handler() expects __user buffer, conversion to __user happens for kernel allocated one where the value is stored. Signed-off-by: Andrey Ignatov <rdna@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:
parent
808649fb78
commit
1d11b3016c
3 changed files with 88 additions and 1 deletions
|
@ -2522,6 +2522,25 @@ union bpf_attr {
|
|||
*
|
||||
* **-E2BIG** if the buffer wasn't big enough (*buf* will contain
|
||||
* truncated name in this case).
|
||||
*
|
||||
* int bpf_sysctl_get_current_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
|
||||
* Description
|
||||
* Get current value of sysctl as it is presented in /proc/sys
|
||||
* (incl. newline, etc), and copy it as a string into provided
|
||||
* by program buffer *buf* of size *buf_len*.
|
||||
*
|
||||
* The whole value is copied, no matter what file position user
|
||||
* space issued e.g. sys_read at.
|
||||
*
|
||||
* The buffer is always NUL terminated, unless it's zero-sized.
|
||||
* Return
|
||||
* Number of character copied (not including the trailing NUL).
|
||||
*
|
||||
* **-E2BIG** if the buffer wasn't big enough (*buf* will contain
|
||||
* truncated name in this case).
|
||||
*
|
||||
* **-EINVAL** if current value was unavailable, e.g. because
|
||||
* sysctl is uninitialized and read returns -EIO for it.
|
||||
*/
|
||||
#define __BPF_FUNC_MAPPER(FN) \
|
||||
FN(unspec), \
|
||||
|
@ -2625,7 +2644,8 @@ union bpf_attr {
|
|||
FN(get_listener_sock), \
|
||||
FN(skc_lookup_tcp), \
|
||||
FN(tcp_check_syncookie), \
|
||||
FN(sysctl_get_name),
|
||||
FN(sysctl_get_name), \
|
||||
FN(sysctl_get_current_value),
|
||||
|
||||
/* integer value in 'imm' field of BPF_CALL instruction selects which helper
|
||||
* function eBPF program intends to call
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue