[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <1892a6ce-bbad-20af-20b4-cc23fb7a6206@linux.dev>
Date: Mon, 5 Dec 2022 23:13:12 -0800
From: Martin KaFai Lau <martin.lau@...ux.dev>
To: Eyal Birger <eyal.birger@...il.com>
Cc: netdev@...r.kernel.org, bpf@...r.kernel.org,
linux-kselftest@...r.kernel.org, davem@...emloft.net,
edumazet@...gle.com, kuba@...nel.org, pabeni@...hat.com,
steffen.klassert@...unet.com, herbert@...dor.apana.org.au,
andrii@...nel.org, daniel@...earbox.net, nicolas.dichtel@...nd.com,
razor@...ckwall.org, mykolal@...com, ast@...nel.org,
song@...nel.org, yhs@...com, john.fastabend@...il.com,
kpsingh@...nel.org, sdf@...gle.com, haoluo@...gle.com,
jolsa@...nel.org, shuah@...nel.org, liuhangbin@...il.com,
lixiaoyan@...gle.com, jtoppins@...hat.com, kuniyu@...zon.co.jp
Subject: Re: [PATCH bpf-next,v6 4/4] selftests/bpf: add xfrm_info tests
On 12/3/22 12:46 AM, Eyal Birger wrote:
> +#define PING_ARGS "-i 0.01 -c 3 -w 10 -q"
Applied with a few changes.
PING_ARGS is removed because it is unused.
[ ... ]
> +static int test_xfrm_ping(struct xfrm_info *skel, u32 if_id)
> +{
> + skel->bss->req_if_id = if_id;
> +
> + SYS("ping -i 0.01 -c 3 -w 10 -q 192.168.1.200 > /dev/null");
> +
> + if (!ASSERT_EQ(skel->bss->resp_if_id, if_id, "if_id"))
> + goto fail;
> +
> + return 0;
> +fail:
> + return -1;
> +}
> +
> +static void _test_xfrm_info(void)
> +{
> + LIBBPF_OPTS(bpf_tc_hook, tc_hook, .attach_point = BPF_TC_INGRESS);
> + int get_xfrm_info_prog_fd, set_xfrm_info_prog_fd;
> + struct xfrm_info *skel = NULL;
> + struct nstoken *nstoken = NULL;
> + int ifindex;
> +
> + /* load and attach bpf progs to ipsec dev tc hook point */
> + skel = xfrm_info__open_and_load();
> + if (!ASSERT_OK_PTR(skel, "xfrm_info__open_and_load"))
> + goto done;
> + nstoken = open_netns(NS0);
> + if (!ASSERT_OK_PTR(nstoken, "setns " NS0))
> + goto done;
> + ifindex = if_nametoindex("ipsec0");
> + if (!ASSERT_NEQ(ifindex, 0, "ipsec0 ifindex"))
> + goto done;
> + tc_hook.ifindex = ifindex;
> + set_xfrm_info_prog_fd = bpf_program__fd(skel->progs.set_xfrm_info);
> + get_xfrm_info_prog_fd = bpf_program__fd(skel->progs.get_xfrm_info);
> + if (!ASSERT_GE(set_xfrm_info_prog_fd, 0, "bpf_program__fd"))
> + goto done;
> + if (!ASSERT_GE(get_xfrm_info_prog_fd, 0, "bpf_program__fd"))
> + goto done;
> + if (attach_tc_prog(&tc_hook, get_xfrm_info_prog_fd,
> + set_xfrm_info_prog_fd))
> + goto done;
> +
> + /* perform test */
> + if (!ASSERT_EQ(test_xfrm_ping(skel, IF_ID_0_TO_1), 0, "ping " NS1))
> + goto done;
> + if (!ASSERT_EQ(test_xfrm_ping(skel, IF_ID_0_TO_2), 0, "ping " NS2))
> + goto done;
> +
> +done:
> + if (nstoken)
> + close_netns(nstoken);
> + if (skel)
NULL check is removed. xfrm_info__destroy() can handle NULL.
> + xfrm_info__destroy(skel);
> +}
Powered by blists - more mailing lists