| 1 |
/* |
| 2 |
* sysctl interface for icmp stats for others than NetBSD |
| 3 |
*/ |
| 4 |
|
| 5 |
#include <sys/param.h> |
| 6 |
#include <sys/sysctl.h> |
| 7 |
#include <sys/protosw.h> |
| 8 |
|
| 9 |
#include <netinet/in.h> |
| 10 |
#include <netinet/in_systm.h> |
| 11 |
#include <netinet/ip.h> |
| 12 |
#include <netinet/ip_icmp.h> |
| 13 |
#include <netinet/ip_var.h> |
| 14 |
#include <netinet/icmp_var.h> |
| 15 |
#include <netinet/icmp6.h> |
| 16 |
|
| 17 |
#include <net-snmp/net-snmp-config.h> |
| 18 |
#include <net-snmp/net-snmp-includes.h> |
| 19 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 20 |
|
| 21 |
#include "kernel_sysctl.h" |
| 22 |
|
| 23 |
#ifndef MLD_LISTENER_QUERY |
| 24 |
#define MLD_LISTENER_QUERY MLD6_LISTENER_QUERY |
| 25 |
#endif |
| 26 |
#ifndef MLD_LISTENER_REPORT |
| 27 |
#define MLD_LISTENER_REPORT MLD6_LISTENER_REPORT |
| 28 |
#endif |
| 29 |
#ifndef MLD_LISTENER_DONE |
| 30 |
#define MLD_LISTENER_DONE MLD6_LISTENER_DONE |
| 31 |
#endif |
| 32 |
|
| 33 |
#if defined(NETSNMP_CAN_USE_SYSCTL) |
| 34 |
|
| 35 |
int |
| 36 |
sysctl_read_icmp_stat(struct icmp_mib *mib) |
| 37 |
{ |
| 38 |
struct icmpstat icmpstat; |
| 39 |
size_t size = sizeof(icmpstat); |
| 40 |
int i; |
| 41 |
static int sname[4] = |
| 42 |
{ CTL_NET, PF_INET, IPPROTO_ICMP, ICMPCTL_STATS }; |
| 43 |
|
| 44 |
(void)memset(mib, 0, sizeof(*mib)); |
| 45 |
|
| 46 |
if (-1 == sysctl(sname, 4, &icmpstat, &size, NULL, 0)) { |
| 47 |
snmp_perror("sysctl_read_icmp_stat: net.inet.icmp.stats"); |
| 48 |
return -1; |
| 49 |
} |
| 50 |
|
| 51 |
mib->icmpInMsgs = icmpstat.icps_badcode |
| 52 |
+ icmpstat.icps_tooshort |
| 53 |
+ icmpstat.icps_checksum |
| 54 |
+ icmpstat.icps_badlen; |
| 55 |
mib->icmpInErrors = mib->icmpInMsgs; |
| 56 |
for (i = 0; i <= ICMP_MAXTYPE; i++) |
| 57 |
mib->icmpInMsgs += icmpstat.icps_inhist[i]; |
| 58 |
mib->icmpInDestUnreachs = icmpstat.icps_inhist[ICMP_UNREACH]; |
| 59 |
mib->icmpInTimeExcds = icmpstat.icps_inhist[ICMP_TIMXCEED]; |
| 60 |
mib->icmpInParmProbs = icmpstat.icps_inhist[ICMP_PARAMPROB]; |
| 61 |
mib->icmpInSrcQuenchs = icmpstat.icps_inhist[ICMP_SOURCEQUENCH]; |
| 62 |
mib->icmpInRedirects = icmpstat.icps_inhist[ICMP_REDIRECT]; |
| 63 |
mib->icmpInEchos = icmpstat.icps_inhist[ICMP_ECHO]; |
| 64 |
mib->icmpInEchoReps = icmpstat.icps_inhist[ICMP_ECHOREPLY]; |
| 65 |
mib->icmpInTimestamps = icmpstat.icps_inhist[ICMP_TSTAMP]; |
| 66 |
mib->icmpInTimestampReps = icmpstat.icps_inhist[ICMP_TSTAMPREPLY]; |
| 67 |
mib->icmpInAddrMasks = icmpstat.icps_inhist[ICMP_MASKREQ]; |
| 68 |
mib->icmpInAddrMaskReps = icmpstat.icps_inhist[ICMP_MASKREPLY]; |
| 69 |
mib->icmpOutMsgs = icmpstat.icps_oldshort + icmpstat.icps_oldicmp; |
| 70 |
for (i = 0; i <= ICMP_MAXTYPE; i++) |
| 71 |
mib->icmpOutMsgs += icmpstat.icps_outhist[i]; |
| 72 |
mib->icmpOutErrors = icmpstat.icps_oldshort + icmpstat.icps_oldicmp; |
| 73 |
mib->icmpOutDestUnreachs = icmpstat.icps_outhist[ICMP_UNREACH]; |
| 74 |
mib->icmpOutTimeExcds = icmpstat.icps_outhist[ICMP_TIMXCEED]; |
| 75 |
mib->icmpOutParmProbs = icmpstat.icps_outhist[ICMP_PARAMPROB]; |
| 76 |
mib->icmpOutSrcQuenchs = icmpstat.icps_outhist[ICMP_SOURCEQUENCH]; |
| 77 |
mib->icmpOutRedirects = icmpstat.icps_outhist[ICMP_REDIRECT]; |
| 78 |
mib->icmpOutEchos = icmpstat.icps_outhist[ICMP_ECHO]; |
| 79 |
mib->icmpOutEchoReps = icmpstat.icps_outhist[ICMP_ECHOREPLY]; |
| 80 |
mib->icmpOutTimestamps = icmpstat.icps_outhist[ICMP_TSTAMP]; |
| 81 |
mib->icmpOutTimestampReps = icmpstat.icps_outhist[ICMP_TSTAMPREPLY]; |
| 82 |
mib->icmpOutAddrMasks = icmpstat.icps_outhist[ICMP_MASKREQ]; |
| 83 |
mib->icmpOutAddrMaskReps = icmpstat.icps_outhist[ICMP_MASKREPLY]; |
| 84 |
|
| 85 |
return 0; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
int |
| 90 |
sysctl_read_icmp6_stat(struct icmp6_mib *mib) |
| 91 |
{ |
| 92 |
struct icmp6stat icmpstat; |
| 93 |
size_t size = sizeof(icmpstat); |
| 94 |
int i; |
| 95 |
static int sname[4] = |
| 96 |
{ CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_STATS }; |
| 97 |
|
| 98 |
(void)memset(mib, 0, sizeof(*mib)); |
| 99 |
|
| 100 |
if (-1 == sysctl(sname, 4, &icmpstat, &size, NULL, 0)) { |
| 101 |
snmp_perror("sysctl_read_icmp6_stat: net.inet6.icmp6.stats"); |
| 102 |
return -1; |
| 103 |
} |
| 104 |
|
| 105 |
mib->icmp6InMsgs = icmpstat.icp6s_badcode |
| 106 |
+ icmpstat.icp6s_tooshort |
| 107 |
+ icmpstat.icp6s_checksum |
| 108 |
+ icmpstat.icp6s_badlen; |
| 109 |
mib->icmp6InErrors = mib->icmp6InMsgs; |
| 110 |
for (i = 0; i <= ICMP6_MAXTYPE; i++) |
| 111 |
mib->icmp6InMsgs += icmpstat.icp6s_inhist[i]; |
| 112 |
mib->icmp6InDestUnreachs = icmpstat.icp6s_inhist[ICMP6_DST_UNREACH]; |
| 113 |
mib->icmp6InPktTooBigs = icmpstat.icp6s_inhist[ICMP6_PACKET_TOO_BIG]; |
| 114 |
mib->icmp6InTimeExcds = icmpstat.icp6s_inhist[ICMP6_TIME_EXCEEDED]; |
| 115 |
mib->icmp6InParmProblems = icmpstat.icp6s_inhist[ICMP6_PARAM_PROB]; |
| 116 |
mib->icmp6InEchos = icmpstat.icp6s_inhist[ICMP6_ECHO_REQUEST]; |
| 117 |
mib->icmp6InEchoReplies = icmpstat.icp6s_inhist[ICMP6_ECHO_REPLY]; |
| 118 |
mib->icmp6InGroupMembQueries = icmpstat.icp6s_inhist[MLD_LISTENER_QUERY]; |
| 119 |
mib->icmp6InGroupMembResponses = icmpstat.icp6s_inhist[MLD_LISTENER_REPORT]; |
| 120 |
mib->icmp6InRouterSolicits = icmpstat.icp6s_inhist[ND_ROUTER_SOLICIT]; |
| 121 |
mib->icmp6InRouterAdvertisements = icmpstat.icp6s_inhist[ND_ROUTER_ADVERT]; |
| 122 |
mib->icmp6InNeighborSolicits = icmpstat.icp6s_inhist[ND_NEIGHBOR_SOLICIT]; |
| 123 |
mib->icmp6InNeighborAdvertisements = icmpstat.icp6s_inhist[ND_NEIGHBOR_ADVERT]; |
| 124 |
mib->icmp6InRedirects = icmpstat.icp6s_inhist[ND_REDIRECT]; |
| 125 |
|
| 126 |
mib->icmp6OutMsgs = icmpstat.icp6s_canterror |
| 127 |
+ icmpstat.icp6s_toofreq; |
| 128 |
for (i = 0; i <= ICMP6_MAXTYPE; i++) |
| 129 |
mib->icmp6OutMsgs += icmpstat.icp6s_outhist[i]; |
| 130 |
mib->icmp6OutDestUnreachs = icmpstat.icp6s_outhist[ICMP6_DST_UNREACH]; |
| 131 |
mib->icmp6OutPktTooBigs = icmpstat.icp6s_outhist[ICMP6_PACKET_TOO_BIG]; |
| 132 |
mib->icmp6OutTimeExcds = icmpstat.icp6s_outhist[ICMP6_TIME_EXCEEDED]; |
| 133 |
mib->icmp6OutParmProblems = icmpstat.icp6s_outhist[ICMP6_PARAM_PROB]; |
| 134 |
mib->icmp6OutEchos = icmpstat.icp6s_outhist[ICMP6_ECHO_REQUEST]; |
| 135 |
mib->icmp6OutEchoReplies = icmpstat.icp6s_outhist[ICMP6_ECHO_REPLY]; |
| 136 |
mib->icmp6OutRouterSolicits = icmpstat.icp6s_outhist[ND_ROUTER_SOLICIT]; |
| 137 |
mib->icmp6OutNeighborSolicits = icmpstat.icp6s_outhist[ND_NEIGHBOR_SOLICIT]; |
| 138 |
mib->icmp6OutNeighborAdvertisements = icmpstat.icp6s_outhist[ND_NEIGHBOR_ADVERT]; |
| 139 |
mib->icmp6OutRedirects = icmpstat.icp6s_outhist[ND_REDIRECT]; |
| 140 |
mib->icmp6OutGroupMembResponses = icmpstat.icp6s_outhist[MLD_LISTENER_REPORT]; |
| 141 |
mib->icmp6OutGroupMembReductions = icmpstat.icp6s_outhist[MLD_LISTENER_DONE]; |
| 142 |
|
| 143 |
return 0; |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
int |
| 148 |
sysctl_read_icmp_msg_stat(struct icmp_mib *mib, |
| 149 |
struct icmp4_msg_mib *msgmib, |
| 150 |
int *flag) |
| 151 |
{ |
| 152 |
sysctl_read_icmp_stat(mib); |
| 153 |
*flag = 0; |
| 154 |
return 0; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
int |
| 159 |
sysctl_read_icmp6_msg_stat(struct icmp6_mib *mib, |
| 160 |
struct icmp6_msg_mib *msgmib, |
| 161 |
int *support) |
| 162 |
{ |
| 163 |
struct icmp6stat icmpstat; |
| 164 |
size_t size = sizeof(icmpstat); |
| 165 |
int i; |
| 166 |
static int sname[4] = |
| 167 |
{ CTL_NET, PF_INET6, IPPROTO_ICMPV6, ICMPV6CTL_STATS }; |
| 168 |
|
| 169 |
sysctl_read_icmp6_stat(mib); |
| 170 |
|
| 171 |
if (-1 == sysctl(sname, 4, &icmpstat, &size, NULL, 0)) { |
| 172 |
snmp_perror("sysctl_read_icmp6_stat: net.inet6.icmp6.stats"); |
| 173 |
return -1; |
| 174 |
} |
| 175 |
|
| 176 |
for (i = 0; i < 256; i++) { |
| 177 |
msgmib->vals[i].InType = icmpstat.icp6s_inhist[i]; |
| 178 |
msgmib->vals[i].OutType = icmpstat.icp6s_outhist[i]; |
| 179 |
} |
| 180 |
*support = 1; |
| 181 |
return 0; |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
#endif |