SC_ATOMIC_DECLARE(unsigned int, num_tags); /**< Atomic counter, to know if we
have tagged hosts/sessions,
to avoid locking */
-static int tag_id = 0; /**< Host storage id for tags */
-static int flow_tag_id = 0; /**< Flow storage id for tags */
+static int host_tag_id = -1; /**< Host storage id for tags */
+static int flow_tag_id = -1; /**< Flow storage id for tags */
void TagInitCtx(void) {
SC_ATOMIC_INIT(num_tags);
- tag_id = HostStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
+ host_tag_id = HostStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
+ if (host_tag_id == -1) {
+ SCLogError(SC_ERR_HOST_INIT, "Can't initiate host storage for tag");
+ exit(EXIT_FAILURE);
+ }
flow_tag_id = FlowStorageRegister("tag", sizeof(void *), NULL, DetectTagDataListFree);
+ if (flow_tag_id == -1) {
+ SCLogError(SC_ERR_FLOW_INIT, "Can't initiate flow storage for tag");
+ exit(EXIT_FAILURE);
+ }
}
/**
}
int TagHostHasTag(Host *host) {
- return HostGetStorageById(host, tag_id) ? 1 : 0;
+ return HostGetStorageById(host, host_tag_id) ? 1 : 0;
}
static DetectTagDataEntry *DetectTagDataCopy(DetectTagDataEntry *dtd) {
return -1;
}
- void *tag = HostGetStorageById(host, tag_id);
+ void *tag = HostGetStorageById(host, host_tag_id);
if (tag == NULL) {
/* get a new tde as the one we have is on the stack */
DetectTagDataEntry *new_tde = DetectTagDataCopy(tde);
if (new_tde != NULL) {
- HostSetStorageById(host, tag_id, new_tde);
+ HostSetStorageById(host, host_tag_id, new_tde);
(void) SC_ATOMIC_ADD(num_tags, 1);
}
} else {
(void) SC_ATOMIC_ADD(num_tags, 1);
new_tde->next = tag;
- HostSetStorageById(host, tag_id, new_tde);
+ HostSetStorageById(host, host_tag_id, new_tde);
}
} else if (num_tags == DETECT_TAG_MAX_TAGS) {
SCLogDebug("Max tags for sessions reached (%"PRIu16")", num_tags);
DetectTagDataEntry *iter;
uint8_t flag_added = 0;
- iter = HostGetStorageById(host, tag_id);
+ iter = HostGetStorageById(host, host_tag_id);
prev = NULL;
while (iter != NULL) {
/* update counters */
iter = iter->next;
SCFree(tde);
(void) SC_ATOMIC_SUB(num_tags, 1);
- HostSetStorageById(host, tag_id, iter);
+ HostSetStorageById(host, host_tag_id, iter);
continue;
}
} else if (flag_added == 0) {
iter = iter->next;
SCFree(tde);
(void) SC_ATOMIC_SUB(num_tags, 1);
- HostSetStorageById(host, tag_id, iter);
+ HostSetStorageById(host, host_tag_id, iter);
continue;
}
} else if (flag_added == 0) {
iter = iter->next;
SCFree(tde);
(void) SC_ATOMIC_SUB(num_tags, 1);
- HostSetStorageById(host, tag_id, iter);
+ HostSetStorageById(host, host_tag_id, iter);
continue;
}
} else if (flag_added == 0) {
DetectTagDataEntry *prev = NULL;
int retval = 1;
- tmp = HostGetStorageById(host, tag_id);
+ tmp = HostGetStorageById(host, host_tag_id);
if (tmp == NULL)
return 1;
SCFree(tde);
(void) SC_ATOMIC_SUB(num_tags, 1);
} else {
- HostSetStorageById(host, tag_id, tmp->next);
+ HostSetStorageById(host, host_tag_id, tmp->next);
tde = tmp;
tmp = tde->next;