diff options
Diffstat (limited to 'sys/contrib/ipfilter/netinet/ip_log.c')
-rw-r--r-- | sys/contrib/ipfilter/netinet/ip_log.c | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/sys/contrib/ipfilter/netinet/ip_log.c b/sys/contrib/ipfilter/netinet/ip_log.c index b3f1e56..189e682 100644 --- a/sys/contrib/ipfilter/netinet/ip_log.c +++ b/sys/contrib/ipfilter/netinet/ip_log.c @@ -58,7 +58,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> @@ -69,13 +68,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> @@ -110,11 +110,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 @@ -122,6 +117,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) @@ -174,7 +173,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; @@ -221,9 +220,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)) || \ @@ -231,10 +232,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 @@ -247,10 +246,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 ? */ @@ -295,20 +295,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]; /* @@ -336,23 +336,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); @@ -364,12 +369,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; } @@ -394,7 +399,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; /* @@ -436,15 +441,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; @@ -473,7 +477,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; } |