Re: [PATCH] Fix overquota output result

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxx>
> ---
>  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.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux