aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesper Dangaard Brouer <brouer@redhat.com>2018-08-15 10:57:14 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-08-16 15:55:32 -0400
commit817b89beb9d8876450fcde9155e17425c329569d (patch)
tree8bce921ed07fac52944dbb6d156cc16f62f864b3
parent21b172ee11b6ec260bd7e6a27b11a8a8d392fce5 (diff)
samples/bpf: all XDP samples should unload xdp/bpf prog on SIGTERM
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>
-rw-r--r--samples/bpf/xdp_redirect_cpu_user.c3
-rw-r--r--samples/bpf/xdp_rxq_info_user.c3
2 files changed, 4 insertions, 2 deletions
diff --git a/samples/bpf/xdp_redirect_cpu_user.c b/samples/bpf/xdp_redirect_cpu_user.c
index 9a6c7e0a6dd1..2d23054aaccf 100644
--- a/samples/bpf/xdp_redirect_cpu_user.c
+++ b/samples/bpf/xdp_redirect_cpu_user.c
@@ -679,8 +679,9 @@ int main(int argc, char **argv)
679 return EXIT_FAIL_OPTION; 679 return EXIT_FAIL_OPTION;
680 } 680 }
681 681
682 /* Remove XDP program when program is interrupted */ 682 /* Remove XDP program when program is interrupted or killed */
683 signal(SIGINT, int_exit); 683 signal(SIGINT, int_exit);
684 signal(SIGTERM, int_exit);
684 685
685 if (bpf_set_link_xdp_fd(ifindex, prog_fd[prog_num], xdp_flags) < 0) { 686 if (bpf_set_link_xdp_fd(ifindex, prog_fd[prog_num], xdp_flags) < 0) {
686 fprintf(stderr, "link set xdp fd failed\n"); 687 fprintf(stderr, "link set xdp fd failed\n");
diff --git a/samples/bpf/xdp_rxq_info_user.c b/samples/bpf/xdp_rxq_info_user.c
index 248a7eab9531..ef26f882f92f 100644
--- a/samples/bpf/xdp_rxq_info_user.c
+++ b/samples/bpf/xdp_rxq_info_user.c
@@ -567,8 +567,9 @@ int main(int argc, char **argv)
567 exit(EXIT_FAIL_BPF); 567 exit(EXIT_FAIL_BPF);
568 } 568 }
569 569
570 /* Remove XDP program when program is interrupted */ 570 /* Remove XDP program when program is interrupted or killed */
571 signal(SIGINT, int_exit); 571 signal(SIGINT, int_exit);
572 signal(SIGTERM, int_exit);
572 573
573 if (bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags) < 0) { 574 if (bpf_set_link_xdp_fd(ifindex, prog_fd, xdp_flags) < 0) {
574 fprintf(stderr, "link set xdp fd failed\n"); 575 fprintf(stderr, "link set xdp fd failed\n");