OpenVZ Forum - RDF feed
type: channel
items: [PATCH] [NETFILTER] Consolidate nf_sockopt and compat_nf_sockopt v2
items: Re: [PATCH] [NETFILTER] Consolidate nf_sockopt and compat_nf_sockopt v2

[PATCH] [NETFILTER] Consolidate nf_sockopt and compat_nf_sockopt v2
type: item
description: Both lookup the nf_sockopt_ops object to call the get/set callbacks from, but they perform it in a completely similar way. Introduce the helper for finding the ops. Ported at the top of today's net-2.6 tree to resolve conflict with the patch from Alexey Dobriyan. Signed-off-by: Pavel Emelyanov <xemul@openvz.org> --- diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c index 2dfac32..87bc144 100644 --- a/net/netfilter/nf_sockopt.c +++ b/net/netfilter/nf_sockopt.c @@ -60,46 +60,57 @@ void nf_unregister_sockopt(struct nf_sockopt_ops *reg) } EXPORT_SYMBOL(nf_unregister_sockopt); -/* Call get/setsockopt() */ -static int nf_sockopt(struct sock *sk, int pf, int val, - char __user *opt, int *len, int get) +static struct nf_sockopt_ops *nf_sockopt_find(struct sock *sk, int pf, + int val, int get) { struct nf_sockopt_ops *ops; - int ret; if (sk->sk_net != &init_net) - return -ENOPROTOOPT; + return ERR_PTR(-ENOPROTOOPT); if (mutex_lock_interruptible(&nf_sockopt_mutex) != 0) - return -EINTR; + return ERR_PTR(-EINTR); list_for_each_entry(ops, &nf_sockopts, list) { if (ops->pf == pf) { if (!try_module_get(ops->owner)) goto out_nosup; + if (get) { - if (val >= ops->get_optmin - && val < ops->get_optmax) { - mutex_unlock(&nf_sockopt_mutex); - ret = ops->get(sk, val, opt, len); + if (val >= ops->get_optmin && + val < ops->get_optmax) goto out; - } } else { - if (val >= ops->set_optmin - && val < ops->set_optmax) { - mutex_unlock(&nf_sockopt_mutex); - ret = ops->set(sk, val, opt, *len); + if (val >= ops->set_optmin && + val < ops->set_optmax) goto out; - } } module_put(ops->owner); } } - out_nosup: +out_nosup: + ops = ERR_PTR(-ENOPROTOOPT); +out: mutex_unlock(&nf_sockopt_mutex); - return -ENOPROTOOPT; + return ops; +} + +/* Call get/setsockopt() */ +static int nf_sockopt(struct sock *sk, int pf, int val, + char __user *opt, int *len, int get) +{ + struct nf_sockopt_ops *ops; + int ret; + + ops = nf_sockopt_find(sk, pf, val, get); + if (IS_ERR(ops)) + return PTR_ERR(op…
creator: Pavel Emelianov
date: 2007-11-06T08:29:18-00:00

Re: [PATCH] [NETFILTER] Consolidate nf_sockopt and compat_nf_sockopt v2
type: item
description: Pavel Emelyanov wrote: > Both lookup the nf_sockopt_ops object to call the get/set callbacks > from, but they perform it in a completely similar way. > > Introduce the helper for finding the ops. > > Ported at the top of today's net-2.6 tree to resolve conflict > with the patch from Alexey Dobriyan. Applied, thanks Pavel.
creator: Patrick McHardy
date: 2007-11-08T16:43:21-00:00