summaryrefslogtreecommitdiff
path: root/proto_nlmsg.c
diff options
context:
space:
mode:
authorVadim Kochan <vadim4j@gmail.com>2015-04-24 19:14:35 +0300
committerTobias Klauser <tklauser@distanz.ch>2015-04-27 11:52:48 +0200
commitd312a25879d5826ff1ca638410bbd36ba2619d93 (patch)
tree301de11dfc9dd5de7be1531f048806e336ed4541 /proto_nlmsg.c
parent7abd76e387c10d9f105af348d2f7bd16e3f671b8 (diff)
netsniff-ng nlmsg: Print netlink protocol name
nlmsg proto handler can't identify Netlink protocol from nlmsghdr, so sockaddr_ll can be used to get it. Also renamed [proto -> handler] member in pkt_buff struct, which is more understandable. Example: >U nlmon0 4756 1429891435s.14505747ns [ NLMSG Proto 0 (RTNETLINK), Len 1160, Type 0x0010 (0x10), Flags 0x0002 (MULTI), Seq-Nr 1429891436, PID 31613 ] Signed-off-by: Vadim Kochan <vadim4j@gmail.com> [tklauser: Handle usage of NETLINK_SOCK_DIAG with pre 3.10 kernel headers, fix nl_proto2str() return value, formatting changes] Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'proto_nlmsg.c')
-rw-r--r--proto_nlmsg.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/proto_nlmsg.c b/proto_nlmsg.c
index 787d9d6..b219867 100644
--- a/proto_nlmsg.c
+++ b/proto_nlmsg.c
@@ -14,6 +14,39 @@
#include "proto.h"
#include "protos.h"
+static const char *nl_proto2str(uint16_t proto)
+{
+ switch (proto) {
+ case NETLINK_ROUTE: return "RTNETLINK";
+ case NETLINK_UNUSED: return "UNUSED";
+ case NETLINK_USERSOCK: return "USERSOCK";
+ case NETLINK_FIREWALL: return "FIREWALL";
+/* NETLINK_INET_DIAG was renamed to NETLINK_SOCK_DIAG in Linux kernel 3.10 */
+#if defined(NETLINK_SOCK_DIAG)
+ case NETLINK_SOCK_DIAG: return "SOCK_DIAG";
+#elif defined(NETLINK_INET_DIAG)
+ case NETLINK_INET_DIAG: return "INET_DIAG";
+#endif
+ case NETLINK_NFLOG: return "NFLOG";
+ case NETLINK_XFRM: return "XFRM";
+ case NETLINK_SELINUX: return "SELINUX";
+ case NETLINK_ISCSI: return "ISCSI";
+ case NETLINK_AUDIT: return "AUDIT";
+ case NETLINK_FIB_LOOKUP: return "FIB_LOOKUP";
+ case NETLINK_CONNECTOR: return "CONNECTOR";
+ case NETLINK_NETFILTER: return "NETFILTER";
+ case NETLINK_IP6_FW: return "IP6_FW";
+ case NETLINK_DNRTMSG: return "DNRTMSG";
+ case NETLINK_KOBJECT_UEVENT: return "UEVENT";
+ case NETLINK_GENERIC: return "GENERIC";
+ case NETLINK_SCSITRANSPORT: return "SCSI";
+ case NETLINK_ECRYPTFS: return "ECRYPTFS";
+ case NETLINK_RDMA: return "RDMA";
+ case NETLINK_CRYPTO: return "CRYPTO";
+ default: return "Unknown";
+ }
+}
+
static void nlmsg(struct pkt_buff *pkt)
{
struct nlmsghdr *hdr = (struct nlmsghdr *) pkt_pull(pkt, sizeof(*hdr));
@@ -44,6 +77,8 @@ static void nlmsg(struct pkt_buff *pkt)
snprintf(procname, sizeof(procname), "kernel");
tprintf(" [ NLMSG ");
+ tprintf("Proto %d (%s%s%s), ", ntohs(pkt->proto), colorize_start(bold),
+ nl_proto2str(ntohs(pkt->proto)), colorize_end());
tprintf("Len %u, ", hdr->nlmsg_len);
tprintf("Type 0x%.4x (%s%s%s), ", hdr->nlmsg_type,
colorize_start(bold),