Skip to content

Commit 850a88c

Browse files
fomichevAlexei Starovoitov
authored andcommitted
bpf: Expose __sk_buff wire_len/gso_segs to BPF_PROG_TEST_RUN
wire_len should not be less than real len and is capped by GSO_MAX_SIZE. gso_segs is capped by GSO_MAX_SEGS. v2: * set wire_len to skb->len when passed wire_len is 0 (Alexei Starovoitov) Signed-off-by: Stanislav Fomichev <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Cc: Martin KaFai Lau <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 02620d9 commit 850a88c

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

net/bpf/test_run.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,30 @@ static int convert___skb_to_skb(struct sk_buff *skb, struct __sk_buff *__skb)
267267
return -EINVAL;
268268

269269
/* tstamp is allowed */
270+
/* wire_len is allowed */
271+
/* gso_segs is allowed */
270272

271-
if (!range_is_zero(__skb, offsetofend(struct __sk_buff, tstamp),
273+
if (!range_is_zero(__skb, offsetofend(struct __sk_buff, gso_segs),
272274
sizeof(struct __sk_buff)))
273275
return -EINVAL;
274276

275277
skb->priority = __skb->priority;
276278
skb->tstamp = __skb->tstamp;
277279
memcpy(&cb->data, __skb->cb, QDISC_CB_PRIV_LEN);
278280

281+
if (__skb->wire_len == 0) {
282+
cb->pkt_len = skb->len;
283+
} else {
284+
if (__skb->wire_len < skb->len ||
285+
__skb->wire_len > GSO_MAX_SIZE)
286+
return -EINVAL;
287+
cb->pkt_len = __skb->wire_len;
288+
}
289+
290+
if (__skb->gso_segs > GSO_MAX_SEGS)
291+
return -EINVAL;
292+
skb_shinfo(skb)->gso_segs = __skb->gso_segs;
293+
279294
return 0;
280295
}
281296

@@ -289,6 +304,8 @@ static void convert_skb_to___skb(struct sk_buff *skb, struct __sk_buff *__skb)
289304
__skb->priority = skb->priority;
290305
__skb->tstamp = skb->tstamp;
291306
memcpy(__skb->cb, &cb->data, QDISC_CB_PRIV_LEN);
307+
__skb->wire_len = cb->pkt_len;
308+
__skb->gso_segs = skb_shinfo(skb)->gso_segs;
292309
}
293310

294311
int bpf_prog_test_run_skb(struct bpf_prog *prog, const union bpf_attr *kattr,

0 commit comments

Comments
 (0)