bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: 范开喜 <fankaixi.li@bytedance.com>
To: Yonghong Song <yhs@fb.com>
Cc: kafai@fb.com, songliubraving@fb.com, john.fastabend@gmail.com,
	kpsingh@kernel.org, bpf@vger.kernel.org, shuah@kernel.org,
	ast@kernel.org, andrii@kernel.org
Subject: Re: [External] [PATCH bpf-next v2 2/3] selftests/bpf: add ipv4 vxlan tunnel source testcase
Date: Sun, 27 Mar 2022 01:04:58 +0800	[thread overview]
Message-ID: <CAEEdnKEF=EfiXsQX7HgPbj2Fz2Un2km1nb=SgK8uNNYxsP05cw@mail.gmail.com> (raw)
In-Reply-To: <1e206112-c610-d4e5-1ab6-e78ea3e2dcea@fb.com>

Yonghong Song <yhs@fb.com> 于2022年3月26日周六 00:41写道:
>
>
>
> On 3/22/22 8:42 AM, fankaixi.li@bytedance.com wrote:
> > From: "kaixi.fan" <fankaixi.li@bytedance.com>
> >
> > Vxlan tunnel is chosen to test bpf code could configure tunnel
> > source ipv4 address.
>
> The added test configures tunnel source ipv4 address.
>
>  >It's sufficient to prove that other types
> > tunnels could also do it.
>
> Could you be more specific what other types will also use source ipv4
> address. It is too vague to claim "it's sufficient to prove ...".
>

Is it better to add more test cases for other types of ip tunnels ? It would
introduce more duplicate codes.

In the kernel, this is referred to as collect metadata mode as follows:
https://man7.org/linux/man-pages/man8/ip-link.8.html
Kernel use "struct ip_tunnel_info" to save tunnel parameters, and use
it for tunnel encapsulation. The process is similar for vxlan, gre,/gretap,
geneve, ipip and erspan tunnels.
The previous test cases in "test_tunnel.sh" test this mechanism for bpf
program code already.  Based on this mechanism, I just use vxlan tunnel
to test tunnel source ip configuration.

>
> > In the vxlan tunnel testcase, two underlay ipv4 addresses
> > are configured on veth device in root namespace. Test bpf kernel
> > code would configure the secondary ipv4 address as the tunnel
> > source ip.
> >
> > Signed-off-by: kaixi.fan <fankaixi.li@bytedance.com>
>
> Again, please use proper name in Signed-off-by tag.

Thanks. I will fix it.

