ip_lookup.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* Copyright (C) 2002-2003 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
# define KERNEL 1
# define _KERNEL 1
#endif
#else
#endif
#if !defined(_KERNEL)
# include <string.h>
# define _KERNEL
# ifdef __OpenBSD__
struct file;
# endif
#endif
#if defined(__FreeBSD__)
#endif
#if defined(_KERNEL)
# endif
#endif
#if SOLARIS2 >= 10
#include "ip_compat.h"
#include "ip_fil.h"
#include "ip_pool.h"
#include "ip_htable.h"
#include "ip_lookup.h"
#else
#include "netinet/ip_compat.h"
#include "netinet/ip_htable.h"
#include "netinet/ip_lookup.h"
#endif
#if !defined(lint)
static const char rcsid[] = "@(#)$Id: ip_lookup.c,v 2.21 2003/06/28 17:01:57 darrenr Exp $";
#endif
#ifdef IPFILTER_LOOKUP
static ip_pool_stat_t ippoolstate;
# ifdef USE_MUTEXES
# endif
int ip_lookup_inited = 0;
int ip_lookup_init()
{
if (ip_pool_init() == -1)
return -1;
ip_lookup_inited = 1;
return 0;
}
void ip_lookup_unload()
{
ip_pool_fini();
if (ip_lookup_inited == 1) {
ip_lookup_inited = 0;
}
}
# if defined(__NetBSD__) || defined(__OpenBSD__)
# else
int cmd;
# endif
int mode;
{
int err;
int s;
# endif
SPL_NET(s);
switch (cmd)
{
case SIOCLOOKUPADDNODE :
if (err == 0)
break;
case SIOCLOOKUPDELNODE :
if (err == 0)
break;
case SIOCLOOKUPADDTABLE :
break;
case SIOCLOOKUPDELTABLE :
break;
case SIOCLOOKUPSTAT :
break;
case SIOCLOOKUPFLUSH :
break;
default :
break;
}
SPL_X(s);
return err;
}
static int iplookup_addnode(data)
{
ip_pool_node_t node, *m;
ip_pool_t *p;
int err;
if (err != 0)
return EFAULT;
{
case IPLT_POOL :
return ENOTSUP;
# else
return EINVAL;
if (err != 0)
return EFAULT;
if (p == NULL)
return ESRCH;
/*
* add an entry to a pool - return an error if it already
* exists remove an entry from a pool - if it exists
* - in both cases, the pool *must* exist!
*/
if (m)
return EEXIST;
# endif
break;
case IPLT_HASH :
return EINVAL;
if (err != 0)
return EFAULT;
return ESRCH;
break;
default :
break;
}
return err;
}
static int iplookup_delnode(data)
{
ip_pool_node_t node, *m;
ip_pool_t *p;
int err;
if (err != 0)
return EFAULT;
{
case IPLT_POOL :
return ENOTSUP;
# else
return EINVAL;
if (err != 0)
return EFAULT;
if (!p)
return ESRCH;
/*
* add an entry to a pool - return an error if it already
* exists remove an entry from a pool - if it exists
* - in both cases, the pool *must* exist!
*/
if (m == NULL)
return ENOENT;
err = ip_pool_remove(p, m);
break;
# endif
case IPLT_HASH :
return EINVAL;
if (err != 0)
return EFAULT;
return ESRCH;
break;
default :
break;
}
return err;
}
static int iplookup_addtable(data)
{
int err;
if (err != 0)
return EFAULT;
/*
* create a new pool - fail if one already exists with
* the same #
*/
{
case IPLT_POOL :
return ENOTSUP;
# else
else
if (err == 0)
break;
# endif
case IPLT_HASH :
else
if (err == 0)
break;
default :
break;
}
return err;
}
/* ------------------------------------------------------------------------ */
/* Function: iplookup_deltable */
/* Returns: int - 0 = success, else error */
/* Parameters: data(I) - pointer to data from ioctl call */
/* */
/* Decodes ioctl request to remove a particular hash table or pool and */
/* calls the relevant function to do the cleanup. */
/* ------------------------------------------------------------------------ */
static int iplookup_deltable(data)
{
int err;
if (err != 0)
return EFAULT;
/*
* create a new pool - fail if one already exists with
* the same #
*/
{
case IPLT_POOL :
return ENOTSUP;
# else
break;
# endif
case IPLT_HASH :
break;
default :
break;
}
return err;
}
/* ------------------------------------------------------------------------ */
/* Function: iplookup_stats */
/* Returns: int - 0 = success, else error */
/* Parameters: data(I) - pointer to data from ioctl call */
/* */
/* Copy statistical information from inside the kernel back to user space. */
/* ------------------------------------------------------------------------ */
static int iplookup_stats(data)
{
return ENOTSUP;
# else
if (err != 0)
return EFAULT;
return EINVAL;
if (unit == IPL_LOGALL) {
for (i = 0; i < IPL_LOGSIZE; i++)
} else
return EINVAL;
return err;
# endif
}
/* ------------------------------------------------------------------------ */
/* Function: iplookup_flush */
/* Returns: int - 0 = success, else error */
/* Parameters: data(I) - pointer to data from ioctl call */
/* */
/* A flush is called when we want to flush all the nodes from a particular */
/* ------------------------------------------------------------------------ */
static int iplookup_flush(data)
{
ip_pool_t *p, *q;
if (err != 0)
return EFAULT;
return EINVAL;
/*
* Flush all ?
* Or flush n except where n == -1 (all pools)
*/
num = 0;
# else
err = 0;
if (err == 0)
num++;
} else {
for (i = 0; i <= IPL_LOGMAX; i++) {
continue;
for (q = ip_pool_list[i]; (p = q) != NULL; ) {
q = p->ipo_next;
if (err == 0)
num++;
else
break;
}
}
}
# endif
}
err = 0;
else {
for (i = 0; i <= IPL_LOGMAX; i++) {
continue;
for (iphn = ipf_htables[i];
}
}
}
}
if (err == 0) {
}
return err;
}
int type;
void *ptr;
{
return;
switch (type)
{
case IPLT_POOL :
break;
case IPLT_HASH :
break;
}
}
#else /* IPFILTER_LOOKUP */
/*ARGSUSED*/
# if defined(__NetBSD__) || defined(__OpenBSD__)
# else
int cmd;
# endif
int mode;
{
return EIO;
}
#endif /* IPFILTER_LOOKUP */