From 127ef8f903f2f0cf9101c7992d3aa7e3dcbb6bee Mon Sep 17 00:00:00 2001 From: Anoop Saldanha Date: Fri, 6 Dec 2013 17:21:57 +0530 Subject: [PATCH] Use a typdef AppProto <-> uint16_t for representing app layer protocol. Some minor refactoring/cleanup, including renaming functions. --- src/app-layer-protos.c | 15 ++++++++------- src/app-layer-protos.h | 15 +++++++++------ src/detect-engine-analyzer.c | 2 +- src/detect-parse.c | 2 +- src/util-profiling.c | 6 +++--- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/app-layer-protos.c b/src/app-layer-protos.c index a68e407f2a..5d62875c07 100644 --- a/src/app-layer-protos.c +++ b/src/app-layer-protos.c @@ -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 + * \author Anoop Saldanha */ #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; } - diff --git a/src/app-layer-protos.h b/src/app-layer-protos.h index 409d8814e5..1d5f45161c 100644 --- a/src/app-layer-protos.h +++ b/src/app-layer-protos.h @@ -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 + * \author Anoop Saldanha */ -#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__ */ diff --git a/src/detect-engine-analyzer.c b/src/detect-engine-analyzer.c index 052b5bab8e..436f0fb54c 100644 --- a/src/detect-engine-analyzer.c +++ b/src/detect-engine-analyzer.c @@ -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); diff --git a/src/detect-parse.c b/src/detect-parse.c index 626af959e6..78e1bd5e0a 100644 --- a/src/detect-parse.c +++ b/src/detect-parse.c @@ -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 " diff --git a/src/util-profiling.c b/src/util-profiling.c index ecfcb5b2f8..89eceecd59 100644 --- a/src/util-profiling.c +++ b/src/util-profiling.c @@ -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); } }