Release 4.16 samples/bpf/xdp1_user.c
/* Copyright (c) 2016 PLUMgrid
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
* 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>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <libgen.h>
#include <sys/resource.h>
#include "bpf_load.h"
#include "bpf_util.h"
#include "libbpf.h"
static int ifindex;
static __u32 xdp_flags;
static void int_exit(int sig)
{
bpf_set_link_xdp_fd(ifindex, -1, xdp_flags);
exit(0);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Brenden Blanco | 21 | 87.50% | 1 | 25.00% |
Eric Leblond | 1 | 4.17% | 1 | 25.00% |
Jesper Dangaard Brouer | 1 | 4.17% | 1 | 25.00% |
David Ahern | 1 | 4.17% | 1 | 25.00% |
Total | 24 | 100.00% | 4 | 100.00% |
/* simple per-protocol drop counter
*/
static void poll_stats(int interval)
{
unsigned int nr_cpus = bpf_num_possible_cpus();
const unsigned int nr_keys = 256;
__u64 values[nr_cpus], prev[nr_keys][nr_cpus];
__u32 key;
int i;
memset(prev, 0, sizeof(prev));
while (1) {
sleep(interval);
for (key = 0; key < nr_keys; key++) {
__u64 sum = 0;
assert(bpf_map_lookup_elem(map_fd[0], &key, values) == 0);
for (i = 0; i < nr_cpus; i++)
sum += (values[i] - prev[key][i]);
if (sum)
printf("proto %u: %10llu pkt/s\n",
key, sum / interval);
memcpy(prev[key], values, sizeof(values));
}
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Brenden Blanco | 161 | 98.17% | 1 | 33.33% |
Daniel Borkmann | 2 | 1.22% | 1 | 33.33% |
Joe Stringer | 1 | 0.61% | 1 | 33.33% |
Total | 164 | 100.00% | 3 | 100.00% |
static void usage(const char *prog)
{
fprintf(stderr,
"usage: %s [OPTS] IFINDEX\n\n"
"OPTS:\n"
" -S use skb-mode\n"
" -N enforce native mode\n",
prog);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David Ahern | 22 | 95.65% | 1 | 50.00% |
Daniel Borkmann | 1 | 4.35% | 1 | 50.00% |
Total | 23 | 100.00% | 2 | 100.00% |
int main(int argc, char **argv)
{
struct rlimit r = {RLIM_INFINITY, RLIM_INFINITY};
const char *optstr = "SN";
char filename[256];
int opt;
while ((opt = getopt(argc, argv, optstr)) != -1) {
switch (opt) {
case 'S':
xdp_flags |= XDP_FLAGS_SKB_MODE;
break;
case 'N':
xdp_flags |= XDP_FLAGS_DRV_MODE;
break;
default:
usage(basename(argv[0]));
return 1;
}
}
if (optind == argc) {
usage(basename(argv[0]));
return 1;
}
if (setrlimit(RLIMIT_MEMLOCK, &r)) {
perror("setrlimit(RLIMIT_MEMLOCK)");
return 1;
}
ifindex = strtoul(argv[optind], NULL, 0);
snprintf(filename, sizeof(filename), "%s_kern.o", argv[0]);
if (load_bpf_file(filename)) {
printf("%s", bpf_log_buf);
return 1;
}
if (!prog_fd[0]) {
printf("load_bpf_file: %s\n", strerror(errno));
return 1;
}
signal(SIGINT, int_exit);
signal(SIGTERM, int_exit);
if (bpf_set_link_xdp_fd(ifindex, prog_fd[0], xdp_flags) < 0) {
printf("link set xdp fd failed\n");
return 1;
}
poll_stats(2);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Brenden Blanco | 135 | 52.12% | 1 | 14.29% |
David Ahern | 75 | 28.96% | 1 | 14.29% |
Tushar Dave | 30 | 11.58% | 1 | 14.29% |
Daniel Borkmann | 9 | 3.47% | 1 | 14.29% |
Andy Gospodarek | 7 | 2.70% | 1 | 14.29% |
Jesper Dangaard Brouer | 2 | 0.77% | 1 | 14.29% |
Eric Leblond | 1 | 0.39% | 1 | 14.29% |
Total | 259 | 100.00% | 7 | 100.00% |
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Brenden Blanco | 353 | 67.62% | 1 | 11.11% |
David Ahern | 106 | 20.31% | 1 | 11.11% |
Tushar Dave | 33 | 6.32% | 1 | 11.11% |
Daniel Borkmann | 15 | 2.87% | 2 | 22.22% |
Andy Gospodarek | 7 | 1.34% | 1 | 11.11% |
Jesper Dangaard Brouer | 5 | 0.96% | 1 | 11.11% |
Eric Leblond | 2 | 0.38% | 1 | 11.11% |
Joe Stringer | 1 | 0.19% | 1 | 11.11% |
Total | 522 | 100.00% | 9 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.