aboutsummaryrefslogtreecommitdiff
path: root/pcap-common.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2016-08-25 13:26:43 -0700
committerGuy Harris <guy@alum.mit.edu>2016-08-25 13:26:43 -0700
commit93ca5ff7030aaf1219e1de05ec89a68384bfc50b (patch)
tree3db074cb78c17f25208875e0b9ea2e99691a8dd1 /pcap-common.c
parent4c9aed03ed8c10215839a8fb845e8893790d0948 (diff)
On Linux, handle all CAN captures with pcap-linux.c, in cooked mode.
There's no need to support capturing on PF_CAN sockets; CAN interfaces show up as regular interfaces on which you can capture with PF_PACKET sockets, so just let pcap-linux.c handle them, and get rid of pcap-can-linux.c. Capture on them in cooked mode, so we get the protocol field and can distinguish between "classic" CAN and CAN FD. The hardware for which pcap-canusb-linux.c was intended never reached production: https://github.com/axos88/libpcap/commit/f3edbb599b8cbcc7e4560000dcba8e992dc11a31#commitcomment-18716617 so we don't need pcap-canusb-linux.c, either. This all removes the need for the "host-endian" link-layer header type; it never made it into a libpcap release, so we just remove it. The "big-endian" link-layer header type is kept for the benefit of packets captured with the old pcap-can-linux.c code; we revert it to its old name.
Diffstat (limited to 'pcap-common.c')
-rw-r--r--pcap-common.c50
1 files changed, 6 insertions, 44 deletions
diff --git a/pcap-common.c b/pcap-common.c
index 71bf9278..63d4216d 100644
--- a/pcap-common.c
+++ b/pcap-common.c
@@ -753,7 +753,7 @@
*
* Requested by Felix Obenhuber <felix@obenhuber.de>.
*/
-#define LINKTYPE_CAN_SOCKETCAN_BIGENDIAN 227
+#define LINKTYPE_CAN_SOCKETCAN 227
/*
* Raw IPv4/IPv6; different from DLT_RAW in that the DLT_ value specifies
@@ -1022,16 +1022,7 @@
*/
#define LINKTYPE_ISO_14443 264
-/*
- * CAN (Controller Area Network) frames, with a pseudo-header as supplied
- * by Linux SocketCAN, and with multi-byte numerical fields in that header
- * in host byte order.
- *
- * See Documentation/networking/can.txt in the Linux source.
- */
-#define LINKTYPE_CAN_SOCKETCAN_HOSTENDIAN 265
-
-#define LINKTYPE_MATCHING_MAX 265 /* highest value in the "matching" range */
+#define LINKTYPE_MATCHING_MAX 264 /* highest value in the "matching" range */
static struct linktype_map {
int dlt;
@@ -1181,9 +1172,9 @@ linktype_to_dlt(int linktype)
#define EXTRACT_
/*
- * DLT_LINUX_SLL packets with a protocol type of LINUX_SLL_P_CAN have
- * SocketCAN headers in front of the payload, with the CAN ID being
- * in host byte order.
+ * DLT_LINUX_SLL packets with a protocol type of LINUX_SLL_P_CAN or
+ * LINUX_SLL_P_CANFD have SocketCAN headers in front of the payload,
+ * with the CAN ID being in host byte order.
*
* When reading a DLT_LINUX_SLL capture file, we need to check for those
* packets and convert the CAN ID from the byte order of the host that
@@ -1205,7 +1196,7 @@ swap_linux_sll_header(const struct pcap_pkthdr *hdr, u_char *buf)
}
protocol = EXTRACT_16BITS(&shdr->sll_protocol);
- if (protocol != LINUX_SLL_P_CAN)
+ if (protocol != LINUX_SLL_P_CAN && protocol != LINUX_SLL_P_CANFD)
return;
/*
@@ -1435,31 +1426,6 @@ swap_nflog_header(const struct pcap_pkthdr *hdr, u_char *buf)
}
}
-/*
- * The CAN ID in the DLT_CAN_SOCKETCAN_HOSTENDIAN header is in host byte
- * order when capturing (the header is filled in by the kernel and provided
- * on a PF_PACKET socket).
- *
- * When reading a DLT_CAN_SOCKETCAN_HOSTENDIAN capture file, we need to
- * convert it from the byte order of the host that wrote the file to
- * this host's byte order.
- */
-static void
-swap_can_socketcan_header(const struct pcap_pkthdr *hdr, u_char *buf)
-{
- u_int caplen = hdr->caplen;
- u_int length = hdr->len;
- pcap_can_socketcan_hdr *chdr = (pcap_can_socketcan_hdr *)buf;
-
- if (caplen < (u_int) sizeof(chdr->can_id) ||
- length < (u_int) sizeof(chdr->can_id)) {
- /* Not enough data to have the CAN ID */
- return;
- }
-
- chdr->can_id = SWAPLONG(chdr->can_id);
-}
-
void
swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data)
{
@@ -1485,9 +1451,5 @@ swap_pseudo_headers(int linktype, struct pcap_pkthdr *hdr, u_char *data)
case DLT_NFLOG:
swap_nflog_header(hdr, data);
break;
-
- case DLT_CAN_SOCKETCAN_HOSTENDIAN:
- swap_can_socketcan_header(hdr, data);
- break;
}
}