app-layer: query raw protocol names

To avoid back-and-forth of http1 conversion
a second query function was added to support
existing use cases.

This change will be handy for the upcoming
default-policy for firewall settings
This commit is contained in:
Lukas Sismis
2026-08-18 08:06:22 +00:00
committed by Victor Julien
parent 9a2b700471
commit 3adbd677e8
6 changed files with 28 additions and 15 deletions
+5 -1
View File
@@ -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" {
+10
View File
@@ -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;
+8 -1
View File
@@ -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.
*
+1 -3
View File
@@ -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) {
+2 -4
View File
@@ -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?
+2 -6
View File
@@ -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;