]> The Tcpdump Group git mirrors - libpcap/commitdiff
linktype: add netlink link/dlt type
authorDaniel Borkmann <[email protected]>
Mon, 18 Nov 2013 23:39:37 +0000 (15:39 -0800)
committerGuy Harris <[email protected]>
Mon, 18 Nov 2013 23:39:37 +0000 (15:39 -0800)
With Linux 3.11, we have the possibility to debug local netlink traffic
[1] i.e.  the workflow looks like this:

Setup:
  modprobe nlmon
  ip link add type nlmon
  ip link set nlmon0 up

Capture:
  tcpdump -i nlmon0 ...

Teardown:
  ip link set nlmon0 down
  ip link del dev nlmon0
  rmmod nlmon

For pcap interoperability, introduce a common link type for netlink
captures.

pcap-common.c
pcap-linux.c
pcap/bpf.h

index 6175a5acb090068bcb7371d6fd92a959eb641c38..f26d22ec63d92342ca8cb4870a79e5fe5473a88e 100644 (file)
  */
 #define LINKTYPE_WIRESHARK_UPPER_PDU   252
 
-#define LINKTYPE_MATCHING_MAX  252             /* highest value in the "matching" range */
+/*
+ * Link-layer header type for the netlink protocol (nlmon devices).
+ */
+#define LINKTYPE_NETLINK               253
+
+#define LINKTYPE_MATCHING_MAX  253             /* highest value in the "matching" range */
 
 static struct linktype_map {
        int     dlt;
index e81738248285e62a7129588b843d32a9824d6bd0..0651522f5f40cacc95e4b8d99b0546fb8cee4dd8 100644 (file)
@@ -2972,6 +2972,19 @@ static void map_arphrd_to_dlt(pcap_t *handle, int arptype, int cooked_ok)
                handle->linktype =  DLT_IEEE802_15_4_NOFCS;
                break;
 
+#ifndef ARPHRD_NETLINK
+#define ARPHRD_NETLINK 824
+#endif
+       case ARPHRD_NETLINK:
+               handle->linktype = DLT_NETLINK;
+               /*
+                * We need to use cooked mode, so that in sll_protocol we
+                * pick up the netlink protocol type such as NETLINK_ROUTE,
+                * NETLINK_GENERIC, NETLINK_FIB_LOOKUP, etc.
+                */
+               handle->cooked = 1;
+               break;
+
        default:
                handle->linktype = -1;
                break;
index ad36eb618fd99ae74a450d09dc13d2f87d501fa7..8286ed5b413f97a5147ef6eb584986c3c499377d 100644 (file)
@@ -1224,7 +1224,12 @@ struct bpf_program {
  */
 #define DLT_WIRESHARK_UPPER_PDU        252
 
-#define DLT_MATCHING_MAX       252     /* highest value in the "matching" range */
+/*
+ * DLT type for the netlink protocol (nlmon devices).
+ */
+#define DLT_NETLINK            253
+
+#define DLT_MATCHING_MAX       253     /* highest value in the "matching" range */
 
 /*
  * DLT and savefile link type values are split into a class and