diff options
author | Alexei Starovoitov <ast@plumgrid.com> | 2015-03-13 19:57:42 +0100 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-03-16 03:02:28 +0100 |
commit | 9bac3d6d548e5cc925570b263f35b70a00a00ffd (patch) | |
tree | 00ae5c37fb877d7c2b4fdf5ee0b8fe4837b1d476 /include/uapi | |
parent | Merge branch 'ebpf_helpers' (diff) | |
download | linux-9bac3d6d548e5cc925570b263f35b70a00a00ffd.tar.xz linux-9bac3d6d548e5cc925570b263f35b70a00a00ffd.zip |
bpf: allow extended BPF programs access skb fields
introduce user accessible mirror of in-kernel 'struct sk_buff':
struct __sk_buff {
__u32 len;
__u32 pkt_type;
__u32 mark;
__u32 queue_mapping;
};
bpf programs can do:
int bpf_prog(struct __sk_buff *skb)
{
__u32 var = skb->pkt_type;
which will be compiled to bpf assembler as:
dst_reg = *(u32 *)(src_reg + 4) // 4 == offsetof(struct __sk_buff, pkt_type)
bpf verifier will check validity of access and will convert it to:
dst_reg = *(u8 *)(src_reg + offsetof(struct sk_buff, __pkt_type_offset))
dst_reg &= 7
since skb->pkt_type is a bitfield.
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'include/uapi')
-rw-r--r-- | include/uapi/linux/bpf.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index de1f63668daf..929545a27546 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -170,4 +170,14 @@ enum bpf_func_id { __BPF_FUNC_MAX_ID, }; +/* user accessible mirror of in-kernel sk_buff. + * new fields can only be added to the end of this structure + */ +struct __sk_buff { + __u32 len; + __u32 pkt_type; + __u32 mark; + __u32 queue_mapping; +}; + #endif /* _UAPI__LINUX_BPF_H__ */ |