1 /* Copyright (c) 2016 PLUMgrid
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of version 2 of the GNU General Public
5 * License as published by the Free Software Foundation.
22 static void int_exit(int sig
)
24 set_link_xdp_fd(ifindex
, -1);
28 /* simple per-protocol drop counter
30 static void poll_stats(int interval
)
32 unsigned int nr_cpus
= bpf_num_possible_cpus();
33 const unsigned int nr_keys
= 256;
34 __u64 values
[nr_cpus
], prev
[nr_keys
][nr_cpus
];
38 memset(prev
, 0, sizeof(prev
));
43 for (key
= 0; key
< nr_keys
; key
++) {
46 assert(bpf_map_lookup_elem(map_fd
[0], &key
, values
) == 0);
47 for (i
= 0; i
< nr_cpus
; i
++)
48 sum
+= (values
[i
] - prev
[key
][i
]);
50 printf("proto %u: %10llu pkt/s\n",
52 memcpy(prev
[key
], values
, sizeof(values
));
57 int main(int ac
, char **argv
)
61 snprintf(filename
, sizeof(filename
), "%s_kern.o", argv
[0]);
64 printf("usage: %s IFINDEX\n", argv
[0]);
68 ifindex
= strtoul(argv
[1], NULL
, 0);
70 if (load_bpf_file(filename
)) {
71 printf("%s", bpf_log_buf
);
76 printf("load_bpf_file: %s\n", strerror(errno
));
80 signal(SIGINT
, int_exit
);
82 if (set_link_xdp_fd(ifindex
, prog_fd
[0]) < 0) {
83 printf("link set xdp fd failed\n");