All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: Willem de Bruijn <willemb@google.com>,
	Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	David Miller <davem@davemloft.net>, Shuah Khan <shuah@kernel.org>,
	Martin KaFai Lau <kafai@fb.com>,
	songliubraving@fb.com, yhs@fb.com, quentin.monnet@netronome.com,
	John Fastabend <john.fastabend@gmail.com>,
	rdna@fb.com, linux-kselftest@vger.kernel.org,
	Network Development <netdev@vger.kernel.org>,
	bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next 2/4] bpf: add layer 2 encap support to bpf_skb_adjust_room
Date: Mon, 1 Apr 2019 13:30:16 -0400	[thread overview]
Message-ID: <CAF=yD-KRFNiRk24CVkNsJBkfw=im8J67J5jCe2gkM28BXs_zSw@mail.gmail.com> (raw)
In-Reply-To: <1554132731-3095-3-git-send-email-alan.maguire@oracle.com>

On Mon, Apr 1, 2019 at 11:33 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> In
>
> commit 868d523535c2 ("bpf: add bpf_skb_adjust_room encap flags")
>
> ...Willem introduced support to bpf_skb_adjust_room for GSO-friendly
> GRE and UDP encapsulation.
>
> For GSO to work for skbs, the inner headers (mac and network) need to
> be marked.  For L3 encapsulation using bpf_skb_adjust_room, the mac
> and network headers are identical.  Here we provide a way of specifying
> the inner mac header length for cases where L2 encap is desired.  Such
> an approach can support encapsulated ethernet headers, MPLS headers etc.
> For example to convert from a packet of form [eth][ip][tcp] to
> [eth][ip][udp][inner mac][ip][tcp], something like the following could
> be done:
>
>         headroom = sizeof(iph) + sizeof(struct udphdr) + inner_maclen;
>
>         ret = bpf_skb_adjust_room(skb, headroom, BPF_ADJ_ROOM_MAC,
>                                   BPF_F_ADJ_ROOM_ENCAP_L4_UDP |
>                                   BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 |
>                                   BPF_F_ADJ_ROOM_ENCAP_L2(inner_maclen));
>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---

> +#define        BPF_F_ADJ_ROOM_ENCAP_L2(len)    (((__u64)len & 0xff) << 56)

Here ..

>
>  /* Mode for BPF_FUNC_skb_adjust_room helper. */
>  enum bpf_adj_room_mode {
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 22eb2ed..02ae8c0 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2969,14 +2969,16 @@ static u32 bpf_skb_net_base_len(const struct sk_buff *skb)
>  #define BPF_F_ADJ_ROOM_MASK            (BPF_F_ADJ_ROOM_FIXED_GSO | \
>                                          BPF_F_ADJ_ROOM_ENCAP_L3_MASK | \
>                                          BPF_F_ADJ_ROOM_ENCAP_L4_GRE | \
> -                                        BPF_F_ADJ_ROOM_ENCAP_L4_UDP)
> +                                        BPF_F_ADJ_ROOM_ENCAP_L4_UDP | \
> +                                        BPF_F_ADJ_ROOM_ENCAP_L2(0xff))

.. and here ..
>
>  static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
>                             u64 flags)
>  {
> +       u16 mac_len = 0, inner_mac = 0, inner_net = 0, inner_trans = 0;
>         bool encap = flags & BPF_F_ADJ_ROOM_ENCAP_L3_MASK;
> -       u16 mac_len = 0, inner_net = 0, inner_trans = 0;
>         unsigned int gso_type = SKB_GSO_DODGY;
> +       u8 inner_mac_len = flags >> 56;

.. and here: please do not use hardcoded constants. Define explicit
constant integers or macros for readability and consistency.

>         int ret;
>
>         if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) {
> @@ -3003,11 +3005,19 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
>                     flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP)
>                         return -EINVAL;
>
> +               if (flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP &&
> +                   flags & BPF_F_ADJ_ROOM_FIXED_GSO &&
> +                   inner_mac_len > 0)
> +                       return -EINVAL;
> +

Why is UDP encap with inner MAC (or MPLS) not allowed with fixed GSO?

WARNING: multiple messages have this Message-ID (diff)
From: willemdebruijn.kernel at gmail.com (Willem de Bruijn)
Subject: [PATCH bpf-next 2/4] bpf: add layer 2 encap support to bpf_skb_adjust_room
Date: Mon, 1 Apr 2019 13:30:16 -0400	[thread overview]
Message-ID: <CAF=yD-KRFNiRk24CVkNsJBkfw=im8J67J5jCe2gkM28BXs_zSw@mail.gmail.com> (raw)
In-Reply-To: <1554132731-3095-3-git-send-email-alan.maguire@oracle.com>

