blob: 0cf257da4dee0f726307240d39fc1ffbe23fcdf3 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* OSPFv2 SNMP support
2 * Copyright (C) 2000 IP Infusion Inc.
3 *
4 * Written by Kunihiro Ishiguro <kunihiro@zebra.org>
5 *
6 * This file is part of GNU Zebra.
7 *
8 * GNU Zebra is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
11 * later version.
12 *
13 * GNU Zebra is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with GNU Zebra; see the file COPYING. If not, write to the Free
20 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 * 02111-1307, USA.
22 */
23
24#include <zebra.h>
25
26#ifdef HAVE_SNMP
paul07661cb2003-03-18 00:03:05 +000027#ifdef HAVE_NETSNMP
28#include <net-snmp/net-snmp-config.h>
29#endif
paul718e3742002-12-13 20:15:29 +000030#include <asn1.h>
31#include <snmp.h>
32#include <snmp_impl.h>
33
34#include "if.h"
35#include "log.h"
36#include "prefix.h"
37#include "table.h"
38#include "command.h"
39#include "memory.h"
40#include "smux.h"
41
42#include "ospfd/ospfd.h"
43#include "ospfd/ospf_interface.h"
44#include "ospfd/ospf_asbr.h"
45#include "ospfd/ospf_lsa.h"
46#include "ospfd/ospf_lsdb.h"
47#include "ospfd/ospf_abr.h"
48#include "ospfd/ospf_neighbor.h"
49#include "ospfd/ospf_nsm.h"
50#include "ospfd/ospf_flood.h"
51
52/* OSPF2-MIB. */
53#define OSPF2MIB 1,3,6,1,2,1,14
54
paul718e3742002-12-13 20:15:29 +000055/* OSPF MIB General Group values. */
56#define OSPFROUTERID 1
57#define OSPFADMINSTAT 2
58#define OSPFVERSIONNUMBER 3
59#define OSPFAREABDRRTRSTATUS 4
60#define OSPFASBDRRTRSTATUS 5
61#define OSPFEXTERNLSACOUNT 6
62#define OSPFEXTERNLSACKSUMSUM 7
63#define OSPFTOSSUPPORT 8
64#define OSPFORIGINATENEWLSAS 9
65#define OSPFRXNEWLSAS 10
66#define OSPFEXTLSDBLIMIT 11
67#define OSPFMULTICASTEXTENSIONS 12
68#define OSPFEXITOVERFLOWINTERVAL 13
69#define OSPFDEMANDEXTENSIONS 14
70
71/* OSPF MIB ospfAreaTable. */
72#define OSPFAREAID 1
73#define OSPFAUTHTYPE 2
74#define OSPFIMPORTASEXTERN 3
75#define OSPFSPFRUNS 4
76#define OSPFAREABDRRTRCOUNT 5
77#define OSPFASBDRRTRCOUNT 6
78#define OSPFAREALSACOUNT 7
79#define OSPFAREALSACKSUMSUM 8
80#define OSPFAREASUMMARY 9
81#define OSPFAREASTATUS 10
82
83/* OSPF MIB ospfStubAreaTable. */
84#define OSPFSTUBAREAID 1
85#define OSPFSTUBTOS 2
86#define OSPFSTUBMETRIC 3
87#define OSPFSTUBSTATUS 4
88#define OSPFSTUBMETRICTYPE 5
89
90/* OSPF MIB ospfLsdbTable. */
91#define OSPFLSDBAREAID 1
92#define OSPFLSDBTYPE 2
93#define OSPFLSDBLSID 3
94#define OSPFLSDBROUTERID 4
95#define OSPFLSDBSEQUENCE 5
96#define OSPFLSDBAGE 6
97#define OSPFLSDBCHECKSUM 7
98#define OSPFLSDBADVERTISEMENT 8
99
100/* OSPF MIB ospfAreaRangeTable. */
101#define OSPFAREARANGEAREAID 1
102#define OSPFAREARANGENET 2
103#define OSPFAREARANGEMASK 3
104#define OSPFAREARANGESTATUS 4
105#define OSPFAREARANGEEFFECT 5
106
107/* OSPF MIB ospfHostTable. */
108#define OSPFHOSTIPADDRESS 1
109#define OSPFHOSTTOS 2
110#define OSPFHOSTMETRIC 3
111#define OSPFHOSTSTATUS 4
112#define OSPFHOSTAREAID 5
113
114/* OSPF MIB ospfIfTable. */
115#define OSPFIFIPADDRESS 1
116#define OSPFADDRESSLESSIF 2
117#define OSPFIFAREAID 3
118#define OSPFIFTYPE 4
119#define OSPFIFADMINSTAT 5
120#define OSPFIFRTRPRIORITY 6
121#define OSPFIFTRANSITDELAY 7
122#define OSPFIFRETRANSINTERVAL 8
123#define OSPFIFHELLOINTERVAL 9
124#define OSPFIFRTRDEADINTERVAL 10
125#define OSPFIFPOLLINTERVAL 11
126#define OSPFIFSTATE 12
127#define OSPFIFDESIGNATEDROUTER 13
128#define OSPFIFBACKUPDESIGNATEDROUTER 14
129#define OSPFIFEVENTS 15
130#define OSPFIFAUTHKEY 16
131#define OSPFIFSTATUS 17
132#define OSPFIFMULTICASTFORWARDING 18
133#define OSPFIFDEMAND 19
134#define OSPFIFAUTHTYPE 20
135
136/* OSPF MIB ospfIfMetricTable. */
137#define OSPFIFMETRICIPADDRESS 1
138#define OSPFIFMETRICADDRESSLESSIF 2
139#define OSPFIFMETRICTOS 3
140#define OSPFIFMETRICVALUE 4
141#define OSPFIFMETRICSTATUS 5
142
143/* OSPF MIB ospfVirtIfTable. */
144#define OSPFVIRTIFAREAID 1
145#define OSPFVIRTIFNEIGHBOR 2
146#define OSPFVIRTIFTRANSITDELAY 3
147#define OSPFVIRTIFRETRANSINTERVAL 4
148#define OSPFVIRTIFHELLOINTERVAL 5
149#define OSPFVIRTIFRTRDEADINTERVAL 6
150#define OSPFVIRTIFSTATE 7
151#define OSPFVIRTIFEVENTS 8
152#define OSPFVIRTIFAUTHKEY 9
153#define OSPFVIRTIFSTATUS 10
154#define OSPFVIRTIFAUTHTYPE 11
155
156/* OSPF MIB ospfNbrTable. */
157#define OSPFNBRIPADDR 1
158#define OSPFNBRADDRESSLESSINDEX 2
159#define OSPFNBRRTRID 3
160#define OSPFNBROPTIONS 4
161#define OSPFNBRPRIORITY 5
162#define OSPFNBRSTATE 6
163#define OSPFNBREVENTS 7
164#define OSPFNBRLSRETRANSQLEN 8
165#define OSPFNBMANBRSTATUS 9
166#define OSPFNBMANBRPERMANENCE 10
167#define OSPFNBRHELLOSUPPRESSED 11
168
169/* OSPF MIB ospfVirtNbrTable. */
170#define OSPFVIRTNBRAREA 1
171#define OSPFVIRTNBRRTRID 2
172#define OSPFVIRTNBRIPADDR 3
173#define OSPFVIRTNBROPTIONS 4
174#define OSPFVIRTNBRSTATE 5
175#define OSPFVIRTNBREVENTS 6
176#define OSPFVIRTNBRLSRETRANSQLEN 7
177#define OSPFVIRTNBRHELLOSUPPRESSED 8
178
179/* OSPF MIB ospfExtLsdbTable. */
180#define OSPFEXTLSDBTYPE 1
181#define OSPFEXTLSDBLSID 2
182#define OSPFEXTLSDBROUTERID 3
183#define OSPFEXTLSDBSEQUENCE 4
184#define OSPFEXTLSDBAGE 5
185#define OSPFEXTLSDBCHECKSUM 6
186#define OSPFEXTLSDBADVERTISEMENT 7
187
188/* OSPF MIB ospfAreaAggregateTable. */
189#define OSPFAREAAGGREGATEAREAID 1
190#define OSPFAREAAGGREGATELSDBTYPE 2
191#define OSPFAREAAGGREGATENET 3
192#define OSPFAREAAGGREGATEMASK 4
193#define OSPFAREAAGGREGATESTATUS 5
194#define OSPFAREAAGGREGATEEFFECT 6
195
196/* SYNTAX Status from OSPF-MIB. */
197#define OSPF_STATUS_ENABLED 1
198#define OSPF_STATUS_DISABLED 2
199
200/* SNMP value hack. */
201#define COUNTER ASN_COUNTER
202#define INTEGER ASN_INTEGER
203#define GAUGE ASN_GAUGE
204#define TIMETICKS ASN_TIMETICKS
205#define IPADDRESS ASN_IPADDRESS
206#define STRING ASN_OCTET_STR
207
208/* Declare static local variables for convenience. */
209SNMP_LOCAL_VARIABLES
210
211/* OSPF-MIB instances. */
212oid ospf_oid [] = { OSPF2MIB };
paul718e3742002-12-13 20:15:29 +0000213
214/* IP address 0.0.0.0. */
215static struct in_addr ospf_empty_addr = {0};
216
217/* Hook functions. */
218static u_char *ospfGeneralGroup ();
219static u_char *ospfAreaEntry ();
220static u_char *ospfStubAreaEntry ();
221static u_char *ospfLsdbEntry ();
222static u_char *ospfAreaRangeEntry ();
223static u_char *ospfHostEntry ();
224static u_char *ospfIfEntry ();
225static u_char *ospfIfMetricEntry ();
226static u_char *ospfVirtIfEntry ();
227static u_char *ospfNbrEntry ();
228static u_char *ospfVirtNbrEntry ();
229static u_char *ospfExtLsdbEntry ();
230static u_char *ospfAreaAggregateEntry ();
231
232struct variable ospf_variables[] =
233{
234 /* OSPF general variables */
235 {OSPFROUTERID, IPADDRESS, RWRITE, ospfGeneralGroup,
236 2, {1, 1}},
237 {OSPFADMINSTAT, INTEGER, RWRITE, ospfGeneralGroup,
238 2, {1, 2}},
239 {OSPFVERSIONNUMBER, INTEGER, RONLY, ospfGeneralGroup,
240 2, {1, 3}},
241 {OSPFAREABDRRTRSTATUS, INTEGER, RONLY, ospfGeneralGroup,
242 2, {1, 4}},
243 {OSPFASBDRRTRSTATUS, INTEGER, RWRITE, ospfGeneralGroup,
244 2, {1, 5}},
245 {OSPFEXTERNLSACOUNT, GAUGE, RONLY, ospfGeneralGroup,
246 2, {1, 6}},
247 {OSPFEXTERNLSACKSUMSUM, INTEGER, RONLY, ospfGeneralGroup,
248 2, {1, 7}},
249 {OSPFTOSSUPPORT, INTEGER, RWRITE, ospfGeneralGroup,
250 2, {1, 8}},
251 {OSPFORIGINATENEWLSAS, COUNTER, RONLY, ospfGeneralGroup,
252 2, {1, 9}},
253 {OSPFRXNEWLSAS, COUNTER, RONLY, ospfGeneralGroup,
254 2, {1, 10}},
255 {OSPFEXTLSDBLIMIT, INTEGER, RWRITE, ospfGeneralGroup,
256 2, {1, 11}},
257 {OSPFMULTICASTEXTENSIONS, INTEGER, RWRITE, ospfGeneralGroup,
258 2, {1, 12}},
259 {OSPFEXITOVERFLOWINTERVAL, INTEGER, RWRITE, ospfGeneralGroup,
260 2, {1, 13}},
261 {OSPFDEMANDEXTENSIONS, INTEGER, RWRITE, ospfGeneralGroup,
262 2, {1, 14}},
263
264 /* OSPF area data structure. */
265 {OSPFAREAID, IPADDRESS, RONLY, ospfAreaEntry,
266 3, {2, 1, 1}},
267 {OSPFAUTHTYPE, INTEGER, RWRITE, ospfAreaEntry,
268 3, {2, 1, 2}},
269 {OSPFIMPORTASEXTERN, INTEGER, RWRITE, ospfAreaEntry,
270 3, {2, 1, 3}},
271 {OSPFSPFRUNS, COUNTER, RONLY, ospfAreaEntry,
272 3, {2, 1, 4}},
273 {OSPFAREABDRRTRCOUNT, GAUGE, RONLY, ospfAreaEntry,
274 3, {2, 1, 5}},
275 {OSPFASBDRRTRCOUNT, GAUGE, RONLY, ospfAreaEntry,
276 3, {2, 1, 6}},
277 {OSPFAREALSACOUNT, GAUGE, RONLY, ospfAreaEntry,
278 3, {2, 1, 7}},
279 {OSPFAREALSACKSUMSUM, INTEGER, RONLY, ospfAreaEntry,
280 3, {2, 1, 8}},
281 {OSPFAREASUMMARY, INTEGER, RWRITE, ospfAreaEntry,
282 3, {2, 1, 9}},
283 {OSPFAREASTATUS, INTEGER, RWRITE, ospfAreaEntry,
284 3, {2, 1, 10}},
285
286 /* OSPF stub area information. */
287 {OSPFSTUBAREAID, IPADDRESS, RONLY, ospfStubAreaEntry,
288 3, {3, 1, 1}},
289 {OSPFSTUBTOS, INTEGER, RONLY, ospfStubAreaEntry,
290 3, {3, 1, 2}},
291 {OSPFSTUBMETRIC, INTEGER, RWRITE, ospfStubAreaEntry,
292 3, {3, 1, 3}},
293 {OSPFSTUBSTATUS, INTEGER, RWRITE, ospfStubAreaEntry,
294 3, {3, 1, 4}},
295 {OSPFSTUBMETRICTYPE, INTEGER, RWRITE, ospfStubAreaEntry,
296 3, {3, 1, 5}},
297
298 /* OSPF link state database. */
299 {OSPFLSDBAREAID, IPADDRESS, RONLY, ospfLsdbEntry,
300 3, {4, 1, 1}},
301 {OSPFLSDBTYPE, INTEGER, RONLY, ospfLsdbEntry,
302 3, {4, 1, 2}},
303 {OSPFLSDBLSID, IPADDRESS, RONLY, ospfLsdbEntry,
304 3, {4, 1, 3}},
305 {OSPFLSDBROUTERID, IPADDRESS, RONLY, ospfLsdbEntry,
306 3, {4, 1, 4}},
307 {OSPFLSDBSEQUENCE, INTEGER, RONLY, ospfLsdbEntry,
308 3, {4, 1, 5}},
309 {OSPFLSDBAGE, INTEGER, RONLY, ospfLsdbEntry,
310 3, {4, 1, 6}},
311 {OSPFLSDBCHECKSUM, INTEGER, RONLY, ospfLsdbEntry,
312 3, {4, 1, 7}},
313 {OSPFLSDBADVERTISEMENT, STRING, RONLY, ospfLsdbEntry,
314 3, {4, 1, 8}},
315
316 /* Area range table. */
317 {OSPFAREARANGEAREAID, IPADDRESS, RONLY, ospfAreaRangeEntry,
318 3, {5, 1, 1}},
319 {OSPFAREARANGENET, IPADDRESS, RONLY, ospfAreaRangeEntry,
320 3, {5, 1, 2}},
321 {OSPFAREARANGEMASK, IPADDRESS, RWRITE, ospfAreaRangeEntry,
322 3, {5, 1, 3}},
323 {OSPFAREARANGESTATUS, INTEGER, RWRITE, ospfAreaRangeEntry,
324 3, {5, 1, 4}},
325 {OSPFAREARANGEEFFECT, INTEGER, RWRITE, ospfAreaRangeEntry,
326 3, {5, 1, 5}},
327
328 /* OSPF host table. */
329 {OSPFHOSTIPADDRESS, IPADDRESS, RONLY, ospfHostEntry,
330 3, {6, 1, 1}},
331 {OSPFHOSTTOS, INTEGER, RONLY, ospfHostEntry,
332 3, {6, 1, 2}},
333 {OSPFHOSTMETRIC, INTEGER, RWRITE, ospfHostEntry,
334 3, {6, 1, 3}},
335 {OSPFHOSTSTATUS, INTEGER, RWRITE, ospfHostEntry,
336 3, {6, 1, 4}},
337 {OSPFHOSTAREAID, IPADDRESS, RONLY, ospfHostEntry,
338 3, {6, 1, 5}},
339
340 /* OSPF interface table. */
341 {OSPFIFIPADDRESS, IPADDRESS, RONLY, ospfIfEntry,
342 3, {7, 1, 1}},
343 {OSPFADDRESSLESSIF, INTEGER, RONLY, ospfIfEntry,
344 3, {7, 1, 2}},
345 {OSPFIFAREAID, IPADDRESS, RWRITE, ospfIfEntry,
346 3, {7, 1, 3}},
347 {OSPFIFTYPE, INTEGER, RWRITE, ospfIfEntry,
348 3, {7, 1, 4}},
349 {OSPFIFADMINSTAT, INTEGER, RWRITE, ospfIfEntry,
350 3, {7, 1, 5}},
351 {OSPFIFRTRPRIORITY, INTEGER, RWRITE, ospfIfEntry,
352 3, {7, 1, 6}},
353 {OSPFIFTRANSITDELAY, INTEGER, RWRITE, ospfIfEntry,
354 3, {7, 1, 7}},
355 {OSPFIFRETRANSINTERVAL, INTEGER, RWRITE, ospfIfEntry,
356 3, {7, 1, 8}},
357 {OSPFIFHELLOINTERVAL, INTEGER, RWRITE, ospfIfEntry,
358 3, {7, 1, 9}},
359 {OSPFIFRTRDEADINTERVAL, INTEGER, RWRITE, ospfIfEntry,
360 3, {7, 1, 10}},
361 {OSPFIFPOLLINTERVAL, INTEGER, RWRITE, ospfIfEntry,
362 3, {7, 1, 11}},
363 {OSPFIFSTATE, INTEGER, RONLY, ospfIfEntry,
364 3, {7, 1, 12}},
365 {OSPFIFDESIGNATEDROUTER, IPADDRESS, RONLY, ospfIfEntry,
366 3, {7, 1, 13}},
367 {OSPFIFBACKUPDESIGNATEDROUTER, IPADDRESS, RONLY, ospfIfEntry,
368 3, {7, 1, 14}},
369 {OSPFIFEVENTS, COUNTER, RONLY, ospfIfEntry,
370 3, {7, 1, 15}},
371 {OSPFIFAUTHKEY, STRING, RWRITE, ospfIfEntry,
372 3, {7, 1, 16}},
373 {OSPFIFSTATUS, INTEGER, RWRITE, ospfIfEntry,
374 3, {7, 1, 17}},
375 {OSPFIFMULTICASTFORWARDING, INTEGER, RWRITE, ospfIfEntry,
376 3, {7, 1, 18}},
377 {OSPFIFDEMAND, INTEGER, RWRITE, ospfIfEntry,
378 3, {7, 1, 19}},
379 {OSPFIFAUTHTYPE, INTEGER, RWRITE, ospfIfEntry,
380 3, {7, 1, 20}},
381
382 /* OSPF interface metric table. */
383 {OSPFIFMETRICIPADDRESS, IPADDRESS, RONLY, ospfIfMetricEntry,
384 3, {8, 1, 1}},
385 {OSPFIFMETRICADDRESSLESSIF, INTEGER, RONLY, ospfIfMetricEntry,
386 3, {8, 1, 2}},
387 {OSPFIFMETRICTOS, INTEGER, RONLY, ospfIfMetricEntry,
388 3, {8, 1, 3}},
389 {OSPFIFMETRICVALUE, INTEGER, RWRITE, ospfIfMetricEntry,
390 3, {8, 1, 4}},
391 {OSPFIFMETRICSTATUS, INTEGER, RWRITE, ospfIfMetricEntry,
392 3, {8, 1, 5}},
393
394 /* OSPF virtual interface table. */
395 {OSPFVIRTIFAREAID, IPADDRESS, RONLY, ospfVirtIfEntry,
396 3, {9, 1, 1}},
397 {OSPFVIRTIFNEIGHBOR, IPADDRESS, RONLY, ospfVirtIfEntry,
398 3, {9, 1, 2}},
399 {OSPFVIRTIFTRANSITDELAY, INTEGER, RWRITE, ospfVirtIfEntry,
400 3, {9, 1, 3}},
401 {OSPFVIRTIFRETRANSINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
402 3, {9, 1, 4}},
403 {OSPFVIRTIFHELLOINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
404 3, {9, 1, 5}},
405 {OSPFVIRTIFRTRDEADINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
406 3, {9, 1, 6}},
407 {OSPFVIRTIFSTATE, INTEGER, RONLY, ospfVirtIfEntry,
408 3, {9, 1, 7}},
409 {OSPFVIRTIFEVENTS, COUNTER, RONLY, ospfVirtIfEntry,
410 3, {9, 1, 8}},
411 {OSPFVIRTIFAUTHKEY, STRING, RWRITE, ospfVirtIfEntry,
412 3, {9, 1, 9}},
413 {OSPFVIRTIFSTATUS, INTEGER, RWRITE, ospfVirtIfEntry,
414 3, {9, 1, 10}},
415 {OSPFVIRTIFAUTHTYPE, INTEGER, RWRITE, ospfVirtIfEntry,
416 3, {9, 1, 11}},
417
418 /* OSPF neighbor table. */
419 {OSPFNBRIPADDR, IPADDRESS, RONLY, ospfNbrEntry,
420 3, {10, 1, 1}},
421 {OSPFNBRADDRESSLESSINDEX, INTEGER, RONLY, ospfNbrEntry,
422 3, {10, 1, 2}},
423 {OSPFNBRRTRID, IPADDRESS, RONLY, ospfNbrEntry,
424 3, {10, 1, 3}},
425 {OSPFNBROPTIONS, INTEGER, RONLY, ospfNbrEntry,
426 3, {10, 1, 4}},
427 {OSPFNBRPRIORITY, INTEGER, RWRITE, ospfNbrEntry,
428 3, {10, 1, 5}},
429 {OSPFNBRSTATE, INTEGER, RONLY, ospfNbrEntry,
430 3, {10, 1, 6}},
431 {OSPFNBREVENTS, COUNTER, RONLY, ospfNbrEntry,
432 3, {10, 1, 7}},
433 {OSPFNBRLSRETRANSQLEN, GAUGE, RONLY, ospfNbrEntry,
434 3, {10, 1, 8}},
435 {OSPFNBMANBRSTATUS, INTEGER, RWRITE, ospfNbrEntry,
436 3, {10, 1, 9}},
437 {OSPFNBMANBRPERMANENCE, INTEGER, RONLY, ospfNbrEntry,
438 3, {10, 1, 10}},
439 {OSPFNBRHELLOSUPPRESSED, INTEGER, RONLY, ospfNbrEntry,
440 3, {10, 1, 11}},
441
442 /* OSPF virtual neighbor table. */
443 {OSPFVIRTNBRAREA, IPADDRESS, RONLY, ospfVirtNbrEntry,
444 3, {11, 1, 1}},
445 {OSPFVIRTNBRRTRID, IPADDRESS, RONLY, ospfVirtNbrEntry,
446 3, {11, 1, 2}},
447 {OSPFVIRTNBRIPADDR, IPADDRESS, RONLY, ospfVirtNbrEntry,
448 3, {11, 1, 3}},
449 {OSPFVIRTNBROPTIONS, INTEGER, RONLY, ospfVirtNbrEntry,
450 3, {11, 1, 4}},
451 {OSPFVIRTNBRSTATE, INTEGER, RONLY, ospfVirtNbrEntry,
452 3, {11, 1, 5}},
453 {OSPFVIRTNBREVENTS, COUNTER, RONLY, ospfVirtNbrEntry,
454 3, {11, 1, 6}},
455 {OSPFVIRTNBRLSRETRANSQLEN, INTEGER, RONLY, ospfVirtNbrEntry,
456 3, {11, 1, 7}},
457 {OSPFVIRTNBRHELLOSUPPRESSED, INTEGER, RONLY, ospfVirtNbrEntry,
458 3, {11, 1, 8}},
459
460 /* OSPF link state database, external. */
461 {OSPFEXTLSDBTYPE, INTEGER, RONLY, ospfExtLsdbEntry,
462 3, {12, 1, 1}},
463 {OSPFEXTLSDBLSID, IPADDRESS, RONLY, ospfExtLsdbEntry,
464 3, {12, 1, 2}},
465 {OSPFEXTLSDBROUTERID, IPADDRESS, RONLY, ospfExtLsdbEntry,
466 3, {12, 1, 3}},
467 {OSPFEXTLSDBSEQUENCE, INTEGER, RONLY, ospfExtLsdbEntry,
468 3, {12, 1, 4}},
469 {OSPFEXTLSDBAGE, INTEGER, RONLY, ospfExtLsdbEntry,
470 3, {12, 1, 5}},
471 {OSPFEXTLSDBCHECKSUM, INTEGER, RONLY, ospfExtLsdbEntry,
472 3, {12, 1, 6}},
473 {OSPFEXTLSDBADVERTISEMENT, STRING, RONLY, ospfExtLsdbEntry,
474 3, {12, 1, 7}},
475
476 /* OSPF area aggregate table. */
477 {OSPFAREAAGGREGATEAREAID, IPADDRESS, RONLY, ospfAreaAggregateEntry,
478 3, {14, 1, 1}},
479 {OSPFAREAAGGREGATELSDBTYPE, INTEGER, RONLY, ospfAreaAggregateEntry,
480 3, {14, 1, 2}},
481 {OSPFAREAAGGREGATENET, IPADDRESS, RONLY, ospfAreaAggregateEntry,
482 3, {14, 1, 3}},
483 {OSPFAREAAGGREGATEMASK, IPADDRESS, RONLY, ospfAreaAggregateEntry,
484 3, {14, 1, 4}},
485 {OSPFAREAAGGREGATESTATUS, INTEGER, RWRITE, ospfAreaAggregateEntry,
486 3, {14, 1, 5}},
487 {OSPFAREAAGGREGATEEFFECT, INTEGER, RWRITE, ospfAreaAggregateEntry,
488 3, {14, 1, 6}}
489};
490
491/* The administrative status of OSPF. When OSPF is enbled on at least
492 one interface return 1. */
493int
paul68980082003-03-25 05:07:42 +0000494ospf_admin_stat (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000495{
paulaa20c6f2004-10-07 14:19:36 +0000496 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000497 struct ospf_interface *oi;
498
paul68980082003-03-25 05:07:42 +0000499 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000500 return 0;
501
paul68980082003-03-25 05:07:42 +0000502 for (node = listhead (ospf->oiflist); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000503 {
504 oi = getdata (node);
505
506 if (oi && oi->address)
507 return 1;
508 }
509 return 0;
510}
511
512static u_char *
513ospfGeneralGroup (struct variable *v, oid *name, size_t *length,
514 int exact, size_t *var_len, WriteMethod **write_method)
515{
paul020709f2003-04-04 02:44:16 +0000516 struct ospf *ospf;
517
518 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +0000519
paul718e3742002-12-13 20:15:29 +0000520 /* Check whether the instance identifier is valid */
521 if (smux_header_generic (v, name, length, exact, var_len, write_method)
522 == MATCH_FAILED)
523 return NULL;
524
525 /* Return the current value of the variable */
526 switch (v->magic)
527 {
528 case OSPFROUTERID: /* 1 */
529 /* Router-ID of this OSPF instance. */
paul68980082003-03-25 05:07:42 +0000530 if (ospf)
531 return SNMP_IPADDRESS (ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000532 else
533 return SNMP_IPADDRESS (ospf_empty_addr);
534 break;
535 case OSPFADMINSTAT: /* 2 */
536 /* The administrative status of OSPF in the router. */
paul68980082003-03-25 05:07:42 +0000537 if (ospf_admin_stat (ospf))
paul718e3742002-12-13 20:15:29 +0000538 return SNMP_INTEGER (OSPF_STATUS_ENABLED);
539 else
540 return SNMP_INTEGER (OSPF_STATUS_DISABLED);
541 break;
542 case OSPFVERSIONNUMBER: /* 3 */
543 /* OSPF version 2. */
544 return SNMP_INTEGER (OSPF_VERSION);
545 break;
546 case OSPFAREABDRRTRSTATUS: /* 4 */
547 /* Area Border router status. */
paul68980082003-03-25 05:07:42 +0000548 if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ABR))
paul718e3742002-12-13 20:15:29 +0000549 return SNMP_INTEGER (SNMP_TRUE);
550 else
551 return SNMP_INTEGER (SNMP_FALSE);
552 break;
553 case OSPFASBDRRTRSTATUS: /* 5 */
554 /* AS Border router status. */
paul68980082003-03-25 05:07:42 +0000555 if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ASBR))
paul718e3742002-12-13 20:15:29 +0000556 return SNMP_INTEGER (SNMP_TRUE);
557 else
558 return SNMP_INTEGER (SNMP_FALSE);
559 break;
560 case OSPFEXTERNLSACOUNT: /* 6 */
561 /* External LSA counts. */
paul68980082003-03-25 05:07:42 +0000562 if (ospf)
563 return SNMP_INTEGER (ospf_lsdb_count_all (ospf->lsdb));
paul718e3742002-12-13 20:15:29 +0000564 else
565 return SNMP_INTEGER (0);
566 break;
567 case OSPFEXTERNLSACKSUMSUM: /* 7 */
568 /* External LSA checksum. */
569 return SNMP_INTEGER (0);
570 break;
571 case OSPFTOSSUPPORT: /* 8 */
572 /* TOS is not supported. */
573 return SNMP_INTEGER (SNMP_FALSE);
574 break;
575 case OSPFORIGINATENEWLSAS: /* 9 */
576 /* The number of new link-state advertisements. */
paul68980082003-03-25 05:07:42 +0000577 if (ospf)
578 return SNMP_INTEGER (ospf->lsa_originate_count);
paul718e3742002-12-13 20:15:29 +0000579 else
580 return SNMP_INTEGER (0);
581 break;
582 case OSPFRXNEWLSAS: /* 10 */
583 /* The number of link-state advertisements received determined
584 to be new instantiations. */
paul68980082003-03-25 05:07:42 +0000585 if (ospf)
586 return SNMP_INTEGER (ospf->rx_lsa_count);
paul718e3742002-12-13 20:15:29 +0000587 else
588 return SNMP_INTEGER (0);
589 break;
590 case OSPFEXTLSDBLIMIT: /* 11 */
591 /* There is no limit for the number of non-default
592 AS-external-LSAs. */
593 return SNMP_INTEGER (-1);
594 break;
595 case OSPFMULTICASTEXTENSIONS: /* 12 */
596 /* Multicast Extensions to OSPF is not supported. */
597 return SNMP_INTEGER (0);
598 break;
599 case OSPFEXITOVERFLOWINTERVAL: /* 13 */
600 /* Overflow is not supported. */
601 return SNMP_INTEGER (0);
602 break;
603 case OSPFDEMANDEXTENSIONS: /* 14 */
604 /* Demand routing is not supported. */
605 return SNMP_INTEGER (SNMP_FALSE);
606 break;
607 default:
608 return NULL;
609 }
610 return NULL;
611}
612
613struct ospf_area *
paul68980082003-03-25 05:07:42 +0000614ospf_area_lookup_next (struct ospf *ospf, struct in_addr *area_id, int first)
paul718e3742002-12-13 20:15:29 +0000615{
616 struct ospf_area *area;
paulaa20c6f2004-10-07 14:19:36 +0000617 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000618
paul020709f2003-04-04 02:44:16 +0000619 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000620 return NULL;
621
622 if (first)
623 {
paul68980082003-03-25 05:07:42 +0000624 node = listhead (ospf->areas);
paul718e3742002-12-13 20:15:29 +0000625 if (node)
626 {
627 area = getdata (node);
628 *area_id = area->area_id;
629 return area;
630 }
631 return NULL;
632 }
paul68980082003-03-25 05:07:42 +0000633 for (node = listhead (ospf->areas); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000634 {
635 area = getdata (node);
636
637 if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))
638 {
639 *area_id = area->area_id;
640 return area;
641 }
642 }
643 return NULL;
644}
645
646struct ospf_area *
647ospfAreaLookup (struct variable *v, oid name[], size_t *length,
648 struct in_addr *addr, int exact)
649{
paul020709f2003-04-04 02:44:16 +0000650 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000651 struct ospf_area *area;
paul68980082003-03-25 05:07:42 +0000652 int len;
paul718e3742002-12-13 20:15:29 +0000653
paul020709f2003-04-04 02:44:16 +0000654 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +0000655 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000656 return NULL;
657
658 if (exact)
659 {
660 /* Length is insufficient to lookup OSPF area. */
661 if (*length - v->namelen != sizeof (struct in_addr))
662 return NULL;
663
664 oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);
665
paul68980082003-03-25 05:07:42 +0000666 area = ospf_area_lookup_by_area_id (ospf, *addr);
paul718e3742002-12-13 20:15:29 +0000667
668 return area;
669 }
670 else
671 {
672 len = *length - v->namelen;
673 if (len > 4)
674 len = 4;
675
676 oid2in_addr (name + v->namelen, len, addr);
677
paul68980082003-03-25 05:07:42 +0000678 area = ospf_area_lookup_next (ospf, addr, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +0000679
680 if (area == NULL)
681 return NULL;
682
683 oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));
684 *length = sizeof (struct in_addr) + v->namelen;
685
686 return area;
687 }
688 return NULL;
689}
690
691static u_char *
692ospfAreaEntry (struct variable *v, oid *name, size_t *length, int exact,
693 size_t *var_len, WriteMethod **write_method)
694{
695 struct ospf_area *area;
696 struct in_addr addr;
697
698 memset (&addr, 0, sizeof (struct in_addr));
699
700 area = ospfAreaLookup (v, name, length, &addr, exact);
701 if (! area)
702 return NULL;
703
704 /* Return the current value of the variable */
705 switch (v->magic)
706 {
707 case OSPFAREAID: /* 1 */
708 return SNMP_IPADDRESS (area->area_id);
709 break;
710 case OSPFAUTHTYPE: /* 2 */
711 return SNMP_INTEGER (area->auth_type);
712 break;
713 case OSPFIMPORTASEXTERN: /* 3 */
714 return SNMP_INTEGER (area->external_routing + 1);
715 break;
716 case OSPFSPFRUNS: /* 4 */
717 return SNMP_INTEGER (area->spf_calculation);
718 break;
719 case OSPFAREABDRRTRCOUNT: /* 5 */
720 return SNMP_INTEGER (area->abr_count);
721 break;
722 case OSPFASBDRRTRCOUNT: /* 6 */
723 return SNMP_INTEGER (area->asbr_count);
724 break;
725 case OSPFAREALSACOUNT: /* 7 */
726 return SNMP_INTEGER (area->lsdb->total);
727 break;
728 case OSPFAREALSACKSUMSUM: /* 8 */
729 return SNMP_INTEGER (0);
730 break;
731 case OSPFAREASUMMARY: /* 9 */
732#define OSPF_noAreaSummary 1
733#define OSPF_sendAreaSummary 2
734 if (area->no_summary)
735 return SNMP_INTEGER (OSPF_noAreaSummary);
736 else
737 return SNMP_INTEGER (OSPF_sendAreaSummary);
738 break;
739 case OSPFAREASTATUS: /* 10 */
740 return SNMP_INTEGER (SNMP_VALID);
741 break;
742 default:
743 return NULL;
744 break;
745 }
746 return NULL;
747}
748
749struct ospf_area *
750ospf_stub_area_lookup_next (struct in_addr *area_id, int first)
751{
752 struct ospf_area *area;
paulaa20c6f2004-10-07 14:19:36 +0000753 struct listnode *node;
paul020709f2003-04-04 02:44:16 +0000754 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000755
paul020709f2003-04-04 02:44:16 +0000756 ospf = ospf_lookup ();
757 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000758 return NULL;
759
paul020709f2003-04-04 02:44:16 +0000760 for (node = listhead (ospf->areas); node; nextnode (node))
paul718e3742002-12-13 20:15:29 +0000761 {
762 area = getdata (node);
763
764 if (area->external_routing == OSPF_AREA_STUB)
765 {
766 if (first)
767 {
768 *area_id = area->area_id;
769 return area;
770 }
771 else if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))
772 {
773 *area_id = area->area_id;
774 return area;
775 }
776 }
777 }
778 return NULL;
779}
780
781struct ospf_area *
782ospfStubAreaLookup (struct variable *v, oid name[], size_t *length,
783 struct in_addr *addr, int exact)
784{
paul020709f2003-04-04 02:44:16 +0000785 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000786 struct ospf_area *area;
paul68980082003-03-25 05:07:42 +0000787 int len;
paul718e3742002-12-13 20:15:29 +0000788
paul020709f2003-04-04 02:44:16 +0000789 ospf = ospf_lookup ();
790 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000791 return NULL;
792
793 /* Exact lookup. */
794 if (exact)
795 {
796 /* ospfStubAreaID + ospfStubTOS. */
797 if (*length != v->namelen + sizeof (struct in_addr) + 1)
798 return NULL;
799
800 /* Check ospfStubTOS is zero. */
801 if (name[*length - 1] != 0)
802 return NULL;
803
804 oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);
805
paul68980082003-03-25 05:07:42 +0000806 area = ospf_area_lookup_by_area_id (ospf, *addr);
paul718e3742002-12-13 20:15:29 +0000807
808 if (area->external_routing == OSPF_AREA_STUB)
809 return area;
810 else
811 return NULL;
812 }
813 else
814 {
815 len = *length - v->namelen;
816 if (len > 4)
817 len = 4;
818
819 oid2in_addr (name + v->namelen, len, addr);
820
821 area = ospf_stub_area_lookup_next (addr, len == 0 ? 1 : 0);
822
823 if (area == NULL)
824 return NULL;
825
826 oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));
827 /* Set TOS 0. */
828 name[v->namelen + sizeof (struct in_addr)] = 0;
829 *length = v->namelen + sizeof (struct in_addr) + 1;
830
831 return area;
832 }
833 return NULL;
834}
835
836static u_char *
837ospfStubAreaEntry (struct variable *v, oid *name, size_t *length,
838 int exact, size_t *var_len, WriteMethod **write_method)
839{
840 struct ospf_area *area;
841 struct in_addr addr;
842
843 memset (&addr, 0, sizeof (struct in_addr));
844
845 area = ospfStubAreaLookup (v, name, length, &addr, exact);
846 if (! area)
847 return NULL;
848
849 /* Return the current value of the variable */
850 switch (v->magic)
851 {
852 case OSPFSTUBAREAID: /* 1 */
853 /* OSPF stub area id. */
854 return SNMP_IPADDRESS (area->area_id);
855 break;
856 case OSPFSTUBTOS: /* 2 */
857 /* TOS value is not supported. */
858 return SNMP_INTEGER (0);
859 break;
860 case OSPFSTUBMETRIC: /* 3 */
861 /* Default cost to stub area. */
862 return SNMP_INTEGER (area->default_cost);
863 break;
864 case OSPFSTUBSTATUS: /* 4 */
865 /* Status of the stub area. */
866 return SNMP_INTEGER (SNMP_VALID);
867 break;
868 case OSPFSTUBMETRICTYPE: /* 5 */
869 /* OSPF Metric type. */
870#define OSPF_ospfMetric 1
871#define OSPF_comparableCost 2
872#define OSPF_nonComparable 3
873 return SNMP_INTEGER (OSPF_ospfMetric);
874 break;
875 default:
876 return NULL;
877 break;
878 }
879 return NULL;
880}
881
882struct ospf_lsa *
883lsdb_lookup_next (struct ospf_area *area, u_char *type, int type_next,
884 struct in_addr *ls_id, int ls_id_next,
885 struct in_addr *router_id, int router_id_next)
886{
887 struct ospf_lsa *lsa;
888 int i;
889
890 if (type_next)
891 i = OSPF_MIN_LSA;
892 else
893 i = *type;
894
895 for (; i < OSPF_MAX_LSA; i++)
896 {
897 *type = i;
898
899 lsa = ospf_lsdb_lookup_by_id_next (area->lsdb, *type, *ls_id, *router_id,
900 ls_id_next);
901 if (lsa)
902 return lsa;
903
904 ls_id_next = 1;
905 }
906 return NULL;
907}
908
909struct ospf_lsa *
910ospfLsdbLookup (struct variable *v, oid *name, size_t *length,
911 struct in_addr *area_id, u_char *type,
912 struct in_addr *ls_id, struct in_addr *router_id, int exact)
913{
paul020709f2003-04-04 02:44:16 +0000914 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000915 struct ospf_area *area;
916 struct ospf_lsa *lsa;
paul6c835672004-10-11 11:00:30 +0000917 unsigned int len;
paul718e3742002-12-13 20:15:29 +0000918 int type_next;
919 int ls_id_next;
920 int router_id_next;
921 oid *offset;
922 int offsetlen;
923
paul020709f2003-04-04 02:44:16 +0000924 ospf = ospf_lookup ();
925
paul718e3742002-12-13 20:15:29 +0000926#define OSPF_LSDB_ENTRY_OFFSET \
927 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
928
929 if (exact)
930 {
931 /* Area ID + Type + LS ID + Router ID. */
932 if (*length - v->namelen != OSPF_LSDB_ENTRY_OFFSET)
933 return NULL;
934
935 /* Set OID offset for Area ID. */
936 offset = name + v->namelen;
937
938 /* Lookup area first. */
939 oid2in_addr (offset, IN_ADDR_SIZE, area_id);
paul68980082003-03-25 05:07:42 +0000940 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +0000941 if (! area)
942 return NULL;
943 offset += IN_ADDR_SIZE;
944
945 /* Type. */
946 *type = *offset;
947 offset++;
948
949 /* LS ID. */
950 oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
951 offset += IN_ADDR_SIZE;
952
953 /* Router ID. */
954 oid2in_addr (offset, IN_ADDR_SIZE, router_id);
955
956 /* Lookup LSDB. */
957 return ospf_lsdb_lookup_by_id (area->lsdb, *type, *ls_id, *router_id);
958 }
959 else
960 {
961 /* Get variable length. */
962 offset = name + v->namelen;
963 offsetlen = *length - v->namelen;
964 len = offsetlen;
965
966 if (len > IN_ADDR_SIZE)
967 len = IN_ADDR_SIZE;
968
969 oid2in_addr (offset, len, area_id);
970
971 /* First we search area. */
972 if (len == IN_ADDR_SIZE)
paul68980082003-03-25 05:07:42 +0000973 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +0000974 else
paul68980082003-03-25 05:07:42 +0000975 area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +0000976
977 if (area == NULL)
978 return NULL;
979
980 do
981 {
982 /* Next we lookup type. */
983 offset += IN_ADDR_SIZE;
984 offsetlen -= IN_ADDR_SIZE;
985 len = offsetlen;
986
987 if (len <= 0)
988 type_next = 1;
989 else
990 {
991 len = 1;
992 type_next = 0;
993 *type = *offset;
994 }
995
996 /* LS ID. */
997 offset++;
998 offsetlen--;
999 len = offsetlen;
1000
1001 if (len <= 0)
1002 ls_id_next = 1;
1003 else
1004 {
1005 ls_id_next = 0;
1006 if (len > IN_ADDR_SIZE)
1007 len = IN_ADDR_SIZE;
1008
1009 oid2in_addr (offset, len, ls_id);
1010 }
1011
1012 /* Router ID. */
1013 offset += IN_ADDR_SIZE;
1014 offsetlen -= IN_ADDR_SIZE;
1015 len = offsetlen;
1016
1017 if (len <= 0)
1018 router_id_next = 1;
1019 else
1020 {
1021 router_id_next = 0;
1022 if (len > IN_ADDR_SIZE)
1023 len = IN_ADDR_SIZE;
1024
1025 oid2in_addr (offset, len, router_id);
1026 }
1027
1028 lsa = lsdb_lookup_next (area, type, type_next, ls_id, ls_id_next,
1029 router_id, router_id_next);
1030
1031 if (lsa)
1032 {
1033 /* Fill in length. */
1034 *length = v->namelen + OSPF_LSDB_ENTRY_OFFSET;
1035
1036 /* Fill in value. */
1037 offset = name + v->namelen;
1038 oid_copy_addr (offset, area_id, IN_ADDR_SIZE);
1039 offset += IN_ADDR_SIZE;
1040 *offset = lsa->data->type;
1041 offset++;
1042 oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
1043 offset += IN_ADDR_SIZE;
1044 oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
1045
1046 return lsa;
1047 }
1048 }
paul68980082003-03-25 05:07:42 +00001049 while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL);
paul718e3742002-12-13 20:15:29 +00001050 }
1051 return NULL;
1052}
1053
1054static u_char *
1055ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
1056 size_t *var_len, WriteMethod **write_method)
1057{
1058 struct ospf_lsa *lsa;
1059 struct lsa_header *lsah;
1060 struct in_addr area_id;
1061 u_char type;
1062 struct in_addr ls_id;
1063 struct in_addr router_id;
paul020709f2003-04-04 02:44:16 +00001064 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001065
1066 /* INDEX { ospfLsdbAreaId, ospfLsdbType,
1067 ospfLsdbLsid, ospfLsdbRouterId } */
1068
1069 memset (&area_id, 0, sizeof (struct in_addr));
1070 type = 0;
1071 memset (&ls_id, 0, sizeof (struct in_addr));
1072 memset (&router_id, 0, sizeof (struct in_addr));
1073
1074 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001075 ospf = ospf_lookup ();
1076 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001077 return NULL;
1078
1079 lsa = ospfLsdbLookup (v, name, length, &area_id, &type, &ls_id, &router_id,
1080 exact);
1081 if (! lsa)
1082 return NULL;
1083
1084 lsah = lsa->data;
1085
1086 /* Return the current value of the variable */
1087 switch (v->magic)
1088 {
1089 case OSPFLSDBAREAID: /* 1 */
1090 return SNMP_IPADDRESS (lsa->area->area_id);
1091 break;
1092 case OSPFLSDBTYPE: /* 2 */
1093 return SNMP_INTEGER (lsah->type);
1094 break;
1095 case OSPFLSDBLSID: /* 3 */
1096 return SNMP_IPADDRESS (lsah->id);
1097 break;
1098 case OSPFLSDBROUTERID: /* 4 */
1099 return SNMP_IPADDRESS (lsah->adv_router);
1100 break;
1101 case OSPFLSDBSEQUENCE: /* 5 */
1102 return SNMP_INTEGER (lsah->ls_seqnum);
1103 break;
1104 case OSPFLSDBAGE: /* 6 */
1105 return SNMP_INTEGER (lsah->ls_age);
1106 break;
1107 case OSPFLSDBCHECKSUM: /* 7 */
1108 return SNMP_INTEGER (lsah->checksum);
1109 break;
1110 case OSPFLSDBADVERTISEMENT: /* 8 */
1111 *var_len = ntohs (lsah->length);
1112 return (u_char *) lsah;
1113 break;
1114 default:
1115 return NULL;
1116 break;
1117 }
1118 return NULL;
1119}
1120
1121struct ospf_area_range *
1122ospfAreaRangeLookup (struct variable *v, oid *name, size_t *length,
1123 struct in_addr *area_id, struct in_addr *range_net,
1124 int exact)
1125{
1126 oid *offset;
1127 int offsetlen;
paul6c835672004-10-11 11:00:30 +00001128 unsigned int len;
paul020709f2003-04-04 02:44:16 +00001129 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001130 struct ospf_area *area;
1131 struct ospf_area_range *range;
1132 struct prefix_ipv4 p;
1133 p.family = AF_INET;
1134 p.prefixlen = IPV4_MAX_BITLEN;
1135
paul020709f2003-04-04 02:44:16 +00001136 ospf = ospf_lookup ();
1137
paul718e3742002-12-13 20:15:29 +00001138 if (exact)
1139 {
1140 /* Area ID + Range Network. */
1141 if (v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE != *length)
1142 return NULL;
1143
1144 /* Set OID offset for Area ID. */
1145 offset = name + v->namelen;
1146
1147 /* Lookup area first. */
1148 oid2in_addr (offset, IN_ADDR_SIZE, area_id);
1149
paul68980082003-03-25 05:07:42 +00001150 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +00001151 if (! area)
1152 return NULL;
1153
1154 offset += IN_ADDR_SIZE;
1155
1156 /* Lookup area range. */
1157 oid2in_addr (offset, IN_ADDR_SIZE, range_net);
1158 p.prefix = *range_net;
1159
1160 return ospf_area_range_lookup (area, &p);
1161 }
1162 else
1163 {
1164 /* Set OID offset for Area ID. */
1165 offset = name + v->namelen;
1166 offsetlen = *length - v->namelen;
1167
1168 len = offsetlen;
1169 if (len > IN_ADDR_SIZE)
1170 len = IN_ADDR_SIZE;
1171
1172 oid2in_addr (offset, len, area_id);
1173
1174 /* First we search area. */
1175 if (len == IN_ADDR_SIZE)
paul68980082003-03-25 05:07:42 +00001176 area = ospf_area_lookup_by_area_id (ospf,*area_id);
paul718e3742002-12-13 20:15:29 +00001177 else
paul68980082003-03-25 05:07:42 +00001178 area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +00001179
1180 if (area == NULL)
1181 return NULL;
1182
1183 do
1184 {
1185 offset += IN_ADDR_SIZE;
1186 offsetlen -= IN_ADDR_SIZE;
1187 len = offsetlen;
1188
1189 if (len < 0)
1190 len = 0;
1191 if (len > IN_ADDR_SIZE)
1192 len = IN_ADDR_SIZE;
1193
1194 oid2in_addr (offset, len, range_net);
1195
1196 range = ospf_area_range_lookup_next (area, range_net,
1197 len == 0 ? 1 : 0);
1198
1199 if (range)
1200 {
1201 /* Fill in length. */
1202 *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
1203
1204 /* Fill in value. */
1205 offset = name + v->namelen;
1206 oid_copy_addr (offset, area_id, IN_ADDR_SIZE);
1207 offset += IN_ADDR_SIZE;
1208 oid_copy_addr (offset, range_net, IN_ADDR_SIZE);
1209
1210 return range;
1211 }
1212 }
paul68980082003-03-25 05:07:42 +00001213 while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL);
paul718e3742002-12-13 20:15:29 +00001214 }
1215 return NULL;
1216}
1217
1218static u_char *
1219ospfAreaRangeEntry (struct variable *v, oid *name, size_t *length, int exact,
1220 size_t *var_len, WriteMethod **write_method)
1221{
1222 struct ospf_area_range *range;
1223 struct in_addr area_id;
1224 struct in_addr range_net;
1225 struct in_addr mask;
paul020709f2003-04-04 02:44:16 +00001226 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001227
1228 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001229 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001230 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001231 return NULL;
1232
1233 memset (&area_id, 0, IN_ADDR_SIZE);
1234 memset (&range_net, 0, IN_ADDR_SIZE);
1235
1236 range = ospfAreaRangeLookup (v, name, length, &area_id, &range_net, exact);
1237 if (! range)
1238 return NULL;
1239
1240 /* Convert prefixlen to network mask format. */
1241 masklen2ip (range->subst_masklen, &mask);
1242
1243 /* Return the current value of the variable */
1244 switch (v->magic)
1245 {
1246 case OSPFAREARANGEAREAID: /* 1 */
1247 return SNMP_IPADDRESS (area_id);
1248 break;
1249 case OSPFAREARANGENET: /* 2 */
1250 return SNMP_IPADDRESS (range_net);
1251 break;
1252 case OSPFAREARANGEMASK: /* 3 */
1253 return SNMP_IPADDRESS (mask);
1254 break;
1255 case OSPFAREARANGESTATUS: /* 4 */
1256 return SNMP_INTEGER (SNMP_VALID);
1257 break;
1258 case OSPFAREARANGEEFFECT: /* 5 */
1259#define OSPF_advertiseMatching 1
1260#define OSPF_doNotAdvertiseMatching 2
1261 return SNMP_INTEGER (OSPF_advertiseMatching);
1262 break;
1263 default:
1264 return NULL;
1265 break;
1266 }
1267 return NULL;
1268}
1269
1270struct ospf_nbr_nbma *
1271ospfHostLookup (struct variable *v, oid *name, size_t *length,
1272 struct in_addr *addr, int exact)
1273{
1274 int len;
1275 struct ospf_nbr_nbma *nbr_nbma;
paul020709f2003-04-04 02:44:16 +00001276 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001277
paul020709f2003-04-04 02:44:16 +00001278 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001279 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001280 return NULL;
1281
1282 if (exact)
1283 {
1284 /* INDEX { ospfHostIpAddress, ospfHostTOS } */
1285 if (*length != v->namelen + IN_ADDR_SIZE + 1)
1286 return NULL;
1287
1288 /* Check ospfHostTOS. */
1289 if (name[*length - 1] != 0)
1290 return NULL;
1291
1292 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, addr);
1293
paul68980082003-03-25 05:07:42 +00001294 nbr_nbma = ospf_nbr_nbma_lookup (ospf, *addr);
paul718e3742002-12-13 20:15:29 +00001295
1296 return nbr_nbma;
1297 }
1298 else
1299 {
1300 len = *length - v->namelen;
1301 if (len > 4)
1302 len = 4;
1303
1304 oid2in_addr (name + v->namelen, len, addr);
1305
paul68980082003-03-25 05:07:42 +00001306 nbr_nbma = ospf_nbr_nbma_lookup_next (ospf, addr, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +00001307
1308 if (nbr_nbma == NULL)
1309 return NULL;
1310
1311 oid_copy_addr (name + v->namelen, addr, IN_ADDR_SIZE);
1312
1313 /* Set TOS 0. */
1314 name[v->namelen + IN_ADDR_SIZE] = 0;
1315
1316 *length = v->namelen + IN_ADDR_SIZE + 1;
1317
1318 return nbr_nbma;
1319 }
1320 return NULL;
1321}
1322
1323static u_char *
1324ospfHostEntry (struct variable *v, oid *name, size_t *length, int exact,
1325 size_t *var_len, WriteMethod **write_method)
1326{
1327 struct ospf_nbr_nbma *nbr_nbma;
1328 struct ospf_interface *oi;
1329 struct in_addr addr;
paul020709f2003-04-04 02:44:16 +00001330 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001331
1332 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001333 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001334 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001335 return NULL;
1336
1337 memset (&addr, 0, sizeof (struct in_addr));
1338
1339 nbr_nbma = ospfHostLookup (v, name, length, &addr, exact);
1340 if (nbr_nbma == NULL)
1341 return NULL;
1342
1343 oi = nbr_nbma->oi;
1344
1345 /* Return the current value of the variable */
1346 switch (v->magic)
1347 {
1348 case OSPFHOSTIPADDRESS: /* 1 */
1349 return SNMP_IPADDRESS (nbr_nbma->addr);
1350 break;
1351 case OSPFHOSTTOS: /* 2 */
1352 return SNMP_INTEGER (0);
1353 break;
1354 case OSPFHOSTMETRIC: /* 3 */
1355 if (oi)
1356 return SNMP_INTEGER (oi->output_cost);
1357 else
1358 return SNMP_INTEGER (1);
1359 break;
1360 case OSPFHOSTSTATUS: /* 4 */
1361 return SNMP_INTEGER (SNMP_VALID);
1362 break;
1363 case OSPFHOSTAREAID: /* 5 */
1364 if (oi && oi->area)
1365 return SNMP_IPADDRESS (oi->area->area_id);
1366 else
1367 return SNMP_IPADDRESS (ospf_empty_addr);
1368 break;
1369 default:
1370 return NULL;
1371 break;
1372 }
1373 return NULL;
1374}
1375
1376struct list *ospf_snmp_iflist;
1377
1378struct ospf_snmp_if
1379{
1380 struct in_addr addr;
1381 unsigned int ifindex;
1382 struct interface *ifp;
1383};
1384
1385struct ospf_snmp_if *
1386ospf_snmp_if_new ()
1387{
1388 struct ospf_snmp_if *osif;
1389
1390 osif = XMALLOC (0, sizeof (struct ospf_snmp_if));
1391 memset (osif, 0, sizeof (struct ospf_snmp_if));
1392 return osif;
1393}
1394
1395void
1396ospf_snmp_if_free (struct ospf_snmp_if *osif)
1397{
1398 XFREE (0, osif);
1399}
1400
1401void
1402ospf_snmp_if_delete (struct interface *ifp)
1403{
1404 struct listnode *nn;
1405 struct ospf_snmp_if *osif;
1406
1407 LIST_LOOP (ospf_snmp_iflist, osif, nn)
1408 {
1409 if (osif->ifp == ifp)
1410 {
1411 list_delete_node (ospf_snmp_iflist, nn);
1412 ospf_snmp_if_free (osif);
1413 return;
1414 }
1415 }
1416}
1417
1418void
1419ospf_snmp_if_update (struct interface *ifp)
1420{
1421 struct listnode *nn;
1422 struct listnode *pn;
1423 struct connected *ifc;
1424 struct prefix *p;
1425 struct ospf_snmp_if *osif;
1426 struct in_addr *addr;
1427 unsigned int ifindex;
1428
1429 ospf_snmp_if_delete (ifp);
1430
1431 p = NULL;
1432 addr = NULL;
1433 ifindex = 0;
1434
1435 /* Lookup first IPv4 address entry. */
1436 LIST_LOOP (ifp->connected, ifc, nn)
1437 {
hasso3fb9cd62004-10-19 19:44:43 +00001438 if (CONNECTED_POINTOPOINT_HOST(ifc))
paul718e3742002-12-13 20:15:29 +00001439 p = ifc->destination;
1440 else
1441 p = ifc->address;
1442
1443 if (p->family == AF_INET)
1444 {
1445 addr = &p->u.prefix4;
1446 break;
1447 }
1448 }
1449 if (! addr)
1450 ifindex = ifp->ifindex;
1451
1452 /* Add interface to the list. */
1453 pn = NULL;
1454 LIST_LOOP (ospf_snmp_iflist, osif, nn)
1455 {
1456 if (addr)
1457 {
1458 if (ntohl (osif->addr.s_addr) > ntohl (addr->s_addr))
1459 break;
1460 }
1461 else
1462 {
1463 /* Unnumbered interface. */
1464 if (osif->addr.s_addr != 0 || osif->ifindex > ifindex)
1465 break;
1466 }
1467 pn = nn;
1468 }
1469
1470 osif = ospf_snmp_if_new ();
1471 if (addr)
1472 osif->addr = *addr;
1473 else
1474 osif->ifindex = ifindex;
1475 osif->ifp = ifp;
1476
1477 listnode_add_after (ospf_snmp_iflist, pn, osif);
1478}
1479
1480struct interface *
1481ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex)
1482{
1483 struct listnode *nn;
1484 struct ospf_snmp_if *osif;
1485
1486 LIST_LOOP (ospf_snmp_iflist, osif, nn)
1487 {
1488 if (ifaddr->s_addr)
1489 {
1490 if (IPV4_ADDR_SAME (&osif->addr, ifaddr))
1491 return osif->ifp;
1492 }
1493 else
1494 {
1495 if (osif->ifindex == *ifindex)
1496 return osif->ifp;
1497 }
1498 }
1499 return NULL;
1500}
1501
1502struct interface *
1503ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex,
1504 int ifaddr_next, int ifindex_next)
1505{
1506 struct ospf_snmp_if *osif;
1507 struct listnode *nn;
1508
1509 if (ifaddr_next)
1510 {
1511 nn = listhead (ospf_snmp_iflist);
1512 if (nn)
1513 {
1514 osif = getdata (nn);
1515 *ifaddr = osif->addr;
1516 *ifindex = osif->ifindex;
1517 return osif->ifp;
1518 }
1519 return NULL;
1520 }
1521
1522 LIST_LOOP (ospf_snmp_iflist, osif, nn)
1523 {
1524 if (ifaddr->s_addr)
1525 {
1526 if (ntohl (osif->addr.s_addr) > ntohl (ifaddr->s_addr))
1527 {
1528 *ifaddr = osif->addr;
1529 *ifindex = osif->ifindex;
1530 return osif->ifp;
1531 }
1532 }
1533 else
1534 {
1535 if (osif->ifindex > *ifindex || osif->addr.s_addr)
1536 {
1537 *ifaddr = osif->addr;
1538 *ifindex = osif->ifindex;
1539 return osif->ifp;
1540 }
1541 }
1542 }
1543 return NULL;
1544}
1545
1546int
1547ospf_snmp_iftype (struct interface *ifp)
1548{
1549#define ospf_snmp_iftype_broadcast 1
1550#define ospf_snmp_iftype_nbma 2
1551#define ospf_snmp_iftype_pointToPoint 3
1552#define ospf_snmp_iftype_pointToMultipoint 5
1553 if (if_is_broadcast (ifp))
1554 return ospf_snmp_iftype_broadcast;
1555 if (if_is_pointopoint (ifp))
1556 return ospf_snmp_iftype_pointToPoint;
1557 return ospf_snmp_iftype_broadcast;
1558}
1559
1560struct interface *
1561ospfIfLookup (struct variable *v, oid *name, size_t *length,
1562 struct in_addr *ifaddr, unsigned int *ifindex, int exact)
1563{
paul6c835672004-10-11 11:00:30 +00001564 unsigned int len;
paul718e3742002-12-13 20:15:29 +00001565 int ifaddr_next = 0;
1566 int ifindex_next = 0;
1567 struct interface *ifp;
1568 oid *offset;
1569
1570 if (exact)
1571 {
1572 if (*length != v->namelen + IN_ADDR_SIZE + 1)
1573 return NULL;
1574
1575 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr);
1576 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1577
1578 return ospf_snmp_if_lookup (ifaddr, ifindex);
1579 }
1580 else
1581 {
1582 len = *length - v->namelen;
1583 if (len >= IN_ADDR_SIZE)
1584 len = IN_ADDR_SIZE;
1585 if (len <= 0)
1586 ifaddr_next = 1;
1587
1588 oid2in_addr (name + v->namelen, len, ifaddr);
1589
1590 len = *length - v->namelen - IN_ADDR_SIZE;
1591 if (len >= 1)
1592 len = 1;
1593 else
1594 ifindex_next = 1;
1595
1596 if (len == 1)
1597 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1598
1599 ifp = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next,
1600 ifindex_next);
1601 if (ifp)
1602 {
1603 *length = v->namelen + IN_ADDR_SIZE + 1;
1604 offset = name + v->namelen;
1605 oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE);
1606 offset += IN_ADDR_SIZE;
1607 *offset = *ifindex;
1608 return ifp;
1609 }
1610 }
1611 return NULL;
1612}
1613
1614static u_char *
1615ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact,
1616 size_t *var_len, WriteMethod **write_method)
1617{
1618 struct interface *ifp;
1619 unsigned int ifindex;
1620 struct in_addr ifaddr;
1621 struct ospf_interface *oi;
paul020709f2003-04-04 02:44:16 +00001622 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001623
1624 ifindex = 0;
1625 memset (&ifaddr, 0, sizeof (struct in_addr));
1626
1627 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001628 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001629 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001630 return NULL;
1631
1632 ifp = ospfIfLookup (v, name, length, &ifaddr, &ifindex, exact);
1633 if (ifp == NULL)
1634 return NULL;
1635
paul68980082003-03-25 05:07:42 +00001636 oi = ospf_if_lookup_by_local_addr (ospf, ifp, ifaddr);
paul718e3742002-12-13 20:15:29 +00001637 if (oi == NULL)
1638 return NULL;
1639
1640 /* Return the current value of the variable */
1641 switch (v->magic)
1642 {
1643 case OSPFIFIPADDRESS: /* 1 */
1644 return SNMP_IPADDRESS (ifaddr);
1645 break;
1646 case OSPFADDRESSLESSIF: /* 2 */
1647 return SNMP_INTEGER (ifindex);
1648 break;
1649 case OSPFIFAREAID: /* 3 */
1650 if (oi->area)
1651 return SNMP_IPADDRESS (oi->area->area_id);
1652 else
1653 return SNMP_IPADDRESS (ospf_empty_addr);
1654 break;
1655 case OSPFIFTYPE: /* 4 */
1656 return SNMP_INTEGER (ospf_snmp_iftype (ifp));
1657 break;
1658 case OSPFIFADMINSTAT: /* 5 */
1659 if (oi)
1660 return SNMP_INTEGER (OSPF_STATUS_ENABLED);
1661 else
1662 return SNMP_INTEGER (OSPF_STATUS_DISABLED);
1663 break;
1664 case OSPFIFRTRPRIORITY: /* 6 */
1665 return SNMP_INTEGER (PRIORITY (oi));
1666 break;
1667 case OSPFIFTRANSITDELAY: /* 7 */
1668 return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
1669 break;
1670 case OSPFIFRETRANSINTERVAL: /* 8 */
1671 return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
1672 break;
1673 case OSPFIFHELLOINTERVAL: /* 9 */
1674 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
1675 break;
1676 case OSPFIFRTRDEADINTERVAL: /* 10 */
1677 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
1678 break;
1679 case OSPFIFPOLLINTERVAL: /* 11 */
1680 return SNMP_INTEGER (OSPF_POLL_INTERVAL_DEFAULT);
1681 break;
1682 case OSPFIFSTATE: /* 12 */
1683 return SNMP_INTEGER (oi->state);
1684 break;
1685 case OSPFIFDESIGNATEDROUTER: /* 13 */
1686 return SNMP_IPADDRESS (DR (oi));
1687 break;
1688 case OSPFIFBACKUPDESIGNATEDROUTER: /* 14 */
1689 return SNMP_IPADDRESS (BDR (oi));
1690 break;
1691 case OSPFIFEVENTS: /* 15 */
1692 return SNMP_INTEGER (oi->state_change);
1693 break;
1694 case OSPFIFAUTHKEY: /* 16 */
1695 *var_len = 0;
1696 return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
1697 break;
1698 case OSPFIFSTATUS: /* 17 */
1699 return SNMP_INTEGER (SNMP_VALID);
1700 break;
1701 case OSPFIFMULTICASTFORWARDING: /* 18 */
1702#define ospf_snmp_multiforward_blocked 1
1703#define ospf_snmp_multiforward_multicast 2
1704#define ospf_snmp_multiforward_unicast 3
1705 return SNMP_INTEGER (ospf_snmp_multiforward_blocked);
1706 break;
1707 case OSPFIFDEMAND: /* 19 */
1708 return SNMP_INTEGER (SNMP_FALSE);
1709 break;
1710 case OSPFIFAUTHTYPE: /* 20 */
1711 if (oi->area)
1712 return SNMP_INTEGER (oi->area->auth_type);
1713 else
1714 return SNMP_INTEGER (0);
1715 break;
1716 default:
1717 return NULL;
1718 break;
1719 }
1720 return NULL;
1721}
1722
1723#define OSPF_SNMP_METRIC_VALUE 1
1724
1725struct interface *
1726ospfIfMetricLookup (struct variable *v, oid *name, size_t *length,
1727 struct in_addr *ifaddr, unsigned int *ifindex, int exact)
1728{
paul6c835672004-10-11 11:00:30 +00001729 unsigned int len;
paul718e3742002-12-13 20:15:29 +00001730 int ifaddr_next = 0;
1731 int ifindex_next = 0;
1732 struct interface *ifp;
1733 oid *offset;
1734 int metric;
1735
1736 if (exact)
1737 {
1738 if (*length != v->namelen + IN_ADDR_SIZE + 1 + 1)
1739 return NULL;
1740
1741 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr);
1742 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1743 metric = name[v->namelen + IN_ADDR_SIZE + 1];
1744
1745 if (metric != OSPF_SNMP_METRIC_VALUE)
1746 return NULL;
1747
1748 return ospf_snmp_if_lookup (ifaddr, ifindex);
1749 }
1750 else
1751 {
1752 len = *length - v->namelen;
1753 if (len >= IN_ADDR_SIZE)
1754 len = IN_ADDR_SIZE;
1755 else
1756 ifaddr_next = 1;
1757
1758 oid2in_addr (name + v->namelen, len, ifaddr);
1759
1760 len = *length - v->namelen - IN_ADDR_SIZE;
1761 if (len >= 1)
1762 len = 1;
1763 else
1764 ifindex_next = 1;
1765
1766 if (len == 1)
1767 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1768
1769 ifp = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next,
1770 ifindex_next);
1771 if (ifp)
1772 {
1773 *length = v->namelen + IN_ADDR_SIZE + 1 + 1;
1774 offset = name + v->namelen;
1775 oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE);
1776 offset += IN_ADDR_SIZE;
1777 *offset = *ifindex;
1778 offset++;
1779 *offset = OSPF_SNMP_METRIC_VALUE;
1780 return ifp;
1781 }
1782 }
1783 return NULL;
1784}
1785
1786static u_char *
1787ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact,
1788 size_t *var_len, WriteMethod **write_method)
1789{
1790 /* Currently we support metric 1 only. */
1791 struct interface *ifp;
1792 unsigned int ifindex;
1793 struct in_addr ifaddr;
1794 struct ospf_interface *oi;
paul020709f2003-04-04 02:44:16 +00001795 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001796
1797 ifindex = 0;
1798 memset (&ifaddr, 0, sizeof (struct in_addr));
1799
1800 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001801 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001802 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001803 return NULL;
1804
1805 ifp = ospfIfMetricLookup (v, name, length, &ifaddr, &ifindex, exact);
1806 if (ifp == NULL)
1807 return NULL;
1808
paul68980082003-03-25 05:07:42 +00001809 oi = ospf_if_lookup_by_local_addr (ospf, ifp, ifaddr);
paul718e3742002-12-13 20:15:29 +00001810 if (oi == NULL)
1811 return NULL;
1812
1813 /* Return the current value of the variable */
1814 switch (v->magic)
1815 {
1816 case OSPFIFMETRICIPADDRESS:
1817 return SNMP_IPADDRESS (ifaddr);
1818 break;
1819 case OSPFIFMETRICADDRESSLESSIF:
1820 return SNMP_INTEGER (ifindex);
1821 break;
1822 case OSPFIFMETRICTOS:
1823 return SNMP_INTEGER (0);
1824 break;
1825 case OSPFIFMETRICVALUE:
1826 return SNMP_INTEGER (OSPF_SNMP_METRIC_VALUE);
1827 break;
1828 case OSPFIFMETRICSTATUS:
1829 return SNMP_INTEGER (1);
1830 break;
1831 default:
1832 return NULL;
1833 break;
1834 }
1835 return NULL;
1836}
1837
1838struct route_table *ospf_snmp_vl_table;
1839
1840void
1841ospf_snmp_vl_add (struct ospf_vl_data *vl_data)
1842{
1843 struct prefix_ls lp;
1844 struct route_node *rn;
1845
1846 memset (&lp, 0, sizeof (struct prefix_ls));
1847 lp.family = 0;
1848 lp.prefixlen = 64;
1849 lp.id = vl_data->vl_area_id;
1850 lp.adv_router = vl_data->vl_peer;
1851
1852 rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp);
1853 rn->info = vl_data;
1854}
1855
1856void
1857ospf_snmp_vl_delete (struct ospf_vl_data *vl_data)
1858{
1859 struct prefix_ls lp;
1860 struct route_node *rn;
1861
1862 memset (&lp, 0, sizeof (struct prefix_ls));
1863 lp.family = 0;
1864 lp.prefixlen = 64;
1865 lp.id = vl_data->vl_area_id;
1866 lp.adv_router = vl_data->vl_peer;
1867
1868 rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
1869 if (! rn)
1870 return;
1871 rn->info = NULL;
1872 route_unlock_node (rn);
1873 route_unlock_node (rn);
1874}
1875
1876struct ospf_vl_data *
1877ospf_snmp_vl_lookup (struct in_addr *area_id, struct in_addr *neighbor)
1878{
1879 struct prefix_ls lp;
1880 struct route_node *rn;
1881 struct ospf_vl_data *vl_data;
1882
1883 memset (&lp, 0, sizeof (struct prefix_ls));
1884 lp.family = 0;
1885 lp.prefixlen = 64;
1886 lp.id = *area_id;
1887 lp.adv_router = *neighbor;
1888
1889 rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
1890 if (rn)
1891 {
1892 vl_data = rn->info;
1893 route_unlock_node (rn);
1894 return vl_data;
1895 }
1896 return NULL;
1897}
1898
1899struct ospf_vl_data *
1900ospf_snmp_vl_lookup_next (struct in_addr *area_id, struct in_addr *neighbor,
1901 int first)
1902{
1903 struct prefix_ls lp;
1904 struct route_node *rn;
1905 struct ospf_vl_data *vl_data;
1906
1907 memset (&lp, 0, sizeof (struct prefix_ls));
1908 lp.family = 0;
1909 lp.prefixlen = 64;
1910 lp.id = *area_id;
1911 lp.adv_router = *neighbor;
1912
1913 if (first)
1914 rn = route_top (ospf_snmp_vl_table);
1915 else
1916 {
1917 rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp);
1918 rn = route_next (rn);
1919 }
1920
1921 for (; rn; rn = route_next (rn))
1922 if (rn->info)
1923 break;
1924
1925 if (rn && rn->info)
1926 {
1927 vl_data = rn->info;
1928 *area_id = vl_data->vl_area_id;
1929 *neighbor = vl_data->vl_peer;
1930 route_unlock_node (rn);
1931 return vl_data;
1932 }
1933 return NULL;
1934}
1935
1936struct ospf_vl_data *
1937ospfVirtIfLookup (struct variable *v, oid *name, size_t *length,
1938 struct in_addr *area_id, struct in_addr *neighbor, int exact)
1939{
1940 int first;
paul6c835672004-10-11 11:00:30 +00001941 unsigned int len;
paul718e3742002-12-13 20:15:29 +00001942 struct ospf_vl_data *vl_data;
1943
1944 if (exact)
1945 {
1946 if (*length != v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE)
1947 return NULL;
1948
1949 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, area_id);
1950 oid2in_addr (name + v->namelen + IN_ADDR_SIZE, IN_ADDR_SIZE, neighbor);
1951
1952 return ospf_snmp_vl_lookup (area_id, neighbor);
1953 }
1954 else
1955 {
1956 first = 0;
1957
1958 len = *length - v->namelen;
1959 if (len <= 0)
1960 first = 1;
1961 if (len > IN_ADDR_SIZE)
1962 len = IN_ADDR_SIZE;
1963 oid2in_addr (name + v->namelen, len, area_id);
1964
1965 len = *length - v->namelen - IN_ADDR_SIZE;
1966 if (len > IN_ADDR_SIZE)
1967 len = IN_ADDR_SIZE;
1968 oid2in_addr (name + v->namelen + IN_ADDR_SIZE, len, neighbor);
1969
1970 vl_data = ospf_snmp_vl_lookup_next (area_id, neighbor, first);
1971
1972 if (vl_data)
1973 {
1974 *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
1975 oid_copy_addr (name + v->namelen, area_id, IN_ADDR_SIZE);
1976 oid_copy_addr (name + v->namelen + IN_ADDR_SIZE, neighbor,
1977 IN_ADDR_SIZE);
1978 return vl_data;
1979 }
1980 }
1981 return NULL;
1982}
1983
1984static u_char *
1985ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact,
1986 size_t *var_len, WriteMethod **write_method)
1987{
1988 struct ospf_vl_data *vl_data;
1989 struct ospf_interface *oi;
1990 struct in_addr area_id;
1991 struct in_addr neighbor;
1992
1993 memset (&area_id, 0, sizeof (struct in_addr));
1994 memset (&neighbor, 0, sizeof (struct in_addr));
1995
1996 vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
1997 if (! vl_data)
1998 return NULL;
1999 oi = vl_data->vl_oi;
2000 if (! oi)
2001 return NULL;
2002
2003 /* Return the current value of the variable */
2004 switch (v->magic)
2005 {
2006 case OSPFVIRTIFAREAID:
2007 return SNMP_IPADDRESS (area_id);
2008 break;
2009 case OSPFVIRTIFNEIGHBOR:
2010 return SNMP_IPADDRESS (neighbor);
2011 break;
2012 case OSPFVIRTIFTRANSITDELAY:
2013 return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
2014 break;
2015 case OSPFVIRTIFRETRANSINTERVAL:
2016 return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
2017 break;
2018 case OSPFVIRTIFHELLOINTERVAL:
2019 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
2020 break;
2021 case OSPFVIRTIFRTRDEADINTERVAL:
2022 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
2023 break;
2024 case OSPFVIRTIFSTATE:
2025 return SNMP_INTEGER (oi->state);
2026 break;
2027 case OSPFVIRTIFEVENTS:
2028 return SNMP_INTEGER (oi->state_change);
2029 break;
2030 case OSPFVIRTIFAUTHKEY:
2031 *var_len = 0;
2032 return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
2033 break;
2034 case OSPFVIRTIFSTATUS:
2035 return SNMP_INTEGER (SNMP_VALID);
2036 break;
2037 case OSPFVIRTIFAUTHTYPE:
2038 if (oi->area)
2039 return SNMP_INTEGER (oi->area->auth_type);
2040 else
2041 return SNMP_INTEGER (0);
2042 break;
2043 default:
2044 return NULL;
2045 break;
2046 }
2047 return NULL;
2048}
2049
2050struct ospf_neighbor *
paul68980082003-03-25 05:07:42 +00002051ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr,
2052 unsigned int *ifindex)
paul718e3742002-12-13 20:15:29 +00002053{
2054 struct listnode *nn;
2055 struct ospf_interface *oi;
2056 struct ospf_neighbor *nbr;
2057 struct route_node *rn;
2058
paul68980082003-03-25 05:07:42 +00002059 LIST_LOOP (ospf->oiflist, oi, nn)
paul718e3742002-12-13 20:15:29 +00002060 {
2061 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
2062 if ((nbr = rn->info) != NULL
2063 && nbr != oi->nbr_self
2064 && nbr->state != NSM_Down
2065 && nbr->src.s_addr != 0)
2066 {
2067 if (IPV4_ADDR_SAME (&nbr->src, nbr_addr))
2068 {
2069 route_unlock_node (rn);
2070 return nbr;
2071 }
2072 }
2073 }
2074 return NULL;
2075}
2076
2077struct ospf_neighbor *
2078ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex,
2079 int first)
2080{
2081 struct listnode *nn;
2082 struct ospf_interface *oi;
2083 struct ospf_neighbor *nbr;
2084 struct route_node *rn;
2085 struct ospf_neighbor *min = NULL;
paul020709f2003-04-04 02:44:16 +00002086 struct ospf *ospf = ospf;
paul718e3742002-12-13 20:15:29 +00002087
paul020709f2003-04-04 02:44:16 +00002088 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00002089 LIST_LOOP (ospf->oiflist, oi, nn)
paul718e3742002-12-13 20:15:29 +00002090 {
2091 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
2092 if ((nbr = rn->info) != NULL
2093 && nbr != oi->nbr_self
2094 && nbr->state != NSM_Down
2095 && nbr->src.s_addr != 0)
2096 {
2097 if (first)
2098 {
2099 if (! min)
2100 min = nbr;
2101 else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
2102 min = nbr;
2103 }
2104 else if (ntohl (nbr->src.s_addr) > ntohl (nbr_addr->s_addr))
2105 {
2106 if (! min)
2107 min = nbr;
2108 else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
2109 min = nbr;
2110 }
2111 }
2112 }
2113 if (min)
2114 {
2115 *nbr_addr = min->src;
2116 *ifindex = 0;
2117 return min;
2118 }
2119 return NULL;
2120}
2121
2122struct ospf_neighbor *
2123ospfNbrLookup (struct variable *v, oid *name, size_t *length,
2124 struct in_addr *nbr_addr, unsigned int *ifindex, int exact)
2125{
paul6c835672004-10-11 11:00:30 +00002126 unsigned int len;
paul718e3742002-12-13 20:15:29 +00002127 int first;
2128 struct ospf_neighbor *nbr;
paul020709f2003-04-04 02:44:16 +00002129 struct ospf *ospf;
2130
2131 ospf = ospf_lookup ();
paul718e3742002-12-13 20:15:29 +00002132
2133 if (exact)
2134 {
2135 if (*length != v->namelen + IN_ADDR_SIZE + 1)
2136 return NULL;
2137
2138 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, nbr_addr);
2139 *ifindex = name[v->namelen + IN_ADDR_SIZE];
2140
paul68980082003-03-25 05:07:42 +00002141 return ospf_snmp_nbr_lookup (ospf, nbr_addr, ifindex);
paul718e3742002-12-13 20:15:29 +00002142 }
2143 else
2144 {
2145 first = 0;
2146 len = *length - v->namelen;
2147
2148 if (len <= 0)
2149 first = 1;
2150
2151 if (len > IN_ADDR_SIZE)
2152 len = IN_ADDR_SIZE;
2153
2154 oid2in_addr (name + v->namelen, len, nbr_addr);
2155
2156 len = *length - v->namelen - IN_ADDR_SIZE;
2157 if (len >= 1)
2158 *ifindex = name[v->namelen + IN_ADDR_SIZE];
2159
2160 nbr = ospf_snmp_nbr_lookup_next (nbr_addr, ifindex, first);
2161
2162 if (nbr)
2163 {
2164 *length = v->namelen + IN_ADDR_SIZE + 1;
2165 oid_copy_addr (name + v->namelen, nbr_addr, IN_ADDR_SIZE);
2166 name[v->namelen + IN_ADDR_SIZE] = *ifindex;
2167 return nbr;
2168 }
2169 }
2170 return NULL;
2171}
2172
2173static u_char *
2174ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
2175 size_t *var_len, WriteMethod **write_method)
2176{
2177 struct in_addr nbr_addr;
2178 unsigned int ifindex;
2179 struct ospf_neighbor *nbr;
2180 struct ospf_interface *oi;
2181
2182 memset (&nbr_addr, 0, sizeof (struct in_addr));
2183 ifindex = 0;
2184
2185 nbr = ospfNbrLookup (v, name, length, &nbr_addr, &ifindex, exact);
2186 if (! nbr)
2187 return NULL;
2188 oi = nbr->oi;
2189 if (! oi)
2190 return NULL;
2191
2192 /* Return the current value of the variable */
2193 switch (v->magic)
2194 {
2195 case OSPFNBRIPADDR:
2196 return SNMP_IPADDRESS (nbr_addr);
2197 break;
2198 case OSPFNBRADDRESSLESSINDEX:
2199 return SNMP_INTEGER (ifindex);
2200 break;
2201 case OSPFNBRRTRID:
2202 return SNMP_IPADDRESS (nbr->router_id);
2203 break;
2204 case OSPFNBROPTIONS:
2205 return SNMP_INTEGER (oi->nbr_self->options);
2206 break;
2207 case OSPFNBRPRIORITY:
2208 return SNMP_INTEGER (nbr->priority);
2209 break;
2210 case OSPFNBRSTATE:
2211 return SNMP_INTEGER (nbr->state);
2212 break;
2213 case OSPFNBREVENTS:
2214 return SNMP_INTEGER (nbr->state_change);
2215 break;
2216 case OSPFNBRLSRETRANSQLEN:
2217 return SNMP_INTEGER (ospf_ls_retransmit_count (nbr));
2218 break;
2219 case OSPFNBMANBRSTATUS:
2220 return SNMP_INTEGER (SNMP_VALID);
2221 break;
2222 case OSPFNBMANBRPERMANENCE:
2223 return SNMP_INTEGER (2);
2224 break;
2225 case OSPFNBRHELLOSUPPRESSED:
2226 return SNMP_INTEGER (SNMP_FALSE);
2227 break;
2228 default:
2229 return NULL;
2230 break;
2231 }
2232 return NULL;
2233}
2234
2235static u_char *
2236ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
2237 size_t *var_len, WriteMethod **write_method)
2238{
2239 struct ospf_vl_data *vl_data;
2240 struct in_addr area_id;
2241 struct in_addr neighbor;
paul020709f2003-04-04 02:44:16 +00002242 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002243
2244 memset (&area_id, 0, sizeof (struct in_addr));
2245 memset (&neighbor, 0, sizeof (struct in_addr));
2246
2247 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00002248 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00002249 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00002250 return NULL;
2251
2252 vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
2253 if (! vl_data)
2254 return NULL;
2255
2256 /* Return the current value of the variable */
2257 switch (v->magic)
2258 {
2259 case OSPFVIRTNBRAREA:
2260 return (u_char *) NULL;
2261 break;
2262 case OSPFVIRTNBRRTRID:
2263 return (u_char *) NULL;
2264 break;
2265 case OSPFVIRTNBRIPADDR:
2266 return (u_char *) NULL;
2267 break;
2268 case OSPFVIRTNBROPTIONS:
2269 return (u_char *) NULL;
2270 break;
2271 case OSPFVIRTNBRSTATE:
2272 return (u_char *) NULL;
2273 break;
2274 case OSPFVIRTNBREVENTS:
2275 return (u_char *) NULL;
2276 break;
2277 case OSPFVIRTNBRLSRETRANSQLEN:
2278 return (u_char *) NULL;
2279 break;
2280 case OSPFVIRTNBRHELLOSUPPRESSED:
2281 return (u_char *) NULL;
2282 break;
2283 default:
2284 return NULL;
2285 break;
2286 }
2287 return NULL;
2288}
2289
2290struct ospf_lsa *
2291ospfExtLsdbLookup (struct variable *v, oid *name, size_t *length, u_char *type,
2292 struct in_addr *ls_id, struct in_addr *router_id, int exact)
2293{
2294 int first;
2295 oid *offset;
2296 int offsetlen;
2297 u_char lsa_type;
paul6c835672004-10-11 11:00:30 +00002298 unsigned int len;
paul718e3742002-12-13 20:15:29 +00002299 struct ospf_lsa *lsa;
paul020709f2003-04-04 02:44:16 +00002300 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002301
paul020709f2003-04-04 02:44:16 +00002302 ospf = ospf_lookup ();
paul718e3742002-12-13 20:15:29 +00002303 if (exact)
2304 {
2305 if (*length != v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
2306 return NULL;
2307
2308 offset = name + v->namelen;
2309
2310 /* Make it sure given value match to type. */
2311 lsa_type = *offset;
2312 offset++;
2313
2314 if (lsa_type != *type)
2315 return NULL;
2316
2317 /* LS ID. */
2318 oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
2319 offset += IN_ADDR_SIZE;
2320
2321 /* Router ID. */
2322 oid2in_addr (offset, IN_ADDR_SIZE, router_id);
2323
paul68980082003-03-25 05:07:42 +00002324 return ospf_lsdb_lookup_by_id (ospf->lsdb, *type, *ls_id, *router_id);
paul718e3742002-12-13 20:15:29 +00002325 }
2326 else
2327 {
2328 /* Get variable length. */
2329 first = 0;
2330 offset = name + v->namelen;
2331 offsetlen = *length - v->namelen;
2332
2333 /* LSA type value. */
2334 lsa_type = *offset;
2335 offset++;
2336 offsetlen--;
2337
2338 if (offsetlen <= 0 || lsa_type < OSPF_AS_EXTERNAL_LSA)
2339 first = 1;
2340
2341 /* LS ID. */
2342 len = offsetlen;
2343 if (len > IN_ADDR_SIZE)
2344 len = IN_ADDR_SIZE;
2345
2346 oid2in_addr (offset, len, ls_id);
2347
2348 offset += IN_ADDR_SIZE;
2349 offsetlen -= IN_ADDR_SIZE;
2350
2351 /* Router ID. */
2352 len = offsetlen;
2353 if (len > IN_ADDR_SIZE)
2354 len = IN_ADDR_SIZE;
2355
2356 oid2in_addr (offset, len, router_id);
2357
paul68980082003-03-25 05:07:42 +00002358 lsa = ospf_lsdb_lookup_by_id_next (ospf->lsdb, *type, *ls_id,
paul718e3742002-12-13 20:15:29 +00002359 *router_id, first);
2360
2361 if (lsa)
2362 {
2363 /* Fill in length. */
2364 *length = v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE;
2365
2366 /* Fill in value. */
2367 offset = name + v->namelen;
2368
2369 *offset = OSPF_AS_EXTERNAL_LSA;
2370 offset++;
2371 oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
2372 offset += IN_ADDR_SIZE;
2373 oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
2374
2375 return lsa;
2376 }
2377 }
2378 return NULL;
2379}
2380
2381static u_char *
2382ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
2383 size_t *var_len, WriteMethod **write_method)
2384{
2385 struct ospf_lsa *lsa;
2386 struct lsa_header *lsah;
2387 u_char type;
2388 struct in_addr ls_id;
2389 struct in_addr router_id;
paul020709f2003-04-04 02:44:16 +00002390 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002391
2392 type = OSPF_AS_EXTERNAL_LSA;
2393 memset (&ls_id, 0, sizeof (struct in_addr));
2394 memset (&router_id, 0, sizeof (struct in_addr));
2395
2396 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00002397 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00002398 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00002399 return NULL;
2400
2401 lsa = ospfExtLsdbLookup (v, name, length, &type, &ls_id, &router_id, exact);
2402 if (! lsa)
2403 return NULL;
2404
2405 lsah = lsa->data;
2406
2407 /* Return the current value of the variable */
2408 switch (v->magic)
2409 {
2410 case OSPFEXTLSDBTYPE:
2411 return SNMP_INTEGER (OSPF_AS_EXTERNAL_LSA);
2412 break;
2413 case OSPFEXTLSDBLSID:
2414 return SNMP_IPADDRESS (lsah->id);
2415 break;
2416 case OSPFEXTLSDBROUTERID:
2417 return SNMP_IPADDRESS (lsah->adv_router);
2418 break;
2419 case OSPFEXTLSDBSEQUENCE:
2420 return SNMP_INTEGER (lsah->ls_seqnum);
2421 break;
2422 case OSPFEXTLSDBAGE:
2423 return SNMP_INTEGER (lsah->ls_age);
2424 break;
2425 case OSPFEXTLSDBCHECKSUM:
2426 return SNMP_INTEGER (lsah->checksum);
2427 break;
2428 case OSPFEXTLSDBADVERTISEMENT:
2429 *var_len = ntohs (lsah->length);
2430 return (u_char *) lsah;
2431 break;
2432 default:
2433 return NULL;
2434 break;
2435 }
2436 return NULL;
2437}
2438
2439static u_char *
2440ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length,
2441 int exact, size_t *var_len, WriteMethod **write_method)
2442{
2443 /* Return the current value of the variable */
2444 switch (v->magic)
2445 {
2446 case OSPFAREAAGGREGATEAREAID:
2447 return (u_char *) NULL;
2448 break;
2449 case OSPFAREAAGGREGATELSDBTYPE:
2450 return (u_char *) NULL;
2451 break;
2452 case OSPFAREAAGGREGATENET:
2453 return (u_char *) NULL;
2454 break;
2455 case OSPFAREAAGGREGATEMASK:
2456 return (u_char *) NULL;
2457 break;
2458 case OSPFAREAAGGREGATESTATUS:
2459 return (u_char *) NULL;
2460 break;
2461 case OSPFAREAAGGREGATEEFFECT:
2462 return (u_char *) NULL;
2463 break;
2464 default:
2465 return NULL;
2466 break;
2467 }
2468 return NULL;
2469}
2470
2471/* Register OSPF2-MIB. */
2472void
2473ospf_snmp_init ()
2474{
2475 ospf_snmp_iflist = list_new ();
2476 ospf_snmp_vl_table = route_table_init ();
hassoc75105a2004-10-13 10:33:26 +00002477 smux_init (om->master);
paul718e3742002-12-13 20:15:29 +00002478 REGISTER_MIB("mibII/ospf", ospf_variables, variable, ospf_oid);
paul718e3742002-12-13 20:15:29 +00002479}
2480#endif /* HAVE_SNMP */