Skip to contentSkip to conversation

ss: Identify more netlink protocol names

PATCH New Vadim Kochan 1 participant 1 message Oct 30, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ss: Identify more netlink protocol names

There were only few Netlink protocol names
which were printed on the screen:

rtnl, fw, tcpdiag

So added the ability to identify Netlink proto name from /etc/iproute/nl_protos or from static table.

---
 etc/iproute2/nl_protos | 23 ++++++++++++++
 include/rt_names.h     |  2 ++
 lib/rt_names.c         | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++
 misc/ss.c              | 17 ++++++-----
 4 files changed, 116 insertions(+), 8 deletions(-)
 create mode 100644 etc/iproute2/nl_protos
etc/iproute2/nl_protos new file +23 -0
new file mode 100644
index 0000000..43418f3
@@ -0,0 +1,23 @@
+# Netlink protocol names mapping
+
+0   rtnl
+1   unused
+2   usersock
+3   fw
+4   tcpdiag
+5   nflog
+6   xfrm
+7   selinux
+8   iscsi
+9   audit
+10  fiblookup
+11  connector
+12  nft 
+13  ip6fw
+14  dec-rt
+15  uevent
+16  genl
+18  scsi-trans
+19  ecryptfs
+20  rdma
+21  crypto 
include/rt_names.h +2 -0
index 56b649a..c0ea4f9 100644
@@ -29,5 +29,7 @@ int ll_addr_a2n(char *lladdr, int len, const char *arg);
 const char * ll_proto_n2a(unsigned short id, char *buf, int len);
 int ll_proto_a2n(unsigned short *id, const char *buf);
 
+const char *nl_proto_n2a(int id, char *buf, int len);
+int nl_proto_a2n(__u32 *id, const char *arg);
 
 #endif
lib/rt_names.c +82 -0

85 lines not on this page · raw message

misc/ss.c +9 -8
index b7e0ef0..291d85f 100644
@@ -2979,6 +2979,8 @@ static void netlink_show_one(struct filter *f,
 				int rq, int wq,
 				unsigned long long sk, unsigned long long cb)
 {
+	SPRINT_BUF(prot_name);
+
 	if (f->f) {
 		struct tcpstat tst;
 		tst.local.family = AF_NETLINK;
@@ -2996,14 +2998,13 @@ static void netlink_show_one(struct filter *f,
 	if (state_width)
 		printf("%-*s ", state_width, "UNCONN");
 	printf("%-6d %-6d ", rq, wq);
-	if (resolve_services && prot == 0)
-		printf("%*s:", addr_width, "rtnl");
-	else if (resolve_services && prot == 3)
-		printf("%*s:", addr_width, "fw");
-	else if (resolve_services && prot == 4)
-		printf("%*s:", addr_width, "tcpdiag");
-	else
-		printf("%*d:", addr_width, prot);
+
+	if (resolve_services)
+	{
+		printf("%*s:", addr_width, nl_proto_n2a(prot, prot_name,
+					sizeof(prot_name)));
+	}
+
 	if (pid == -1) {
 		printf("%-*s ", serv_width, "*");
 	} else if (resolve_services) {
Signature · 1 line
2.1.0