1261601Sglebius/*- 2261601Sglebius * Copyright (c) 2014 Gleb Smirnoff <glebius@FreeBSD.org> 3261601Sglebius * 4261601Sglebius * Redistribution and use in source and binary forms, with or without 5261601Sglebius * modification, are permitted provided that the following conditions 6261601Sglebius * are met: 7261601Sglebius * 1. Redistributions of source code must retain the above copyright 8261601Sglebius * notice, this list of conditions and the following disclaimer. 9261601Sglebius * 2. Redistributions in binary form must reproduce the above copyright 10261601Sglebius * notice, this list of conditions and the following disclaimer in the 11261601Sglebius * documentation and/or other materials provided with the distribution. 12261601Sglebius * 4. Neither the name of the University nor the names of its contributors 13261601Sglebius * may be used to endorse or promote products derived from this software 14261601Sglebius * without specific prior written permission. 15261601Sglebius * 16261601Sglebius * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 17261601Sglebius * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18261601Sglebius * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19261601Sglebius * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20261601Sglebius * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21261601Sglebius * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22261601Sglebius * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23261601Sglebius * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24261601Sglebius * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25261601Sglebius * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26261601Sglebius * SUCH DAMAGE. 27261601Sglebius */ 28261601Sglebius 29261601Sglebius#include <sys/cdefs.h> 30261601Sglebius__FBSDID("$FreeBSD$"); 31261601Sglebius#include <sys/param.h> 32261601Sglebius#include <sys/sysctl.h> 33261601Sglebius#include <net/flowtable.h> 34261601Sglebius#include <err.h> 35261601Sglebius#include <stdint.h> 36261601Sglebius#include <stdio.h> 37261601Sglebius#include "netstat.h" 38261601Sglebius 39261601Sglebius/* 40261601Sglebius * Print flowtable statistics. 41261601Sglebius */ 42261601Sglebius 43261601Sglebiusstatic void 44261601Sglebiusprint_stats(struct flowtable_stat *stat) 45261601Sglebius{ 46261601Sglebius 47261601Sglebius#define p(f, m) if (stat->f || sflag <= 1) \ 48261601Sglebius printf(m, (uintmax_t)stat->f, plural(stat->f)) 49261601Sglebius#define p2(f, m) if (stat->f || sflag <= 1) \ 50261601Sglebius printf(m, (uintmax_t)stat->f, plurales(stat->f)) 51261601Sglebius 52261601Sglebius p(ft_lookups, "\t%ju lookup%s\n"); 53261601Sglebius p(ft_hits, "\t%ju hit%s\n"); 54261601Sglebius p2(ft_misses, "\t%ju miss%s\n"); 55262743Sglebius p(ft_inserts, "\t%ju insert%s\n"); 56261601Sglebius p(ft_collisions, "\t%ju collision%s\n"); 57261601Sglebius p(ft_free_checks, "\t%ju free check%s\n"); 58261601Sglebius p(ft_frees, "\t%ju free%s\n"); 59262743Sglebius p(ft_fail_lle_invalid, 60262743Sglebius "\t%ju lookup%s with not resolved Layer 2 address\n"); 61261601Sglebius 62261601Sglebius#undef p2 63261601Sglebius#undef p 64261601Sglebius} 65261601Sglebius 66261601Sglebiusvoid 67261601Sglebiusflowtable_stats(void) 68261601Sglebius{ 69261601Sglebius struct flowtable_stat stat; 70261601Sglebius size_t len = sizeof(stat); 71261601Sglebius 72261601Sglebius if (!live) 73261601Sglebius return; 74261601Sglebius 75261601Sglebius if (sysctlbyname("net.flowtable.ip4.stat", &stat, &len, NULL, 0) == 0) { 76261601Sglebius printf("flowtable for IPv4:\n"); 77261601Sglebius print_stats(&stat); 78261601Sglebius } 79261601Sglebius 80261601Sglebius if (sysctlbyname("net.flowtable.ip6.stat", &stat, &len, NULL, 0) == 0) { 81261601Sglebius printf("flowtable for IPv6:\n"); 82261601Sglebius print_stats(&stat); 83261601Sglebius } 84261601Sglebius} 85