hostdb

Name

hostdb -- Host Database, to associate persistant data with a connection.

Synopsis



struct      hostdb;
hostdb_t*   hostdb_search                   (const struct ip *ip);
hostdb_t*   hostdb_new                      (const struct ip *ip);
void        hostdb_del                      (hostdb_t *h,
                                             unsigned int pid);
int         hostdb_init                     (void);
#define     hostdb_get_plugin_data          (h, pid)
#define     hostdb_set_plugin_data          (h, pid, data)

Description

This interface permit Detection Plugins to associate data with a connection.

Here is an exemple about how to use the hostdb database:

Using the Host Database

static void handle_connection(struct ip *ipcur, void *data)
{
	void *p;
        hostdb_t *hdb;

        hdb = hostdb_search(ipcur);
        if ( ! hdb ) {
		/*
		 * No entry for this connection exist yet.
		 */
		hdb = hostdb_new(ipcur);
		if ( ! hdb )
			return;

		hostdb_set_plugin_data(hdb, plug_id, (unsigned long) data);
        } else {
		p = hostdb_get_plugin_data(hdb, plug_id);
		if ( ! p ) 
			/*
			 * No data associated with this connection by this plugin (identified by plug_id).
			 */
			hostdb_set_plugin_data(hdb, plug_id, (unsigned long) data);
	}
}
  

Details

struct hostdb

struct hostdb {
        const struct ip *ip;
        int key_cache;
        unsigned long *pdata;
        unsigned int refcount;
        struct _hostdb *prev;
        struct _hostdb *next;
};


hostdb_search ()

hostdb_t*   hostdb_search                   (const struct ip *ip);

Search for a host in the database.


hostdb_new ()

hostdb_t*   hostdb_new                      (const struct ip *ip);

Create a new hostdb entry and allocate space for plugin to associate data with this entry.


hostdb_del ()

void        hostdb_del                      (hostdb_t *h,
                                             unsigned int pid);

Delete a hostdb entry if the decreased refcount for this entry is now 0.


hostdb_init ()

int         hostdb_init                     (void);


hostdb_get_plugin_data()

#define hostdb_get_plugin_data(h, pid) (h)->pdata[(pid)]


hostdb_set_plugin_data()

#define hostdb_set_plugin_data(h, pid, data) (h)->pdata[(pid)] = (data); (h)->refcount++