SCEnter();
AppProto a;
+ AppProto b = StringToAppProto(alproto_name);
for (a = 0; a < ALPROTO_MAX; a++) {
- if (alpd_ctx.alproto_names[a] != NULL &&
- strlen(alpd_ctx.alproto_names[a]) == strlen(alproto_name) &&
- (SCMemcmp(alpd_ctx.alproto_names[a], alproto_name, strlen(alproto_name)) == 0))
- {
- SCReturnCT(a, "AppProto");
+ if (alpd_ctx.alproto_names[a] != NULL && AppProtoEquals(b, a)) {
+ SCReturnCT(b, "AppProto");
}
}
return ((a > ALPROTO_UNKNOWN && a < ALPROTO_FAILED));
}
+// wether a signature AppProto matches a flow (or signature) AppProto
+static inline bool AppProtoEquals(AppProto sigproto, AppProto alproto)
+{
+ if (alproto == ALPROTO_HTTP2 && sigproto == ALPROTO_HTTP) {
+ // TODO config option
+ return true;
+ }
+ return (sigproto == alproto);
+}
+
/**
* \brief Maps the ALPROTO_*, to its string equivalent.
*
case PREFILTER_EXTRA_MATCH_UNUSED:
break;
case PREFILTER_EXTRA_MATCH_ALPROTO:
- if (p->flow == NULL || p->flow->alproto != ctx->value)
+ if (p->flow == NULL || !AppProtoEquals(ctx->value, p->flow->alproto))
return FALSE;
break;
case PREFILTER_EXTRA_MATCH_SRCPORT:
if (t->alproto == ALPROTO_UNKNOWN) {
/* special case, inspect engine applies to all protocols */
- } else if (s->alproto != ALPROTO_UNKNOWN && s->alproto != t->alproto)
+ } else if (s->alproto != ALPROTO_UNKNOWN && !AppProtoEquals(s->alproto, t->alproto))
goto next;
if (s->flags & SIG_FLAG_TOSERVER && !(s->flags & SIG_FLAG_TOCLIENT)) {
{
UtRegisterTest("DetectFilestoreTest01", DetectFilestoreTest01);
}
-#endif /* UNITTESTS */
\ No newline at end of file
+#endif /* UNITTESTS */
goto error;
if (lua->alproto != ALPROTO_UNKNOWN) {
- if (s->alproto != ALPROTO_UNKNOWN && lua->alproto != s->alproto) {
+ if (s->alproto != ALPROTO_UNKNOWN && !AppProtoEquals(s->alproto, lua->alproto)) {
goto error;
}
s->alproto = lua->alproto;
sigmatch_table[sm_type].name);
goto end;
}
- if (s->alproto != ALPROTO_UNKNOWN && s->alproto != alproto) {
+ if (s->alproto != ALPROTO_UNKNOWN && !AppProtoEquals(s->alproto, alproto)) {
SCLogError(SC_ERR_CONFLICTING_RULE_KEYWORDS, "rule contains conflicting "
"alprotos set");
goto end;
return -1;
}
- if (s->alproto != ALPROTO_UNKNOWN && s->alproto != alproto &&
- // allow to keep HTTP2 with HTTP1 keywords
- !(s->alproto == ALPROTO_HTTP2 && alproto == ALPROTO_HTTP)) {
+ if (s->alproto != ALPROTO_UNKNOWN && !AppProtoEquals(alproto, s->alproto)) {
SCLogError(SC_ERR_CONFLICTING_RULE_KEYWORDS,
"can't set rule app proto to %s: already set to %s",
AppProtoToString(alproto), AppProtoToString(s->alproto));
return -1;
}
- if (!(s->alproto == ALPROTO_HTTP2 && alproto == ALPROTO_HTTP)) {
+ // allow to keep HTTP2 as s->alproto with HTTP1 alproto keywords
+ if (!AppProtoEquals(alproto, s->alproto)) {
s->alproto = alproto;
}
s->flags |= SIG_FLAG_APPLAYER;
if (s->init_data->smlists[x]) {
const DetectEngineAppInspectionEngine *app = de_ctx->app_inspect_engines;
for ( ; app != NULL; app = app->next) {
- if (app->sm_list == x && ((s->alproto == app->alproto) || s->alproto == 0)) {
+ if (app->sm_list == x &&
+ (AppProtoEquals(s->alproto, app->alproto) || s->alproto == 0)) {
SCLogDebug("engine %s dir %d alproto %d",
DetectBufferTypeGetNameById(de_ctx, app->sm_list),
app->dir, app->alproto);
if (alproto != ALPROTO_UNKNOWN) {
/* see if the proto doesn't conflict
* with what we already have. */
- if (s->alproto != ALPROTO_UNKNOWN &&
- alproto != s->alproto) {
+ if (s->alproto != ALPROTO_UNKNOWN && !AppProtoEquals(s->alproto, alproto)) {
goto error;
}
if (DetectSignatureSetAppProto(s, alproto) < 0)
UtRegisterTest("DetectPcreParseCaptureTest", DetectPcreParseCaptureTest);
}
-#endif /* UNITTESTS */
\ No newline at end of file
+#endif /* UNITTESTS */
* so build the non_mpm array only for match candidates */
const SignatureMask rule_mask = det_ctx->non_pf_store_ptr[x].mask;
const uint8_t rule_alproto = det_ctx->non_pf_store_ptr[x].alproto;
- if ((rule_mask & mask) == rule_mask && (rule_alproto == 0 || rule_alproto == alproto)) {
+ if ((rule_mask & mask) == rule_mask &&
+ (rule_alproto == 0 || AppProtoEquals(rule_alproto, alproto))) {
det_ctx->non_pf_id_array[det_ctx->non_pf_id_cnt++] = det_ctx->non_pf_store_ptr[x].id;
}
}
/* if the sig has alproto and the session as well they should match */
if (likely(sflags & SIG_FLAG_APPLAYER)) {
- if (s->alproto != ALPROTO_UNKNOWN && s->alproto != scratch->alproto) {
+ if (s->alproto != ALPROTO_UNKNOWN && !AppProtoEquals(s->alproto, scratch->alproto)) {
if (s->alproto == ALPROTO_DCERPC) {
if (scratch->alproto != ALPROTO_SMB) {
SCLogDebug("DCERPC sig, alproto not SMB");
return false;
}
/* stream mpm and negated mpm sigs can end up here with wrong proto */
- if (!(f->alproto == s->alproto || s->alproto == ALPROTO_UNKNOWN)) {
+ if (!(AppProtoEquals(s->alproto, f->alproto) || s->alproto == ALPROTO_UNKNOWN)) {
TRACE_SID_TXS(s->id, tx, "alproto mismatch");
return false;
}