Calculating a hash from a eBPF program?
[This isn't strictly an XDP question, I'm using cls_bpf but I don't know of a better place to ask]
Is there a way to calculate a hash of a struct or other data from within an eBPF program? I need to build a classifier that can hash a flow encapsulated in protocols like PPPoE or GTP-U. Basically like cls_flow's use of jhash2 but at a different offset. I looked at the helpers in bpf.h but don't see anything helpful there.
Thanks.
Quoted 8 lines · Dan Siemon
[This isn't strictly an XDP question, I'm using
cls_bpfbut I don't know of a better place to ask]Is there a way to calculate a hash of a struct or other data from within an eBPF program? I need to build a classifier that can hash a flow encapsulated in protocols like PPPoE or GTP-U. Basically like cls_flow's use of jhash2 but at a different offset. I looked at the helpers in
bpf.hbut don't see anything helpful there.
Why no implement it inside the BPF prog like it's done here [1] (the example is XDP but cls_bpf should work just as well)?
There's also a bpf_set_hash(struct __sk_buff *skb, u32 hash) helper (net-next) for cls_bpf, where you can then use the jhash result and set it as skb->hash.
[1] http://lingrok.org/xref/linux-net-next/tools/testing/selftests/bpf/test_l4lb.c#26
Quoted 2 lines
Thanks.