mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Xuesen Huang <hxseverything@gmail.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
	David Miller <davem@davemloft.net>, bpf <bpf@vger.kernel.org>,
	Network Development <netdev@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Li Wang <wangli09@kuaishou.com>
Subject: Re: [PATCH] selftests_bpf: extend test_tc_tunnel test with vxlan
Date: Fri, 5 Mar 2021 20:20:41 +0800	[thread overview]
Message-ID: <9789D5AA-5B93-4045-9818-B1E84C01A16C@gmail.com> (raw)
In-Reply-To: <CA+FuTSfj2u5pEbKJR_m0qCiPfdhCVS_BZVPPO=dNjAyL7HG7FQ@mail.gmail.com>



> 2021年3月4日 下午10:02,Willem de Bruijn <willemdebruijn.kernel@gmail.com> 写道:
> 
> On Thu, Mar 4, 2021 at 1:42 AM Xuesen Huang <hxseverything@gmail.com> wrote:
>> 
>> From: Xuesen Huang <huangxuesen@kuaishou.com>
>> 
>> Add BPF_F_ADJ_ROOM_ENCAP_L2_ETH flag to the existing tests which
>> encapsulates the ethernet as the inner l2 header.
>> 
>> Update a vxlan encapsulation test case.
>> 
>> Signed-off-by: Xuesen Huang <huangxuesen@kuaishou.com>
>> Signed-off-by: Li Wang <wangli09@kuaishou.com>
>> Signed-off-by: Willem de Bruijn <willemb@google.com>
> 
> Please mark patch target: [PATCH bpf-next]
> 
Thanks.

>> ---
>> tools/testing/selftests/bpf/progs/test_tc_tunnel.c | 113 ++++++++++++++++++---
>> tools/testing/selftests/bpf/test_tc_tunnel.sh      |  15 ++-
>> 2 files changed, 111 insertions(+), 17 deletions(-)
> 
> 
>> -static __always_inline int encap_ipv4(struct __sk_buff *skb, __u8 encap_proto,
>> -                                     __u16 l2_proto)
>> +static __always_inline int __encap_ipv4(struct __sk_buff *skb, __u8 encap_proto,
>> +                                       __u16 l2_proto, __u16 ext_proto)
>> {
>>        __u16 udp_dst = UDP_PORT;
>>        struct iphdr iph_inner;
>>        struct v4hdr h_outer;
>>        struct tcphdr tcph;
>>        int olen, l2_len;
>> +       __u8 *l2_hdr = NULL;
>>        int tcp_off;
>>        __u64 flags;
>> 
>> @@ -141,7 +157,11 @@ static __always_inline int encap_ipv4(struct __sk_buff *skb, __u8 encap_proto,
>>                break;
>>        case ETH_P_TEB:
>>                l2_len = ETH_HLEN;
>> -               udp_dst = ETH_OVER_UDP_PORT;
>> +               if (ext_proto & EXTPROTO_VXLAN) {
>> +                       udp_dst = VXLAN_UDP_PORT;
>> +                       l2_len += sizeof(struct vxlanhdr);
>> +               } else
>> +                       udp_dst = ETH_OVER_UDP_PORT;
>>                break;
>>        }
>>        flags |= BPF_F_ADJ_ROOM_ENCAP_L2(l2_len);
>> @@ -171,14 +191,26 @@ static __always_inline int encap_ipv4(struct __sk_buff *skb, __u8 encap_proto,
>>        }
>> 
>>        /* add L2 encap (if specified) */
>> +       l2_hdr = (__u8 *)&h_outer + olen;
>>        switch (l2_proto) {
>>        case ETH_P_MPLS_UC:
>> -               *((__u32 *)((__u8 *)&h_outer + olen)) = mpls_label;
>> +               *(__u32 *)l2_hdr = mpls_label;
>>                break;
>>        case ETH_P_TEB:
>> -               if (bpf_skb_load_bytes(skb, 0, (__u8 *)&h_outer + olen,
>> -                                      ETH_HLEN))
>> +               flags |= BPF_F_ADJ_ROOM_ENCAP_L2_ETH;
>> +
>> +               if (ext_proto & EXTPROTO_VXLAN) {
>> +                       struct vxlanhdr *vxlan_hdr = (struct vxlanhdr *)l2_hdr;
>> +
>> +                       vxlan_hdr->vx_flags = VXLAN_FLAGS;
>> +                       vxlan_hdr->vx_vni = bpf_htonl((VXLAN_VNI & VXLAN_VNI_MASK) << 8);
>> +
>> +                       l2_hdr += sizeof(struct vxlanhdr);
> 
> should this be l2_len? (here and ipv6 below)
> 
Should be l2_hdr. 

It’s a little tricky. l2_len has already been modified above. We use l2_hdr here 
to help us to find the address in h_outer to load original Ethernet header which 
is different in (eth) and (vxlan + eth).

>> +SEC("encap_vxlan_eth")
>> +int __encap_vxlan_eth(struct __sk_buff *skb)
>> +{
>> +       if (skb->protocol == __bpf_constant_htons(ETH_P_IP))
>> +               return __encap_ipv4(skb, IPPROTO_UDP,
>> +                               ETH_P_TEB,
>> +                               EXTPROTO_VXLAN);
> 
> non-standard indentation: align with the opening parenthesis. (here
> and ipv6 below)
Thanks.


      reply	other threads:[~2021-03-05 12:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04  6:42 Xuesen Huang
2021-03-04 14:02 ` Willem de Bruijn
2021-03-05 12:20   ` Xuesen Huang [this message]

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=9789D5AA-5B93-4045-9818-B1E84C01A16C@gmail.com \
    --to=hxseverything@gmail.com \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=wangli09@kuaishou.com \
    --cc=willemdebruijn.kernel@gmail.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

all inboxes | Powered by JetHome®