protodetect: simplify code since DCERPC UDP detection is improved

Protocol detection code is simplified. Removed dependency on explicit
alproto constants from the common part of code that must not be aware of
the each specific protocol features.

Ticket - 7111
pull/12514/head
Ilya Bakhtin 7 months ago committed by Victor Julien
parent 27f0db7526
commit fec06f8ac3

@ -1408,7 +1408,6 @@ AppProto AppLayerProtoDetectGetProto(AppLayerProtoDetectThreadCtx *tctx, Flow *f
(flags & STREAM_TOSERVER) ? "toserver" : "toclient"); (flags & STREAM_TOSERVER) ? "toserver" : "toclient");
AppProto alproto = ALPROTO_UNKNOWN; AppProto alproto = ALPROTO_UNKNOWN;
AppProto pm_alproto = ALPROTO_UNKNOWN;
if (!FLOW_IS_PM_DONE(f, flags)) { if (!FLOW_IS_PM_DONE(f, flags)) {
AppProto pm_results[g_alproto_max]; AppProto pm_results[g_alproto_max];
@ -1426,38 +1425,24 @@ AppProto AppLayerProtoDetectGetProto(AppLayerProtoDetectThreadCtx *tctx, Flow *f
FLOW_RESET_PP_DONE(f, reverse_dir); FLOW_RESET_PP_DONE(f, reverse_dir);
} }
} }
SCReturnUInt(alproto);
/* HACK: if detected protocol is dcerpc/udp, we run PP as well
* to avoid misdetecting DNS as DCERPC. */
if (!(ipproto == IPPROTO_UDP && alproto == ALPROTO_DCERPC))
goto end;
pm_alproto = alproto;
/* fall through */
} }
} }
if (!FLOW_IS_PP_DONE(f, flags)) { if (!FLOW_IS_PP_DONE(f, flags)) {
bool rflow = false; DEBUG_VALIDATE_BUG_ON(*reverse_flow);
alproto = AppLayerProtoDetectPPGetProto(f, buf, buflen, ipproto, flags, &rflow); alproto = AppLayerProtoDetectPPGetProto(f, buf, buflen, ipproto, flags, reverse_flow);
if (AppProtoIsValid(alproto)) { if (AppProtoIsValid(alproto)) {
if (rflow) { SCReturnUInt(alproto);
*reverse_flow = true;
}
goto end;
} }
} }
/* Look if flow can be found in expectation list */ /* Look if flow can be found in expectation list */
if (!FLOW_IS_PE_DONE(f, flags)) { if (!FLOW_IS_PE_DONE(f, flags)) {
DEBUG_VALIDATE_BUG_ON(*reverse_flow);
alproto = AppLayerProtoDetectPEGetProto(f, flags); alproto = AppLayerProtoDetectPEGetProto(f, flags);
} }
end:
if (!AppProtoIsValid(alproto))
alproto = pm_alproto;
SCReturnUInt(alproto); SCReturnUInt(alproto);
} }

Loading…
Cancel
Save