Skip to content

Commit 7a4b28c

Browse files
borkmanndavem330
authored andcommitted
bpf: add helper to invalidate hash
Add a small helper that complements 36bbef5 ("bpf: direct packet write and access for helpers for clsact progs") for invalidating the current skb->hash after mangling on headers via direct packet write. Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Alexei Starovoitov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 669dc4d commit 7a4b28c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

include/uapi/linux/bpf.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,13 @@ enum bpf_func_id {
419419
*/
420420
BPF_FUNC_csum_update,
421421

422+
/**
423+
* bpf_set_hash_invalid(skb)
424+
* Invalidate current skb>hash.
425+
* @skb: pointer to skb
426+
*/
427+
BPF_FUNC_set_hash_invalid,
428+
422429
__BPF_FUNC_MAX_ID,
423430
};
424431

net/core/filter.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,22 @@ static const struct bpf_func_proto bpf_get_hash_recalc_proto = {
17771777
.arg1_type = ARG_PTR_TO_CTX,
17781778
};
17791779

1780+
BPF_CALL_1(bpf_set_hash_invalid, struct sk_buff *, skb)
1781+
{
1782+
/* After all direct packet write, this can be used once for
1783+
* triggering a lazy recalc on next skb_get_hash() invocation.
1784+
*/
1785+
skb_clear_hash(skb);
1786+
return 0;
1787+
}
1788+
1789+
static const struct bpf_func_proto bpf_set_hash_invalid_proto = {
1790+
.func = bpf_set_hash_invalid,
1791+
.gpl_only = false,
1792+
.ret_type = RET_INTEGER,
1793+
.arg1_type = ARG_PTR_TO_CTX,
1794+
};
1795+
17801796
BPF_CALL_3(bpf_skb_vlan_push, struct sk_buff *, skb, __be16, vlan_proto,
17811797
u16, vlan_tci)
17821798
{
@@ -2534,6 +2550,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id)
25342550
return &bpf_get_route_realm_proto;
25352551
case BPF_FUNC_get_hash_recalc:
25362552
return &bpf_get_hash_recalc_proto;
2553+
case BPF_FUNC_set_hash_invalid:
2554+
return &bpf_set_hash_invalid_proto;
25372555
case BPF_FUNC_perf_event_output:
25382556
return &bpf_skb_event_output_proto;
25392557
case BPF_FUNC_get_smp_processor_id:

0 commit comments

Comments
 (0)