|
@@ -5,6 +5,7 @@
|
|
|
* License as published by the Free Software Foundation.
|
|
|
*/
|
|
|
#include <linux/bpf.h>
|
|
|
+#include <linux/if_link.h>
|
|
|
#include <assert.h>
|
|
|
#include <errno.h>
|
|
|
#include <signal.h>
|
|
@@ -12,16 +13,18 @@
|
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
|
#include <unistd.h>
|
|
|
+#include <libgen.h>
|
|
|
|
|
|
#include "bpf_load.h"
|
|
|
#include "bpf_util.h"
|
|
|
#include "libbpf.h"
|
|
|
|
|
|
static int ifindex;
|
|
|
+static int flags;
|
|
|
|
|
|
static void int_exit(int sig)
|
|
|
{
|
|
|
- set_link_xdp_fd(ifindex, -1);
|
|
|
+ set_link_xdp_fd(ifindex, -1, flags);
|
|
|
exit(0);
|
|
|
}
|
|
|
|
|
@@ -54,18 +57,39 @@ static void poll_stats(int interval)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-int main(int ac, char **argv)
|
|
|
+static void usage(const char *prog)
|
|
|
{
|
|
|
- char filename[256];
|
|
|
+ fprintf(stderr,
|
|
|
+ "usage: %s [OPTS] IFINDEX\n\n"
|
|
|
+ "OPTS:\n"
|
|
|
+ " -S use skb-mode\n",
|
|
|
+ prog);
|
|
|
+}
|
|
|
|
|
|
- snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
|
|
|
+int main(int argc, char **argv)
|
|
|
+{
|
|
|
+ const char *optstr = "S";
|
|
|
+ char filename[256];
|
|
|
+ int opt;
|
|
|
+
|
|
|
+ while ((opt = getopt(argc, argv, optstr)) != -1) {
|
|
|
+ switch (opt) {
|
|
|
+ case 'S':
|
|
|
+ flags |= XDP_FLAGS_SKB_MODE;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ usage(basename(argv[0]));
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (ac != 2) {
|
|
|
- printf("usage: %s IFINDEX\n", argv[0]);
|
|
|
+ if (optind == argc) {
|
|
|
+ usage(basename(argv[0]));
|
|
|
return 1;
|
|
|
}
|
|
|
+ ifindex = strtoul(argv[optind], NULL, 0);
|
|
|
|
|
|
- ifindex = strtoul(argv[1], NULL, 0);
|
|
|
+ snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
|
|
|
|
|
|
if (load_bpf_file(filename)) {
|
|
|
printf("%s", bpf_log_buf);
|
|
@@ -79,7 +103,7 @@ int main(int ac, char **argv)
|
|
|
|
|
|
signal(SIGINT, int_exit);
|
|
|
|
|
|
- if (set_link_xdp_fd(ifindex, prog_fd[0]) < 0) {
|
|
|
+ if (set_link_xdp_fd(ifindex, prog_fd[0], flags) < 0) {
|
|
|
printf("link set xdp fd failed\n");
|
|
|
return 1;
|
|
|
}
|