bpf: allow clearing all sock_ops callback flags
The helper function bpf_sock_ops_cb_flags_set() can be used to both set and clear the sock_ops callback flags. However, its current behavior is not consistent. BPF program may clear a flag if more than one were set, or replace a flag with another one, but cannot clear all flags. This patch also updates the documentation to clarify the ability to clear flags of this helper function. Signed-off-by: Hoang Tran <hoang.tran@uclouvain.be> Acked-by: Martin KaFai Lau <kafai@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
This commit is contained in:

committed by
Alexei Starovoitov

parent
809041e765
commit
725721a650
@@ -1737,12 +1737,19 @@ union bpf_attr {
|
|||||||
* error if an eBPF program tries to set a callback that is not
|
* error if an eBPF program tries to set a callback that is not
|
||||||
* supported in the current kernel.
|
* supported in the current kernel.
|
||||||
*
|
*
|
||||||
* The supported callback values that *argval* can combine are:
|
* *argval* is a flag array which can combine these flags:
|
||||||
*
|
*
|
||||||
* * **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
|
* * **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
|
||||||
* * **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
|
* * **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
|
||||||
* * **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
|
* * **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
|
||||||
*
|
*
|
||||||
|
* Therefore, this function can be used to clear a callback flag by
|
||||||
|
* setting the appropriate bit to zero. e.g. to disable the RTO
|
||||||
|
* callback:
|
||||||
|
*
|
||||||
|
* **bpf_sock_ops_cb_flags_set(bpf_sock,**
|
||||||
|
* **bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**
|
||||||
|
*
|
||||||
* Here are some examples of where one could call such eBPF
|
* Here are some examples of where one could call such eBPF
|
||||||
* program:
|
* program:
|
||||||
*
|
*
|
||||||
|
@@ -4437,8 +4437,7 @@ BPF_CALL_2(bpf_sock_ops_cb_flags_set, struct bpf_sock_ops_kern *, bpf_sock,
|
|||||||
if (!IS_ENABLED(CONFIG_INET) || !sk_fullsock(sk))
|
if (!IS_ENABLED(CONFIG_INET) || !sk_fullsock(sk))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
if (val)
|
tcp_sk(sk)->bpf_sock_ops_cb_flags = val;
|
||||||
tcp_sk(sk)->bpf_sock_ops_cb_flags = val;
|
|
||||||
|
|
||||||
return argval & (~BPF_SOCK_OPS_ALL_CB_FLAGS);
|
return argval & (~BPF_SOCK_OPS_ALL_CB_FLAGS);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user