forked from mirrors/linux
		
	netfilter: nf_defrag_ipv4: use net_generic infra
This allows followup patch to remove the defrag_ipv4 member from struct net. It also allows to auto-remove the hooks later on by adding a _disable() function. This will be done later in a follow patch series. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
This commit is contained in:
		
							parent
							
								
									8b0adbe3e3
								
							
						
					
					
						commit
						7b1957b049
					
				
					 1 changed files with 15 additions and 5 deletions
				
			
		| 
						 | 
					@ -20,8 +20,13 @@
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
#include <net/netfilter/nf_conntrack_zones.h>
 | 
					#include <net/netfilter/nf_conntrack_zones.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static unsigned int defrag4_pernet_id __read_mostly;
 | 
				
			||||||
static DEFINE_MUTEX(defrag4_mutex);
 | 
					static DEFINE_MUTEX(defrag4_mutex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct defrag4_pernet {
 | 
				
			||||||
 | 
						unsigned int users;
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int nf_ct_ipv4_gather_frags(struct net *net, struct sk_buff *skb,
 | 
					static int nf_ct_ipv4_gather_frags(struct net *net, struct sk_buff *skb,
 | 
				
			||||||
				   u_int32_t user)
 | 
									   u_int32_t user)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -106,15 +111,19 @@ static const struct nf_hook_ops ipv4_defrag_ops[] = {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void __net_exit defrag4_net_exit(struct net *net)
 | 
					static void __net_exit defrag4_net_exit(struct net *net)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	if (net->nf.defrag_ipv4) {
 | 
						struct defrag4_pernet *nf_defrag = net_generic(net, defrag4_pernet_id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (nf_defrag->users) {
 | 
				
			||||||
		nf_unregister_net_hooks(net, ipv4_defrag_ops,
 | 
							nf_unregister_net_hooks(net, ipv4_defrag_ops,
 | 
				
			||||||
					ARRAY_SIZE(ipv4_defrag_ops));
 | 
										ARRAY_SIZE(ipv4_defrag_ops));
 | 
				
			||||||
		net->nf.defrag_ipv4 = false;
 | 
							nf_defrag->users = 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct pernet_operations defrag4_net_ops = {
 | 
					static struct pernet_operations defrag4_net_ops = {
 | 
				
			||||||
	.exit = defrag4_net_exit,
 | 
						.exit = defrag4_net_exit,
 | 
				
			||||||
 | 
						.id   = &defrag4_pernet_id,
 | 
				
			||||||
 | 
						.size = sizeof(struct defrag4_pernet),
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static int __init nf_defrag_init(void)
 | 
					static int __init nf_defrag_init(void)
 | 
				
			||||||
| 
						 | 
					@ -129,21 +138,22 @@ static void __exit nf_defrag_fini(void)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int nf_defrag_ipv4_enable(struct net *net)
 | 
					int nf_defrag_ipv4_enable(struct net *net)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						struct defrag4_pernet *nf_defrag = net_generic(net, defrag4_pernet_id);
 | 
				
			||||||
	int err = 0;
 | 
						int err = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	might_sleep();
 | 
						might_sleep();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (net->nf.defrag_ipv4)
 | 
						if (nf_defrag->users)
 | 
				
			||||||
		return 0;
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mutex_lock(&defrag4_mutex);
 | 
						mutex_lock(&defrag4_mutex);
 | 
				
			||||||
	if (net->nf.defrag_ipv4)
 | 
						if (nf_defrag->users)
 | 
				
			||||||
		goto out_unlock;
 | 
							goto out_unlock;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	err = nf_register_net_hooks(net, ipv4_defrag_ops,
 | 
						err = nf_register_net_hooks(net, ipv4_defrag_ops,
 | 
				
			||||||
				    ARRAY_SIZE(ipv4_defrag_ops));
 | 
									    ARRAY_SIZE(ipv4_defrag_ops));
 | 
				
			||||||
	if (err == 0)
 | 
						if (err == 0)
 | 
				
			||||||
		net->nf.defrag_ipv4 = true;
 | 
							nf_defrag->users = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 out_unlock:
 | 
					 out_unlock:
 | 
				
			||||||
	mutex_unlock(&defrag4_mutex);
 | 
						mutex_unlock(&defrag4_mutex);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue