From patchwork Mon Mar 14 06:50:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Changli Gao X-Patchwork-Id: 86681 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 B8797B6F87 for ; Mon, 14 Mar 2011 17:51:48 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754129Ab1CNGvo (ORCPT ); Mon, 14 Mar 2011 02:51:44 -0400 Received: from mail-iw0-f174.google.com ([209.85.214.174]:41059 "EHLO mail-iw0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753966Ab1CNGvn (ORCPT ); Mon, 14 Mar 2011 02:51:43 -0400 Received: by iwn34 with SMTP id 34so4630478iwn.19 for ; Sun, 13 Mar 2011 23:51:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references; bh=dQIG9kuqFwsIQC16nofgMnArY0FLCJK/BLFjngSf1zc=; b=kbx5jcRd4OuJLjD1Jf1yZI6GGdRW5qmPLztKDbnlVPsiiBBtUIswHnw1HoWTH43zL/ 6OwQp0ToGKVLZRyzjrMjp0yh1fhNTmTpMAdli9ghTeUPKVlZW1N0qDm+BTdlzj8Za1D2 firIfjwXiRxXtL6FSupFvK1y8I6r5hXqhAAFM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; b=wkWEIz17GZ28SvGbG8Z/B/wFlP+fHRiMAGSp/GrU/w7tdTw/OHzSnF4I/tai5poNpz kSCHzuFvL5KqJ+Il2erssHUDTm+83St5wcppAxOvACydrsxDPnlo+/6wd7spvH8tMNry KdDR8Y5o5WXuB+cuvBiK/CMr2PQ9Dg26u7WUg= Received: by 10.43.54.134 with SMTP id vu6mr1313994icb.501.1300085502501; Sun, 13 Mar 2011 23:51:42 -0700 (PDT) Received: from localhost.localdomain ([221.239.34.230]) by mx.google.com with ESMTPS id d10sm6372832ibb.12.2011.03.13.23.51.30 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 13 Mar 2011 23:51:41 -0700 (PDT) From: Changli Gao To: Patrick McHardy Cc: "David S. Miller" , netfilter-devel@vger.kernel.org, netdev@vger.kernel.org, Changli Gao Subject: [PATCH 3/4] netfilter: xt_connlimit: use hlist instead Date: Mon, 14 Mar 2011 14:50:13 +0800 Message-Id: <1300085414-27275-3-git-send-email-xiaosuo@gmail.com> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1300085414-27275-1-git-send-email-xiaosuo@gmail.com> References: <1300085414-27275-1-git-send-email-xiaosuo@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The header of hlist is smaller than list. Signed-off-by: Changli Gao --- net/netfilter/xt_connlimit.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c index ade2a80..da56d6e 100644 --- a/net/netfilter/xt_connlimit.c +++ b/net/netfilter/xt_connlimit.c @@ -33,14 +33,14 @@ /* we will save the tuples of all connections we care about */ struct xt_connlimit_conn { - struct list_head list; + struct hlist_node node; struct nf_conntrack_tuple tuple; union nf_inet_addr addr; }; struct xt_connlimit_data { - struct list_head iphash[256]; - spinlock_t lock; + struct hlist_head iphash[256]; + spinlock_t lock; }; static u_int32_t connlimit_rnd __read_mostly; @@ -102,9 +102,9 @@ static int count_them(struct net *net, { const struct nf_conntrack_tuple_hash *found; struct xt_connlimit_conn *conn; - struct xt_connlimit_conn *tmp; + struct hlist_node *pos, *n; struct nf_conn *found_ct; - struct list_head *hash; + struct hlist_head *hash; bool addit = true; int matches = 0; @@ -116,7 +116,7 @@ static int count_them(struct net *net, rcu_read_lock(); /* check the saved connections */ - list_for_each_entry_safe(conn, tmp, hash, list) { + hlist_for_each_entry_safe(conn, pos, n, hash, node) { found = nf_conntrack_find_get(net, NF_CT_DEFAULT_ZONE, &conn->tuple); found_ct = NULL; @@ -136,7 +136,7 @@ static int count_them(struct net *net, if (found == NULL) { /* this one is gone */ - list_del(&conn->list); + hlist_del(&conn->node); kfree(conn); continue; } @@ -147,7 +147,7 @@ static int count_them(struct net *net, * closed already -> ditch it */ nf_ct_put(found_ct); - list_del(&conn->list); + hlist_del(&conn->node); kfree(conn); continue; } @@ -167,7 +167,7 @@ static int count_them(struct net *net, return -ENOMEM; conn->tuple = *tuple; conn->addr = *addr; - list_add(&conn->list, hash); + hlist_add_head(&conn->node, hash); ++matches; } @@ -246,7 +246,7 @@ static int connlimit_mt_check(const struct xt_mtchk_param *par) spin_lock_init(&info->data->lock); for (i = 0; i < ARRAY_SIZE(info->data->iphash); ++i) - INIT_LIST_HEAD(&info->data->iphash[i]); + INIT_HLIST_HEAD(&info->data->iphash[i]); return 0; } @@ -255,15 +255,15 @@ static void connlimit_mt_destroy(const struct xt_mtdtor_param *par) { const struct xt_connlimit_info *info = par->matchinfo; struct xt_connlimit_conn *conn; - struct xt_connlimit_conn *tmp; - struct list_head *hash = info->data->iphash; + struct hlist_node *pos, *n; + struct hlist_head *hash = info->data->iphash; unsigned int i; nf_ct_l3proto_module_put(par->family); for (i = 0; i < ARRAY_SIZE(info->data->iphash); ++i) { - list_for_each_entry_safe(conn, tmp, &hash[i], list) { - list_del(&conn->list); + hlist_for_each_entry_safe(conn, pos, n, &hash[i], node) { + hlist_del(&conn->node); kfree(conn); } }