From patchwork Fri Dec 19 15:25:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric B Munson X-Patchwork-Id: 422902 X-Patchwork-Delegate: kadlec@blackhole.kfki.hu 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 48E7E140082 for ; Sat, 20 Dec 2014 02:35:05 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752078AbaLSPfE (ORCPT ); Fri, 19 Dec 2014 10:35:04 -0500 Received: from prod-mail-xrelay02.akamai.com ([72.246.2.14]:59884 "EHLO prod-mail-xrelay02.akamai.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752011AbaLSPfD (ORCPT ); Fri, 19 Dec 2014 10:35:03 -0500 X-Greylist: delayed 589 seconds by postgrey-1.27 at vger.kernel.org; Fri, 19 Dec 2014 10:35:02 EST Received: from prod-mail-xrelay02.akamai.com (localhost [127.0.0.1]) by postfix.imss70 (Postfix) with ESMTP id 69336284E4; Fri, 19 Dec 2014 15:25:12 +0000 (GMT) Received: from prod-mail-relay06.akamai.com (prod-mail-relay06.akamai.com [172.17.120.126]) by prod-mail-xrelay02.akamai.com (Postfix) with ESMTP id 4BCC9284D8; Fri, 19 Dec 2014 15:25:12 +0000 (GMT) Received: from lappy-486.kendall.corp.akamai.com (lappy-486.kendall.corp.akamai.com [172.28.12.253]) by prod-mail-relay06.akamai.com (Postfix) with ESMTP id 42971202D; Fri, 19 Dec 2014 15:25:12 +0000 (GMT) From: Eric B Munson To: netfilter-devel@vger.kernel.org Cc: Eric B Munson , Jozsef Kadlecsik , Josh Hunt Subject: [PATCH] Add element count to hash headers Date: Fri, 19 Dec 2014 10:25:09 -0500 Message-Id: <1419002709-4914-1-git-send-email-emunson@akamai.com> X-Mailer: git-send-email 1.9.1 Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org It would be useful for userspace to query the size of an ipset hash, however, this data is not exposed to userspace outside of counting the number of member entries. This patch uses the attribute IPSET_ATTR_ELEMENTS to indicate the size in the the header that is exported to userspace. This field is then printed by the userspace tool for hashes. Because it is only meaningful for hashes to report their size, the output is conditional on the set type. To do this checking the MATCH_TYPENAME macro was moved to utils.h. Signed-off-by: Eric B Munson Cc: Jozsef Kadlecsik Cc: Josh Hunt --- include/libipset/utils.h | 3 +++ kernel/net/netfilter/ipset/ip_set_hash_gen.h | 3 ++- lib/errcode.c | 2 -- lib/session.c | 14 ++++++++++++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/libipset/utils.h b/include/libipset/utils.h index 3cd29da..ceedd45 100644 --- a/include/libipset/utils.h +++ b/include/libipset/utils.h @@ -19,6 +19,9 @@ #define STRCASEQ(a, b) (strcasecmp(a, b) == 0) #define STRNCASEQ(a, b, n) (strncasecmp(a, b, n) == 0) +/* Match set type names */ +#define MATCH_TYPENAME(a, b) STRNEQ(a, b, strlen(b)) + /* Stringify tokens */ #define _STR(c) #c #define STR(c) _STR(c) diff --git a/kernel/net/netfilter/ipset/ip_set_hash_gen.h b/kernel/net/netfilter/ipset/ip_set_hash_gen.h index 885105b..2000a20 100644 --- a/kernel/net/netfilter/ipset/ip_set_hash_gen.h +++ b/kernel/net/netfilter/ipset/ip_set_hash_gen.h @@ -1040,7 +1040,8 @@ mtype_head(struct ip_set *set, struct sk_buff *skb) goto nla_put_failure; #endif if (nla_put_net32(skb, IPSET_ATTR_REFERENCES, htonl(set->ref - 1)) || - nla_put_net32(skb, IPSET_ATTR_MEMSIZE, htonl(memsize))) + nla_put_net32(skb, IPSET_ATTR_MEMSIZE, htonl(memsize)) || + nla_put_net32(skb, IPSET_ATTR_ELEMENTS, htonl(h->elements))) goto nla_put_failure; if (unlikely(ip_set_put_flags(skb, set))) goto nla_put_failure; diff --git a/lib/errcode.c b/lib/errcode.c index 8eb275b..3881121 100644 --- a/lib/errcode.c +++ b/lib/errcode.c @@ -148,8 +148,6 @@ static const struct ipset_errcode_table list_errcode_table[] = { { }, }; -#define MATCH_TYPENAME(a, b) STRNEQ(a, b, strlen(b)) - /** * ipset_errcode - interpret a kernel error code * @session: session structure diff --git a/lib/session.c b/lib/session.c index 013d9d8..07f3396 100644 --- a/lib/session.c +++ b/lib/session.c @@ -931,6 +931,10 @@ list_create(struct ipset_session *session, struct nlattr *nla[]) safe_dprintf(session, ipset_print_number, IPSET_OPT_MEMSIZE); safe_snprintf(session, "\nReferences: "); safe_dprintf(session, ipset_print_number, IPSET_OPT_REFERENCES); + if (MATCH_TYPENAME(type->name , "hash:")) { + safe_snprintf(session, "\nNum Entries: "); + safe_dprintf(session, ipset_print_number, IPSET_OPT_ELEMENTS); + } safe_snprintf(session, session->envopts & IPSET_ENV_LIST_HEADER ? "\n" : "\nMembers:\n"); @@ -940,10 +944,16 @@ list_create(struct ipset_session *session, struct nlattr *nla[]) safe_dprintf(session, ipset_print_number, IPSET_OPT_MEMSIZE); safe_snprintf(session, "\n"); safe_dprintf(session, ipset_print_number, IPSET_OPT_REFERENCES); + safe_snprintf(session, "\n"); + if (MATCH_TYPENAME(type->name , "hash:")) { + safe_snprintf(session, ""); + safe_dprintf(session, ipset_print_number, IPSET_OPT_ELEMENTS); + safe_snprintf(session, "\n"); + } safe_snprintf(session, session->envopts & IPSET_ENV_LIST_HEADER ? - "\n\n" : - "\n\n\n"); + "\n" : + "\n\n"); break; default: break;