OpenVAS Scanner 23.23.1
pluginlaunch.c File Reference

Manages the launching of plugins within processes. More...

#include "pluginlaunch.h"
#include "../misc/heartbeat.h"
#include "../misc/network.h"
#include "../misc/nvt_categories.h"
#include "../misc/plugutils.h"
#include "pluginload.h"
#include "pluginscheduler.h"
#include "plugs_req.h"
#include "processes.h"
#include "sighand.h"
#include "utils.h"
#include <errno.h>
#include <gvm/base/prefs.h>
#include <gvm/util/nvticache.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <unistd.h>

Data Structures

struct  running
 Structure to represent a process in the sense of a running NVT. More...

Macros

#define G_LOG_DOMAIN   "sd main"
 GLib log domain.
#define MAX_PROCESSES   32
 'Hard' limit of the max. number of concurrent plugins per host.

Functions

static int max_nvt_timeouts_reached (void)
 Check if max_nvt_timeouts is set and if has been reached.
static void update_running_processes (kb_t main_kb, kb_t kb)
static int common (GSList *list1, GSList *list2)
static GSList * required_ports_in_list (const char *oid, GSList *list)
static int simult_ports (const char *oid, const char *next_oid)
static int next_free_process (kb_t main_kb, kb_t kb, struct scheduler_plugin *upcoming)
void pluginlaunch_init (const char *host)
void pluginlaunch_disable_parallel_checks (void)
void pluginlaunch_enable_parallel_checks (void)
void pluginlaunch_stop (void)
static int plugin_timeout (nvti_t *nvti)
static int get_available_memory ()
static int check_memory ()
static int check_sysload ()
int plugin_launch (struct scan_globals *globals, struct scheduler_plugin *plugin, struct in6_addr *ip, GSList *vhosts, kb_t kb, kb_t main_kb, nvti_t *nvti, int *error)
 Start a plugin.
void pluginlaunch_wait (kb_t main_kb, kb_t kb)
 Waits and 'pushes' processes until num_running_processes is 0.
static int timeout_running_processes (void)
 Return shortest timeout of the running processes.
void pluginlaunch_wait_for_free_process (kb_t main_kb, kb_t kb)
 Waits and 'pushes' processes until the number of running processes has changed.

Variables

int global_min_memory
int global_max_sysload
static struct running processes [MAX_PROCESSES]
static int num_running_processes
static int max_running_processes
static int old_max_running_processes
static GSList * non_simult_ports = NULL
const char * hostname = NULL

Detailed Description

Manages the launching of plugins within processes.

Macro Definition Documentation

◆ G_LOG_DOMAIN

#define G_LOG_DOMAIN   "sd main"

GLib log domain.

◆ MAX_PROCESSES

#define MAX_PROCESSES   32

'Hard' limit of the max. number of concurrent plugins per host.

Function Documentation

◆ check_memory()

int check_memory ( )
static

◆ check_sysload()

int check_sysload ( )
static

◆ common()

int common ( GSList * list1,
GSList * list2 )
static

◆ get_available_memory()

int get_available_memory ( )
static

◆ max_nvt_timeouts_reached()

int max_nvt_timeouts_reached ( void )
static

Check if max_nvt_timeouts is set and if has been reached.

Returns
1 if reached, 0 if not reached or no set.

◆ next_free_process()

int next_free_process ( kb_t main_kb,
kb_t kb,
struct scheduler_plugin * upcoming )
static

If another NVT with same port requirements is running, wait.

Returns
ERR_NO_FREE_SLOT if MAX_PROCESSES are running, the index of the first free "slot" in the processes array otherwise.

◆ plugin_launch()

int plugin_launch ( struct scan_globals * globals,
struct scheduler_plugin * plugin,
struct in6_addr * ip,
GSList * vhosts,
kb_t kb,
kb_t main_kb,
nvti_t * nvti,
int * error )

Start a plugin.

Check for free slots available in the process table. Set error with ERR_NO_FREE_SLOT if the process table is full. Set error with ERR_CANT_FORK if was not possible to fork() a new child.

Returns
PID of process that is connected to the plugin as returned by plugin classes pl_launch function. Less than 0 means there was a problem, but error param should be checked.

◆ plugin_timeout()

int plugin_timeout ( nvti_t * nvti)
static

◆ pluginlaunch_disable_parallel_checks()

void pluginlaunch_disable_parallel_checks ( void )

◆ pluginlaunch_enable_parallel_checks()

void pluginlaunch_enable_parallel_checks ( void )

◆ pluginlaunch_init()

void pluginlaunch_init ( const char * host)

◆ pluginlaunch_stop()

void pluginlaunch_stop ( void )

◆ pluginlaunch_wait()

void pluginlaunch_wait ( kb_t main_kb,
kb_t kb )

Waits and 'pushes' processes until num_running_processes is 0.

◆ pluginlaunch_wait_for_free_process()

void pluginlaunch_wait_for_free_process ( kb_t main_kb,
kb_t kb )

Waits and 'pushes' processes until the number of running processes has changed.

◆ required_ports_in_list()

GSList * required_ports_in_list ( const char * oid,
GSList * list )
static

◆ simult_ports()

int simult_ports ( const char * oid,
const char * next_oid )
static

◆ timeout_running_processes()

int timeout_running_processes ( void )
static

Return shortest timeout of the running processes.

◆ update_running_processes()

void update_running_processes ( kb_t main_kb,
kb_t kb )
static

Variable Documentation

◆ global_max_sysload

int global_max_sysload
extern

◆ global_min_memory

int global_min_memory
extern

◆ hostname

const char* hostname = NULL

◆ max_running_processes

int max_running_processes
static

◆ non_simult_ports

GSList* non_simult_ports = NULL
static

◆ num_running_processes

int num_running_processes
static

◆ old_max_running_processes

int old_max_running_processes
static

◆ processes

struct running processes[MAX_PROCESSES]
static