All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] nstat: case-insensitive pattern matching
@ 2020-07-08 12:38 Anton Danilov
  2020-07-08 15:28 ` Stephen Hemminger
  2020-07-08 15:40 ` [PATCH iproute2] nstat: case-insensitive pattern matching Stephen Hemminger
  0 siblings, 2 replies; 6+ messages in thread
From: Anton Danilov @ 2020-07-08 12:38 UTC (permalink / raw)
  To: netdev; +Cc: stephen, Anton Danilov

The option 'nocase' allows ignore case in the pattern matching.

Examples:
    nstat --nocase *drop*
    nstat -azi icmp*

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 man/man8/rtacct.8 |  8 +++++++-
 misc/nstat.c      | 14 ++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/man/man8/rtacct.8 b/man/man8/rtacct.8
index ccdbf6ca..cb6ac912 100644
--- a/man/man8/rtacct.8
+++ b/man/man8/rtacct.8
@@ -4,7 +4,7 @@
 nstat, rtacct - network statistics tools.
 
 .SH SYNOPSIS
-Usage: nstat [ -h?vVzrnasd:t:jp ] [ PATTERN [ PATTERN ] ]
+Usage: nstat [ -h?vVzrnasd:t:jpi ] [ PATTERN [ PATTERN ] ]
 .br
 Usage: rtacct [ -h?vVzrnasd:t: ] [ ListOfRealms ]
 
@@ -14,6 +14,9 @@ and
 .B rtacct
 are simple tools to monitor kernel snmp counters and network interface statistics.
 
+.B nstat
+can filter kernel snmp counters by name with one or several specified wildcards.
+
 .SH OPTIONS
 .B \-h, \-\-help
 Print help
@@ -44,6 +47,9 @@ When combined with
 .BR \-\-json ,
 pretty print the output.
 .TP
+.B \-i, \-\-nocase
+Ignore case in pattern matching.
+.TP
 .B \-d, \-\-scan <INTERVAL>
 Run in daemon mode collecting statistics. <INTERVAL> is interval between measurements in seconds.
 .TP
diff --git a/misc/nstat.c b/misc/nstat.c
index 425e75ef..243caebe 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -43,6 +43,7 @@ int time_constant;
 double W;
 char **patterns;
 int npatterns;
+int nocase;
 
 char info_source[128];
 int source_mismatch;
@@ -114,7 +115,7 @@ static int match(const char *id)
 		return 1;
 
 	for (i = 0; i < npatterns; i++) {
-		if (!fnmatch(patterns[i], id, 0))
+		if (!fnmatch(patterns[i], id, nocase ? FNM_CASEFOLD : 0))
 			return 1;
 	}
 	return 0;
@@ -551,6 +552,7 @@ static void usage(void)
 		"   -h, --help		this message\n"
 		"   -a, --ignore	ignore history\n"
 		"   -d, --scan=SECS	sample every statistics every SECS\n"
+		"   -i, --nocase	ignore case in pattern matching\n"
 		"   -j, --json		format output in JSON\n"
 		"   -n, --nooutput	do history only\n"
 		"   -p, --pretty	pretty print\n"
