Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4c091156 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Pablo Neira Ayuso
Browse files

netfilter: Simply the tests for enabling and disabling the ingress queue hook



Replace an overcomplicated switch statement with a simple if statement.

This also removes the ingress queue enable outside of nf_hook_mutex as
the protection provided by the mutex is not necessary and the code is
clearer having both of the static key increments together.

Signed-off-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 70aa9966
Loading
Loading
Loading
Loading
+6 −11
Original line number Original line Diff line number Diff line
@@ -74,7 +74,6 @@ int nf_register_hook(struct nf_hook_ops *reg)
		if (reg->hooknum == NF_NETDEV_INGRESS) {
		if (reg->hooknum == NF_NETDEV_INGRESS) {
			BUG_ON(reg->dev == NULL);
			BUG_ON(reg->dev == NULL);
			nf_hook_list = &reg->dev->nf_hooks_ingress;
			nf_hook_list = &reg->dev->nf_hooks_ingress;
			net_inc_ingress_queue();
			break;
			break;
		}
		}
#endif
#endif
@@ -90,6 +89,10 @@ int nf_register_hook(struct nf_hook_ops *reg)
	}
	}
	list_add_rcu(&reg->list, elem->list.prev);
	list_add_rcu(&reg->list, elem->list.prev);
	mutex_unlock(&nf_hook_mutex);
	mutex_unlock(&nf_hook_mutex);
#ifdef CONFIG_NETFILTER_INGRESS
	if (reg->pf == NFPROTO_NETDEV && reg->hooknum == NF_NETDEV_INGRESS)
		net_inc_ingress_queue();
#endif
#ifdef HAVE_JUMP_LABEL
#ifdef HAVE_JUMP_LABEL
	static_key_slow_inc(&nf_hooks_needed[reg->pf][reg->hooknum]);
	static_key_slow_inc(&nf_hooks_needed[reg->pf][reg->hooknum]);
#endif
#endif
@@ -102,18 +105,10 @@ void nf_unregister_hook(struct nf_hook_ops *reg)
	mutex_lock(&nf_hook_mutex);
	mutex_lock(&nf_hook_mutex);
	list_del_rcu(&reg->list);
	list_del_rcu(&reg->list);
	mutex_unlock(&nf_hook_mutex);
	mutex_unlock(&nf_hook_mutex);
	switch (reg->pf) {
	case NFPROTO_NETDEV:
#ifdef CONFIG_NETFILTER_INGRESS
#ifdef CONFIG_NETFILTER_INGRESS
		if (reg->hooknum == NF_NETDEV_INGRESS) {
	if (reg->pf == NFPROTO_NETDEV && reg->hooknum == NF_NETDEV_INGRESS)
		net_dec_ingress_queue();
		net_dec_ingress_queue();
			break;
		}
		break;
#endif
#endif
	default:
		break;
	}
#ifdef HAVE_JUMP_LABEL
#ifdef HAVE_JUMP_LABEL
	static_key_slow_dec(&nf_hooks_needed[reg->pf][reg->hooknum]);
	static_key_slow_dec(&nf_hooks_needed[reg->pf][reg->hooknum]);
#endif
#endif