ndpi: use helpers to register packet keywords

Register ndpi-protocol and ndpi-risk through SCDetectHelperKeywordRegister
and install their packet callbacks with the new companion function. This
removes direct sigmatch_table writes while retaining the keyword metadata,
flags, setup functions, and match callbacks.

Note: Check the registration helper's UINT16_MAX failure result before installing
the packet callback.

Related to ticket: 7499
pull/16454/head
Jason Ish 1 week ago
parent a244b8fcd6
commit 4fc0cd8bfa

@ -533,34 +533,36 @@ static void EveCallback(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder
static void NdpInitRiskKeyword(void)
{
/* SCSigTableAppLiteElmt and SCDetectHelperKeywordRegister don't yet
* support all the fields required to register the nDPI keywords,
* missing the (packet) Match callback,
* so we'll just register with an empty keyword specifier to get
* the ID, then fill in the ID. */
ndpi_protocol_keyword_id = SCDetectHelperNewKeywordId();
const SCSigTableAppLiteElmt protocol_kw = {
.name = "ndpi-protocol",
.desc = "match on the detected nDPI protocol",
.url = "/rules/ndpi-protocol.html",
.flags = SIGMATCH_QUOTES_OPTIONAL | SIGMATCH_HANDLE_NEGATION,
.Setup = DetectnDPIProtocolSetup,
.Free = DetectnDPIProtocolFree,
};
ndpi_protocol_keyword_id = SCDetectHelperKeywordRegister(&protocol_kw);
if (ndpi_protocol_keyword_id == UINT16_MAX) {
FatalError("Failed to register ndpi-protocol keyword");
}
SCDetectHelperKeywordPacketMatchRegister(
ndpi_protocol_keyword_id, DetectnDPIProtocolPacketMatch);
SCLogDebug("Registered new ndpi-protocol keyword with ID %" PRIu32, ndpi_protocol_keyword_id);
sigmatch_table[ndpi_protocol_keyword_id].name = "ndpi-protocol";
sigmatch_table[ndpi_protocol_keyword_id].desc = "match on the detected nDPI protocol";
sigmatch_table[ndpi_protocol_keyword_id].url = "/rules/ndpi-protocol.html";
sigmatch_table[ndpi_protocol_keyword_id].Match = DetectnDPIProtocolPacketMatch;
sigmatch_table[ndpi_protocol_keyword_id].Setup = DetectnDPIProtocolSetup;
sigmatch_table[ndpi_protocol_keyword_id].Free = DetectnDPIProtocolFree;
sigmatch_table[ndpi_protocol_keyword_id].flags =
(SIGMATCH_QUOTES_OPTIONAL | SIGMATCH_HANDLE_NEGATION);
ndpi_risk_keyword_id = SCDetectHelperNewKeywordId();
const SCSigTableAppLiteElmt risk_kw = {
.name = "ndpi-risk",
.desc = "match on the detected nDPI risk",
.url = "/rules/ndpi-risk.html",
.flags = SIGMATCH_QUOTES_OPTIONAL | SIGMATCH_HANDLE_NEGATION,
.Setup = DetectnDPIRiskSetup,
.Free = DetectnDPIRiskFree,
};
ndpi_risk_keyword_id = SCDetectHelperKeywordRegister(&risk_kw);
if (ndpi_risk_keyword_id == UINT16_MAX) {
FatalError("Failed to register ndpi-risk keyword");
}
SCDetectHelperKeywordPacketMatchRegister(ndpi_risk_keyword_id, DetectnDPIRiskPacketMatch);
SCLogDebug("Registered new ndpi-risk keyword with ID %" PRIu32, ndpi_risk_keyword_id);
sigmatch_table[ndpi_risk_keyword_id].name = "ndpi-risk";
sigmatch_table[ndpi_risk_keyword_id].desc = "match on the detected nDPI risk";
sigmatch_table[ndpi_risk_keyword_id].url = "/rules/ndpi-risk.html";
sigmatch_table[ndpi_risk_keyword_id].Match = DetectnDPIRiskPacketMatch;
sigmatch_table[ndpi_risk_keyword_id].Setup = DetectnDPIRiskSetup;
sigmatch_table[ndpi_risk_keyword_id].Free = DetectnDPIRiskFree;
sigmatch_table[ndpi_risk_keyword_id].flags =
(SIGMATCH_QUOTES_OPTIONAL | SIGMATCH_HANDLE_NEGATION);
}
static void NdpiInit(void)

Loading…
Cancel
Save