capture: use uint16_t for max_pending_packets

Use a fixed type of max_pending_packets instead of intmax_t which can
differ based on the platform/standard library.

Should also prevent lints about possible arithmetic overflow.
pull/8815/head
Jason Ish 2 years ago committed by Victor Julien
parent bbe13885a2
commit b5fbdc3e5f

@ -59,7 +59,7 @@
#include "source-af-packet.h" #include "source-af-packet.h"
#include "util-bpf.h" #include "util-bpf.h"
extern intmax_t max_pending_packets; extern uint16_t max_pending_packets;
const char *RunModeAFPGetDefaultMode(void) const char *RunModeAFPGetDefaultMode(void)
{ {

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

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

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

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

@ -102,7 +102,7 @@ TmEcode NoIPFWSupportExit(ThreadVars *tv, const void *initdata, void **data)
#include "action-globals.h" #include "action-globals.h"
extern intmax_t max_pending_packets; extern uint16_t max_pending_packets;
/** /**
* \brief Structure to hold thread specific variables. * \brief Structure to hold thread specific variables.

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

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

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

@ -32,7 +32,7 @@
#include "runmode-unix-socket.h" #include "runmode-unix-socket.h"
#include "suricata.h" #include "suricata.h"
extern intmax_t max_pending_packets; extern uint16_t max_pending_packets;
PcapFileGlobalVars pcap_g; PcapFileGlobalVars pcap_g;
/** /**

@ -57,7 +57,7 @@ TmEcode DecodePfringThreadInit(ThreadVars *, const void *, void **);
TmEcode DecodePfring(ThreadVars *, Packet *, void *); TmEcode DecodePfring(ThreadVars *, Packet *, void *);
TmEcode DecodePfringThreadDeinit(ThreadVars *tv, void *data); TmEcode DecodePfringThreadDeinit(ThreadVars *tv, void *data);
extern intmax_t max_pending_packets; extern uint16_t max_pending_packets;
#ifndef HAVE_PFRING #ifndef HAVE_PFRING

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

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

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

@ -89,7 +89,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
tmm_modules[TMM_FLOWWORKER].ThreadInit(&tv, NULL, &fwd); tmm_modules[TMM_FLOWWORKER].ThreadInit(&tv, NULL, &fwd);
StatsSetupPrivate(&tv); StatsSetupPrivate(&tv);
extern intmax_t max_pending_packets; extern uint16_t max_pending_packets;
max_pending_packets = 128; max_pending_packets = 128;
PacketPoolInit(); PacketPoolInit();
initialized = 1; initialized = 1;

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

@ -283,7 +283,7 @@ void PacketPoolInitEmpty(void)
void PacketPoolInit(void) void PacketPoolInit(void)
{ {
extern intmax_t max_pending_packets; extern uint16_t max_pending_packets;
PktPool *my_pool = GetThreadPacketPool(); PktPool *my_pool = GetThreadPacketPool();
@ -499,8 +499,8 @@ void TmqhReleasePacketsToPacketPool(PacketQueue *pq)
*/ */
void PacketPoolPostRunmodes(void) void PacketPoolPostRunmodes(void)
{ {
extern intmax_t max_pending_packets; extern uint16_t max_pending_packets;
intmax_t pending_packets = max_pending_packets; uint16_t pending_packets = max_pending_packets;
if (pending_packets < RESERVED_PACKETS) { if (pending_packets < RESERVED_PACKETS) {
FatalError("'max-pending-packets' setting " FatalError("'max-pending-packets' setting "
"must be at least %d", "must be at least %d",

Loading…
Cancel
Save