ipsecstats.c (0bfd163f522701b486e066fa2e56624c02f5081a) ipsecstats.c (60caf0c9c2848b8389cc3159bbc219dd408a2496)
1/*-
2 * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
1/*-
2 * Copyright (c) 2002, 2003 Sam Leffler, Errno Consulting
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD$
27 */
28#include <sys/types.h>
28
29#include <sys/param.h>
30#include <sys/sysctl.h>
31
29#include <netipsec/ipsec.h>
30#include <netipsec/ah_var.h>
31#include <netipsec/esp_var.h>
32#include <netipsec/ipsec.h>
33#include <netipsec/ah_var.h>
34#include <netipsec/esp_var.h>
35
36#include <err.h>
32#include <stdint.h>
33#include <stdio.h>
34
35struct alg {
36 int a;
37 const char *name;
38};
39static const struct alg aalgs[] = {

--- 17 unchanged lines hidden (view full) ---

57 { SADB_X_EALG_RIJNDAELCBC, "rijndael-cbc", },
58};
59static const struct alg ipcompalgs[] = {
60 { SADB_X_CALG_NONE, "none", },
61 { SADB_X_CALG_OUI, "oui", },
62 { SADB_X_CALG_DEFLATE, "deflate", },
63 { SADB_X_CALG_LZS, "lzs", },
64};
37#include <stdint.h>
38#include <stdio.h>
39
40struct alg {
41 int a;
42 const char *name;
43};
44static const struct alg aalgs[] = {

--- 17 unchanged lines hidden (view full) ---

62 { SADB_X_EALG_RIJNDAELCBC, "rijndael-cbc", },
63};
64static const struct alg ipcompalgs[] = {
65 { SADB_X_CALG_NONE, "none", },
66 { SADB_X_CALG_OUI, "oui", },
67 { SADB_X_CALG_DEFLATE, "deflate", },
68 { SADB_X_CALG_LZS, "lzs", },
69};
65#define N(a) (sizeof(a)/sizeof(a[0]))
66
67static const char*
68algname(int a, const struct alg algs[], int nalgs)
69{
70 static char buf[80];
71 int i;
72
73 for (i = 0; i < nalgs; i++)

--- 12 unchanged lines hidden (view full) ---

86#define STAT(x,fmt) if (x) printf(fmt "\n", (uintmax_t)x)
87 struct ipsecstat ips;
88 struct ahstat ahs;
89 struct espstat esps;
90 size_t slen;
91 int i;
92
93 slen = sizeof (ips);
70
71static const char*
72algname(int a, const struct alg algs[], int nalgs)
73{
74 static char buf[80];
75 int i;
76
77 for (i = 0; i < nalgs; i++)

--- 12 unchanged lines hidden (view full) ---

90#define STAT(x,fmt) if (x) printf(fmt "\n", (uintmax_t)x)
91 struct ipsecstat ips;
92 struct ahstat ahs;
93 struct espstat esps;
94 size_t slen;
95 int i;
96
97 slen = sizeof (ips);
94 if (sysctlbyname("net.inet.ipsec.ipsecstats", &ips, &slen, NULL, NULL) < 0)
98 if (sysctlbyname("net.inet.ipsec.ipsecstats", &ips, &slen, NULL, 0) < 0)
95 err(1, "net.inet.ipsec.ipsecstats");
96 slen = sizeof (ahs);
99 err(1, "net.inet.ipsec.ipsecstats");
100 slen = sizeof (ahs);
97 if (sysctlbyname("net.inet.ah.stats", &ahs, &slen, NULL, NULL) < 0)
101 if (sysctlbyname("net.inet.ah.stats", &ahs, &slen, NULL, 0) < 0)
98 err(1, "net.inet.ah.stats");
99 slen = sizeof (esps);
102 err(1, "net.inet.ah.stats");
103 slen = sizeof (esps);
100 if (sysctlbyname("net.inet.esp.stats", &esps, &slen, NULL, NULL) < 0)
104 if (sysctlbyname("net.inet.esp.stats", &esps, &slen, NULL, 0) < 0)
101 err(1, "net.inet.esp.stats");
102
103#define AHSTAT(x,fmt) if (x) printf("ah " fmt ": %ju\n", (uintmax_t)x)
104 AHSTAT(ahs.ahs_input, "input packets processed");
105 AHSTAT(ahs.ahs_output, "output packets processed");
106 AHSTAT(ahs.ahs_hdrops, "headers too short");
107 AHSTAT(ahs.ahs_nopf, "headers for unsupported address family");
108 AHSTAT(ahs.ahs_notdb, "packets with no SA");

--- 7 unchanged lines hidden (view full) ---

116 AHSTAT(ahs.ahs_invalid, "packets with an invalid SA");
117 AHSTAT(ahs.ahs_toobig, "packets too big");
118 AHSTAT(ahs.ahs_pdrops, "packets dropped due to policy");
119 AHSTAT(ahs.ahs_crypto, "failed crypto requests");
120 AHSTAT(ahs.ahs_tunnel, "tunnel sanity check failures");
121 for (i = 0; i < AH_ALG_MAX; i++)
122 if (ahs.ahs_hist[i])
123 printf("ah packets with %s: %ju\n"
105 err(1, "net.inet.esp.stats");
106
107#define AHSTAT(x,fmt) if (x) printf("ah " fmt ": %ju\n", (uintmax_t)x)
108 AHSTAT(ahs.ahs_input, "input packets processed");
109 AHSTAT(ahs.ahs_output, "output packets processed");
110 AHSTAT(ahs.ahs_hdrops, "headers too short");
111 AHSTAT(ahs.ahs_nopf, "headers for unsupported address family");
112 AHSTAT(ahs.ahs_notdb, "packets with no SA");

--- 7 unchanged lines hidden (view full) ---

120 AHSTAT(ahs.ahs_invalid, "packets with an invalid SA");
121 AHSTAT(ahs.ahs_toobig, "packets too big");
122 AHSTAT(ahs.ahs_pdrops, "packets dropped due to policy");
123 AHSTAT(ahs.ahs_crypto, "failed crypto requests");
124 AHSTAT(ahs.ahs_tunnel, "tunnel sanity check failures");
125 for (i = 0; i < AH_ALG_MAX; i++)
126 if (ahs.ahs_hist[i])
127 printf("ah packets with %s: %ju\n"
124 , algname(i, aalgs, N(aalgs))
128 , algname(i, aalgs, nitems(aalgs))
125 , (uintmax_t)ahs.ahs_hist[i]
126 );
127 AHSTAT(ahs.ahs_ibytes, "bytes received");
128 AHSTAT(ahs.ahs_obytes, "bytes transmitted");
129#undef AHSTAT
130
131#define ESPSTAT(x,fmt) if (x) printf("esp " fmt ": %ju\n", (uintmax_t)x)
132 ESPSTAT(esps.esps_input, "input packets processed");

--- 12 unchanged lines hidden (view full) ---

145 ESPSTAT(esps.esps_invalid, "packets with an invalid SA");
146 ESPSTAT(esps.esps_toobig, "packets too big");
147 ESPSTAT(esps.esps_pdrops, "packets dropped due to policy");
148 ESPSTAT(esps.esps_crypto, "failed crypto requests");
149 ESPSTAT(esps.esps_tunnel, "tunnel sanity check failures");
150 for (i = 0; i < ESP_ALG_MAX; i++)
151 if (esps.esps_hist[i])
152 printf("esp packets with %s: %ju\n"
129 , (uintmax_t)ahs.ahs_hist[i]
130 );
131 AHSTAT(ahs.ahs_ibytes, "bytes received");
132 AHSTAT(ahs.ahs_obytes, "bytes transmitted");
133#undef AHSTAT
134
135#define ESPSTAT(x,fmt) if (x) printf("esp " fmt ": %ju\n", (uintmax_t)x)
136 ESPSTAT(esps.esps_input, "input packets processed");

--- 12 unchanged lines hidden (view full) ---

149 ESPSTAT(esps.esps_invalid, "packets with an invalid SA");
150 ESPSTAT(esps.esps_toobig, "packets too big");
151 ESPSTAT(esps.esps_pdrops, "packets dropped due to policy");
152 ESPSTAT(esps.esps_crypto, "failed crypto requests");
153 ESPSTAT(esps.esps_tunnel, "tunnel sanity check failures");
154 for (i = 0; i < ESP_ALG_MAX; i++)
155 if (esps.esps_hist[i])
156 printf("esp packets with %s: %ju\n"
153 , algname(i, espalgs, N(espalgs))
157 , algname(i, espalgs, nitems(espalgs))
154 , (uintmax_t)esps.esps_hist[i]
155 );
156 ESPSTAT(esps.esps_ibytes, "bytes received");
157 ESPSTAT(esps.esps_obytes, "bytes transmitted");
158#undef ESPSTAT
159
160 printf("\n");
161 if (ips.ips_in_polvio+ips.ips_out_polvio)

--- 17 unchanged lines hidden ---
158 , (uintmax_t)esps.esps_hist[i]
159 );
160 ESPSTAT(esps.esps_ibytes, "bytes received");
161 ESPSTAT(esps.esps_obytes, "bytes transmitted");
162#undef ESPSTAT
163
164 printf("\n");
165 if (ips.ips_in_polvio+ips.ips_out_polvio)

--- 17 unchanged lines hidden ---