Commit 24bb90a4 authored by Geliang Tang's avatar Geliang Tang Committed by Daniel Borkmann
Browse files

selftests/bpf: Replace tx_prog_fd with tx_prog in test_sockmap



bpf_program__attach_sockmap() needs to take a parameter of type bpf_program
instead of an fd, so tx_prog_fd becomes useless. This patch uses a pointer
tx_prog to point to an item in progs[] array.

Signed-off-by: default avatarGeliang Tang <tanggeliang@kylinos.cn>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Tested-by: default avatarJakub Sitnicki <jakub@cloudflare.com>
Acked-by: default avatarJohn Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/bpf/23b37f932c547dd1ebfe154bbc0b0e957be21ee6.1716446893.git.tanggeliang@kylinos.cn
parent 3f32a115
Loading
Loading
Loading
Loading
+14 −16
Original line number Diff line number Diff line
@@ -954,7 +954,8 @@ enum {

static int run_options(struct sockmap_options *options, int cg_fd,  int test)
{
	int i, key, next_key, err, tx_prog_fd = -1, zero = 0;
	int i, key, next_key, err, zero = 0;
	struct bpf_program *tx_prog;

	/* If base test skip BPF setup */
	if (test == BASE || test == BASE_SENDPAGE)
@@ -1015,27 +1016,27 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)

	/* Attach txmsg program to sockmap */
	if (txmsg_pass)
		tx_prog_fd = prog_fd[4];
		tx_prog = progs[4];
	else if (txmsg_redir)
		tx_prog_fd = prog_fd[5];
		tx_prog = progs[5];
	else if (txmsg_apply)
		tx_prog_fd = prog_fd[6];
		tx_prog = progs[6];
	else if (txmsg_cork)
		tx_prog_fd = prog_fd[7];
		tx_prog = progs[7];
	else if (txmsg_drop)
		tx_prog_fd = prog_fd[8];
		tx_prog = progs[8];
	else
		tx_prog_fd = -1;
		tx_prog = NULL;

	if (tx_prog_fd > 0) {
	if (tx_prog) {
		int redir_fd;

		err = bpf_prog_attach(tx_prog_fd,
				      map_fd[1], BPF_SK_MSG_VERDICT, 0);
		if (err) {
		links[4] = bpf_program__attach_sockmap(tx_prog, map_fd[1]);
		if (!links[4]) {
			fprintf(stderr,
				"ERROR: bpf_prog_attach (txmsg): %d (%s)\n",
				err, strerror(errno));
				"ERROR: bpf_program__attach_sockmap (txmsg): (%s)\n",
				strerror(errno));
			err = -1;
			goto out;
		}

@@ -1285,9 +1286,6 @@ static int run_options(struct sockmap_options *options, int cg_fd, int test)
			bpf_link__detach(links[i]);
	}

	if (tx_prog_fd > 0)
		bpf_prog_detach2(tx_prog_fd, map_fd[1], BPF_SK_MSG_VERDICT);

	for (i = 0; i < 8; i++) {
		key = next_key = 0;
		bpf_map_update_elem(map_fd[i], &key, &zero, BPF_ANY);