From 323a747f391ed65171659bdbd50fe7cdc711bebe Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Tue, 1 Oct 2019 12:50:13 +0200 Subject: [PATCH] classtype: increase id size Switch from u8 to u16 to allow for more classtypes. Rename Signature::class to Signature::class_id to make it clear it is an id. --- src/alert-unified2-alert.c | 4 ++-- src/detect-classtype.c | 8 ++++---- src/detect.h | 2 +- src/util-classification-config.c | 10 +++++----- src/util-classification-config.h | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/alert-unified2-alert.c b/src/alert-unified2-alert.c index 6fe26efa45..fd23ed1bd0 100644 --- a/src/alert-unified2-alert.c +++ b/src/alert-unified2-alert.c @@ -948,7 +948,7 @@ static int Unified2IPv6TypeAlert(ThreadVars *t, const Packet *p, void *data) phdr->generator_id = htonl(pa->s->gid); phdr->signature_id = htonl(pa->s->id); phdr->signature_revision = htonl(pa->s->rev); - phdr->classification_id = htonl(pa->s->class); + phdr->classification_id = htonl(pa->s->class_id); phdr->priority_id = htonl(pa->s->prio); SCMutexLock(&file_ctx->fp_mutex); @@ -1136,7 +1136,7 @@ static int Unified2IPv4TypeAlert (ThreadVars *tv, const Packet *p, void *data) phdr->generator_id = htonl(pa->s->gid); phdr->signature_id = htonl(pa->s->id); phdr->signature_revision = htonl(pa->s->rev); - phdr->classification_id = htonl(pa->s->class); + phdr->classification_id = htonl(pa->s->class_id); phdr->priority_id = htonl(pa->s->prio); /* check and enforce the filesize limit */ diff --git a/src/detect-classtype.c b/src/detect-classtype.c index 6122e523f9..04955bf5cf 100644 --- a/src/detect-classtype.c +++ b/src/detect-classtype.c @@ -101,7 +101,7 @@ static int DetectClasstypeSetup(DetectEngineCtx *de_ctx, Signature *s, const cha { char parsed_ct_name[1024] = ""; - if ((s->class > 0) || (s->class_msg != NULL)) { + if ((s->class_id > 0) || (s->class_msg != NULL)) { SCLogWarning(SC_ERR_CONFLICTING_RULE_KEYWORDS, "duplicated 'classtype' " "keyword detected. Using instance with highest priority"); } @@ -121,16 +121,16 @@ static int DetectClasstypeSetup(DetectEngineCtx *de_ctx, Signature *s, const cha if ((s->init_data->init_flags & SIG_FLAG_INIT_PRIO_EXPLICT) != 0) { /* don't touch Signature::prio */ - s->class = ct->classtype_id; + s->class_id = ct->classtype_id; s->class_msg = ct->classtype_desc; } else if (s->prio == -1) { s->prio = ct->priority; - s->class = ct->classtype_id; + s->class_id = ct->classtype_id; s->class_msg = ct->classtype_desc; } else { if (ct->priority < s->prio) { s->prio = ct->priority; - s->class = ct->classtype_id; + s->class_id = ct->classtype_id; s->class_msg = ct->classtype_desc; } } diff --git a/src/detect.h b/src/detect.h index d556dd1fd9..c4babf91ff 100644 --- a/src/detect.h +++ b/src/detect.h @@ -535,7 +535,7 @@ typedef struct Signature_ { DetectProto proto; /** classification id **/ - uint8_t class; + uint16_t class_id; /** ipv4 match arrays */ uint16_t addr_dst_match4_cnt; diff --git a/src/util-classification-config.c b/src/util-classification-config.c index a59624af6f..6cc75672c9 100644 --- a/src/util-classification-config.c +++ b/src/util-classification-config.c @@ -56,7 +56,7 @@ char SCClassConfClasstypeHashCompareFunc(void *data1, uint16_t datalen1, void SCClassConfClasstypeHashFree(void *ch); static const char *SCClassConfGetConfFilename(const DetectEngineCtx *de_ctx); -static SCClassConfClasstype *SCClassConfAllocClasstype(uint8_t classtype_id, +static SCClassConfClasstype *SCClassConfAllocClasstype(uint16_t classtype_id, const char *classtype, const char *classtype_desc, int priority); static void SCClassConfDeAllocClasstype(SCClassConfClasstype *ct); @@ -248,13 +248,13 @@ static char *SCClassConfStringToLowercase(const char *str) * \retval 0 On success. * \retval -1 On failure. */ -static int SCClassConfAddClasstype(char *rawstr, uint8_t index, DetectEngineCtx *de_ctx) +static int SCClassConfAddClasstype(char *rawstr, uint16_t index, DetectEngineCtx *de_ctx) { char ct_name[64]; char ct_desc[512]; char ct_priority_str[16]; int ct_priority = 0; - uint8_t ct_id = index; + uint16_t ct_id = index; SCClassConfClasstype *ct_new = NULL; SCClassConfClasstype *ct_lookup = NULL; @@ -359,7 +359,7 @@ static int SCClassConfIsLineBlankOrComment(char *line) static void SCClassConfParseFile(DetectEngineCtx *de_ctx, FILE *fd) { char line[1024]; - uint8_t i = 1; + uint16_t i = 1; while (fgets(line, sizeof(line), fd) != NULL) { if (SCClassConfIsLineBlankOrComment(line)) @@ -389,7 +389,7 @@ static void SCClassConfParseFile(DetectEngineCtx *de_ctx, FILE *fd) * \retval ct Pointer to the new instance of SCClassConfClasstype on success; * NULL on failure. */ -static SCClassConfClasstype *SCClassConfAllocClasstype(uint8_t classtype_id, +static SCClassConfClasstype *SCClassConfAllocClasstype(uint16_t classtype_id, const char *classtype, const char *classtype_desc, int priority) diff --git a/src/util-classification-config.h b/src/util-classification-config.h index e35e992e18..97f58abb5b 100644 --- a/src/util-classification-config.h +++ b/src/util-classification-config.h @@ -29,7 +29,7 @@ */ typedef struct SCClassConfClasstype_ { /* The index of the classification within classification.confg */ - uint8_t classtype_id; + uint16_t classtype_id; /* The priority this classification type carries */ int priority; -- 2.47.2