~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/samples/bpf/tc_l2_redirect_user.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-only
  2 /* Copyright (c) 2016 Facebook
  3  */
  4 #include <linux/unistd.h>
  5 #include <linux/bpf.h>
  6 
  7 #include <stdlib.h>
  8 #include <stdio.h>
  9 #include <unistd.h>
 10 #include <string.h>
 11 #include <errno.h>
 12 
 13 #include <bpf/bpf.h>
 14 
 15 static void usage(void)
 16 {
 17         printf("Usage: tc_l2_ipip_redirect [...]\n");
 18         printf("       -U <file>   Update an already pinned BPF array\n");
 19         printf("       -i <ifindex> Interface index\n");
 20         printf("       -h          Display this help\n");
 21 }
 22 
 23 int main(int argc, char **argv)
 24 {
 25         const char *pinned_file = NULL;
 26         int ifindex = -1;
 27         int array_key = 0;
 28         int array_fd = -1;
 29         int ret = -1;
 30         int opt;
 31 
 32         while ((opt = getopt(argc, argv, "F:U:i:")) != -1) {
 33                 switch (opt) {
 34                 /* General args */
 35                 case 'U':
 36                         pinned_file = optarg;
 37                         break;
 38                 case 'i':
 39                         ifindex = atoi(optarg);
 40                         break;
 41                 default:
 42                         usage();
 43                         goto out;
 44                 }
 45         }
 46 
 47         if (ifindex < 0 || !pinned_file) {
 48                 usage();
 49                 goto out;
 50         }
 51 
 52         array_fd = bpf_obj_get(pinned_file);
 53         if (array_fd < 0) {
 54                 fprintf(stderr, "bpf_obj_get(%s): %s(%d)\n",
 55                         pinned_file, strerror(errno), errno);
 56                 goto out;
 57         }
 58 
 59         /* bpf_tunnel_key.remote_ipv4 expects host byte orders */
 60         ret = bpf_map_update_elem(array_fd, &array_key, &ifindex, 0);
 61         if (ret) {
 62                 perror("bpf_map_update_elem");
 63                 goto out;
 64         }
 65 
 66 out:
 67         if (array_fd != -1)
 68                 close(array_fd);
 69         return ret;
 70 }
 71 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php