Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to re allocate the finish flag in the hosts queue for alive tests. #407

Merged
merged 10 commits into from
Oct 12, 2020
23 changes: 22 additions & 1 deletion boreas/boreas_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ get_host_from_queue (kb_t alive_hosts_kb, gboolean *alive_deteciton_finished)
* @param kb KB to use.
* @param addr_str IP addr in str representation to put on queue.
*/
static void
void
put_host_on_queue (kb_t kb, char *addr_str)
{
/* Print host on command line if no kb is available. No kb available could
Expand All @@ -238,6 +238,27 @@ put_host_on_queue (kb_t kb, char *addr_str)
__func__, addr_str);
}

/**
* @brief Reallocate finish signal at the end of alive detection queue.
*
* @param main_kb kb to use
*/
void
realloc_finish_signal_on_queue(kb_t main_kb)
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
{
int kb_item_push_str_err, pos;

pos = 1; // Append the item at the end of the queue.
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
kb_item_push_str_err = kb_item_add_str_unique (main_kb,
ALIVE_DETECTION_QUEUE,
ALIVE_DETECTION_FINISHED,
0, pos);
mattmundell marked this conversation as resolved.
Show resolved Hide resolved
if (kb_item_push_str_err)
g_debug ("%s: Could not push the Boreas finish signal on the alive "
"detection Queue.",
__func__);
}

/**
* @brief Put finish signal on alive detection queue.
*
Expand Down
6 changes: 6 additions & 0 deletions boreas/boreas_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@
gvm_host_t *
get_host_from_queue (kb_t, gboolean *);

void
put_host_on_queue (kb_t, char *);

void
put_finish_signal_on_queue (void *);

void
realloc_finish_signal_on_queue(kb_t);
mattmundell marked this conversation as resolved.
Show resolved Hide resolved

void
send_dead_hosts_to_ospd_openvas (int);

Expand Down
8 changes: 5 additions & 3 deletions util/kb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1112,11 +1112,13 @@ redis_del_items (kb_t kb, const char *name)
* @param[in] name Item name.
* @param[in] str Item value.
* @param[in] len Value length. Used for blobs.
* @param[in] pos Which position the value is appended to. 0 for right,
* 1 for left position in the list.
*
* @return 0 on success, non-null on error.
*/
static int
redis_add_str_unique (kb_t kb, const char *name, const char *str, size_t len)
redis_add_str_unique (kb_t kb, const char *name, const char *str, size_t len, int pos)
{
struct kb_redis *kbr;
redisReply *rep = NULL;
Expand All @@ -1135,7 +1137,7 @@ redis_add_str_unique (kb_t kb, const char *name, const char *str, size_t len)
if (len == 0)
{
redisAppendCommand (ctx, "LREM %s 1 %s", name, str);
redisAppendCommand (ctx, "RPUSH %s %s", name, str);
redisAppendCommand (ctx, "%s %s %s", pos ? "LPUSH" : "RPUSH", name, str);
redisGetReply (ctx, (void **) &rep);
if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
g_debug ("Key '%s' already contained value '%s'", name, str);
Expand All @@ -1145,7 +1147,7 @@ redis_add_str_unique (kb_t kb, const char *name, const char *str, size_t len)
else
{
redisAppendCommand (ctx, "LREM %s 1 %b", name, str, len);
redisAppendCommand (ctx, "RPUSH %s %b", name, str, len);
redisAppendCommand (ctx, "%s %s %b", pos ? "LPUSH" : "RPUSH", name, str, len);
redisGetReply (ctx, (void **) &rep);
if (rep && rep->type == REDIS_REPLY_INTEGER && rep->integer == 1)
g_debug ("Key '%s' already contained string '%s'", name, str);
Expand Down
8 changes: 5 additions & 3 deletions util/kb.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ struct kb_operations
* Function provided by an implementation to insert (append) a new
* unique entry under a given name.
*/
int (*kb_add_str_unique) (kb_t, const char *, const char *, size_t);
int (*kb_add_str_unique) (kb_t, const char *, const char *, size_t, int);
/**
* Function provided by an implementation to get (replace) a new entry
* under a given name.
Expand Down Expand Up @@ -458,16 +458,18 @@ kb_item_add_str (kb_t kb, const char *name, const char *str, size_t len)
* @param[in] name Item name.
* @param[in] str Item value.
* @param[in] len Value length. Used for blobs.
* @param[in] pos Which position the value is appended to. 0 for right,
* 1 for left position in the list.
* @return 0 on success, non-null on error.
*/
static inline int
kb_item_add_str_unique (kb_t kb, const char *name, const char *str, size_t len)
kb_item_add_str_unique (kb_t kb, const char *name, const char *str, size_t len, int pos)
{
assert (kb);
assert (kb->kb_ops);
assert (kb->kb_ops->kb_add_str_unique);

return kb->kb_ops->kb_add_str_unique (kb, name, str, len);
return kb->kb_ops->kb_add_str_unique (kb, name, str, len, pos);
}

/**
Expand Down