* [PATCH bpf] bpf: allow clearing all sock_ops callback flags
@ 2019-04-15 9:54 Viet Hoang Tran
2019-04-15 22:46 ` Martin Lau
2019-04-17 2:27 ` Alexei Starovoitov
0 siblings, 2 replies; 3+ messages in thread
From: Viet Hoang Tran @ 2019-04-15 9:54 UTC (permalink / raw)
To: bpf
Cc: netdev, Alexei Starovoitov, Daniel Borkmann, David S. Miller,
Lawrence Brakmo, Martin Lau, Quentin Monnet, tranviethoang.vn,
Viet Hoang Tran
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>
---
include/uapi/linux/bpf.h | 9 ++++++++-
net/core/filter.c | 3 +--
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 929c8e537a14..f9ee093fe8d3 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -1694,12 +1694,19 @@ union bpf_attr {
* error if an eBPF program tries to set a callback that is not
* 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_RETRANS_CB_FLAG** (retransmission)
* * **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
* program:
*
diff --git a/net/core/filter.c b/net/core/filter.c
index fc92ebc4e200..0c4cdfbb2fc7 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4355,8 +4355,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))
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);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] bpf: allow clearing all sock_ops callback flags
2019-04-15 9:54 [PATCH bpf] bpf: allow clearing all sock_ops callback flags Viet Hoang Tran
@ 2019-04-15 22:46 ` Martin Lau
2019-04-17 2:27 ` Alexei Starovoitov
1 sibling, 0 replies; 3+ messages in thread
From: Martin Lau @ 2019-04-15 22:46 UTC (permalink / raw)
To: Viet Hoang Tran
Cc: bpf, netdev, Alexei Starovoitov, Daniel Borkmann,
David S. Miller, Lawrence Brakmo, Quentin Monnet,
tranviethoang.vn
On Mon, Apr 15, 2019 at 09:54:55AM +0000, Viet Hoang Tran wrote:
> 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.
>
[ ... ]
> diff --git a/net/core/filter.c b/net/core/filter.c
> index fc92ebc4e200..0c4cdfbb2fc7 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -4355,8 +4355,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))
> return -EINVAL;
>
> - if (val)
> - tcp_sk(sk)->bpf_sock_ops_cb_flags = val;
> + tcp_sk(sk)->bpf_sock_ops_cb_flags = val;
Acked-by: Martin KaFai Lau <kafai@fb.com>
>
> return argval & (~BPF_SOCK_OPS_ALL_CB_FLAGS);
> }
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH bpf] bpf: allow clearing all sock_ops callback flags
2019-04-15 9:54 [PATCH bpf] bpf: allow clearing all sock_ops callback flags Viet Hoang Tran
2019-04-15 22:46 ` Martin Lau
@ 2019-04-17 2:27 ` Alexei Starovoitov
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2019-04-17 2:27 UTC (permalink / raw)
To: Viet Hoang Tran
Cc: bpf, netdev, Alexei Starovoitov, Daniel Borkmann,
David S. Miller, Lawrence Brakmo, Martin Lau, Quentin Monnet,
tranviethoang.vn
On Mon, Apr 15, 2019 at 2:55 AM Viet Hoang Tran <hoang.tran@uclouvain.be> wrote:
>
> 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>
Applied. Thanks
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-04-17 2:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-15 9:54 [PATCH bpf] bpf: allow clearing all sock_ops callback flags Viet Hoang Tran
2019-04-15 22:46 ` Martin Lau
2019-04-17 2:27 ` Alexei Starovoitov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).