1 //==========================================================================
3 // snmp/snmpagent/current/src/mibgroup/mibII/icmp.c
6 //==========================================================================
7 //####ECOSGPLCOPYRIGHTBEGIN####
8 // -------------------------------------------
9 // This file is part of eCos, the Embedded Configurable Operating System.
10 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
12 // eCos is free software; you can redistribute it and/or modify it under
13 // the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 2 or (at your option) any later version.
16 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
17 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 // You should have received a copy of the GNU General Public License along
22 // with eCos; if not, write to the Free Software Foundation, Inc.,
23 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
25 // As a special exception, if other files instantiate templates or use macros
26 // or inline functions from this file, or you compile this file and link it
27 // with other works to produce a work based on this file, this file does not
28 // by itself cause the resulting work to be covered by the GNU General Public
29 // License. However the source code for this file must still be made available
30 // in accordance with section (3) of the GNU General Public License.
32 // This exception does not invalidate any other reasons why a work based on
33 // this file might be covered by the GNU General Public License.
35 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
36 // at http://sources.redhat.com/ecos/ecos-license/
37 // -------------------------------------------
38 //####ECOSGPLCOPYRIGHTEND####
39 //####UCDSNMPCOPYRIGHTBEGIN####
41 // -------------------------------------------
43 // Portions of this software may have been derived from the UCD-SNMP
44 // project, <http://ucd-snmp.ucdavis.edu/> from the University of
45 // California at Davis, which was originally based on the Carnegie Mellon
46 // University SNMP implementation. Portions of this software are therefore
47 // covered by the appropriate copyright disclaimers included herein.
49 // The release used was version 4.1.2 of May 2000. "ucd-snmp-4.1.2"
50 // -------------------------------------------
52 //####UCDSNMPCOPYRIGHTEND####
53 //==========================================================================
54 //#####DESCRIPTIONBEGIN####
59 // Purpose: Port of UCD-SNMP distribution to eCos.
63 //####DESCRIPTIONEND####
65 //==========================================================================
66 /********************************************************************
67 Copyright 1989, 1991, 1992 by Carnegie Mellon University
70 Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
74 Permission to use, copy, modify and distribute this software and its
75 documentation for any purpose and without fee is hereby granted,
76 provided that the above copyright notice appears in all copies and
77 that both that copyright notice and this permission notice appear in
78 supporting documentation, and that the name of CMU and The Regents of
79 the University of California not be used in advertising or publicity
80 pertaining to distribution of the software without specific written
83 CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
84 WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
85 WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL CMU OR
86 THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
87 INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
88 FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
89 CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
90 CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91 *********************************************************************/
92 /* This file was generated by mib2c and is intended for use as a mib module
93 for the ucd-snmp snmpd agent. */
96 /* This should always be included first before anything else */
100 /* minimal include directives */
102 #include "mibgroup/util_funcs.h"
103 #include "mibgroup/mibII/icmp.h"
107 #include <netinet/ip_icmp.h>
108 #include <netinet/icmp_var.h>
111 * icmp_variables_oid:
112 * this is the top level oid that we want to register under. This
113 * is essentially a prefix, with the suffix appearing in the
118 oid icmp_variables_oid[] = { 1,3,6,1,2,1,5 };
122 * variable2 icmp_variables:
123 * this variable defines function callbacks and type return information
124 * for the icmp mib section
128 struct variable2 icmp_variables[] = {
129 /* magic number , variable type , ro/rw , callback fn , L, oidsuffix */
131 { ICMPINMSGS , ASN_COUNTER , RONLY , var_icmp, 1, { 1 } },
132 #define ICMPINERRORS 2
133 { ICMPINERRORS , ASN_COUNTER , RONLY , var_icmp, 1, { 2 } },
134 #define ICMPINDESTUNREACHS 3
135 { ICMPINDESTUNREACHS , ASN_COUNTER , RONLY , var_icmp, 1, { 3 } },
136 #define ICMPINTIMEEXCDS 4
137 { ICMPINTIMEEXCDS , ASN_COUNTER , RONLY , var_icmp, 1, { 4 } },
138 #define ICMPINPARMPROBS 5
139 { ICMPINPARMPROBS , ASN_COUNTER , RONLY , var_icmp, 1, { 5 } },
140 #define ICMPINSRCQUENCHS 6
141 { ICMPINSRCQUENCHS , ASN_COUNTER , RONLY , var_icmp, 1, { 6 } },
142 #define ICMPINREDIRECTS 7
143 { ICMPINREDIRECTS , ASN_COUNTER , RONLY , var_icmp, 1, { 7 } },
144 #define ICMPINECHOS 8
145 { ICMPINECHOS , ASN_COUNTER , RONLY , var_icmp, 1, { 8 } },
146 #define ICMPINECHOREPS 9
147 { ICMPINECHOREPS , ASN_COUNTER , RONLY , var_icmp, 1, { 9 } },
148 #define ICMPINTIMESTAMPS 10
149 { ICMPINTIMESTAMPS , ASN_COUNTER , RONLY , var_icmp, 1, { 10 } },
150 #define ICMPINTIMESTAMPREPS 11
151 { ICMPINTIMESTAMPREPS , ASN_COUNTER , RONLY , var_icmp, 1, { 11 } },
152 #define ICMPINADDRMASKS 12
153 { ICMPINADDRMASKS , ASN_COUNTER , RONLY , var_icmp, 1, { 12 } },
154 #define ICMPINADDRMASKREPS 13
155 { ICMPINADDRMASKREPS , ASN_COUNTER , RONLY , var_icmp, 1, { 13 } },
156 #define ICMPOUTMSGS 14
157 { ICMPOUTMSGS , ASN_COUNTER , RONLY , var_icmp, 1, { 14 } },
158 #define ICMPOUTERRORS 15
159 { ICMPOUTERRORS , ASN_COUNTER , RONLY , var_icmp, 1, { 15 } },
160 #define ICMPOUTDESTUNREACHS 16
161 { ICMPOUTDESTUNREACHS , ASN_COUNTER , RONLY , var_icmp, 1, { 16 } },
162 #define ICMPOUTTIMEEXCDS 17
163 { ICMPOUTTIMEEXCDS , ASN_COUNTER , RONLY , var_icmp, 1, { 17 } },
164 #define ICMPOUTPARMPROBS 18
165 { ICMPOUTPARMPROBS , ASN_COUNTER , RONLY , var_icmp, 1, { 18 } },
166 #define ICMPOUTSRCQUENCHS 19
167 { ICMPOUTSRCQUENCHS , ASN_COUNTER , RONLY , var_icmp, 1, { 19 } },
168 #define ICMPOUTREDIRECTS 20
169 { ICMPOUTREDIRECTS , ASN_COUNTER , RONLY , var_icmp, 1, { 20 } },
170 #define ICMPOUTECHOS 21
171 { ICMPOUTECHOS , ASN_COUNTER , RONLY , var_icmp, 1, { 21 } },
172 #define ICMPOUTECHOREPS 22
173 { ICMPOUTECHOREPS , ASN_COUNTER , RONLY , var_icmp, 1, { 22 } },
174 #define ICMPOUTTIMESTAMPS 23
175 { ICMPOUTTIMESTAMPS , ASN_COUNTER , RONLY , var_icmp, 1, { 23 } },
176 #define ICMPOUTTIMESTAMPREPS 24
177 { ICMPOUTTIMESTAMPREPS, ASN_COUNTER , RONLY , var_icmp, 1, { 24 } },
178 #define ICMPOUTADDRMASKS 25
179 { ICMPOUTADDRMASKS , ASN_COUNTER , RONLY , var_icmp, 1, { 25 } },
180 #define ICMPOUTADDRMASKREPS 26
181 { ICMPOUTADDRMASKREPS , ASN_COUNTER , RONLY , var_icmp, 1, { 26 } },
184 /* (L = length of the oidsuffix) */
189 * Initialization routine. This is called when the agent starts up.
190 * At a minimum, registration of your variables should take place here.
192 void init_icmp(void) {
195 /* register ourselves with the agent to handle our mib tree */
196 REGISTER_MIB("icmp", icmp_variables, variable2,
200 /* place any other initialization junk you need here */
206 * This function is called every time the agent gets a request for
207 * a scalar variable that might be found within your mib section
208 * registered above. It is up to you to do the right thing and
209 * return the correct value.
210 * You should also correct the value of "var_len" if necessary.
212 * Please see the documentation for more information about writing
213 * module extensions, and check out the examples in the examples
214 * and mibII directories.
217 var_icmp(struct variable *vp,
222 WriteMethod **write_method)
224 /* variables we may use later */
225 static long long_ret;
228 if (header_generic(vp,name,length,exact,var_len,write_method)
234 long_ret = icmpstat.icps_badcode + icmpstat.icps_tooshort +
235 icmpstat.icps_checksum + icmpstat.icps_badlen;
236 for (i=0; i <= ICMP_MAXTYPE; i++)
237 long_ret += icmpstat.icps_inhist[i];
238 return (u_char *)&long_ret;
240 long_ret = icmpstat.icps_badcode + icmpstat.icps_tooshort +
241 icmpstat.icps_checksum + icmpstat.icps_badlen;
242 return (u_char *)&long_ret;
243 case ICMPINDESTUNREACHS:
244 long_ret = icmpstat.icps_inhist[ICMP_UNREACH];
245 return (u_char *) &long_ret;
246 case ICMPINTIMEEXCDS:
247 long_ret = icmpstat.icps_inhist[ICMP_TIMXCEED];
248 return (u_char *) &long_ret;
249 case ICMPINPARMPROBS:
250 long_ret = icmpstat.icps_inhist[ICMP_PARAMPROB];
251 return (u_char *) &long_ret;
252 case ICMPINSRCQUENCHS:
253 long_ret = icmpstat.icps_inhist[ICMP_SOURCEQUENCH];
254 return (u_char *) &long_ret;
255 case ICMPINREDIRECTS:
256 long_ret = icmpstat.icps_inhist[ICMP_REDIRECT];
257 return (u_char *) &long_ret;
259 long_ret = icmpstat.icps_inhist[ICMP_ECHO];
260 return (u_char *) &long_ret;
262 long_ret = icmpstat.icps_inhist[ICMP_ECHOREPLY];
263 return (u_char *) &long_ret;
264 case ICMPINTIMESTAMPS:
265 long_ret = icmpstat.icps_inhist[ICMP_TSTAMP];
266 return (u_char *) &long_ret;
267 case ICMPINTIMESTAMPREPS:
268 long_ret = icmpstat.icps_inhist[ICMP_TSTAMPREPLY];
269 return (u_char *) &long_ret;
270 case ICMPINADDRMASKS:
271 long_ret = icmpstat.icps_inhist[ICMP_MASKREQ];
272 return (u_char *) &long_ret;
273 case ICMPINADDRMASKREPS:
274 long_ret = icmpstat.icps_inhist[ICMP_MASKREPLY];
275 return (u_char *) &long_ret;
277 long_ret = icmpstat.icps_oldshort + icmpstat.icps_oldicmp;
278 for (i=0; i <= ICMP_MAXTYPE; i++)
279 long_ret += icmpstat.icps_outhist[i];
280 return (u_char *)&long_ret;
282 long_ret = icmpstat.icps_oldshort + icmpstat.icps_oldicmp;
283 return (u_char *)&long_ret;
284 case ICMPOUTDESTUNREACHS:
285 long_ret = icmpstat.icps_outhist[ICMP_UNREACH];
286 return (u_char *) &long_ret;
287 case ICMPOUTTIMEEXCDS:
288 long_ret = icmpstat.icps_outhist[ICMP_TIMXCEED];
289 return (u_char *) &long_ret;
290 case ICMPOUTPARMPROBS:
291 long_ret = icmpstat.icps_outhist[ICMP_PARAMPROB];
292 return (u_char *) &long_ret;
293 case ICMPOUTSRCQUENCHS:
294 long_ret = icmpstat.icps_outhist[ICMP_SOURCEQUENCH];
295 return (u_char *) &long_ret;
296 case ICMPOUTREDIRECTS:
297 long_ret = icmpstat.icps_outhist[ICMP_REDIRECT];
298 return (u_char *) &long_ret;
300 long_ret = icmpstat.icps_outhist[ICMP_ECHO];
301 return (u_char *) &long_ret;
302 case ICMPOUTECHOREPS:
303 long_ret = icmpstat.icps_outhist[ICMP_ECHOREPLY];
304 return (u_char *) &long_ret;
305 case ICMPOUTTIMESTAMPS:
306 long_ret = icmpstat.icps_outhist[ICMP_TSTAMP];
307 return (u_char *) &long_ret;
308 case ICMPOUTTIMESTAMPREPS:
309 long_ret = icmpstat.icps_outhist[ICMP_TSTAMPREPLY];
310 return (u_char *) &long_ret;
311 case ICMPOUTADDRMASKS:
312 long_ret = icmpstat.icps_outhist[ICMP_MASKREQ];
313 return (u_char *) &long_ret;
314 case ICMPOUTADDRMASKREPS:
315 long_ret = icmpstat.icps_outhist[ICMP_MASKREPLY];
316 return (u_char *) &long_ret;
318 DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_icmp\n", vp->magic));