BPF List
 help / color / mirror / Atom feed
From: Maxim Mikityanskiy <maximmi@nvidia.com>
To: Daniel Borkmann <daniel@iogearbox.net>
Cc: bpf@vger.kernel.org, "Alexei Starovoitov" <ast@kernel.org>,
	"Andrii Nakryiko" <andrii@kernel.org>,
	netdev@vger.kernel.org, "Tariq Toukan" <tariqt@nvidia.com>,
	"Martin KaFai Lau" <kafai@fb.com>,
	"Song Liu" <songliubraving@fb.com>, "Yonghong Song" <yhs@fb.com>,
	"John Fastabend" <john.fastabend@gmail.com>,
	"KP Singh" <kpsingh@kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Petar Penkov" <ppenkov@google.com>,
	"Lorenz Bauer" <lmb@cloudflare.com>,
	"Eric Dumazet" <edumazet@google.com>,
	"Hideaki YOSHIFUJI" <yoshfuji@linux-ipv6.org>,
	"David Ahern" <dsahern@kernel.org>,
	"Shuah Khan" <shuah@kernel.org>,
	"Jesper Dangaard Brouer" <hawk@kernel.org>,
	"Nathan Chancellor" <nathan@kernel.org>,
	"Nick Desaulniers" <ndesaulniers@google.com>,
	"Joe Stringer" <joe@cilium.io>,
	"Florent Revest" <revest@chromium.org>,
	linux-kselftest@vger.kernel.org,
	"Toke Høiland-Jørgensen" <toke@toke.dk>,
	"Kumar Kartikeya Dwivedi" <memxor@gmail.com>,
	"Florian Westphal" <fw@strlen.de>
Subject: Re: [PATCH bpf-next v5 4/6] bpf: Add helpers to issue and check SYN cookies in XDP
Date: Fri, 22 Apr 2022 20:23:25 +0300	[thread overview]
Message-ID: <87ad8351-6c2d-39ec-7b72-1cf273bbaa72@nvidia.com> (raw)
In-Reply-To: <e75057fd-42d4-071e-b8b9-0b93e643adfd@iogearbox.net>

On 2022-04-14 01:48, Daniel Borkmann wrote:
> On 4/13/22 3:41 PM, Maxim Mikityanskiy wrote:
> [...]
>>   /* integer value in 'imm' field of BPF_CALL instruction selects 
>> which helper
>> diff --git a/net/core/filter.c b/net/core/filter.c
>> index 7446b0ba4e38..428cc63ecdf7 100644
>> --- a/net/core/filter.c
>> +++ b/net/core/filter.c
>> @@ -7425,6 +7425,124 @@ static const struct bpf_func_proto 
>> bpf_skb_set_tstamp_proto = {
>>       .arg3_type      = ARG_ANYTHING,
>>   };
>> +BPF_CALL_3(bpf_tcp_raw_gen_syncookie_ipv4, struct iphdr *, iph,
>> +       struct tcphdr *, th, u32, th_len)
>> +{
>> +#ifdef CONFIG_SYN_COOKIES
>> +    u32 cookie;
>> +    u16 mss;
>> +
>> +    if (unlikely(th_len < sizeof(*th) || th_len != th->doff * 4))
>> +        return -EINVAL;
>> +
>> +    mss = tcp_parse_mss_option(th, 0) ?: TCP_MSS_DEFAULT;
>> +    cookie = __cookie_v4_init_sequence(iph, th, &mss);
>> +
>> +    return cookie | ((u64)mss << 32);
>> +#else
>> +    return -EOPNOTSUPP;
>> +#endif /* CONFIG_SYN_COOKIES */
> 
> This (and for other added helpers below) will be rather tricky to probe 
> for availability
> e.g. via `bpftool feature probe [...]`. Much better if you wrap the 
> ifdef CONFIG_SYN_COOKIES
> around the {xdp,tc_cls_act}_func_proto() instead as we do elsewhere.

Just for the record, I copied this pattern from the existing SYN cookie 
helpers, but what you suggest makes sense, so I'll fix it for my helpers 
and resubmit.

