Use a typdef AppProto <-> uint16_t for representing app layer protocol.

Some minor refactoring/cleanup, including renaming functions.
pull/745/head
Anoop Saldanha 12 years ago
parent abded4200a
commit 127ef8f903

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2011 Open Information Security Foundation
/* Copyright (C) 2007-2013 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -19,24 +19,26 @@
* \file
*
* \author Victor Julien <victor@inliniac.net>
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
*/
#include "suricata-common.h"
#include "app-layer-protos.h"
#define CASE_CODE(E) case E: return #E
/**
* \brief Maps the ALPROTO_*, to its string equivalent
* \brief Maps the ALPROTO_*, to its string equivalent.
*
* \param proto app layer protocol id
* \param alproto App layer protocol id.
*
* \retval string equivalent for the alproto
* \retval String equivalent for the alproto.
*/
const char *TmModuleAlprotoToString(enum AppProto proto)
const char *AppProtoToString(AppProto alproto)
{
const char *proto_name = NULL;
switch (proto) {
switch (alproto) {
case ALPROTO_HTTP:
proto_name = "http";
break;
@ -96,4 +98,3 @@ const char *TmModuleAlprotoToString(enum AppProto proto)
return proto_name;
}

@ -1,4 +1,4 @@
/* Copyright (C) 2007-2010 Open Information Security Foundation
/* Copyright (C) 2007-2013 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
@ -19,12 +19,13 @@
* \file
*
* \author Victor Julien <victor@inliniac.net>
* \author Anoop Saldanha <anoopsaldanha@gmail.com>
*/
#ifndef __APP_LAYER_PROTOS_H__
#define __APP_LAYER_PROTOS_H__
#ifndef __APP_LAYER_PROTOS__H__
#define __APP_LAYER_PROTOS__H__
enum AppProto {
enum {
ALPROTO_UNKNOWN = 0,
ALPROTO_HTTP,
ALPROTO_FTP,
@ -54,7 +55,9 @@ enum AppProto {
ALPROTO_MAX,
};
const char *TmModuleAlprotoToString(enum AppProto proto);
typedef uint16_t AppProto;
#endif /* __APP_LAYER_PROTOS_H__ */
const char *AppProtoToString(AppProto alproto);
#endif /* __APP_LAYER_PROTOS__H__ */

@ -785,7 +785,7 @@ void EngineAnalysisRules(Signature *s, char *line)
if (http_stat_code_buf) fprintf(rule_engine_analysis_FD, " Rule matches on http stat code buffer.\n");
if (http_ua_buf) fprintf(rule_engine_analysis_FD, " Rule matches on http user agent buffer.\n");
if (s->alproto != ALPROTO_UNKNOWN) {
fprintf(rule_engine_analysis_FD, " App layer protocol is %s.\n", TmModuleAlprotoToString(s->alproto));
fprintf(rule_engine_analysis_FD, " App layer protocol is %s.\n", AppProtoToString(s->alproto));
}
if (rule_content || rule_content_http || rule_pcre || rule_pcre_http) {
fprintf(rule_engine_analysis_FD, " Rule contains %d content options, %d http content options, %d pcre options, and %d pcre options with http modifiers.\n", rule_content, rule_content_http, rule_pcre, rule_pcre_http);

@ -1238,7 +1238,7 @@ int SigValidate(DetectEngineCtx *de_ctx, Signature *s) {
} else {
if (al_proto_table[s->alproto].to_server == 0 ||
al_proto_table[s->alproto].to_client == 0) {
const char *proto_name = TmModuleAlprotoToString(s->alproto);
const char *proto_name = AppProtoToString(s->alproto);
SCLogInfo("Signature uses options that need the app layer "
"parser for \"%s\", but the parser's disabled "
"for the protocol. Please check if you have "

@ -199,7 +199,7 @@ SCProfilingInit(void)
}
fprintf(packet_profile_csv_fp, "threading,");
for (i = 0; i < ALPROTO_MAX; i++) {
fprintf(packet_profile_csv_fp, "%s,", TmModuleAlprotoToString(i));
fprintf(packet_profile_csv_fp, "%s,", AppProtoToString(i));
}
fprintf(packet_profile_csv_fp, "STREAM (no app),proto detect,");
for (i = 0; i < PROF_DETECT_SIZE; i++) {
@ -455,7 +455,7 @@ void SCProfilingDumpPacketStats(void) {
(long double)total * 100;
fprintf(fp, "%-20s IPv4 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n",
TmModuleAlprotoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
AppProtoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
}
}
@ -473,7 +473,7 @@ void SCProfilingDumpPacketStats(void) {
(long double)total * 100;
fprintf(fp, "%-20s IPv6 %3d %12"PRIu64" %12"PRIu64" %12"PRIu64" %12"PRIu64" %12s %-6.2f\n",
TmModuleAlprotoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
AppProtoToString(m), p, pd->cnt, pd->min, pd->max, (uint64_t)(pd->tot / pd->cnt), totalstr, percent);
}
}

Loading…
Cancel
Save