Things required to build libalias as kernel module:
- kernel module declarations and handler. - macros to map malloc(3) calls to malloc(9) ones. - malloc(9) declarations. - call finishoff() from module handler MOD_UNLOAD case instead of atexit(3). - use panic(9) instead of abort(3) - take time from time_second instead of gettimeofday(2) - define INADDR_NONE
This commit is contained in:
parent
81aed9a0a8
commit
d1dba4a851
@ -341,6 +341,43 @@ struct alias_link { /* Main data structure */
|
||||
} data;
|
||||
};
|
||||
|
||||
/* Clean up procedure. */
|
||||
static void finishoff(void);
|
||||
|
||||
/* Kernel module definition. */
|
||||
#ifdef _KERNEL
|
||||
MALLOC_DEFINE(M_ALIAS, "libalias", "packet aliasing");
|
||||
|
||||
MODULE_VERSION(libalias, 1);
|
||||
|
||||
static int
|
||||
alias_mod_handler(module_t mod, int type, void *data)
|
||||
{
|
||||
int error;
|
||||
|
||||
switch (type) {
|
||||
case MOD_LOAD:
|
||||
error = 0;
|
||||
break;
|
||||
case MOD_QUIESCE:
|
||||
case MOD_UNLOAD:
|
||||
finishoff();
|
||||
error = 0;
|
||||
break;
|
||||
default:
|
||||
error = EINVAL;
|
||||
}
|
||||
|
||||
return (error);
|
||||
}
|
||||
|
||||
static moduledata_t alias_mod = {
|
||||
"alias", alias_mod_handler, NULL
|
||||
};
|
||||
|
||||
DECLARE_MODULE(alias, alias_mod, SI_SUB_DRIVERS, SI_ORDER_SECOND);
|
||||
#endif
|
||||
|
||||
/* Internal utility routines (used only in alias_db.c)
|
||||
|
||||
Lookup table starting points:
|
||||
@ -1766,7 +1803,11 @@ SetStateIn(struct alias_link *lnk, int state)
|
||||
lnk->expire_time = TCP_EXPIRE_CONNECTED;
|
||||
break;
|
||||
default:
|
||||
#ifdef _KERNEL
|
||||
panic("libalias:SetStateIn() unknown state");
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
lnk->data.tcp->state.in = state;
|
||||
}
|
||||
@ -1788,7 +1829,11 @@ SetStateOut(struct alias_link *lnk, int state)
|
||||
lnk->expire_time = TCP_EXPIRE_CONNECTED;
|
||||
break;
|
||||
default:
|
||||
#ifdef _KERNEL
|
||||
panic("libalias:SetStateOut() unknown state");
|
||||
#else
|
||||
abort();
|
||||
#endif
|
||||
}
|
||||
lnk->data.tcp->state.out = state;
|
||||
}
|
||||
@ -2110,16 +2155,22 @@ void
|
||||
HouseKeeping(struct libalias *la)
|
||||
{
|
||||
int i, n, n100;
|
||||
#ifndef _KERNEL
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Save system time (seconds) in global variable timeStamp for use
|
||||
* by other functions. This is done so as not to unnecessarily
|
||||
* waste timeline by making system calls.
|
||||
*/
|
||||
#ifdef _KERNEL
|
||||
la->timeStamp = time_second;
|
||||
#else
|
||||
gettimeofday(&tv, &tz);
|
||||
la->timeStamp = tv.tv_sec;
|
||||
#endif
|
||||
|
||||
/* Compute number of spokes (output table link chains) to cover */
|
||||
n100 = LINK_TABLE_OUT_SIZE * 100 + la->houseKeepingResidual;
|
||||
@ -2379,20 +2430,30 @@ struct libalias *
|
||||
LibAliasInit(struct libalias *la)
|
||||
{
|
||||
int i;
|
||||
#ifndef _KERNEL
|
||||
struct timeval tv;
|
||||
struct timezone tz;
|
||||
#endif
|
||||
|
||||
if (la == NULL) {
|
||||
la = calloc(sizeof *la, 1);
|
||||
if (la == NULL)
|
||||
return (la);
|
||||
|
||||
#ifndef _KERNEL /* kernel cleans up on module unload */
|
||||
if (LIST_EMPTY(&instancehead))
|
||||
atexit(finishoff);
|
||||
#endif
|
||||
LIST_INSERT_HEAD(&instancehead, la, instancelist);
|
||||
|
||||
#ifdef _KERNEL
|
||||
la->timeStamp = time_second;
|
||||
la->lastCleanupTime = time_second;
|
||||
#else
|
||||
gettimeofday(&tv, &tz);
|
||||
la->timeStamp = tv.tv_sec;
|
||||
la->lastCleanupTime = tv.tv_sec;
|
||||
#endif
|
||||
la->houseKeepingResidual = 0;
|
||||
|
||||
for (i = 0; i < LINK_TABLE_OUT_SIZE; i++)
|
||||
|
@ -48,6 +48,19 @@
|
||||
|
||||
#include <sys/queue.h>
|
||||
|
||||
/* Use kernel allocator. */
|
||||
#if defined(_KERNEL) && defined(_SYS_MALLOC_H_)
|
||||
MALLOC_DECLARE(M_ALIAS);
|
||||
#define malloc(x) malloc(x, M_ALIAS, M_NOWAIT|M_ZERO)
|
||||
#define calloc(x, n) malloc(x*n)
|
||||
#define free(x) free(x, M_ALIAS)
|
||||
#endif
|
||||
|
||||
/* XXX: LibAliasSetTarget() uses this constant. */
|
||||
#ifdef _KERNEL
|
||||
#define INADDR_NONE 0xffffffff
|
||||
#endif
|
||||
|
||||
/* Sizes of input and output link tables */
|
||||
#define LINK_TABLE_OUT_SIZE 101
|
||||
#define LINK_TABLE_IN_SIZE 4001
|
||||
|
Loading…
Reference in New Issue
Block a user