mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-08-23 01:10:04 +00:00
![Thomas Gleixner](/assets/img/avatar_default.png)
Based on 1 normalized pattern(s): 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 extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 107 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Allison Randal <allison@lohutok.net> Reviewed-by: Richard Fontana <rfontana@redhat.com> Reviewed-by: Steve Winslow <swinslow@gmail.com> Reviewed-by: Alexios Zavras <alexios.zavras@intel.com> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190528171438.615055994@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
70 lines
1.3 KiB
C
70 lines
1.3 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/* Copyright (c) 2016 Facebook
|
|
*/
|
|
#include <linux/unistd.h>
|
|
#include <linux/bpf.h>
|
|
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
|
|
#include <bpf/bpf.h>
|
|
|
|
static void usage(void)
|
|
{
|
|
printf("Usage: tc_l2_ipip_redirect [...]\n");
|
|
printf(" -U <file> Update an already pinned BPF array\n");
|
|
printf(" -i <ifindex> Interface index\n");
|
|
printf(" -h Display this help\n");
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
const char *pinned_file = NULL;
|
|
int ifindex = -1;
|
|
int array_key = 0;
|
|
int array_fd = -1;
|
|
int ret = -1;
|
|
int opt;
|
|
|
|
while ((opt = getopt(argc, argv, "F:U:i:")) != -1) {
|
|
switch (opt) {
|
|
/* General args */
|
|
case 'U':
|
|
pinned_file = optarg;
|
|
break;
|
|
case 'i':
|
|
ifindex = atoi(optarg);
|
|
break;
|
|
default:
|
|
usage();
|
|
goto out;
|
|
}
|
|
}
|
|
|
|
if (ifindex < 0 || !pinned_file) {
|
|
usage();
|
|
goto out;
|
|
}
|
|
|
|
array_fd = bpf_obj_get(pinned_file);
|
|
if (array_fd < 0) {
|
|
fprintf(stderr, "bpf_obj_get(%s): %s(%d)\n",
|
|
pinned_file, strerror(errno), errno);
|
|
goto out;
|
|
}
|
|
|
|
/* bpf_tunnel_key.remote_ipv4 expects host byte orders */
|
|
ret = bpf_map_update_elem(array_fd, &array_key, &ifindex, 0);
|
|
if (ret) {
|
|
perror("bpf_map_update_elem");
|
|
goto out;
|
|
}
|
|
|
|
out:
|
|
if (array_fd != -1)
|
|
close(array_fd);
|
|
return ret;
|
|
}
|