0001
0002
0003 #include <linux/sysctl.h>
0004 #include <net/lwtunnel.h>
0005 #include <net/netfilter/nf_hooks_lwtunnel.h>
0006
0007 static inline int nf_hooks_lwtunnel_get(void)
0008 {
0009 if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled))
0010 return 1;
0011 else
0012 return 0;
0013 }
0014
0015 static inline int nf_hooks_lwtunnel_set(int enable)
0016 {
0017 if (static_branch_unlikely(&nf_hooks_lwtunnel_enabled)) {
0018 if (!enable)
0019 return -EBUSY;
0020 } else if (enable) {
0021 static_branch_enable(&nf_hooks_lwtunnel_enabled);
0022 }
0023
0024 return 0;
0025 }
0026
0027 #ifdef CONFIG_SYSCTL
0028 int nf_hooks_lwtunnel_sysctl_handler(struct ctl_table *table, int write,
0029 void *buffer, size_t *lenp, loff_t *ppos)
0030 {
0031 int proc_nf_hooks_lwtunnel_enabled = 0;
0032 struct ctl_table tmp = {
0033 .procname = table->procname,
0034 .data = &proc_nf_hooks_lwtunnel_enabled,
0035 .maxlen = sizeof(int),
0036 .mode = table->mode,
0037 .extra1 = SYSCTL_ZERO,
0038 .extra2 = SYSCTL_ONE,
0039 };
0040 int ret;
0041
0042 if (!write)
0043 proc_nf_hooks_lwtunnel_enabled = nf_hooks_lwtunnel_get();
0044
0045 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
0046
0047 if (write && ret == 0)
0048 ret = nf_hooks_lwtunnel_set(proc_nf_hooks_lwtunnel_enabled);
0049
0050 return ret;
0051 }
0052 EXPORT_SYMBOL_GPL(nf_hooks_lwtunnel_sysctl_handler);
0053 #endif