ip_log.c revision 8128a42d18f03617e333c5aa4e3219cb31a28f48
/*
* Copyright (C) 1997-2003 by Darren Reed.
*
* See the IPFILTER.LICENCE file for details on licencing.
*
* $Id: ip_log.c,v 2.75.2.7 2005/06/11 07:47:44 darrenr Exp $
*
* Copyright 2007 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
defined(_KERNEL)
# include "opt_ipfilter_log.h"
#endif
#if defined(__FreeBSD__) && !defined(IPFILTER_LKM)
# if defined(_KERNEL)
# include "opt_ipfilter.h"
# endif
# else
# include <osreldate.h>
# endif
#endif
#ifndef SOLARIS
#endif
#ifndef _KERNEL
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <ctype.h>
# define _KERNEL
# define KERNEL
# ifdef __OpenBSD__
struct file;
# endif
#endif
#else
#endif
#if defined(_KERNEL)
# endif
#endif /* _KERNEL */
# else
# endif
#else
# include <sys/dditypes.h>
# endif /* !__hpux */
#endif /* !SOLARIS && !__hpux */
#if !defined(linux)
#endif
#ifdef sun
#endif
#if __FreeBSD_version >= 300000
#endif
#ifdef __sgi
# ifdef IFF_DRVRLOCK /* IRIX6 */
# endif
#endif
#endif
#include <netinet/in_systm.h>
#ifdef USE_INET6
#endif
#if !defined(linux)
#endif
#ifndef _KERNEL
# include <syslog.h>
#endif
#include "netinet/ip_compat.h"
#include "netinet/ip_state.h"
#include "netinet/ipf_stack.h"
#endif
/* END OF INCLUDES */
#ifdef IPFILTER_LOG
# if defined(IPL_SELECT)
# include <sys/kthread_iface.h>
# define READ_COLLISION 0x001
extern int selwait;
# endif /* IPL_SELECT */
/* ipl_magic never changes */
/* ------------------------------------------------------------------------ */
/* Function: fr_loginit */
/* Returns: int - 0 == success (always returned) */
/* Parameters: Nil */
/* */
/* Initialise log buffers & pointers. Also iniialised the CRC to a local */
/* secret for use in calculating the "last log checksum". */
/* ------------------------------------------------------------------------ */
int fr_loginit(ifs)
{
int i;
for (i = IPL_LOGMAX; i >= 0; i--) {
ifs->ifs_iplused[i] = 0;
# ifdef IPL_SELECT
iplog_ss[i].read_waiter = 0;
# endif
# endif
}
# endif
return 0;
}
/* ------------------------------------------------------------------------ */
/* Function: fr_logunload */
/* Returns: Nil */
/* Parameters: Nil */
/* */
/* Clean up any log data that has accumulated without being read. */
/* ------------------------------------------------------------------------ */
void fr_logunload(ifs)
{
int i;
if (ifs->ifs_ipl_log_init == 0)
return;
for (i = IPL_LOGMAX; i >= 0; i--)
(void) ipflog_clear(i, ifs);
# endif
ifs->ifs_ipl_log_init = 0;
}
/* ------------------------------------------------------------------------ */
/* Function: ipflog */
/* Returns: int - 0 == success, -1 == failure */
/* Parameters: fin(I) - pointer to packet information */
/* flags(I) - flags from filter rules */
/* */
/* Create a log record for a packet given that it has been triggered by a */
/* rule (or the default setting). Calculate the transport protocol header */
/* size using predetermined size of a couple of popular protocols and thus */
/* how much data to copy into the log, including part of the data body if */
/* requested. */
/* ------------------------------------------------------------------------ */
{
void *ptrs[2];
u_char p;
mb_t *m;
void *ifp;
# else
# else
# endif
# endif /* SOLARIS */
/*
* calculate header size.
*/
if (p == IPPROTO_TCP)
else if (p == IPPROTO_UDP)
else if (p == IPPROTO_ICMP) {
/*
* For ICMP, if the packet is an error packet, also
* include the information about the packet which
* caused the error.
*/
{
case ICMP_UNREACH :
case ICMP_SOURCEQUENCH :
case ICMP_REDIRECT :
case ICMP_TIMXCEED :
case ICMP_PARAMPROB :
break;
default :
break;
}
}
# ifdef USE_INET6
else if (p == IPPROTO_ICMPV6) {
/*
* For ICMPV6, if the packet is an error packet, also
* include the information about the packet which
* caused the error.
*/
} else {
}
}
# endif
}
/*
* Get the interface number and name to which this packet is
* currently associated.
*/
return (-1);
}
# else
# else
# else
# if defined(_KERNEL)
# else
# endif
# endif
# endif /* __hpux */
# endif /* SOLARIS */
if (!ifs->ifs_ipl_logall) {
} else if ((flags & FR_LOGBODY) == 0) {
mlen = 0;
}
if (mlen < 0)
mlen = 0;
} else {
}
types[0] = 0;
/*
* Are we copied from the mblk or an aligned array ?
*/
ptrs[1] = m;
} else {
types[1] = 0;
}
# else
ptrs[1] = m;
# endif /* MENTAT */
}
/* ------------------------------------------------------------------------ */
/* Function: ipllog */
/* Returns: int - 0 == success, -1 == failure */
/* Parameters: dev(I) - device that owns this log record */
/* fin(I) - pointer to packet information */
/* items(I) - array of pointers to log data */
/* itemsz(I) - array of size of valid memory pointed to */
/* types(I) - type of data pointed to by items pointers */
/* */
/* Takes an array of parameters and constructs one record to include the */
/* miscellaneous packet information, as well as packet data, for reading */
/* from the log device. */
/* ------------------------------------------------------------------------ */
int dev;
void **items;
{
int i;
SPL_INT(s);
/*
* Check to see if this log record has a CRC which matches the last
* record logged. If it does, just up the count on the previous one
* rather than create a new one.
*/
if (ifs->ifs_ipl_suppress) {
FI_LCSIZE) == 0) {
return 0;
}
} else
}
/*
* Get the total amount of data to be logged.
*/
/*
* check that we have space to record this information and can
* allocate that much.
*/
return -1;
SPL_NET(s);
SPL_X(s);
return -1;
}
SPL_X(s);
/*
* advance the log pointer to the next empty record and deduct the
* amount of space we're going to use.
*/
#ifdef _KERNEL
#else
#endif
/*
* Loop through all the items to be logged, copying each one to the
* buffer. Use bcopy for normal data or the mb_t copyout routine.
*/
if (types[i] == 0) {
} else if (types[i] == 1) {
}
}
SPL_NET(s);
/*
* Now that the log record has been completed and added to the queue,
* wake up any listeners who may want to read it.
*/
# else
# endif
SPL_X(s);
# ifdef IPL_SELECT
# endif
return 0;
}
/* ------------------------------------------------------------------------ */
/* Function: ipflog_read */
/* Returns: int - 0 == success, else error value. */
/* Parameters: unit(I) - device we are reading from */
/* uio(O) - pointer to information about where to store data */
/* */
/* Called to handle a read on an IPFilter device. Returns only complete */
/* log messages - will not partially copy a log record out to userland. */
/* */
/* NOTE: This function will block and wait for a signal to return data if */
/* there is none present. Asynchronous I/O is not implemented. */
/* ------------------------------------------------------------------------ */
{
int error = 0;
SPL_INT(s);
/*
* Sanity checks. Make sure the minor # is valid and we're copying
* a valid chunk of data.
*/
if (IPL_LOGMAX < unit)
return ENXIO;
return 0;
return EINVAL;
/*
* Lock the log so we can snapshot the variables. Wait for a signal
* if the log is empty.
*/
SPL_NET(s);
return EINTR;
}
# else
lock_t *l;
# ifdef IPL_SELECT
/* this is no blocking system call */
return 0;
}
# endif
spinunlock(l);
# else
# else
SPL_X(s);
# endif /* __osf__ */
# endif /* __hpux */
if (error)
return error;
SPL_NET(s);
# endif /* SOLARIS */
}
# endif
break;
/*
* Don't hold the mutex over the uiomove call.
*/
}
SPL_X(s);
if (error) {
SPL_NET(s);
}
break;
}
SPL_NET(s);
}
SPL_X(s);
return error;
}
/* ------------------------------------------------------------------------ */
/* Function: ipflog_clear */
/* Returns: int - number of log bytes cleared. */
/* Parameters: unit(I) - device we are reading from */
/* */
/* Deletes all queued up log records for a given output device. */
/* ------------------------------------------------------------------------ */
{
int used;
SPL_INT(s);
SPL_NET(s);
}
SPL_X(s);
return used;
}
#endif /* IPFILTER_LOG */