Name
hostdb -- Host Database, to associate persistant data with a connection.
Description
This interface permit to associate data with a connection,
this allow Detection Plugin to easily maintain persistant information
accross the various packet of a given connection.
A hostdb entry representating a connection is shared accross plugin.
Here is an exemple about how to use the hostdb database:
Using the Host Database
static void handle_connection(struct ip *ipcur)
{
hostdb_t *hdb;
host_data_t *ptr;
hdb = hostdb_search(ipcur);
if ( ! hdb ) {
/*
* No entry for this connection exist yet.
*/
hdb = hostdb_new(ipcur);
if ( ! hdb )
return;
ptr = create_host_data(ipcur);
if ( ! ptr )
return;
hostdb_set_plugin_data(hdb, plug_id, (unsigned long) ptr);
} else {
ptr = hostdb_get_plugin_data(hdb, plug_id);
if ( ! ptr ) {
/*
* No data associated with this connection by this plugin (identified by plug_id).
*/
ptr = create_host_data(ipcur);
if (! ptr )
return;
hostdb_set_plugin_data(hdb, plug_id, (unsigned long) ptr);
}
}
[ Play with 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 identified by the ip structure 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 only if the refcount for this hostdb element
is now 0.
hostdb_get_plugin_data()
#define hostdb_get_plugin_data(h, pid) (h)->pdata[(pid)] |
Return a pointer on the data associated with a given hostdb entry.
hostdb_set_plugin_data()
#define hostdb_set_plugin_data(h, pid, data) (h)->pdata[(pid)] = (data); (h)->refcount++ |
Associate data with the given hostdb entry.