From: Yonghong Song <yhs@fb.com>
To: Cong Wang <xiyou.wangcong@gmail.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
bpf <bpf@vger.kernel.org>, <duanxiongchun@bytedance.com>,
Dongdong Wang <wangdongdong.6@bytedance.com>,
Jiang Wang <jiang.wang@bytedance.com>,
Cong Wang <cong.wang@bytedance.com>,
John Fastabend <john.fastabend@gmail.com>,
Daniel Borkmann <daniel@iogearbox.net>,
Jakub Sitnicki <jakub@cloudflare.com>,
Lorenz Bauer <lmb@cloudflare.com>
Subject: Re: [Patch bpf-next v2 8/9] sock_map: update sock type checks for UDP
Date: Wed, 3 Mar 2021 10:50:38 -0800 [thread overview]
Message-ID: <33a6d38b-28dd-0c38-05a0-6fa09290fbea@fb.com> (raw)
In-Reply-To: <CAM_iQpXM+kyi=LFe0YygYuVE7kcApVGJ9f2A-D=ST2nFPusttg@mail.gmail.com>
On 3/3/21 10:02 AM, Cong Wang wrote:
> On Tue, Mar 2, 2021 at 10:37 PM Yonghong Song <yhs@fb.com> wrote:
>>
>>
>>
>> On 3/1/21 6:37 PM, Cong Wang wrote:
>>> From: Cong Wang <cong.wang@bytedance.com>
>>>
>>> Now UDP supports sockmap and redirection, we can safely update
>>> the sock type checks for it accordingly.
>>>
>>> Cc: John Fastabend <john.fastabend@gmail.com>
>>> Cc: Daniel Borkmann <daniel@iogearbox.net>
>>> Cc: Jakub Sitnicki <jakub@cloudflare.com>
>>> Cc: Lorenz Bauer <lmb@cloudflare.com>
>>> Signed-off-by: Cong Wang <cong.wang@bytedance.com>
>>> ---
>>> net/core/sock_map.c | 5 ++++-
>>> 1 file changed, 4 insertions(+), 1 deletion(-)
>>>
>>> diff --git a/net/core/sock_map.c b/net/core/sock_map.c
>>> index 13d2af5bb81c..f7eee4b7b994 100644
>>> --- a/net/core/sock_map.c
>>> +++ b/net/core/sock_map.c
>>> @@ -549,7 +549,10 @@ static bool sk_is_udp(const struct sock *sk)
>>>
>>> static bool sock_map_redirect_allowed(const struct sock *sk)
>>> {
>>> - return sk_is_tcp(sk) && sk->sk_state != TCP_LISTEN;
>>> + if (sk_is_tcp(sk))
>>> + return sk->sk_state != TCP_LISTEN;
>>> + else
>>> + return sk->sk_state == TCP_ESTABLISHED;
>>
>> Not a networking expert, a dump question. Here we tested
>> whether sk_is_tcp(sk) or not, if not we compare
>> sk->sk_state == TCP_ESTABLISHED, could this be
>> always false? Mostly I missed something, some comments
>> here will be good.
>
> No, dgram sockets also use TCP_ESTABLISHED as a valid
> state. I know its name looks confusing, but it is already widely
> used in networking:
>
> net/appletalk/ddp.c: sk->sk_state = TCP_ESTABLISHED;
> net/appletalk/ddp.c: if (sk->sk_state != TCP_ESTABLISHED)
> net/appletalk/ddp.c: if (sk->sk_state != TCP_ESTABLISHED)
> net/ax25/af_ax25.c: sk->sk_state = TCP_ESTABLISHED;
> net/ax25/af_ax25.c: case TCP_ESTABLISHED: /* connection
> established */
> net/ax25/af_ax25.c: if (sk->sk_state == TCP_ESTABLISHED &&
> sk->sk_type == SOCK_SEQPACKET) {
> net/ax25/af_ax25.c: sk->sk_state = TCP_ESTABLISHED;
> net/ax25/af_ax25.c: if (sk->sk_state != TCP_ESTABLISHED && (flags
> & O_NONBLOCK)) {
> net/ax25/af_ax25.c: if (sk->sk_state != TCP_ESTABLISHED) {
> net/ax25/af_ax25.c: if (sk->sk_state != TCP_ESTABLISHED) {
> net/ax25/af_ax25.c: if (sk->sk_state != TCP_ESTABLISHED) {
> net/ax25/af_ax25.c: if (sk->sk_state != TCP_ESTABLISHED) {
> net/ax25/af_ax25.c: if (sk->sk_type == SOCK_SEQPACKET &&
> sk->sk_state != TCP_ESTABLISHED) {
> net/ax25/ax25_ds_in.c: ax25->sk->sk_state = TCP_ESTABLISHED;
> net/ax25/ax25_in.c: make->sk_state = TCP_ESTABLISHED;
> net/ax25/ax25_std_in.c: ax25->sk->sk_state =
> TCP_ESTABLISHED;
> net/caif/caif_socket.c: CAIF_CONNECTED = TCP_ESTABLISHED,
> net/ceph/messenger.c: case TCP_ESTABLISHED:
> net/ceph/messenger.c: dout("%s TCP_ESTABLISHED\n", __func__);
> net/core/datagram.c: !(sk->sk_state == TCP_ESTABLISHED ||
> sk->sk_state == TCP_LISTEN))
> ...
>
> Hence, I believe it is okay to use it as it is, otherwise we would need
> to comment on every use of it. ;)
That is okay. Thanks for explanation!
>
> Thanks.
>
next prev parent reply other threads:[~2021-03-03 22:57 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-02 2:37 [Patch bpf-next v2 0/9] sockmap: introduce BPF_SK_SKB_VERDICT and support UDP Cong Wang
2021-03-02 2:37 ` [Patch bpf-next v2 1/9] sock_map: introduce BPF_SK_SKB_VERDICT Cong Wang
2021-03-02 2:37 ` [Patch bpf-next v2 2/9] sock: introduce sk_prot->update_proto() Cong Wang
2021-03-02 16:22 ` Lorenz Bauer
2021-03-02 18:23 ` Cong Wang
2021-03-03 9:35 ` Lorenz Bauer
2021-03-03 18:20 ` Cong Wang
2021-03-04 9:30 ` Lorenz Bauer
2021-03-04 23:52 ` Cong Wang
2021-03-06 0:27 ` John Fastabend
2021-03-06 0:57 ` Cong Wang
2021-03-06 1:55 ` John Fastabend
2021-03-09 17:53 ` Cong Wang
2021-03-10 6:33 ` John Fastabend
2021-03-02 2:37 ` [Patch bpf-next v2 3/9] udp: implement ->sendmsg_locked() Cong Wang
2021-03-02 2:37 ` [Patch bpf-next v2 4/9] udp: implement ->read_sock() for sockmap Cong Wang
2021-03-03 6:26 ` Yonghong Song
2021-03-02 2:37 ` [Patch bpf-next v2 5/9] udp: add ->read_sock() and ->sendmsg_locked() to ipv6 Cong Wang
2021-03-02 16:23 ` Lorenz Bauer
2021-03-02 17:59 ` Cong Wang
2021-03-02 2:37 ` [Patch bpf-next v2 6/9] skmsg: extract __tcp_bpf_recvmsg() and tcp_bpf_wait_data() Cong Wang
2021-03-02 2:37 ` [Patch bpf-next v2 7/9] udp: implement udp_bpf_recvmsg() for sockmap Cong Wang
2021-03-02 2:37 ` [Patch bpf-next v2 8/9] sock_map: update sock type checks for UDP Cong Wang
2021-03-03 6:37 ` Yonghong Song
2021-03-03 18:02 ` Cong Wang
2021-03-03 18:50 ` Yonghong Song [this message]
2021-03-02 2:37 ` [Patch bpf-next v2 9/9] selftests/bpf: add a test case for udp sockmap Cong Wang
2021-03-02 16:31 ` Lorenz Bauer
2021-03-02 18:05 ` Cong Wang
2021-03-03 10:20 ` Lorenz Bauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=33a6d38b-28dd-0c38-05a0-6fa09290fbea@fb.com \
--to=yhs@fb.com \
--cc=bpf@vger.kernel.org \
--cc=cong.wang@bytedance.com \
--cc=daniel@iogearbox.net \
--cc=duanxiongchun@bytedance.com \
--cc=jakub@cloudflare.com \
--cc=jiang.wang@bytedance.com \
--cc=john.fastabend@gmail.com \
--cc=lmb@cloudflare.com \
--cc=netdev@vger.kernel.org \
--cc=wangdongdong.6@bytedance.com \
--cc=xiyou.wangcong@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).