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

Add auto retry on scanner connection lost during a runnning task #1452

Merged
merged 11 commits into from
Mar 18, 2021
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add standard info elem fields for NVTs in get_info [#1426](https://github.com/greenbone/gvmd/pull/1426)
- Add --ldap-debug option [#1439](https://github.com/greenbone/gvmd/pull/1439)
- Add check if PostgreSQL extensions are installed [#1444](https://github.com/greenbone/gvmd/pull/1444)
- Add auto retry on scanner connection lost during a running task [#1452](https://github.com/greenbone/gvmd/pull/1452)

### Changed
- Improve report counts performance [#1438](https://github.com/greenbone/gvmd/pull/1438)
Expand Down
25 changes: 11 additions & 14 deletions doc/gvmd.8
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,18 @@ Scanner type for --create-scanner and --modify-scanner.

Either 'OpenVAS', 'OSP', 'GMP', 'OSP-Sensor' or a number as used in GMP.
.TP
\fB--scanner-connection-retry=\fINUMBER\fB\f1
During a running task, number of auto retry on scanner connection lost, default 3.
.TP
\fB--schedule-timeout=\fITIME\fB\f1
Time out tasks that are more than TIME minutes overdue. -1 to disable, 0 for minimum time.
.TP
\fB--secinfo-commit-size=\fINUMBER\fB\f1
During CERT and SCAP sync, commit updates to the database every NUMBER items, 0 for unlimited.
.TP
\fB--slave-commit-size=\fINUMBER\fB\f1
During slave updates, commit after every NUMBER updated results and hosts, 0 for unlimited.
.TP
\fB-c, --unix-socket=\fIFILENAME\fB\f1
Listen on UNIX socket at FILENAME.
.TP
Expand All @@ -203,23 +209,14 @@ gvmd --port 1241

Serve GMP clients on port 1241 and connect to an OpenVAS scanner via the default OTP file socket.
.SH SEE ALSO
\fBopenvas(8)\f1, \fBgsad(8)\f1, \fBospd-openvas(8)\f1, \fBgreenbone-certdata-sync(8)\f1, \fBgreenbone-scapdata-sync(8)\f1,
\fBopenvas(8)\f1, \fBgsad(8)\f1, \fBospd-openvas(8)\f1, \fBgreenbone-certdata-sync(8)\f1, \fBgreenbone-scapdata-sync(8)\f1,
.SH MORE INFORMATION
The canonical places where you will find more information about the Greenbone Vulnerability Manager are:

.RS
.UR https://community.greenbone.net
Community Portal
.UE
.br
.UR https://github.com/greenbone
Development Platform
.UE
.br
.UR https://www.greenbone.net
Greenbone Website
.UE
.RE
\fBhttps://community.greenbone.net\f1 (Community Portal)

\fBhttps://github.com/greenbone\f1 (Development Platform)

\fBhttps://www.greenbone.net\f1 (Greenbone Website)
.SH COPYRIGHT
The Greenbone Vulnerability Manager is released under the GNU GPL, version 2, or, at your option, any later version.
7 changes: 7 additions & 0 deletions doc/gvmd.8.xml
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,13 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
as used in GMP.</p>
</optdesc>
</option>
<option>
<p><opt>--scanner-connection-retry=<arg>NUMBER</arg></opt></p>
<optdesc>
<p>During a running task, number of auto retry on scanner connection
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
lost, default 3.</p>
</optdesc>
</option>
<option>
<p><opt>--schedule-timeout=<arg>TIME</arg></opt></p>
<optdesc>
Expand Down
9 changes: 9 additions & 0 deletions src/gvmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1723,6 +1723,7 @@ gvmd (int argc, char** argv)
static gchar *scanner_credential = NULL;
static gchar *scanner_key_pub = NULL;
static gchar *scanner_key_priv = NULL;
static int scanner_connection_retry = SCANNER_CONNECTION_RETRY_DEFAULT;
static int schedule_timeout = SCHEDULE_TIMEOUT_DEFAULT;
static int secinfo_commit_size = SECINFO_COMMIT_SIZE_DEFAULT;
static int slave_commit_size = SLAVE_COMMIT_SIZE_DEFAULT;
Expand Down Expand Up @@ -1958,6 +1959,11 @@ gvmd (int argc, char** argv)
&scanner_ca_pub,
"Scanner CA Certificate path for --[create|modify]-scanner.",
"<scanner-ca-pub>" },
{ "scanner-connection-retry", '\0', 0, G_OPTION_ARG_INT,
&scanner_connection_retry,
"During a running task, number of auto retry on lost connection,"
" default: "G_STRINGIFY (SCANNER_CONNECTION_RETRY),
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
"<number>" },
{ "scanner-credential", '\0', 0, G_OPTION_ARG_STRING,
&scanner_credential,
"Scanner credential for --create-scanner and --modify-scanner."
Expand Down Expand Up @@ -2082,6 +2088,9 @@ gvmd (int argc, char** argv)

set_schedule_timeout (schedule_timeout);

/* Set the connection auto retry */
set_scanner_connection_retry (scanner_connection_retry);

/* Set slave commit size */
set_slave_commit_size (slave_commit_size);

Expand Down
62 changes: 61 additions & 1 deletion src/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ static int relay_migrate_sensors = 0;
*/
static int schedule_timeout = SCHEDULE_TIMEOUT_DEFAULT;

/**
* @brief Default for max auto retry on connection to scanner lost.
*/
static int scanner_connection_retry = SCANNER_CONNECTION_RETRY_DEFAULT;


/* Certificate and key management. */

Expand Down Expand Up @@ -3562,6 +3567,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
int rc, port;
scanner_t scanner;
gboolean started, queued_status_updated;
int retry, connection_retry;

scanner = task_scanner (task);
host = scanner_host (scanner);
Expand All @@ -3571,8 +3577,10 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
key_priv = scanner_key_priv (scanner);
started = FALSE;
queued_status_updated = FALSE;
connection_retry = get_scanner_connection_retry ();

while (1)
retry = connection_retry;
while (1 && retry >= 0)
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
{
int run_status, progress;
osp_scan_status_t osp_scan_status;
Expand All @@ -3585,10 +3593,20 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
break;
}

/* Get only the progress, without results and details. */
progress = get_osp_scan_report (scan_id, host, port, ca_pub, key_pub,
key_priv, 0, 0, NULL);

if (progress < 0 || progress > 100)
{
if (retry > 0)
{
retry--;
g_warning ("Connection lost with the scanner at %s. "
"Trying again in 1 second.", host);
gvm_sleep (1);
continue;
}
result_t result = make_osp_result
(task, "", "", "",
threat_message_type ("Error"),
Expand All @@ -3608,6 +3626,15 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
key_priv, 1, 1, &report_xml);
if (progress < 0 || progress > 100)
{
if (retry > 0)
{
retry--;
g_warning ("Connection lost with the scanner at %s. "
"Trying again in 1 second.", host);
gvm_sleep (1);
continue;
}

g_free (report_xml);
result_t result = make_osp_result
(task, "", "", "",
Expand Down Expand Up @@ -3653,6 +3680,15 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
else if (progress >= 0 && progress < 100
&& osp_scan_status == OSP_SCAN_STATUS_STOPPED)
{
if (retry > 0)
{
retry--;
g_warning ("Connection lost with the scanner at %s. "
"Trying again in 1 second.", host);
gvm_sleep (1);
continue;
}

result_t result = make_osp_result
(task, "", "", "",
threat_message_type ("Error"),
Expand Down Expand Up @@ -3683,6 +3719,7 @@ handle_osp_scan (task_t task, report_t report, const char *scan_id)
}
}

retry = connection_retry;
gvm_sleep (5);
}

Expand Down Expand Up @@ -4648,6 +4685,29 @@ run_osp_task (task_t task, int from, char **report_id)
return 0;
}

/**
* @brief Get the number of retry on a scanner connection lost.
timopollmeier marked this conversation as resolved.
Show resolved Hide resolved
*
* @return The number of retry on a scanner connection lost.
*/
int
get_scanner_connection_retry ()
{
return scanner_connection_retry;
}

/**
* @brief Set the number of retry on a scanner connection lost.
*
* @param new_retry The number of retry on a scanner connection lost.
*/
void
set_scanner_connection_retry (int new_retry)
{
if (new_retry >= 0)
scanner_connection_retry = new_retry;
}


/* CVE tasks. */

Expand Down
11 changes: 11 additions & 0 deletions src/manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2432,6 +2432,11 @@ manage_system_report (const char *, const char *, const char *, const char *,
*/
#define SLAVE_COMMIT_SIZE_DEFAULT 0

/**
* @brief Default for max auto retry on connection to scanner lost.
*/
#define SCANNER_CONNECTION_RETRY_DEFAULT 3

int
manage_create_scanner (GSList *, const db_conn_info_t *, const char *,
const char *, const char *, const char *, const char *,
Expand Down Expand Up @@ -2599,6 +2604,12 @@ osp_connect_with_data (const char *,
osp_connection_t *
osp_scanner_connect (scanner_t);

int
get_scanner_connection_retry ();

void
set_scanner_connection_retry (int);

int
verify_scanner (const char *, char **);

Expand Down