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 # if defined(sun) && (defined(__svr4__) || defined(__SVR4))
28 #include <sys/errno.h>
29 #include <sys/types.h>
45 #if (defined(__FreeBSD_version) && (__FreeBSD_version >= 220000)) && \
47 # include <sys/fcntl.h>
48 # include <sys/filio.h>
50 # include <sys/ioctl.h>
54 # include <sys/systm.h>
55 # if (defined(NetBSD) && (__NetBSD_Version__ >= 104000000))
56 # include <sys/proc.h>
59 #if !SOLARIS && !defined(__hpux) && !defined(linux)
60 # if (defined(NetBSD) && (NetBSD > 199609)) || \
61 (defined(OpenBSD) && (OpenBSD > 199603)) || \
62 (defined(__FreeBSD_version) && (__FreeBSD_version >= 300000))
63 # include <sys/dirent.h>
67 # include <sys/mbuf.h>
68 # include <sys/select.h>
69 # if __FreeBSD_version >= 500000
70 # include <sys/selinfo.h>
73 # if !defined(__hpux) && defined(_KERNEL)
74 # include <sys/filio.h>
75 # include <sys/cred.h>
77 # include <sys/sunddi.h>
78 # include <sys/ksynch.h>
79 # include <sys/kmem.h>
80 # include <sys/mkdev.h>
81 # include <sys/dditypes.h>
82 # include <sys/cmn_err.h>
84 #endif /* !SOLARIS && !__hpux */
86 # include <sys/protosw.h>
88 #include <sys/socket.h>
94 #if __FreeBSD_version >= 300000
95 # include <net/if_var.h>
97 #include <netinet/in.h>
100 # ifdef IFF_DRVRLOCK /* IRIX6 */
101 # include <sys/hashing.h>
104 #if !defined(__hpux) && !defined(linux) && \
105 !(defined(__sgi) && !defined(IFF_DRVRLOCK)) /*IRIX<6*/
106 # include <netinet/in_var.h>
108 #include <netinet/in_systm.h>
109 #include <netinet/ip.h>
110 #include <netinet/tcp.h>
111 #include <netinet/udp.h>
112 #include <netinet/ip_icmp.h>
114 # include <netinet/icmp6.h>
117 # include <netinet/ip_var.h>
122 #include "netinet/ip_compat.h"
123 #include <netinet/tcpip.h>
124 #include "netinet/ip_fil.h"
125 #include "netinet/ip_nat.h"
126 #include "netinet/ip_frag.h"
127 #include "netinet/ip_state.h"
128 #include "netinet/ip_auth.h"
129 #if (__FreeBSD_version >= 300000) || defined(__NetBSD__)
130 # include <sys/malloc.h>
132 /* END OF INCLUDES */
136 # if defined(IPL_SELECT)
137 # include <machine/sys/user.h>
138 # include <sys/kthread_iface.h>
139 # define READ_COLLISION 0x001
141 # endif /* IPL_SELECT */
143 typedef struct ipf_log_softc_s {
144 ipfmutex_t ipl_mutex[IPL_LOGSIZE];
145 # if SOLARIS && defined(_KERNEL)
146 kcondvar_t ipl_wait[IPL_LOGSIZE];
148 # if defined(linux) && defined(_KERNEL)
149 wait_queue_head_t iplh_linux[IPL_LOGSIZE];
151 # if defined(__hpux) && defined(_KERNEL)
152 iplog_select_t ipl_ss[IPL_LOGSIZE];
154 iplog_t **iplh[IPL_LOGSIZE];
155 iplog_t *iplt[IPL_LOGSIZE];
156 iplog_t *ipll[IPL_LOGSIZE];
157 u_long ipl_logfail[IPL_LOGSIZE];
158 u_long ipl_logok[IPL_LOGSIZE];
159 fr_info_t ipl_crc[IPL_LOGSIZE];
160 u_32_t ipl_counter[IPL_LOGSIZE];
165 int ipl_used[IPL_LOGSIZE];
166 int ipl_magic[IPL_LOGSIZE];
167 ipftuneable_t *ipf_log_tune;
168 int ipl_readers[IPL_LOGSIZE];
171 static int magic[IPL_LOGSIZE] = { IPL_MAGIC, IPL_MAGIC_NAT, IPL_MAGIC_STATE,
172 IPL_MAGIC, IPL_MAGIC, IPL_MAGIC,
173 IPL_MAGIC, IPL_MAGIC };
175 static ipftuneable_t ipf_log_tuneables[] = {
177 { { (void *)offsetof(ipf_log_softc_t, ipl_suppress) },
178 "log_suppress", 0, 1,
179 stsizeof(ipf_log_softc_t, ipl_suppress),
181 { { (void *)offsetof(ipf_log_softc_t, ipl_logall) },
183 stsizeof(ipf_log_softc_t, ipl_logall),
185 { { (void *)offsetof(ipf_log_softc_t, ipl_logsize) },
186 "log_size", 0, 0x80000,
187 stsizeof(ipf_log_softc_t, ipl_logsize),
189 { { NULL }, NULL, 0, 0,
203 ipf_log_main_unload()
208 /* ------------------------------------------------------------------------ */
209 /* Function: ipf_log_soft_create */
210 /* Returns: void * - NULL = failure, else pointer to log context data */
211 /* Parameters: softc(I) - pointer to soft context main structure */
213 /* Initialise log buffers & pointers. Also iniialised the CRC to a local */
214 /* secret for use in calculating the "last log checksum". */
215 /* ------------------------------------------------------------------------ */
217 ipf_log_soft_create(softc)
218 ipf_main_softc_t *softc;
220 ipf_log_softc_t *softl;
223 KMALLOC(softl, ipf_log_softc_t *);
227 bzero((char *)softl, sizeof(*softl));
228 bcopy((char *)magic, (char *)softl->ipl_magic, sizeof(magic));
230 softl->ipf_log_tune = ipf_tune_array_copy(softl,
231 sizeof(ipf_log_tuneables),
233 if (softl->ipf_log_tune == NULL) {
234 ipf_log_soft_destroy(softc, softl);
237 if (ipf_tune_array_link(softc, softl->ipf_log_tune) == -1) {
238 ipf_log_soft_destroy(softc, softl);
242 for (i = IPL_LOGMAX; i >= 0; i--) {
243 MUTEX_INIT(&softl->ipl_mutex[i], "ipf log mutex");
246 softl->ipl_suppress = 1;
247 softl->ipl_logall = 0;
248 softl->ipl_log_init = 0;
249 softl->ipl_logsize = IPFILTER_LOGSIZE;
254 /* ------------------------------------------------------------------------ */
255 /* Function: ipf_log_soft_init */
256 /* Returns: int - 0 == success (always returned) */
257 /* Parameters: softc(I) - pointer to soft context main structure */
259 /* Initialise log buffers & pointers. Also iniialised the CRC to a local */
260 /* secret for use in calculating the "last log checksum". */
261 /* ------------------------------------------------------------------------ */
263 ipf_log_soft_init(softc, arg)
264 ipf_main_softc_t *softc;
267 ipf_log_softc_t *softl = arg;
270 for (i = IPL_LOGMAX; i >= 0; i--) {
271 softl->iplt[i] = NULL;
272 softl->ipll[i] = NULL;
273 softl->iplh[i] = &softl->iplt[i];
274 bzero((char *)&softl->ipl_crc[i], sizeof(softl->ipl_crc[i]));
276 softl->iplog_ss[i].read_waiter = 0;
277 softl->iplog_ss[i].state = 0;
282 softl->ipl_log_init = 1;
288 /* ------------------------------------------------------------------------ */
289 /* Function: ipf_log_soft_fini */
290 /* Parameters: softc(I) - pointer to soft context main structure */
291 /* arg(I) - pointer to log context structure */
293 /* Clean up any log data that has accumulated without being read. */
294 /* ------------------------------------------------------------------------ */
296 ipf_log_soft_fini(softc, arg)
297 ipf_main_softc_t *softc;
300 ipf_log_softc_t *softl = arg;
303 if (softl->ipl_log_init == 0)
306 softl->ipl_log_init = 0;
308 for (i = IPL_LOGMAX; i >= 0; i--) {
309 (void) ipf_log_clear(softc, i);
312 * This is a busy-wait loop so as to avoid yet another lock
315 MUTEX_ENTER(&softl->ipl_mutex[i]);
316 while (softl->ipl_readers[i] > 0) {
317 # if SOLARIS && defined(_KERNEL)
318 cv_broadcast(&softl->ipl_wait[i]);
319 MUTEX_EXIT(&softl->ipl_mutex[i]);
321 pollwakeup(&softc->ipf_poll_head[i], POLLRDNORM);
323 MUTEX_EXIT(&softl->ipl_mutex[i]);
324 WAKEUP(softl->iplh, i);
327 MUTEX_ENTER(&softl->ipl_mutex[i]);
329 MUTEX_EXIT(&softl->ipl_mutex[i]);
336 /* ------------------------------------------------------------------------ */
337 /* Function: ipf_log_soft_destroy */
338 /* Parameters: softc(I) - pointer to soft context main structure */
339 /* arg(I) - pointer to log context structure */
341 /* When this function is called, it is expected that there are no longer */
342 /* any threads active in the reading code path or the logging code path. */
343 /* ------------------------------------------------------------------------ */
345 ipf_log_soft_destroy(softc, arg)
346 ipf_main_softc_t *softc;
349 ipf_log_softc_t *softl = arg;
352 for (i = IPL_LOGMAX; i >= 0; i--) {
353 # if SOLARIS && defined(_KERNEL)
354 cv_destroy(&softl->ipl_wait[i]);
356 MUTEX_DESTROY(&softl->ipl_mutex[i]);
359 if (softl->ipf_log_tune != NULL) {
360 ipf_tune_array_unlink(softc, softl->ipf_log_tune);
361 KFREES(softl->ipf_log_tune, sizeof(ipf_log_tuneables));
362 softl->ipf_log_tune = NULL;
369 /* ------------------------------------------------------------------------ */
370 /* Function: ipf_log_pkt */
371 /* Returns: int - 0 == success, -1 == failure */
372 /* Parameters: fin(I) - pointer to packet information */
373 /* flags(I) - flags from filter rules */
375 /* Create a log record for a packet given that it has been triggered by a */
376 /* rule (or the default setting). Calculate the transport protocol header */
377 /* size using predetermined size of a couple of popular protocols and thus */
378 /* how much data to copy into the log, including part of the data body if */
380 /* ------------------------------------------------------------------------ */
382 ipf_log_pkt(fin, flags)
386 ipf_main_softc_t *softc = fin->fin_main_soft;
387 ipf_log_softc_t *softl = softc->ipf_log_soft;
388 register size_t hlen;
395 # if (SOLARIS || defined(__hpux)) && defined(_KERNEL) && !defined(FW_HOOKS)
399 # endif /* SOLARIS || __hpux */
405 ipfl.fl_nattag.ipt_num[0] = 0;
407 hlen = (char *)fin->fin_dp - (char *)fin->fin_ip;
410 * calculate header size.
412 if (fin->fin_off == 0) {
413 p = fin->fin_fi.fi_p;
414 if (p == IPPROTO_TCP)
415 hlen += MIN(sizeof(tcphdr_t), fin->fin_dlen);
416 else if (p == IPPROTO_UDP)
417 hlen += MIN(sizeof(udphdr_t), fin->fin_dlen);
418 else if (p == IPPROTO_ICMP) {
421 icmp = (struct icmp *)fin->fin_dp;
424 * For ICMP, if the packet is an error packet, also
425 * include the information about the packet which
428 switch (icmp->icmp_type)
431 case ICMP_SOURCEQUENCH :
434 case ICMP_PARAMPROB :
435 hlen += MIN(sizeof(struct icmp) + 8,
439 hlen += MIN(sizeof(struct icmp),
445 else if (p == IPPROTO_ICMPV6) {
446 struct icmp6_hdr *icmp;
448 icmp = (struct icmp6_hdr *)fin->fin_dp;
451 * For ICMPV6, if the packet is an error packet, also
452 * include the information about the packet which
455 if (icmp->icmp6_type < 128) {
456 hlen += MIN(sizeof(struct icmp6_hdr) + 8,
459 hlen += MIN(sizeof(struct icmp6_hdr),
466 * Get the interface number and name to which this packet is
467 * currently associated.
469 # if (SOLARIS || defined(__hpux)) && defined(_KERNEL)
470 # if !defined(FW_HOOKS)
471 ipfl.fl_unit = (u_int)ifp->qf_ppa;
473 COPYIFNAME(fin->fin_v, ifp, ipfl.fl_ifname);
475 # if (defined(NetBSD) && (NetBSD <= 1991011) && (NetBSD >= 199603)) || \
476 OPENBSD_GE_REV(199603) || defined(linux) || FREEBSD_GE_REV(501113)
477 COPYIFNAME(fin->fin_v, ifp, ipfl.fl_ifname);
479 ipfl.fl_unit = (u_int)ifp->if_unit;
480 # if defined(_KERNEL)
481 if ((ipfl.fl_ifname[0] = ifp->if_name[0]))
482 if ((ipfl.fl_ifname[1] = ifp->if_name[1]))
483 if ((ipfl.fl_ifname[2] = ifp->if_name[2]))
484 ipfl.fl_ifname[3] = ifp->if_name[3];
486 (void) strncpy(ipfl.fl_ifname, IFNAME(ifp), sizeof(ipfl.fl_ifname));
487 ipfl.fl_ifname[sizeof(ipfl.fl_ifname) - 1] = '\0';
490 # endif /* __hpux || SOLARIS */
491 mlen = fin->fin_plen - hlen;
492 if (!softl->ipl_logall) {
493 mlen = (flags & FR_LOGBODY) ? MIN(mlen, 128) : 0;
494 } else if ((flags & FR_LOGBODY) == 0) {
499 ipfl.fl_plen = (u_char)mlen;
500 ipfl.fl_hlen = (u_char)hlen;
501 ipfl.fl_rule = fin->fin_rule;
502 (void) strncpy(ipfl.fl_group, fin->fin_group, FR_GROUPLEN);
503 if (fin->fin_fr != NULL) {
504 ipfl.fl_loglevel = fin->fin_fr->fr_loglevel;
505 ipfl.fl_logtag = fin->fin_fr->fr_logtag;
507 ipfl.fl_loglevel = 0xffff;
508 ipfl.fl_logtag = FR_NOLOGTAG;
510 if (fin->fin_nattag != NULL)
511 bcopy(fin->fin_nattag, (void *)&ipfl.fl_nattag,
512 sizeof(ipfl.fl_nattag));
513 ipfl.fl_flags = flags;
514 ipfl.fl_breason = (fin->fin_reason & 0xff);
515 ipfl.fl_dir = fin->fin_out;
516 ipfl.fl_lflags = fin->fin_flx;
517 ipfl.fl_family = fin->fin_family;
518 ptrs[0] = (void *)&ipfl;
519 sizes[0] = sizeof(ipfl);
521 # if defined(MENTAT) && defined(_KERNEL)
523 * Are we copied from the mblk or an aligned array ?
525 if (fin->fin_ip == (ip_t *)m->b_rptr) {
527 sizes[1] = hlen + mlen;
530 ptrs[1] = fin->fin_ip;
531 sizes[1] = hlen + mlen;
536 sizes[1] = hlen + mlen;
539 return ipf_log_items(softc, IPL_LOGIPF, fin, ptrs, sizes, types, 2);
543 /* ------------------------------------------------------------------------ */
544 /* Function: ipf_log_items */
545 /* Returns: int - 0 == success, -1 == failure */
546 /* Parameters: softc(I) - pointer to main soft context */
547 /* unit(I) - device we are reading from */
548 /* fin(I) - pointer to packet information */
549 /* items(I) - array of pointers to log data */
550 /* itemsz(I) - array of size of valid memory pointed to */
551 /* types(I) - type of data pointed to by items pointers */
552 /* cnt(I) - number of elements in arrays items/itemsz/types */
554 /* Takes an array of parameters and constructs one record to include the */
555 /* miscellaneous packet information, as well as packet data, for reading */
556 /* from the log device. */
557 /* ------------------------------------------------------------------------ */
559 ipf_log_items(softc, unit, fin, items, itemsz, types, cnt)
560 ipf_main_softc_t *softc;
567 ipf_log_softc_t *softl = softc->ipf_log_soft;
575 * Get the total amount of data to be logged.
577 for (i = 0, len = sizeof(iplog_t); i < cnt; i++)
581 MUTEX_ENTER(&softl->ipl_mutex[unit]);
582 softl->ipl_counter[unit]++;
584 * check that we have space to record this information and can
585 * allocate that much.
587 if ((softl->ipl_used[unit] + len) > softl->ipl_logsize) {
588 softl->ipl_logfail[unit]++;
589 MUTEX_EXIT(&softl->ipl_mutex[unit]);
593 KMALLOCS(buf, caddr_t, len);
595 softl->ipl_logfail[unit]++;
596 MUTEX_EXIT(&softl->ipl_mutex[unit]);
599 ipl = (iplog_t *)buf;
600 ipl->ipl_magic = softl->ipl_magic[unit];
602 ipl->ipl_seqnum = softl->ipl_counter[unit];
603 ipl->ipl_next = NULL;
604 ipl->ipl_dsize = len;
606 GETKTIME(&ipl->ipl_sec);
613 * Loop through all the items to be logged, copying each one to the
614 * buffer. Use bcopy for normal data or the mb_t copyout routine.
616 for (i = 0, ptr = buf + sizeof(*ipl); i < cnt; i++) {
618 bcopy(items[i], ptr, itemsz[i]);
619 } else if (types[i] == 1) {
620 COPYDATA(items[i], 0, itemsz[i], ptr);
625 * Check to see if this log record has a CRC which matches the last
626 * record logged. If it does, just up the count on the previous one
627 * rather than create a new one.
629 if (softl->ipl_suppress) {
630 if ((fin != NULL) && (fin->fin_off == 0)) {
631 if ((softl->ipll[unit] != NULL) &&
632 (fin->fin_crc == softl->ipl_crc[unit].fin_crc) &&
633 bcmp((char *)fin, (char *)&softl->ipl_crc[unit],
635 softl->ipll[unit]->ipl_count++;
636 MUTEX_EXIT(&softl->ipl_mutex[unit]);
641 bcopy((char *)fin, (char *)&softl->ipl_crc[unit],
643 softl->ipl_crc[unit].fin_crc = fin->fin_crc;
645 bzero((char *)&softl->ipl_crc[unit], FI_CSIZE);
649 * advance the log pointer to the next empty record and deduct the
650 * amount of space we're going to use.
652 softl->ipl_logok[unit]++;
653 softl->ipll[unit] = ipl;
654 *softl->iplh[unit] = ipl;
655 softl->iplh[unit] = &ipl->ipl_next;
656 softl->ipl_used[unit] += len;
659 * Now that the log record has been completed and added to the queue,
660 * wake up any listeners who may want to read it.
662 # if SOLARIS && defined(_KERNEL)
663 cv_signal(&softl->ipl_wait[unit]);
664 MUTEX_EXIT(&softl->ipl_mutex[unit]);
665 pollwakeup(&softc->ipf_poll_head[unit], POLLRDNORM);
667 MUTEX_EXIT(&softl->ipl_mutex[unit]);
668 WAKEUP(softl->iplh, unit);
673 iplog_input_ready(unit);
679 /* ------------------------------------------------------------------------ */
680 /* Function: ipf_log_read */
681 /* Returns: int - 0 == success, else error value. */
682 /* Parameters: softc(I) - pointer to main soft context */
683 /* unit(I) - device we are reading from */
684 /* uio(O) - pointer to information about where to store data */
686 /* Called to handle a read on an IPFilter device. Returns only complete */
687 /* log messages - will not partially copy a log record out to userland. */
689 /* NOTE: This function will block and wait for a signal to return data if */
690 /* there is none present. Asynchronous I/O is not implemented. */
691 /* ------------------------------------------------------------------------ */
693 ipf_log_read(softc, unit, uio)
694 ipf_main_softc_t *softc;
698 ipf_log_softc_t *softl = softc->ipf_log_soft;
704 if (softl->ipl_log_init == 0) {
710 * Sanity checks. Make sure the minor # is valid and we're copying
711 * a valid chunk of data.
713 if (IPL_LOGMAX < unit) {
717 if (uio->uio_resid == 0)
720 if (uio->uio_resid < sizeof(iplog_t)) {
724 if (uio->uio_resid > softl->ipl_logsize) {
730 * Lock the log so we can snapshot the variables. Wait for a signal
731 * if the log is empty.
734 MUTEX_ENTER(&softl->ipl_mutex[unit]);
735 softl->ipl_readers[unit]++;
737 while (softl->ipl_log_init == 1 && softl->iplt[unit] == NULL) {
738 # if SOLARIS && defined(_KERNEL)
739 if (!cv_wait_sig(&softl->ipl_wait[unit],
740 &softl->ipl_mutex[unit].ipf_lk)) {
741 softl->ipl_readers[unit]--;
742 MUTEX_EXIT(&softl->ipl_mutex[unit]);
747 # if defined(__hpux) && defined(_KERNEL)
751 if (uio->uio_fpflags & (FNBLOCK|FNDELAY)) {
752 /* this is no blocking system call */
753 softl->ipl_readers[unit]--;
754 MUTEX_EXIT(&softl->ipl_mutex[unit]);
759 MUTEX_EXIT(&softl->ipl_mutex[unit]);
760 l = get_sleep_lock(&softl->iplh[unit]);
761 error = sleep(&softl->iplh[unit], PZERO+1);
764 # if defined(__osf__) && defined(_KERNEL)
765 error = mpsleep(&softl->iplh[unit], PSUSP|PCATCH, "ipfread", 0,
766 &softl->ipl_mutex, MS_LOCK_SIMPLE);
768 MUTEX_EXIT(&softl->ipl_mutex[unit]);
770 error = SLEEP(unit + softl->iplh, "ipl sleep");
771 # endif /* __osf__ */
774 MUTEX_ENTER(&softl->ipl_mutex[unit]);
776 softl->ipl_readers[unit]--;
777 MUTEX_EXIT(&softl->ipl_mutex[unit]);
781 # endif /* SOLARIS */
783 if (softl->ipl_log_init != 1) {
784 softl->ipl_readers[unit]--;
785 MUTEX_EXIT(&softl->ipl_mutex[unit]);
790 # if (defined(BSD) && (BSD >= 199101)) || defined(__FreeBSD__) || \
792 uio->uio_rw = UIO_READ;
795 for (copied = 0; (ipl = softl->iplt[unit]) != NULL; copied += dlen) {
796 dlen = ipl->ipl_dsize;
797 if (dlen > uio->uio_resid)
800 * Don't hold the mutex over the uiomove call.
802 softl->iplt[unit] = ipl->ipl_next;
803 softl->ipl_used[unit] -= dlen;
804 MUTEX_EXIT(&softl->ipl_mutex[unit]);
806 error = UIOMOVE(ipl, dlen, UIO_READ, uio);
809 MUTEX_ENTER(&softl->ipl_mutex[unit]);
811 ipl->ipl_next = softl->iplt[unit];
812 softl->iplt[unit] = ipl;
813 softl->ipl_used[unit] += dlen;
816 MUTEX_ENTER(&softl->ipl_mutex[unit]);
817 KFREES((caddr_t)ipl, dlen);
820 if (!softl->iplt[unit]) {
821 softl->ipl_used[unit] = 0;
822 softl->iplh[unit] = &softl->iplt[unit];
823 softl->ipll[unit] = NULL;
826 softl->ipl_readers[unit]--;
827 MUTEX_EXIT(&softl->ipl_mutex[unit]);
833 /* ------------------------------------------------------------------------ */
834 /* Function: ipf_log_clear */
835 /* Returns: int - number of log bytes cleared. */
836 /* Parameters: softc(I) - pointer to main soft context */
837 /* unit(I) - device we are reading from */
839 /* Deletes all queued up log records for a given output device. */
840 /* ------------------------------------------------------------------------ */
842 ipf_log_clear(softc, unit)
843 ipf_main_softc_t *softc;
846 ipf_log_softc_t *softl = softc->ipf_log_soft;
852 MUTEX_ENTER(&softl->ipl_mutex[unit]);
853 while ((ipl = softl->iplt[unit]) != NULL) {
854 softl->iplt[unit] = ipl->ipl_next;
855 KFREES((caddr_t)ipl, ipl->ipl_dsize);
857 softl->iplh[unit] = &softl->iplt[unit];
858 softl->ipll[unit] = NULL;
859 used = softl->ipl_used[unit];
860 softl->ipl_used[unit] = 0;
861 bzero((char *)&softl->ipl_crc[unit], FI_CSIZE);
862 MUTEX_EXIT(&softl->ipl_mutex[unit]);
868 /* ------------------------------------------------------------------------ */
869 /* Function: ipf_log_canread */
870 /* Returns: int - 0 == no data to read, 1 = data present */
871 /* Parameters: softc(I) - pointer to main soft context */
872 /* unit(I) - device we are reading from */
874 /* Returns an indication of whether or not there is data present in the */
875 /* current buffer for the selected ipf device. */
876 /* ------------------------------------------------------------------------ */
878 ipf_log_canread(softc, unit)
879 ipf_main_softc_t *softc;
882 ipf_log_softc_t *softl = softc->ipf_log_soft;
884 return softl->iplt[unit] != NULL;
888 /* ------------------------------------------------------------------------ */
889 /* Function: ipf_log_canread */
890 /* Returns: int - 0 == no data to read, 1 = data present */
891 /* Parameters: softc(I) - pointer to main soft context */
892 /* unit(I) - device we are reading from */
894 /* Returns how many bytes are currently held in log buffers for the */
895 /* selected ipf device. */
896 /* ------------------------------------------------------------------------ */
898 ipf_log_bytesused(softc, unit)
899 ipf_main_softc_t *softc;
902 ipf_log_softc_t *softl = softc->ipf_log_soft;
907 return softl->ipl_used[unit];
911 /* ------------------------------------------------------------------------ */
912 /* Function: ipf_log_failures */
913 /* Returns: U_QUAD_T - number of log failures */
914 /* Parameters: softc(I) - pointer to main soft context */
915 /* unit(I) - device we are reading from */
917 /* Returns how many times we've tried to log a packet but failed to do so */
918 /* for the selected ipf device. */
919 /* ------------------------------------------------------------------------ */
921 ipf_log_failures(softc, unit)
922 ipf_main_softc_t *softc;
925 ipf_log_softc_t *softl = softc->ipf_log_soft;
930 return softl->ipl_logfail[unit];
934 /* ------------------------------------------------------------------------ */
935 /* Function: ipf_log_logok */
936 /* Returns: U_QUAD_T - number of packets logged */
937 /* Parameters: softc(I) - pointer to main soft context */
938 /* unit(I) - device we are reading from */
940 /* Returns how many times we've successfully logged a packet for the */
941 /* selected ipf device. */
942 /* ------------------------------------------------------------------------ */
944 ipf_log_logok(softc, unit)
945 ipf_main_softc_t *softc;
948 ipf_log_softc_t *softl = softc->ipf_log_soft;
953 return softl->ipl_logok[unit];
955 #endif /* IPFILTER_LOG */