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

TOMOYO Linux Cross Reference
Linux/net/netfilter/nf_hooks_lwtunnel.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
  2 
  3 #include <linux/sysctl.h>
  4 #include <net/lwtunnel.h>
  5 #include <net/netfilter/nf_hooks_lwtunnel.h>
  6 #include <linux/netfilter.h>
  7 
  8 #include "nf_internals.h"
  9 
 10 static inline int nf_hooks_lwtunnel_get(void)
 11 {
 12         if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled))
 13                 return 1;
 14         else
 15                 return 0;
 16 }
 17 
 18 static inline int nf_hooks_lwtunnel_set(int enable)
 19 {
 20         if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) {
 21                 if (!enable)
 22                         return -EBUSY;
 23         } else if (enable) {
 24                 static_branch_enable(&nf_hooks_lwtunnel_enabled);
 25         }
 26 
 27         return 0;
 28 }
 29 
 30 #ifdef CONFIG_SYSCTL
 31 int nf_hooks_lwtunnel_sysctl_handler(const struct ctl_table *table, int write,
 32                                      void *buffer, size_t *lenp, loff_t *ppos)
 33 {
 34         int proc_nf_hooks_lwtunnel_enabled = 0;
 35         struct ctl_table tmp = {
 36                 .procname = table->procname,
 37                 .data = &proc_nf_hooks_lwtunnel_enabled,
 38                 .maxlen = sizeof(int),
 39                 .mode = table->mode,
 40                 .extra1 = SYSCTL_ZERO,
 41                 .extra2 = SYSCTL_ONE,
 42         };
 43         int ret;
 44 
 45         if (!write)
 46                 proc_nf_hooks_lwtunnel_enabled = nf_hooks_lwtunnel_get();
 47 
 48         ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
 49 
 50         if (write && ret == 0)
 51                 ret = nf_hooks_lwtunnel_set(proc_nf_hooks_lwtunnel_enabled);
 52 
 53         return ret;
 54 }
 55 EXPORT_SYMBOL_GPL(nf_hooks_lwtunnel_sysctl_handler);
 56 
 57 static struct ctl_table nf_lwtunnel_sysctl_table[] = {
 58         {
 59                 .procname       = "nf_hooks_lwtunnel",
 60                 .data           = NULL,
 61                 .maxlen         = sizeof(int),
 62                 .mode           = 0644,
 63                 .proc_handler   = nf_hooks_lwtunnel_sysctl_handler,
 64         },
 65 };
 66 
 67 static int __net_init nf_lwtunnel_net_init(struct net *net)
 68 {
 69         struct ctl_table_header *hdr;
 70         struct ctl_table *table;
 71 
 72         table = nf_lwtunnel_sysctl_table;
 73         if (!net_eq(net, &init_net)) {
 74                 table = kmemdup(nf_lwtunnel_sysctl_table,
 75                                 sizeof(nf_lwtunnel_sysctl_table),
 76                                 GFP_KERNEL);
 77                 if (!table)
 78                         goto err_alloc;
 79         }
 80 
 81         hdr = register_net_sysctl_sz(net, "net/netfilter", table,
 82                                      ARRAY_SIZE(nf_lwtunnel_sysctl_table));
 83         if (!hdr)
 84                 goto err_reg;
 85 
 86         net->nf.nf_lwtnl_dir_header = hdr;
 87 
 88         return 0;
 89 err_reg:
 90         if (!net_eq(net, &init_net))
 91                 kfree(table);
 92 err_alloc:
 93         return -ENOMEM;
 94 }
 95 
 96 static void __net_exit nf_lwtunnel_net_exit(struct net *net)
 97 {
 98         const struct ctl_table *table;
 99 
100         table = net->nf.nf_lwtnl_dir_header->ctl_table_arg;
101         unregister_net_sysctl_table(net->nf.nf_lwtnl_dir_header);
102         if (!net_eq(net, &init_net))
103                 kfree(table);
104 }
105 
106 static struct pernet_operations nf_lwtunnel_net_ops = {
107         .init = nf_lwtunnel_net_init,
108         .exit = nf_lwtunnel_net_exit,
109 };
110 
111 int __init netfilter_lwtunnel_init(void)
112 {
113         return register_pernet_subsys(&nf_lwtunnel_net_ops);
114 }
115 
116 void netfilter_lwtunnel_fini(void)
117 {
118         unregister_pernet_subsys(&nf_lwtunnel_net_ops);
119 }
120 #else
121 int __init netfilter_lwtunnel_init(void) { return 0; }
122 void netfilter_lwtunnel_fini(void) {}
123 #endif /* CONFIG_SYSCTL */
124 

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