Linux Kernel Selftest development
 help / color / mirror / Atom feed
From: Stanislav Fomichev <sdf@google.com>
To: Gilad Sever <gilad9366@gmail.com>
Cc: dsahern@kernel.org, martin.lau@linux.dev, daniel@iogearbox.net,
	john.fastabend@gmail.com, ast@kernel.org, andrii@kernel.org,
	song@kernel.org, yhs@fb.com, kpsingh@kernel.org,
	haoluo@google.com, jolsa@kernel.org, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	mykolal@fb.com, shuah@kernel.org, hawk@kernel.org,
	joe@wand.net.nz, eyal.birger@gmail.com,
	shmulik.ladkani@gmail.com, bpf@vger.kernel.org,
	netdev@vger.kernel.org, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH bpf,v3 1/4] bpf: factor out socket lookup functions for the TC hookpoint.
Date: Thu, 27 Apr 2023 11:03:53 -0700	[thread overview]
Message-ID: <ZEq5CV/Yr/KqmufE@google.com> (raw)
In-Reply-To: <20230426085122.376768-2-gilad9366@gmail.com>

On 04/26, Gilad Sever wrote:
> Change BPF helper socket lookup functions to use TC specific variants:
> bpf_tc_sk_lookup_tcp() / bpf_tc_sk_lookup_udp() / bpf_tc_skc_lookup_tcp()
> instead of sharing implementation with the cg / sk_skb hooking points.
> This allows introducing a separate logic for the TC flow.
> 
> The tc functions are identical to the original code.
> 
> Reviewed-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
> Reviewed-by: Eyal Birger <eyal.birger@gmail.com>
> Signed-off-by: Gilad Sever <gilad9366@gmail.com>

Acked-by: Stanislav Fomichev <sdf@google.com>

