]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
samples/bpf: all XDP samples should unload xdp/bpf prog on SIGTERM
authorJesper Dangaard Brouer <brouer@redhat.com>
Wed, 15 Aug 2018 14:57:14 +0000 (16:57 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 15 Sep 2018 07:46:48 +0000 (09:46 +0200)
[ Upstream commit 817b89beb9d8876450fcde9155e17425c329569d ]

It is common XDP practice to unload/deattach the XDP bpf program,
when the XDP sample program is Ctrl-C interrupted (SIGINT) or
killed (SIGTERM).

The samples/bpf programs xdp_redirect_cpu and xdp_rxq_info,
forgot to trap signal SIGTERM (which is the default signal used
by the kill command).

This was discovered by Red Hat QA, which automated scripts depend
on killing the XDP sample program after a timeout period.

Fixes: fad3917e361b ("samples/bpf: add cpumap sample program xdp_redirect_cpu")
Fixes: 0fca931a6f21 ("samples/bpf: program demonstrating access to xdp_rxq_info")
Reported-by: Jean-Tsung Hsiao <jhsiao@redhat.com>
Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
samples/bpf/xdp_redirect_cpu_user.c
samples/bpf/xdp_rxq_info_user.c

index 4b4d78fffe30427d26ee28a338ff6749dccb7448..da9070889223fc9547cd20bf261e59030397bf76 100644 (file)
@@ -679,8 +679,9 @@ int main(int argc, char **argv)
                return EXIT_FAIL_OPTION;
        }
 
-       /* Remove XDP program when program is interrupted */
+       /* Remove XDP program when program is interrupted or killed */
        signal(SIGINT, int_exit);
+       signal(SIGTERM, int_exit);
 
        if (bpf_set_link_xdp_fd(ifindex, prog_fd[prog_num], xdp_flags) < 0) {
                fprintf(stderr, "link set xdp fd failed\n");
index e4e9ba52bff02c457410543424b0f90148a01730..bb278447299c92b81d3817df3ea1f4c00514716a 100644 (file)
@@ -534,8 +534,9 @@ int main(int argc, char **argv)
                exit(EXIT_FAIL_BPF);
        }
 
-       /* Remove XDP program when program is interrupted */
+       /* Remove XDP program when program is interrupted or killed */
        signal(SIGINT, int_exit);
+       signal(SIGTERM, int_exit);
 
        if (bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags) < 0) {
                fprintf(stderr, "link set xdp fd failed\n");