summaryrefslogtreecommitdiffstats
path: root/sys/netinet/libalias
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2005-05-05 21:05:38 +0000
committerglebius <glebius@FreeBSD.org>2005-05-05 21:05:38 +0000
commitd1dba4a851bc3d09783bf3abbf16fe469fe2e732 (patch)
treea18ba6912f06ede06c4a7622b578ac1d068cda53 /sys/netinet/libalias
parent81aed9a0a8ff8516b4a133a5bbac6c1693192e10 (diff)
downloadFreeBSD-src-d1dba4a851bc3d09783bf3abbf16fe469fe2e732.zip
FreeBSD-src-d1dba4a851bc3d09783bf3abbf16fe469fe2e732.tar.gz
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
Diffstat (limited to 'sys/netinet/libalias')
-rw-r--r--sys/netinet/libalias/alias_db.c61
-rw-r--r--sys/netinet/libalias/alias_local.h13
2 files changed, 74 insertions, 0 deletions
diff --git a/sys/netinet/libalias/alias_db.c b/sys/netinet/libalias/alias_db.c
index 17f320c..fcb4e0c 100644
--- a/sys/netinet/libalias/alias_db.c
+++ b/sys/netinet/libalias/alias_db.c
@@ -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++)
diff --git a/sys/netinet/libalias/alias_local.h b/sys/netinet/libalias/alias_local.h
index 34f91e3..63f6288 100644
--- a/sys/netinet/libalias/alias_local.h
+++ b/sys/netinet/libalias/alias_local.h
@@ -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
OpenPOWER on IntegriCloud