aboutsummaryrefslogtreecommitdiff
path: root/pcap-linux.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2021-10-20 00:31:11 -0700
committerGuy Harris <gharris@sonic.net>2022-02-20 15:21:46 -0800
commitf82087f4c097a5809cda53eb5e9289cc16801093 (patch)
treec916e8794e9b4008a77e4c154ca18934a64ae4b3 /pcap-linux.c
parentb87f85ef13473281b80604400e8e3e4284dfcd3e (diff)
downloadlibpcap-f82087f4c097a5809cda53eb5e9289cc16801093.tar.gz
linux: clean up the SocketCAN header for classic CAN frames.
We already clean it up for CAN FD frames; clean it up for classic CAN frames as well, to allow heuristics to be used to try to guess whether the len8_dlc field was filled in. (cherry picked from commit e9eaad85f3888c72f79de705fae7e0768d8a622d)
Diffstat (limited to 'pcap-linux.c')
-rw-r--r--pcap-linux.c39
1 files changed, 30 insertions, 9 deletions
diff --git a/pcap-linux.c b/pcap-linux.c
index e931f84f..52decc31 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -3936,20 +3936,41 @@ static int pcap_handle_packet_mmap(
* does happen.)
*
* Update this if Linux adds more flag
- * bits to the fd_flags field or uses
- * either of the reserved fields for
- * FD frames.
+ * bits to the fd_flags field, uses the
+ * len8_dlc field for CAN FD frames, or
+ * uses the reserved frame for CAN FD
+ * frames.
*/
canhdr->fd_flags &= ~(CANFD_FDF|CANFD_ESI|CANFD_BRS);
- canhdr->reserved1 = 0;
- canhdr->reserved2 = 0;
+ canhdr->len8_dlc = 0;
+ canhdr->reserved = 0;
} else {
/*
- * Clear CANFD_FDF if it's set (probably
- * again meaning that that field is
- * uninitialized junk).
+ * The FD flags field is CAN FD-only,
+ * so it should be zero.
+ *
+ * If it's not zero, or the reserved
+ * field is not zero, or the len8_dlc
+ * field does not have a value between
+ * 8 and 15, assume the header was not
+ * initialized past the payload_length
+ * field, and zero out the len8_dlc field.
+ *
+ * Then zero out the fd_flags and reserved
+ * fields.
+ *
+ * Update this if Linux uses the fd_flags
+ * field or the reserved field, or puts
+ * values not between 8 and 15 in the
+ * len8_dlc field, for classic CAN frames.
*/
- canhdr->fd_flags &= ~CANFD_FDF;
+ if (canhdr->fd_flags != 0 ||
+ canhdr->reserved != 0 ||
+ (canhdr->len8_dlc < 8 ||
+ canhdr->len8_dlc > 15))
+ canhdr->len8_dlc = 0;
+ canhdr->fd_flags = 0;
+ canhdr->reserved = 0;
}
}
}