aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/bpf/helpers.c
diff options
context:
space:
mode:
authorDaniel Borkmann <daniel@iogearbox.net>2015-05-29 17:23:06 -0400
committerDavid S. Miller <davem@davemloft.net>2015-06-01 00:44:44 -0400
commit17ca8cbf49be3aa94bb1c2b7ee6545fd70094eb4 (patch)
tree100f160426a26857a776c4b3fd3beb8848bda474 /kernel/bpf/helpers.c
parenta24c85abc0815c14d9e5266d06b9acd8a0a57b9a (diff)
ebpf: allow bpf_ktime_get_ns_proto also for networking
As this is already exported from tracing side via commit d9847d310ab4 ("tracing: Allow BPF programs to call bpf_ktime_get_ns()"), we might as well want to move it to the core, so also networking users can make use of it, e.g. to measure diffs for certain flows from ingress/egress. Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Cc: Alexei Starovoitov <ast@plumgrid.com> Cc: Ingo Molnar <mingo@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'kernel/bpf/helpers.c')
-rw-r--r--kernel/bpf/helpers.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c
index bd7f5988ed9c..b3aaabdf9a50 100644
--- a/kernel/bpf/helpers.c
+++ b/kernel/bpf/helpers.c
@@ -13,6 +13,7 @@
13#include <linux/rcupdate.h> 13#include <linux/rcupdate.h>
14#include <linux/random.h> 14#include <linux/random.h>
15#include <linux/smp.h> 15#include <linux/smp.h>
16#include <linux/ktime.h>
16 17
17/* If kernel subsystem is allowing eBPF programs to call this function, 18/* If kernel subsystem is allowing eBPF programs to call this function,
18 * inside its own verifier_ops->get_func_proto() callback it should return 19 * inside its own verifier_ops->get_func_proto() callback it should return
@@ -111,3 +112,15 @@ const struct bpf_func_proto bpf_get_smp_processor_id_proto = {
111 .gpl_only = false, 112 .gpl_only = false,
112 .ret_type = RET_INTEGER, 113 .ret_type = RET_INTEGER,
113}; 114};
115
116static u64 bpf_ktime_get_ns(u64 r1, u64 r2, u64 r3, u64 r4, u64 r5)
117{
118 /* NMI safe access to clock monotonic */
119 return ktime_get_mono_fast_ns();
120}
121
122const struct bpf_func_proto bpf_ktime_get_ns_proto = {
123 .func = bpf_ktime_get_ns,
124 .gpl_only = true,
125 .ret_type = RET_INTEGER,
126};