diff --git a/rust/sys/src/sys.rs b/rust/sys/src/sys.rs index b13890f6b9..09ce2b8f78 100644 --- a/rust/sys/src/sys.rs +++ b/rust/sys/src/sys.rs @@ -73,7 +73,11 @@ pub enum AppProtoEnum { } pub type AppProto = u16; extern "C" { - #[doc = " \\brief Maps the ALPROTO_*, to its string equivalent.\n\n \\param alproto App layer protocol id.\n\n \\retval String equivalent for the alproto."] + #[doc = " \\brief Maps the ALPROTO_*, to its registered string equivalent.\n \\param alproto App layer protocol id.\n \\retval String equivalent for the alproto."] + pub fn AppProtoToStringRaw(alproto: AppProto) -> *const ::std::os::raw::c_char; +} +extern "C" { + #[doc = " \\brief Maps the ALPROTO_*, to its normalized string equivalent.\n\n \\param alproto App layer protocol id.\n\n \\retval String equivalent for the alproto."] pub fn AppProtoToString(alproto: AppProto) -> *const ::std::os::raw::c_char; } extern "C" { diff --git a/src/app-layer-protos.c b/src/app-layer-protos.c index 13fe402949..4a648dffcd 100644 --- a/src/app-layer-protos.c +++ b/src/app-layer-protos.c @@ -38,6 +38,16 @@ typedef struct AppProtoStringTuple { AppProtoStringTuple *g_alproto_strings = NULL; +const char *AppProtoToStringRaw(AppProto alproto) +{ + const char *proto_name = NULL; + if (alproto < g_alproto_max) { + DEBUG_VALIDATE_BUG_ON(g_alproto_strings[alproto].alproto != alproto); + proto_name = g_alproto_strings[alproto].str; + } + return proto_name; +} + const char *AppProtoToString(AppProto alproto) { const char *proto_name = NULL; diff --git a/src/app-layer-protos.h b/src/app-layer-protos.h index 21b21359ca..75c4ee3db9 100644 --- a/src/app-layer-protos.h +++ b/src/app-layer-protos.h @@ -178,7 +178,14 @@ static inline AppProto AppProtoCommon(AppProto sigproto, AppProto alproto) } /** - * \brief Maps the ALPROTO_*, to its string equivalent. + * \brief Maps the ALPROTO_*, to its registered string equivalent. + * \param alproto App layer protocol id. + * \retval String equivalent for the alproto. + */ +const char *AppProtoToStringRaw(AppProto alproto); + +/** + * \brief Maps the ALPROTO_*, to its normalized string equivalent. * * \param alproto App layer protocol id. * diff --git a/src/detect-engine.c b/src/detect-engine.c index f27112e581..14c1740003 100644 --- a/src/detect-engine.c +++ b/src/detect-engine.c @@ -885,13 +885,11 @@ const char *DetectEngineAppHookToName( int DetectEngineAppHookToSmlist( const AppProto p, const uint8_t sub_state, const uint8_t state, const uint8_t direction) { - const char *app_proto = AppProtoToString(p); + const char *app_proto = AppProtoToStringRaw(p); if (app_proto == NULL) { SCLogError("unknown app_proto %u", p); return -1; } - if (strcmp(app_proto, "http") == 0) - app_proto = "http1"; char generic_hook_name[256]; if (sub_state == 0) { diff --git a/src/detect-parse.c b/src/detect-parse.c index 758ca54d03..a0af3fdd99 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -1156,14 +1156,12 @@ static bool IsBuiltIn(const char *n) void DetectRegisterAppLayerHookLists(void) { for (AppProto a = ALPROTO_FAILED + 1; a < g_alproto_max; a++) { - const char *alproto_name = AppProtoToString(a); - if (strcmp(alproto_name, "http") == 0) - alproto_name = "http1"; + const char *alproto_name = AppProtoToStringRaw(a); SCLogDebug("alproto %u/%s", a, alproto_name); if (AppLayerParserSupportsSubStates(a)) { uint8_t max_sub_state = AppLayerParserGetMaxSubState(a); - SCLogDebug("%s: max sub state for %u is %u", AppProtoToString(a), a, max_sub_state); + SCLogDebug("%s: max sub state for %u is %u", alproto_name, a, max_sub_state); for (uint8_t s = 1; s <= max_sub_state; s++) { const uint8_t max_state = AppLayerParserGetSubStateCompletion( a, s); // TODO allow different completion per direction? diff --git a/src/util-running-modes.c b/src/util-running-modes.c index 668f7d1ac6..5aaf6bf09d 100644 --- a/src/util-running-modes.c +++ b/src/util-running-modes.c @@ -113,9 +113,7 @@ int ListAppLayerHooks(const char *conf_filename) } } } else { - const char *alproto_name = AppProtoToString(a); - if (strcmp(alproto_name, "http") == 0) - alproto_name = "http1"; + const char *alproto_name = AppProtoToStringRaw(a); SCLogDebug("alproto %u/%s", a, alproto_name); const int max_progress_ts = @@ -164,9 +162,7 @@ int ListAppLayerFrames(const char *conf_filename) if (alprotos[a] != 1) continue; - const char *alproto_name = AppProtoToString(a); - if (strcmp(alproto_name, "http") == 0) - alproto_name = "http1"; + const char *alproto_name = AppProtoToStringRaw(a); SCLogDebug("alproto %u/%s", a, alproto_name); bool tcp_stream_once = false;