packetpool: allow larger max-pending-packets

Original limit was due to a specific data structure.
This commit is contained in:
Victor Julien 2024-07-07 19:43:37 +02:00 committed by Victor Julien
parent 304271e63a
commit 96a0ffadde
17 changed files with 25 additions and 26 deletions

View file

@ -59,7 +59,7 @@ TmEcode DecodePfringThreadInit(ThreadVars *, const void *, void **);
TmEcode DecodePfring(ThreadVars *, Packet *, void *);
TmEcode DecodePfringThreadDeinit(ThreadVars *tv, void *data);
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
#include <pfring.h>

View file

@ -59,7 +59,7 @@
#include "source-af-packet.h"
#include "util-bpf.h"
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
const char *RunModeAFPGetDefaultMode(void)
{
@ -685,7 +685,7 @@ finalize:
(void) SC_ATOMIC_ADD(aconf->ref, aconf->threads);
if (aconf->ring_size != 0) {
if (aconf->ring_size * aconf->threads < max_pending_packets) {
if (aconf->ring_size * aconf->threads < (int)max_pending_packets) {
aconf->ring_size = max_pending_packets / aconf->threads + 1;
SCLogWarning("%s: inefficient setup: ring-size < max_pending_packets. "
"Resetting to decent value %d.",

View file

@ -50,7 +50,7 @@
#include "suricata.h"
#include "util-bpf.h"
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
const char *RunModeNetmapGetDefaultMode(void)
{

View file

@ -269,7 +269,7 @@ void RunUnittests(int list_unittests, const char *regex_arg)
UtListTests(regex_arg);
} else {
/* global packet pool */
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
max_pending_packets = 128;
PacketPoolInit();

View file

@ -118,7 +118,7 @@ struct bpf_program {
#endif /* HAVE_AF_PACKET */
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
#ifndef HAVE_AF_PACKET

View file

@ -89,7 +89,7 @@ NoErfDagSupportExit(ThreadVars *tv, const void *initdata, void **data)
/* Number of bytes per loop to process before fetching more data. */
#define BYTES_PER_LOOP (4 * 1024 * 1024) /* 4 MB */
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
typedef struct ErfDagThreadVars_ {
ThreadVars *tv;

View file

@ -98,7 +98,7 @@ TmEcode NoIPFWSupportExit(ThreadVars *tv, const void *initdata, void **data)
#define IPFW_SOCKET_POLL_MSEC 300
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
/**
* \brief Structure to hold thread specific variables.

View file

@ -81,7 +81,7 @@ TmEcode NoNapatechSupportExit(ThreadVars *tv, const void *initdata, void **data)
#include <numa.h>
#include <nt.h>
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
typedef struct NapatechThreadVars_
{

View file

@ -97,7 +97,7 @@ static TmEcode NoNFQSupportExit(ThreadVars *tv, const void *initdata, void **dat
#else /* we do have NFQ support */
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
#define MAX_ALREADY_TREATED 5
#define NFQ_VERDICT_RETRY_COUNT 3

View file

@ -31,7 +31,7 @@
#include "source-pcap-file.h"
#include "util-exception-policy.h"
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
extern PcapFileGlobalVars pcap_g;
static void PcapFileCallbackLoop(char *user, struct pcap_pkthdr *h, u_char *pkt);

View file

@ -33,7 +33,7 @@
#include "suricata.h"
#include "conf.h"
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
PcapFileGlobalVars pcap_g;
/**

View file

@ -178,7 +178,7 @@ static enum EngineMode g_engine_mode = ENGINE_MODE_UNKNOWN;
uint8_t host_mode = SURI_HOST_IS_SNIFFER_ONLY;
/** Maximum packets to simultaneously process. */
uint16_t max_pending_packets;
uint32_t max_pending_packets;
/** global indicating if detection is enabled */
int g_detect_disabled = 0;
@ -2421,16 +2421,16 @@ static int ConfigGetCaptureValue(SCInstance *suri)
intmax_t tmp_max_pending_packets;
if (ConfGetInt("max-pending-packets", &tmp_max_pending_packets) != 1)
tmp_max_pending_packets = DEFAULT_MAX_PENDING_PACKETS;
if (tmp_max_pending_packets < 1 || tmp_max_pending_packets >= UINT16_MAX) {
SCLogError("Maximum max-pending-packets setting is 65534 and must be greater than 0. "
if (tmp_max_pending_packets < 1 || tmp_max_pending_packets > 2147483648) {
SCLogError("Maximum max-pending-packets setting is 2147483648 and must be greater than 0. "
"Please check %s for errors",
suri->conf_filename);
return TM_ECODE_FAILED;
} else {
max_pending_packets = (uint16_t)tmp_max_pending_packets;
max_pending_packets = (uint32_t)tmp_max_pending_packets;
}
SCLogDebug("Max pending packets set to %" PRIu16, max_pending_packets);
SCLogDebug("Max pending packets set to %" PRIu32, max_pending_packets);
/* Pull the default packet size from the config, if not found fall
* back on a sane default. */

View file

@ -78,7 +78,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
tmm_modules[TMM_DECODEPCAPFILE].ThreadInit(tv, NULL, (void **) &dtv);
(void)SC_ATOMIC_SET(tv->tm_slots->slot_next->slot_data, dtv);
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
max_pending_packets = 128;
PacketPoolInit();
SC_ATOMIC_SET(engine_stage, SURICATA_RUNTIME);

View file

@ -97,7 +97,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
tmm_modules[TMM_FLOWWORKER].ThreadInit(&tv, NULL, &fwd);
StatsSetupPrivate(&tv);
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
max_pending_packets = 128;
PacketPoolInit();
if (DetectEngineReload(&surifuzz) < 0) {

View file

@ -90,7 +90,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
tmm_modules[TMM_FLOWWORKER].ThreadInit(&tv, NULL, &fwd);
StatsSetupPrivate(&tv);
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
max_pending_packets = 128;
PacketPoolInit();
SC_ATOMIC_SET(engine_stage, SURICATA_RUNTIME);

View file

@ -115,7 +115,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
tmm_modules[TMM_FLOWWORKER].ThreadInit(&tv, NULL, &fwd);
StatsSetupPrivate(&tv);
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
max_pending_packets = 128;
PacketPoolInit();
SC_ATOMIC_SET(engine_stage, SURICATA_RUNTIME);

View file

@ -35,7 +35,7 @@
#include "util-validate.h"
#include "action-globals.h"
extern uint16_t max_pending_packets;
extern uint32_t max_pending_packets;
/* Number of freed packet to save for one pool before freeing them. */
#define MAX_PENDING_RETURN_PACKETS 32
@ -259,8 +259,7 @@ void PacketPoolInit(void)
/* pre allocate packets */
SCLogDebug("preallocating packets... packet size %" PRIuMAX "",
(uintmax_t)SIZE_OF_PACKET);
int i = 0;
for (i = 0; i < max_pending_packets; i++) {
for (uint32_t i = 0; i < max_pending_packets; i++) {
Packet *p = PacketGetFromAlloc();
if (unlikely(p == NULL)) {
FatalError("Fatal error encountered while allocating a packet. Exiting...");
@ -459,8 +458,8 @@ void TmqhReleasePacketsToPacketPool(PacketQueue *pq)
*/
void PacketPoolPostRunmodes(void)
{
extern uint16_t max_pending_packets;
uint16_t pending_packets = max_pending_packets;
extern uint32_t max_pending_packets;
uint32_t pending_packets = max_pending_packets;
if (pending_packets < RESERVED_PACKETS) {
FatalError("'max-pending-packets' setting "
"must be at least %d",