diff options
author | Guy Harris <guy@alum.mit.edu> | 2016-09-19 12:56:11 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2016-09-19 12:56:11 -0700 |
commit | ae94350551861bbefb52f10c4ba499c1440a6a10 (patch) | |
tree | 0a7581929071cb6c105198759d8134ee4738ea40 /pcap-linux.c | |
parent | 53b5b9cb8350679b5b04eb24cbeaf80b756b8289 (diff) |
Filter out duplicate looped back CAN frames.
CAN devices and drivers, and the Linux CAN stack, always arrange to loop
back transmitted packets, so they also appear as incoming packets. We
don't want duplicate packets, and we can't easily distinguish packets
looped back by the CAN layer than those received by the CAN layer, so we
discard packets with a packet type "outgoing" and a protocol of CAN or
CAN FD.
Diffstat (limited to 'pcap-linux.c')
-rw-r--r-- | pcap-linux.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/pcap-linux.c b/pcap-linux.c index b7fb6889..f1ce0c61 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -1643,6 +1643,22 @@ linux_check_direction(const pcap_t *handle, const struct sockaddr_ll *sll) return 0; /* + * If this is an outgoing CAN or CAN FD frame, and + * the user doesn't only want outgoing packets, + * reject it; CAN devices and drivers, and the CAN + * stack, always arrange to loop back transmitted + * packets, so they also appear as incoming packets. + * We don't want duplicate packets, and we can't + * easily distinguish packets looped back by the CAN + * layer than those received by the CAN layer, so we + * eliminate this packet instead. + */ + if ((sll->sll_protocol == LINUX_SLL_P_CAN || + sll->sll_protocol == LINUX_SLL_P_CANFD) && + handle->direction != PCAP_D_OUT) + return 0; + + /* * If the user only wants incoming packets, reject it. */ if (handle->direction == PCAP_D_IN) |