netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Fix overquota output result
@ 2014-07-30 15:25 Alexey Perevalov
  2014-07-30 15:25 ` Alexey Perevalov
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey Perevalov @ 2014-07-30 15:25 UTC (permalink / raw)
  To: pablo
  Cc: Alexey Perevalov, alexey.perevalov, mathieu.poirier,
	netfilter-devel, kyungmin.park, hs81.go

This patch fixes client side of nfacct report.
For details, see kernel patches in "fixes for NFACCT_F_OVERQUOTA usage" thread.
After this fix kernel bugs became visible.

Alexey Perevalov (1):
  Fix overquota output result

 src/libnetfilter_acct.c |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Fix overquota output result
  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
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey Perevalov @ 2014-07-30 15:25 UTC (permalink / raw)
  To: pablo
  Cc: Alexey Perevalov, alexey.perevalov, mathieu.poirier,
	netfilter-devel, kyungmin.park, hs81.go

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);
+			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);
 		}
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix overquota output result
  2014-07-30 15:25 ` Alexey Perevalov
@ 2014-07-30 17:01   ` Pablo Neira Ayuso
  2014-07-31 13:12     ` [PATCH v2] " Alexey Perevalov
  0 siblings, 1 reply; 5+ messages in thread
From: Pablo Neira Ayuso @ 2014-07-30 17:01 UTC (permalink / raw)
  To: Alexey Perevalov
  Cc: alexey.perevalov, mathieu.poirier, netfilter-devel, kyungmin.park,
	hs81.go

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2] Fix overquota output result
  2014-07-30 17:01   ` Pablo Neira Ayuso
@ 2014-07-31 13:12     ` Alexey Perevalov
  2014-07-31 18:46       ` Pablo Neira Ayuso
  0 siblings, 1 reply; 5+ messages in thread
From: Alexey Perevalov @ 2014-07-31 13:12 UTC (permalink / raw)
  To: pablo
  Cc: Alexey Perevalov, alexey.perevalov, mathieu.poirier,
	netfilter-devel, kyungmin.park, hs81.go

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.

This commmit adds additional column - overquota with yes/no value.

Signed-off-by: Alexey Perevalov <a.perevalov@samsung.com>
---
 src/libnetfilter_acct.c |   19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/libnetfilter_acct.c b/src/libnetfilter_acct.c
index 7f539b6..0156c9a 100644
--- a/src/libnetfilter_acct.c
+++ b/src/libnetfilter_acct.c
@@ -266,15 +266,22 @@ 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;
+			if (mode & NFACCT_F_QUOTA_PKTS)
+				mode_name = "packet";
+			else if (mode & NFACCT_F_QUOTA_BYTES)
+				mode_name = "byte";
+			else
+				mode_name = "unknown";
 
 			ret = snprintf(buf + offset, rem,
-				", quota = %.20"PRIu64", mode = %s",
+				", quota = %.20"PRIu64", mode = %s"\
+				", overquota = %s",
 				nfacct_attr_get_u64(nfacct, NFACCT_ATTR_QUOTA),
-				mode == NFACCT_F_QUOTA_BYTES ?
-				"byte" : "packet");
+				mode_name,
+				mode & NFACCT_F_OVERQUOTA ? "yes" : "no");
 			SNPRINTF_CHECK(ret, rem, offset, len);
 		}
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Fix overquota output result
  2014-07-31 13:12     ` [PATCH v2] " Alexey Perevalov
@ 2014-07-31 18:46       ` Pablo Neira Ayuso
  0 siblings, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2014-07-31 18:46 UTC (permalink / raw)
  To: Alexey Perevalov
  Cc: alexey.perevalov, mathieu.poirier, netfilter-devel, kyungmin.park,
	hs81.go

On Thu, Jul 31, 2014 at 05:12:33PM +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.
> 
> This commmit adds additional column - overquota with yes/no value.

Applied, thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-07-31 18:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-07-31 13:12     ` [PATCH v2] " Alexey Perevalov
2014-07-31 18:46       ` Pablo Neira Ayuso

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).