[PATCH] Print route tables as an integer versus hex

David Ahern dsa at cumulusnetworks.com
Tue Apr 12 14:00:28 PDT 2016


route tables as an integer are more usable than hex.

Signed-off-by: David Ahern <dsa at cumulusnetworks.com>
---
 include/netlink-private/netlink.h |  1 +
 lib/route/route_utils.c           |  2 +-
 lib/utils.c                       | 21 ++++++++++++++++++---
 libnl-3.sym                       |  1 +
 4 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/include/netlink-private/netlink.h b/include/netlink-private/netlink.h
index befd3014afcb..c8a59640d853 100644
--- a/include/netlink-private/netlink.h
+++ b/include/netlink-private/netlink.h
@@ -129,6 +129,7 @@ extern void __trans_list_clear(struct nl_list_head *);
 extern char *__type2str(int, char *, size_t, const struct trans_tbl *, size_t);
 extern int __str2type(const char *, const struct trans_tbl *, size_t);
 
+extern char *__list_table2str(int, char *, size_t, struct nl_list_head *);
 extern char *__list_type2str(int, char *, size_t, struct nl_list_head *);
 extern int __list_str2type(const char *, struct nl_list_head *);
 
diff --git a/lib/route/route_utils.c b/lib/route/route_utils.c
index 9cd326f2c3ef..3a04a85e2ee3 100644
--- a/lib/route/route_utils.c
+++ b/lib/route/route_utils.c
@@ -78,7 +78,7 @@ int rtnl_route_read_table_names(const char *path)
 
 char *rtnl_route_table2str(int table, char *buf, size_t size)
 {
-	return __list_type2str(table, buf, size, &table_names);
+	return __list_table2str(table, buf, size, &table_names);
 }
 
 int rtnl_route_str2table(const char *name)
diff --git a/lib/utils.c b/lib/utils.c
index 85beb8663054..9a8c405cc595 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -979,8 +979,8 @@ char *__type2str(int type, char *buf, size_t len,
 	return buf;
 }
 
-char *__list_type2str(int type, char *buf, size_t len,
-		      struct nl_list_head *head)
+static char *___list_type2str(int type, char *buf, size_t len,
+			      struct nl_list_head *head, int in_hex)
 {
 	struct trans_list *tl;
 
@@ -991,10 +991,25 @@ char *__list_type2str(int type, char *buf, size_t len,
 		}
 	}
 
-	snprintf(buf, len, "0x%x", type);
+	if (in_hex)
+		snprintf(buf, len, "0x%x", type);
+	else
+		snprintf(buf, len, "%d", type);
 	return buf;
 }
 
+char *__list_type2str(int type, char *buf, size_t len,
+		      struct nl_list_head *head)
+{
+	return ___list_type2str(type, buf, len, head, 1);
+}
+
+char *__list_table2str(int type, char *buf, size_t len,
+		       struct nl_list_head *head)
+{
+	return ___list_type2str(type, buf, len, head, 0);
+}
+
 char *__flags2str(int flags, char *buf, size_t len,
 		  const struct trans_tbl *tbl, size_t tbl_len)
 {
diff --git a/libnl-3.sym b/libnl-3.sym
index 4e09bdd672a1..35df7206bcb4 100644
--- a/libnl-3.sym
+++ b/libnl-3.sym
@@ -350,4 +350,5 @@ libnl_3_2_27 {
 libnl_3_2_28 {
 global:
 	nl_object_diff64;
+	__list_table2str;
 } libnl_3_2_27;
-- 
1.9.1




More information about the libnl mailing list