On Mon, Apr 1, 2019 at 11:33 AM Alan Maguire <alan.maguire at oracle.com> wrote:
>
> In
>
> commit 868d523535c2 ("bpf: add bpf_skb_adjust_room encap flags")
>
> ...Willem introduced support to bpf_skb_adjust_room for GSO-friendly
> GRE and UDP encapsulation.
>
> For GSO to work for skbs, the inner headers (mac and network) need to
> be marked.  For L3 encapsulation using bpf_skb_adjust_room, the mac
> and network headers are identical.  Here we provide a way of specifying
> the inner mac header length for cases where L2 encap is desired.  Such
> an approach can support encapsulated ethernet headers, MPLS headers etc.
> For example to convert from a packet of form [eth][ip][tcp] to
> [eth][ip][udp][inner mac][ip][tcp], something like the following could
> be done:
>
>         headroom = sizeof(iph) + sizeof(struct udphdr) + inner_maclen;
>
>         ret = bpf_skb_adjust_room(skb, headroom, BPF_ADJ_ROOM_MAC,
>                                   BPF_F_ADJ_ROOM_ENCAP_L4_UDP |
>                                   BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 |
>                                   BPF_F_ADJ_ROOM_ENCAP_L2(inner_maclen));
>
> Signed-off-by: Alan Maguire <alan.maguire at oracle.com>
> ---

> +#define        BPF_F_ADJ_ROOM_ENCAP_L2(len)    (((__u64)len & 0xff) << 56)

Here ..

>
>  /* Mode for BPF_FUNC_skb_adjust_room helper. */
>  enum bpf_adj_room_mode {
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 22eb2ed..02ae8c0 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2969,14 +2969,16 @@ static u32 bpf_skb_net_base_len(const struct sk_buff *skb)
>  #define BPF_F_ADJ_ROOM_MASK            (BPF_F_ADJ_ROOM_FIXED_GSO | \
>                                          BPF_F_ADJ_ROOM_ENCAP_L3_MASK | \
>                                          BPF_F_ADJ_ROOM_ENCAP_L4_GRE | \
> -                                        BPF_F_ADJ_ROOM_ENCAP_L4_UDP)
> +                                        BPF_F_ADJ_ROOM_ENCAP_L4_UDP | \
> +                                        BPF_F_ADJ_ROOM_ENCAP_L2(0xff))

.. and here ..
>
>  static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
>                             u64 flags)
>  {
> +       u16 mac_len = 0, inner_mac = 0, inner_net = 0, inner_trans = 0;
>         bool encap = flags & BPF_F_ADJ_ROOM_ENCAP_L3_MASK;
> -       u16 mac_len = 0, inner_net = 0, inner_trans = 0;
>         unsigned int gso_type = SKB_GSO_DODGY;
> +       u8 inner_mac_len = flags >> 56;

.. and here: please do not use hardcoded constants. Define explicit
constant integers or macros for readability and consistency.

>         int ret;
>
>         if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) {
> @@ -3003,11 +3005,19 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
>                     flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP)
>                         return -EINVAL;
>
> +               if (flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP &&
> +                   flags & BPF_F_ADJ_ROOM_FIXED_GSO &&
> +                   inner_mac_len > 0)
> +                       return -EINVAL;
> +

Why is UDP encap with inner MAC (or MPLS) not allowed with fixed GSO?

WARNING: multiple messages have this Message-ID (diff)
From: willemdebruijn.kernel@gmail.com (Willem de Bruijn)
Subject: [PATCH bpf-next 2/4] bpf: add layer 2 encap support to bpf_skb_adjust_room
Date: Mon, 1 Apr 2019 13:30:16 -0400	[thread overview]
Message-ID: <CAF=yD-KRFNiRk24CVkNsJBkfw=im8J67J5jCe2gkM28BXs_zSw@mail.gmail.com> (raw)
Message-ID: <20190401173016.I1UvPHYHhlxeZtHRNXvaEm3CaVSpqvd1juBRrHgoFx8@z> (raw)
In-Reply-To: <1554132731-3095-3-git-send-email-alan.maguire@oracle.com>

On Mon, Apr 1, 2019@11:33 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> In
>
> commit 868d523535c2 ("bpf: add bpf_skb_adjust_room encap flags")
>
> ...Willem introduced support to bpf_skb_adjust_room for GSO-friendly
> GRE and UDP encapsulation.
>
> For GSO to work for skbs, the inner headers (mac and network) need to
> be marked.  For L3 encapsulation using bpf_skb_adjust_room, the mac
> and network headers are identical.  Here we provide a way of specifying
> the inner mac header length for cases where L2 encap is desired.  Such
> an approach can support encapsulated ethernet headers, MPLS headers etc.
> For example to convert from a packet of form [eth][ip][tcp] to
> [eth][ip][udp][inner mac][ip][tcp], something like the following could
> be done:
>
>         headroom = sizeof(iph) + sizeof(struct udphdr) + inner_maclen;
>
>         ret = bpf_skb_adjust_room(skb, headroom, BPF_ADJ_ROOM_MAC,
>                                   BPF_F_ADJ_ROOM_ENCAP_L4_UDP |
>                                   BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 |
>                                   BPF_F_ADJ_ROOM_ENCAP_L2(inner_maclen));
>
> Signed-off-by: Alan Maguire <alan.maguire at oracle.com>
> ---

