LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Pravin Shelar <pravin.ovn@gmail.com>
To: Cpp Code <cpp.code.lv@gmail.com>
Cc: Linux Kernel Network Developers <netdev@vger.kernel.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>, ovs dev <dev@openvswitch.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net-next v8] net: openvswitch: IPv6: Add IPv6 extension header support
Date: Thu, 9 Dec 2021 23:36:09 -0800	[thread overview]
Message-ID: <CAOrHB_CyBoTYO8Qn-qtcfrbqfVc9TjaU6ib_2ZSQx-R9ns-bUQ@mail.gmail.com> (raw)
In-Reply-To: <CAASuNyUKj+dsf++7mhdkjm2mabQggYW4x42_BV=y+VPPSBFqfA@mail.gmail.com>

()

On Mon, Dec 6, 2021 at 3:00 PM Cpp Code <cpp.code.lv@gmail.com> wrote:
>
> On Thu, Dec 2, 2021 at 9:28 PM Pravin Shelar <pravin.ovn@gmail.com> wrote:
> >
> > On Thu, Dec 2, 2021 at 12:20 PM Cpp Code <cpp.code.lv@gmail.com> wrote:
> > >
> > > On Wed, Dec 1, 2021 at 11:34 PM Pravin Shelar <pravin.ovn@gmail.com> wrote:
> > > >
> > > > On Wed, Nov 24, 2021 at 11:33 AM Toms Atteka <cpp.code.lv@gmail.com> wrote:
> > > > >
> > > > > This change adds a new OpenFlow field OFPXMT_OFB_IPV6_EXTHDR and
> > > > > packets can be filtered using ipv6_ext flag.
> > > > >
> > > > > Signed-off-by: Toms Atteka <cpp.code.lv@gmail.com>
> > > > > ---
> > > > >  include/uapi/linux/openvswitch.h |   6 ++
> > > > >  net/openvswitch/flow.c           | 140 +++++++++++++++++++++++++++++++
> > > > >  net/openvswitch/flow.h           |  14 ++++
> > > > >  net/openvswitch/flow_netlink.c   |  26 +++++-
> > > > >  4 files changed, 184 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h
> > > > > index a87b44cd5590..43790f07e4a2 100644
> > > > > --- a/include/uapi/linux/openvswitch.h
> > > > > +++ b/include/uapi/linux/openvswitch.h
> > > > > @@ -342,6 +342,7 @@ enum ovs_key_attr {
> > > > >         OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV4,   /* struct ovs_key_ct_tuple_ipv4 */
> > > > >         OVS_KEY_ATTR_CT_ORIG_TUPLE_IPV6,   /* struct ovs_key_ct_tuple_ipv6 */
> > > > >         OVS_KEY_ATTR_NSH,       /* Nested set of ovs_nsh_key_* */
> > > > > +       OVS_KEY_ATTR_IPV6_EXTHDRS,  /* struct ovs_key_ipv6_exthdr */
> > > > >
> > > > >  #ifdef __KERNEL__
> > > > >         OVS_KEY_ATTR_TUNNEL_INFO,  /* struct ip_tunnel_info */
> > > > > @@ -421,6 +422,11 @@ struct ovs_key_ipv6 {
> > > > >         __u8   ipv6_frag;       /* One of OVS_FRAG_TYPE_*. */
> > > > >  };
> > > > >
> > > > > +/* separate structure to support backward compatibility with older user space */
> > > > > +struct ovs_key_ipv6_exthdrs {
> > > > > +       __u16  hdrs;
> > > > > +};
> > > > > +
> > > > >  struct ovs_key_tcp {
> > > > >         __be16 tcp_src;
> > > > >         __be16 tcp_dst;
> > > > > diff --git a/net/openvswitch/flow.c b/net/openvswitch/flow.c
> > > > > index 9d375e74b607..28acb40437ca 100644
> > > > > --- a/net/openvswitch/flow.c
> > > > > +++ b/net/openvswitch/flow.c
> > > > > @@ -239,6 +239,144 @@ static bool icmphdr_ok(struct sk_buff *skb)
> > > > >                                   sizeof(struct icmphdr));
> > > > >  }
> > > > >
> > > > > +/**
> > > > > + * get_ipv6_ext_hdrs() - Parses packet and sets IPv6 extension header flags.
> > > > > + *
> > > > > + * @skb: buffer where extension header data starts in packet
> > > > > + * @nh: ipv6 header
> > > > > + * @ext_hdrs: flags are stored here
> > > > > + *
> > > > > + * OFPIEH12_UNREP is set if more than one of a given IPv6 extension header
> > > > > + * is unexpectedly encountered. (Two destination options headers may be
> > > > > + * expected and would not cause this bit to be set.)
> > > > > + *
> > > > > + * OFPIEH12_UNSEQ is set if IPv6 extension headers were not in the order
> > > > > + * preferred (but not required) by RFC 2460:
> > > > > + *
> > > > > + * When more than one extension header is used in the same packet, it is
> > > > > + * recommended that those headers appear in the following order:
> > > > > + *      IPv6 header
> > > > > + *      Hop-by-Hop Options header
> > > > > + *      Destination Options header
> > > > > + *      Routing header
> > > > > + *      Fragment header
> > > > > + *      Authentication header
> > > > > + *      Encapsulating Security Payload header
> > > > > + *      Destination Options header
> > > > > + *      upper-layer header
> > > > > + */
> > > > > +static void get_ipv6_ext_hdrs(struct sk_buff *skb, struct ipv6hdr *nh,
> > > > > +                             u16 *ext_hdrs)
> > > > > +{
> > > > > +       u8 next_type = nh->nexthdr;
> > > > > +       unsigned int start = skb_network_offset(skb) + sizeof(struct ipv6hdr);
> > > > > +       int dest_options_header_count = 0;
> > > > > +
> > > > > +       *ext_hdrs = 0;
> > > > > +
> > > > > +       while (ipv6_ext_hdr(next_type)) {
> > > > > +               struct ipv6_opt_hdr _hdr, *hp;
> > > > > +
> > > > > +               switch (next_type) {
> > > > > +               case IPPROTO_NONE:
> > > > > +                       *ext_hdrs |= OFPIEH12_NONEXT;
> > > > > +                       /* stop parsing */
> > > > > +                       return;
> > > > > +
> > > > > +               case IPPROTO_ESP:
> > > > > +                       if (*ext_hdrs & OFPIEH12_ESP)
> > > > > +                               *ext_hdrs |= OFPIEH12_UNREP;
> > > > > +                       if ((*ext_hdrs & ~(OFPIEH12_HOP | OFPIEH12_DEST |
> > > > > +                                          OFPIEH12_ROUTER | IPPROTO_FRAGMENT |
> > > > > +                                          OFPIEH12_AUTH | OFPIEH12_UNREP)) ||
> > > > > +                           dest_options_header_count >= 2) {
> > > > > +                               *ext_hdrs |= OFPIEH12_UNSEQ;
> > > > > +                       }
> > > > > +                       *ext_hdrs |= OFPIEH12_ESP;
> > > > > +                       break;
> > > > you need to check_header() before looking into each extension header.
> > >
> > > Could you elaborate why I need to add check_header(),
> > > skb_header_pointer() is doing sanitization.
> >
> > I mean check_header() would allow you to read the header without
> > copying the bits, it is used in ovs flow extraction so its usual
> > check.
>
> But check_header() will call *__pskb_pull_tail which in turn will copy
> bits if data will be fragmented.
>
OVS flow extract uses this function to extract flow upto L4, so
skb_header_pointer() is not saving any copy operation.

> /* Moves tail of skb head forward, copying data from fragmented part,
>  * when it is necessary.
>  * 1. It may fail due to malloc failure.
>  * 2. It may change skb pointers.
>  *
>  * It is pretty complicated. Luckily, it is called only in exceptional cases.
>  */
> void *__pskb_pull_tail(struct sk_buff *skb, int delta)
>
> as well I noticed that for example commit
> 4a06fa67c4da20148803525151845276cdb995c1 is moving from
> pskb_may_pull() to skb_header_pointer()
ok, I see advantage of using skb_header_pointer() in this case, but
replacing all check_header() with skb_header_pointer() would add lot
of copy operation in flow extract. Anyways for this use case
skb_header_pointer() is fine.

Acked-by: Pravin B Shelar <pshelar@ovn.org>

  reply	other threads:[~2021-12-10  7:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-24 19:33 Toms Atteka
2021-12-02  7:33 ` Pravin Shelar
2021-12-02 20:20   ` Cpp Code
2021-12-03  5:28     ` Pravin Shelar
2021-12-06 23:00       ` Cpp Code
2021-12-10  7:36         ` Pravin Shelar [this message]
2022-02-09 20:46           ` Cpp Code
2022-02-10  0:58             ` Jakub Kicinski
  -- strict thread matches above, loose matches on Subject: below --
2022-02-24  0:54 Toms Atteka
2022-02-25 10:40 ` patchwork-bot+netdevbpf
2021-10-29 18:20 Toms Atteka
2021-11-02 18:39 ` Jakub Kicinski

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=CAOrHB_CyBoTYO8Qn-qtcfrbqfVc9TjaU6ib_2ZSQx-R9ns-bUQ@mail.gmail.com \
    --to=pravin.ovn@gmail.com \
    --cc=cpp.code.lv@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --subject='Re: [PATCH net-next v8] net: openvswitch: IPv6: Add IPv6 extension header support' \
    /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

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).