snmp.c revision 1.1 1 1.1 mycroft /*
2 1.1 mycroft * snmp.c
3 1.1 mycroft *
4 1.1 mycroft * Code written by David Thaler <thalerd (at) eecs.umich.edu>
5 1.1 mycroft * Moved to a seperate file by Bill Fenner <fenner (at) parc.xerox.com>
6 1.1 mycroft */
7 1.1 mycroft
8 1.1 mycroft
9 1.1 mycroft #include "defs.h"
10 1.1 mycroft #include <string.h>
11 1.1 mycroft #include "snmp.h"
12 1.1 mycroft
13 1.1 mycroft #define NUMMIBS 2
14 1.1 mycroft #define SNMPD_RETRY_INTERVAL 300 /* periodic snmpd probe interval */
15 1.1 mycroft
16 1.1 mycroft char *mibs[]={ "ipMRouteMIB", "dvmrpMIB" };
17 1.1 mycroft
18 1.1 mycroft extern int o_ipMRouteTable();
19 1.1 mycroft extern int o_ipMRouteNextHopTable();
20 1.1 mycroft extern int o_dvmrpRouteTable();
21 1.1 mycroft extern int o_dvmrpRouteNextHopTable();
22 1.1 mycroft
23 1.1 mycroft int smux_fd = NOTOK;
24 1.1 mycroft int rock_and_roll = 0;
25 1.1 mycroft int dont_bother_anymore = 0;
26 1.1 mycroft int quantum = 0;
27 1.1 mycroft static OID subtree[NUMMIBS] = NULLOID;
28 1.1 mycroft static struct smuxEntry *se = NULL;
29 1.1 mycroft extern int smux_errno;
30 1.1 mycroft extern char smux_info[BUFSIZ];
31 1.1 mycroft
32 1.1 mycroft /*
33 1.1 mycroft * Place an IP address into an OID starting at element n
34 1.1 mycroft */
35 1.1 mycroft void
36 1.1 mycroft put_address(oid, addr, n)
37 1.1 mycroft OID oid;
38 1.1 mycroft u_long addr;
39 1.1 mycroft int n;
40 1.1 mycroft {
41 1.1 mycroft int i;
42 1.1 mycroft
43 1.1 mycroft for (i=n+3; i>=n+0; i--) {
44 1.1 mycroft oid->oid_elements[i] = addr & 0xFF;
45 1.1 mycroft addr >>= 8;
46 1.1 mycroft }
47 1.1 mycroft }
48 1.1 mycroft
49 1.1 mycroft /* Get an IP address from an OID starting at element n */
50 1.1 mycroft int
51 1.1 mycroft get_address(oid, addr, n)
52 1.1 mycroft OID oid;
53 1.1 mycroft u_long *addr;
54 1.1 mycroft int n;
55 1.1 mycroft {
56 1.1 mycroft int i;
57 1.1 mycroft int ok = 1;
58 1.1 mycroft
59 1.1 mycroft (*addr) = 0;
60 1.1 mycroft
61 1.1 mycroft if (oid -> oid_nelem < n+4)
62 1.1 mycroft return 0;
63 1.1 mycroft
64 1.1 mycroft for (i=n; i<n+4; i++) {
65 1.1 mycroft (*addr) <<= 8;
66 1.1 mycroft if (i >= oid->oid_nelem)
67 1.1 mycroft ok = 0;
68 1.1 mycroft else
69 1.1 mycroft (*addr) |= oid->oid_elements[i];
70 1.1 mycroft }
71 1.1 mycroft
72 1.1 mycroft return ok;
73 1.1 mycroft }
74 1.1 mycroft
75 1.1 mycroft /*
76 1.1 mycroft * Attempt to start up SMUX protocol
77 1.1 mycroft */
78 1.1 mycroft void
79 1.1 mycroft try_smux_init()
80 1.1 mycroft {
81 1.1 mycroft if (smux_fd != NOTOK || dont_bother_anymore)
82 1.1 mycroft return;
83 1.1 mycroft if ((smux_fd = smux_init(debug)) == NOTOK) {
84 1.1 mycroft log(LOG_WARNING, 0,"smux_init: %s [%s]", smux_error(smux_errno),
85 1.1 mycroft smux_info);
86 1.1 mycroft } else
87 1.1 mycroft rock_and_roll = 0;
88 1.1 mycroft }
89 1.1 mycroft
90 1.1 mycroft /*
91 1.1 mycroft * Implements scalar objects from both MIBs
92 1.1 mycroft */
93 1.1 mycroft static int
94 1.1 mycroft o_scalar(oi, v, offset)
95 1.1 mycroft OI oi;
96 1.1 mycroft register struct type_SNMP_VarBind *v;
97 1.1 mycroft int offset;
98 1.1 mycroft {
99 1.1 mycroft int ifvar;
100 1.1 mycroft register OID oid = oi -> oi_name;
101 1.1 mycroft register OT ot = oi -> oi_type;
102 1.1 mycroft
103 1.1 mycroft ifvar = (int) ot -> ot_info;
104 1.1 mycroft switch (offset) {
105 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
106 1.1 mycroft if (oid -> oid_nelem !=
107 1.1 mycroft ot -> ot_name -> oid_nelem + 1
108 1.1 mycroft || oid -> oid_elements[oid -> oid_nelem - 1]
109 1.1 mycroft != 0)
110 1.1 mycroft return int_SNMP_error__status_noSuchName;
111 1.1 mycroft break;
112 1.1 mycroft
113 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
114 1.1 mycroft if (oid -> oid_nelem
115 1.1 mycroft == ot -> ot_name -> oid_nelem) {
116 1.1 mycroft OID new;
117 1.1 mycroft
118 1.1 mycroft if ((new = oid_extend (oid, 1)) == NULLOID)
119 1.1 mycroft return int_SNMP_error__status_genErr;
120 1.1 mycroft new -> oid_elements[new -> oid_nelem - 1] = 0;
121 1.1 mycroft
122 1.1 mycroft if (v -> name)
123 1.1 mycroft free_SNMP_ObjectName (v -> name);
124 1.1 mycroft v -> name = new;
125 1.1 mycroft }
126 1.1 mycroft else
127 1.1 mycroft return NOTOK;
128 1.1 mycroft break;
129 1.1 mycroft
130 1.1 mycroft default:
131 1.1 mycroft return int_SNMP_error__status_genErr;
132 1.1 mycroft }
133 1.1 mycroft
134 1.1 mycroft switch (ifvar) {
135 1.1 mycroft case ipMRouteEnable:
136 1.1 mycroft return o_integer (oi, v, 1);
137 1.1 mycroft
138 1.1 mycroft case dvmrpVersion: {
139 1.1 mycroft static char buff[15];
140 1.1 mycroft
141 1.1 mycroft sprintf(buff, "mrouted%d.%d", PROTOCOL_VERSION, MROUTED_VERSION);
142 1.1 mycroft return o_string (oi, v, buff, strlen (buff));
143 1.1 mycroft }
144 1.1 mycroft
145 1.1 mycroft case dvmrpGenerationId:
146 1.1 mycroft return o_integer (oi, v, dvmrp_genid);
147 1.1 mycroft
148 1.1 mycroft default:
149 1.1 mycroft return int_SNMP_error__status_noSuchName;
150 1.1 mycroft }
151 1.1 mycroft }
152 1.1 mycroft
153 1.1 mycroft /*
154 1.1 mycroft * Find if a specific scoped boundary exists on a Vif
155 1.1 mycroft */
156 1.1 mycroft struct vif_acl *
157 1.1 mycroft find_boundary(vifi, addr, mask)
158 1.1 mycroft int vifi;
159 1.1 mycroft int addr;
160 1.1 mycroft int mask;
161 1.1 mycroft {
162 1.1 mycroft struct vif_acl *n;
163 1.1 mycroft
164 1.1 mycroft for (n = uvifs[vifi].uv_acl; n != NULL; n = n->acl_next) {
165 1.1 mycroft if (addr == n->acl_addr && mask==n->acl_mask)
166 1.1 mycroft return n;
167 1.1 mycroft }
168 1.1 mycroft return NULL;
169 1.1 mycroft }
170 1.1 mycroft
171 1.1 mycroft /*
172 1.1 mycroft * Find the next scoped boundary in order after a given spec
173 1.1 mycroft */
174 1.1 mycroft struct vif_acl *
175 1.1 mycroft next_boundary(vifi, addr, mask)
176 1.1 mycroft int *vifi;
177 1.1 mycroft int addr;
178 1.1 mycroft int mask;
179 1.1 mycroft {
180 1.1 mycroft struct vif_acl *bestn, *n;
181 1.1 mycroft int i;
182 1.1 mycroft
183 1.1 mycroft for (i = *vifi; i < numvifs; i++) {
184 1.1 mycroft bestn = NULL;
185 1.1 mycroft for (n = uvifs[i].uv_acl; n; n=n->acl_next) {
186 1.1 mycroft if ((i > *vifi || n->acl_addr > addr
187 1.1 mycroft || (n->acl_addr==addr && n->acl_mask>mask))
188 1.1 mycroft && (!bestn || n->acl_addr < bestn->acl_addr
189 1.1 mycroft || (n->acl_addr==bestn->acl_addr && n->acl_mask<bestn->acl_mask)))
190 1.1 mycroft bestn = n;
191 1.1 mycroft }
192 1.1 mycroft if (bestn) {
193 1.1 mycroft *vifi = i;
194 1.1 mycroft return bestn;
195 1.1 mycroft }
196 1.1 mycroft }
197 1.1 mycroft return NULL;
198 1.1 mycroft }
199 1.1 mycroft
200 1.1 mycroft /*
201 1.1 mycroft * Implements the Boundary Table portion of the DVMRP MIB
202 1.1 mycroft */
203 1.1 mycroft static int
204 1.1 mycroft o_dvmrpBoundaryTable (oi, v, offset)
205 1.1 mycroft OI oi;
206 1.1 mycroft register struct type_SNMP_VarBind *v;
207 1.1 mycroft {
208 1.1 mycroft int ifvar, vifi,
209 1.1 mycroft addr, mask;
210 1.1 mycroft register OID oid = oi -> oi_name;
211 1.1 mycroft register OT ot = oi -> oi_type;
212 1.1 mycroft struct vif_acl *bound;
213 1.1 mycroft
214 1.1 mycroft ifvar = (int) ot -> ot_info;
215 1.1 mycroft switch (offset) {
216 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
217 1.1 mycroft if (oid->oid_nelem != ot->ot_name->oid_nelem + 9)
218 1.1 mycroft return int_SNMP_error__status_noSuchName;
219 1.1 mycroft
220 1.1 mycroft if ((vifi = oid -> oid_elements[ot-> ot_name->oid_nelem]) >= numvifs)
221 1.1 mycroft return int_SNMP_error__status_noSuchName;
222 1.1 mycroft
223 1.1 mycroft if (!get_address(oid, &addr, ot->ot_name->oid_nelem+1)
224 1.1 mycroft || !get_address(oid, &mask, ot->ot_name->oid_nelem+5))
225 1.1 mycroft return int_SNMP_error__status_noSuchName;
226 1.1 mycroft
227 1.1 mycroft if (!(bound = find_boundary(vifi, addr, mask)))
228 1.1 mycroft return int_SNMP_error__status_noSuchName;
229 1.1 mycroft break;
230 1.1 mycroft
231 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
232 1.1 mycroft if (oid->oid_nelem < ot->ot_name->oid_nelem + 9) {
233 1.1 mycroft OID new;
234 1.1 mycroft
235 1.1 mycroft if (oid->oid_nelem == ot->ot_name->oid_nelem) {
236 1.1 mycroft vifi = addr = mask = 0;
237 1.1 mycroft } else {
238 1.1 mycroft vifi = oid->oid_elements[ot->ot_name->oid_nelem];
239 1.1 mycroft get_address(oid, &addr, ot->ot_name->oid_nelem+1);
240 1.1 mycroft get_address(oid, &mask, ot->ot_name->oid_nelem+5);
241 1.1 mycroft }
242 1.1 mycroft
243 1.1 mycroft bound = next_boundary(&vifi,addr,mask);
244 1.1 mycroft if (!bound)
245 1.1 mycroft return NOTOK;
246 1.1 mycroft
247 1.1 mycroft new = oid_extend (oid, ot->ot_name->oid_nelem+9-oid->oid_nelem);
248 1.1 mycroft if (new == NULLOID)
249 1.1 mycroft return NOTOK;
250 1.1 mycroft new -> oid_elements[ot->ot_name->oid_nelem] = vifi;
251 1.1 mycroft put_address(new, bound->acl_addr, ot->ot_name->oid_nelem+1);
252 1.1 mycroft put_address(new, bound->acl_mask, ot->ot_name->oid_nelem+5);
253 1.1 mycroft
254 1.1 mycroft if (v -> name)
255 1.1 mycroft free_SNMP_ObjectName (v -> name);
256 1.1 mycroft v -> name = new;
257 1.1 mycroft } else { /* get next entry given previous */
258 1.1 mycroft int i = ot -> ot_name -> oid_nelem;
259 1.1 mycroft
260 1.1 mycroft vifi = oid->oid_elements[i];
261 1.1 mycroft get_address(oid, &addr, ot->ot_name->oid_nelem+1);
262 1.1 mycroft get_address(oid, &mask, ot->ot_name->oid_nelem+5);
263 1.1 mycroft if (!(bound = next_boundary(&vifi,addr,mask+1)))
264 1.1 mycroft return NOTOK;
265 1.1 mycroft
266 1.1 mycroft put_address(oid, bound->acl_addr, ot->ot_name->oid_nelem+1);
267 1.1 mycroft put_address(oid, bound->acl_mask, ot->ot_name->oid_nelem+5);
268 1.1 mycroft oid->oid_elements[i] = vifi;
269 1.1 mycroft oid->oid_nelem = i + 9;
270 1.1 mycroft }
271 1.1 mycroft break;
272 1.1 mycroft
273 1.1 mycroft default:
274 1.1 mycroft return int_SNMP_error__status_genErr;
275 1.1 mycroft }
276 1.1 mycroft
277 1.1 mycroft switch (ifvar) {
278 1.1 mycroft
279 1.1 mycroft case dvmrpBoundaryVifIndex:
280 1.1 mycroft return o_integer (oi, v, vifi);
281 1.1 mycroft
282 1.1 mycroft default:
283 1.1 mycroft return int_SNMP_error__status_noSuchName;
284 1.1 mycroft }
285 1.1 mycroft }
286 1.1 mycroft
287 1.1 mycroft /*
288 1.1 mycroft * Given a vif index and address, return the next greater neighbor entry
289 1.1 mycroft */
290 1.1 mycroft struct listaddr *
291 1.1 mycroft next_neighbor(vifi, addr)
292 1.1 mycroft int *vifi;
293 1.1 mycroft int addr;
294 1.1 mycroft {
295 1.1 mycroft struct listaddr *bestn, *n;
296 1.1 mycroft int i;
297 1.1 mycroft
298 1.1 mycroft for (i = *vifi; i < numvifs; i++) {
299 1.1 mycroft bestn = NULL;
300 1.1 mycroft for (n = uvifs[i].uv_neighbors; n; n=n->al_next) {
301 1.1 mycroft if ((i > *vifi || n->al_addr > addr)
302 1.1 mycroft && (!bestn || n->al_addr < bestn->al_addr))
303 1.1 mycroft bestn = n;
304 1.1 mycroft }
305 1.1 mycroft if (bestn) {
306 1.1 mycroft *vifi = i;
307 1.1 mycroft return bestn;
308 1.1 mycroft }
309 1.1 mycroft }
310 1.1 mycroft return NULL;
311 1.1 mycroft }
312 1.1 mycroft
313 1.1 mycroft /*
314 1.1 mycroft * Find a neighbor, if it exists off a given Vif
315 1.1 mycroft */
316 1.1 mycroft struct listaddr *
317 1.1 mycroft find_neighbor(vifi, addr)
318 1.1 mycroft int vifi;
319 1.1 mycroft int addr;
320 1.1 mycroft {
321 1.1 mycroft struct listaddr *n;
322 1.1 mycroft
323 1.1 mycroft for (n = uvifs[vifi].uv_neighbors; n != NULL; n = n->al_next) {
324 1.1 mycroft if (addr == n->al_addr)
325 1.1 mycroft return n;
326 1.1 mycroft }
327 1.1 mycroft return NULL;
328 1.1 mycroft }
329 1.1 mycroft
330 1.1 mycroft /*
331 1.1 mycroft * Implements the Neighbor Table portion of the DVMRP MIB
332 1.1 mycroft */
333 1.1 mycroft static int
334 1.1 mycroft o_dvmrpNeighborTable (oi, v, offset)
335 1.1 mycroft OI oi;
336 1.1 mycroft register struct type_SNMP_VarBind *v;
337 1.1 mycroft {
338 1.1 mycroft int ifvar, vifi,
339 1.1 mycroft addr;
340 1.1 mycroft register OID oid = oi -> oi_name;
341 1.1 mycroft register OT ot = oi -> oi_type;
342 1.1 mycroft struct listaddr *neighbor;
343 1.1 mycroft
344 1.1 mycroft ifvar = (int) ot -> ot_info;
345 1.1 mycroft switch (offset) {
346 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
347 1.1 mycroft if (oid->oid_nelem != ot->ot_name->oid_nelem + 5)
348 1.1 mycroft return int_SNMP_error__status_noSuchName;
349 1.1 mycroft
350 1.1 mycroft if ((vifi = oid -> oid_elements[ot-> ot_name->oid_nelem]) >= numvifs)
351 1.1 mycroft return int_SNMP_error__status_noSuchName;
352 1.1 mycroft
353 1.1 mycroft if (!get_address(oid, &addr, ot->ot_name->oid_nelem+1))
354 1.1 mycroft return int_SNMP_error__status_noSuchName;
355 1.1 mycroft
356 1.1 mycroft if (!(neighbor = find_neighbor(vifi, addr)))
357 1.1 mycroft return int_SNMP_error__status_noSuchName;
358 1.1 mycroft break;
359 1.1 mycroft
360 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
361 1.1 mycroft if (oid->oid_nelem < ot->ot_name->oid_nelem + 5) {
362 1.1 mycroft OID new;
363 1.1 mycroft
364 1.1 mycroft if (oid->oid_nelem == ot->ot_name->oid_nelem) {
365 1.1 mycroft vifi = addr = 0;
366 1.1 mycroft } else {
367 1.1 mycroft vifi = oid->oid_elements[ot->ot_name->oid_nelem];
368 1.1 mycroft get_address(oid, &addr, ot->ot_name->oid_nelem+1);
369 1.1 mycroft }
370 1.1 mycroft
371 1.1 mycroft neighbor = next_neighbor(&vifi,addr); /* Get first entry */
372 1.1 mycroft if (!neighbor)
373 1.1 mycroft return NOTOK;
374 1.1 mycroft
375 1.1 mycroft new = oid_extend (oid, ot->ot_name->oid_nelem+5-oid->oid_nelem);
376 1.1 mycroft if (new == NULLOID)
377 1.1 mycroft return NOTOK;
378 1.1 mycroft new -> oid_elements[ot->ot_name->oid_nelem] = vifi;
379 1.1 mycroft put_address(new, neighbor->al_addr, ot->ot_name->oid_nelem+1);
380 1.1 mycroft
381 1.1 mycroft if (v -> name)
382 1.1 mycroft free_SNMP_ObjectName (v -> name);
383 1.1 mycroft v -> name = new;
384 1.1 mycroft
385 1.1 mycroft } else { /* get next entry given previous */
386 1.1 mycroft int i = ot -> ot_name -> oid_nelem;
387 1.1 mycroft
388 1.1 mycroft vifi = oid->oid_elements[i];
389 1.1 mycroft get_address(oid, &addr, ot->ot_name->oid_nelem+1);
390 1.1 mycroft if (!(neighbor = next_neighbor(&vifi,addr+1)))
391 1.1 mycroft return NOTOK;
392 1.1 mycroft
393 1.1 mycroft put_address(oid, neighbor->al_addr, ot->ot_name->oid_nelem+1);
394 1.1 mycroft oid->oid_elements[i] = vifi;
395 1.1 mycroft oid->oid_nelem = i + 5;
396 1.1 mycroft }
397 1.1 mycroft break;
398 1.1 mycroft
399 1.1 mycroft default:
400 1.1 mycroft return int_SNMP_error__status_genErr;
401 1.1 mycroft }
402 1.1 mycroft
403 1.1 mycroft switch (ifvar) {
404 1.1 mycroft
405 1.1 mycroft case dvmrpNeighborUpTime: {
406 1.1 mycroft time_t currtime;
407 1.1 mycroft time(&currtime);
408 1.1 mycroft return o_integer (oi, v, (currtime - neighbor->al_ctime)*100);
409 1.1 mycroft }
410 1.1 mycroft
411 1.1 mycroft case dvmrpNeighborExpiryTime:
412 1.1 mycroft return o_integer (oi, v, (NEIGHBOR_EXPIRE_TIME-neighbor->al_timer) * 100);
413 1.1 mycroft
414 1.1 mycroft case dvmrpNeighborVersion: {
415 1.1 mycroft static char buff[15];
416 1.1 mycroft
417 1.1 mycroft sprintf(buff, "%d.%d", neighbor->al_pv, neighbor->al_mv);
418 1.1 mycroft return o_string (oi, v, buff, strlen (buff));
419 1.1 mycroft }
420 1.1 mycroft
421 1.1 mycroft case dvmrpNeighborGenerationId:
422 1.1 mycroft return o_integer (oi, v, neighbor->al_genid);
423 1.1 mycroft
424 1.1 mycroft default:
425 1.1 mycroft return int_SNMP_error__status_noSuchName;
426 1.1 mycroft }
427 1.1 mycroft }
428 1.1 mycroft
429 1.1 mycroft /*
430 1.1 mycroft * Given a virtual interface number, make sure we have the current
431 1.1 mycroft * kernel information for that Vif.
432 1.1 mycroft */
433 1.1 mycroft refresh_vif(v_req, ifnum)
434 1.1 mycroft struct sioc_vif_req *v_req;
435 1.1 mycroft int ifnum;
436 1.1 mycroft {
437 1.1 mycroft static int lastq = -1;
438 1.1 mycroft
439 1.1 mycroft if (quantum!=lastq || v_req->vifi != ifnum) {
440 1.1 mycroft lastq = quantum;
441 1.1 mycroft v_req->vifi = ifnum;
442 1.1 mycroft if (ioctl(udp_socket, SIOCGETVIFCNT, (char *)v_req) < 0)
443 1.1 mycroft v_req->icount = v_req->ocount = v_req->ibytes = v_req->obytes = 0;
444 1.1 mycroft }
445 1.1 mycroft }
446 1.1 mycroft
447 1.1 mycroft /*
448 1.1 mycroft * Implements the Multicast Routing Interface Table portion of the Multicast MIB
449 1.1 mycroft */
450 1.1 mycroft static int
451 1.1 mycroft o_ipMRouteInterfaceTable (oi, v, offset)
452 1.1 mycroft OI oi;
453 1.1 mycroft register struct type_SNMP_VarBind *v;
454 1.1 mycroft int offset;
455 1.1 mycroft {
456 1.1 mycroft int ifnum,
457 1.1 mycroft ifvar;
458 1.1 mycroft register OID oid = oi -> oi_name;
459 1.1 mycroft register OT ot = oi -> oi_type;
460 1.1 mycroft static struct sioc_vif_req v_req;
461 1.1 mycroft
462 1.1 mycroft ifvar = (int) ot -> ot_info;
463 1.1 mycroft switch (offset) {
464 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
465 1.1 mycroft if (oid -> oid_nelem != ot -> ot_name -> oid_nelem + 1)
466 1.1 mycroft return int_SNMP_error__status_noSuchName;
467 1.1 mycroft if ((ifnum = oid -> oid_elements[oid -> oid_nelem - 1]) >= numvifs)
468 1.1 mycroft return int_SNMP_error__status_noSuchName;
469 1.1 mycroft break;
470 1.1 mycroft
471 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
472 1.1 mycroft if (oid -> oid_nelem == ot -> ot_name -> oid_nelem) {
473 1.1 mycroft OID new;
474 1.1 mycroft
475 1.1 mycroft ifnum = 0;
476 1.1 mycroft
477 1.1 mycroft if ((new = oid_extend (oid, 1)) == NULLOID)
478 1.1 mycroft return NOTOK;
479 1.1 mycroft new -> oid_elements[new -> oid_nelem - 1] = ifnum;
480 1.1 mycroft
481 1.1 mycroft if (v -> name)
482 1.1 mycroft free_SNMP_ObjectName (v -> name);
483 1.1 mycroft v -> name = new;
484 1.1 mycroft
485 1.1 mycroft } else {
486 1.1 mycroft int i = ot -> ot_name -> oid_nelem;
487 1.1 mycroft
488 1.1 mycroft if ((ifnum = oid -> oid_elements[i] + 1) >= numvifs)
489 1.1 mycroft return NOTOK;
490 1.1 mycroft
491 1.1 mycroft oid -> oid_elements[i] = ifnum;
492 1.1 mycroft oid -> oid_nelem = i + 1;
493 1.1 mycroft }
494 1.1 mycroft break;
495 1.1 mycroft
496 1.1 mycroft default:
497 1.1 mycroft return int_SNMP_error__status_genErr;
498 1.1 mycroft }
499 1.1 mycroft
500 1.1 mycroft switch (ifvar) {
501 1.1 mycroft case ipMRouteInterfaceTtl:
502 1.1 mycroft return o_integer (oi, v, uvifs[ifnum].uv_threshold);
503 1.1 mycroft
504 1.1 mycroft case dvmrpVInterfaceType:
505 1.1 mycroft if (uvifs[ifnum].uv_flags & VIFF_SRCRT)
506 1.1 mycroft return o_integer (oi, v, 2);
507 1.1 mycroft else if (uvifs[ifnum].uv_flags & VIFF_TUNNEL)
508 1.1 mycroft return o_integer (oi, v, 1);
509 1.1 mycroft else if (uvifs[ifnum].uv_flags & VIFF_QUERIER)
510 1.1 mycroft return o_integer (oi, v, 3);
511 1.1 mycroft else /* SUBNET */
512 1.1 mycroft return o_integer (oi, v, 4);
513 1.1 mycroft
514 1.1 mycroft case dvmrpVInterfaceState:
515 1.1 mycroft if (uvifs[ifnum].uv_flags & VIFF_DISABLED)
516 1.1 mycroft return o_integer (oi, v, 3);
517 1.1 mycroft else if (uvifs[ifnum].uv_flags & VIFF_DOWN)
518 1.1 mycroft return o_integer (oi, v, 2);
519 1.1 mycroft else /* UP */
520 1.1 mycroft return o_integer (oi, v, 1);
521 1.1 mycroft
522 1.1 mycroft case dvmrpVInterfaceLocalAddress: {
523 1.1 mycroft struct sockaddr_in tmp;
524 1.1 mycroft tmp.sin_addr.s_addr = uvifs[ifnum].uv_lcl_addr;
525 1.1 mycroft return o_ipaddr (oi, v, &tmp);
526 1.1 mycroft }
527 1.1 mycroft
528 1.1 mycroft case dvmrpVInterfaceRemoteAddress: {
529 1.1 mycroft struct sockaddr_in tmp;
530 1.1 mycroft tmp.sin_addr.s_addr = (uvifs[ifnum].uv_flags & VIFF_TUNNEL) ?
531 1.1 mycroft uvifs[ifnum].uv_rmt_addr :
532 1.1 mycroft uvifs[ifnum].uv_subnet;
533 1.1 mycroft return o_ipaddr (oi, v, &tmp);
534 1.1 mycroft }
535 1.1 mycroft
536 1.1 mycroft case dvmrpVInterfaceRemoteSubnetMask: {
537 1.1 mycroft struct sockaddr_in tmp;
538 1.1 mycroft tmp.sin_addr.s_addr = uvifs[ifnum].uv_subnetmask;
539 1.1 mycroft return o_ipaddr (oi, v, &tmp);
540 1.1 mycroft }
541 1.1 mycroft
542 1.1 mycroft case dvmrpVInterfaceMetric:
543 1.1 mycroft return o_integer (oi, v, uvifs[ifnum].uv_metric);
544 1.1 mycroft
545 1.1 mycroft case dvmrpVInterfaceRateLimit:
546 1.1 mycroft return o_integer (oi, v, uvifs[ifnum].uv_rate_limit);
547 1.1 mycroft
548 1.1 mycroft case dvmrpVInterfaceInPkts:
549 1.1 mycroft refresh_vif(&v_req, ifnum);
550 1.1 mycroft return o_integer(oi, v, v_req.icount);
551 1.1 mycroft
552 1.1 mycroft case dvmrpVInterfaceOutPkts:
553 1.1 mycroft refresh_vif(&v_req, ifnum);
554 1.1 mycroft return o_integer(oi, v, v_req.ocount);
555 1.1 mycroft
556 1.1 mycroft case dvmrpVInterfaceInOctets:
557 1.1 mycroft refresh_vif(&v_req, ifnum);
558 1.1 mycroft return o_integer(oi, v, v_req.ibytes);
559 1.1 mycroft
560 1.1 mycroft case dvmrpVInterfaceOutOctets:
561 1.1 mycroft refresh_vif(&v_req, ifnum);
562 1.1 mycroft return o_integer(oi, v, v_req.obytes);
563 1.1 mycroft
564 1.1 mycroft default:
565 1.1 mycroft return int_SNMP_error__status_noSuchName;
566 1.1 mycroft }
567 1.1 mycroft }
568 1.1 mycroft
569 1.1 mycroft struct mib_variable {
570 1.1 mycroft char *name; /* MIB variable name */
571 1.1 mycroft int (*function)(); /* Function to call */
572 1.1 mycroft int info; /* Which variable */
573 1.1 mycroft } mib_vars[] = {
574 1.1 mycroft "ipMRouteEnable", o_scalar, ipMRouteEnable,
575 1.1 mycroft "ipMRouteUpstreamNeighbor", o_ipMRouteTable, ipMRouteUpstreamNeighbor,
576 1.1 mycroft "ipMRouteInIfIndex", o_ipMRouteTable, ipMRouteInIfIndex,
577 1.1 mycroft "ipMRouteUpTime", o_ipMRouteTable, ipMRouteUpTime,
578 1.1 mycroft "ipMRouteExpiryTime", o_ipMRouteTable, ipMRouteExpiryTime,
579 1.1 mycroft "ipMRoutePkts", o_ipMRouteTable, ipMRoutePkts,
580 1.1 mycroft "ipMRouteDifferentInIfIndexes", o_ipMRouteTable, ipMRouteDifferentInIfIndexes,
581 1.1 mycroft "ipMRouteOctets", o_ipMRouteTable, ipMRouteOctets,
582 1.1 mycroft "ipMRouteProtocol", o_ipMRouteTable, ipMRouteProtocol,
583 1.1 mycroft "ipMRouteNextHopState", o_ipMRouteNextHopTable, ipMRouteNextHopState,
584 1.1 mycroft "ipMRouteNextHopUpTime", o_ipMRouteNextHopTable, ipMRouteNextHopUpTime,
585 1.1 mycroft "ipMRouteNextHopExpiryTime", o_ipMRouteNextHopTable, ipMRouteNextHopExpiryTime,
586 1.1 mycroft "ipMRouteNextHopClosestMemberHops", o_ipMRouteNextHopTable, ipMRouteNextHopClosestMemberHops,
587 1.1 mycroft "ipMRouteNextHopProtocol", o_ipMRouteNextHopTable, ipMRouteNextHopProtocol,
588 1.1 mycroft "ipMRouteInterfaceTtl", o_ipMRouteInterfaceTable, ipMRouteInterfaceTtl,
589 1.1 mycroft "dvmrpVersion", o_scalar, dvmrpVersion,
590 1.1 mycroft "dvmrpGenerationId", o_scalar, dvmrpGenerationId,
591 1.1 mycroft "dvmrpVInterfaceType", o_ipMRouteInterfaceTable, dvmrpVInterfaceType,
592 1.1 mycroft "dvmrpVInterfaceState", o_ipMRouteInterfaceTable, dvmrpVInterfaceState,
593 1.1 mycroft "dvmrpVInterfaceLocalAddress", o_ipMRouteInterfaceTable, dvmrpVInterfaceLocalAddress,
594 1.1 mycroft "dvmrpVInterfaceRemoteAddress", o_ipMRouteInterfaceTable, dvmrpVInterfaceRemoteAddress,
595 1.1 mycroft "dvmrpVInterfaceRemoteSubnetMask", o_ipMRouteInterfaceTable, dvmrpVInterfaceRemoteSubnetMask,
596 1.1 mycroft "dvmrpVInterfaceMetric", o_ipMRouteInterfaceTable, dvmrpVInterfaceMetric,
597 1.1 mycroft "dvmrpVInterfaceRateLimit", o_ipMRouteInterfaceTable, dvmrpVInterfaceRateLimit,
598 1.1 mycroft "dvmrpVInterfaceInPkts", o_ipMRouteInterfaceTable, dvmrpVInterfaceInPkts,
599 1.1 mycroft "dvmrpVInterfaceOutPkts", o_ipMRouteInterfaceTable, dvmrpVInterfaceOutPkts,
600 1.1 mycroft "dvmrpVInterfaceInOctets", o_ipMRouteInterfaceTable, dvmrpVInterfaceInOctets,
601 1.1 mycroft "dvmrpVInterfaceOutOctets", o_ipMRouteInterfaceTable, dvmrpVInterfaceOutOctets,
602 1.1 mycroft "dvmrpNeighborUpTime", o_dvmrpNeighborTable, dvmrpNeighborUpTime,
603 1.1 mycroft "dvmrpNeighborExpiryTime", o_dvmrpNeighborTable, dvmrpNeighborExpiryTime,
604 1.1 mycroft "dvmrpNeighborVersion", o_dvmrpNeighborTable, dvmrpNeighborVersion,
605 1.1 mycroft "dvmrpNeighborGenerationId",o_dvmrpNeighborTable, dvmrpNeighborGenerationId,
606 1.1 mycroft "dvmrpRouteUpstreamNeighbor", o_dvmrpRouteTable, dvmrpRouteUpstreamNeighbor,
607 1.1 mycroft "dvmrpRouteInVifIndex", o_dvmrpRouteTable, dvmrpRouteInVifIndex,
608 1.1 mycroft "dvmrpRouteMetric", o_dvmrpRouteTable, dvmrpRouteMetric,
609 1.1 mycroft "dvmrpRouteExpiryTime", o_dvmrpRouteTable, dvmrpRouteExpiryTime,
610 1.1 mycroft "dvmrpRouteNextHopType", o_dvmrpRouteNextHopTable, dvmrpRouteNextHopType,
611 1.1 mycroft "dvmrpBoundaryVifIndex", o_dvmrpBoundaryTable, dvmrpBoundaryVifIndex,
612 1.1 mycroft 0, 0, 0
613 1.1 mycroft };
614 1.1 mycroft
615 1.1 mycroft /*
616 1.1 mycroft * Register variables as part of the MIBs
617 1.1 mycroft */
618 1.1 mycroft void
619 1.1 mycroft init_mib()
620 1.1 mycroft {
621 1.1 mycroft register OT ot;
622 1.1 mycroft int i;
623 1.1 mycroft
624 1.1 mycroft for (i=0; mib_vars[i].name; i++)
625 1.1 mycroft if (ot=text2obj(mib_vars[i].name)) {
626 1.1 mycroft ot->ot_getfnx = mib_vars[i].function;
627 1.1 mycroft ot->ot_info = (caddr_t)mib_vars[i].info;
628 1.1 mycroft }
629 1.1 mycroft }
630 1.1 mycroft
631 1.1 mycroft /*
632 1.1 mycroft * Initialize the SNMP part of mrouted
633 1.1 mycroft */
634 1.1 mycroft void
635 1.1 mycroft snmp_init()
636 1.1 mycroft {
637 1.1 mycroft OT ot;
638 1.1 mycroft int i;
639 1.1 mycroft
640 1.1 mycroft if (readobjects("mrouted.defs") == NOTOK)
641 1.1 mycroft log(LOG_ERR, 0, "readobjects: %s", PY_pepy);
642 1.1 mycroft for (i=0; i < NUMMIBS; i++) {
643 1.1 mycroft if ((ot = text2obj(mibs[i])) == NULL)
644 1.1 mycroft log(LOG_ERR, 0, "object \"%s\" not in \"%s\"",
645 1.1 mycroft mibs[i], "mrouted.defs");
646 1.1 mycroft subtree[i] = ot -> ot_name;
647 1.1 mycroft }
648 1.1 mycroft init_mib();
649 1.1 mycroft try_smux_init();
650 1.1 mycroft }
651 1.1 mycroft
652 1.1 mycroft /*
653 1.1 mycroft * Process an SNMP "get" or "get-next" request
654 1.1 mycroft */
655 1.1 mycroft static
656 1.1 mycroft get_smux (pdu, offset)
657 1.1 mycroft register struct type_SNMP_GetRequest__PDU *pdu;
658 1.1 mycroft int offset;
659 1.1 mycroft {
660 1.1 mycroft int idx,
661 1.1 mycroft status;
662 1.1 mycroft object_instance ois;
663 1.1 mycroft register struct type_SNMP_VarBindList *vp;
664 1.1 mycroft IFP method;
665 1.1 mycroft
666 1.1 mycroft quantum = pdu -> request__id;
667 1.1 mycroft idx = 0;
668 1.1 mycroft for (vp = pdu -> variable__bindings; vp; vp = vp -> next) {
669 1.1 mycroft register OI oi;
670 1.1 mycroft register OT ot;
671 1.1 mycroft register struct type_SNMP_VarBind *v = vp -> VarBind;
672 1.1 mycroft
673 1.1 mycroft idx++;
674 1.1 mycroft
675 1.1 mycroft if (offset == type_SNMP_SMUX__PDUs_get__next__request) {
676 1.1 mycroft if ((oi = name2inst (v -> name)) == NULLOI
677 1.1 mycroft && (oi = next2inst (v -> name)) == NULLOI)
678 1.1 mycroft goto no_name;
679 1.1 mycroft
680 1.1 mycroft if ((ot = oi -> oi_type) -> ot_getfnx == NULLIFP)
681 1.1 mycroft goto get_next;
682 1.1 mycroft }
683 1.1 mycroft else
684 1.1 mycroft if ((oi = name2inst (v -> name)) == NULLOI
685 1.1 mycroft || (ot = oi -> oi_type) -> ot_getfnx
686 1.1 mycroft == NULLIFP) {
687 1.1 mycroft no_name: ;
688 1.1 mycroft pdu -> error__status =
689 1.1 mycroft int_SNMP_error__status_noSuchName;
690 1.1 mycroft goto out;
691 1.1 mycroft }
692 1.1 mycroft
693 1.1 mycroft try_again: ;
694 1.1 mycroft switch (offset) {
695 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
696 1.1 mycroft if (!(method = ot -> ot_getfnx))
697 1.1 mycroft goto no_name;
698 1.1 mycroft break;
699 1.1 mycroft
700 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
701 1.1 mycroft if (!(method = ot -> ot_getfnx))
702 1.1 mycroft goto get_next;
703 1.1 mycroft break;
704 1.1 mycroft
705 1.1 mycroft case type_SNMP_SMUX__PDUs_set__request:
706 1.1 mycroft if (!(method = ot -> ot_setfnx))
707 1.1 mycroft goto no_name;
708 1.1 mycroft break;
709 1.1 mycroft
710 1.1 mycroft default:
711 1.1 mycroft goto no_name;
712 1.1 mycroft }
713 1.1 mycroft
714 1.1 mycroft switch (status = (*ot -> ot_getfnx) (oi, v, offset)) {
715 1.1 mycroft case NOTOK: /* get-next wants a bump */
716 1.1 mycroft get_next: ;
717 1.1 mycroft oi = &ois;
718 1.1 mycroft for (;;) {
719 1.1 mycroft if ((ot = ot -> ot_next) == NULLOT) {
720 1.1 mycroft pdu -> error__status =
721 1.1 mycroft int_SNMP_error__status_noSuchName;
722 1.1 mycroft goto out;
723 1.1 mycroft }
724 1.1 mycroft oi -> oi_name =
725 1.1 mycroft (oi -> oi_type = ot) -> ot_name;
726 1.1 mycroft if (ot -> ot_getfnx)
727 1.1 mycroft goto try_again;
728 1.1 mycroft }
729 1.1 mycroft
730 1.1 mycroft case int_SNMP_error__status_noError:
731 1.1 mycroft break;
732 1.1 mycroft
733 1.1 mycroft default:
734 1.1 mycroft pdu -> error__status = status;
735 1.1 mycroft goto out;
736 1.1 mycroft }
737 1.1 mycroft }
738 1.1 mycroft idx = 0;
739 1.1 mycroft
740 1.1 mycroft out: ;
741 1.1 mycroft pdu -> error__index = idx;
742 1.1 mycroft
743 1.1 mycroft if (smux_response (pdu) == NOTOK) {
744 1.1 mycroft log(LOG_WARNING,0,"smux_response: %s [%s]",
745 1.1 mycroft smux_error (smux_errno), smux_info);
746 1.1 mycroft smux_fd = NOTOK;
747 1.1 mycroft }
748 1.1 mycroft }
749 1.1 mycroft
750 1.1 mycroft /*
751 1.1 mycroft * Handle SNMP "set" request by replying that it is illegal
752 1.1 mycroft */
753 1.1 mycroft static
754 1.1 mycroft set_smux(event)
755 1.1 mycroft struct type_SNMP_SMUX__PDUs *event;
756 1.1 mycroft {
757 1.1 mycroft switch (event -> offset) {
758 1.1 mycroft case type_SNMP_SMUX__PDUs_set__request:
759 1.1 mycroft {
760 1.1 mycroft register struct type_SNMP_GetResponse__PDU *pdu =
761 1.1 mycroft event -> un.get__response;
762 1.1 mycroft
763 1.1 mycroft pdu -> error__status = int_SNMP_error__status_noSuchName;
764 1.1 mycroft pdu -> error__index = pdu -> variable__bindings ? 1 : 0;
765 1.1 mycroft
766 1.1 mycroft if (smux_response (pdu) == NOTOK) {
767 1.1 mycroft log(LOG_WARNING, 0,
768 1.1 mycroft "smux_response: %s [%s]",
769 1.1 mycroft smux_error (smux_errno),
770 1.1 mycroft smux_info);
771 1.1 mycroft smux_fd = NOTOK;
772 1.1 mycroft }
773 1.1 mycroft }
774 1.1 mycroft break;
775 1.1 mycroft
776 1.1 mycroft case type_SNMP_SMUX__PDUs_commitOrRollback:
777 1.1 mycroft {
778 1.1 mycroft struct type_SNMP_SOutPDU *cor =
779 1.1 mycroft event -> un.commitOrRollback;
780 1.1 mycroft
781 1.1 mycroft if (cor -> parm == int_SNMP_SOutPDU_commit) {
782 1.1 mycroft /* "should not happen" */
783 1.1 mycroft (void) smux_close (protocolError);
784 1.1 mycroft smux_fd = NOTOK;
785 1.1 mycroft }
786 1.1 mycroft }
787 1.1 mycroft break;
788 1.1 mycroft }
789 1.1 mycroft }
790 1.1 mycroft
791 1.1 mycroft /*
792 1.1 mycroft * Handle an incoming SNMP message
793 1.1 mycroft */
794 1.1 mycroft void
795 1.1 mycroft doit_smux()
796 1.1 mycroft {
797 1.1 mycroft struct type_SNMP_SMUX__PDUs *event;
798 1.1 mycroft
799 1.1 mycroft if (smux_wait(&event, NOTOK)==NOTOK) {
800 1.1 mycroft if (smux_errno==inProgress)
801 1.1 mycroft return;
802 1.1 mycroft log(LOG_WARNING, 0, "smux_wait: %s [%s]", smux_error(smux_errno),
803 1.1 mycroft smux_info);
804 1.1 mycroft smux_fd = NOTOK;
805 1.1 mycroft return;
806 1.1 mycroft }
807 1.1 mycroft
808 1.1 mycroft switch (event -> offset) {
809 1.1 mycroft case type_SNMP_SMUX__PDUs_registerResponse:
810 1.1 mycroft {
811 1.1 mycroft struct type_SNMP_RRspPDU *rsp =
812 1.1 mycroft event -> un.registerResponse;
813 1.1 mycroft
814 1.1 mycroft if (rsp -> parm == int_SNMP_RRspPDU_failure) {
815 1.1 mycroft log(LOG_WARNING,0,"SMUX registration of subtree failed");
816 1.1 mycroft dont_bother_anymore = 1;
817 1.1 mycroft (void) smux_close (goingDown);
818 1.1 mycroft break;
819 1.1 mycroft }
820 1.1 mycroft }
821 1.1 mycroft if (smux_trap(NULLOID, int_SNMP_generic__trap_coldStart, 0,
822 1.1 mycroft (struct type_SNMP_VarBindList *)0) == NOTOK) {
823 1.1 mycroft log(LOG_WARNING,0,"smux_trap: %s [%s]", smux_error (smux_errno),
824 1.1 mycroft smux_info);
825 1.1 mycroft break;
826 1.1 mycroft }
827 1.1 mycroft return;
828 1.1 mycroft
829 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
830 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
831 1.1 mycroft get_smux (event -> un.get__request, event -> offset);
832 1.1 mycroft return;
833 1.1 mycroft
834 1.1 mycroft case type_SNMP_SMUX__PDUs_close:
835 1.1 mycroft log(LOG_WARNING, 0, "SMUX close: %s",
836 1.1 mycroft smux_error (event -> un.close -> parm));
837 1.1 mycroft break;
838 1.1 mycroft
839 1.1 mycroft case type_SNMP_SMUX__PDUs_set__request:
840 1.1 mycroft case type_SNMP_SMUX__PDUs_commitOrRollback:
841 1.1 mycroft set_smux (event);
842 1.1 mycroft return;
843 1.1 mycroft
844 1.1 mycroft default:
845 1.1 mycroft log(LOG_WARNING,0,"bad SMUX operation: %d", event -> offset);
846 1.1 mycroft (void) smux_close (protocolError);
847 1.1 mycroft break;
848 1.1 mycroft }
849 1.1 mycroft smux_fd = NOTOK;
850 1.1 mycroft }
851 1.1 mycroft
852 1.1 mycroft /*
853 1.1 mycroft * Inform snmpd that we are here and handling our MIBs
854 1.1 mycroft */
855 1.1 mycroft void
856 1.1 mycroft start_smux()
857 1.1 mycroft {
858 1.1 mycroft int i;
859 1.1 mycroft
860 1.1 mycroft for (i=0; i<NUMMIBS; i++) {
861 1.1 mycroft if ((se = getsmuxEntrybyname (mibs[i])) == NULL) {
862 1.1 mycroft log(LOG_WARNING,0,"no SMUX entry for \"%s\"", mibs[i]);
863 1.1 mycroft return;
864 1.1 mycroft }
865 1.1 mycroft
866 1.1 mycroft /* Only open a new connection the first time through */
867 1.1 mycroft if (!i) {
868 1.1 mycroft if (smux_simple_open(&se->se_identity, mibs[i],
869 1.1 mycroft se->se_password, strlen(se->se_password))==NOTOK) {
870 1.1 mycroft if (smux_errno == inProgress)
871 1.1 mycroft return;
872 1.1 mycroft
873 1.1 mycroft log(LOG_WARNING, 0,"smux_simple_open: %s [%s]",
874 1.1 mycroft smux_error(smux_errno), smux_info);
875 1.1 mycroft smux_fd = NOTOK;
876 1.1 mycroft return;
877 1.1 mycroft }
878 1.1 mycroft log(LOG_NOTICE,0, "SMUX open: %s \"%s\"",
879 1.1 mycroft oid2ode (&se->se_identity), se->se_name);
880 1.1 mycroft rock_and_roll = 1;
881 1.1 mycroft }
882 1.1 mycroft
883 1.1 mycroft if (smux_register(subtree[i], -1, readWrite)==NOTOK) {
884 1.1 mycroft log(LOG_WARNING, 0,"smux_register: %s [%s]", smux_error(smux_errno),
885 1.1 mycroft smux_info);
886 1.1 mycroft smux_fd = NOTOK;
887 1.1 mycroft return;
888 1.1 mycroft }
889 1.1 mycroft }
890 1.1 mycroft log(LOG_NOTICE, 0, "SMUX registered");
891 1.1 mycroft }
892 1.1 mycroft
893 1.1 mycroft /*
894 1.1 mycroft * Implements the DVMRP Route Table portion of the DVMRP MIB
895 1.1 mycroft */
896 1.1 mycroft int
897 1.1 mycroft o_dvmrpRouteTable (oi, v, offset)
898 1.1 mycroft OI oi;
899 1.1 mycroft register struct type_SNMP_VarBind *v;
900 1.1 mycroft int offset;
901 1.1 mycroft {
902 1.1 mycroft u_long src, mask;
903 1.1 mycroft int ifvar;
904 1.1 mycroft register OID oid = oi -> oi_name;
905 1.1 mycroft register OT ot = oi -> oi_type;
906 1.1 mycroft struct rtentry *rt = NULL;
907 1.1 mycroft
908 1.1 mycroft ifvar = (int) ot -> ot_info;
909 1.1 mycroft switch (offset) {
910 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
911 1.1 mycroft if (!get_address(oid, &src, ot->ot_name->oid_nelem)
912 1.1 mycroft || !get_address(oid, &mask, ot->ot_name->oid_nelem+4)
913 1.1 mycroft || !(rt = snmp_find_route(src,mask)))
914 1.1 mycroft return int_SNMP_error__status_noSuchName;
915 1.1 mycroft break;
916 1.1 mycroft
917 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
918 1.1 mycroft
919 1.1 mycroft /* Check if we're requesting the first row */
920 1.1 mycroft if (oid->oid_nelem < ot->ot_name->oid_nelem+8) {
921 1.1 mycroft OID new;
922 1.1 mycroft
923 1.1 mycroft /* Get partial specification (if any) */
924 1.1 mycroft get_address(oid, &src, ot->ot_name->oid_nelem);
925 1.1 mycroft get_address(oid, &mask, ot->ot_name->oid_nelem+4);
926 1.1 mycroft
927 1.1 mycroft if (!next_route(&rt,src,mask)) /* Get first entry */
928 1.1 mycroft return NOTOK;
929 1.1 mycroft
930 1.1 mycroft /* Extend by 8 more ints to hold index columns */
931 1.1 mycroft new = oid_extend (oid, ot->ot_name->oid_nelem+8-oid->oid_nelem);
932 1.1 mycroft if (new == NULLOID)
933 1.1 mycroft return NOTOK;
934 1.1 mycroft
935 1.1 mycroft put_address(new, rt->rt_origin, ot->ot_name->oid_nelem);
936 1.1 mycroft put_address(new, rt->rt_originmask, ot->ot_name->oid_nelem+4);
937 1.1 mycroft
938 1.1 mycroft if (v -> name)
939 1.1 mycroft free_SNMP_ObjectName (v -> name);
940 1.1 mycroft v -> name = new;
941 1.1 mycroft
942 1.1 mycroft /* Else we start from a previous row */
943 1.1 mycroft } else {
944 1.1 mycroft int i = ot -> ot_name -> oid_nelem;
945 1.1 mycroft
946 1.1 mycroft /* Get the lowest entry in the table > the given grp/src/mask */
947 1.1 mycroft get_address(oid, &src, ot->ot_name->oid_nelem);
948 1.1 mycroft get_address(oid, &mask, ot->ot_name->oid_nelem+4);
949 1.1 mycroft if (!next_route(&rt, src,mask))
950 1.1 mycroft return NOTOK;
951 1.1 mycroft
952 1.1 mycroft put_address(oid, rt->rt_origin, ot->ot_name->oid_nelem);
953 1.1 mycroft put_address(oid, rt->rt_originmask, ot->ot_name->oid_nelem+4);
954 1.1 mycroft }
955 1.1 mycroft break;
956 1.1 mycroft
957 1.1 mycroft default:
958 1.1 mycroft return int_SNMP_error__status_genErr;
959 1.1 mycroft }
960 1.1 mycroft
961 1.1 mycroft switch (ifvar) {
962 1.1 mycroft case dvmrpRouteUpstreamNeighbor: {
963 1.1 mycroft struct sockaddr_in tmp;
964 1.1 mycroft tmp.sin_addr.s_addr = rt->rt_gateway;
965 1.1 mycroft return o_ipaddr (oi, v, &tmp);
966 1.1 mycroft }
967 1.1 mycroft
968 1.1 mycroft case dvmrpRouteInVifIndex:
969 1.1 mycroft return o_integer (oi, v, rt->rt_parent);
970 1.1 mycroft
971 1.1 mycroft case dvmrpRouteMetric:
972 1.1 mycroft return o_integer (oi, v, rt->rt_metric);
973 1.1 mycroft
974 1.1 mycroft case dvmrpRouteExpiryTime:
975 1.1 mycroft return o_integer (oi, v, rt->rt_timer*100);
976 1.1 mycroft
977 1.1 mycroft default:
978 1.1 mycroft return int_SNMP_error__status_noSuchName;
979 1.1 mycroft }
980 1.1 mycroft }
981 1.1 mycroft
982 1.1 mycroft /*
983 1.1 mycroft * Implements the DVMRP Routing Next Hop Table portion of the DVMRP MIB
984 1.1 mycroft */
985 1.1 mycroft int
986 1.1 mycroft o_dvmrpRouteNextHopTable (oi, v, offset)
987 1.1 mycroft OI oi;
988 1.1 mycroft register struct type_SNMP_VarBind *v;
989 1.1 mycroft int offset;
990 1.1 mycroft {
991 1.1 mycroft u_long src, mask;
992 1.1 mycroft vifi_t vifi;
993 1.1 mycroft int ifvar;
994 1.1 mycroft register OID oid = oi -> oi_name;
995 1.1 mycroft register OT ot = oi -> oi_type;
996 1.1 mycroft struct rtentry *rt = NULL;
997 1.1 mycroft
998 1.1 mycroft ifvar = (int) ot -> ot_info;
999 1.1 mycroft switch (offset) {
1000 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
1001 1.1 mycroft if (oid->oid_nelem != ot->ot_name->oid_nelem+9)
1002 1.1 mycroft return int_SNMP_error__status_noSuchName;
1003 1.1 mycroft
1004 1.1 mycroft if (!get_address(oid, &src, ot->ot_name->oid_nelem)
1005 1.1 mycroft || !get_address(oid, &mask, ot->ot_name->oid_nelem+4)
1006 1.1 mycroft || (!(rt=snmp_find_route(src,mask))))
1007 1.1 mycroft return int_SNMP_error__status_noSuchName;
1008 1.1 mycroft
1009 1.1 mycroft vifi = oid->oid_elements[ot->ot_name->oid_nelem+8];
1010 1.1 mycroft if (!(VIFM_ISSET(vifi, rt->rt_children)))
1011 1.1 mycroft return int_SNMP_error__status_noSuchName;
1012 1.1 mycroft break;
1013 1.1 mycroft
1014 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
1015 1.1 mycroft
1016 1.1 mycroft /* Check if we're requesting the first row */
1017 1.1 mycroft if (oid->oid_nelem < ot->ot_name->oid_nelem+9) {
1018 1.1 mycroft OID new;
1019 1.1 mycroft
1020 1.1 mycroft get_address(oid, &src, ot->ot_name->oid_nelem);
1021 1.1 mycroft get_address(oid, &mask, ot->ot_name->oid_nelem+4);
1022 1.1 mycroft
1023 1.1 mycroft /* Find first child vif */
1024 1.1 mycroft vifi=0;
1025 1.1 mycroft if (!next_route_child(&rt, src, mask, &vifi))
1026 1.1 mycroft return NOTOK;
1027 1.1 mycroft
1028 1.1 mycroft /* Extend by 9 more ints to hold index columns */
1029 1.1 mycroft new = oid_extend (oid, ot->ot_name->oid_nelem+9-oid->oid_nelem);
1030 1.1 mycroft if (new == NULLOID)
1031 1.1 mycroft return NOTOK;
1032 1.1 mycroft
1033 1.1 mycroft put_address(new, rt->rt_origin, ot->ot_name->oid_nelem);
1034 1.1 mycroft put_address(new, rt->rt_originmask, ot->ot_name->oid_nelem+4);
1035 1.1 mycroft new->oid_elements[ot->ot_name->oid_nelem+8] = vifi;
1036 1.1 mycroft
1037 1.1 mycroft if (v -> name)
1038 1.1 mycroft free_SNMP_ObjectName (v -> name);
1039 1.1 mycroft v -> name = new;
1040 1.1 mycroft
1041 1.1 mycroft /* Else we start from a previous row */
1042 1.1 mycroft } else {
1043 1.1 mycroft int i = ot -> ot_name -> oid_nelem;
1044 1.1 mycroft
1045 1.1 mycroft /* Get the lowest entry in the table > the given grp/src/mask */
1046 1.1 mycroft vifi = oid->oid_elements[oid->oid_nelem-1] + 1;
1047 1.1 mycroft if (!get_address(oid, &src, ot->ot_name->oid_nelem)
1048 1.1 mycroft || !get_address(oid, &mask, ot->ot_name->oid_nelem+4)
1049 1.1 mycroft || !next_route_child(&rt, src, mask, &vifi))
1050 1.1 mycroft return NOTOK;
1051 1.1 mycroft
1052 1.1 mycroft put_address(oid, rt->rt_origin, ot->ot_name->oid_nelem);
1053 1.1 mycroft put_address(oid, rt->rt_originmask, ot->ot_name->oid_nelem+4);
1054 1.1 mycroft oid->oid_elements[ot->ot_name->oid_nelem+8] = vifi;
1055 1.1 mycroft }
1056 1.1 mycroft break;
1057 1.1 mycroft
1058 1.1 mycroft default:
1059 1.1 mycroft return int_SNMP_error__status_genErr;
1060 1.1 mycroft }
1061 1.1 mycroft
1062 1.1 mycroft switch (ifvar) {
1063 1.1 mycroft
1064 1.1 mycroft case dvmrpRouteNextHopType:
1065 1.1 mycroft return o_integer (oi, v, (VIFM_ISSET(vifi, rt->rt_leaves))? 1 : 2);
1066 1.1 mycroft
1067 1.1 mycroft default:
1068 1.1 mycroft return int_SNMP_error__status_noSuchName;
1069 1.1 mycroft }
1070 1.1 mycroft }
1071 1.1 mycroft
1072 1.1 mycroft /*
1073 1.1 mycroft * Implements the IP Multicast Route Table portion of the Multicast MIB
1074 1.1 mycroft */
1075 1.1 mycroft int
1076 1.1 mycroft o_ipMRouteTable (oi, v, offset)
1077 1.1 mycroft OI oi;
1078 1.1 mycroft register struct type_SNMP_VarBind *v;
1079 1.1 mycroft int offset;
1080 1.1 mycroft {
1081 1.1 mycroft u_long src, grp, mask;
1082 1.1 mycroft int ifvar;
1083 1.1 mycroft register OID oid = oi -> oi_name;
1084 1.1 mycroft register OT ot = oi -> oi_type;
1085 1.1 mycroft struct gtable *gt = NULL;
1086 1.1 mycroft struct stable *st = NULL;
1087 1.1 mycroft static struct sioc_sg_req sg_req;
1088 1.1 mycroft
1089 1.1 mycroft ifvar = (int) ot -> ot_info;
1090 1.1 mycroft switch (offset) {
1091 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
1092 1.1 mycroft if (!get_address(oid, &grp, ot->ot_name->oid_nelem)
1093 1.1 mycroft || !get_address(oid, &src, ot->ot_name->oid_nelem+4)
1094 1.1 mycroft || !get_address(oid, &mask, ot->ot_name->oid_nelem+8)
1095 1.1 mycroft || (mask != 0xFFFFFFFF) /* we keep sources now, not subnets */
1096 1.1 mycroft || !(gt = find_grp(grp))
1097 1.1 mycroft || !(st = find_grp_src(gt,src)))
1098 1.1 mycroft return int_SNMP_error__status_noSuchName;
1099 1.1 mycroft break;
1100 1.1 mycroft
1101 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
1102 1.1 mycroft
1103 1.1 mycroft /* Check if we're requesting the first row */
1104 1.1 mycroft if (oid->oid_nelem < ot->ot_name->oid_nelem+12) {
1105 1.1 mycroft OID new;
1106 1.1 mycroft
1107 1.1 mycroft /* Get partial specification (if any) */
1108 1.1 mycroft get_address(oid, &grp, ot->ot_name->oid_nelem);
1109 1.1 mycroft get_address(oid, &src, ot->ot_name->oid_nelem+4);
1110 1.1 mycroft get_address(oid, &mask, ot->ot_name->oid_nelem+8);
1111 1.1 mycroft
1112 1.1 mycroft if (!next_grp_src_mask(>,&st,grp,src,mask)) /* Get first entry */
1113 1.1 mycroft return NOTOK;
1114 1.1 mycroft
1115 1.1 mycroft /* Extend by 12 more ints to hold index columns */
1116 1.1 mycroft new = oid_extend (oid, ot->ot_name->oid_nelem+12-oid->oid_nelem);
1117 1.1 mycroft if (new == NULLOID)
1118 1.1 mycroft return NOTOK;
1119 1.1 mycroft
1120 1.1 mycroft put_address(new, gt->gt_mcastgrp, ot->ot_name->oid_nelem);
1121 1.1 mycroft put_address(new, st->st_origin, ot->ot_name->oid_nelem+4);
1122 1.1 mycroft put_address(new, 0xFFFFFFFF, ot->ot_name->oid_nelem+8);
1123 1.1 mycroft
1124 1.1 mycroft if (v -> name)
1125 1.1 mycroft free_SNMP_ObjectName (v -> name);
1126 1.1 mycroft v -> name = new;
1127 1.1 mycroft
1128 1.1 mycroft /* Else we start from a previous row */
1129 1.1 mycroft } else {
1130 1.1 mycroft int i = ot -> ot_name -> oid_nelem;
1131 1.1 mycroft
1132 1.1 mycroft /* Get the lowest entry in the table > the given grp/src/mask */
1133 1.1 mycroft get_address(oid, &grp, ot->ot_name->oid_nelem);
1134 1.1 mycroft get_address(oid, &src, ot->ot_name->oid_nelem+4);
1135 1.1 mycroft get_address(oid, &mask, ot->ot_name->oid_nelem+8);
1136 1.1 mycroft if (!next_grp_src_mask(>, &st, grp,src,mask))
1137 1.1 mycroft return NOTOK;
1138 1.1 mycroft
1139 1.1 mycroft put_address(oid, gt->gt_mcastgrp, ot->ot_name->oid_nelem);
1140 1.1 mycroft put_address(oid, st->st_origin, ot->ot_name->oid_nelem+4);
1141 1.1 mycroft put_address(oid, 0xFFFFFFFF, ot->ot_name->oid_nelem+8);
1142 1.1 mycroft }
1143 1.1 mycroft break;
1144 1.1 mycroft
1145 1.1 mycroft default:
1146 1.1 mycroft return int_SNMP_error__status_genErr;
1147 1.1 mycroft }
1148 1.1 mycroft
1149 1.1 mycroft switch (ifvar) {
1150 1.1 mycroft case ipMRouteUpstreamNeighbor: {
1151 1.1 mycroft struct sockaddr_in tmp;
1152 1.1 mycroft tmp.sin_addr.s_addr = gt->gt_route->rt_gateway;
1153 1.1 mycroft return o_ipaddr (oi, v, &tmp);
1154 1.1 mycroft }
1155 1.1 mycroft
1156 1.1 mycroft case ipMRouteInIfIndex:
1157 1.1 mycroft return o_integer (oi, v, gt->gt_route->rt_parent);
1158 1.1 mycroft
1159 1.1 mycroft case ipMRouteUpTime: {
1160 1.1 mycroft time_t currtime;
1161 1.1 mycroft time(&currtime);
1162 1.1 mycroft return o_integer (oi, v, (currtime - gt->gt_ctime)*100);
1163 1.1 mycroft }
1164 1.1 mycroft
1165 1.1 mycroft case ipMRouteExpiryTime:
1166 1.1 mycroft return o_integer (oi, v, gt->gt_timer*100);
1167 1.1 mycroft
1168 1.1 mycroft case ipMRoutePkts:
1169 1.1 mycroft refresh_sg(&sg_req, gt, st);
1170 1.1 mycroft return o_integer (oi, v, sg_req.pktcnt);
1171 1.1 mycroft
1172 1.1 mycroft case ipMRouteOctets:
1173 1.1 mycroft refresh_sg(&sg_req, gt, st);
1174 1.1 mycroft return o_integer (oi, v, sg_req.bytecnt);
1175 1.1 mycroft
1176 1.1 mycroft case ipMRouteDifferentInIfIndexes:
1177 1.1 mycroft refresh_sg(&sg_req, gt, st);
1178 1.1 mycroft return o_integer (oi, v, sg_req.wrong_if);
1179 1.1 mycroft
1180 1.1 mycroft case ipMRouteProtocol:
1181 1.1 mycroft return o_integer (oi, v, 4);
1182 1.1 mycroft
1183 1.1 mycroft default:
1184 1.1 mycroft return int_SNMP_error__status_noSuchName;
1185 1.1 mycroft }
1186 1.1 mycroft }
1187 1.1 mycroft
1188 1.1 mycroft /*
1189 1.1 mycroft * Implements the IP Multicast Routing Next Hop Table portion of the Multicast
1190 1.1 mycroft * MIB
1191 1.1 mycroft */
1192 1.1 mycroft int
1193 1.1 mycroft o_ipMRouteNextHopTable (oi, v, offset)
1194 1.1 mycroft OI oi;
1195 1.1 mycroft register struct type_SNMP_VarBind *v;
1196 1.1 mycroft int offset;
1197 1.1 mycroft {
1198 1.1 mycroft u_long src, grp, mask, addr;
1199 1.1 mycroft vifi_t vifi;
1200 1.1 mycroft int ifvar;
1201 1.1 mycroft register OID oid = oi -> oi_name;
1202 1.1 mycroft register OT ot = oi -> oi_type;
1203 1.1 mycroft struct gtable *gt;
1204 1.1 mycroft struct stable *st;
1205 1.1 mycroft
1206 1.1 mycroft ifvar = (int) ot -> ot_info;
1207 1.1 mycroft switch (offset) {
1208 1.1 mycroft case type_SNMP_SMUX__PDUs_get__request:
1209 1.1 mycroft if (oid->oid_nelem != ot->ot_name->oid_nelem+17)
1210 1.1 mycroft return int_SNMP_error__status_noSuchName;
1211 1.1 mycroft
1212 1.1 mycroft if (!get_address(oid, &grp, ot->ot_name->oid_nelem)
1213 1.1 mycroft || !get_address(oid, &src, ot->ot_name->oid_nelem+4)
1214 1.1 mycroft || !get_address(oid, &mask, ot->ot_name->oid_nelem+8)
1215 1.1 mycroft || !get_address(oid, &addr, ot->ot_name->oid_nelem+13)
1216 1.1 mycroft || grp!=addr
1217 1.1 mycroft || mask!=0xFFFFFFFF
1218 1.1 mycroft || (!(gt=find_grp(grp)))
1219 1.1 mycroft || (!(st=find_grp_src(gt,src))))
1220 1.1 mycroft return int_SNMP_error__status_noSuchName;
1221 1.1 mycroft
1222 1.1 mycroft vifi = oid->oid_elements[ot->ot_name->oid_nelem+12];
1223 1.1 mycroft if (!(VIFM_ISSET(vifi, gt->gt_route->rt_children)))
1224 1.1 mycroft return int_SNMP_error__status_noSuchName;
1225 1.1 mycroft break;
1226 1.1 mycroft
1227 1.1 mycroft case type_SNMP_SMUX__PDUs_get__next__request:
1228 1.1 mycroft
1229 1.1 mycroft /* Check if we're requesting the first row */
1230 1.1 mycroft if (oid->oid_nelem < ot->ot_name->oid_nelem+17) {
1231 1.1 mycroft OID new;
1232 1.1 mycroft
1233 1.1 mycroft get_address(oid, &grp, ot->ot_name->oid_nelem);
1234 1.1 mycroft get_address(oid, &src, ot->ot_name->oid_nelem+4);
1235 1.1 mycroft get_address(oid, &mask, ot->ot_name->oid_nelem+8);
1236 1.1 mycroft
1237 1.1 mycroft /* Find first child vif */
1238 1.1 mycroft vifi=0;
1239 1.1 mycroft if (!next_child(>, &st, grp, src, mask, &vifi))
1240 1.1 mycroft return NOTOK;
1241 1.1 mycroft
1242 1.1 mycroft /* Extend by 17 more ints to hold index columns */
1243 1.1 mycroft new = oid_extend (oid, ot->ot_name->oid_nelem+17-oid->oid_nelem);
1244 1.1 mycroft if (new == NULLOID)
1245 1.1 mycroft return NOTOK;
1246 1.1 mycroft
1247 1.1 mycroft put_address(new, gt->gt_mcastgrp, ot->ot_name->oid_nelem);
1248 1.1 mycroft put_address(new, st->st_origin, ot->ot_name->oid_nelem+4);
1249 1.1 mycroft put_address(new, 0xFFFFFFFF, ot->ot_name->oid_nelem+8);
1250 1.1 mycroft new->oid_elements[ot->ot_name->oid_nelem+12] = vifi;
1251 1.1 mycroft put_address(new, gt->gt_mcastgrp, ot->ot_name->oid_nelem+13);
1252 1.1 mycroft
1253 1.1 mycroft if (v -> name)
1254 1.1 mycroft free_SNMP_ObjectName (v -> name);
1255 1.1 mycroft v -> name = new;
1256 1.1 mycroft
1257 1.1 mycroft /* Else we start from a previous row */
1258 1.1 mycroft } else {
1259 1.1 mycroft int i = ot -> ot_name -> oid_nelem;
1260 1.1 mycroft
1261 1.1 mycroft /* Get the lowest entry in the table > the given grp/src/mask */
1262 1.1 mycroft vifi = oid->oid_elements[oid->oid_nelem-1] + 1;
1263 1.1 mycroft if (!get_address(oid, &grp, ot->ot_name->oid_nelem)
1264 1.1 mycroft || !get_address(oid, &src, ot->ot_name->oid_nelem+4)
1265 1.1 mycroft || !get_address(oid, &mask, ot->ot_name->oid_nelem+8)
1266 1.1 mycroft || !next_child(>, &st, grp, src, mask, &vifi))
1267 1.1 mycroft return NOTOK;
1268 1.1 mycroft
1269 1.1 mycroft put_address(oid, gt->gt_mcastgrp, ot->ot_name->oid_nelem);
1270 1.1 mycroft put_address(oid, st->st_origin, ot->ot_name->oid_nelem+4);
1271 1.1 mycroft put_address(oid, 0xFFFFFFFF, ot->ot_name->oid_nelem+8);
1272 1.1 mycroft oid->oid_elements[ot->ot_name->oid_nelem+12] = vifi;
1273 1.1 mycroft put_address(oid, gt->gt_mcastgrp, ot->ot_name->oid_nelem+13);
1274 1.1 mycroft }
1275 1.1 mycroft break;
1276 1.1 mycroft
1277 1.1 mycroft default:
1278 1.1 mycroft return int_SNMP_error__status_genErr;
1279 1.1 mycroft }
1280 1.1 mycroft
1281 1.1 mycroft switch (ifvar) {
1282 1.1 mycroft
1283 1.1 mycroft case ipMRouteNextHopState:
1284 1.1 mycroft return o_integer (oi, v, (VIFM_ISSET(vifi, gt->gt_grpmems))? 2 : 1);
1285 1.1 mycroft
1286 1.1 mycroft /* Currently equal to ipMRouteUpTime */
1287 1.1 mycroft case ipMRouteNextHopUpTime: {
1288 1.1 mycroft time_t currtime;
1289 1.1 mycroft time(&currtime);
1290 1.1 mycroft return o_integer (oi, v, (currtime - gt->gt_ctime)*100);
1291 1.1 mycroft }
1292 1.1 mycroft
1293 1.1 mycroft case ipMRouteNextHopExpiryTime:
1294 1.1 mycroft return o_integer (oi, v, gt->gt_prsent_timer);
1295 1.1 mycroft
1296 1.1 mycroft case ipMRouteNextHopClosestMemberHops:
1297 1.1 mycroft return o_integer (oi, v, 0);
1298 1.1 mycroft
1299 1.1 mycroft case ipMRouteNextHopProtocol:
1300 1.1 mycroft return o_integer (oi, v, 4);
1301 1.1 mycroft
1302 1.1 mycroft default:
1303 1.1 mycroft return int_SNMP_error__status_noSuchName;
1304 1.1 mycroft }
1305 1.1 mycroft }
1306