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

TOMOYO Linux Cross Reference
Linux/kernel/bpf/preload/bpf_preload_kern.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0
  2 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  3 #include <linux/init.h>
  4 #include <linux/module.h>
  5 #include "bpf_preload.h"
  6 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
  7 #include "iterators/iterators.lskel-little-endian.h"
  8 #else
  9 #include "iterators/iterators.lskel-big-endian.h"
 10 #endif
 11 
 12 static struct bpf_link *maps_link, *progs_link;
 13 static struct iterators_bpf *skel;
 14 
 15 static void free_links_and_skel(void)
 16 {
 17         if (!IS_ERR_OR_NULL(maps_link))
 18                 bpf_link_put(maps_link);
 19         if (!IS_ERR_OR_NULL(progs_link))
 20                 bpf_link_put(progs_link);
 21         iterators_bpf__destroy(skel);
 22 }
 23 
 24 static int preload(struct bpf_preload_info *obj)
 25 {
 26         strscpy(obj[0].link_name, "maps.debug", sizeof(obj[0].link_name));
 27         obj[0].link = maps_link;
 28         strscpy(obj[1].link_name, "progs.debug", sizeof(obj[1].link_name));
 29         obj[1].link = progs_link;
 30         return 0;
 31 }
 32 
 33 static struct bpf_preload_ops ops = {
 34         .preload = preload,
 35         .owner = THIS_MODULE,
 36 };
 37 
 38 static int load_skel(void)
 39 {
 40         int err;
 41 
 42         skel = iterators_bpf__open();
 43         if (!skel)
 44                 return -ENOMEM;
 45         err = iterators_bpf__load(skel);
 46         if (err)
 47                 goto out;
 48         err = iterators_bpf__attach(skel);
 49         if (err)
 50                 goto out;
 51         maps_link = bpf_link_get_from_fd(skel->links.dump_bpf_map_fd);
 52         if (IS_ERR(maps_link)) {
 53                 err = PTR_ERR(maps_link);
 54                 goto out;
 55         }
 56         progs_link = bpf_link_get_from_fd(skel->links.dump_bpf_prog_fd);
 57         if (IS_ERR(progs_link)) {
 58                 err = PTR_ERR(progs_link);
 59                 goto out;
 60         }
 61         /* Avoid taking over stdin/stdout/stderr of init process. Zeroing out
 62          * makes skel_closenz() a no-op later in iterators_bpf__destroy().
 63          */
 64         close_fd(skel->links.dump_bpf_map_fd);
 65         skel->links.dump_bpf_map_fd = 0;
 66         close_fd(skel->links.dump_bpf_prog_fd);
 67         skel->links.dump_bpf_prog_fd = 0;
 68         return 0;
 69 out:
 70         free_links_and_skel();
 71         return err;
 72 }
 73 
 74 static int __init load(void)
 75 {
 76         int err;
 77 
 78         err = load_skel();
 79         if (err)
 80                 return err;
 81         bpf_preload_ops = &ops;
 82         return err;
 83 }
 84 
 85 static void __exit fini(void)
 86 {
 87         bpf_preload_ops = NULL;
 88         free_links_and_skel();
 89 }
 90 late_initcall(load);
 91 module_exit(fini);
 92 MODULE_LICENSE("GPL");
 93 

~ [ 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