> +#define        BPF_F_ADJ_ROOM_ENCAP_L2(len)    (((__u64)len & 0xff) << 56)

Here ..

>
>  /* Mode for BPF_FUNC_skb_adjust_room helper. */
>  enum bpf_adj_room_mode {
> diff --git a/net/core/filter.c b/net/core/filter.c
> index 22eb2ed..02ae8c0 100644
> --- a/net/core/filter.c
> +++ b/net/core/filter.c
> @@ -2969,14 +2969,16 @@ static u32 bpf_skb_net_base_len(const struct sk_buff *skb)
>  #define BPF_F_ADJ_ROOM_MASK            (BPF_F_ADJ_ROOM_FIXED_GSO | \
>                                          BPF_F_ADJ_ROOM_ENCAP_L3_MASK | \
>                                          BPF_F_ADJ_ROOM_ENCAP_L4_GRE | \
> -                                        BPF_F_ADJ_ROOM_ENCAP_L4_UDP)
> +                                        BPF_F_ADJ_ROOM_ENCAP_L4_UDP | \
> +                                        BPF_F_ADJ_ROOM_ENCAP_L2(0xff))

.. and here ..
>
>  static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
>                             u64 flags)
>  {
> +       u16 mac_len = 0, inner_mac = 0, inner_net = 0, inner_trans = 0;
>         bool encap = flags & BPF_F_ADJ_ROOM_ENCAP_L3_MASK;
> -       u16 mac_len = 0, inner_net = 0, inner_trans = 0;
>         unsigned int gso_type = SKB_GSO_DODGY;
> +       u8 inner_mac_len = flags >> 56;

.. and here: please do not use hardcoded constants. Define explicit
constant integers or macros for readability and consistency.

>         int ret;
>
>         if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) {
> @@ -3003,11 +3005,19 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 off, u32 len_diff,
>                     flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP)
>                         return -EINVAL;
>
> +               if (flags & BPF_F_ADJ_ROOM_ENCAP_L4_UDP &&
> +                   flags & BPF_F_ADJ_ROOM_FIXED_GSO &&
> +                   inner_mac_len > 0)
> +                       return -EINVAL;
> +

Why is UDP encap with inner MAC (or MPLS) not allowed with fixed GSO?

  reply	other threads:[~2019-04-01 17:48 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01 15:32 [PATCH bpf-next 0/4] L2 encap support for bpf_skb_adjust_room Alan Maguire
2019-04-01 15:32 ` Alan Maguire
2019-04-01 15:32 ` alan.maguire
2019-04-01 15:32 ` [PATCH bpf-next 1/4] selftests_bpf: extend test_tc_tunnel for UDP encap Alan Maguire
2019-04-01 15:32   ` Alan Maguire
2019-04-01 15:32   ` alan.maguire
2019-04-01 17:26   ` Willem de Bruijn
2019-04-01 17:26     ` Willem de Bruijn
2019-04-01 17:26     ` willemdebruijn.kernel
2019-04-01 15:32 ` [PATCH bpf-next 2/4] bpf: add layer 2 encap support to bpf_skb_adjust_room Alan Maguire
2019-04-01 15:32   ` Alan Maguire
2019-04-01 15:32   ` alan.maguire
2019-04-01 17:30   ` Willem de Bruijn [this message]
2019-04-01 17:30     ` Willem de Bruijn
2019-04-01 17:30     ` willemdebruijn.kernel
2019-04-01 15:32 ` [PATCH bpf-next 3/4] bpf: sync bpf.h to tools/ for BPF_F_ADJ_ROOM_ENCAP_L2 Alan Maguire
2019-04-01 15:32   ` Alan Maguire
2019-04-01 15:32   ` alan.maguire
2019-04-01 15:32 ` [PATCH bpf-next 4/4] selftests_bpf: extend test_tc_tunnel.sh test for L2 encap Alan Maguire
2019-04-01 15:32   ` Alan Maguire
2019-04-01 15:32   ` alan.maguire
2019-04-01 17:45   ` Willem de Bruijn
2019-04-01 17:45     ` Willem de Bruijn
2019-04-01 17:45     ` willemdebruijn.kernel
2019-04-01 17:23 ` [PATCH bpf-next 0/4] L2 encap support for bpf_skb_adjust_room Willem de Bruijn
2019-04-01 17:23   ` Willem de Bruijn
2019-04-01 17:23   ` willemdebruijn.kernel
2019-04-01 17:47 ` Willem de Bruijn
2019-04-01 17:47   ` Willem de Bruijn
2019-04-01 17:47   ` willemdebruijn.kernel

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='CAF=yD-KRFNiRk24CVkNsJBkfw=im8J67J5jCe2gkM28BXs_zSw@mail.gmail.com' \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=alan.maguire@oracle.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=quentin.monnet@netronome.com \
    --cc=rdna@fb.com \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.com \
    --cc=willemb@google.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.