Skip to content

Commit

Permalink
get rid of version checks
Browse files Browse the repository at this point in the history
version checks don't work at all on kernels with backported bpf bits
they also fail when /usr/include/linux/bpf.h doesn't match loaded
kernel.
Fix these issues by embedding bpf.h into libbcc.so and force load it
in clang, so we can remove all version checks and rely on verifier
complaining on unknown function call.
Later patch can make verifier errors less cryptic by converting
'unknown call 12' to strings.

while at it update bpf.h to the latest.

Signed-off-by: Alexei Starovoitov <[email protected]>
  • Loading branch information
4ast committed Mar 31, 2016
1 parent 63a8800 commit f09b5b8
Show file tree
Hide file tree
Showing 6 changed files with 414 additions and 18 deletions.
21 changes: 21 additions & 0 deletions src/cc/compat/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ enum bpf_prog_type {
#define BPF_NOEXIST 1 /* create new element if it didn't exist */
#define BPF_EXIST 2 /* update existing element */

#define BPF_F_NO_PREALLOC (1U << 0)

union bpf_attr {
struct { /* anonymous struct used by BPF_MAP_CREATE command */
__u32 map_type; /* one of enum bpf_map_type */
__u32 key_size; /* size of key in bytes */
__u32 value_size; /* size of value in bytes */
__u32 max_entries; /* max number of entries in a map */
__u32 map_flags; /* prealloc or not */
};

struct { /* anonymous struct used by BPF_MAP_*_ELEM commands */
Expand Down Expand Up @@ -298,13 +301,25 @@ enum bpf_func_id {
* Return: csum result
*/
BPF_FUNC_csum_diff,

/**
* bpf_skb_[gs]et_tunnel_opt(skb, opt, size)
* retrieve or populate tunnel options metadata
* @skb: pointer to skb
* @opt: pointer to raw tunnel option data
* @size: size of @opt
* Return: 0 on success for set, option size for get
*/
BPF_FUNC_skb_get_tunnel_opt,
BPF_FUNC_skb_set_tunnel_opt,
__BPF_FUNC_MAX_ID,
};

/* All flags used by eBPF helper functions, placed here. */

/* BPF_FUNC_skb_store_bytes flags. */
#define BPF_F_RECOMPUTE_CSUM (1ULL << 0)
#define BPF_F_INVALIDATE_HASH (1ULL << 1)

/* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
* First 4 bits are for passing the header field size.
Expand All @@ -327,6 +342,10 @@ enum bpf_func_id {
#define BPF_F_FAST_STACK_CMP (1ULL << 9)
#define BPF_F_REUSE_STACKID (1ULL << 10)

/* BPF_FUNC_skb_set_tunnel_key flags. */
#define BPF_F_ZERO_CSUM_TX (1ULL << 1)
#define BPF_F_DONT_FRAGMENT (1ULL << 2)

/* user accessible mirror of in-kernel sk_buff.
* new fields can only be added to the end of this structure
*/
Expand Down Expand Up @@ -356,6 +375,8 @@ struct bpf_tunnel_key {
};
__u8 tunnel_tos;
__u8 tunnel_ttl;
__u16 tunnel_ext;
__u32 tunnel_label;
};

#endif /* _UAPI__LINUX_BPF_H__ */
Loading

0 comments on commit f09b5b8

Please sign in to comment.