#ifdef INET6
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <netinet/in.h>
#include <netinet/icmp6.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include <paths.h>
#include "systat.h"
#include "extern.h"
#include "mode.h"
static struct icmp6stat icmp6stat, initstat, oldstat;
WINDOW *
openicmp6(void)
{
return (subwin(stdscr, LINES-3-1, 0, MAINWIN_ROW, 0));
}
void
closeicmp6(WINDOW *w)
{
if (w == NULL)
return;
wclear(w);
wrefresh(w);
delwin(w);
}
void
labelicmp6(void)
{
wmove(wnd, 0, 0); wclrtoeol(wnd);
#define L(row, str) mvwprintw(wnd, row, 10, str)
#define R(row, str) mvwprintw(wnd, row, 45, str);
L(0, "ICMPv6 Input"); R(0, "ICMPv6 Output");
L(1, "total messages"); R(1, "total messages");
L(2, "with bad code"); R(2, "errors generated");
L(3, "with bad length"); R(3, "suppressed - original too short");
L(4, "with bad checksum"); R(4, "suppressed - original was ICMP");
L(5, "with insufficient data"); R(5, "responses sent");
L(7, "Input Histogram"); R(7, "Output Histogram");
#define B(row, str) L(row, str); R(row, str)
B(8, "echo response");
B(9, "echo request");
B(10, "destination unreachable");
B(11, "redirect");
B(12, "time-to-live exceeded");
B(13, "parameter problem");
B(14, "neighbor solicitation");
B(15, "neighbor advertisement");
L(16, "router advertisement"); R(16, "router solicitation");
#undef L
#undef R
#undef B
}
static void
domode(struct icmp6stat *ret)
{
const struct icmp6stat *sub;
int i, divisor = 1;
switch(currentmode) {
case display_RATE:
sub = &oldstat;
divisor = (delay > 1000000) ? delay / 1000000 : 1;
break;
case display_DELTA:
sub = &oldstat;
break;
case display_SINCE:
sub = &initstat;
break;
default:
*ret = icmp6stat;
return;
}
#define DO(stat) ret->stat = (icmp6stat.stat - sub->stat) / divisor
DO(icp6s_error);
DO(icp6s_tooshort);
DO(icp6s_canterror);
for (i = 0; i <= ICMP6_MAXTYPE; i++) {
DO(icp6s_outhist[i]);
}
DO(icp6s_badcode);
DO(icp6s_tooshort);
DO(icp6s_checksum);
DO(icp6s_badlen);
DO(icp6s_reflect);
for (i = 0; i <= ICMP6_MAXTYPE; i++) {
DO(icp6s_inhist[i]);
}
#undef DO
}
void
showicmp6(void)
{
struct icmp6stat stats;
uint64_t totalin, totalout;
int i;
memset(&stats, 0, sizeof stats);
domode(&stats);
for (i = totalin = totalout = 0; i <= ICMP6_MAXTYPE; i++) {
totalin += stats.icp6s_inhist[i];
totalout += stats.icp6s_outhist[i];
}
totalin += stats.icp6s_badcode + stats.icp6s_badlen +
stats.icp6s_checksum + stats.icp6s_tooshort;
mvwprintw(wnd, 1, 0, "%9"PRIu64, totalin);
mvwprintw(wnd, 1, 35, "%9"PRIu64, totalout);
#define DO(stat, row, col) \
mvwprintw(wnd, row, col, "%9"PRIu64, stats.stat)
DO(icp6s_badcode, 2, 0);
DO(icp6s_badlen, 3, 0);
DO(icp6s_checksum, 4, 0);
DO(icp6s_tooshort, 5, 0);
DO(icp6s_error, 2, 35);
DO(icp6s_tooshort, 3, 35);
DO(icp6s_canterror, 4, 35);
DO(icp6s_reflect, 5, 35);
#define DO2(type, row) DO(icp6s_inhist[type], row, 0); DO(icp6s_outhist[type], \
row, 35)
DO2(ICMP6_ECHO_REPLY, 8);
DO2(ICMP6_ECHO_REQUEST, 9);
DO2(ICMP6_DST_UNREACH, 10);
DO2(ND_REDIRECT, 11);
DO2(ICMP6_TIME_EXCEEDED, 12);
DO2(ICMP6_PARAM_PROB, 13);
DO2(ND_NEIGHBOR_SOLICIT, 14);
DO2(ND_NEIGHBOR_ADVERT, 15);
DO(icp6s_inhist[ND_ROUTER_SOLICIT], 16, 0);
DO(icp6s_outhist[ND_ROUTER_ADVERT], 16, 35);
#undef DO
#undef DO2
}
int
initicmp6(void)
{
size_t len;
int name[4];
name[0] = CTL_NET;
name[1] = PF_INET6;
name[2] = IPPROTO_ICMPV6;
name[3] = ICMPV6CTL_STATS;
len = 0;
if (sysctl(name, 4, 0, &len, 0, 0) < 0) {
error("sysctl getting icmp6stat size failed");
return 0;
}
if (len > sizeof icmp6stat) {
error("icmp6stat structure has grown--recompile systat!");
return 0;
}
if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) {
error("sysctl getting icmp6stat size failed");
return 0;
}
oldstat = initstat;
return 1;
}
void
reseticmp6(void)
{
size_t len;
int name[4];
name[0] = CTL_NET;
name[1] = PF_INET6;
name[2] = IPPROTO_ICMPV6;
name[3] = ICMPV6CTL_STATS;
len = sizeof initstat;
if (sysctl(name, 4, &initstat, &len, 0, 0) < 0) {
error("sysctl getting icmp6stat size failed");
}
oldstat = initstat;
}
void
fetchicmp6(void)
{
int name[4];
size_t len;
oldstat = icmp6stat;
name[0] = CTL_NET;
name[1] = PF_INET6;
name[2] = IPPROTO_ICMPV6;
name[3] = ICMPV6CTL_STATS;
len = sizeof icmp6stat;
if (sysctl(name, 4, &icmp6stat, &len, 0, 0) < 0)
return;
}
#endif