netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Alexey Perevalov <a.perevalov@samsung.com>
Cc: alexey.perevalov@hotmail.com, mathieu.poirier@linaro.org,
	netfilter-devel@vger.kernel.org, kyungmin.park@samsung.com,
	hs81.go@samsung.com
Subject: Re: [PATCH] Fix overquota output result
Date: Wed, 30 Jul 2014 19:01:15 +0200	[thread overview]
Message-ID: <20140730170115.GA6364@salvia> (raw)
In-Reply-To: <1406733925-5344-2-git-send-email-a.perevalov@samsung.com>

On Wed, Jul 30, 2014 at 07:25:25PM +0400, Alexey Perevalov wrote:
> Current implementation shows "packet" for none byte quota type.
> It means "packet" was used for overquota counter as well and it
> wasn't so informative.
> 
> Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
> ---
>  src/libnetfilter_acct.c |   22 +++++++++++++++-------
>  1 file changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/src/libnetfilter_acct.c b/src/libnetfilter_acct.c
> index 7f539b6..9ed50c9 100644
> --- a/src/libnetfilter_acct.c
> +++ b/src/libnetfilter_acct.c
> @@ -266,15 +266,23 @@ nfacct_snprintf_plain(char *buf, size_t rem, struct nfacct *nfacct,
>  		SNPRINTF_CHECK(ret, rem, offset, len);
>  
>  		if (nfacct->flags) {
> -			uint32_t mode;
> -
> -			mode = nfacct_attr_get_u64(nfacct, NFACCT_ATTR_FLAGS);
> -
> +			const uint32_t mode = nfacct_attr_get_u64(nfacct,
> +				NFACCT_ATTR_FLAGS);
> +			char *mode_name = NULL, *overquota = NULL;
> +			printf("mode %u", mode);

I guess this just accidentally slipped through.

> +			if (mode & NFACCT_F_QUOTA_PKTS)
> +				mode_name = "packet";
> +			else if (mode & NFACCT_F_QUOTA_BYTES)
> +				mode_name = "byte";
> +
> +			if (mode & NFACCT_F_OVERQUOTA)
> +				overquota = " overquota";
> +			else
> +				overquota = "";
>  			ret = snprintf(buf + offset, rem,
> -				", quota = %.20"PRIu64", mode = %s",
> +				", quota = %.20"PRIu64", mode = %s%s",
>  				nfacct_attr_get_u64(nfacct, NFACCT_ATTR_QUOTA),
> -				mode == NFACCT_F_QUOTA_BYTES ?
> -				"byte" : "packet");
> +				mode_name, overquota);
>  			SNPRINTF_CHECK(ret, rem, offset, len);

I prefer if this is represented in this way:

quota = ..., mode = ..., overquota = yes }

or

overquota = no

depending on the result. If there is some people parsing this CSV
already, if they are doing it in some sane way they will just skip
unknown keys.

Thanks.

  reply	other threads:[~2014-07-30 17:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-30 15:25 [PATCH] Fix overquota output result Alexey Perevalov
2014-07-30 15:25 ` Alexey Perevalov
2014-07-30 17:01   ` Pablo Neira Ayuso [this message]
2014-07-31 13:12     ` [PATCH v2] " Alexey Perevalov
2014-07-31 18:46       ` Pablo Neira Ayuso

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=20140730170115.GA6364@salvia \
    --to=pablo@netfilter.org \
    --cc=a.perevalov@samsung.com \
    --cc=alexey.perevalov@hotmail.com \
    --cc=hs81.go@samsung.com \
    --cc=kyungmin.park@samsung.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=netfilter-devel@vger.kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).