Home | History | Annotate | Line # | Download | only in netstat
pfsync.c revision 1.1
      1  1.1  dyoung /*	$NetBSD: pfsync.c,v 1.1 2011/03/01 19:01:59 dyoung Exp $	*/
      2  1.1  dyoung 
      3  1.1  dyoung /*
      4  1.1  dyoung  * Copyright (c) 1983, 1988, 1993
      5  1.1  dyoung  *	The Regents of the University of California.  All rights reserved.
      6  1.1  dyoung  *
      7  1.1  dyoung  * Redistribution and use in source and binary forms, with or without
      8  1.1  dyoung  * modification, are permitted provided that the following conditions
      9  1.1  dyoung  * are met:
     10  1.1  dyoung  * 1. Redistributions of source code must retain the above copyright
     11  1.1  dyoung  *    notice, this list of conditions and the following disclaimer.
     12  1.1  dyoung  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  dyoung  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  dyoung  *    documentation and/or other materials provided with the distribution.
     15  1.1  dyoung  * 3. Neither the name of the University nor the names of its contributors
     16  1.1  dyoung  *    may be used to endorse or promote products derived from this software
     17  1.1  dyoung  *    without specific prior written permission.
     18  1.1  dyoung  *
     19  1.1  dyoung  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20  1.1  dyoung  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.1  dyoung  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.1  dyoung  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23  1.1  dyoung  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.1  dyoung  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.1  dyoung  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.1  dyoung  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.1  dyoung  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.1  dyoung  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.1  dyoung  * SUCH DAMAGE.
     30  1.1  dyoung  */
     31  1.1  dyoung 
     32  1.1  dyoung #include <sys/cdefs.h>
     33  1.1  dyoung #ifndef lint
     34  1.1  dyoung __RCSID("$NetBSD: pfsync.c,v 1.1 2011/03/01 19:01:59 dyoung Exp $");
     35  1.1  dyoung #endif /* not lint */
     36  1.1  dyoung 
     37  1.1  dyoung #define	_CALLOUT_PRIVATE	/* for defs in sys/callout.h */
     38  1.1  dyoung 
     39  1.1  dyoung #include <sys/param.h>
     40  1.1  dyoung #include <sys/queue.h>
     41  1.1  dyoung #include <sys/socket.h>
     42  1.1  dyoung #include <sys/socketvar.h>
     43  1.1  dyoung #include <sys/mbuf.h>
     44  1.1  dyoung #include <sys/protosw.h>
     45  1.1  dyoung #include <sys/sysctl.h>
     46  1.1  dyoung 
     47  1.1  dyoung #include <net/if_arp.h>
     48  1.1  dyoung #include <net/route.h>
     49  1.1  dyoung #include <netinet/in.h>
     50  1.1  dyoung #include <netinet/in_systm.h>
     51  1.1  dyoung #include <netinet/ip.h>
     52  1.1  dyoung #include <netinet/in_pcb.h>
     53  1.1  dyoung #include <netinet/ip_icmp.h>
     54  1.1  dyoung 
     55  1.1  dyoung #ifdef INET6
     56  1.1  dyoung #include <netinet/ip6.h>
     57  1.1  dyoung #endif
     58  1.1  dyoung 
     59  1.1  dyoung #include <net/pfvar.h>
     60  1.1  dyoung #include <net/if_pfsync.h>
     61  1.1  dyoung 
     62  1.1  dyoung #include <arpa/inet.h>
     63  1.1  dyoung #include <kvm.h>
     64  1.1  dyoung #include <netdb.h>
     65  1.1  dyoung #include <stdio.h>
     66  1.1  dyoung #include <string.h>
     67  1.1  dyoung #include <unistd.h>
     68  1.1  dyoung #include <stdlib.h>
     69  1.1  dyoung #include <err.h>
     70  1.1  dyoung #include "netstat.h"
     71  1.1  dyoung #include "prog_ops.h"
     72  1.1  dyoung 
     73  1.1  dyoung /*
     74  1.1  dyoung  * Dump PFSYNC statistics structure.
     75  1.1  dyoung  */
     76  1.1  dyoung void
     77  1.1  dyoung pfsync_stats(u_long off, const char *name)
     78  1.1  dyoung {
     79  1.1  dyoung 	uint64_t pfsyncstat[PFSYNC_NSTATS];
     80  1.1  dyoung 
     81  1.1  dyoung 	if (use_sysctl) {
     82  1.1  dyoung 		size_t size = sizeof(pfsyncstat);
     83  1.1  dyoung 
     84  1.1  dyoung 		if (sysctlbyname("net.inet.pfsync.stats", pfsyncstat, &size,
     85  1.1  dyoung 				 NULL, 0) == -1)
     86  1.1  dyoung 			return;
     87  1.1  dyoung 	} else {
     88  1.1  dyoung 		warnx("%s stats not available via KVM.", name);
     89  1.1  dyoung 		return;
     90  1.1  dyoung 	}
     91  1.1  dyoung 
     92  1.1  dyoung 	printf("%s:\n", name);
     93  1.1  dyoung 
     94  1.1  dyoung #define p(f, m) if (pfsyncstat[f] || sflag <= 1) \
     95  1.1  dyoung 	printf(m, pfsyncstat[f], plural(pfsyncstat[f]))
     96  1.1  dyoung #define p2(f, m) if (pfsyncstat[f] || sflag <= 1) \
     97  1.1  dyoung 	printf(m, pfsyncstat[f])
     98  1.1  dyoung 
     99  1.1  dyoung 	p(PFSYNC_STAT_IPACKETS, "\t%" PRIu64 " packet%s received (IPv4)\n");
    100  1.1  dyoung 	p(PFSYNC_STAT_IPACKETS6,"\t%" PRIu64 " packet%s received (IPv6)\n");
    101  1.1  dyoung 	p(PFSYNC_STAT_BADIF, "\t\t%" PRIu64 " packet%s discarded for bad interface\n");
    102  1.1  dyoung 	p(PFSYNC_STAT_BADTTL, "\t\t%" PRIu64 " packet%s discarded for bad ttl\n");
    103  1.1  dyoung 	p(PFSYNC_STAT_HDROPS, "\t\t%" PRIu64 " packet%s shorter than header\n");
    104  1.1  dyoung 	p(PFSYNC_STAT_BADVER, "\t\t%" PRIu64 " packet%s discarded for bad version\n");
    105  1.1  dyoung 	p(PFSYNC_STAT_BADAUTH, "\t\t%" PRIu64 " packet%s discarded for bad HMAC\n");
    106  1.1  dyoung 	p(PFSYNC_STAT_BADACT,"\t\t%" PRIu64 " packet%s discarded for bad action\n");
    107  1.1  dyoung 	p(PFSYNC_STAT_BADLEN, "\t\t%" PRIu64 " packet%s discarded for short packet\n");
    108  1.1  dyoung 	p(PFSYNC_STAT_BADVAL, "\t\t%" PRIu64 " state%s discarded for bad values\n");
    109  1.1  dyoung 	p(PFSYNC_STAT_STALE, "\t\t%" PRIu64 " stale state%s\n");
    110  1.1  dyoung 	p(PFSYNC_STAT_BADSTATE, "\t\t%" PRIu64 " failed state lookup/insert%s\n");
    111  1.1  dyoung 	p(PFSYNC_STAT_OPACKETS, "\t%" PRIu64 " packet%s sent (IPv4)\n");
    112  1.1  dyoung 	p(PFSYNC_STAT_OPACKETS6, "\t%" PRIu64 " packet%s sent (IPv6)\n");
    113  1.1  dyoung 	p2(PFSYNC_STAT_ONOMEM, "\t\t%" PRIu64 " send failed due to mbuf memory error\n");
    114  1.1  dyoung 	p2(PFSYNC_STAT_OERRORS, "\t\t%" PRIu64 " send error\n");
    115  1.1  dyoung #undef p
    116  1.1  dyoung #undef p2
    117  1.1  dyoung }
    118  1.1  dyoung 
    119  1.1  dyoung 
    120