diff options
Diffstat (limited to 'contrib/ipfilter/ip_log.c')
| -rw-r--r-- | contrib/ipfilter/ip_log.c | 76 |
1 files changed, 40 insertions, 36 deletions
diff --git a/contrib/ipfilter/ip_log.c b/contrib/ipfilter/ip_log.c index 5968f46ad4b0..e56c60262460 100644 --- a/contrib/ipfilter/ip_log.c +++ b/contrib/ipfilter/ip_log.c @@ -3,7 +3,7 @@ * * See the IPFILTER.LICENCE file for details on licencing. * - * $Id: ip_log.c,v 2.5.2.5 2001/06/26 10:43:14 darrenr Exp $ + * $Id: ip_log.c,v 2.5.2.17 2002/03/13 03:57:05 darrenr Exp $ */ #include <sys/param.h> #if defined(KERNEL) && !defined(_KERNEL) @@ -52,7 +52,6 @@ # if defined(_KERNEL) # include <sys/systm.h> # endif -# include <sys/uio.h> # if !SOLARIS # if (NetBSD > 199609) || (OpenBSD > 199603) || (__FreeBSD_version >= 300000) # include <sys/dirent.h> @@ -63,13 +62,14 @@ # else # include <sys/filio.h> # include <sys/cred.h> -# include <sys/ddi.h> -# include <sys/sunddi.h> -# include <sys/ksynch.h> # include <sys/kmem.h> -# include <sys/mkdev.h> -# include <sys/dditypes.h> -# include <sys/cmn_err.h> +# ifdef _KERNEL +# include <sys/ddi.h> +# include <sys/sunddi.h> +# include <sys/ksynch.h> +# include <sys/dditypes.h> +# include <sys/cmn_err.h> +# endif # endif # include <sys/protosw.h> # include <sys/socket.h> @@ -104,11 +104,6 @@ # include "netinet/ip_compat.h" # include <netinet/tcpip.h> # include "netinet/ip_fil.h" -# include "netinet/ip_proxy.h" -# include "netinet/ip_nat.h" -# include "netinet/ip_frag.h" -# include "netinet/ip_state.h" -# include "netinet/ip_auth.h" # if (__FreeBSD_version >= 300000) # include <sys/malloc.h> # endif @@ -116,6 +111,10 @@ # ifndef MIN # define MIN(a,b) (((a)<(b))?(a):(b)) # endif +# ifdef IPFILTER_LOGSIZE +# undef IPLLOGSIZE +# define IPLLOGSIZE IPFILTER_LOGSIZE +# endif # if SOLARIS || defined(__sgi) @@ -168,7 +167,7 @@ mb_t *m; void *ptrs[2]; int types[2]; u_char p; -# if SOLARIS +# if SOLARIS && defined(_KERNEL) ill_t *ifp = fin->fin_ifp; # else struct ifnet *ifp = fin->fin_ifp; @@ -215,9 +214,11 @@ mb_t *m; * Get the interface number and name to which this packet is * currently associated. */ -# if SOLARIS + bzero((char *)ipfl.fl_ifname, sizeof(ipfl.fl_ifname)); +# if SOLARIS && defined(_KERNEL) ipfl.fl_unit = (u_char)ifp->ill_ppa; - bcopy(ifp->ill_name, ipfl.fl_ifname, MIN(ifp->ill_name_length, 4)); + bcopy(ifp->ill_name, ipfl.fl_ifname, + MIN(ifp->ill_name_length, sizeof(ipfl.fl_ifname))); mlen = (flags & FR_LOGBODY) ? MIN(msgdsize(m) - hlen, 128) : 0; # else # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \ @@ -225,10 +226,8 @@ mb_t *m; strncpy(ipfl.fl_ifname, ifp->if_xname, IFNAMSIZ); # else ipfl.fl_unit = (u_char)ifp->if_unit; - if ((ipfl.fl_ifname[0] = ifp->if_name[0])) - if ((ipfl.fl_ifname[1] = ifp->if_name[1])) - if ((ipfl.fl_ifname[2] = ifp->if_name[2])) - ipfl.fl_ifname[3] = ifp->if_name[3]; + strncpy(ipfl.fl_ifname, ifp->if_name, MIN(sizeof(ipfl.fl_ifname), + sizeof(ifp->if_name))); # endif mlen = (flags & FR_LOGBODY) ? MIN(fin->fin_plen - hlen, 128) : 0; # endif @@ -241,10 +240,11 @@ mb_t *m; else ipfl.fl_loglevel = 0xffff; ipfl.fl_flags = flags; + ipfl.fl_dir = fin->fin_out; ptrs[0] = (void *)&ipfl; sizes[0] = sizeof(ipfl); types[0] = 0; -# if SOLARIS +# if SOLARIS && defined(_KERNEL) /* * Are we copied from the mblk or an aligned array ? */ @@ -289,20 +289,20 @@ int *types, cnt; MUTEX_ENTER(&ipl_mutex); if (fin != NULL) { if ((ipll[dev] != NULL) && - bcmp((char *)fin, (char *)&iplcrc[dev], FI_CSIZE) == 0) { + bcmp((char *)fin, (char *)&iplcrc[dev], FI_LCSIZE) == 0) { ipll[dev]->ipl_count++; MUTEX_EXIT(&ipl_mutex); return 1; } - bcopy((char *)fin, (char *)&iplcrc[dev], FI_CSIZE); + bcopy((char *)fin, (char *)&iplcrc[dev], FI_LCSIZE); } else - bzero((char *)&iplcrc[dev], FI_CSIZE); + bzero((char *)&iplcrc[dev], FI_LCSIZE); MUTEX_EXIT(&ipl_mutex); /* * Get the total amount of data to be logged. */ - for (i = 0, len = sizeof(iplog_t); i < cnt; i++) + for (i = 0, len = IPLOG_SIZE; i < cnt; i++) len += itemsz[i]; /* @@ -330,23 +330,28 @@ int *types, cnt; ipl->ipl_count = 1; ipl->ipl_next = NULL; ipl->ipl_dsize = len; -# if SOLARIS || defined(sun) +# ifdef _KERNEL +# if SOLARIS || defined(sun) uniqtime((struct timeval *)&ipl->ipl_sec); -# else -# if BSD >= 199306 || defined(__FreeBSD__) || defined(__sgi) +# else +# if BSD >= 199306 || defined(__FreeBSD__) || defined(__sgi) microtime((struct timeval *)&ipl->ipl_sec); +# endif # endif +# else + ipl->ipl_sec = 0; + ipl->ipl_usec = 0; # 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. */ - for (i = 0, s = buf + sizeof(*ipl); i < cnt; i++) { + for (i = 0, s = buf + IPLOG_SIZE; i < cnt; i++) { if (types[i] == 0) bcopy(items[i], s, itemsz[i]); else if (types[i] == 1) { -# if SOLARIS +# if SOLARIS && defined(_KERNEL) copyout_mblk(items[i], 0, itemsz[i], s); # else m_copydata(items[i], 0, itemsz[i], s); @@ -358,12 +363,12 @@ int *types, cnt; ipll[dev] = ipl; *iplh[dev] = ipl; iplh[dev] = &ipl->ipl_next; -# if SOLARIS +# if SOLARIS && defined(_KERNEL) cv_signal(&iplwait); mutex_exit(&ipl_mutex); # else MUTEX_EXIT(&ipl_mutex); - wakeup(&iplh[dev]); + WAKEUP(&iplh[dev]); # endif return 1; } @@ -388,7 +393,7 @@ struct uio *uio; return ENXIO; if (!uio->uio_resid) return 0; - if (uio->uio_resid < sizeof(iplog_t)) + if (uio->uio_resid < IPLOG_SIZE) return EINVAL; /* @@ -430,15 +435,14 @@ struct uio *uio; iplused[unit] -= dlen; MUTEX_EXIT(&ipl_mutex); error = UIOMOVE((caddr_t)ipl, dlen, UIO_READ, uio); + MUTEX_ENTER(&ipl_mutex); if (error) { - MUTEX_ENTER(&ipl_mutex); ipl->ipl_next = iplt[unit]; iplt[unit] = ipl; iplused[unit] += dlen; break; } KFREES((caddr_t)ipl, dlen); - MUTEX_ENTER(&ipl_mutex); } if (!iplt[unit]) { iplused[unit] = 0; @@ -467,7 +471,7 @@ minor_t unit; ipll[unit] = NULL; used = iplused[unit]; iplused[unit] = 0; - bzero((char *)&iplcrc[unit], FI_CSIZE); + bzero((char *)&iplcrc[unit], FI_LCSIZE); MUTEX_EXIT(&ipl_mutex); return used; } |
