From patchwork Tue Oct 20 22:20:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarno Rajahalme X-Patchwork-Id: 533524 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 31DF41401DE for ; Wed, 21 Oct 2015 09:21:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754376AbbJTWVJ (ORCPT ); Tue, 20 Oct 2015 18:21:09 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:36824 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754161AbbJTWU4 (ORCPT ); Tue, 20 Oct 2015 18:20:56 -0400 Received: by pacfv9 with SMTP id fv9so34638416pac.3 for ; Tue, 20 Oct 2015 15:20:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D8TM1Kxx7vKQasM6ELg/9qINsCVqvlG5pONRaK/WcpA=; b=HXOiLiZTRMcu2ybh9dWLVznAuUixJ6K5w1TObOVrRn/pcTeSaCoRIe2nj5gb0m4mRS +xAou57SZ0uwkYyGddSide45jJdL+olhAfLOQR5A+qTdIAnTXdfgO3/0D7Nuv7gtQnk6 cpU4/a8vAf7Pvot40pW4N/J/Qz8S0qgKV3rbfeu1V7N083zXsajRiGa91h7t0U3DSbSZ WsafG0gzIqvySaxX1NmhrmdgaJki6osuHiKhabi5ETt8wD2zAw7uXj4YHApHNFkUMY/Z FL/YTJJnCOoGOCh4MymdIUPeXr05zXSP2loh+L89AFUdo16i4GMS5F3apd7EsVymXHhz ds2g== X-Gm-Message-State: ALoCoQkfLEeL6DTgWVbVz7KL4/ky3VpJtC5E9iEJCcXr/npYk0V3MiBEJ9SkSlYDwaPigHr6NMlh X-Received: by 10.68.96.67 with SMTP id dq3mr6465338pbb.161.1445379656100; Tue, 20 Oct 2015 15:20:56 -0700 (PDT) Received: from sc9-mailhost3.vmware.com ([208.91.1.34]) by smtp.gmail.com with ESMTPSA id nz4sm5544866pbb.47.2015.10.20.15.20.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Oct 2015 15:20:55 -0700 (PDT) From: Jarno Rajahalme To: netdev@vger.kernel.org Cc: dev@openvswitch.org, jrajahalme@nicira.com Subject: [RFC PATCH 2/5] netfilter: Factor out nf_ct_get_info(). Date: Tue, 20 Oct 2015 15:20:26 -0700 Message-Id: <1445379629-112880-2-git-send-email-jrajahalme@nicira.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1445379629-112880-1-git-send-email-jrajahalme@nicira.com> References: <1445379629-112880-1-git-send-email-jrajahalme@nicira.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Define a new inline function to map conntrack status to enum ip_conntrack_info. This removes the need to otherwise duplicate this code in a later patch. Signed-off-by: Jarno Rajahalme --- include/net/netfilter/nf_conntrack.h | 15 +++++++++++++++ net/netfilter/nf_conntrack_core.c | 22 +++------------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h index fde4068..b3de10e 100644 --- a/include/net/netfilter/nf_conntrack.h +++ b/include/net/netfilter/nf_conntrack.h @@ -125,6 +125,21 @@ nf_ct_tuplehash_to_ctrack(const struct nf_conntrack_tuple_hash *hash) tuplehash[hash->tuple.dst.dir]); } +static inline enum ip_conntrack_info +nf_ct_get_info(const struct nf_conntrack_tuple_hash *h) +{ + const struct nf_conn *ct = nf_ct_tuplehash_to_ctrack(h); + + if (NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY) + return IP_CT_ESTABLISHED_REPLY; + /* Once we've had two way comms, always ESTABLISHED. */ + if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) + return IP_CT_ESTABLISHED; + if (test_bit(IPS_EXPECTED_BIT, &ct->status)) + return IP_CT_RELATED; + return IP_CT_NEW; +} + static inline u_int16_t nf_ct_l3num(const struct nf_conn *ct) { return ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num; diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c index 3cb3cb8..70ddbd8 100644 --- a/net/netfilter/nf_conntrack_core.c +++ b/net/netfilter/nf_conntrack_core.c @@ -1056,25 +1056,9 @@ resolve_normal_ct(struct net *net, struct nf_conn *tmpl, ct = nf_ct_tuplehash_to_ctrack(h); /* It exists; we have (non-exclusive) reference. */ - if (NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY) { - *ctinfo = IP_CT_ESTABLISHED_REPLY; - /* Please set reply bit if this packet OK */ - *set_reply = 1; - } else { - /* Once we've had two way comms, always ESTABLISHED. */ - if (test_bit(IPS_SEEN_REPLY_BIT, &ct->status)) { - pr_debug("nf_conntrack_in: normal packet for %p\n", ct); - *ctinfo = IP_CT_ESTABLISHED; - } else if (test_bit(IPS_EXPECTED_BIT, &ct->status)) { - pr_debug("nf_conntrack_in: related packet for %p\n", - ct); - *ctinfo = IP_CT_RELATED; - } else { - pr_debug("nf_conntrack_in: new packet for %p\n", ct); - *ctinfo = IP_CT_NEW; - } - *set_reply = 0; - } + *ctinfo = nf_ct_get_info(h); + *set_reply = NF_CT_DIRECTION(h) == IP_CT_DIR_REPLY; + skb->nfct = &ct->ct_general; skb->nfctinfo = *ctinfo; return ct;