> ---
>  net/core/filter.c | 63 ++++++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 60 insertions(+), 3 deletions(-)
> 
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 1d6f165923bf..5910956f4e0d 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -6701,6 +6701,63 @@ static const struct bpf_func_proto bpf_sk_lookup_udp_proto = {
>  	.arg5_type	= ARG_ANYTHING,
>  };
>  
> +BPF_CALL_5(bpf_tc_skc_lookup_tcp, struct sk_buff *, skb,
> +	   struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
> +{
> +	return (unsigned long)bpf_skc_lookup(skb, tuple, len, IPPROTO_TCP,
> +					     netns_id, flags);
> +}
> +
> +static const struct bpf_func_proto bpf_tc_skc_lookup_tcp_proto = {
> +	.func		= bpf_tc_skc_lookup_tcp,
> +	.gpl_only	= false,
> +	.pkt_access	= true,
> +	.ret_type	= RET_PTR_TO_SOCK_COMMON_OR_NULL,
> +	.arg1_type	= ARG_PTR_TO_CTX,
> +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
> +	.arg3_type	= ARG_CONST_SIZE,
> +	.arg4_type	= ARG_ANYTHING,
> +	.arg5_type	= ARG_ANYTHING,
> +};
> +
> +BPF_CALL_5(bpf_tc_sk_lookup_tcp, struct sk_buff *, skb,
> +	   struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
> +{
> +	return (unsigned long)bpf_sk_lookup(skb, tuple, len, IPPROTO_TCP,
> +					    netns_id, flags);
> +}
> +
> +static const struct bpf_func_proto bpf_tc_sk_lookup_tcp_proto = {
> +	.func		= bpf_tc_sk_lookup_tcp,
> +	.gpl_only	= false,
> +	.pkt_access	= true,
> +	.ret_type	= RET_PTR_TO_SOCKET_OR_NULL,
> +	.arg1_type	= ARG_PTR_TO_CTX,
> +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
> +	.arg3_type	= ARG_CONST_SIZE,
> +	.arg4_type	= ARG_ANYTHING,
> +	.arg5_type	= ARG_ANYTHING,
> +};
> +
> +BPF_CALL_5(bpf_tc_sk_lookup_udp, struct sk_buff *, skb,
> +	   struct bpf_sock_tuple *, tuple, u32, len, u64, netns_id, u64, flags)
> +{
> +	return (unsigned long)bpf_sk_lookup(skb, tuple, len, IPPROTO_UDP,
> +					    netns_id, flags);
> +}
> +
> +static const struct bpf_func_proto bpf_tc_sk_lookup_udp_proto = {
> +	.func		= bpf_tc_sk_lookup_udp,
> +	.gpl_only	= false,
> +	.pkt_access	= true,
> +	.ret_type	= RET_PTR_TO_SOCKET_OR_NULL,
> +	.arg1_type	= ARG_PTR_TO_CTX,
> +	.arg2_type	= ARG_PTR_TO_MEM | MEM_RDONLY,
> +	.arg3_type	= ARG_CONST_SIZE,
> +	.arg4_type	= ARG_ANYTHING,
> +	.arg5_type	= ARG_ANYTHING,
> +};
> +
>  BPF_CALL_1(bpf_sk_release, struct sock *, sk)
>  {
>  	if (sk && sk_is_refcounted(sk))
> @@ -7954,9 +8011,9 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
>  #endif
>  #ifdef CONFIG_INET
>  	case BPF_FUNC_sk_lookup_tcp:
> -		return &bpf_sk_lookup_tcp_proto;
> +		return &bpf_tc_sk_lookup_tcp_proto;
>  	case BPF_FUNC_sk_lookup_udp:
> -		return &bpf_sk_lookup_udp_proto;
> +		return &bpf_tc_sk_lookup_udp_proto;
>  	case BPF_FUNC_sk_release:
>  		return &bpf_sk_release_proto;
>  	case BPF_FUNC_tcp_sock:
> @@ -7964,7 +8021,7 @@ tc_cls_act_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
>  	case BPF_FUNC_get_listener_sock:
>  		return &bpf_get_listener_sock_proto;
>  	case BPF_FUNC_skc_lookup_tcp:
> -		return &bpf_skc_lookup_tcp_proto;
> +		return &bpf_tc_skc_lookup_tcp_proto;
>  	case BPF_FUNC_tcp_check_syncookie:
>  		return &bpf_tcp_check_syncookie_proto;
>  	case BPF_FUNC_skb_ecn_set_ce:
> -- 
> 2.34.1
> 

  reply	other threads:[~2023-04-27 18:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-26  8:51 [PATCH bpf,v3 0/4] Socket lookup BPF API from tc/xdp ingress does not respect VRF bindings Gilad Sever
2023-04-26  8:51 ` [PATCH bpf,v3 1/4] bpf: factor out socket lookup functions for the TC hookpoint Gilad Sever
2023-04-27 18:03   ` Stanislav Fomichev [this message]
2023-04-26  8:51 ` [PATCH bpf,v3 2/4] bpf: Call __bpf_sk_lookup()/__bpf_skc_lookup() directly via " Gilad Sever
2023-04-27 18:03   ` Stanislav Fomichev
2023-04-26  8:51 ` [PATCH bpf,v3 3/4] bpf: fix bpf socket lookup from tc/xdp to respect socket VRF bindings Gilad Sever
2023-04-27 18:03   ` Stanislav Fomichev
2023-04-26  8:51 ` [PATCH bpf,v3 4/4] selftests/bpf: Add vrf_socket_lookup tests Gilad Sever
2023-04-27 17:31   ` Stanislav Fomichev

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=ZEq5CV/Yr/KqmufE@google.com \
    --to=sdf@google.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=eyal.birger@gmail.com \
    --cc=gilad9366@gmail.com \
    --cc=haoluo@google.com \
    --cc=hawk@kernel.org \
    --cc=joe@wand.net.nz \
    --cc=john.fastabend@gmail.com \
    --cc=jolsa@kernel.org \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=mykolal@fb.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=shmulik.ladkani@gmail.com \
    --cc=shuah@kernel.org \
    --cc=song@kernel.org \
    --cc=yhs@fb.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