Skip to content

Commit ba94094

Browse files
fomichevAlexei Starovoitov
authored andcommitted
bpf: Allow __sk_buff tstamp in BPF_PROG_TEST_RUN
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 <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Acked-by: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent da92746 commit ba94094

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

net/bpf/test_run.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,18 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
218218

219219
if (!range_is_zero(__skb, offsetof(struct __sk_buff, cb) +
220220
FIELD_SIZEOF(struct __sk_buff, cb),
221+
offsetof(struct __sk_buff, tstamp)))
222+
return -EINVAL;
223+
224+
/* tstamp is allowed */
225+
226+
if (!range_is_zero(__skb, offsetof(struct __sk_buff, tstamp) +
227+
FIELD_SIZEOF(struct __sk_buff, tstamp),
221228
sizeof(struct __sk_buff)))
222229
return -EINVAL;
223230

224231
skb->priority = __skb->priority;
232+
skb->tstamp = __skb->tstamp;
225233
memcpy(&cb->data, __skb->cb, QDISC_CB_PRIV_LEN);
226234

227235
return 0;
@@ -235,6 +243,7 @@ static void convert_skb_to___skb(struct sk_buff *skb, struct __sk_buff *__skb)
235243
return;
236244

237245
__skb->priority = skb->priority;
246+
__skb->tstamp = skb->tstamp;
238247
memcpy(__skb->cb, &cb->data, QDISC_CB_PRIV_LEN);
239248
}
240249

0 commit comments

Comments
 (0)