From: Vadim Kochan <[email protected]>

Print nlmsg type name for rtnetlink messages

Signed-off-by: Vadim Kochan <[email protected]>
---
 proto_nlmsg.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 2 deletions(-)

diff --git a/proto_nlmsg.c b/proto_nlmsg.c
index 51b303f..1e34056 100644
--- a/proto_nlmsg.c
+++ b/proto_nlmsg.c
@@ -47,6 +47,86 @@ static const char *nlmsg_family2str(uint16_t family)
        }
 }
 
+static char * rtnl_types2str[RTM_MAX] = {
+       [RTM_NEWLINK] = "new link",
+       [RTM_DELLINK] = "del link",
+       [RTM_GETLINK] = "get link",
+       [RTM_SETLINK] = "set link",
+
+       [RTM_NEWADDR] = "new address",
+       [RTM_DELADDR] = "del address",
+       [RTM_GETADDR] = "get address",
+
+       [RTM_NEWROUTE] = "new route",
+       [RTM_DELROUTE] = "del route",
+       [RTM_GETROUTE] = "get route",
+
+       [RTM_NEWNEIGH] = "new neighbour",
+       [RTM_DELNEIGH] = "del neighbour",
+       [RTM_GETNEIGH] = "get neighbour",
+
+       [RTM_NEWRULE] = "new rule",
+       [RTM_DELRULE] = "del rule",
+       [RTM_GETRULE] = "get rule",
+
+       [RTM_NEWQDISC] = "new tc qdisc",
+       [RTM_DELQDISC] = "del tc qdisc",
+       [RTM_GETQDISC] = "get tc qdisc",
+
+       [RTM_NEWTCLASS] = "new tc class",
+       [RTM_DELTCLASS] = "del tc class",
+       [RTM_GETTCLASS] = "get tc class",
+
+       [RTM_NEWTFILTER] = "new tc filter",
+       [RTM_DELTFILTER] = "del tc filter",
+       [RTM_GETTFILTER] = "get tc filter",
+
+       [RTM_NEWACTION] = "new tc action",
+       [RTM_DELACTION] = "del tc action",
+       [RTM_GETACTION] = "get tc action",
+
+       [RTM_NEWPREFIX] = "new prefix",
+
+       [RTM_GETMULTICAST] = "get multicast address",
+
+       [RTM_GETANYCAST] = "get anycast address",
+
+       [RTM_NEWNEIGHTBL] = "new neighbour tabel",
+       [RTM_GETNEIGHTBL] = "get neighbour tabel",
+       [RTM_SETNEIGHTBL] = "set neighbour tabel",
+
+       [RTM_NEWNDUSEROPT] = "new ndisc user option",
+
+       [RTM_NEWADDRLABEL] = "new address label",
+       [RTM_DELADDRLABEL] = "del address label",
+       [RTM_GETADDRLABEL] = "get address label",
+
+       [RTM_GETDCB] = "get data-center-bridge",
+       [RTM_SETDCB] = "set data-center-bridge",
+
+       [RTM_NEWNETCONF] = "new netconf",
+       [RTM_GETNETCONF] = "get netconf",
+
+       [RTM_NEWMDB] = "new bridge mdb",
+       [RTM_DELMDB] = "del bridge mdb",
+       [RTM_GETMDB] = "get bridge mdb",
+};
+
+static char *nlmsg_type2str(uint16_t proto, uint16_t type, char *buf, int len)
+{
+       char *name = NULL;
+
+       if (proto == NETLINK_ROUTE && type < RTM_MAX)
+               name = rtnl_types2str[type];
+
+       if (name) {
+               strncpy(buf, name, len);
+               return buf;
+       }
+
+       return nl_nlmsgtype2str(type, buf, len);
+}
+
 static void nlmsg(struct pkt_buff *pkt)
 {
        struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr));
@@ -82,8 +162,8 @@ static void nlmsg(struct pkt_buff *pkt)
        tprintf("Len %u, ", hdr->nlmsg_len);
        tprintf("Type 0x%.4x (%s%s%s), ", hdr->nlmsg_type,
                colorize_start(bold),
-               nl_nlmsgtype2str(hdr->nlmsg_type, type, sizeof(type)),
-               colorize_end());
+               nlmsg_type2str(ntohs(pkt->proto), hdr->nlmsg_type, type,
+                       sizeof(type)), colorize_end());
        tprintf("Flags 0x%.4x (%s%s%s), ", hdr->nlmsg_flags,
                colorize_start(bold),
                nl_nlmsg_flags2str(hdr->nlmsg_flags, flags, sizeof(flags)),
-- 
2.3.1

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to