History

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.

Alexei Starovoitov committed 11 years ago

Commit 9bac3d61 parent a498cfe5 files · +234 −35Browse files

Showing the changes to include/uapi (1 of 5 files). Show all

Unified · Split

include/uapi/linux/bpf.h+10−0
@@ -170,4 +170,14 @@ enum bpf_func_id { · 169 unmodified lines
170 __BPF_FUNC_MAX_ID,170 __BPF_FUNC_MAX_ID,
171};171};
172 172
173/* user accessible mirror of in-kernel sk_buff.
174 * new fields can only be added to the end of this structure
175 */
176struct __sk_buff {
177 __u32 len;
178 __u32 pkt_type;
179 __u32 mark;
180 __u32 queue_mapping;
181};
182
173#endif /* _UAPI__LINUX_BPF_H__ */183#endif /* _UAPI__LINUX_BPF_H__ */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t