Skip to content

Commit

Permalink
Change: Send a message with excluded hosts count to ospd. (#1528)
Browse files Browse the repository at this point in the history
Also, the excluded hosts count is subtracted from the hosts count sent to ospd.

With this change, openvas sends the information necessary for the progress calculation,
and ospd doesn't have to calculate the excluded hosts and subtract from the total amount of hosts.
  • Loading branch information
jjnicola committed Mar 11, 2024
1 parent fb77d8c commit cefbebc
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/attack.c
Original file line number Diff line number Diff line change
Expand Up @@ -912,22 +912,23 @@ attack_start (struct ipc_context *ipcc, struct attack_start_args *args)
}
}

static void
static int
apply_hosts_excluded (gvm_hosts_t *hosts)
{
const char *exclude_hosts = prefs_get ("exclude_hosts");

int ret = 0;
/* Exclude hosts ? */
if (exclude_hosts)
{
/* Exclude hosts, resolving hostnames. */
int ret = gvm_hosts_exclude (hosts, exclude_hosts);
ret = gvm_hosts_exclude (hosts, exclude_hosts);

if (ret > 0)
g_message ("exclude_hosts: Skipped %d host(s).", ret);
if (ret < 0)
g_message ("exclude_hosts: Error.");
}
return ret;
}

#ifdef FEATURE_HOSTS_ALLOWED_ONLY
Expand Down Expand Up @@ -1279,16 +1280,23 @@ attack_network (struct scan_globals *globals)
apply_hosts_allow_deny (hosts);
#endif

// Remove the excluded hosts
int exc = apply_hosts_excluded (hosts);

/* Send the excluded hosts count to the client, after removing duplicated and
* unresolved hosts.*/
sprintf (buf, "%d", exc + already_excluded);
connect_main_kb (&main_kb);
message_to_client (main_kb, buf, NULL, NULL, "HOSTS_EXCLUDED");
kb_lnk_reset (main_kb);

/* Send the hosts count to the client, after removing duplicated and
* unresolved hosts.*/
sprintf (buf, "%d", gvm_hosts_count (hosts) + already_excluded);
sprintf (buf, "%d", gvm_hosts_count (hosts));
connect_main_kb (&main_kb);
message_to_client (main_kb, buf, NULL, NULL, "HOSTS_COUNT");
kb_lnk_reset (main_kb);

// Remove the excluded hosts
apply_hosts_excluded (hosts);

host = gvm_hosts_next (hosts);
if (host == NULL)
goto stop;
Expand Down

0 comments on commit cefbebc

Please sign in to comment.