Go to the documentation of this file.
49 #define TEMPLATE_DEFAULT_PORT "7"
53 #define TEMPLATE_MIN_FRAME_LEN 1
92 static void TemplateTxFree(
void *txv)
109 static void *TemplateStateAlloc(
void *orig_state,
AppProto proto_orig)
120 static void TemplateStateFree(
void *state)
125 while ((tx =
TAILQ_FIRST(&template_state->tx_list)) != NULL) {
138 static void TemplateStateTxFree(
void *statev, uint64_t tx_id)
149 if (tx->
tx_id != tx_id) {
159 SCLogNotice(
"Transaction %"PRIu64
" not found.", tx_id);
162 static int TemplateStateGetEventInfo(
const char *event_name,
int *event_id,
166 if (*event_id == -1) {
168 "template enum map table.", event_name);
178 static int TemplateStateGetEventInfoById(
int event_id,
const char **event_name,
182 if (*event_name == NULL) {
184 "template enum map table.", event_id);
201 static AppProto TemplateProbingParserTs(
Flow *f, uint8_t direction,
202 const uint8_t *input, uint32_t input_len, uint8_t *rdir)
210 SCLogNotice(
"Protocol not detected as ALPROTO_TEMPLATE.");
223 static AppProto TemplateProbingParserTc(
Flow *f, uint8_t direction,
224 const uint8_t *input, uint32_t input_len, uint8_t *rdir)
232 SCLogNotice(
"Protocol not detected as ALPROTO_TEMPLATE.");
237 StreamSlice stream_slice,
void *local_data)
240 const uint8_t *input = StreamSliceGetData(&stream_slice);
241 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
242 const uint8_t
flags = StreamSliceGetFlags(&stream_slice);
244 SCLogNotice(
"Parsing template request: len=%"PRIu32, input_len);
251 }
else if (
flags & STREAM_GAP) {
286 SCLogNotice(
"Failed to allocate new Template tx.");
312 StreamSlice stream_slice,
void *local_data)
316 const uint8_t *input = StreamSliceGetData(&stream_slice);
317 uint32_t input_len = StreamSliceGetDataLen(&stream_slice);
322 if ((input == NULL || input_len == 0) &&
329 if (input == NULL || input_len == 0) {
345 SCLogNotice(
"Failed to find transaction for response on state %p.",
350 SCLogNotice(
"Found transaction %"PRIu64
" for response on state %p.",
360 SCLogNotice(
"WARNING: Transaction already has response data, "
361 "existing data will be overwritten.");
381 static uint64_t TemplateGetTxCnt(
void *statev)
388 static void *TemplateGetTx(
void *statev, uint64_t tx_id)
393 SCLogDebug(
"Requested tx ID %" PRIu64
".", tx_id);
396 if (tx->
tx_id == tx_id) {
397 SCLogDebug(
"Transaction %" PRIu64
" found, returning tx object %p.", tx_id, tx);
402 SCLogDebug(
"Transaction ID %" PRIu64
" not found.", tx_id);
419 static int TemplateGetStateProgress(
void *txv, uint8_t direction)
423 SCLogNotice(
"Transaction progress requested for tx ID %"PRIu64
424 ", direction=0x%02x", tx->
tx_id, direction);
429 else if (direction & STREAM_TOSERVER) {
441 static AppLayerTxData *TemplateGetTxData(
void *vtx)
449 const char *proto_name =
"template";
455 SCLogDebug(
"Template TCP protocol detection enabled.");
461 SCLogNotice(
"Unittest mode, registering default configuration.");
464 TemplateProbingParserTs, TemplateProbingParserTc);
471 TemplateProbingParserTs, TemplateProbingParserTc)) {
472 SCLogDebug(
"No template app-layer configuration, enabling echo"
473 " detection TCP detection on port %s.",
478 TemplateProbingParserTs, TemplateProbingParserTc);
486 SCLogDebug(
"Protocol detector and parser disabled for Template.");
492 SCLogNotice(
"Registering Template protocol parser.");
497 TemplateStateAlloc, TemplateStateFree);
501 STREAM_TOSERVER, TemplateParseRequest);
505 STREAM_TOCLIENT, TemplateParseResponse);
510 TemplateStateTxFree);
526 TemplateStateGetEventInfo);
528 TemplateStateGetEventInfoById);
536 SCLogDebug(
"Template protocol parsing disabled.");
void AppLayerParserRegisterGetStateProgressFunc(uint8_t ipproto, AppProto alproto, int(*StateGetProgress)(void *alstate, uint8_t direction))
int AppLayerProtoDetectPPParseConfPorts(const char *ipproto_name, uint8_t ipproto, const char *alproto_name, AppProto alproto, uint16_t min_depth, uint16_t max_depth, ProbingParserFPtr ProbingParserTs, ProbingParserFPtr ProbingParserTc)
void TemplateParserRegisterTests(void)
void AppLayerParserRegisterOptionFlags(uint8_t ipproto, AppProto alproto, uint32_t flags)
struct HtpBodyChunk_ * next
int AppLayerParserConfParserEnabled(const char *ipproto, const char *alproto_name)
check if a parser is enabled in the config Returns enabled always if: were running unittests
enum AppLayerEventType_ AppLayerEventType
void AppLayerParserRegisterStateProgressCompletionStatus(AppProto alproto, const int ts, const int tc)
void AppLayerParserRegisterTxFreeFunc(uint8_t ipproto, AppProto alproto, void(*StateTransactionFree)(void *, uint64_t))
#define TAILQ_FOREACH(var, head, field)
void AppLayerDecoderEventsFreeEvents(AppLayerDecoderEvents **events)
#define TEMPLATE_DEFAULT_PORT
#define TAILQ_INSERT_TAIL(head, elm, field)
#define APP_LAYER_PARSER_EOF_TS
@ APP_LAYER_EVENT_TYPE_TRANSACTION
void AppLayerProtoDetectPPRegister(uint8_t ipproto, const char *portstr, AppProto alproto, uint16_t min_depth, uint16_t max_depth, uint8_t direction, ProbingParserFPtr ProbingParser1, ProbingParserFPtr ProbingParser2)
register parser at a port
int AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint8_t flag)
#define TAILQ_REMOVE(head, elm, field)
#define TAILQ_FIRST(head)
uint32_t response_buffer_len
void AppLayerParserRegisterStateFuncs(uint8_t ipproto, AppProto alproto, void *(*StateAlloc)(void *, AppProto), void(*StateFree)(void *))
void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto, void(*RegisterUnittests)(void))
#define APP_LAYER_PARSER_EOF_TC
void AppLayerParserRegisterGetEventInfo(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfo)(const char *event_name, int *event_id, AppLayerEventType *event_type))
@ TEMPLATE_DECODER_EVENT_EMPTY_MESSAGE
void AppLayerProtoDetectRegisterProtocol(AppProto alproto, const char *alproto_name)
Registers a protocol for protocol detection phase.
int RunmodeIsUnittests(void)
#define TAILQ_FOREACH_SAFE(var, head, field, tvar)
int AppLayerParserRegisterParser(uint8_t ipproto, AppProto alproto, uint8_t direction, AppLayerParserFPtr Parser)
Register app layer parser for the protocol.
void AppLayerParserRegisterGetTx(uint8_t ipproto, AppProto alproto, void *(StateGetTx)(void *alstate, uint64_t tx_id))
uint8_t * response_buffer
const char * SCMapEnumValueToName(int enum_value, SCEnumCharMap *table)
Maps an enum value to a string name, from the supplied table.
#define SCReturnStruct(x)
uint32_t request_buffer_len
int SCMapEnumNameToValue(const char *enum_name, SCEnumCharMap *table)
Maps a string name to an enum value from the supplied table. Please specify the last element of any m...
void AppLayerDecoderEventsSetEventRaw(AppLayerDecoderEvents **sevents, uint8_t event)
Set an app layer decoder event.
#define SCLogError(err_code,...)
Macro used to log ERROR messages.
void AppLayerParserRegisterTxDataFunc(uint8_t ipproto, AppProto alproto, AppLayerTxData *(*GetTxData)(void *tx))
#define APP_LAYER_PARSER_OPT_ACCEPT_GAPS
void AppLayerParserRegisterGetEventInfoById(uint8_t ipproto, AppProto alproto, int(*StateGetEventInfoById)(int event_id, const char **event_name, AppLayerEventType *event_type))
void RegisterTemplateParsers(void)
void AppLayerParserRegisterGetTxCnt(uint8_t ipproto, AppProto alproto, uint64_t(*StateGetTxCnt)(void *alstate))
@ SC_ERR_INVALID_ENUM_MAP
int AppLayerProtoDetectConfProtoDetectionEnabledDefault(const char *ipproto, const char *alproto, bool default_enabled)
Given a protocol name, checks if proto detection is enabled in the conf file.
#define SCLogNotice(...)
Macro used to log NOTICE messages.
#define TEMPLATE_MIN_FRAME_LEN
#define DEBUG_VALIDATE_BUG_ON(exp)
SCEnumCharMap template_decoder_event_table[]