From: John Fastabend <john.fastabend@gmail.com>
To: Shmulik Ladkani <shmulik@metanetworks.com>,
bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
John Fastabend <john.fastabend@gmail.com>,
Joanne Koong <joannelkoong@gmail.com>
Cc: Andrii Nakryiko <andrii@kernel.org>,
Paul Chaignon <paul@isovalent.com>,
Shmulik Ladkani <shmulik.ladkani@gmail.com>
Subject: RE: [PATCH v5 bpf-next 4/4] selftests/bpf: Add geneve with bpf_skb_set_tunnel_opt_dynptr test-case to test_progs
Date: Thu, 25 Aug 2022 09:33:39 -0700 [thread overview]
Message-ID: <6307a4631c9a5_12460b20842@john.notmuch> (raw)
In-Reply-To: <20220824044117.137658-5-shmulik.ladkani@gmail.com>
Shmulik Ladkani wrote:
> Add geneve test to test_tunnel. The test setup and scheme resembles the
> existing vxlan test.
>
> The test also checks variable length tunnel option assignment using
> bpf_skb_set_tunnel_opt_dynptr.
>
> Signed-off-by: Shmulik Ladkani <shmulik.ladkani@gmail.com>
> ---
> .../selftests/bpf/prog_tests/test_tunnel.c | 108 ++++++++++++++
> .../selftests/bpf/progs/test_tunnel_kern.c | 136 ++++++++++++++++++
> 2 files changed, 244 insertions(+)
Overall lgtm couple missing ret codes.
[...]
> +
> +SEC("tc")
> +int geneve_set_tunnel_src(struct __sk_buff *skb)
> +{
> + int ret;
> + struct bpf_tunnel_key key;
> + __u32 index = 0;
> + __u32 *local_ip = NULL;
> +
> + local_ip = bpf_map_lookup_elem(&local_ip_map, &index);
> + if (!local_ip) {
> + log_err(ret);
log_err(-1)?
> + return TC_ACT_SHOT;
> + }
> +
> + __builtin_memset(&key, 0x0, sizeof(key));
> + key.local_ipv4 = *local_ip;
> + 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) {
> + log_err(ret);
> + return TC_ACT_SHOT;
> + }
> +
> + return TC_ACT_OK;
> +}
> +
> +SEC("tc")
> +int geneve_get_tunnel_src(struct __sk_buff *skb)
> +{
> + int ret;
> + struct bpf_tunnel_key key;
> + struct tun_opts_raw opts;
> + int expected_opts_len;
> + __u32 index = 0;
> + __u32 *local_ip = NULL;
> +
> + local_ip = bpf_map_lookup_elem(&local_ip_map, &index);
> + if (!local_ip) {
> + log_err(ret);
log_err(-1)
> + return TC_ACT_SHOT;
> + }
> +
> + ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
> + if (ret < 0) {
> + log_err(ret);
> + return TC_ACT_SHOT;
> + }
> +
> + ret = bpf_skb_get_tunnel_opt(skb, &opts, sizeof(opts));
> + if (ret < 0) {
> + log_err(ret);
> + return TC_ACT_SHOT;
> + }
> +
> + expected_opts_len = (skb->len % sizeof(opts)) & ~(sizeof(__u32) - 1);
> + if (key.local_ipv4 != *local_ip || ret != expected_opts_len) {
> + bpf_printk("geneve key %d local ip 0x%x remote ip 0x%x opts_len %d\n",
> + key.tunnel_id, key.local_ipv4,
> + key.remote_ipv4, ret);
In general I don't really like the printks. But ok.
> + bpf_printk("local_ip 0x%x\n", *local_ip);
> + log_err(ret);
> + return TC_ACT_SHOT;
> + }
> +
> + return TC_ACT_OK;
> +}
> +
> SEC("tc")
> int vxlan_set_tunnel_dst(struct __sk_buff *skb)
> {
> --
> 2.37.2
>
prev parent reply other threads:[~2022-08-25 16:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-24 4:41 [PATCH v5 bpf-next 0/4] bpf: Support setting variable-length tunnel options Shmulik Ladkani
2022-08-24 4:41 ` [PATCH v5 bpf-next 1/4] bpf: Add 'bpf_dynptr_get_data' helper Shmulik Ladkani
2022-08-25 16:14 ` John Fastabend
2022-08-30 16:57 ` Shmulik Ladkani
2022-08-24 4:41 ` [PATCH v5 bpf-next 2/4] bpf: Support setting variable-length tunnel options Shmulik Ladkani
2022-08-25 18:20 ` Andrii Nakryiko
2022-08-30 20:02 ` Shmulik Ladkani
2022-08-30 20:13 ` Shmulik Ladkani
2022-08-30 23:35 ` Joanne Koong
2022-08-24 4:41 ` [PATCH v5 bpf-next 3/4] selftests/bpf: Simplify test_tunnel setup for allowing non-local tunnel traffic Shmulik Ladkani
2022-08-24 4:41 ` [PATCH v5 bpf-next 4/4] selftests/bpf: Add geneve with bpf_skb_set_tunnel_opt_dynptr test-case to test_progs Shmulik Ladkani
2022-08-25 16:33 ` John Fastabend [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=6307a4631c9a5_12460b20842@john.notmuch \
--to=john.fastabend@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=joannelkoong@gmail.com \
--cc=paul@isovalent.com \
--cc=shmulik.ladkani@gmail.com \
--cc=shmulik@metanetworks.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