From d8aade59b5787f5d3517fededcd684fe85367afa Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Mon, 29 May 2017 11:54:43 +0200
Subject: [PATCH] Backport patch to bound tpacketv2 to 64k
---
pcap-linux.c | 29 ++++++++++++++++++-----------
1 file changed, 18 insertions(+), 11 deletions(-)
diff --git a/pcap-linux.c b/pcap-linux.c
index f7f2aae..d7149d5 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -3600,6 +3600,8 @@ prepare_tpacket_socket(pcap_t *handle)
return 1;
}
+#define MAX(a,b) ((a)>(b)?(a):(b))
+
/*
* Attempt to set up memory-mapped access.
*
@@ -3674,25 +3676,30 @@ create_ring(pcap_t *handle, int *status)
* "packets" bigger than the MTU. */
frame_size = handle->snapshot;
if (handle->linktype == DLT_EN10MB) {
+ unsigned int max_frame_len;
int mtu;
int offload;
+ mtu = iface_get_mtu(handle->fd, handle->opt.source,
+ handle->errbuf);
+ if (mtu == -1) {
+ *status = PCAP_ERROR;
+ return -1;
+ }
offload = iface_get_offload(handle);
if (offload == -1) {
*status = PCAP_ERROR;
return -1;
}
- if (!offload) {
- mtu = iface_get_mtu(handle->fd, handle->opt.source,
- handle->errbuf);
- if (mtu == -1) {
- *status = PCAP_ERROR;
- return -1;
- }
- if (frame_size > mtu + 18)
- frame_size = mtu + 18;
- }
- }
+ if (offload)
+ max_frame_len = MAX(mtu, 65535);
+ else
+ max_frame_len = mtu;
+ max_frame_len += 18;
+
+ if (frame_size > max_frame_len)
+ frame_size = max_frame_len;
+ }
/* NOTE: calculus matching those in tpacket_rcv()
* in linux-2.6/net/packet/af_packet.c
--
2.13.0