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))
adding here some flag values that bpf helper functions take, namely bpf_skb* functions; along with prototypes for
bpf_l3_csum_replace
andbpf_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: