1/* $FreeBSD: head/usr.bin/netstat/ipsec.c 160787 2006-07-28 16:09:19Z yar $ */ |
2/* $KAME: ipsec.c,v 1.33 2003/07/25 09:54:32 itojun Exp $ */ 3 4/* 5 * Copyright (c) 2005 NTT Multimedia Communications Laboratories, Inc. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions --- 81 unchanged lines hidden (view full) --- 91 92#if 0 93#ifndef lint 94static char sccsid[] = "@(#)inet.c 8.5 (Berkeley) 5/24/95"; 95#endif /* not lint */ 96#endif 97 98#include <sys/cdefs.h> |
99__FBSDID("$FreeBSD: head/usr.bin/netstat/ipsec.c 160787 2006-07-28 16:09:19Z yar $"); |
100 101#include <sys/param.h> 102#include <sys/queue.h> 103#include <sys/socket.h> 104 105#include <netinet/in.h> 106 107#if defined(IPSEC) && !defined(FAST_IPSEC) 108#include <netinet6/ipsec.h> 109#endif 110 111#ifdef FAST_IPSEC 112#include <netipsec/ipsec.h> 113#include <netipsec/ah_var.h> 114#include <netipsec/esp_var.h> 115#include <netipsec/ipcomp_var.h> 116#endif 117 |
118#include <stdint.h> |
119#include <stdio.h> 120#include <string.h> 121#include <unistd.h> 122#include "netstat.h" 123 124#ifdef IPSEC 125struct val2str { 126 int val; --- 73 unchanged lines hidden (view full) --- 200 printf("\t%s histogram:\n", title); 201 first = 0; 202 } 203 for (p = name; p && p->str; p++) { 204 if (p->val == (int)proto) 205 break; 206 } 207 if (p && p->str) { |
208 printf("\t\t%s: %ju\n", p->str, (uintmax_t)hist[proto]); |
209 } else { |
210 printf("\t\t#%ld: %ju\n", (long)proto, 211 (uintmax_t)hist[proto]); |
212 } 213 } 214} 215 216static void 217print_ipsecstats(const struct ipsecstat *ipsecstat) 218{ 219#define p(f, m) if (ipsecstat->f || sflag <= 1) \ |
220 printf(m, (uintmax_t)ipsecstat->f, plural(ipsecstat->f)) |
221#define pes(f, m) if (ipsecstat->f || sflag <= 1) \ |
222 printf(m, (uintmax_t)ipsecstat->f, plurales(ipsecstat->f)) |
223#define hist(f, n, t) \ 224 ipsec_hist((f), sizeof(f)/sizeof(f[0]), (n), (t)); 225 |
226 p(in_success, "\t%ju inbound packet%s processed successfully\n"); 227 p(in_polvio, "\t%ju inbound packet%s violated process security " |
228 "policy\n"); |
229 p(in_nosa, "\t%ju inbound packet%s with no SA available\n"); 230 p(in_inval, "\t%ju invalid inbound packet%s\n"); 231 p(in_nomem, "\t%ju inbound packet%s failed due to insufficient memory\n"); 232 p(in_badspi, "\t%ju inbound packet%s failed getting SPI\n"); 233 p(in_ahreplay, "\t%ju inbound packet%s failed on AH replay check\n"); 234 p(in_espreplay, "\t%ju inbound packet%s failed on ESP replay check\n"); 235 p(in_ahauthsucc, "\t%ju inbound packet%s considered authentic\n"); 236 p(in_ahauthfail, "\t%ju inbound packet%s failed on authentication\n"); |
237 hist(ipsecstat->in_ahhist, ipsec_ahnames, "AH input"); 238 hist(ipsecstat->in_esphist, ipsec_espnames, "ESP input"); 239 hist(ipsecstat->in_comphist, ipsec_compnames, "IPComp input"); 240 |
241 p(out_success, "\t%ju outbound packet%s processed successfully\n"); 242 p(out_polvio, "\t%ju outbound packet%s violated process security " |
243 "policy\n"); |
244 p(out_nosa, "\t%ju outbound packet%s with no SA available\n"); 245 p(out_inval, "\t%ju invalid outbound packet%s\n"); 246 p(out_nomem, "\t%ju outbound packet%s failed due to insufficient memory\n"); 247 p(out_noroute, "\t%ju outbound packet%s with no route\n"); |
248 hist(ipsecstat->out_ahhist, ipsec_ahnames, "AH output"); 249 hist(ipsecstat->out_esphist, ipsec_espnames, "ESP output"); 250 hist(ipsecstat->out_comphist, ipsec_compnames, "IPComp output"); |
251 p(spdcachelookup, "\t%ju SPD cache lookup%s\n"); 252 pes(spdcachemiss, "\t%ju SPD cache miss%s\n"); |
253#undef p 254#undef pes 255#undef hist 256} 257 258void 259ipsec_stats(u_long off, const char *name, int af1 __unused) 260{ --- 87 unchanged lines hidden (view full) --- 348} 349 350static void 351print_ahstats(const struct ahstat *ahstat) 352{ 353#define p32(f, m) if (ahstat->f || sflag <= 1) \ 354 printf("\t%u" m, (unsigned int)ahstat->f, plural(ahstat->f)) 355#define p64(f, m) if (ahstat->f || sflag <= 1) \ |
356 printf("\t%ju" m, (uintmax_t)ahstat->f, plural(ahstat->f)) |
357#define hist(f, n, t) \ 358 ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t)); 359 360 p32(ahs_hdrops, " packet%s shorter than header shows\n"); 361 p32(ahs_nopf, " packet%s dropped; protocol family not supported\n"); 362 p32(ahs_notdb, " packet%s dropped; no TDB\n"); 363 p32(ahs_badkcr, " packet%s dropped; bad KCR\n"); 364 p32(ahs_qfull, " packet%s dropped; queue full\n"); --- 32 unchanged lines hidden (view full) --- 397} 398 399static void 400print_espstats(const struct espstat *espstat) 401{ 402#define p32(f, m) if (espstat->f || sflag <= 1) \ 403 printf("\t%u" m, (unsigned int)espstat->f, plural(espstat->f)) 404#define p64(f, m) if (espstat->f || sflag <= 1) \ |
405 printf("\t%ju" m, (uintmax_t)espstat->f, plural(espstat->f)) |
406#define hist(f, n, t) \ 407 ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t)); 408 409 p32(esps_hdrops, " packet%s shorter than header shows\n"); 410 p32(esps_nopf, " packet%s dropped; protocol family not supported\n"); 411 p32(esps_notdb, " packet%s dropped; no TDB\n"); 412 p32(esps_badkcr, " packet%s dropped; bad KCR\n"); 413 p32(esps_qfull, " packet%s dropped; queue full\n"); --- 33 unchanged lines hidden (view full) --- 447} 448 449static void 450print_ipcompstats(const struct ipcompstat *ipcompstat) 451{ 452#define p32(f, m) if (ipcompstat->f || sflag <= 1) \ 453 printf("\t%u" m, (unsigned int)ipcompstat->f, plural(ipcompstat->f)) 454#define p64(f, m) if (ipcompstat->f || sflag <= 1) \ |
455 printf("\t%ju" m, (uintmax_t)ipcompstat->f, plural(ipcompstat->f)) |
456#define hist(f, n, t) \ 457 ipsec_hist_new((f), sizeof(f)/sizeof(f[0]), (n), (t)); 458 459 p32(ipcomps_hdrops, " packet%s shorter than header shows\n"); 460 p32(ipcomps_nopf, " packet%s dropped; protocol family not supported\n"); 461 p32(ipcomps_notdb, " packet%s dropped; no TDB\n"); 462 p32(ipcomps_badkcr, " packet%s dropped; bad KCR\n"); 463 p32(ipcomps_qfull, " packet%s dropped; queue full\n"); --- 32 unchanged lines hidden --- |