UPSTREAM: bpf: Add gso_size to __sk_buff
BPF programs may want to know whether an skb is gso. The canonical answer is skb_is_gso(skb), which tests that gso_size != 0. Expose this field in the same manner as gso_segs. That field itself is not a sufficient signal, as the comment in skb_shared_info makes clear: gso_segs may be zero, e.g., from dodgy sources. Also prepare net/bpf/test_run for upcoming BPF_PROG_TEST_RUN tests of the feature. Signed-off-by: Willem de Bruijn <willemb@google.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200303200503.226217-2-willemdebruijn.kernel@gmail.com Note: backported without changes to net/bpf/test_run.c (cherry picked from commit cf62089b0edd7e74a1f474844b4d9f7b5697fb5c) Signed-off-by: Maciej Żenczykowski <maze@google.com> Change-Id: I1f7d1b49e5ac35f18546d468e3847deaae5056ca
This commit is contained in:
parent
42c433c5f7
commit
4f5efed8ed
@ -3005,6 +3005,7 @@ struct __sk_buff {
|
||||
__u32 wire_len;
|
||||
__u32 gso_segs;
|
||||
__bpf_md_ptr(struct bpf_sock *, sk);
|
||||
__u32 gso_size;
|
||||
};
|
||||
|
||||
struct bpf_tunnel_key {
|
||||
|
@ -7223,6 +7223,27 @@ static u32 flow_dissector_convert_ctx_access(enum bpf_access_type type,
|
||||
return insn - insn_buf;
|
||||
}
|
||||
|
||||
static struct bpf_insn *bpf_convert_shinfo_access(const struct bpf_insn *si,
|
||||
struct bpf_insn *insn)
|
||||
{
|
||||
/* si->dst_reg = skb_shinfo(SKB); */
|
||||
#ifdef NET_SKBUFF_DATA_USES_OFFSET
|
||||
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end),
|
||||
BPF_REG_AX, si->src_reg,
|
||||
offsetof(struct sk_buff, end));
|
||||
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, head),
|
||||
si->dst_reg, si->src_reg,
|
||||
offsetof(struct sk_buff, head));
|
||||
*insn++ = BPF_ALU64_REG(BPF_ADD, si->dst_reg, BPF_REG_AX);
|
||||
#else
|
||||
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end),
|
||||
si->dst_reg, si->src_reg,
|
||||
offsetof(struct sk_buff, end));
|
||||
#endif
|
||||
|
||||
return insn;
|
||||
}
|
||||
|
||||
static u32 bpf_convert_ctx_access(enum bpf_access_type type,
|
||||
const struct bpf_insn *si,
|
||||
struct bpf_insn *insn_buf,
|
||||
@ -7545,26 +7566,21 @@ static u32 bpf_convert_ctx_access(enum bpf_access_type type,
|
||||
break;
|
||||
|
||||
case offsetof(struct __sk_buff, gso_segs):
|
||||
/* si->dst_reg = skb_shinfo(SKB); */
|
||||
#ifdef NET_SKBUFF_DATA_USES_OFFSET
|
||||
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end),
|
||||
BPF_REG_AX, si->src_reg,
|
||||
offsetof(struct sk_buff, end));
|
||||
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, head),
|
||||
si->dst_reg, si->src_reg,
|
||||
offsetof(struct sk_buff, head));
|
||||
*insn++ = BPF_ALU64_REG(BPF_ADD, si->dst_reg, BPF_REG_AX);
|
||||
#else
|
||||
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, end),
|
||||
si->dst_reg, si->src_reg,
|
||||
offsetof(struct sk_buff, end));
|
||||
#endif
|
||||
insn = bpf_convert_shinfo_access(si, insn);
|
||||
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct skb_shared_info, gso_segs),
|
||||
si->dst_reg, si->dst_reg,
|
||||
bpf_target_off(struct skb_shared_info,
|
||||
gso_segs, 2,
|
||||
target_size));
|
||||
break;
|
||||
case offsetof(struct __sk_buff, gso_size):
|
||||
insn = bpf_convert_shinfo_access(si, insn);
|
||||
*insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct skb_shared_info, gso_size),
|
||||
si->dst_reg, si->dst_reg,
|
||||
bpf_target_off(struct skb_shared_info,
|
||||
gso_size, 2,
|
||||
target_size));
|
||||
break;
|
||||
case offsetof(struct __sk_buff, wire_len):
|
||||
BUILD_BUG_ON(FIELD_SIZEOF(struct qdisc_skb_cb, pkt_len) != 4);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user