ipproto: *const ::std::os::raw::c_char, alproto_name: *const ::std::os::raw::c_char,
) -> ::std::os::raw::c_int;
}
+extern "C" {
+ pub fn SCAppLayerParserReallocCtx(alproto: AppProto) -> ::std::os::raw::c_int;
+}
extern "C" {
pub fn SCAppLayerParserRegisterParserAcceptableDataDirection(
ipproto: u8, alproto: AppProto, direction: u8,
{
SCEnter();
- if (alp_ctx.ctxs_len <= alproto && alproto < g_alproto_max) {
- // Realloc now as AppLayerParserRegisterStateFuncs is called first
- void *tmp = SCRealloc(
- alp_ctx.ctxs, sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]) * g_alproto_max);
- if (unlikely(tmp == NULL)) {
- FatalError("Unable to realloc alp_ctx.ctxs.");
- }
- alp_ctx.ctxs = tmp;
- memset(&alp_ctx.ctxs[alp_ctx.ctxs_len], 0,
- sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]) *
- (g_alproto_max - alp_ctx.ctxs_len));
- alp_ctx.ctxs_len = g_alproto_max;
- }
-
alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateAlloc = StateAlloc;
alp_ctx.ctxs[alproto][FlowGetProtoMapping(ipproto)].StateFree = StateFree;
static size_t preregistered_callbacks_nb = 0;
static size_t preregistered_callbacks_cap = 0;
+int SCAppLayerParserReallocCtx(AppProto alproto)
+{
+ if (alp_ctx.ctxs_len <= alproto && alproto < g_alproto_max) {
+ /* Realloc alp_ctx.ctxs, so that dynamic alproto can be treated as real/normal ones.
+ * In case we need to turn off dynamic alproto. */
+ void *tmp = SCRealloc(alp_ctx.ctxs, sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]) *
+ (alp_ctx.ctxs_len + ARRAY_CAP_STEP));
+ if (unlikely(tmp == NULL)) {
+ FatalError("Unable to realloc alp_ctx.ctxs.");
+ }
+ alp_ctx.ctxs = tmp;
+ memset(&alp_ctx.ctxs[alp_ctx.ctxs_len], 0,
+ sizeof(AppLayerParserProtoCtx[FLOW_PROTO_MAX]) * ARRAY_CAP_STEP);
+ alp_ctx.ctxs_len += ARRAY_CAP_STEP;
+ }
+ return 0;
+}
+
int AppLayerParserPreRegister(void (*Register)(void))
{
if (preregistered_callbacks_nb == preregistered_callbacks_cap) {
typedef int (*AppLayerParserGetFrameIdByNameFn)(const char *frame_name);
typedef const char *(*AppLayerParserGetFrameNameByIdFn)(const uint8_t id);
+int SCAppLayerParserReallocCtx(AppProto alproto);
int AppLayerParserPreRegister(void (*Register)(void));
/**
* \brief Register app layer parser for the protocol.
#include "suricata-common.h"
#include "app-layer-protos.h"
+#include "app-layer-parser.h"
#include "rust.h"
AppProto g_alproto_max = ALPROTO_MAX_STATIC;
g_alproto_strings = tmp;
}
g_alproto_max++;
+ SCAppLayerParserReallocCtx(alproto);
}
g_alproto_strings[alproto].str = proto_name;
g_alproto_strings[alproto].alproto = alproto;