All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Hunt <johunt@akamai.com>
To: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Cc: Eric B Munson <emunson@akamai.com>,
	netfilter-devel@vger.kernel.org,
	Pablo Neira Ayuso <pablo@netfilter.org>
Subject: Re: [PATCH RESEND] Add element count to hash headers
Date: Tue, 03 Mar 2015 21:34:06 -0600	[thread overview]
Message-ID: <54F67D2E.5050003@akamai.com> (raw)
In-Reply-To: <1424289208-6164-1-git-send-email-emunson@akamai.com>

[-- Attachment #1: Type: text/plain, Size: 5106 bytes --]

On 02/18/2015 01:53 PM, Eric B Munson wrote:
> 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 <emunson@akamai.com>
> Cc: Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
> Cc: Pablo Neira Ayuso <pablo@netfilter.org>
> Cc: Josh Hunt <johunt@akamai.com>
> ---
>   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, "</memsize>\n<references>");
>   		safe_dprintf(session, ipset_print_number, IPSET_OPT_REFERENCES);
> +		safe_snprintf(session, "</references>\n");
> +		if (MATCH_TYPENAME(type->name , "hash:")) {
> +			safe_snprintf(session, "<numentries>");
> +			safe_dprintf(session, ipset_print_number, IPSET_OPT_ELEMENTS);
> +			safe_snprintf(session, "</numentries>\n");
> +		}
>   		safe_snprintf(session,
>   			session->envopts & IPSET_ENV_LIST_HEADER ?
> -			"</references>\n</header>\n" :
> -			"</references>\n</header>\n<members>\n");
> +			"</header>\n" :
> +			"</header>\n<members>\n");
>   		break;
>   	default:
>   		break;
>

Jozsef

Can you clarify what you're looking for when you mentioned (in a 
previous mail) "I don't like any change which
affects the userspace but not expressed in new set type revision."? Are 
we breaking ABI here by adding a new field to print out the # of 
elements in a hash? Would it be better to default this to off and only 
print it if a new flag were presented?

I guess I don't see why we should rev all of the hash types for this 
change when we're not really adding any functionality to them. We can 
rev the ver of the library to signify a change here. Would that help?

If we do need to add a new revision I think we may want to step back and 
make sure there's no other information we want to expose first and if 
there is do it all in one shot to minimize the # of revisions.

Thanks for your help.
Josh


[-- Attachment #2: S/MIME Cryptographic Signature --]
[-- Type: application/pkcs7-signature, Size: 4566 bytes --]

  reply	other threads:[~2015-03-04  3:34 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-18 19:53 [PATCH RESEND] Add element count to hash headers Eric B Munson
2015-03-04  3:34 ` Josh Hunt [this message]
2015-03-04 14:39   ` Eric B Munson
2015-03-06 21:45   ` Jozsef Kadlecsik
2015-03-09 19:05     ` Eric B Munson
2015-03-11 19:20       ` Jozsef Kadlecsik
2015-03-19 17:38         ` Eric B Munson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54F67D2E.5050003@akamai.com \
    --to=johunt@akamai.com \
    --cc=emunson@akamai.com \
    --cc=kadlec@blackhole.kfki.hu \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=pablo@netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.