]> The Tcpdump Group git mirrors - libpcap/commitdiff
Filter out duplicate looped back CAN frames.
authorGuy Harris <[email protected]>
Mon, 19 Sep 2016 19:56:11 +0000 (12:56 -0700)
committerGuy Harris <[email protected]>
Mon, 19 Sep 2016 19:56:11 +0000 (12:56 -0700)
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.

pcap-linux.c

index b7fb6889f31c821a138327554535a2b00d2d85d6..f1ce0c618a373336503bffeca183c3877597ea05 100644 (file)
@@ -1642,6 +1642,22 @@ linux_check_direction(const pcap_t *handle, const struct sockaddr_ll *sll)
                if (sll->sll_ifindex == handlep->lo_ifindex)
                        return 0;
 
                if (sll->sll_ifindex == handlep->lo_ifindex)
                        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 the user only wants incoming packets, reject it.
                 */