2 * snmp_vars.c - return a pointer to the named variable.
6 /***********************************************************
7 Copyright 1988, 1989, 1990 by Carnegie Mellon University
8 Copyright 1989 TGV, Incorporated
12 Permission to use, copy, modify, and distribute this software and its
13 documentation for any purpose and without fee is hereby granted,
14 provided that the above copyright notice appear in all copies and that
15 both that copyright notice and this permission notice appear in
16 supporting documentation, and that the name of CMU and TGV not be used
17 in advertising or publicity pertaining to distribution of the software
18 without specific, written prior permission.
20 CMU AND TGV DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
22 EVENT SHALL CMU OR TGV BE LIABLE FOR ANY SPECIAL, INDIRECT OR
23 CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
24 USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
25 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
26 PERFORMANCE OF THIS SOFTWARE.
27 ******************************************************************/
29 * additions, fixes and enhancements for Linux by Erik Schoenfelder
30 * (schoenfr@ibr.cs.tu-bs.de) 1994/1995.
31 * Linux additions taken from CMU to UCD stack by Jennifer Bray of Origin
32 * (jbray@origin-at.co.uk) 1997
36 * XXXWWW merge todo: incl/excl range changes in differences between
40 #include <net-snmp/net-snmp-config.h>
47 #include <sys/types.h>
51 #if TIME_WITH_SYS_TIME
53 # include <sys/timeb.h>
55 # include <sys/time.h>
60 # include <sys/time.h>
69 # include <sys/socket.h>
72 #include <sys/stream.h>
74 #if HAVE_SYS_SOCKETVAR_H
75 # include <sys/socketvar.h>
78 #include <netinet/in.h>
80 #if HAVE_NETINET_IN_SYSTM_H
81 #include <netinet/in_systm.h>
84 #include <netinet/ip.h>
87 #if HAVE_NETINET_IP6_H
88 #include <netinet/ip6.h>
92 #include <sys/queue.h>
95 #include <net/route.h>
97 #if HAVE_NETINET_IP_VAR_H
98 #include <netinet/ip_var.h>
101 #if HAVE_NETINET6_IP6_VAR_H
102 #include <netinet6/ip6_var.h>
105 #if HAVE_NETINET_IN_PCB_H
106 #include <netinet/in_pcb.h>
109 #include <inet/mib2.h>
116 #include <net-snmp/net-snmp-includes.h>
117 #include <net-snmp/agent/net-snmp-agent-includes.h>
120 #include "mibgroup/struct.h"
122 #include "net-snmp/agent/all_helpers.h"
123 #include "mib_module_includes.h"
124 #include "net-snmp/library/container.h"
127 #define MIN(a,b) (((a) < (b)) ? (a) : (b))
131 * mib clients are passed a pointer to a oid buffer. Some mib clients
132 * * (namely, those first noticed in mibII/vacm.c) modify this oid buffer
133 * * before they determine if they really need to send results back out
134 * * using it. If the master agent determined that the client was not the
135 * * right one to talk with, it will use the same oid buffer to pass to the
136 * * rest of the clients, which may not longer be valid. This should be
137 * * fixed in all clients rather than the master. However, its not a
138 * * particularily easy bug to track down so this saves debugging time at
139 * * the expense of a few memcpy's.
141 #define MIB_CLIENTS_ARE_EVIL 1
143 extern netsnmp_subtree
*subtrees
;
146 * Each variable name is placed in the variable table, without the
147 * terminating substring that determines the instance of the variable. When
148 * a string is found that is lexicographicly preceded by the input string,
149 * the function for that entry is called to find the method of access of the
150 * instance of the named variable. If that variable is not found, NULL is
151 * returned, and the search through the table continues (it will probably
152 * stop at the next entry). If it is found, the function returns a character
153 * pointer and a length or a function pointer. The former is the address
154 * of the operand, the latter is a write routine for the variable.
157 * findVar(name, length, exact, var_len, write_method)
158 * oid *name; IN/OUT - input name requested, output name found
159 * int length; IN/OUT - number of sub-ids in the in and out oid's
160 * int exact; IN - TRUE if an exact match was requested.
161 * int len; OUT - length of variable or 0 if function returned.
162 * int write_method; OUT - pointer to function to set variable,
165 * The writeVar function is returned to handle row addition or complex
166 * writes that require boundary checking or executing an action.
167 * This routine will be called three times for each varbind in the packet.
168 * The first time for each varbind, action is set to RESERVE1. The type
169 * and value should be checked during this pass. If any other variables
170 * in the MIB depend on this variable, this variable will be stored away
171 * (but *not* committed!) in a place where it can be found by a call to
172 * writeVar for a dependent variable, even in the same PDU. During
173 * the second pass, action is set to RESERVE2. If this variable is dependent
174 * on any other variables, it will check them now. It must check to see
175 * if any non-committed values have been stored for variables in the same
176 * PDU that it depends on. Sometimes resources will need to be reserved
177 * in the first two passes to guarantee that the operation can proceed
178 * during the third pass. During the third pass, if there were no errors
179 * in the first two passes, writeVar is called for every varbind with action
180 * set to COMMIT. It is now that the values should be written. If there
181 * were errors during the first two passes, writeVar is called in the third
182 * pass once for each varbind, with the action set to FREE. An opportunity
183 * is thus provided to free those resources reserved in the first two passes.
185 * writeVar(action, var_val, var_val_type, var_val_len, statP, name, name_len)
186 * int action; IN - RESERVE1, RESERVE2, COMMIT, or FREE
187 * u_char *var_val; IN - input or output buffer space
188 * u_char var_val_type; IN - type of input buffer
189 * int var_val_len; IN - input and output buffer len
190 * u_char *statP; IN - pointer to local statistic
191 * oid *name IN - pointer to name requested
192 * int name_len IN - number of sub-ids in the name
197 u_char return_buf
[258];
199 u_char return_buf
[256]; /* nee 64 */
202 struct timeval starttime
;
203 netsnmp_session
*callback_master_sess
;
204 int callback_master_num
;
207 * init_agent() returns non-zero on error
210 init_agent(const char *app
)
215 * get current time (ie, the time the agent started)
217 gettimeofday(&starttime
, NULL
);
219 starttime
.tv_usec
+= 1000000L;
222 * we handle alarm signals ourselves in the select loop
224 netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID
,
225 NETSNMP_DS_LIB_ALARM_DONT_USE_SIG
, 1);
228 init_kmem("/dev/kmem");
233 init_agent_read_config(app
);
236 auto_nlist_print_tree(-2, 0);
241 * the pipe call creates fds that select chokes on, so
242 * disable callbacks on WIN32 until a fix can be found
245 * always register a callback transport for internal use
247 callback_master_sess
= netsnmp_callback_open(0, handle_snmp_packet
,
248 netsnmp_agent_check_packet
,
249 netsnmp_agent_check_parse
);
250 if (callback_master_sess
)
251 callback_master_num
= callback_master_sess
->local_port
;
254 callback_master_num
= -1;
256 netsnmp_init_helpers();
258 netsnmp_container_init_list();
261 * initialize agentx subagent if necessary.
263 #ifdef USING_AGENTX_SUBAGENT_MODULE
264 if (netsnmp_ds_get_boolean(NETSNMP_DS_APPLICATION_ID
,
265 NETSNMP_DS_AGENT_ROLE
) == SUB_AGENT
) {
266 r
= subagent_pre_init();
272 * Register configuration tokens from transport modules.
274 #ifdef SNMP_TRANSPORT_UDP_DOMAIN
275 netsnmp_udp_agent_config_tokens_register();
277 #ifdef SNMP_TRANSPORT_UDPIPV6_DOMAIN
278 netsnmp_udp6_agent_config_tokens_register();
281 #ifdef NETSNMP_EMBEDDED_PERL
286 } /* end init_agent() */
288 oid nullOid
[] = { 0, 0 };
289 int nullOidLen
= sizeof(nullOid
);