From patchwork Tue Aug 4 10:02:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Neira Ayuso X-Patchwork-Id: 503484 X-Patchwork-Delegate: pablo@netfilter.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 23B6C1402D4 for ; Tue, 4 Aug 2015 19:57:21 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932973AbbHDJ5P (ORCPT ); Tue, 4 Aug 2015 05:57:15 -0400 Received: from mail.us.es ([193.147.175.20]:55949 "EHLO mail.us.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932474AbbHDJ5L (ORCPT ); Tue, 4 Aug 2015 05:57:11 -0400 Received: (qmail 29626 invoked from network); 4 Aug 2015 11:57:10 +0200 Received: from unknown (HELO us.es) (192.168.2.14) by us.es with SMTP; 4 Aug 2015 11:57:10 +0200 Received: (qmail 474 invoked by uid 507); 4 Aug 2015 09:57:10 -0000 X-Qmail-Scanner-Diagnostics: from 127.0.0.1 by antivirus4 (envelope-from , uid 501) with qmail-scanner-2.10 (clamdscan: 0.98.7/20763. spamassassin: 3.4.0. Clear:RC:1(127.0.0.1):SA:0(-100.0/7.5):. Processed in 1.933819 secs); 04 Aug 2015 09:57:10 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on antivirus4 X-Spam-Level: X-Spam-Status: No, score=-100.0 required=7.5 tests=BAYES_50,RCVD_IN_BRBL, RCVD_IN_BRBL_LASTEXT, RCVD_IN_PBL, RCVD_IN_SORBS_DUL, RDNS_DYNAMIC, SMTPAUTH_US, USER_IN_WHITELIST autolearn=disabled version=3.4.0 X-Spam-ASN: AS12353 93.108.0.0/16 X-Envelope-From: pablo@netfilter.org Received: from unknown (HELO antivirus4) (127.0.0.1) by us.es with SMTP; 4 Aug 2015 09:57:08 -0000 Received: from 192.168.1.13 (192.168.1.13) by antivirus4 (F-Secure/fsigk_smtp/412/antivirus4); Tue, 04 Aug 2015 11:57:08 +0200 (CEST) X-Virus-Status: clean(F-Secure/fsigk_smtp/412/antivirus4) Received: (qmail 16707 invoked from network); 4 Aug 2015 11:57:08 +0200 Received: from 113.101.108.93.rev.vodafone.pt (HELO salvia.VodafoneMobile.wifi) (pneira@us.es@93.108.101.113) by mail.us.es with SMTP; 4 Aug 2015 11:57:08 +0200 From: Pablo Neira Ayuso To: netfilter-devel@vger.kernel.org Cc: davem@davemloft.net, netdev@vger.kernel.org Subject: [PATCH 02/18] netfilter: Simply the tests for enabling and disabling the ingress queue hook Date: Tue, 4 Aug 2015 12:02:32 +0200 Message-Id: <1438682568-8346-3-git-send-email-pablo@netfilter.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1438682568-8346-1-git-send-email-pablo@netfilter.org> References: <1438682568-8346-1-git-send-email-pablo@netfilter.org> Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org From: "Eric W. Biederman" 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: "Eric W. Biederman" Signed-off-by: Pablo Neira Ayuso --- net/netfilter/core.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/net/netfilter/core.c b/net/netfilter/core.c index a0e5497..c4c3b85 100644 --- a/net/netfilter/core.c +++ b/net/netfilter/core.c @@ -74,7 +74,6 @@ int nf_register_hook(struct nf_hook_ops *reg) if (reg->hooknum == NF_NETDEV_INGRESS) { BUG_ON(reg->dev == NULL); nf_hook_list = ®->dev->nf_hooks_ingress; - net_inc_ingress_queue(); break; } #endif @@ -90,6 +89,10 @@ int nf_register_hook(struct nf_hook_ops *reg) } list_add_rcu(®->list, elem->list.prev); 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 static_key_slow_inc(&nf_hooks_needed[reg->pf][reg->hooknum]); #endif @@ -102,18 +105,10 @@ void nf_unregister_hook(struct nf_hook_ops *reg) mutex_lock(&nf_hook_mutex); list_del_rcu(®->list); mutex_unlock(&nf_hook_mutex); - switch (reg->pf) { - case NFPROTO_NETDEV: #ifdef CONFIG_NETFILTER_INGRESS - if (reg->hooknum == NF_NETDEV_INGRESS) { - net_dec_ingress_queue(); - break; - } - break; + if (reg->pf == NFPROTO_NETDEV && reg->hooknum == NF_NETDEV_INGRESS) + net_dec_ingress_queue(); #endif - default: - break; - } #ifdef HAVE_JUMP_LABEL static_key_slow_dec(&nf_hooks_needed[reg->pf][reg->hooknum]); #endif