4 * Copyright (C) 2012 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
9 * Id: ip_log.c,v 2.75.2.19 2007/09/09 11:32:06 darrenr Exp $
11 #include <sys/param.h>
12 #if defined(KERNEL) || defined(_KERNEL)
18 #if defined(__FreeBSD__) && !defined(_KERNEL)
19 # include <osreldate.h>
22 # define SOLARIS (defined(sun) && (defined(__svr4__) || defined(__SVR4)))
24 #include <sys/errno.h>
25 #include <sys/types.h>
41 #if (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000)) && \
43 # include <sys/fcntl.h>
44 # include <sys/filio.h>
46 # include <sys/ioctl.h>
50 # include <sys/systm.h>
51 # if (defined(NetBSD) && (__NetBSD_Version__ >= 104000000))
52 # include <sys/proc.h>
55 #if !SOLARIS && !defined(__hpux) && !defined(linux)
56 # if (defined(NetBSD) && (NetBSD > 199609)) || \
57 (defined(OpenBSD) && (OpenBSD > 199603)) || \
58 (defined(__FreeBSD_version) && (__FreeBSD_version >= 300000))
59 # include <sys/dirent.h>
63 # include <sys/mbuf.h>
64 # include <sys/select.h>
65 # if __FreeBSD_version >= 500000
66 # include <sys/selinfo.h>
69 # if !defined(__hpux) && defined(_KERNEL)
70 # include <sys/filio.h>
71 # include <sys/cred.h>
73 # include <sys/sunddi.h>
74 # include <sys/ksynch.h>
75 # include <sys/kmem.h>
76 # include <sys/mkdev.h>
77 # include <sys/dditypes.h>
78 # include <sys/cmn_err.h>
80 #endif /* !SOLARIS && !__hpux */
82 # include <sys/protosw.h>
84 #include <sys/socket.h>
90 #if __FreeBSD_version >= 300000
91 # include <net/if_var.h>
93 #include <netinet/in.h>
96 # ifdef IFF_DRVRLOCK /* IRIX6 */
97 # include <sys/hashing.h>
100 #if !defined(__hpux) && !defined(linux) && \
101 !(defined(__sgi) && !defined(IFF_DRVRLOCK)) /*IRIX<6*/
102 # include <netinet/in_var.h>
104 #include <netinet/in_systm.h>
105 #include <netinet/ip.h>
106 #include <netinet/tcp.h>
107 #include <netinet/udp.h>
108 #include <netinet/ip_icmp.h>
110 # include <netinet/icmp6.h>
113 # include <netinet/ip_var.h>
118 #include "netinet/ip_compat.h"
119 #include <netinet/tcpip.h>
120 #include "netinet/ip_fil.h"
121 #include "netinet/ip_nat.h"
122 #include "netinet/ip_frag.h"
123 #include "netinet/ip_state.h"
124 #include "netinet/ip_auth.h"
125 #if (__FreeBSD_version >= 300000) || defined(__NetBSD__)
126 # include <sys/malloc.h>
128 /* END OF INCLUDES */
132 # if defined(IPL_SELECT)
133 # include <machine/sys/user.h>
134 # include <sys/kthread_iface.h>
135 # define READ_COLLISION 0x001
137 # endif /* IPL_SELECT */
139 typedef struct ipf_log_softc_s {
140 ipfmutex_t ipl_mutex[IPL_LOGSIZE];
141 # if SOLARIS && defined(_KERNEL)
142 kcondvar_t ipl_wait[IPL_LOGSIZE];
144 # if defined(linux) && defined(_KERNEL)
145 wait_queue_head_t iplh_linux[IPL_LOGSIZE];
147 # if defined(__hpux) && defined(_KERNEL)
148 iplog_select_t ipl_ss[IPL_LOGSIZE];
150 iplog_t **iplh[IPL_LOGSIZE];
151 iplog_t *iplt[IPL_LOGSIZE];
152 iplog_t *ipll[IPL_LOGSIZE];
153 u_long ipl_logfail[IPL_LOGSIZE];
154 u_long ipl_logok[IPL_LOGSIZE];
155 fr_info_t ipl_crc[IPL_LOGSIZE];
156 u_32_t ipl_counter[IPL_LOGSIZE];
161 int ipl_used[IPL_LOGSIZE];
162 int ipl_magic[IPL_LOGSIZE];
163 ipftuneable_t *ipf_log_tune;
164 int ipl_readers[IPL_LOGSIZE];
167 static int magic[IPL_LOGSIZE] = { IPL_MAGIC, IPL_MAGIC_NAT, IPL_MAGIC_STATE,
168 IPL_MAGIC, IPL_MAGIC, IPL_MAGIC,
169 IPL_MAGIC, IPL_MAGIC };
171 static ipftuneable_t ipf_log_tuneables[] = {
173 { { (void *)offsetof(ipf_log_softc_t, ipl_suppress) },
174 "log_suppress", 0, 1,
175 stsizeof(ipf_log_softc_t, ipl_suppress),
177 { { (void *)offsetof(ipf_log_softc_t, ipl_logall) },
179 stsizeof(ipf_log_softc_t, ipl_logall),
181 { { (void *)offsetof(ipf_log_softc_t, ipl_logsize) },
182 "log_size", 0, 0x80000,
183 stsizeof(ipf_log_softc_t, ipl_logsize),
185 { { NULL }, NULL, 0, 0,
199 ipf_log_main_unload()
204 /* ------------------------------------------------------------------------ */
205 /* Function: ipf_log_soft_create */
206 /* Returns: void * - NULL = failure, else pointer to log context data */
207 /* Parameters: softc(I) - pointer to soft context main structure */
209 /* Initialise log buffers & pointers. Also iniialised the CRC to a local */
210 /* secret for use in calculating the "last log checksum". */
211 /* ------------------------------------------------------------------------ */
213 ipf_log_soft_create(softc)
214 ipf_main_softc_t *softc;
216 ipf_log_softc_t *softl;
219 KMALLOC(softl, ipf_log_softc_t *);
223 bzero((char *)softl, sizeof(*softl));
224 bcopy((char *)magic, (char *)softl->ipl_magic, sizeof(magic));
226 softl->ipf_log_tune = ipf_tune_array_copy(softl,
227 sizeof(ipf_log_tuneables),
229 if (softl->ipf_log_tune == NULL) {
230 ipf_log_soft_destroy(softc, softl);
233 if (ipf_tune_array_link(softc, softl->ipf_log_tune) == -1) {
234 ipf_log_soft_destroy(softc, softl);
238 for (i = IPL_LOGMAX; i >= 0; i--) {
239 MUTEX_INIT(&softl->ipl_mutex[i], "ipf log mutex");
242 softl->ipl_suppress = 1;
243 softl->ipl_logall = 0;
244 softl->ipl_log_init = 0;
245 softl->ipl_logsize = IPFILTER_LOGSIZE;
250 /* ------------------------------------------------------------------------ */
251 /* Function: ipf_log_soft_init */
252 /* Returns: int - 0 == success (always returned) */
253 /* Parameters: softc(I) - pointer to soft context main structure */
255 /* Initialise log buffers & pointers. Also iniialised the CRC to a local */
256 /* secret for use in calculating the "last log checksum". */
257 /* ------------------------------------------------------------------------ */
259 ipf_log_soft_init(softc, arg)
260 ipf_main_softc_t *softc;
263 ipf_log_softc_t *softl = arg;
266 for (i = IPL_LOGMAX; i >= 0; i--) {
267 softl->iplt[i] = NULL;
268 softl->ipll[i] = NULL;
269 softl->iplh[i] = &softl->iplt[i];
270 bzero((char *)&softl->ipl_crc[i], sizeof(softl->ipl_crc[i]));
272 softl->iplog_ss[i].read_waiter = 0;
273 softl->iplog_ss[i].state = 0;
278 softl->ipl_log_init = 1;
284 /* ------------------------------------------------------------------------ */
285 /* Function: ipf_log_soft_fini */
286 /* Parameters: softc(I) - pointer to soft context main structure */
287 /* arg(I) - pointer to log context structure */
289 /* Clean up any log data that has accumulated without being read. */
290 /* ------------------------------------------------------------------------ */
292 ipf_log_soft_fini(softc, arg)
293 ipf_main_softc_t *softc;
296 ipf_log_softc_t *softl = arg;
299 if (softl->ipl_log_init == 0)
302 softl->ipl_log_init = 0;
304 for (i = IPL_LOGMAX; i >= 0; i--) {
305 (void) ipf_log_clear(softc, i);
308 * This is a busy-wait loop so as to avoid yet another lock
311 MUTEX_ENTER(&softl->ipl_mutex[i]);
312 while (softl->ipl_readers[i] > 0) {
313 # if SOLARIS && defined(_KERNEL)
314 cv_broadcast(&softl->ipl_wait[i]);
315 MUTEX_EXIT(&softl->ipl_mutex[i]);
317 pollwakeup(&softc->ipf_poll_head[i], POLLRDNORM);
319 MUTEX_EXIT(&softl->ipl_mutex[i]);
320 WAKEUP(softl->iplh, i);
323 MUTEX_ENTER(&softl->ipl_mutex[i]);
325 MUTEX_EXIT(&softl->ipl_mutex[i]);
332 /* ------------------------------------------------------------------------ */
333 /* Function: ipf_log_soft_destroy */
334 /* Parameters: softc(I) - pointer to soft context main structure */
335 /* arg(I) - pointer to log context structure */
337 /* When this function is called, it is expected that there are no longer */
338 /* any threads active in the reading code path or the logging code path. */
339 /* ------------------------------------------------------------------------ */
341 ipf_log_soft_destroy(softc, arg)
342 ipf_main_softc_t *softc;
345 ipf_log_softc_t *softl = arg;
348 for (i = IPL_LOGMAX; i >= 0; i--) {
349 # if SOLARIS && defined(_KERNEL)
350 cv_destroy(&softl->ipl_wait[i]);
352 MUTEX_DESTROY(&softl->ipl_mutex[i]);
355 if (softl->ipf_log_tune != NULL) {
356 ipf_tune_array_unlink(softc, softl->ipf_log_tune);
357 KFREES(softl->ipf_log_tune, sizeof(ipf_log_tuneables));
358 softl->ipf_log_tune = NULL;
365 /* ------------------------------------------------------------------------ */
366 /* Function: ipf_log_pkt */
367 /* Returns: int - 0 == success, -1 == failure */
368 /* Parameters: fin(I) - pointer to packet information */
369 /* flags(I) - flags from filter rules */
371 /* Create a log record for a packet given that it has been triggered by a */
372 /* rule (or the default setting). Calculate the transport protocol header */
373 /* size using predetermined size of a couple of popular protocols and thus */
374 /* how much data to copy into the log, including part of the data body if */
376 /* ------------------------------------------------------------------------ */
378 ipf_log_pkt(fin, flags)
382 ipf_main_softc_t *softc = fin->fin_main_soft;
383 ipf_log_softc_t *softl = softc->ipf_log_soft;
384 register size_t hlen;
391 # if (SOLARIS || defined(__hpux)) && defined(_KERNEL) && !defined(FW_HOOKS)
395 # endif /* SOLARIS || __hpux */
401 ipfl.fl_nattag.ipt_num[0] = 0;
403 hlen = (char *)fin->fin_dp - (char *)fin->fin_ip;
406 * calculate header size.
408 if (fin->fin_off == 0) {
409 p = fin->fin_fi.fi_p;
410 if (p == IPPROTO_TCP)
411 hlen += MIN(sizeof(tcphdr_t), fin->fin_dlen);
412 else if (p == IPPROTO_UDP)
413 hlen += MIN(sizeof(udphdr_t), fin->fin_dlen);
414 else if (p == IPPROTO_ICMP) {
417 icmp = (struct icmp *)fin->fin_dp;
420 * For ICMP, if the packet is an error packet, also
421 * include the information about the packet which
424 switch (icmp->icmp_type)
427 case ICMP_SOURCEQUENCH :
430 case ICMP_PARAMPROB :
431 hlen += MIN(sizeof(struct icmp) + 8,
435 hlen += MIN(sizeof(struct icmp),
441 else if (p == IPPROTO_ICMPV6) {
442 struct icmp6_hdr *icmp;
444 icmp = (struct icmp6_hdr *)fin->fin_dp;
447 * For ICMPV6, if the packet is an error packet, also
448 * include the information about the packet which
451 if (icmp->icmp6_type < 128) {
452 hlen += MIN(sizeof(struct icmp6_hdr) + 8,
455 hlen += MIN(sizeof(struct icmp6_hdr),
462 * Get the interface number and name to which this packet is
463 * currently associated.
465 # if (SOLARIS || defined(__hpux)) && defined(_KERNEL)
466 # if !defined(FW_HOOKS)
467 ipfl.fl_unit = (u_int)ifp->qf_ppa;
469 COPYIFNAME(fin->fin_v, ifp, ipfl.fl_ifname);
471 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
472 OPENBSD_GE_REV(199603) || defined(linux) || FREEBSD_GE_REV(501113)
473 COPYIFNAME(fin->fin_v, ifp, ipfl.fl_ifname);
475 ipfl.fl_unit = (u_int)ifp->if_unit;
476 # if defined(_KERNEL)
477 if ((ipfl.fl_ifname[0] = ifp->if_name[0]))
478 if ((ipfl.fl_ifname[1] = ifp->if_name[1]))
479 if ((ipfl.fl_ifname[2] = ifp->if_name[2]))
480 ipfl.fl_ifname[3] = ifp->if_name[3];
482 (void) strncpy(ipfl.fl_ifname, IFNAME(ifp), sizeof(ipfl.fl_ifname));
483 ipfl.fl_ifname[sizeof(ipfl.fl_ifname) - 1] = '\0';
486 # endif /* __hpux || SOLARIS */
487 mlen = fin->fin_plen - hlen;
488 if (!softl->ipl_logall) {
489 mlen = (flags & FR_LOGBODY) ? MIN(mlen, 128) : 0;
490 } else if ((flags & FR_LOGBODY) == 0) {
495 ipfl.fl_plen = (u_char)mlen;
496 ipfl.fl_hlen = (u_char)hlen;
497 ipfl.fl_rule = fin->fin_rule;
498 (void) strncpy(ipfl.fl_group, fin->fin_group, FR_GROUPLEN);
499 if (fin->fin_fr != NULL) {
500 ipfl.fl_loglevel = fin->fin_fr->fr_loglevel;
501 ipfl.fl_logtag = fin->fin_fr->fr_logtag;
503 ipfl.fl_loglevel = 0xffff;
504 ipfl.fl_logtag = FR_NOLOGTAG;
506 if (fin->fin_nattag != NULL)
507 bcopy(fin->fin_nattag, (void *)&ipfl.fl_nattag,
508 sizeof(ipfl.fl_nattag));
509 ipfl.fl_flags = flags;
510 ipfl.fl_breason = (fin->fin_reason & 0xff);
511 ipfl.fl_dir = fin->fin_out;
512 ipfl.fl_lflags = fin->fin_flx;
513 ipfl.fl_family = fin->fin_family;
514 ptrs[0] = (void *)&ipfl;
515 sizes[0] = sizeof(ipfl);
517 # if defined(MENTAT) && defined(_KERNEL)
519 * Are we copied from the mblk or an aligned array ?
521 if (fin->fin_ip == (ip_t *)m->b_rptr) {
523 sizes[1] = hlen + mlen;
526 ptrs[1] = fin->fin_ip;
527 sizes[1] = hlen + mlen;
532 sizes[1] = hlen + mlen;
535 return ipf_log_items(softc, IPL_LOGIPF, fin, ptrs, sizes, types, 2);
539 /* ------------------------------------------------------------------------ */
540 /* Function: ipf_log_items */
541 /* Returns: int - 0 == success, -1 == failure */
542 /* Parameters: softc(I) - pointer to main soft context */
543 /* unit(I) - device we are reading from */
544 /* fin(I) - pointer to packet information */
545 /* items(I) - array of pointers to log data */
546 /* itemsz(I) - array of size of valid memory pointed to */
547 /* types(I) - type of data pointed to by items pointers */
548 /* cnt(I) - number of elements in arrays items/itemsz/types */
550 /* Takes an array of parameters and constructs one record to include the */
551 /* miscellaneous packet information, as well as packet data, for reading */
552 /* from the log device. */
553 /* ------------------------------------------------------------------------ */
555 ipf_log_items(softc, unit, fin, items, itemsz, types, cnt)
556 ipf_main_softc_t *softc;
563 ipf_log_softc_t *softl = softc->ipf_log_soft;
571 * Get the total amount of data to be logged.
573 for (i = 0, len = sizeof(iplog_t); i < cnt; i++)
577 MUTEX_ENTER(&softl->ipl_mutex[unit]);
578 softl->ipl_counter[unit]++;
580 * check that we have space to record this information and can
581 * allocate that much.
583 if ((softl->ipl_used[unit] + len) > softl->ipl_logsize) {
584 softl->ipl_logfail[unit]++;
585 MUTEX_EXIT(&softl->ipl_mutex[unit]);
589 KMALLOCS(buf, caddr_t, len);
591 softl->ipl_logfail[unit]++;
592 MUTEX_EXIT(&softl->ipl_mutex[unit]);
595 ipl = (iplog_t *)buf;
596 ipl->ipl_magic = softl->ipl_magic[unit];
598 ipl->ipl_seqnum = softl->ipl_counter[unit];
599 ipl->ipl_next = NULL;
600 ipl->ipl_dsize = len;
602 GETKTIME(&ipl->ipl_sec);
609 * Loop through all the items to be logged, copying each one to the
610 * buffer. Use bcopy for normal data or the mb_t copyout routine.
612 for (i = 0, ptr = buf + sizeof(*ipl); i < cnt; i++) {
614 bcopy(items[i], ptr, itemsz[i]);
615 } else if (types[i] == 1) {
616 COPYDATA(items[i], 0, itemsz[i], ptr);
621 * Check to see if this log record has a CRC which matches the last
622 * record logged. If it does, just up the count on the previous one
623 * rather than create a new one.
625 if (softl->ipl_suppress) {
626 if ((fin != NULL) && (fin->fin_off == 0)) {
627 if ((softl->ipll[unit] != NULL) &&
628 (fin->fin_crc == softl->ipl_crc[unit].fin_crc) &&
629 bcmp((char *)fin, (char *)&softl->ipl_crc[unit],
631 softl->ipll[unit]->ipl_count++;
632 MUTEX_EXIT(&softl->ipl_mutex[unit]);
637 bcopy((char *)fin, (char *)&softl->ipl_crc[unit],
639 softl->ipl_crc[unit].fin_crc = fin->fin_crc;
641 bzero((char *)&softl->ipl_crc[unit], FI_CSIZE);
645 * advance the log pointer to the next empty record and deduct the
646 * amount of space we're going to use.
648 softl->ipl_logok[unit]++;
649 softl->ipll[unit] = ipl;
650 *softl->iplh[unit] = ipl;
651 softl->iplh[unit] = &ipl->ipl_next;
652 softl->ipl_used[unit] += len;
655 * Now that the log record has been completed and added to the queue,
656 * wake up any listeners who may want to read it.
658 # if SOLARIS && defined(_KERNEL)
659 cv_signal(&softl->ipl_wait[unit]);
660 MUTEX_EXIT(&softl->ipl_mutex[unit]);
661 pollwakeup(&softc->ipf_poll_head[unit], POLLRDNORM);
663 MUTEX_EXIT(&softl->ipl_mutex[unit]);
664 WAKEUP(softl->iplh, unit);
669 iplog_input_ready(unit);
675 /* ------------------------------------------------------------------------ */
676 /* Function: ipf_log_read */
677 /* Returns: int - 0 == success, else error value. */
678 /* Parameters: softc(I) - pointer to main soft context */
679 /* unit(I) - device we are reading from */
680 /* uio(O) - pointer to information about where to store data */
682 /* Called to handle a read on an IPFilter device. Returns only complete */
683 /* log messages - will not partially copy a log record out to userland. */
685 /* NOTE: This function will block and wait for a signal to return data if */
686 /* there is none present. Asynchronous I/O is not implemented. */
687 /* ------------------------------------------------------------------------ */
689 ipf_log_read(softc, unit, uio)
690 ipf_main_softc_t *softc;
694 ipf_log_softc_t *softl = softc->ipf_log_soft;
700 if (softl->ipl_log_init == 0) {
706 * Sanity checks. Make sure the minor # is valid and we're copying
707 * a valid chunk of data.
709 if (IPL_LOGMAX < unit) {
713 if (uio->uio_resid == 0)
716 if (uio->uio_resid < sizeof(iplog_t)) {
720 if (uio->uio_resid > softl->ipl_logsize) {
726 * Lock the log so we can snapshot the variables. Wait for a signal
727 * if the log is empty.
730 MUTEX_ENTER(&softl->ipl_mutex[unit]);
731 softl->ipl_readers[unit]++;
733 while (softl->ipl_log_init == 1 && softl->iplt[unit] == NULL) {
734 # if SOLARIS && defined(_KERNEL)
735 if (!cv_wait_sig(&softl->ipl_wait[unit],
736 &softl->ipl_mutex[unit].ipf_lk)) {
737 softl->ipl_readers[unit]--;
738 MUTEX_EXIT(&softl->ipl_mutex[unit]);
743 # if defined(__hpux) && defined(_KERNEL)
747 if (uio->uio_fpflags & (FNBLOCK|FNDELAY)) {
748 /* this is no blocking system call */
749 softl->ipl_readers[unit]--;
750 MUTEX_EXIT(&softl->ipl_mutex[unit]);
755 MUTEX_EXIT(&softl->ipl_mutex[unit]);
756 l = get_sleep_lock(&softl->iplh[unit]);
757 error = sleep(&softl->iplh[unit], PZERO+1);
760 # if defined(__osf__) && defined(_KERNEL)
761 error = mpsleep(&softl->iplh[unit], PSUSP|PCATCH, "ipfread", 0,
762 &softl->ipl_mutex, MS_LOCK_SIMPLE);
764 MUTEX_EXIT(&softl->ipl_mutex[unit]);
766 error = SLEEP(unit + softl->iplh, "ipl sleep");
767 # endif /* __osf__ */
770 MUTEX_ENTER(&softl->ipl_mutex[unit]);
772 softl->ipl_readers[unit]--;
773 MUTEX_EXIT(&softl->ipl_mutex[unit]);
777 # endif /* SOLARIS */
779 if (softl->ipl_log_init != 1) {
780 softl->ipl_readers[unit]--;
781 MUTEX_EXIT(&softl->ipl_mutex[unit]);
786 # if (defined(BSD) && (BSD >= 199101)) || defined(__FreeBSD__) || \
788 uio->uio_rw = UIO_READ;
791 for (copied = 0; (ipl = softl->iplt[unit]) != NULL; copied += dlen) {
792 dlen = ipl->ipl_dsize;
793 if (dlen > uio->uio_resid)
796 * Don't hold the mutex over the uiomove call.
798 softl->iplt[unit] = ipl->ipl_next;
799 softl->ipl_used[unit] -= dlen;
800 MUTEX_EXIT(&softl->ipl_mutex[unit]);
802 error = UIOMOVE(ipl, dlen, UIO_READ, uio);
805 MUTEX_ENTER(&softl->ipl_mutex[unit]);
807 ipl->ipl_next = softl->iplt[unit];
808 softl->iplt[unit] = ipl;
809 softl->ipl_used[unit] += dlen;
812 MUTEX_ENTER(&softl->ipl_mutex[unit]);
813 KFREES((caddr_t)ipl, dlen);
816 if (!softl->iplt[unit]) {
817 softl->ipl_used[unit] = 0;
818 softl->iplh[unit] = &softl->iplt[unit];
819 softl->ipll[unit] = NULL;
822 softl->ipl_readers[unit]--;
823 MUTEX_EXIT(&softl->ipl_mutex[unit]);
829 /* ------------------------------------------------------------------------ */
830 /* Function: ipf_log_clear */
831 /* Returns: int - number of log bytes cleared. */
832 /* Parameters: softc(I) - pointer to main soft context */
833 /* unit(I) - device we are reading from */
835 /* Deletes all queued up log records for a given output device. */
836 /* ------------------------------------------------------------------------ */
838 ipf_log_clear(softc, unit)
839 ipf_main_softc_t *softc;
842 ipf_log_softc_t *softl = softc->ipf_log_soft;
848 MUTEX_ENTER(&softl->ipl_mutex[unit]);
849 while ((ipl = softl->iplt[unit]) != NULL) {
850 softl->iplt[unit] = ipl->ipl_next;
851 KFREES((caddr_t)ipl, ipl->ipl_dsize);
853 softl->iplh[unit] = &softl->iplt[unit];
854 softl->ipll[unit] = NULL;
855 used = softl->ipl_used[unit];
856 softl->ipl_used[unit] = 0;
857 bzero((char *)&softl->ipl_crc[unit], FI_CSIZE);
858 MUTEX_EXIT(&softl->ipl_mutex[unit]);
864 /* ------------------------------------------------------------------------ */
865 /* Function: ipf_log_canread */
866 /* Returns: int - 0 == no data to read, 1 = data present */
867 /* Parameters: softc(I) - pointer to main soft context */
868 /* unit(I) - device we are reading from */
870 /* Returns an indication of whether or not there is data present in the */
871 /* current buffer for the selected ipf device. */
872 /* ------------------------------------------------------------------------ */
874 ipf_log_canread(softc, unit)
875 ipf_main_softc_t *softc;
878 ipf_log_softc_t *softl = softc->ipf_log_soft;
880 return softl->iplt[unit] != NULL;
884 /* ------------------------------------------------------------------------ */
885 /* Function: ipf_log_canread */
886 /* Returns: int - 0 == no data to read, 1 = data present */
887 /* Parameters: softc(I) - pointer to main soft context */
888 /* unit(I) - device we are reading from */
890 /* Returns how many bytes are currently held in log buffers for the */
891 /* selected ipf device. */
892 /* ------------------------------------------------------------------------ */
894 ipf_log_bytesused(softc, unit)
895 ipf_main_softc_t *softc;
898 ipf_log_softc_t *softl = softc->ipf_log_soft;
903 return softl->ipl_used[unit];
907 /* ------------------------------------------------------------------------ */
908 /* Function: ipf_log_failures */
909 /* Returns: U_QUAD_T - number of log failures */
910 /* Parameters: softc(I) - pointer to main soft context */
911 /* unit(I) - device we are reading from */
913 /* Returns how many times we've tried to log a packet but failed to do so */
914 /* for the selected ipf device. */
915 /* ------------------------------------------------------------------------ */
917 ipf_log_failures(softc, unit)
918 ipf_main_softc_t *softc;
921 ipf_log_softc_t *softl = softc->ipf_log_soft;
926 return softl->ipl_logfail[unit];
930 /* ------------------------------------------------------------------------ */
931 /* Function: ipf_log_logok */
932 /* Returns: U_QUAD_T - number of packets logged */
933 /* Parameters: softc(I) - pointer to main soft context */
934 /* unit(I) - device we are reading from */
936 /* Returns how many times we've successfully logged a packet for the */
937 /* selected ipf device. */
938 /* ------------------------------------------------------------------------ */
940 ipf_log_logok(softc, unit)
941 ipf_main_softc_t *softc;
944 ipf_log_softc_t *softl = softc->ipf_log_soft;
949 return softl->ipl_logok[unit];
951 #endif /* IPFILTER_LOG */