From: Guy Harris Date: Wed, 13 Apr 2022 23:16:08 +0000 (-0700) Subject: linux: reserve space for DLT_LINUX_SLL2 on all cooked captures. X-Git-Tag: libpcap-1.10.2~155 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/c47df96974748353b6ad728227b53083960c4113 linux: reserve space for DLT_LINUX_SLL2 on all cooked captures. Don't just do it if we're using DLT_LINUX_SLL2 up front; that can be changed by the software using libpcap at any point. (cherry picked from commit 17a48ca162de1a6d40a3b767eb318c2899666eb4) --- diff --git a/pcap-linux.c b/pcap-linux.c index 6b09c798..8dbf89bc 100644 --- a/pcap-linux.c +++ b/pcap-linux.c @@ -2891,22 +2891,22 @@ create_ring(pcap_t *handle, int *status) tp_reserve = VLAN_TAG_LEN; /* - * If we're using DLT_LINUX_SLL2, reserve space for a - * DLT_LINUX_SLL2 header. + * If we're capturing in cooked mode, reserve space for + * a DLT_LINUX_SLL2 header; we don't know yet whether + * we'll be using DLT_LINUX_SLL or DLT_LINUX_SLL2, as + * that can be changed on an open device, so we reserve + * space for the larger of the two. * * XXX - we assume that the kernel is still adding - * 16 bytes of extra space; that happens to - * correspond to SLL_HDR_LEN (whether intentionally - * or not - the kernel code has a raw "16" in - * the expression), so we subtract SLL_HDR_LEN - * from SLL2_HDR_LEN to get the additional space - * needed. That also means we don't bother reserving - * any additional space if we're using DLT_LINUX_SLL. + * 16 bytes of extra space, so we subtract 16 from + * SLL2_HDR_LEN to get the additional space needed. + * (Are they doing that for DLT_LINUX_SLL, the link- + * layer header for which is 16 bytes?) * - * XXX - should we use TPACKET_ALIGN(SLL2_HDR_LEN - SLL_HDR_LEN)? + * XXX - should we use TPACKET_ALIGN(SLL2_HDR_LEN - 16)? */ - if (handle->linktype == DLT_LINUX_SLL2) - tp_reserve += SLL2_HDR_LEN - SLL_HDR_LEN; + if (handlep->cooked) + tp_reserve += SLL2_HDR_LEN - 16; /* * Try to request that amount of reserve space.