Skip to content

Commit

Permalink
samples/bpf: xdp_ddos01 export blacklist eBPF map via filesystem
Browse files Browse the repository at this point in the history
First gotcha need to mount:
  mount -t bpf bpf /sys/fs/bpf/

Stange this does not seem to work, still after mounting
/sys/fs/bpf/ the file does not appear.  And stranger it does not
report/catch any errors.
  • Loading branch information
netoptimizer committed Feb 14, 2017
1 parent 309fa69 commit ada1c31
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions kernel/samples/bpf/xdp_ddos01_blacklist_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ static const char *__doc__=
static int ifindex = -1;
static int verbose = 1;

/* Export eBPF map for IPv4 blacklist as a file
* Gotcha need to mount:
* mount -t bpf bpf /sys/fs/bpf/
*/
const char *file = "/sys/fs/bpf/ddos_blacklist";

static void int_exit(int sig)
{
fprintf(stderr, "Interrupted: Removing XDP program on ifindex:%d\n",
Expand Down Expand Up @@ -233,6 +239,14 @@ int main(int argc, char **argv)
}

blacklist_add("192.2.1.3");

/* Export map as a file */
if (bpf_obj_pin(map_fd[0], file) != 0) {
printf("ERROR: Cannot pin map file:%s err(%d):%s",
file, errno, strerror(errno));
return EXIT_FAIL_XDP;
}

blacklist_add("192.2.1.3");
sleep(10);
blacklist_add("198.18.50.3");
Expand Down

0 comments on commit ada1c31

Please sign in to comment.