Skip to content

Commit d9e4f0a

Browse files
author
Lukas Sismis
committed
add extra config options, add offset to know when to call HS immediately
1 parent 77725a1 commit d9e4f0a

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

src/app-layer-detect-proto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ static inline int PMGetProtoInspect(AppLayerProtoDetectThreadCtx *tctx,
276276
/* do the mpm search */
277277
uint32_t search_cnt = mpm_table[pm_ctx->mpm_ctx.mpm_type].Search(
278278
&pm_ctx->mpm_ctx, mpm_tctx, &tctx->pmq,
279-
buf, searchlen);
279+
buf, MPM_RXP_REQUIRED_HS_OFFSET + searchlen);
280280
if (search_cnt == 0) {
281281
if (buflen >= pm_ctx->mpm_ctx.maxdepth)
282282
return -1;

src/app-layer-ftp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ static int FTPParseRequestCommand(
415415
* should make the use of the mpm very efficient */
416416
PmqReset(td->pmq);
417417
int mpm_cnt = mpm_table[FTP_MPM].Search(
418-
ftp_mpm_ctx, td->ftp_mpm_thread_ctx, td->pmq, line->buf, line->len);
418+
ftp_mpm_ctx, td->ftp_mpm_thread_ctx, td->pmq, line->buf, MPM_RXP_REQUIRED_HS_OFFSET + line->len);
419419
if (mpm_cnt) {
420420
*cmd_descriptor = &FtpCommands[td->pmq->rule_id_array[0]];
421421
SCReturnInt(1);

src/app-layer-smtp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ static int SMTPProcessReply(SMTPState *state, Flow *f, AppLayerParserState *psta
943943
* should make the use of the mpm very efficient */
944944
PmqReset(td->pmq);
945945
int mpm_cnt = mpm_table[SMTP_MPM].Search(
946-
smtp_mpm_ctx, td->smtp_mpm_thread_ctx, td->pmq, line->buf, 3);
946+
smtp_mpm_ctx, td->smtp_mpm_thread_ctx, td->pmq, line->buf, MPM_RXP_REQUIRED_HS_OFFSET + 3);
947947
if (mpm_cnt == 0) {
948948
/* set decoder event - reply code invalid */
949949
SMTPSetEvent(state, SMTP_DECODER_EVENT_INVALID_REPLY);

src/suricata.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ bool g_disable_hashing = false;
217217
/* snapshot of the system's hugepages before system intitialization. */
218218
SystemHugepageSnapshot *prerun_snap = NULL;
219219

220-
220+
uint16_t g_rxp_deq_retry_after_us = 0;
221+
uint16_t g_rxp_minlength = 0;
221222
uint16_t g_worker_threads_cnt = 0;
222223
uint32_t g_mpm_groups_cnt = 0;
223224

src/suricata.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ enum EngineMode {
104104
ENGINE_MODE_IPS,
105105
};
106106

107+
#define MPM_RXP_REQUIRED_HS_OFFSET 100000000
108+
extern uint16_t g_rxp_deq_retry_after_us;
109+
extern uint16_t g_rxp_minlength;
107110
extern uint16_t g_worker_threads_cnt;
108111
extern uint32_t g_mpm_groups_cnt;
109112

src/util-mpm-rxp.c

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
#include <hs.h>
4444
#include <openssl/evp.h>
4545

46-
#define MPM_RXP_DESCRIPTORS 2048 // descriptors used in the rxp queues
46+
#define MPM_RXP_DESCRIPTORS 1024 // descriptors used in the rxp queues
4747
#define MPM_RXP_OPERATIONS 32 // number of operations when de/enqueueing to RXP queues
4848
#define MPM_RXP_MAX_WORKERS 8 // should correspond to the number of workers
4949
#define MPM_RXP_PATTERNS_PATH "/tmp/suricata-mpm.patterns" // path to where extracted contents from Suricata rules will be temporarily stored
@@ -944,8 +944,8 @@ uint32_t SCRXPFinalizeSearchAndBulkDequeueAll(PrefilterRuleStore *pmq)
944944
g_rxp_ops,
945945
MPM_RXP_OPERATIONS);
946946
if (deqed == 0) {
947-
rte_delay_us_sleep(1);
948-
pthread_yield();
947+
rte_delay_us_sleep(g_rxp_deq_retry_after_us);
948+
sched_yield();
949949
}
950950

951951
// convert RXP results to PMQ
@@ -1017,7 +1017,7 @@ uint32_t SCRXPFinalizeSearchAndBulkDequeueAll(PrefilterRuleStore *pmq)
10171017
* \retval matches Match count.
10181018
*/
10191019
static uint32_t SCRXPSearchBulk(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_ctx,
1020-
PrefilterRuleStore *pmq, const uint8_t *buf, const uint32_t buflen)
1020+
PrefilterRuleStore *pmq, const uint8_t *buf, uint32_t buflen)
10211021
{
10221022
uint32_t ret = 0;
10231023
SCRXPCtx *rxp_ctx = (SCRXPCtx *)mpm_ctx->ctx;
@@ -1026,16 +1026,15 @@ static uint32_t SCRXPSearchBulk(const MpmCtx *mpm_ctx, MpmThreadCtx *mpm_thread_
10261026
uint16_t enqed = 0;
10271027
uint16_t prep_i = 0;
10281028

1029-
if (unlikely(buflen == 0)) {
1029+
if (unlikely(buflen == 0 || buflen == MPM_RXP_REQUIRED_HS_OFFSET)) {
10301030
return 0;
10311031
}
1032-
// TODO:
1033-
// try to think of traffic and rules that would be more suitable
1034-
// continue with stats - measure the time
1035-
1032+
if (buflen > MPM_RXP_REQUIRED_HS_OFFSET) {
1033+
buflen -= MPM_RXP_REQUIRED_HS_OFFSET;
1034+
goto hs_fallback;
1035+
}
10361036
uint32_t seg_len = rxp_ctx->max_payload_size; // rxp_ctx->max_payload_size
1037-
1038-
if (buflen < 1) {
1037+
if (buflen < g_rxp_minlength) {
10391038
goto hs_fallback;
10401039
}
10411040

@@ -1539,14 +1538,46 @@ void RXPInit()
15391538
FatalError("Unable to get %s configuration node", dpdk_node_query);
15401539
}
15411540
const char iface_name[] = "0000:51:00.0";
1541+
int32_t entry_int;
15421542
ConfNode *if_node = ConfNodeLookupKeyValue(dpdk_node, "interface", iface_name);
15431543
const char *entry_str = NULL;
15441544
int retval = ConfGetChildValue(if_node, "threads", &entry_str);
15451545
if (retval < 0)
15461546
FatalError("Unable to get threads configuration node");
1547-
if (StringParseInt32(&g_worker_threads_cnt, 10, 0, entry_str) < 0) {
1547+
if (StringParseInt32(&entry_int, 10, 0, entry_str) < 0) {
15481548
FatalError("Unable to parse threads configuration node");
15491549
}
1550+
if (entry_int < 1) {
1551+
FatalError("Invalid threads configuration node");
1552+
}
1553+
g_worker_threads_cnt = (uint16_t)entry_int;
1554+
if (run_mode == RUNMODE_PCAP_FILE) {
1555+
// this mode runs in autofp mode and the 1 RX thread does the applayer
1556+
// protocol detection, so we need to add 1 extra queue
1557+
g_worker_threads_cnt += 1;
1558+
}
1559+
1560+
retval = ConfGetChildValue(if_node, "rxp-min-buflen", &entry_str);
1561+
if (retval < 0)
1562+
FatalError("Unable to get rxp-min-buflen configuration node");
1563+
if (StringParseInt32(&entry_int, 10, 0, entry_str) < 0) {
1564+
FatalError("Unable to parse rxp-min-buflen configuration node");
1565+
}
1566+
if (entry_int < 1) {
1567+
FatalError("Invalid rxp-min-buflen configuration node");
1568+
}
1569+
g_rxp_minlength = (uint16_t)entry_int;
1570+
1571+
retval = ConfGetChildValue(if_node, "rxp-dequeue-retry-after-us", &entry_str);
1572+
if (retval < 0)
1573+
FatalError("Unable to get rxp-dequeue-retry-after-us configuration node");
1574+
if (StringParseInt32(&entry_int, 10, 0, entry_str) < 0) {
1575+
FatalError("Unable to parse rxp-dequeue-retry-after-us configuration node");
1576+
}
1577+
if (entry_int < 1) {
1578+
FatalError("Invalid rxp-dequeue-retry-after-us configuration node");
1579+
}
1580+
g_rxp_deq_retry_after_us = (uint16_t)entry_int;
15501581

15511582
SCLogNotice("nb queues %u nb groups %u", g_worker_threads_cnt, g_mpm_groups_cnt);
15521583
dev_conf.nb_queue_pairs = g_worker_threads_cnt;

0 commit comments

Comments
 (0)