All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2 net-next] ip: add a new parameter -Numeric
@ 2019-05-20  7:56 Hangbin Liu
  2019-05-20 10:24 ` Phil Sutter
  2019-05-20 15:18 ` David Ahern
  0 siblings, 2 replies; 6+ messages in thread
From: Hangbin Liu @ 2019-05-20  7:56 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern, Phil Sutter, Stephen Hemminger, Hangbin Liu

When calles rtnl_dsfield_n2a(), we get the dsfield name from
/etc/iproute2/rt_dsfield. But different distribution may have
different names. So add a new parameter '-Numeric' to only show
the dsfield number.

This parameter is only used for tos value at present. We could enable
this for other fields if needed in the future.

Suggested-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
---
 include/utils.h | 1 +
 ip/ip.c         | 6 +++++-
 lib/rt_names.c  | 4 +++-
 man/man8/ip.8   | 6 ++++++
 4 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/include/utils.h b/include/utils.h
index 8a9c3020..0f57ee97 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -34,6 +34,7 @@ extern int timestamp_short;
 extern const char * _SL_;
 extern int max_flush_loops;
 extern int batch_mode;
+extern int numeric;
 extern bool do_all;
 
 #ifndef CONFDIR
diff --git a/ip/ip.c b/ip/ip.c
index e4131714..2db5bbb0 100644
--- a/ip/ip.c
+++ b/ip/ip.c
@@ -36,6 +36,7 @@ int timestamp;
 int force;
 int max_flush_loops = 10;
 int batch_mode;
+int numeric;
 bool do_all;
 
 struct rtnl_handle rth = { .fd = -1 };
@@ -57,7 +58,8 @@ static void usage(void)
 "                    -4 | -6 | -I | -D | -M | -B | -0 |\n"
 "                    -l[oops] { maximum-addr-flush-attempts } | -br[ief] |\n"
 "                    -o[neline] | -t[imestamp] | -ts[hort] | -b[atch] [filename] |\n"
-"                    -rc[vbuf] [size] | -n[etns] name | -a[ll] | -c[olor]}\n");
+"                    -rc[vbuf] [size] | -n[etns] name | -N[umeric]} | -a[ll] |\n"
+"                    -c[olor]}\n");
 	exit(-1);
 }
 
@@ -287,6 +289,8 @@ int main(int argc, char **argv)
 			NEXT_ARG();
 			if (netns_switch(argv[1]))
 				exit(-1);
+		} else if (matches(opt, "-Numeric") == 0) {
+			++numeric;
 		} else if (matches(opt, "-all") == 0) {
 			do_all = true;
 		} else {
diff --git a/lib/rt_names.c b/lib/rt_names.c
index 66d5f2f0..122bdd74 100644
--- a/lib/rt_names.c
+++ b/lib/rt_names.c
@@ -27,6 +27,8 @@
 
 #define NAME_MAX_LEN 512
 
+int numeric;
+
 struct rtnl_hash_entry {
 	struct rtnl_hash_entry	*next;
 	const char		*name;
@@ -480,7 +482,7 @@ const char *rtnl_dsfield_n2a(int id, char *buf, int len)
 		snprintf(buf, len, "%d", id);
 		return buf;
 	}
-	if (!rtnl_rtdsfield_tab[id]) {
+	if (!rtnl_rtdsfield_tab[id] && !numeric) {
 		if (!rtnl_rtdsfield_init)
 			rtnl_rtdsfield_initialize();
 	}
diff --git a/man/man8/ip.8 b/man/man8/ip.8
index f4cbfc03..c2a8a92d 100644
--- a/man/man8/ip.8
+++ b/man/man8/ip.8
@@ -47,6 +47,7 @@ ip \- show / manipulate routing, network devices, interfaces and tunnels
 \fB\-t\fR[\fIimestamp\fR] |
 \fB\-ts\fR[\fIhort\fR] |
 \fB\-n\fR[\fIetns\fR] name |
+\fB\-N\fR[\fIumeric\fR] |
 \fB\-a\fR[\fIll\fR] |
 \fB\-c\fR[\fIolor\fR] |
 \fB\-br\fR[\fIief\fR] |
@@ -174,6 +175,11 @@ to
 .RI "-n[etns] " NETNS " [ " OPTIONS " ] " OBJECT " { " COMMAND " | "
 .BR help " }"
 
+.TP
+.BR "\-N" , " \-Numeric"
+Print the dsfield's numeric directly instead of converting to the name from
+/etc/iproute2/rt_dsfield.
+
 .TP
 .BR "\-a" , " \-all"
 executes specified command over all objects, it depends if command
-- 
2.19.2


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

end of thread, other threads:[~2019-05-21 21:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-20  7:56 [PATCH iproute2 net-next] ip: add a new parameter -Numeric Hangbin Liu
2019-05-20 10:24 ` Phil Sutter
2019-05-20 15:18 ` David Ahern
2019-05-20 17:03   ` Stephen Hemminger
2019-05-21 12:13     ` Hangbin Liu
2019-05-21 21:20       ` David Ahern

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.