diff options
Diffstat (limited to 'pcap-dpdk.c')
-rw-r--r-- | pcap-dpdk.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/pcap-dpdk.c b/pcap-dpdk.c index 765abe59..94c33092 100644 --- a/pcap-dpdk.c +++ b/pcap-dpdk.c @@ -85,6 +85,7 @@ env DPDK_CFG="--log-level=debug -l0 -dlibrte_pmd_e1000.so -dlibrte_pmd_ixgbe.so #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <limits.h> /* for INT_MAX */ #include <time.h> #include <sys/time.h> @@ -331,13 +332,28 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c u_char *large_buffer=NULL; int timeout_ms = p->opt.timeout; - if ( !PACKET_COUNT_IS_UNLIMITED(max_cnt) && max_cnt < MAX_PKT_BURST){ + /* + * This can conceivably process more than INT_MAX packets, + * which would overflow the packet count, causing it either + * to look like a negative number, and thus cause us to + * return a value that looks like an error, or overflow + * back into positive territory, and thus cause us to + * return a too-low count. + * + * Therefore, if the packet count is unlimited, we clip + * it at INT_MAX; this routine is not expected to + * process packets indefinitely, so that's not an issue. + */ + if (PACKET_COUNT_IS_UNLIMITED(max_cnt)) + max_cnt = INT_MAX; + + if (max_cnt < MAX_PKT_BURST){ burst_cnt = max_cnt; }else{ burst_cnt = MAX_PKT_BURST; } - while( PACKET_COUNT_IS_UNLIMITED(max_cnt) || pkt_cnt < max_cnt){ + while( pkt_cnt < max_cnt){ if (p->break_loop){ p->break_loop = 0; return PCAP_ERROR_BREAK; |