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$"); 31293307Smarkj 32261601Sglebius#include <sys/param.h> 33293307Smarkj 34261601Sglebius#include <net/flowtable.h> 35293307Smarkj 36261601Sglebius#include <stdint.h> 37261601Sglebius#include <stdio.h> 38293307Smarkj 39261601Sglebius#include "netstat.h" 40261601Sglebius 41261601Sglebius/* 42261601Sglebius * Print flowtable statistics. 43261601Sglebius */ 44261601Sglebius 45261601Sglebiusstatic void 46261601Sglebiusprint_stats(struct flowtable_stat *stat) 47261601Sglebius{ 48261601Sglebius 49261601Sglebius#define p(f, m) if (stat->f || sflag <= 1) \ 50261601Sglebius printf(m, (uintmax_t)stat->f, plural(stat->f)) 51261601Sglebius#define p2(f, m) if (stat->f || sflag <= 1) \ 52261601Sglebius printf(m, (uintmax_t)stat->f, plurales(stat->f)) 53261601Sglebius 54261601Sglebius p(ft_lookups, "\t%ju lookup%s\n"); 55261601Sglebius p(ft_hits, "\t%ju hit%s\n"); 56261601Sglebius p2(ft_misses, "\t%ju miss%s\n"); 57262743Sglebius p(ft_inserts, "\t%ju insert%s\n"); 58261601Sglebius p(ft_collisions, "\t%ju collision%s\n"); 59261601Sglebius p(ft_free_checks, "\t%ju free check%s\n"); 60261601Sglebius p(ft_frees, "\t%ju free%s\n"); 61262743Sglebius p(ft_fail_lle_invalid, 62262743Sglebius "\t%ju lookup%s with not resolved Layer 2 address\n"); 63261601Sglebius 64261601Sglebius#undef p2 65261601Sglebius#undef p 66261601Sglebius} 67261601Sglebius 68261601Sglebiusvoid 69261601Sglebiusflowtable_stats(void) 70261601Sglebius{ 71261601Sglebius struct flowtable_stat stat; 72261601Sglebius 73261601Sglebius if (!live) 74261601Sglebius return; 75261601Sglebius 76293307Smarkj if (fetch_stats("net.flowtable.ip4.stat", 0, &stat, 77293307Smarkj sizeof(stat), NULL) == 0) { 78261601Sglebius printf("flowtable for IPv4:\n"); 79261601Sglebius print_stats(&stat); 80261601Sglebius } 81261601Sglebius 82293307Smarkj if (fetch_stats("net.flowtable.ip6.stat", 0, &stat, 83293307Smarkj sizeof(stat), NULL) == 0) { 84261601Sglebius printf("flowtable for IPv6:\n"); 85261601Sglebius print_stats(&stat); 86261601Sglebius } 87261601Sglebius} 88