1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// ./agent/current/src/mibgroup/mibII/sysORTable.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 |
|
|
* Template MIB group implementation - sysORTable.c
|
94 |
|
|
*
|
95 |
|
|
*/
|
96 |
|
|
#include <config.h>
|
97 |
|
|
#if HAVE_STDLIB_H
|
98 |
|
|
#include <stdlib.h>
|
99 |
|
|
#endif
|
100 |
|
|
#include <sys/types.h>
|
101 |
|
|
#if TIME_WITH_SYS_TIME
|
102 |
|
|
# ifdef WIN32
|
103 |
|
|
# include <sys/timeb.h>
|
104 |
|
|
# else
|
105 |
|
|
# include <sys/time.h>
|
106 |
|
|
# endif
|
107 |
|
|
# include <time.h>
|
108 |
|
|
#else
|
109 |
|
|
# if HAVE_SYS_TIME_H
|
110 |
|
|
# include <sys/time.h>
|
111 |
|
|
# else
|
112 |
|
|
# include <time.h>
|
113 |
|
|
# endif
|
114 |
|
|
#endif
|
115 |
|
|
#if HAVE_STRING_H
|
116 |
|
|
#include <string.h>
|
117 |
|
|
#else
|
118 |
|
|
#include <strings.h>
|
119 |
|
|
#endif
|
120 |
|
|
|
121 |
|
|
#if HAVE_WINSOCK_H
|
122 |
|
|
#include <winsock.h>
|
123 |
|
|
#endif
|
124 |
|
|
|
125 |
|
|
#if HAVE_DMALLOC_H
|
126 |
|
|
#include <dmalloc.h>
|
127 |
|
|
#endif
|
128 |
|
|
|
129 |
|
|
#include "mibincl.h"
|
130 |
|
|
#include "system.h"
|
131 |
|
|
#include "mibgroup/struct.h"
|
132 |
|
|
#include "mibgroup/util_funcs.h"
|
133 |
|
|
#include "mibgroup/mibII/sysORTable.h"
|
134 |
|
|
#include "snmpd.h"
|
135 |
|
|
#include "default_store.h"
|
136 |
|
|
#include "ds_agent.h"
|
137 |
|
|
#include "callback.h"
|
138 |
|
|
#include "agent_callbacks.h"
|
139 |
|
|
|
140 |
|
|
#ifdef USING_AGENTX_SUBAGENT_MODULE
|
141 |
|
|
#include "agentx/subagent.h"
|
142 |
|
|
#include "agentx/client.h"
|
143 |
|
|
#endif
|
144 |
|
|
|
145 |
|
|
extern struct timeval starttime;
|
146 |
|
|
|
147 |
|
|
struct timeval sysOR_lastchange;
|
148 |
|
|
static struct sysORTable *table=NULL;
|
149 |
|
|
static int numEntries=0;
|
150 |
|
|
|
151 |
|
|
/* define the structure we're going to ask the agent to register our
|
152 |
|
|
information at */
|
153 |
|
|
struct variable2 sysORTable_variables[] = {
|
154 |
|
|
{ SYSORTABLEID, ASN_OBJECT_ID, RONLY, var_sysORTable, 1, {2}},
|
155 |
|
|
{ SYSORTABLEDESCR, ASN_OCTET_STR, RONLY, var_sysORTable, 1, {3}},
|
156 |
|
|
{ SYSORTABLEUPTIME, ASN_TIMETICKS, RONLY, var_sysORTable, 1, {4}}
|
157 |
|
|
};
|
158 |
|
|
|
159 |
|
|
/* Define the OID pointer to the top of the mib tree that we're
|
160 |
|
|
registering underneath */
|
161 |
|
|
oid sysORTable_variables_oid[] = { SNMP_OID_MIB2,1,9,1 };
|
162 |
|
|
#ifdef USING_MIBII_SYSTEM_MIB_MODULE
|
163 |
|
|
extern oid system_module_oid[];
|
164 |
|
|
extern int system_module_oid_len;
|
165 |
|
|
extern int system_module_count;
|
166 |
|
|
#endif
|
167 |
|
|
|
168 |
|
|
void
|
169 |
|
|
init_sysORTable(void) {
|
170 |
|
|
/* register ourselves with the agent to handle our mib tree */
|
171 |
|
|
|
172 |
|
|
#ifdef USING_AGENTX_SUBAGENT_MODULE
|
173 |
|
|
if ( ds_get_boolean(DS_APPLICATION_ID, DS_AGENT_ROLE) == MASTER_AGENT )
|
174 |
|
|
(void)register_mib_priority("mibII/sysORTable",
|
175 |
|
|
(struct variable *) sysORTable_variables,
|
176 |
|
|
sizeof(struct variable2),
|
177 |
|
|
sizeof(sysORTable_variables)/sizeof(struct variable2),
|
178 |
|
|
sysORTable_variables_oid,
|
179 |
|
|
sizeof(sysORTable_variables_oid)/sizeof(oid), 1);
|
180 |
|
|
else
|
181 |
|
|
#endif
|
182 |
|
|
REGISTER_MIB("mibII/sysORTable", sysORTable_variables, variable2, sysORTable_variables_oid);
|
183 |
|
|
|
184 |
|
|
#ifdef USING_MIBII_SYSTEM_MIB_MODULE
|
185 |
|
|
if ( ++system_module_count == 3 )
|
186 |
|
|
REGISTER_SYSOR_TABLE( system_module_oid, system_module_oid_len,
|
187 |
|
|
"The MIB module for SNMPv2 entities");
|
188 |
|
|
#endif
|
189 |
|
|
|
190 |
|
|
gettimeofday(&sysOR_lastchange, NULL);
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
/*********************
|
194 |
|
|
*
|
195 |
|
|
* System specific implementation functions
|
196 |
|
|
*
|
197 |
|
|
*********************/
|
198 |
|
|
|
199 |
|
|
u_char *
|
200 |
|
|
var_sysORTable(struct variable *vp,
|
201 |
|
|
oid *name,
|
202 |
|
|
size_t *length,
|
203 |
|
|
int exact,
|
204 |
|
|
size_t *var_len,
|
205 |
|
|
WriteMethod **write_method)
|
206 |
|
|
{
|
207 |
|
|
struct timeval diff;
|
208 |
|
|
int i;
|
209 |
|
|
struct sysORTable *ptr;
|
210 |
|
|
|
211 |
|
|
if (header_simple_table(vp, name, length, exact, var_len, write_method, numEntries))
|
212 |
|
|
return NULL;
|
213 |
|
|
|
214 |
|
|
DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- "));
|
215 |
|
|
for(i = 1, ptr=table; ptr != NULL && i < (int)name[*length-1];
|
216 |
|
|
ptr = ptr->next, i++) {
|
217 |
|
|
DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- %d != %d\n",i,name[*length-1]));
|
218 |
|
|
}
|
219 |
|
|
if (ptr == NULL) {
|
220 |
|
|
DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- no match: %d\n",i));
|
221 |
|
|
return NULL;
|
222 |
|
|
}
|
223 |
|
|
DEBUGMSGTL(("mibII/sysORTable", "sysORTable -- match: %d\n",i));
|
224 |
|
|
|
225 |
|
|
switch (vp->magic){
|
226 |
|
|
case SYSORTABLEID:
|
227 |
|
|
*var_len = ptr->OR_oidlen*sizeof(ptr->OR_oid[0]);
|
228 |
|
|
return (u_char *) ptr->OR_oid;
|
229 |
|
|
|
230 |
|
|
case SYSORTABLEDESCR:
|
231 |
|
|
*var_len = strlen(ptr->OR_descr);
|
232 |
|
|
return (u_char *) ptr->OR_descr;
|
233 |
|
|
|
234 |
|
|
case SYSORTABLEUPTIME:
|
235 |
|
|
ptr->OR_uptime.tv_sec--;
|
236 |
|
|
ptr->OR_uptime.tv_usec += 1000000L;
|
237 |
|
|
diff.tv_sec = ptr->OR_uptime.tv_sec - 1 - starttime.tv_sec;
|
238 |
|
|
diff.tv_usec = ptr->OR_uptime.tv_usec + 1000000L - starttime.tv_usec;
|
239 |
|
|
if (diff.tv_usec > 1000000L){
|
240 |
|
|
diff.tv_usec -= 1000000L;
|
241 |
|
|
diff.tv_sec++;
|
242 |
|
|
}
|
243 |
|
|
if ((diff.tv_sec * 100) + (diff.tv_usec / 10000) < 0)
|
244 |
|
|
long_return = 0;
|
245 |
|
|
else
|
246 |
|
|
long_return = ((diff.tv_sec * 100) + (diff.tv_usec / 10000));
|
247 |
|
|
return ((u_char *) &long_return);
|
248 |
|
|
|
249 |
|
|
default:
|
250 |
|
|
DEBUGMSGTL(("snmpd", "unknown sub-id %d in var_sysORTable\n", vp->magic));
|
251 |
|
|
}
|
252 |
|
|
return NULL;
|
253 |
|
|
}
|
254 |
|
|
|
255 |
|
|
|
256 |
|
|
int register_sysORTable_sess(oid *oidin,
|
257 |
|
|
size_t oidlen,
|
258 |
|
|
const char *descr,
|
259 |
|
|
struct snmp_session *ss)
|
260 |
|
|
{
|
261 |
|
|
struct sysORTable **ptr=&table;
|
262 |
|
|
struct register_sysOR_parameters reg_sysOR_parms;
|
263 |
|
|
|
264 |
|
|
DEBUGMSGTL(("mibII/sysORTable", "sysORTable registering: "));
|
265 |
|
|
DEBUGMSGOID(("mibII/sysORTable", oidin, oidlen));
|
266 |
|
|
DEBUGMSG(("mibII/sysORTable","\n"));
|
267 |
|
|
|
268 |
|
|
while(*ptr != NULL)
|
269 |
|
|
ptr = &((*ptr)->next);
|
270 |
|
|
*ptr = (struct sysORTable *) malloc(sizeof(struct sysORTable));
|
271 |
|
|
if ( *ptr == NULL ) {
|
272 |
|
|
return SYS_ORTABLE_REGISTRATION_FAILED;
|
273 |
|
|
}
|
274 |
|
|
(*ptr)->OR_descr = (char *) malloc(strlen(descr)+1);
|
275 |
|
|
if ( (*ptr)->OR_descr == NULL ) {
|
276 |
|
|
free( *ptr );
|
277 |
|
|
return SYS_ORTABLE_REGISTRATION_FAILED;
|
278 |
|
|
}
|
279 |
|
|
strcpy((*ptr)->OR_descr, descr);
|
280 |
|
|
(*ptr)->OR_oidlen = oidlen;
|
281 |
|
|
(*ptr)->OR_oid = (oid *) malloc(sizeof(oid)*oidlen);
|
282 |
|
|
if ( (*ptr)->OR_oid == NULL ) {
|
283 |
|
|
free( *ptr );
|
284 |
|
|
free( (*ptr)->OR_descr );
|
285 |
|
|
return SYS_ORTABLE_REGISTRATION_FAILED;
|
286 |
|
|
}
|
287 |
|
|
memcpy((*ptr)->OR_oid, oidin, sizeof(oid)*oidlen);
|
288 |
|
|
gettimeofday(&((*ptr)->OR_uptime), NULL);
|
289 |
|
|
(*ptr)->OR_sess = ss;
|
290 |
|
|
(*ptr)->next = NULL;
|
291 |
|
|
numEntries++;
|
292 |
|
|
|
293 |
|
|
reg_sysOR_parms.name = oidin;
|
294 |
|
|
reg_sysOR_parms.namelen = oidlen;
|
295 |
|
|
reg_sysOR_parms.descr = descr;
|
296 |
|
|
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_REG_SYSOR,
|
297 |
|
|
®_sysOR_parms);
|
298 |
|
|
|
299 |
|
|
return SYS_ORTABLE_REGISTERED_OK;
|
300 |
|
|
}
|
301 |
|
|
|
302 |
|
|
int register_sysORTable(oid *oidin,
|
303 |
|
|
size_t oidlen,
|
304 |
|
|
const char *descr)
|
305 |
|
|
{
|
306 |
|
|
return register_sysORTable_sess( oidin, oidlen, descr, NULL );
|
307 |
|
|
}
|
308 |
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
|
|
int unregister_sysORTable_sess(oid *oidin,
|
312 |
|
|
size_t oidlen,
|
313 |
|
|
struct snmp_session *ss)
|
314 |
|
|
{
|
315 |
|
|
struct sysORTable **ptr=&table, *prev=NULL;
|
316 |
|
|
int found = SYS_ORTABLE_NO_SUCH_REGISTRATION;
|
317 |
|
|
struct register_sysOR_parameters reg_sysOR_parms;
|
318 |
|
|
|
319 |
|
|
DEBUGMSGTL(("mibII/sysORTable", "sysORTable unregistering: "));
|
320 |
|
|
DEBUGMSGOID(("mibII/sysORTable", oidin, oidlen));
|
321 |
|
|
DEBUGMSG(("mibII/sysORTable","\n"));
|
322 |
|
|
|
323 |
|
|
while(*ptr != NULL) {
|
324 |
|
|
if ( snmp_oid_compare( oidin, oidlen, (*ptr)->OR_oid, (*ptr)->OR_oidlen) == 0 ) {
|
325 |
|
|
if ( (*ptr)->OR_sess != ss )
|
326 |
|
|
continue; /* different session */
|
327 |
|
|
if ( prev == NULL )
|
328 |
|
|
table = (*ptr)->next;
|
329 |
|
|
else
|
330 |
|
|
prev->next = (*ptr)->next;
|
331 |
|
|
|
332 |
|
|
free( (*ptr)->OR_descr );
|
333 |
|
|
free( (*ptr)->OR_oid );
|
334 |
|
|
free( (*ptr) );
|
335 |
|
|
numEntries--;
|
336 |
|
|
found = SYS_ORTABLE_UNREGISTERED_OK;
|
337 |
|
|
break;
|
338 |
|
|
}
|
339 |
|
|
prev = *ptr;
|
340 |
|
|
ptr = &((*ptr)->next);
|
341 |
|
|
}
|
342 |
|
|
|
343 |
|
|
reg_sysOR_parms.name = oidin;
|
344 |
|
|
reg_sysOR_parms.namelen = oidlen;
|
345 |
|
|
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION, SNMPD_CALLBACK_UNREG_SYSOR,
|
346 |
|
|
®_sysOR_parms);
|
347 |
|
|
|
348 |
|
|
return found;
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
|
352 |
|
|
int unregister_sysORTable(oid *oidin,
|
353 |
|
|
size_t oidlen)
|
354 |
|
|
{
|
355 |
|
|
return unregister_sysORTable_sess( oidin, oidlen, NULL );
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
void unregister_sysORTable_by_session(struct snmp_session *ss)
|
359 |
|
|
{
|
360 |
|
|
struct sysORTable *ptr=table, *prev=NULL, *next;
|
361 |
|
|
|
362 |
|
|
while ( ptr != NULL ) {
|
363 |
|
|
next = ptr->next;
|
364 |
|
|
if (( (ss->flags & SNMP_FLAGS_SUBSESSION) && ptr->OR_sess == ss ) ||
|
365 |
|
|
(!(ss->flags & SNMP_FLAGS_SUBSESSION) &&
|
366 |
|
|
ptr->OR_sess->subsession == ss )) {
|
367 |
|
|
if ( prev == NULL )
|
368 |
|
|
table = next;
|
369 |
|
|
else
|
370 |
|
|
prev->next = next;
|
371 |
|
|
free( ptr->OR_descr );
|
372 |
|
|
free( ptr->OR_oid );
|
373 |
|
|
free( ptr );
|
374 |
|
|
numEntries--;
|
375 |
|
|
|
376 |
|
|
}
|
377 |
|
|
else
|
378 |
|
|
prev = ptr;
|
379 |
|
|
ptr = next;
|
380 |
|
|
}
|
381 |
|
|
}
|
382 |
|
|
|