Commit 7bd4224d authored by Jesper Dangaard Brouer's avatar Jesper Dangaard Brouer Committed by Daniel Borkmann

selftests/bpf: xdp_hw_metadata correct status value in error(3)

The glibc error reporting function error():

 void error(int status, int errnum, const char *format, ...);

The status argument should be a positive value between 0-255 as it
is passed over to the exit(3) function as the value as the shell exit
status. The least significant byte of status (i.e., status & 0xFF) is
returned to the shell parent.

Fix this by using 1 instead of -1. As 1 corresponds to C standard
constant EXIT_FAILURE.

Fixes: 297a3f12 ("selftests/bpf: Simple program to dump XDP RX metadata")
Signed-off-by: default avatarJesper Dangaard Brouer <brouer@redhat.com>
Signed-off-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
Acked-by: default avatarStanislav Fomichev <sdf@google.com>
Link: https://lore.kernel.org/bpf/167527272038.937063.9137108142012298120.stgit@firesoul
parent a19a62e5
......@@ -165,7 +165,7 @@ static void verify_skb_metadata(int fd)
hdr.msg_controllen = sizeof(cmsg_buf);
if (recvmsg(fd, &hdr, 0) < 0)
error(-1, errno, "recvmsg");
error(1, errno, "recvmsg");
for (cmsg = CMSG_FIRSTHDR(&hdr); cmsg != NULL;
cmsg = CMSG_NXTHDR(&hdr, cmsg)) {
......@@ -275,11 +275,11 @@ static int rxq_num(const char *ifname)
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (fd < 0)
error(-1, errno, "socket");
error(1, errno, "socket");
ret = ioctl(fd, SIOCETHTOOL, &ifr);
if (ret < 0)
error(-1, errno, "ioctl(SIOCETHTOOL)");
error(1, errno, "ioctl(SIOCETHTOOL)");
close(fd);
......@@ -296,11 +296,11 @@ static void hwtstamp_ioctl(int op, const char *ifname, struct hwtstamp_config *c
fd = socket(AF_UNIX, SOCK_DGRAM, 0);
if (fd < 0)
error(-1, errno, "socket");
error(1, errno, "socket");
ret = ioctl(fd, op, &ifr);
if (ret < 0)
error(-1, errno, "ioctl(%d)", op);
error(1, errno, "ioctl(%d)", op);
close(fd);
}
......@@ -360,7 +360,7 @@ static void timestamping_enable(int fd, int val)
ret = setsockopt(fd, SOL_SOCKET, SO_TIMESTAMPING, &val, sizeof(val));
if (ret < 0)
error(-1, errno, "setsockopt(SO_TIMESTAMPING)");
error(1, errno, "setsockopt(SO_TIMESTAMPING)");
}
int main(int argc, char *argv[])
......@@ -386,13 +386,13 @@ int main(int argc, char *argv[])
rx_xsk = malloc(sizeof(struct xsk) * rxq);
if (!rx_xsk)
error(-1, ENOMEM, "malloc");
error(1, ENOMEM, "malloc");
for (i = 0; i < rxq; i++) {
printf("open_xsk(%s, %p, %d)\n", ifname, &rx_xsk[i], i);
ret = open_xsk(ifindex, &rx_xsk[i], i);
if (ret)
error(-1, -ret, "open_xsk");
error(1, -ret, "open_xsk");
printf("xsk_socket__fd() -> %d\n", xsk_socket__fd(rx_xsk[i].socket));
}
......@@ -400,7 +400,7 @@ int main(int argc, char *argv[])
printf("open bpf program...\n");
bpf_obj = xdp_hw_metadata__open();
if (libbpf_get_error(bpf_obj))
error(-1, libbpf_get_error(bpf_obj), "xdp_hw_metadata__open");
error(1, libbpf_get_error(bpf_obj), "xdp_hw_metadata__open");
prog = bpf_object__find_program_by_name(bpf_obj->obj, "rx");
bpf_program__set_ifindex(prog, ifindex);
......@@ -409,12 +409,12 @@ int main(int argc, char *argv[])
printf("load bpf program...\n");
ret = xdp_hw_metadata__load(bpf_obj);
if (ret)
error(-1, -ret, "xdp_hw_metadata__load");
error(1, -ret, "xdp_hw_metadata__load");
printf("prepare skb endpoint...\n");
server_fd = start_server(AF_INET6, SOCK_DGRAM, NULL, 9092, 1000);
if (server_fd < 0)
error(-1, errno, "start_server");
error(1, errno, "start_server");
timestamping_enable(server_fd,
SOF_TIMESTAMPING_SOFTWARE |
SOF_TIMESTAMPING_RAW_HARDWARE);
......@@ -427,7 +427,7 @@ int main(int argc, char *argv[])
printf("map[%d] = %d\n", queue_id, sock_fd);
ret = bpf_map_update_elem(bpf_map__fd(bpf_obj->maps.xsk), &queue_id, &sock_fd, 0);
if (ret)
error(-1, -ret, "bpf_map_update_elem");
error(1, -ret, "bpf_map_update_elem");
}
printf("attach bpf program...\n");
......@@ -435,12 +435,12 @@ int main(int argc, char *argv[])
bpf_program__fd(bpf_obj->progs.rx),
XDP_FLAGS, NULL);
if (ret)
error(-1, -ret, "bpf_xdp_attach");
error(1, -ret, "bpf_xdp_attach");
signal(SIGINT, handle_signal);
ret = verify_metadata(rx_xsk, rxq, server_fd);
close(server_fd);
cleanup();
if (ret)
error(-1, -ret, "verify_metadata");
error(1, -ret, "verify_metadata");
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment