]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
bpf: Allow __sk_buff tstamp in BPF_PROG_TEST_RUN
authorStanislav Fomichev <sdf@google.com>
Tue, 15 Oct 2019 18:31:24 +0000 (11:31 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 15 Oct 2019 23:24:26 +0000 (16:24 -0700)
It's useful for implementing EDT related tests (set tstamp, run the
test, see how the tstamp is changed or observe some other parameter).

Note that bpf_ktime_get_ns() helper is using monotonic clock, so for
the BPF programs that compare tstamp against it, tstamp should be
derived from clock_gettime(CLOCK_MONOTONIC, ...).

Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Martin KaFai Lau <kafai@fb.com>
Link: https://lore.kernel.org/bpf/20191015183125.124413-1-sdf@google.com
net/bpf/test_run.c

index 1153bbcdff721de951a7ebfe23e83ddb9cc43ae1..0be4497cb832c765eb6c9ece614b7aa8882bda93 100644 (file)
@@ -218,10 +218,18 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
 
        if (!range_is_zero(__skb, offsetof(struct __sk_buff, cb) +
                           FIELD_SIZEOF(struct __sk_buff, cb),
+                          offsetof(struct __sk_buff, tstamp)))
+               return -EINVAL;
+
+       /* tstamp is allowed */
+
+       if (!range_is_zero(__skb, offsetof(struct __sk_buff, tstamp) +
+                          FIELD_SIZEOF(struct __sk_buff, tstamp),
                           sizeof(struct __sk_buff)))
                return -EINVAL;
 
        skb->priority = __skb->priority;
+       skb->tstamp = __skb->tstamp;
        memcpy(&cb->data, __skb->cb, QDISC_CB_PRIV_LEN);
 
        return 0;
@@ -235,6 +243,7 @@ static void convert_skb_to___skb(struct sk_buff *skb, struct __sk_buff *__skb)
                return;
 
        __skb->priority = skb->priority;
+       __skb->tstamp = skb->tstamp;
        memcpy(__skb->cb, &cb->data, QDISC_CB_PRIV_LEN);
 }