1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// ./agent/current/src/mibgroup/mibII/snmp_mib.c
|
4 |
|
|
//
|
5 |
|
|
//
|
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.
|
11 |
|
|
//
|
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.
|
15 |
|
|
//
|
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
|
19 |
|
|
// for more details.
|
20 |
|
|
//
|
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.
|
24 |
|
|
//
|
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.
|
31 |
|
|
//
|
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.
|
34 |
|
|
//
|
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####
|
40 |
|
|
//
|
41 |
|
|
// -------------------------------------------
|
42 |
|
|
//
|
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.
|
48 |
|
|
//
|
49 |
|
|
// The release used was version 4.1.2 of May 2000. "ucd-snmp-4.1.2"
|
50 |
|
|
// -------------------------------------------
|
51 |
|
|
//
|
52 |
|
|
//####UCDSNMPCOPYRIGHTEND####
|
53 |
|
|
//==========================================================================
|
54 |
|
|
//#####DESCRIPTIONBEGIN####
|
55 |
|
|
//
|
56 |
|
|
// Author(s): hmt
|
57 |
|
|
// Contributors: hmt
|
58 |
|
|
// Date: 2000-05-30
|
59 |
|
|
// Purpose: Port of UCD-SNMP distribution to eCos.
|
60 |
|
|
// Description:
|
61 |
|
|
//
|
62 |
|
|
//
|
63 |
|
|
//####DESCRIPTIONEND####
|
64 |
|
|
//
|
65 |
|
|
//==========================================================================
|
66 |
|
|
/********************************************************************
|
67 |
|
|
Copyright 1989, 1991, 1992 by Carnegie Mellon University
|
68 |
|
|
|
69 |
|
|
Derivative Work -
|
70 |
|
|
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
|
71 |
|
|
|
72 |
|
|
All Rights Reserved
|
73 |
|
|
|
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
|
81 |
|
|
permission.
|
82 |
|
|
|
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 |
|
|
/*
|
93 |
|
|
* SNMPv1 MIB group implementation - snmp.c
|
94 |
|
|
*
|
95 |
|
|
*/
|
96 |
|
|
|
97 |
|
|
#include <config.h>
|
98 |
|
|
#include <sys/types.h>
|
99 |
|
|
#if HAVE_STRING_H
|
100 |
|
|
#include <string.h>
|
101 |
|
|
#else
|
102 |
|
|
#include <strings.h>
|
103 |
|
|
#endif
|
104 |
|
|
#if HAVE_NETINET_IN_H
|
105 |
|
|
#include <netinet/in.h>
|
106 |
|
|
#endif
|
107 |
|
|
|
108 |
|
|
#if HAVE_WINSOCK_H
|
109 |
|
|
#include <winsock.h>
|
110 |
|
|
#endif
|
111 |
|
|
|
112 |
|
|
#include "mibincl.h"
|
113 |
|
|
#include "system.h"
|
114 |
|
|
#include "mibgroup/util_funcs.h"
|
115 |
|
|
|
116 |
|
|
#include "mibgroup/mibII/snmp_mib.h"
|
117 |
|
|
#include "mibgroup/mibII/sysORTable.h"
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
/*********************
|
121 |
|
|
*
|
122 |
|
|
* Kernel & interface information,
|
123 |
|
|
* and internal forward declarations
|
124 |
|
|
*
|
125 |
|
|
*********************/
|
126 |
|
|
|
127 |
|
|
extern int snmp_enableauthentraps;
|
128 |
|
|
int old_snmp_enableauthentraps;
|
129 |
|
|
|
130 |
|
|
/*********************
|
131 |
|
|
*
|
132 |
|
|
* Initialisation & common implementation functions
|
133 |
|
|
*
|
134 |
|
|
*********************/
|
135 |
|
|
|
136 |
|
|
/* define the structure we're going to ask the agent to register our
|
137 |
|
|
information at */
|
138 |
|
|
struct variable2 snmp_variables[] = {
|
139 |
|
|
{SNMPINPKTS, ASN_COUNTER, RONLY, var_snmp, 1, {1}},
|
140 |
|
|
{SNMPOUTPKTS, ASN_COUNTER, RONLY, var_snmp, 1, {2}},
|
141 |
|
|
{SNMPINBADVERSIONS, ASN_COUNTER, RONLY, var_snmp, 1, {3}},
|
142 |
|
|
{SNMPINBADCOMMUNITYNAMES, ASN_COUNTER, RONLY, var_snmp, 1, {4}},
|
143 |
|
|
{SNMPINBADCOMMUNITYUSES, ASN_COUNTER, RONLY, var_snmp, 1, {5}},
|
144 |
|
|
{SNMPINASNPARSEERRORS, ASN_COUNTER, RONLY, var_snmp, 1, {6}},
|
145 |
|
|
{SNMPINTOOBIGS, ASN_COUNTER, RONLY, var_snmp, 1, {8}},
|
146 |
|
|
{SNMPINNOSUCHNAMES, ASN_COUNTER, RONLY, var_snmp, 1, {9}},
|
147 |
|
|
{SNMPINBADVALUES, ASN_COUNTER, RONLY, var_snmp, 1, {10}},
|
148 |
|
|
{SNMPINREADONLYS, ASN_COUNTER, RONLY, var_snmp, 1, {11}},
|
149 |
|
|
{SNMPINGENERRS, ASN_COUNTER, RONLY, var_snmp, 1, {12}},
|
150 |
|
|
{SNMPINTOTALREQVARS, ASN_COUNTER, RONLY, var_snmp, 1, {13}},
|
151 |
|
|
{SNMPINTOTALSETVARS, ASN_COUNTER, RONLY, var_snmp, 1, {14}},
|
152 |
|
|
{SNMPINGETREQUESTS, ASN_COUNTER, RONLY, var_snmp, 1, {15}},
|
153 |
|
|
{SNMPINGETNEXTS, ASN_COUNTER, RONLY, var_snmp, 1, {16}},
|
154 |
|
|
{SNMPINSETREQUESTS, ASN_COUNTER, RONLY, var_snmp, 1, {17}},
|
155 |
|
|
{SNMPINGETRESPONSES, ASN_COUNTER, RONLY, var_snmp, 1, {18}},
|
156 |
|
|
{SNMPINTRAPS, ASN_COUNTER, RONLY, var_snmp, 1, {19}},
|
157 |
|
|
{SNMPOUTTOOBIGS, ASN_COUNTER, RONLY, var_snmp, 1, {20}},
|
158 |
|
|
{SNMPOUTNOSUCHNAMES, ASN_COUNTER, RONLY, var_snmp, 1, {21}},
|
159 |
|
|
{SNMPOUTBADVALUES, ASN_COUNTER, RONLY, var_snmp, 1, {22}},
|
160 |
|
|
{SNMPOUTGENERRS, ASN_COUNTER, RONLY, var_snmp, 1, {24}},
|
161 |
|
|
{SNMPOUTGETREQUESTS, ASN_COUNTER, RONLY, var_snmp, 1, {25}},
|
162 |
|
|
{SNMPOUTGETNEXTS, ASN_COUNTER, RONLY, var_snmp, 1, {26}},
|
163 |
|
|
{SNMPOUTSETREQUESTS, ASN_COUNTER, RONLY, var_snmp, 1, {27}},
|
164 |
|
|
{SNMPOUTGETRESPONSES, ASN_COUNTER, RONLY, var_snmp, 1, {28}},
|
165 |
|
|
{SNMPOUTTRAPS, ASN_COUNTER, RONLY, var_snmp, 1, {29}},
|
166 |
|
|
{SNMPENABLEAUTHENTRAPS, ASN_INTEGER, RWRITE, var_snmp, 1, {30}},
|
167 |
|
|
{SNMPSILENTDROPS, ASN_COUNTER, RONLY, var_snmp, 1, {31}},
|
168 |
|
|
{SNMPPROXYDROPS, ASN_COUNTER, RONLY, var_snmp, 1, {32}}
|
169 |
|
|
};
|
170 |
|
|
|
171 |
|
|
/* Define the OID pointer to the top of the mib tree that we're
|
172 |
|
|
registering underneath */
|
173 |
|
|
oid snmp_variables_oid[] = { SNMP_OID_MIB2,11 };
|
174 |
|
|
#ifdef USING_MIBII_SYSTEM_MIB_MODULE
|
175 |
|
|
extern oid system_module_oid[];
|
176 |
|
|
extern int system_module_oid_len;
|
177 |
|
|
extern int system_module_count;
|
178 |
|
|
#endif
|
179 |
|
|
|
180 |
|
|
void
|
181 |
|
|
init_snmp_mib(void) {
|
182 |
|
|
/* register ourselves with the agent to handle our mib tree */
|
183 |
|
|
REGISTER_MIB("mibII/snmp", snmp_variables, variable2, snmp_variables_oid);
|
184 |
|
|
|
185 |
|
|
#ifdef USING_MIBII_SYSTEM_MIB_MODULE
|
186 |
|
|
if ( ++system_module_count == 3 )
|
187 |
|
|
REGISTER_SYSOR_TABLE( system_module_oid, system_module_oid_len,
|
188 |
|
|
"The MIB module for SNMPv2 entities");
|
189 |
|
|
#endif
|
190 |
|
|
}
|
191 |
|
|
|
192 |
|
|
/*
|
193 |
|
|
header_snmp(...
|
194 |
|
|
Arguments:
|
195 |
|
|
vp IN - pointer to variable entry that points here
|
196 |
|
|
name IN/OUT - IN/name requested, OUT/name found
|
197 |
|
|
length IN/OUT - length of IN/OUT oid's
|
198 |
|
|
exact IN - TRUE if an exact match was requested
|
199 |
|
|
var_len OUT - length of variable or 0 if function returned
|
200 |
|
|
write_method
|
201 |
|
|
|
202 |
|
|
*/
|
203 |
|
|
|
204 |
|
|
/*********************
|
205 |
|
|
*
|
206 |
|
|
* System specific implementation functions
|
207 |
|
|
* (actually common!)
|
208 |
|
|
*
|
209 |
|
|
*********************/
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
u_char *
|
213 |
|
|
var_snmp(struct variable *vp,
|
214 |
|
|
oid *name,
|
215 |
|
|
size_t *length,
|
216 |
|
|
int exact,
|
217 |
|
|
size_t *var_len,
|
218 |
|
|
WriteMethod **write_method)
|
219 |
|
|
{
|
220 |
|
|
static long long_ret;
|
221 |
|
|
|
222 |
|
|
*write_method = 0; /* assume it isnt writable for the time being */
|
223 |
|
|
*var_len = sizeof(long_ret); /* assume an integer and change later if not */
|
224 |
|
|
|
225 |
|
|
if (header_generic(vp, name, length, exact, var_len, write_method)
|
226 |
|
|
== MATCH_FAILED)
|
227 |
|
|
return NULL;
|
228 |
|
|
|
229 |
|
|
/* this is where we do the value assignments for the mib results. */
|
230 |
|
|
if (vp->magic == SNMPENABLEAUTHENTRAPS) {
|
231 |
|
|
*write_method = write_snmp;
|
232 |
|
|
long_return = snmp_enableauthentraps;
|
233 |
|
|
return (u_char *) &long_return;
|
234 |
|
|
} else if ( (vp->magic >= 1)
|
235 |
|
|
&& (vp->magic <= (STAT_SNMP_STATS_END - STAT_SNMP_STATS_START + 1)) ) {
|
236 |
|
|
long_ret = snmp_get_statistic(vp->magic + STAT_SNMP_STATS_START - 1);
|
237 |
|
|
return (unsigned char *) &long_ret;
|
238 |
|
|
}
|
239 |
|
|
return NULL;
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
/*
|
243 |
|
|
* only for snmpEnableAuthenTraps:
|
244 |
|
|
*/
|
245 |
|
|
|
246 |
|
|
int
|
247 |
|
|
write_snmp (int action,
|
248 |
|
|
u_char *var_val,
|
249 |
|
|
u_char var_val_type,
|
250 |
|
|
size_t var_val_len,
|
251 |
|
|
u_char *statP,
|
252 |
|
|
oid *name,
|
253 |
|
|
size_t name_len)
|
254 |
|
|
{
|
255 |
|
|
long intval = *((long *) var_val);
|
256 |
|
|
|
257 |
|
|
switch ( action ) {
|
258 |
|
|
case RESERVE1: /* Check values for acceptability */
|
259 |
|
|
if (var_val_type != ASN_INTEGER){
|
260 |
|
|
DEBUGMSGTL(("mibII/snmp_mib", "%x not integer type", var_val_type));
|
261 |
|
|
return SNMP_ERR_WRONGTYPE;
|
262 |
|
|
}
|
263 |
|
|
|
264 |
|
|
if (intval != 1 && intval != 2) {
|
265 |
|
|
DEBUGMSGTL(("mibII/snmp_mib", "not valid %x\n", intval));
|
266 |
|
|
return SNMP_ERR_WRONGVALUE;
|
267 |
|
|
}
|
268 |
|
|
break;
|
269 |
|
|
|
270 |
|
|
case RESERVE2: /* Allocate memory and similar resources */
|
271 |
|
|
|
272 |
|
|
/* Using static variables, so nothing needs to be done */
|
273 |
|
|
break;
|
274 |
|
|
|
275 |
|
|
case ACTION: /* Perform the SET action (if reversible) */
|
276 |
|
|
|
277 |
|
|
/* Save the old value, in case of UNDO */
|
278 |
|
|
old_snmp_enableauthentraps = snmp_enableauthentraps;
|
279 |
|
|
snmp_enableauthentraps = intval;
|
280 |
|
|
break;
|
281 |
|
|
|
282 |
|
|
case UNDO: /* Reverse the SET action and free resources */
|
283 |
|
|
|
284 |
|
|
snmp_enableauthentraps = old_snmp_enableauthentraps;
|
285 |
|
|
break;
|
286 |
|
|
|
287 |
|
|
case COMMIT: /* Confirm the SET, performing any irreversible actions,
|
288 |
|
|
and free resources */
|
289 |
|
|
/* save_into_conffile ("authentraps:", intval == 1 ? "yes" : "no"); */
|
290 |
|
|
break;
|
291 |
|
|
|
292 |
|
|
case FREE: /* Free any resources allocated */
|
293 |
|
|
break;
|
294 |
|
|
}
|
295 |
|
|
return SNMP_ERR_NOERROR;
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
/*********************
|
299 |
|
|
*
|
300 |
|
|
* Internal implementation functions
|
301 |
|
|
*
|
302 |
|
|
*********************/
|