1 #include <linux/kernel.h>
3 #include <linux/module.h>
5 #include <linux/netfilter.h>
18 static inline int overlap(
int min1,
int max1,
int min2,
int max2)
20 return max1 > min2 && min1 < max2;
26 struct nf_sockopt_ops *
ops;
33 if (ops->pf == reg->pf
34 && (overlap(ops->set_optmin, ops->set_optmax,
35 reg->set_optmin, reg->set_optmax)
36 || overlap(ops->get_optmin, ops->get_optmax,
37 reg->get_optmin, reg->get_optmax))) {
38 NFDEBUG(
"nf_sock overlap: %u-%u/%u-%u v %u-%u/%u-%u\n",
39 ops->set_optmin, ops->set_optmax,
40 ops->get_optmin, ops->get_optmax,
41 reg->set_optmin, reg->set_optmax,
42 reg->get_optmin, reg->get_optmax);
48 list_add(®->list, &nf_sockopts);
66 struct nf_sockopt_ops *
ops;
69 return ERR_PTR(-
EINTR);
73 if (!try_module_get(ops->owner))
77 if (val >= ops->get_optmin &&
78 val < ops->get_optmax)
81 if (val >= ops->set_optmin &&
82 val < ops->set_optmax)
85 module_put(ops->owner);
96 static int nf_sockopt(
struct sock *sk,
u_int8_t pf,
int val,
97 char __user *
opt,
int *len,
int get)
99 struct nf_sockopt_ops *ops;
102 ops = nf_sockopt_find(sk, pf, val,
get);
107 ret = ops->get(sk, val, opt, len);
109 ret = ops->set(sk, val, opt, *len);
111 module_put(ops->owner);
118 return nf_sockopt(sk, pf, val, opt, &len, 0);
125 return nf_sockopt(sk, pf, val, opt, len, 1);
130 static int compat_nf_sockopt(
struct sock *sk,
u_int8_t pf,
int val,
131 char __user *opt,
int *len,
int get)
133 struct nf_sockopt_ops *ops;
136 ops = nf_sockopt_find(sk, pf, val,
get);
142 ret = ops->compat_get(sk, val, opt, len);
144 ret = ops->get(sk, val, opt, len);
147 ret = ops->compat_set(sk, val, opt, *len);
149 ret = ops->set(sk, val, opt, *len);
152 module_put(ops->owner);
157 int val,
char __user *opt,
unsigned int len)
159 return compat_nf_sockopt(sk, pf, val, opt, &len, 0);
164 int val,
char __user *opt,
int *len)
166 return compat_nf_sockopt(sk, pf, val, opt, len, 1);