>
> > ---
> >   .../selftests/bpf/progs/test_tunnel_kern.c    | 64 +++++++++++++++++++
> >   tools/testing/selftests/bpf/test_tunnel.sh    | 37 ++++++++++-
> >   2 files changed, 99 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> > index ef0dde83b85a..ab635c55ae9b 100644
> > --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> > +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c
> > @@ -676,4 +676,68 @@ int _xfrm_get_state(struct __sk_buff *skb)
> >       return TC_ACT_OK;
> >   }
> >
> > +SEC("vxlan_set_tunnel_src")
> > +int _vxlan_set_tunnel_src(struct __sk_buff *skb)
> > +{
> > +     int ret;
> > +     struct bpf_tunnel_key key;
> > +     struct vxlan_metadata md;
> > +
> > +     __builtin_memset(&key, 0x0, sizeof(key));
> > +     key.local_ipv4 = 0xac100114; /* 172.16.1.20 */
> > +     key.remote_ipv4 = 0xac100164; /* 172.16.1.100 */
> > +     key.tunnel_id = 2;
> > +     key.tunnel_tos = 0;
> > +     key.tunnel_ttl = 64;
> > +
> > +     ret = bpf_skb_set_tunnel_key(skb, &key, sizeof(key),
> > +                                  BPF_F_ZERO_CSUM_TX);
> > +     if (ret < 0) {
> > +             ERROR(ret);
> > +             return TC_ACT_SHOT;
> > +     }
> > +
> > +     md.gbp = 0x800FF; /* Set VXLAN Group Policy extension */
> > +     ret = bpf_skb_set_tunnel_opt(skb, &md, sizeof(md));
> > +     if (ret < 0) {
> > +             ERROR(ret);
> > +             return TC_ACT_SHOT;
> > +     }
> > +
> > +     return TC_ACT_OK;
> > +}
> > +
> > +SEC("vxlan_get_tunnel_src")
> > +int _vxlan_get_tunnel_src(struct __sk_buff *skb)
> > +{
> > +     int ret;
> > +     struct bpf_tunnel_key key;
> > +     struct vxlan_metadata md;
> > +     char fmt[] = "key %d remote ip 0x%x source ip 0x%x\n";
> > +     char fmt2[] = "vxlan gbp 0x%x\n";
> > +
> > +     ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
> > +     if (ret < 0) {
> > +             ERROR(ret);
> > +             return TC_ACT_SHOT;
> > +     }
> > +
> > +     ret = bpf_skb_get_tunnel_opt(skb, &md, sizeof(md));
> > +     if (ret < 0) {
> > +             ERROR(ret);
> > +             return TC_ACT_SHOT;
> > +     }
> > +
> > +     bpf_trace_printk(fmt, sizeof(fmt),
> > +                      key.tunnel_id, key.remote_ipv4, key.local_ipv4);
> > +     bpf_trace_printk(fmt2, sizeof(fmt2),
>
> In bpf_helpers.h, bpf_printk can be used instead of bpf_trace_printk.
>
> > +                      md.gbp);
> > +
> > +     if (key.local_ipv4 != 0xac100114) {
>
> I would suggest to make 0xac100114 a macro, so both set_* and get_*
> programs can use the same macro, which makes it easier to understand
> and check.

OK. I will replace it with a macro.

>
> > +             ERROR(ret);
> > +             return TC_ACT_SHOT;
> > +     }
> > +     return TC_ACT_OK;
> > +}
> > +
> [...]

  reply	other threads:[~2022-03-26 17:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-22 15:42 [External] [PATCH bpf-next v2 0/3] bpf: Add support to set and get fankaixi.li
2022-03-22 15:42 ` [External] [PATCH bpf-next v2 1/3] bpf: Add source ip in "struct bpf_tunnel_key" fankaixi.li
2022-03-25 16:26   ` Yonghong Song
2022-03-22 15:42 ` [External] [PATCH bpf-next v2 2/3] selftests/bpf: add ipv4 vxlan tunnel source testcase fankaixi.li
2022-03-25 16:41   ` Yonghong Song
2022-03-26 17:04     ` 范开喜 [this message]
2022-03-28 23:10       ` Yonghong Song
2022-03-29  2:02         ` 范开喜
2022-03-22 15:42 ` [External] [PATCH bpf-next v2 3/3] selftests/bpf: add ipv6 " fankaixi.li
2022-03-24 19:37   ` Martin KaFai Lau
2022-03-26 17:24     ` 范开喜
2022-04-06  8:03       ` 范开喜
2022-04-07 17:53         ` Martin KaFai Lau
2022-04-08 13:56           ` 范开喜
2022-04-15 23:11           ` Peilin Ye
2022-04-20 17:09             ` Andrii Nakryiko
2022-04-20 17:54               ` Peilin Ye
2022-04-21 11:27                 ` 范开喜
2022-03-25 16:45   ` Yonghong Song
2022-03-25 16:46 ` [External] [PATCH bpf-next v2 0/3] bpf: Add support to set and get Yonghong Song
2022-03-26 17:06   ` 范开喜

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='CAEEdnKEF=EfiXsQX7HgPbj2Fz2Un2km1nb=SgK8uNNYxsP05cw@mail.gmail.com' \
    --to=fankaixi.li@bytedance.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@kernel.org \
    --cc=shuah@kernel.org \
    --cc=songliubraving@fb.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 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).