]> The Tcpdump Group git mirrors - libpcap/commitdiff
Linux kernel 3.0 uses TP_STATUS_VLAN_VALID flag in packet
authorAni Sinha <[email protected]>
Tue, 11 Dec 2012 00:02:52 +0000 (16:02 -0800)
committerGuy Harris <[email protected]>
Tue, 11 Dec 2012 23:18:33 +0000 (15:18 -0800)
    auxilliary data (aux->tp_status) to indicate a packet tagged
    with a valid vlan ID 0 with another packet that is not
    vlan tagged. Use this flag to check for the presence of
    a vlan tagged packet. Also be careful not to cause any
    breakage when libpcap is compiled against a newer kernel
    (>=3.0) and used on top of an older kernel that does not
    use this flag.

Signed-off-by: Ani Sinha <[email protected]>
pcap-linux.c

index ad22821020f2dbdfbfa3048d8ce5b8d3cfa8eb91..9fddadb6cf567ee9fa943ee605be465c9144d63d 100644 (file)
@@ -133,6 +133,7 @@ static const char rcsid[] _U_ =
 #include <sys/utsname.h>
 #include <sys/mman.h>
 #include <linux/if.h>
+#include <linux/if_packet.h>
 #include <netinet/in.h>
 #include <linux/if_ether.h>
 #include <net/if_arp.h>
@@ -1631,7 +1632,13 @@ pcap_read_packet(pcap_t *handle, pcap_handler callback, u_char *userdata)
                                continue;
 
                        aux = (struct tpacket_auxdata *)CMSG_DATA(cmsg);
-                       if (aux->tp_vlan_tci == 0)
+#if defined(TP_STATUS_VLAN_VALID)
+                       if ((aux->tp_vlan_tci == 0) && !(aux->tp_status & TP_STATUS_VLAN_VALID))
+#else
+                       if (aux->tp_vlan_tci == 0) /* this is ambigious but without the
+                                               TP_STATUS_VLAN_VALID flag, there is
+                                               nothing that we can do */
+#endif
                                continue;
 
                        len = packet_len > iov.iov_len ? iov.iov_len : packet_len;
@@ -4074,7 +4081,12 @@ pcap_read_linux_mmap(pcap_t *handle, int max_packets, pcap_handler callback,
                }
 
 #ifdef HAVE_TPACKET2
-               if (handle->md.tp_version == TPACKET_V2 && h.h2->tp_vlan_tci &&
+               if ((handle->md.tp_version == TPACKET_V2) &&
+#if defined(TP_STATUS_VLAN_VALID)
+               (h.h2->tp_vlan_tci || (h.h2->tp_status & TP_STATUS_VLAN_VALID)) &&
+#else
+               h.h2->tp_vlan_tci &&
+#endif
                    handle->md.vlan_offset != -1 &&
                    tp_snaplen >= (unsigned int) handle->md.vlan_offset) {
                        struct vlan_tag *tag;