📄 icmp.c
字号:
/* * ICMP MIB group implementation - icmp.c * */#include <config.h>#if defined(IFNET_NEEDS_KERNEL) && !defined(_KERNEL)#define _KERNEL 1#define _I_DEFINED_KERNEL#endif#include <sys/types.h>#if HAVE_SYS_PARAM_H#include <sys/param.h>#endif#include <sys/socket.h>#if HAVE_STRING_H#include <string.h>#endif#if HAVE_STDLIB_H#include <stdlib.h>#endif#if TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# if HAVE_SYS_TIME_H# include <sys/time.h># else# include <time.h># endif#endif#if HAVE_NETINET_IN_H#include <netinet/in.h>#endif#if HAVE_SYS_SYSMP_H#include <sys/sysmp.h>#endif#if HAVE_SYS_TCPIPSTATS_H#include <sys/tcpipstats.h>#endif#include <net/if.h>#if HAVE_NET_IF_VAR_H#include <net/if_var.h>#endif#ifdef _I_DEFINED_KERNEL#undef _KERNEL#endif#if HAVE_NETINET_IN_SYSTM_H#include <netinet/in_systm.h>#endif#include <netinet/ip.h>#include <netinet/ip_icmp.h>#if HAVE_NETINET_ICMP_VAR_H#include <netinet/icmp_var.h>#endif#if HAVE_SYS_SYSCTL_H#include <sys/sysctl.h>#endif#if HAVE_INET_MIB2_H#include <inet/mib2.h>#endif#if HAVE_DMALLOC_H#include <dmalloc.h>#endif#ifdef solaris2#include "kernel_sunos5.h"#endif#include "system.h"#include "asn1.h"#include "snmp_debug.h"#include "mibincl.h"#include "auto_nlist.h"#ifdef hpux#include <sys/mib.h>#include <netinet/mib_kern.h>#endif /* hpux *//* #include "../common_header.h" */#include "icmp.h"#include "sysORTable.h" /********************* * * Kernel & interface information, * and internal forward declarations * *********************/#ifdef linuxstatic voidlinux_read_icmp_stat (struct icmp_mib *);#endif /********************* * * Initialisation & common implementation functions * *********************//* define the structure we're going to ask the agent to register our information at */struct variable2 icmp_variables[] = { {ICMPINMSGS, ASN_COUNTER, RONLY, var_icmp, 1, {1}}, {ICMPINERRORS, ASN_COUNTER, RONLY, var_icmp, 1, {2}}, {ICMPINDESTUNREACHS, ASN_COUNTER, RONLY, var_icmp, 1, {3}}, {ICMPINTIMEEXCDS, ASN_COUNTER, RONLY, var_icmp, 1, {4}}, {ICMPINPARMPROBS, ASN_COUNTER, RONLY, var_icmp, 1, {5}}, {ICMPINSRCQUENCHS, ASN_COUNTER, RONLY, var_icmp, 1, {6}}, {ICMPINREDIRECTS, ASN_COUNTER, RONLY, var_icmp, 1, {7}}, {ICMPINECHOS, ASN_COUNTER, RONLY, var_icmp, 1, {8}}, {ICMPINECHOREPS, ASN_COUNTER, RONLY, var_icmp, 1, {9}}, {ICMPINTIMESTAMPS, ASN_COUNTER, RONLY, var_icmp, 1, {10}}, {ICMPINTIMESTAMPREPS, ASN_COUNTER, RONLY, var_icmp, 1, {11}}, {ICMPINADDRMASKS, ASN_COUNTER, RONLY, var_icmp, 1, {12}}, {ICMPINADDRMASKREPS, ASN_COUNTER, RONLY, var_icmp, 1, {13}}, {ICMPOUTMSGS, ASN_COUNTER, RONLY, var_icmp, 1, {14}}, {ICMPOUTERRORS, ASN_COUNTER, RONLY, var_icmp, 1, {15}}, {ICMPOUTDESTUNREACHS, ASN_COUNTER, RONLY, var_icmp, 1, {16}}, {ICMPOUTTIMEEXCDS, ASN_COUNTER, RONLY, var_icmp, 1, {17}}, {ICMPOUTPARMPROBS, ASN_COUNTER, RONLY, var_icmp, 1, {18}}, {ICMPOUTSRCQUENCHS, ASN_COUNTER, RONLY, var_icmp, 1, {19}}, {ICMPOUTREDIRECTS, ASN_COUNTER, RONLY, var_icmp, 1, {20}}, {ICMPOUTECHOS, ASN_COUNTER, RONLY, var_icmp, 1, {21}}, {ICMPOUTECHOREPS, ASN_COUNTER, RONLY, var_icmp, 1, {22}}, {ICMPOUTTIMESTAMPS, ASN_COUNTER, RONLY, var_icmp, 1, {23}}, {ICMPOUTTIMESTAMPREPS, ASN_COUNTER, RONLY, var_icmp, 1, {24}}, {ICMPOUTADDRMASKS, ASN_COUNTER, RONLY, var_icmp, 1, {25}}, {ICMPOUTADDRMASKREPS, ASN_COUNTER, RONLY, var_icmp, 1, {26}}};/* Define the OID pointer to the top of the mib tree that we're registering underneath */oid icmp_variables_oid[] = { SNMP_OID_MIB2,5 };#ifdef USING_MIBII_IP_MODULEextern oid ip_module_oid[];extern int ip_module_oid_len;extern int ip_module_count;#endifvoid init_icmp(void){ /* register ourselves with the agent to handle our mib tree */ REGISTER_MIB("mibII/icmp", icmp_variables, variable2, icmp_variables_oid);#ifdef USING_MIBII_IP_MODULE if ( ++ip_module_count == 2 ) REGISTER_SYSOR_TABLE( ip_module_oid, ip_module_oid_len, "The MIB module for managing IP and ICMP implementations");#endif #ifdef ICMPSTAT_SYMBOL auto_nlist( ICMPSTAT_SYMBOL,0,0 );#endif}/* header_icmp(... Arguments: vp IN - pointer to variable entry that points here name IN/OUT - IN/name requested, OUT/name found length IN/OUT - length of IN/OUT oid's exact IN - TRUE if an exact match was requested var_len OUT - length of variable or 0 if function returned write_method */intheader_icmp(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method){#define ICMP_NAME_LENGTH 8 oid newname[MAX_OID_LEN]; int result; DEBUGMSGTL(("mibII/icmp", "var_icmp: ")); DEBUGMSGOID(("mibII/icmp", name, *length)); DEBUGMSG(("mibII/icmp"," %d\n", exact)); memcpy( (char *)newname,(char *)vp->name, (int)vp->namelen * sizeof(oid)); newname[ICMP_NAME_LENGTH] = 0; result = snmp_oid_compare(name, *length, newname, (int)vp->namelen + 1); if ((exact && (result != 0)) || (!exact && (result >= 0))) return(MATCH_FAILED); memcpy( (char *)name,(char *)newname, ((int)vp->namelen + 1) * sizeof(oid)); *length = vp->namelen + 1; *write_method = 0; *var_len = sizeof(long); /* default to 'long' results */ return(MATCH_SUCCEEDED);} /********************* * * System specific implementation functions * *********************/#ifndef solaris2#ifndef linux#if HAVE_SYS_TCPIPSTATS_Hu_char *var_icmp(struct variable *vp, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method){ register int i; static struct icmpstat icmpstat; static struct kna tcpipstats; if (header_icmp(vp, name, length, exact, var_len, write_method) == MATCH_FAILED ) return NULL; /* * Get the ICMP statistics from the kernel... */ if (sysmp (MP_SAGET, MPSA_TCPIPSTATS, &tcpipstats, sizeof tcpipstats) == -1) { snmp_log_perror ("sysmp(MP_SAGET)(MPSA_TCPIPSTATS)"); }#define icmpstat tcpipstats.icmpstat switch (vp->magic){ case ICMPINMSGS: long_return = icmpstat.icps_badcode + icmpstat.icps_tooshort + icmpstat.icps_checksum + icmpstat.icps_badlen; for (i=0; i <= ICMP_MAXTYPE; i++) long_return += icmpstat.icps_inhist[i]; return (u_char *)&long_return; case ICMPINERRORS: long_return = icmpstat.icps_badcode + icmpstat.icps_tooshort + icmpstat.icps_checksum + icmpstat.icps_badlen; return (u_char *)&long_return; case ICMPINDESTUNREACHS: long_return = icmpstat.icps_inhist[ICMP_UNREACH]; return (u_char *) &long_return; case ICMPINTIMEEXCDS: long_return = icmpstat.icps_inhist[ICMP_TIMXCEED]; return (u_char *) &long_return; case ICMPINPARMPROBS: long_return = icmpstat.icps_inhist[ICMP_PARAMPROB]; return (u_char *) &long_return; case ICMPINSRCQUENCHS: long_return = icmpstat.icps_inhist[ICMP_SOURCEQUENCH]; return (u_char *) &long_return; case ICMPINREDIRECTS: long_return = icmpstat.icps_inhist[ICMP_REDIRECT]; return (u_char *) &long_return; case ICMPINECHOS: long_return = icmpstat.icps_inhist[ICMP_ECHO]; return (u_char *) &long_return; case ICMPINECHOREPS: long_return = icmpstat.icps_inhist[ICMP_ECHOREPLY]; return (u_char *) &long_return; case ICMPINTIMESTAMPS: long_return = icmpstat.icps_inhist[ICMP_TSTAMP]; return (u_char *) &long_return; case ICMPINTIMESTAMPREPS: long_return = icmpstat.icps_inhist[ICMP_TSTAMPREPLY]; return (u_char *) &long_return; case ICMPINADDRMASKS: long_return = icmpstat.icps_inhist[ICMP_MASKREQ]; return (u_char *) &long_return; case ICMPINADDRMASKREPS: long_return = icmpstat.icps_inhist[ICMP_MASKREPLY]; return (u_char *) &long_return; case ICMPOUTMSGS: long_return = icmpstat.icps_oldshort + icmpstat.icps_oldicmp; for (i=0; i <= ICMP_MAXTYPE; i++) long_return += icmpstat.icps_outhist[i]; return (u_char *)&long_return; case ICMPOUTERRORS: long_return = icmpstat.icps_oldshort + icmpstat.icps_oldicmp; return (u_char *)&long_return; case ICMPOUTDESTUNREACHS: long_return = icmpstat.icps_outhist[ICMP_UNREACH]; return (u_char *) &long_return; case ICMPOUTTIMEEXCDS: long_return = icmpstat.icps_outhist[ICMP_TIMXCEED]; return (u_char *) &long_return; case ICMPOUTPARMPROBS: long_return = icmpstat.icps_outhist[ICMP_PARAMPROB]; return (u_char *) &long_return; case ICMPOUTSRCQUENCHS: long_return = icmpstat.icps_outhist[ICMP_SOURCEQUENCH]; return (u_char *) &long_return; case ICMPOUTREDIRECTS: long_return = icmpstat.icps_outhist[ICMP_REDIRECT]; return (u_char *) &long_return; case ICMPOUTECHOS: long_return = icmpstat.icps_outhist[ICMP_ECHO]; return (u_char *) &long_return; case ICMPOUTECHOREPS: long_return = icmpstat.icps_outhist[ICMP_ECHOREPLY]; return (u_char *) &long_return; case ICMPOUTTIMESTAMPS: long_return = icmpstat.icps_outhist[ICMP_TSTAMP]; return (u_char *) &long_return; case ICMPOUTTIMESTAMPREPS: long_return = icmpstat.icps_outhist[ICMP_TSTAMPREPLY]; return (u_char *) &long_return; case ICMPOUTADDRMASKS: long_return = icmpstat.icps_outhist[ICMP_MASKREQ]; return (u_char *) &long_return; case ICMPOUTADDRMASKREPS: long_return = icmpstat.icps_outhist[ICMP_MASKREPLY]; return (u_char *) &long_return; default: DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_icmp\n", vp->magic)); } return NULL;}#else /* not HAVE_SYS_TCPIPSTATS_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -