dropbox / goebpf

Library to work with eBPF programs from Go
Other
1.14k stars 85 forks source link

[bpf-helpers] update bpf_helpers.h with flag values for some bpf helpers #61

Closed bersoare closed 2 years ago

bersoare commented 2 years ago

adding here some flag values that bpf helper functions take, namely bpf_skb* functions; along with prototypes for bpf_l3_csum_replace and bpf_l4_csum_replace helpers.

also added a new offsetof function that can be used for getting an offset from a struct member, useful if passing offsets to these helpers are needed. example:

// we'll always get a l2 skb, so hardcode ethernet header in the logic
#define TTL_OFFSET (sizeof(struct ethhdr) + offsetof(struct iphdr, ttl))
#define CSUM_OFFSET (sizeof(struct ethhdr) + offsetof(struct iphdr, check))
#define HOPLIMIT_OFFSET (sizeof(struct ethhdr) + offsetof(struct ipv6hdr, hop_limit))

// pass ttl and csum field offsets to the functions to get them updated
bpf_skb_store_bytes(skb, TTL_OFFSET, &ttl, sizeof(__u8), 0);
bpf_l3_csum_replace(skb, CSUM_OFFSET, ip.ttl, ttl, sizeof(__u16))
belyalov commented 2 years ago

@nberezin mind to merge it?

belyalov commented 2 years ago

Thanks for approval! Travis CI build got stuck, so @nberezin could you please restart it or simply merge this PR?