>> +}
>> +
>> +static const struct bpf_func_proto 
>> bpf_tcp_raw_gen_syncookie_ipv4_proto = {
>> +    .func        = bpf_tcp_raw_gen_syncookie_ipv4,
>> +    .gpl_only    = true, /* __cookie_v4_init_sequence() is GPL */
>> +    .pkt_access    = true,
>> +    .ret_type    = RET_INTEGER,
>> +    .arg1_type    = ARG_PTR_TO_MEM,
>> +    .arg1_size    = sizeof(struct iphdr),
>> +    .arg2_type    = ARG_PTR_TO_MEM,
>> +    .arg3_type    = ARG_CONST_SIZE,
>> +};
>> +
>> +BPF_CALL_3(bpf_tcp_raw_gen_syncookie_ipv6, struct ipv6hdr *, iph,
>> +       struct tcphdr *, th, u32, th_len)
>> +{
>> +#ifndef CONFIG_SYN_COOKIES
>> +    return -EOPNOTSUPP;
>> +#elif !IS_BUILTIN(CONFIG_IPV6)
>> +    return -EPROTONOSUPPORT;
>> +#else
>> +    const u16 mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) -
>> +        sizeof(struct ipv6hdr);
>> +    u32 cookie;
>> +    u16 mss;
>> +
>> +    if (unlikely(th_len < sizeof(*th) || th_len != th->doff * 4))
>> +        return -EINVAL;
>> +
>> +    mss = tcp_parse_mss_option(th, 0) ?: mss_clamp;
>> +    cookie = __cookie_v6_init_sequence(iph, th, &mss);
>> +
>> +    return cookie | ((u64)mss << 32);
>> +#endif
>> +}
>> +
>> +static const struct bpf_func_proto 
>> bpf_tcp_raw_gen_syncookie_ipv6_proto = {
>> +    .func        = bpf_tcp_raw_gen_syncookie_ipv6,
>> +    .gpl_only    = true, /* __cookie_v6_init_sequence() is GPL */
>> +    .pkt_access    = true,
>> +    .ret_type    = RET_INTEGER,
>> +    .arg1_type    = ARG_PTR_TO_MEM,
>> +    .arg1_size    = sizeof(struct ipv6hdr),
>> +    .arg2_type    = ARG_PTR_TO_MEM,
>> +    .arg3_type    = ARG_CONST_SIZE,
>> +};
> [...]
>>   bool bpf_helper_changes_pkt_data(void *func)
>> @@ -7837,6 +7955,14 @@ xdp_func_proto(enum bpf_func_id func_id, const 
>> struct bpf_prog *prog)
>>           return &bpf_tcp_check_syncookie_proto;
>>       case BPF_FUNC_tcp_gen_syncookie:
>>           return &bpf_tcp_gen_syncookie_proto;
>> +    case BPF_FUNC_tcp_raw_gen_syncookie_ipv4:
>> +        return &bpf_tcp_raw_gen_syncookie_ipv4_proto;
>> +    case BPF_FUNC_tcp_raw_gen_syncookie_ipv6:
>> +        return &bpf_tcp_raw_gen_syncookie_ipv6_proto;
>> +    case BPF_FUNC_tcp_raw_check_syncookie_ipv4:
>> +        return &bpf_tcp_raw_check_syncookie_ipv4_proto;
>> +    case BPF_FUNC_tcp_raw_check_syncookie_ipv6:
>> +        return &bpf_tcp_raw_check_syncookie_ipv6_proto;
>>   #endif
>>       default:
>>           return bpf_sk_base_func_proto(func_id);


  reply	other threads:[~2022-04-22 17:28 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-13 13:41 [PATCH bpf-next v5 0/5] New BPF helpers to accelerate synproxy Maxim Mikityanskiy
2022-04-13 13:41 ` [PATCH bpf-next v5 1/6] bpf: Use ipv6_only_sock in bpf_tcp_gen_syncookie Maxim Mikityanskiy
2022-04-13 13:41 ` [PATCH bpf-next v5 2/6] bpf: Fix documentation of th_len in bpf_tcp_{gen,check}_syncookie Maxim Mikityanskiy
2022-04-13 13:41 ` [PATCH bpf-next v5 3/6] bpf: Allow helpers to accept pointers with a fixed size Maxim Mikityanskiy
2022-04-13 13:41 ` [PATCH bpf-next v5 4/6] bpf: Add helpers to issue and check SYN cookies in XDP Maxim Mikityanskiy
2022-04-13 22:48   ` Daniel Borkmann
2022-04-22 17:23     ` Maxim Mikityanskiy [this message]
2022-04-13 13:41 ` [PATCH bpf-next v5 5/6] bpf: Add selftests for raw syncookie helpers Maxim Mikityanskiy
2022-04-13 13:41 ` [PATCH bpf-next v5 6/6] bpf: Allow the new syncookie helpers to work with SKBs Maxim Mikityanskiy

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=87ad8351-6c2d-39ec-7b72-1cf273bbaa72@nvidia.com \
    --to=maximmi@nvidia.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=fw@strlen.de \
    --cc=hawk@kernel.org \
    --cc=joe@cilium.io \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=lmb@cloudflare.com \
    --cc=memxor@gmail.com \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=ppenkov@google.com \
    --cc=revest@chromium.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=tariqt@nvidia.com \
    --cc=toke@toke.dk \
    --cc=yhs@fb.com \
    --cc=yoshfuji@linux-ipv6.org \
    /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