Skip to content

Commit 8455efd

Browse files
committed
app-layer: add substate support to list hooks
Add substates to the --list-app-layer-hooks option.
1 parent 8a5e8c6 commit 8455efd

1 file changed

Lines changed: 48 additions & 26 deletions

File tree

src/util-running-modes.c

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -92,35 +92,57 @@ int ListAppLayerHooks(const char *conf_filename)
9292
if (alprotos[a] != 1)
9393
continue;
9494

95-
const char *alproto_name = AppProtoToString(a);
96-
if (strcmp(alproto_name, "http") == 0)
97-
alproto_name = "http1";
98-
SCLogDebug("alproto %u/%s", a, alproto_name);
99-
100-
const int max_progress_ts =
101-
AppLayerParserGetStateProgressCompletionStatus(a, STREAM_TOSERVER);
102-
const int max_progress_tc =
103-
AppLayerParserGetStateProgressCompletionStatus(a, STREAM_TOCLIENT);
104-
105-
printf("%s:%s\n", alproto_name, "request_started");
106-
for (int p = 0; p <= max_progress_ts; p++) {
107-
const char *name = AppLayerParserGetStateNameById(
108-
IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOSERVER);
109-
if (name != NULL && !IsBuiltIn(name)) {
110-
printf("%s:%s\n", alproto_name, name);
95+
if (AppLayerParserSupportsSubStates(a)) {
96+
const uint8_t max_sub_state = AppLayerParserGetMaxSubState(a);
97+
for (uint8_t sub_state = 1; sub_state <= max_sub_state; sub_state++) {
98+
const char *sub_state_name = AppLayerParserGetSubStateName(a, sub_state);
99+
const uint8_t max_progress = AppLayerParserGetSubStateCompletion(a, sub_state);
100+
for (uint8_t state = 0; state <= max_progress; state++) {
101+
const char *name = AppLayerParserGetSubStateProgressName(
102+
a, sub_state, state, STREAM_TOSERVER);
103+
if (name != NULL) {
104+
printf("%s:%s:%s\n", AppProtoToString(a), sub_state_name, name);
105+
}
106+
}
107+
for (uint8_t state = 0; state <= max_progress; state++) {
108+
const char *name = AppLayerParserGetSubStateProgressName(
109+
a, sub_state, state, STREAM_TOCLIENT);
110+
if (name != NULL) {
111+
printf("%s:%s:%s\n", AppProtoToString(a), sub_state_name, name);
112+
}
113+
}
111114
}
112-
}
113-
printf("%s:%s\n", alproto_name, "request_complete");
114-
115-
printf("%s:%s\n", alproto_name, "response_started");
116-
for (int p = 0; p <= max_progress_tc; p++) {
117-
const char *name = AppLayerParserGetStateNameById(
118-
IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOCLIENT);
119-
if (name != NULL && !IsBuiltIn(name)) {
120-
printf("%s:%s\n", alproto_name, name);
115+
} else {
116+
const char *alproto_name = AppProtoToString(a);
117+
if (strcmp(alproto_name, "http") == 0)
118+
alproto_name = "http1";
119+
SCLogDebug("alproto %u/%s", a, alproto_name);
120+
121+
const int max_progress_ts =
122+
AppLayerParserGetStateProgressCompletionStatus(a, STREAM_TOSERVER);
123+
const int max_progress_tc =
124+
AppLayerParserGetStateProgressCompletionStatus(a, STREAM_TOCLIENT);
125+
126+
printf("%s:%s\n", alproto_name, "request_started");
127+
for (int p = 0; p <= max_progress_ts; p++) {
128+
const char *name = AppLayerParserGetStateNameById(
129+
IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOSERVER);
130+
if (name != NULL && !IsBuiltIn(name)) {
131+
printf("%s:%s\n", alproto_name, name);
132+
}
133+
}
134+
printf("%s:%s\n", alproto_name, "request_complete");
135+
136+
printf("%s:%s\n", alproto_name, "response_started");
137+
for (int p = 0; p <= max_progress_tc; p++) {
138+
const char *name = AppLayerParserGetStateNameById(
139+
IPPROTO_TCP /* TODO no ipproto */, a, p, STREAM_TOCLIENT);
140+
if (name != NULL && !IsBuiltIn(name)) {
141+
printf("%s:%s\n", alproto_name, name);
142+
}
121143
}
144+
printf("%s:%s\n", alproto_name, "response_complete");
122145
}
123-
printf("%s:%s\n", alproto_name, "response_complete");
124146
}
125147
return TM_ECODE_DONE;
126148
}

0 commit comments

Comments
 (0)