@@ -566,11 +568,12 @@ static const struct option longopts[] = {
 	{ "help", 0, 0, 'h' },
 	{ "ignore",  0,  0, 'a' },
 	{ "scan", 1, 0, 'd'},
-	{ "nooutput", 0, 0, 'n' },
+	{ "nocase", 0, 0, 'i' },
 	{ "json", 0, 0, 'j' },
+	{ "nooutput", 0, 0, 'n' },
+	{ "pretty", 0, 0, 'p' },
 	{ "reset", 0, 0, 'r' },
 	{ "noupdate", 0, 0, 's' },
-	{ "pretty", 0, 0, 'p' },
 	{ "interval", 1, 0, 't' },
 	{ "version", 0, 0, 'V' },
 	{ "zeros", 0, 0, 'z' },
@@ -585,7 +588,7 @@ int main(int argc, char *argv[])
 	int ch;
 	int fd;
 
-	while ((ch = getopt_long(argc, argv, "h?vVzrnasd:t:jp",
+	while ((ch = getopt_long(argc, argv, "h?vVzrnasd:t:jpi",
 				 longopts, NULL)) != EOF) {
 		switch (ch) {
 		case 'z':
@@ -619,6 +622,9 @@ int main(int argc, char *argv[])
 		case 'p':
 			pretty = 1;
 			break;
+		case 'i':
+			nocase = 1;
+			break;
 		case 'v':
 		case 'V':
 			printf("nstat utility, iproute2-ss%s\n", SNAPSHOT);
-- 
2.26.2


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

* Re: [PATCH iproute2] nstat: case-insensitive pattern matching
  2020-07-08 12:38 [PATCH iproute2] nstat: case-insensitive pattern matching Anton Danilov
@ 2020-07-08 15:28 ` Stephen Hemminger
  2020-07-09 15:03   ` [PATCH v2 iproute2] misc: make the pattern matching case-insensitive Anton Danilov
  2020-07-08 15:40 ` [PATCH iproute2] nstat: case-insensitive pattern matching Stephen Hemminger
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2020-07-08 15:28 UTC (permalink / raw)
  To: Anton Danilov; +Cc: netdev

On Wed,  8 Jul 2020 15:38:02 +0300
Anton Danilov <littlesmilingcloud@gmail.com> wrote:

> The option 'nocase' allows ignore case in the pattern matching.
> 
> Examples:
>     nstat --nocase *drop*
>     nstat -azi icmp*
> 
> Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>

Why not just make it the default?
I can't imagine a scenario where user would want to match on icmp different than ICMP


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

* Re: [PATCH iproute2] nstat: case-insensitive pattern matching
  2020-07-08 12:38 [PATCH iproute2] nstat: case-insensitive pattern matching Anton Danilov
  2020-07-08 15:28 ` Stephen Hemminger
@ 2020-07-08 15:40 ` Stephen Hemminger
  2020-07-08 21:48   ` Anton Danilov
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2020-07-08 15:40 UTC (permalink / raw)
  To: Anton Danilov; +Cc: netdev

On Wed,  8 Jul 2020 15:38:02 +0300
Anton Danilov <littlesmilingcloud@gmail.com> wrote:

> The option 'nocase' allows ignore case in the pattern matching.
> 
> Examples:
>     nstat --nocase *drop*
>     nstat -azi icmp*
> 
> Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>

On second thought, this looks like a good idea.
Perhaps it should also be applied to ifstat and ss.

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

* Re: [PATCH iproute2] nstat: case-insensitive pattern matching
  2020-07-08 15:40 ` [PATCH iproute2] nstat: case-insensitive pattern matching Stephen Hemminger
@ 2020-07-08 21:48   ` Anton Danilov
  0 siblings, 0 replies; 6+ messages in thread
From: Anton Danilov @ 2020-07-08 21:48 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Linux Kernel Network Developers

Hello, Stephen.

Thanks for feedback.

> Why not just make it the default?
> I can't imagine a scenario where user would want to match on icmp different than ICMP

Yes, I'm agreed. I'll make it the default in the v2 patch.

> Perhaps it should also be applied to ifstat and ss.

I'll prepare the patches for ifstat ans ss too.

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

* [PATCH v2 iproute2] misc: make the pattern matching case-insensitive
  2020-07-08 15:28 ` Stephen Hemminger
@ 2020-07-09 15:03   ` Anton Danilov
  2020-07-20 20:30     ` Stephen Hemminger
  0 siblings, 1 reply; 6+ messages in thread
From: Anton Danilov @ 2020-07-09 15:03 UTC (permalink / raw)
  To: netdev; +Cc: stephen, Anton Danilov

To improve the usability better use case-insensitive pattern-matching
in ifstat, nstat and ss tools.

Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>
---
 man/man8/rtacct.8 | 7 +++++++
 misc/ifstat.c     | 2 +-
 misc/nstat.c      | 2 +-
 misc/ss.c         | 2 +-
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/man/man8/rtacct.8 b/man/man8/rtacct.8
index ccdbf6ca..988a6d1b 100644
--- a/man/man8/rtacct.8
+++ b/man/man8/rtacct.8
@@ -14,6 +14,13 @@ and
 .B rtacct
 are simple tools to monitor kernel snmp counters and network interface statistics.
 
+.B nstat
+can filter kernel snmp counters by name with one or several specified wildcards. Wildcards are case-insensitive and can include special symbols
+.B ?
+and
+.B *
+.
+
 .SH OPTIONS
 .B \-h, \-\-help
 Print help
diff --git a/misc/ifstat.c b/misc/ifstat.c
index 60efe6cb..03327af8 100644
--- a/misc/ifstat.c
+++ b/misc/ifstat.c
@@ -104,7 +104,7 @@ static int match(const char *id)
 		return 1;
 
 	for (i = 0; i < npatterns; i++) {
-		if (!fnmatch(patterns[i], id, 0))
+		if (!fnmatch(patterns[i], id, FNM_CASEFOLD))
 			return 1;
 	}
 	return 0;
diff --git a/misc/nstat.c b/misc/nstat.c
index 425e75ef..88f52eaf 100644
--- a/misc/nstat.c
+++ b/misc/nstat.c
@@ -114,7 +114,7 @@ static int match(const char *id)
 		return 1;
 
 	for (i = 0; i < npatterns; i++) {
-		if (!fnmatch(patterns[i], id, 0))
+		if (!fnmatch(patterns[i], id, FNM_CASEFOLD))
 			return 1;
 	}
 	return 0;
diff --git a/misc/ss.c b/misc/ss.c
index f3d01812..5aa10e4a 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -1670,7 +1670,7 @@ static int unix_match(const inet_prefix *a, const inet_prefix *p)
 		return 1;
 	if (addr == NULL)
 		addr = "";
-	return !fnmatch(pattern, addr, 0);
+	return !fnmatch(pattern, addr, FNM_CASEFOLD);
 }
 
 static int run_ssfilter(struct ssfilter *f, struct sockstat *s)
-- 
2.26.2


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

* Re: [PATCH v2 iproute2] misc: make the pattern matching case-insensitive
  2020-07-09 15:03   ` [PATCH v2 iproute2] misc: make the pattern matching case-insensitive Anton Danilov
@ 2020-07-20 20:30     ` Stephen Hemminger
  0 siblings, 0 replies; 6+ messages in thread
From: Stephen Hemminger @ 2020-07-20 20:30 UTC (permalink / raw)
  To: Anton Danilov; +Cc: netdev

On Thu,  9 Jul 2020 18:03:43 +0300
Anton Danilov <littlesmilingcloud@gmail.com> wrote:

> To improve the usability better use case-insensitive pattern-matching
> in ifstat, nstat and ss tools.
> 
> Signed-off-by: Anton Danilov <littlesmilingcloud@gmail.com>

Applied

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

end of thread, other threads:[~2020-07-20 20:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-08 12:38 [PATCH iproute2] nstat: case-insensitive pattern matching Anton Danilov
2020-07-08 15:28 ` Stephen Hemminger
2020-07-09 15:03   ` [PATCH v2 iproute2] misc: make the pattern matching case-insensitive Anton Danilov
2020-07-20 20:30     ` Stephen Hemminger
2020-07-08 15:40 ` [PATCH iproute2] nstat: case-insensitive pattern matching Stephen Hemminger
2020-07-08 21:48   ` Anton Danilov

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.