aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/bpf.h
diff options
context:
space:
mode:
authorAndrey Ignatov <rdna@fb.com>2019-03-18 20:55:26 -0400
committerAlexei Starovoitov <ast@kernel.org>2019-04-12 16:54:59 -0400
commitd7a4cb9b6705a89937d12c8158a35a3145dc967a (patch)
tree1a412b1d491dcc6aca5032dc2792a2a530e26af3 /include/linux/bpf.h
parent57c3bb725a3dd97d960d7e1cd0845d88de53217f (diff)
bpf: Introduce bpf_strtol and bpf_strtoul helpers
Add bpf_strtol and bpf_strtoul to convert a string to long and unsigned long correspondingly. It's similar to user space strtol(3) and strtoul(3) with a few changes to the API: * instead of NUL-terminated C string the helpers expect buffer and buffer length; * resulting long or unsigned long is returned in a separate result-argument; * return value is used to indicate success or failure, on success number of consumed bytes is returned that can be used to identify position to read next if the buffer is expected to contain multiple integers; * instead of *base* argument, *flags* is used that provides base in 5 LSB, other bits are reserved for future use; * number of supported bases is limited. Documentation for the new helpers is provided in bpf.h UAPI. The helpers are made available to BPF_PROG_TYPE_CGROUP_SYSCTL programs to be able to convert string input to e.g. "ulongvec" output. E.g. "net/ipv4/tcp_mem" consists of three ulong integers. They can be parsed by calling to bpf_strtoul three times. Implementation notes: Implementation includes "../../lib/kstrtox.h" to reuse integer parsing functions. It's done exactly same way as fs/proc/base.c already does. Unfortunately existing kstrtoX function can't be used directly since they fail if any invalid character is present right after integer in the string. Existing simple_strtoX functions can't be used either since they're obsolete and don't handle overflow properly. Signed-off-by: Andrey Ignatov <rdna@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'include/linux/bpf.h')
-rw-r--r--include/linux/bpf.h2
1 files changed, 2 insertions, 0 deletions
diff --git a/include/linux/bpf.h b/include/linux/bpf.h
index fd06ada941ad..f15432d90728 100644
--- a/include/linux/bpf.h
+++ b/include/linux/bpf.h
@@ -989,6 +989,8 @@ extern const struct bpf_func_proto bpf_sk_redirect_map_proto;
989extern const struct bpf_func_proto bpf_spin_lock_proto; 989extern const struct bpf_func_proto bpf_spin_lock_proto;
990extern const struct bpf_func_proto bpf_spin_unlock_proto; 990extern const struct bpf_func_proto bpf_spin_unlock_proto;
991extern const struct bpf_func_proto bpf_get_local_storage_proto; 991extern const struct bpf_func_proto bpf_get_local_storage_proto;
992extern const struct bpf_func_proto bpf_strtol_proto;
993extern const struct bpf_func_proto bpf_strtoul_proto;
992 994
993/* Shared helpers among cBPF and eBPF. */ 995/* Shared helpers among cBPF and eBPF. */
994void bpf_user_rnd_init_once(void); 996void bpf_user_rnd_init_once(void);