blob: 4ed1fab8900dffc662bb357fb5dac5cec2af359c [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
paul1eb8ef22005-04-07 07:30:20 +0000502 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
503 if (oi && oi->address)
504 return 1;
paul718e3742002-12-13 20:15:29 +0000505
paul718e3742002-12-13 20:15:29 +0000506 return 0;
507}
508
509static u_char *
510ospfGeneralGroup (struct variable *v, oid *name, size_t *length,
511 int exact, size_t *var_len, WriteMethod **write_method)
512{
paul020709f2003-04-04 02:44:16 +0000513 struct ospf *ospf;
514
515 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +0000516
paul718e3742002-12-13 20:15:29 +0000517 /* Check whether the instance identifier is valid */
518 if (smux_header_generic (v, name, length, exact, var_len, write_method)
519 == MATCH_FAILED)
520 return NULL;
521
522 /* Return the current value of the variable */
523 switch (v->magic)
524 {
525 case OSPFROUTERID: /* 1 */
526 /* Router-ID of this OSPF instance. */
paul68980082003-03-25 05:07:42 +0000527 if (ospf)
528 return SNMP_IPADDRESS (ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000529 else
530 return SNMP_IPADDRESS (ospf_empty_addr);
531 break;
532 case OSPFADMINSTAT: /* 2 */
533 /* The administrative status of OSPF in the router. */
paul68980082003-03-25 05:07:42 +0000534 if (ospf_admin_stat (ospf))
paul718e3742002-12-13 20:15:29 +0000535 return SNMP_INTEGER (OSPF_STATUS_ENABLED);
536 else
537 return SNMP_INTEGER (OSPF_STATUS_DISABLED);
538 break;
539 case OSPFVERSIONNUMBER: /* 3 */
540 /* OSPF version 2. */
541 return SNMP_INTEGER (OSPF_VERSION);
542 break;
543 case OSPFAREABDRRTRSTATUS: /* 4 */
544 /* Area Border router status. */
paul68980082003-03-25 05:07:42 +0000545 if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ABR))
paul718e3742002-12-13 20:15:29 +0000546 return SNMP_INTEGER (SNMP_TRUE);
547 else
548 return SNMP_INTEGER (SNMP_FALSE);
549 break;
550 case OSPFASBDRRTRSTATUS: /* 5 */
551 /* AS Border router status. */
paul68980082003-03-25 05:07:42 +0000552 if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ASBR))
paul718e3742002-12-13 20:15:29 +0000553 return SNMP_INTEGER (SNMP_TRUE);
554 else
555 return SNMP_INTEGER (SNMP_FALSE);
556 break;
557 case OSPFEXTERNLSACOUNT: /* 6 */
558 /* External LSA counts. */
paul68980082003-03-25 05:07:42 +0000559 if (ospf)
560 return SNMP_INTEGER (ospf_lsdb_count_all (ospf->lsdb));
paul718e3742002-12-13 20:15:29 +0000561 else
562 return SNMP_INTEGER (0);
563 break;
564 case OSPFEXTERNLSACKSUMSUM: /* 7 */
565 /* External LSA checksum. */
566 return SNMP_INTEGER (0);
567 break;
568 case OSPFTOSSUPPORT: /* 8 */
569 /* TOS is not supported. */
570 return SNMP_INTEGER (SNMP_FALSE);
571 break;
572 case OSPFORIGINATENEWLSAS: /* 9 */
573 /* The number of new link-state advertisements. */
paul68980082003-03-25 05:07:42 +0000574 if (ospf)
575 return SNMP_INTEGER (ospf->lsa_originate_count);
paul718e3742002-12-13 20:15:29 +0000576 else
577 return SNMP_INTEGER (0);
578 break;
579 case OSPFRXNEWLSAS: /* 10 */
580 /* The number of link-state advertisements received determined
581 to be new instantiations. */
paul68980082003-03-25 05:07:42 +0000582 if (ospf)
583 return SNMP_INTEGER (ospf->rx_lsa_count);
paul718e3742002-12-13 20:15:29 +0000584 else
585 return SNMP_INTEGER (0);
586 break;
587 case OSPFEXTLSDBLIMIT: /* 11 */
588 /* There is no limit for the number of non-default
589 AS-external-LSAs. */
590 return SNMP_INTEGER (-1);
591 break;
592 case OSPFMULTICASTEXTENSIONS: /* 12 */
593 /* Multicast Extensions to OSPF is not supported. */
594 return SNMP_INTEGER (0);
595 break;
596 case OSPFEXITOVERFLOWINTERVAL: /* 13 */
597 /* Overflow is not supported. */
598 return SNMP_INTEGER (0);
599 break;
600 case OSPFDEMANDEXTENSIONS: /* 14 */
601 /* Demand routing is not supported. */
602 return SNMP_INTEGER (SNMP_FALSE);
603 break;
604 default:
605 return NULL;
606 }
607 return NULL;
608}
609
610struct ospf_area *
paul68980082003-03-25 05:07:42 +0000611ospf_area_lookup_next (struct ospf *ospf, struct in_addr *area_id, int first)
paul718e3742002-12-13 20:15:29 +0000612{
613 struct ospf_area *area;
paulaa20c6f2004-10-07 14:19:36 +0000614 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000615
paul020709f2003-04-04 02:44:16 +0000616 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000617 return NULL;
618
619 if (first)
620 {
paul68980082003-03-25 05:07:42 +0000621 node = listhead (ospf->areas);
paul718e3742002-12-13 20:15:29 +0000622 if (node)
623 {
paul1eb8ef22005-04-07 07:30:20 +0000624 area = listgetdata (node);
paul718e3742002-12-13 20:15:29 +0000625 *area_id = area->area_id;
626 return area;
627 }
628 return NULL;
629 }
paul1eb8ef22005-04-07 07:30:20 +0000630 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000631 {
paul718e3742002-12-13 20:15:29 +0000632 if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))
633 {
634 *area_id = area->area_id;
635 return area;
636 }
637 }
638 return NULL;
639}
640
641struct ospf_area *
642ospfAreaLookup (struct variable *v, oid name[], size_t *length,
643 struct in_addr *addr, int exact)
644{
paul020709f2003-04-04 02:44:16 +0000645 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000646 struct ospf_area *area;
paul68980082003-03-25 05:07:42 +0000647 int len;
paul718e3742002-12-13 20:15:29 +0000648
paul020709f2003-04-04 02:44:16 +0000649 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +0000650 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000651 return NULL;
652
653 if (exact)
654 {
655 /* Length is insufficient to lookup OSPF area. */
656 if (*length - v->namelen != sizeof (struct in_addr))
657 return NULL;
658
659 oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);
660
paul68980082003-03-25 05:07:42 +0000661 area = ospf_area_lookup_by_area_id (ospf, *addr);
paul718e3742002-12-13 20:15:29 +0000662
663 return area;
664 }
665 else
666 {
667 len = *length - v->namelen;
668 if (len > 4)
669 len = 4;
670
671 oid2in_addr (name + v->namelen, len, addr);
672
paul68980082003-03-25 05:07:42 +0000673 area = ospf_area_lookup_next (ospf, addr, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +0000674
675 if (area == NULL)
676 return NULL;
677
678 oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));
679 *length = sizeof (struct in_addr) + v->namelen;
680
681 return area;
682 }
683 return NULL;
684}
685
686static u_char *
687ospfAreaEntry (struct variable *v, oid *name, size_t *length, int exact,
688 size_t *var_len, WriteMethod **write_method)
689{
690 struct ospf_area *area;
691 struct in_addr addr;
692
693 memset (&addr, 0, sizeof (struct in_addr));
694
695 area = ospfAreaLookup (v, name, length, &addr, exact);
696 if (! area)
697 return NULL;
698
699 /* Return the current value of the variable */
700 switch (v->magic)
701 {
702 case OSPFAREAID: /* 1 */
703 return SNMP_IPADDRESS (area->area_id);
704 break;
705 case OSPFAUTHTYPE: /* 2 */
706 return SNMP_INTEGER (area->auth_type);
707 break;
708 case OSPFIMPORTASEXTERN: /* 3 */
709 return SNMP_INTEGER (area->external_routing + 1);
710 break;
711 case OSPFSPFRUNS: /* 4 */
712 return SNMP_INTEGER (area->spf_calculation);
713 break;
714 case OSPFAREABDRRTRCOUNT: /* 5 */
715 return SNMP_INTEGER (area->abr_count);
716 break;
717 case OSPFASBDRRTRCOUNT: /* 6 */
718 return SNMP_INTEGER (area->asbr_count);
719 break;
720 case OSPFAREALSACOUNT: /* 7 */
721 return SNMP_INTEGER (area->lsdb->total);
722 break;
723 case OSPFAREALSACKSUMSUM: /* 8 */
724 return SNMP_INTEGER (0);
725 break;
726 case OSPFAREASUMMARY: /* 9 */
727#define OSPF_noAreaSummary 1
728#define OSPF_sendAreaSummary 2
729 if (area->no_summary)
730 return SNMP_INTEGER (OSPF_noAreaSummary);
731 else
732 return SNMP_INTEGER (OSPF_sendAreaSummary);
733 break;
734 case OSPFAREASTATUS: /* 10 */
735 return SNMP_INTEGER (SNMP_VALID);
736 break;
737 default:
738 return NULL;
739 break;
740 }
741 return NULL;
742}
743
744struct ospf_area *
745ospf_stub_area_lookup_next (struct in_addr *area_id, int first)
746{
747 struct ospf_area *area;
paulaa20c6f2004-10-07 14:19:36 +0000748 struct listnode *node;
paul020709f2003-04-04 02:44:16 +0000749 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000750
paul020709f2003-04-04 02:44:16 +0000751 ospf = ospf_lookup ();
752 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000753 return NULL;
754
paul1eb8ef22005-04-07 07:30:20 +0000755 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000756 {
paul718e3742002-12-13 20:15:29 +0000757 if (area->external_routing == OSPF_AREA_STUB)
758 {
759 if (first)
760 {
761 *area_id = area->area_id;
762 return area;
763 }
764 else if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))
765 {
766 *area_id = area->area_id;
767 return area;
768 }
769 }
770 }
771 return NULL;
772}
773
774struct ospf_area *
775ospfStubAreaLookup (struct variable *v, oid name[], size_t *length,
776 struct in_addr *addr, int exact)
777{
paul020709f2003-04-04 02:44:16 +0000778 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000779 struct ospf_area *area;
paul68980082003-03-25 05:07:42 +0000780 int len;
paul718e3742002-12-13 20:15:29 +0000781
paul020709f2003-04-04 02:44:16 +0000782 ospf = ospf_lookup ();
783 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000784 return NULL;
785
786 /* Exact lookup. */
787 if (exact)
788 {
789 /* ospfStubAreaID + ospfStubTOS. */
790 if (*length != v->namelen + sizeof (struct in_addr) + 1)
791 return NULL;
792
793 /* Check ospfStubTOS is zero. */
794 if (name[*length - 1] != 0)
795 return NULL;
796
797 oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);
798
paul68980082003-03-25 05:07:42 +0000799 area = ospf_area_lookup_by_area_id (ospf, *addr);
paul718e3742002-12-13 20:15:29 +0000800
801 if (area->external_routing == OSPF_AREA_STUB)
802 return area;
803 else
804 return NULL;
805 }
806 else
807 {
808 len = *length - v->namelen;
809 if (len > 4)
810 len = 4;
811
812 oid2in_addr (name + v->namelen, len, addr);
813
814 area = ospf_stub_area_lookup_next (addr, len == 0 ? 1 : 0);
815
816 if (area == NULL)
817 return NULL;
818
819 oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));
820 /* Set TOS 0. */
821 name[v->namelen + sizeof (struct in_addr)] = 0;
822 *length = v->namelen + sizeof (struct in_addr) + 1;
823
824 return area;
825 }
826 return NULL;
827}
828
829static u_char *
830ospfStubAreaEntry (struct variable *v, oid *name, size_t *length,
831 int exact, size_t *var_len, WriteMethod **write_method)
832{
833 struct ospf_area *area;
834 struct in_addr addr;
835
836 memset (&addr, 0, sizeof (struct in_addr));
837
838 area = ospfStubAreaLookup (v, name, length, &addr, exact);
839 if (! area)
840 return NULL;
841
842 /* Return the current value of the variable */
843 switch (v->magic)
844 {
845 case OSPFSTUBAREAID: /* 1 */
846 /* OSPF stub area id. */
847 return SNMP_IPADDRESS (area->area_id);
848 break;
849 case OSPFSTUBTOS: /* 2 */
850 /* TOS value is not supported. */
851 return SNMP_INTEGER (0);
852 break;
853 case OSPFSTUBMETRIC: /* 3 */
854 /* Default cost to stub area. */
855 return SNMP_INTEGER (area->default_cost);
856 break;
857 case OSPFSTUBSTATUS: /* 4 */
858 /* Status of the stub area. */
859 return SNMP_INTEGER (SNMP_VALID);
860 break;
861 case OSPFSTUBMETRICTYPE: /* 5 */
862 /* OSPF Metric type. */
863#define OSPF_ospfMetric 1
864#define OSPF_comparableCost 2
865#define OSPF_nonComparable 3
866 return SNMP_INTEGER (OSPF_ospfMetric);
867 break;
868 default:
869 return NULL;
870 break;
871 }
872 return NULL;
873}
874
875struct ospf_lsa *
876lsdb_lookup_next (struct ospf_area *area, u_char *type, int type_next,
877 struct in_addr *ls_id, int ls_id_next,
878 struct in_addr *router_id, int router_id_next)
879{
880 struct ospf_lsa *lsa;
881 int i;
882
883 if (type_next)
884 i = OSPF_MIN_LSA;
885 else
886 i = *type;
887
888 for (; i < OSPF_MAX_LSA; i++)
889 {
890 *type = i;
891
892 lsa = ospf_lsdb_lookup_by_id_next (area->lsdb, *type, *ls_id, *router_id,
893 ls_id_next);
894 if (lsa)
895 return lsa;
896
897 ls_id_next = 1;
898 }
899 return NULL;
900}
901
902struct ospf_lsa *
903ospfLsdbLookup (struct variable *v, oid *name, size_t *length,
904 struct in_addr *area_id, u_char *type,
905 struct in_addr *ls_id, struct in_addr *router_id, int exact)
906{
paul020709f2003-04-04 02:44:16 +0000907 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000908 struct ospf_area *area;
909 struct ospf_lsa *lsa;
paul6c835672004-10-11 11:00:30 +0000910 unsigned int len;
paul718e3742002-12-13 20:15:29 +0000911 int type_next;
912 int ls_id_next;
913 int router_id_next;
914 oid *offset;
915 int offsetlen;
916
paul020709f2003-04-04 02:44:16 +0000917 ospf = ospf_lookup ();
918
paul718e3742002-12-13 20:15:29 +0000919#define OSPF_LSDB_ENTRY_OFFSET \
920 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
921
922 if (exact)
923 {
924 /* Area ID + Type + LS ID + Router ID. */
925 if (*length - v->namelen != OSPF_LSDB_ENTRY_OFFSET)
926 return NULL;
927
928 /* Set OID offset for Area ID. */
929 offset = name + v->namelen;
930
931 /* Lookup area first. */
932 oid2in_addr (offset, IN_ADDR_SIZE, area_id);
paul68980082003-03-25 05:07:42 +0000933 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +0000934 if (! area)
935 return NULL;
936 offset += IN_ADDR_SIZE;
937
938 /* Type. */
939 *type = *offset;
940 offset++;
941
942 /* LS ID. */
943 oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
944 offset += IN_ADDR_SIZE;
945
946 /* Router ID. */
947 oid2in_addr (offset, IN_ADDR_SIZE, router_id);
948
949 /* Lookup LSDB. */
950 return ospf_lsdb_lookup_by_id (area->lsdb, *type, *ls_id, *router_id);
951 }
952 else
953 {
954 /* Get variable length. */
955 offset = name + v->namelen;
956 offsetlen = *length - v->namelen;
957 len = offsetlen;
958
959 if (len > IN_ADDR_SIZE)
960 len = IN_ADDR_SIZE;
961
962 oid2in_addr (offset, len, area_id);
963
964 /* First we search area. */
965 if (len == IN_ADDR_SIZE)
paul68980082003-03-25 05:07:42 +0000966 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +0000967 else
paul68980082003-03-25 05:07:42 +0000968 area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +0000969
970 if (area == NULL)
971 return NULL;
972
973 do
974 {
975 /* Next we lookup type. */
976 offset += IN_ADDR_SIZE;
977 offsetlen -= IN_ADDR_SIZE;
978 len = offsetlen;
979
980 if (len <= 0)
981 type_next = 1;
982 else
983 {
984 len = 1;
985 type_next = 0;
986 *type = *offset;
987 }
988
989 /* LS ID. */
990 offset++;
991 offsetlen--;
992 len = offsetlen;
993
994 if (len <= 0)
995 ls_id_next = 1;
996 else
997 {
998 ls_id_next = 0;
999 if (len > IN_ADDR_SIZE)
1000 len = IN_ADDR_SIZE;
1001
1002 oid2in_addr (offset, len, ls_id);
1003 }
1004
1005 /* Router ID. */
1006 offset += IN_ADDR_SIZE;
1007 offsetlen -= IN_ADDR_SIZE;
1008 len = offsetlen;
1009
1010 if (len <= 0)
1011 router_id_next = 1;
1012 else
1013 {
1014 router_id_next = 0;
1015 if (len > IN_ADDR_SIZE)
1016 len = IN_ADDR_SIZE;
1017
1018 oid2in_addr (offset, len, router_id);
1019 }
1020
1021 lsa = lsdb_lookup_next (area, type, type_next, ls_id, ls_id_next,
1022 router_id, router_id_next);
1023
1024 if (lsa)
1025 {
1026 /* Fill in length. */
1027 *length = v->namelen + OSPF_LSDB_ENTRY_OFFSET;
1028
1029 /* Fill in value. */
1030 offset = name + v->namelen;
1031 oid_copy_addr (offset, area_id, IN_ADDR_SIZE);
1032 offset += IN_ADDR_SIZE;
1033 *offset = lsa->data->type;
1034 offset++;
1035 oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
1036 offset += IN_ADDR_SIZE;
1037 oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
1038
1039 return lsa;
1040 }
1041 }
paul68980082003-03-25 05:07:42 +00001042 while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL);
paul718e3742002-12-13 20:15:29 +00001043 }
1044 return NULL;
1045}
1046
1047static u_char *
1048ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
1049 size_t *var_len, WriteMethod **write_method)
1050{
1051 struct ospf_lsa *lsa;
1052 struct lsa_header *lsah;
1053 struct in_addr area_id;
1054 u_char type;
1055 struct in_addr ls_id;
1056 struct in_addr router_id;
paul020709f2003-04-04 02:44:16 +00001057 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001058
1059 /* INDEX { ospfLsdbAreaId, ospfLsdbType,
1060 ospfLsdbLsid, ospfLsdbRouterId } */
1061
1062 memset (&area_id, 0, sizeof (struct in_addr));
1063 type = 0;
1064 memset (&ls_id, 0, sizeof (struct in_addr));
1065 memset (&router_id, 0, sizeof (struct in_addr));
1066
1067 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001068 ospf = ospf_lookup ();
1069 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001070 return NULL;
1071
1072 lsa = ospfLsdbLookup (v, name, length, &area_id, &type, &ls_id, &router_id,
1073 exact);
1074 if (! lsa)
1075 return NULL;
1076
1077 lsah = lsa->data;
1078
1079 /* Return the current value of the variable */
1080 switch (v->magic)
1081 {
1082 case OSPFLSDBAREAID: /* 1 */
1083 return SNMP_IPADDRESS (lsa->area->area_id);
1084 break;
1085 case OSPFLSDBTYPE: /* 2 */
1086 return SNMP_INTEGER (lsah->type);
1087 break;
1088 case OSPFLSDBLSID: /* 3 */
1089 return SNMP_IPADDRESS (lsah->id);
1090 break;
1091 case OSPFLSDBROUTERID: /* 4 */
1092 return SNMP_IPADDRESS (lsah->adv_router);
1093 break;
1094 case OSPFLSDBSEQUENCE: /* 5 */
1095 return SNMP_INTEGER (lsah->ls_seqnum);
1096 break;
1097 case OSPFLSDBAGE: /* 6 */
1098 return SNMP_INTEGER (lsah->ls_age);
1099 break;
1100 case OSPFLSDBCHECKSUM: /* 7 */
1101 return SNMP_INTEGER (lsah->checksum);
1102 break;
1103 case OSPFLSDBADVERTISEMENT: /* 8 */
1104 *var_len = ntohs (lsah->length);
1105 return (u_char *) lsah;
1106 break;
1107 default:
1108 return NULL;
1109 break;
1110 }
1111 return NULL;
1112}
1113
1114struct ospf_area_range *
1115ospfAreaRangeLookup (struct variable *v, oid *name, size_t *length,
1116 struct in_addr *area_id, struct in_addr *range_net,
1117 int exact)
1118{
1119 oid *offset;
1120 int offsetlen;
paul6c835672004-10-11 11:00:30 +00001121 unsigned int len;
paul020709f2003-04-04 02:44:16 +00001122 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001123 struct ospf_area *area;
1124 struct ospf_area_range *range;
1125 struct prefix_ipv4 p;
1126 p.family = AF_INET;
1127 p.prefixlen = IPV4_MAX_BITLEN;
1128
paul020709f2003-04-04 02:44:16 +00001129 ospf = ospf_lookup ();
1130
paul718e3742002-12-13 20:15:29 +00001131 if (exact)
1132 {
1133 /* Area ID + Range Network. */
1134 if (v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE != *length)
1135 return NULL;
1136
1137 /* Set OID offset for Area ID. */
1138 offset = name + v->namelen;
1139
1140 /* Lookup area first. */
1141 oid2in_addr (offset, IN_ADDR_SIZE, area_id);
1142
paul68980082003-03-25 05:07:42 +00001143 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +00001144 if (! area)
1145 return NULL;
1146
1147 offset += IN_ADDR_SIZE;
1148
1149 /* Lookup area range. */
1150 oid2in_addr (offset, IN_ADDR_SIZE, range_net);
1151 p.prefix = *range_net;
1152
1153 return ospf_area_range_lookup (area, &p);
1154 }
1155 else
1156 {
1157 /* Set OID offset for Area ID. */
1158 offset = name + v->namelen;
1159 offsetlen = *length - v->namelen;
1160
1161 len = offsetlen;
1162 if (len > IN_ADDR_SIZE)
1163 len = IN_ADDR_SIZE;
1164
1165 oid2in_addr (offset, len, area_id);
1166
1167 /* First we search area. */
1168 if (len == IN_ADDR_SIZE)
paul68980082003-03-25 05:07:42 +00001169 area = ospf_area_lookup_by_area_id (ospf,*area_id);
paul718e3742002-12-13 20:15:29 +00001170 else
paul68980082003-03-25 05:07:42 +00001171 area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +00001172
1173 if (area == NULL)
1174 return NULL;
1175
1176 do
1177 {
1178 offset += IN_ADDR_SIZE;
1179 offsetlen -= IN_ADDR_SIZE;
1180 len = offsetlen;
1181
1182 if (len < 0)
1183 len = 0;
1184 if (len > IN_ADDR_SIZE)
1185 len = IN_ADDR_SIZE;
1186
1187 oid2in_addr (offset, len, range_net);
1188
1189 range = ospf_area_range_lookup_next (area, range_net,
1190 len == 0 ? 1 : 0);
1191
1192 if (range)
1193 {
1194 /* Fill in length. */
1195 *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
1196
1197 /* Fill in value. */
1198 offset = name + v->namelen;
1199 oid_copy_addr (offset, area_id, IN_ADDR_SIZE);
1200 offset += IN_ADDR_SIZE;
1201 oid_copy_addr (offset, range_net, IN_ADDR_SIZE);
1202
1203 return range;
1204 }
1205 }
paul68980082003-03-25 05:07:42 +00001206 while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL);
paul718e3742002-12-13 20:15:29 +00001207 }
1208 return NULL;
1209}
1210
1211static u_char *
1212ospfAreaRangeEntry (struct variable *v, oid *name, size_t *length, int exact,
1213 size_t *var_len, WriteMethod **write_method)
1214{
1215 struct ospf_area_range *range;
1216 struct in_addr area_id;
1217 struct in_addr range_net;
1218 struct in_addr mask;
paul020709f2003-04-04 02:44:16 +00001219 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001220
1221 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001222 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001223 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001224 return NULL;
1225
1226 memset (&area_id, 0, IN_ADDR_SIZE);
1227 memset (&range_net, 0, IN_ADDR_SIZE);
1228
1229 range = ospfAreaRangeLookup (v, name, length, &area_id, &range_net, exact);
1230 if (! range)
1231 return NULL;
1232
1233 /* Convert prefixlen to network mask format. */
1234 masklen2ip (range->subst_masklen, &mask);
1235
1236 /* Return the current value of the variable */
1237 switch (v->magic)
1238 {
1239 case OSPFAREARANGEAREAID: /* 1 */
1240 return SNMP_IPADDRESS (area_id);
1241 break;
1242 case OSPFAREARANGENET: /* 2 */
1243 return SNMP_IPADDRESS (range_net);
1244 break;
1245 case OSPFAREARANGEMASK: /* 3 */
1246 return SNMP_IPADDRESS (mask);
1247 break;
1248 case OSPFAREARANGESTATUS: /* 4 */
1249 return SNMP_INTEGER (SNMP_VALID);
1250 break;
1251 case OSPFAREARANGEEFFECT: /* 5 */
1252#define OSPF_advertiseMatching 1
1253#define OSPF_doNotAdvertiseMatching 2
1254 return SNMP_INTEGER (OSPF_advertiseMatching);
1255 break;
1256 default:
1257 return NULL;
1258 break;
1259 }
1260 return NULL;
1261}
1262
1263struct ospf_nbr_nbma *
1264ospfHostLookup (struct variable *v, oid *name, size_t *length,
1265 struct in_addr *addr, int exact)
1266{
1267 int len;
1268 struct ospf_nbr_nbma *nbr_nbma;
paul020709f2003-04-04 02:44:16 +00001269 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001270
paul020709f2003-04-04 02:44:16 +00001271 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001272 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001273 return NULL;
1274
1275 if (exact)
1276 {
1277 /* INDEX { ospfHostIpAddress, ospfHostTOS } */
1278 if (*length != v->namelen + IN_ADDR_SIZE + 1)
1279 return NULL;
1280
1281 /* Check ospfHostTOS. */
1282 if (name[*length - 1] != 0)
1283 return NULL;
1284
1285 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, addr);
1286
paul68980082003-03-25 05:07:42 +00001287 nbr_nbma = ospf_nbr_nbma_lookup (ospf, *addr);
paul718e3742002-12-13 20:15:29 +00001288
1289 return nbr_nbma;
1290 }
1291 else
1292 {
1293 len = *length - v->namelen;
1294 if (len > 4)
1295 len = 4;
1296
1297 oid2in_addr (name + v->namelen, len, addr);
1298
paul68980082003-03-25 05:07:42 +00001299 nbr_nbma = ospf_nbr_nbma_lookup_next (ospf, addr, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +00001300
1301 if (nbr_nbma == NULL)
1302 return NULL;
1303
1304 oid_copy_addr (name + v->namelen, addr, IN_ADDR_SIZE);
1305
1306 /* Set TOS 0. */
1307 name[v->namelen + IN_ADDR_SIZE] = 0;
1308
1309 *length = v->namelen + IN_ADDR_SIZE + 1;
1310
1311 return nbr_nbma;
1312 }
1313 return NULL;
1314}
1315
1316static u_char *
1317ospfHostEntry (struct variable *v, oid *name, size_t *length, int exact,
1318 size_t *var_len, WriteMethod **write_method)
1319{
1320 struct ospf_nbr_nbma *nbr_nbma;
1321 struct ospf_interface *oi;
1322 struct in_addr addr;
paul020709f2003-04-04 02:44:16 +00001323 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001324
1325 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001326 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001327 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001328 return NULL;
1329
1330 memset (&addr, 0, sizeof (struct in_addr));
1331
1332 nbr_nbma = ospfHostLookup (v, name, length, &addr, exact);
1333 if (nbr_nbma == NULL)
1334 return NULL;
1335
1336 oi = nbr_nbma->oi;
1337
1338 /* Return the current value of the variable */
1339 switch (v->magic)
1340 {
1341 case OSPFHOSTIPADDRESS: /* 1 */
1342 return SNMP_IPADDRESS (nbr_nbma->addr);
1343 break;
1344 case OSPFHOSTTOS: /* 2 */
1345 return SNMP_INTEGER (0);
1346 break;
1347 case OSPFHOSTMETRIC: /* 3 */
1348 if (oi)
1349 return SNMP_INTEGER (oi->output_cost);
1350 else
1351 return SNMP_INTEGER (1);
1352 break;
1353 case OSPFHOSTSTATUS: /* 4 */
1354 return SNMP_INTEGER (SNMP_VALID);
1355 break;
1356 case OSPFHOSTAREAID: /* 5 */
1357 if (oi && oi->area)
1358 return SNMP_IPADDRESS (oi->area->area_id);
1359 else
1360 return SNMP_IPADDRESS (ospf_empty_addr);
1361 break;
1362 default:
1363 return NULL;
1364 break;
1365 }
1366 return NULL;
1367}
1368
1369struct list *ospf_snmp_iflist;
1370
1371struct ospf_snmp_if
1372{
1373 struct in_addr addr;
1374 unsigned int ifindex;
1375 struct interface *ifp;
1376};
1377
1378struct ospf_snmp_if *
1379ospf_snmp_if_new ()
1380{
1381 struct ospf_snmp_if *osif;
1382
1383 osif = XMALLOC (0, sizeof (struct ospf_snmp_if));
1384 memset (osif, 0, sizeof (struct ospf_snmp_if));
1385 return osif;
1386}
1387
1388void
1389ospf_snmp_if_free (struct ospf_snmp_if *osif)
1390{
1391 XFREE (0, osif);
1392}
1393
1394void
1395ospf_snmp_if_delete (struct interface *ifp)
1396{
paul1eb8ef22005-04-07 07:30:20 +00001397 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001398 struct ospf_snmp_if *osif;
1399
paul1eb8ef22005-04-07 07:30:20 +00001400 for (ALL_LIST_ELEMENTS (ospf_snmp_iflist, node, nnode, osif))
paul718e3742002-12-13 20:15:29 +00001401 {
1402 if (osif->ifp == ifp)
1403 {
paul1eb8ef22005-04-07 07:30:20 +00001404 list_delete_node (ospf_snmp_iflist, node);
paul718e3742002-12-13 20:15:29 +00001405 ospf_snmp_if_free (osif);
1406 return;
1407 }
1408 }
1409}
1410
1411void
1412ospf_snmp_if_update (struct interface *ifp)
1413{
paul1eb8ef22005-04-07 07:30:20 +00001414 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001415 struct listnode *pn;
1416 struct connected *ifc;
1417 struct prefix *p;
1418 struct ospf_snmp_if *osif;
1419 struct in_addr *addr;
1420 unsigned int ifindex;
1421
1422 ospf_snmp_if_delete (ifp);
1423
1424 p = NULL;
1425 addr = NULL;
1426 ifindex = 0;
1427
1428 /* Lookup first IPv4 address entry. */
paul1eb8ef22005-04-07 07:30:20 +00001429 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
paul718e3742002-12-13 20:15:29 +00001430 {
hasso3fb9cd62004-10-19 19:44:43 +00001431 if (CONNECTED_POINTOPOINT_HOST(ifc))
paul718e3742002-12-13 20:15:29 +00001432 p = ifc->destination;
1433 else
1434 p = ifc->address;
1435
1436 if (p->family == AF_INET)
1437 {
1438 addr = &p->u.prefix4;
1439 break;
1440 }
1441 }
1442 if (! addr)
1443 ifindex = ifp->ifindex;
1444
1445 /* Add interface to the list. */
1446 pn = NULL;
paul1eb8ef22005-04-07 07:30:20 +00001447 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif))
paul718e3742002-12-13 20:15:29 +00001448 {
1449 if (addr)
1450 {
1451 if (ntohl (osif->addr.s_addr) > ntohl (addr->s_addr))
1452 break;
1453 }
1454 else
1455 {
1456 /* Unnumbered interface. */
1457 if (osif->addr.s_addr != 0 || osif->ifindex > ifindex)
1458 break;
1459 }
paul1eb8ef22005-04-07 07:30:20 +00001460 pn = node;
paul718e3742002-12-13 20:15:29 +00001461 }
1462
1463 osif = ospf_snmp_if_new ();
1464 if (addr)
1465 osif->addr = *addr;
1466 else
1467 osif->ifindex = ifindex;
1468 osif->ifp = ifp;
1469
1470 listnode_add_after (ospf_snmp_iflist, pn, osif);
1471}
1472
1473struct interface *
1474ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex)
1475{
paul1eb8ef22005-04-07 07:30:20 +00001476 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001477 struct ospf_snmp_if *osif;
1478
paul1eb8ef22005-04-07 07:30:20 +00001479 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif))
paul718e3742002-12-13 20:15:29 +00001480 {
1481 if (ifaddr->s_addr)
1482 {
1483 if (IPV4_ADDR_SAME (&osif->addr, ifaddr))
1484 return osif->ifp;
1485 }
1486 else
1487 {
1488 if (osif->ifindex == *ifindex)
1489 return osif->ifp;
1490 }
1491 }
1492 return NULL;
1493}
1494
1495struct interface *
1496ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex,
1497 int ifaddr_next, int ifindex_next)
1498{
1499 struct ospf_snmp_if *osif;
1500 struct listnode *nn;
1501
1502 if (ifaddr_next)
1503 {
1504 nn = listhead (ospf_snmp_iflist);
1505 if (nn)
1506 {
paul1eb8ef22005-04-07 07:30:20 +00001507 osif = listgetdata (nn);
paul718e3742002-12-13 20:15:29 +00001508 *ifaddr = osif->addr;
1509 *ifindex = osif->ifindex;
1510 return osif->ifp;
1511 }
1512 return NULL;
1513 }
1514
paul1eb8ef22005-04-07 07:30:20 +00001515 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, nn, osif))
paul718e3742002-12-13 20:15:29 +00001516 {
1517 if (ifaddr->s_addr)
1518 {
1519 if (ntohl (osif->addr.s_addr) > ntohl (ifaddr->s_addr))
1520 {
1521 *ifaddr = osif->addr;
1522 *ifindex = osif->ifindex;
1523 return osif->ifp;
1524 }
1525 }
1526 else
1527 {
1528 if (osif->ifindex > *ifindex || osif->addr.s_addr)
1529 {
1530 *ifaddr = osif->addr;
1531 *ifindex = osif->ifindex;
1532 return osif->ifp;
1533 }
1534 }
1535 }
1536 return NULL;
1537}
1538
1539int
1540ospf_snmp_iftype (struct interface *ifp)
1541{
1542#define ospf_snmp_iftype_broadcast 1
1543#define ospf_snmp_iftype_nbma 2
1544#define ospf_snmp_iftype_pointToPoint 3
1545#define ospf_snmp_iftype_pointToMultipoint 5
1546 if (if_is_broadcast (ifp))
1547 return ospf_snmp_iftype_broadcast;
1548 if (if_is_pointopoint (ifp))
1549 return ospf_snmp_iftype_pointToPoint;
1550 return ospf_snmp_iftype_broadcast;
1551}
1552
1553struct interface *
1554ospfIfLookup (struct variable *v, oid *name, size_t *length,
1555 struct in_addr *ifaddr, unsigned int *ifindex, int exact)
1556{
paul6c835672004-10-11 11:00:30 +00001557 unsigned int len;
paul718e3742002-12-13 20:15:29 +00001558 int ifaddr_next = 0;
1559 int ifindex_next = 0;
1560 struct interface *ifp;
1561 oid *offset;
1562
1563 if (exact)
1564 {
1565 if (*length != v->namelen + IN_ADDR_SIZE + 1)
1566 return NULL;
1567
1568 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr);
1569 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1570
1571 return ospf_snmp_if_lookup (ifaddr, ifindex);
1572 }
1573 else
1574 {
1575 len = *length - v->namelen;
1576 if (len >= IN_ADDR_SIZE)
1577 len = IN_ADDR_SIZE;
1578 if (len <= 0)
1579 ifaddr_next = 1;
1580
1581 oid2in_addr (name + v->namelen, len, ifaddr);
1582
1583 len = *length - v->namelen - IN_ADDR_SIZE;
1584 if (len >= 1)
1585 len = 1;
1586 else
1587 ifindex_next = 1;
1588
1589 if (len == 1)
1590 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1591
1592 ifp = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next,
1593 ifindex_next);
1594 if (ifp)
1595 {
1596 *length = v->namelen + IN_ADDR_SIZE + 1;
1597 offset = name + v->namelen;
1598 oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE);
1599 offset += IN_ADDR_SIZE;
1600 *offset = *ifindex;
1601 return ifp;
1602 }
1603 }
1604 return NULL;
1605}
1606
1607static u_char *
1608ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact,
1609 size_t *var_len, WriteMethod **write_method)
1610{
1611 struct interface *ifp;
1612 unsigned int ifindex;
1613 struct in_addr ifaddr;
1614 struct ospf_interface *oi;
paul020709f2003-04-04 02:44:16 +00001615 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001616
1617 ifindex = 0;
1618 memset (&ifaddr, 0, sizeof (struct in_addr));
1619
1620 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001621 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001622 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001623 return NULL;
1624
1625 ifp = ospfIfLookup (v, name, length, &ifaddr, &ifindex, exact);
1626 if (ifp == NULL)
1627 return NULL;
1628
paul68980082003-03-25 05:07:42 +00001629 oi = ospf_if_lookup_by_local_addr (ospf, ifp, ifaddr);
paul718e3742002-12-13 20:15:29 +00001630 if (oi == NULL)
1631 return NULL;
1632
1633 /* Return the current value of the variable */
1634 switch (v->magic)
1635 {
1636 case OSPFIFIPADDRESS: /* 1 */
1637 return SNMP_IPADDRESS (ifaddr);
1638 break;
1639 case OSPFADDRESSLESSIF: /* 2 */
1640 return SNMP_INTEGER (ifindex);
1641 break;
1642 case OSPFIFAREAID: /* 3 */
1643 if (oi->area)
1644 return SNMP_IPADDRESS (oi->area->area_id);
1645 else
1646 return SNMP_IPADDRESS (ospf_empty_addr);
1647 break;
1648 case OSPFIFTYPE: /* 4 */
1649 return SNMP_INTEGER (ospf_snmp_iftype (ifp));
1650 break;
1651 case OSPFIFADMINSTAT: /* 5 */
1652 if (oi)
1653 return SNMP_INTEGER (OSPF_STATUS_ENABLED);
1654 else
1655 return SNMP_INTEGER (OSPF_STATUS_DISABLED);
1656 break;
1657 case OSPFIFRTRPRIORITY: /* 6 */
1658 return SNMP_INTEGER (PRIORITY (oi));
1659 break;
1660 case OSPFIFTRANSITDELAY: /* 7 */
1661 return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
1662 break;
1663 case OSPFIFRETRANSINTERVAL: /* 8 */
1664 return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
1665 break;
1666 case OSPFIFHELLOINTERVAL: /* 9 */
1667 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
1668 break;
1669 case OSPFIFRTRDEADINTERVAL: /* 10 */
1670 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
1671 break;
1672 case OSPFIFPOLLINTERVAL: /* 11 */
1673 return SNMP_INTEGER (OSPF_POLL_INTERVAL_DEFAULT);
1674 break;
1675 case OSPFIFSTATE: /* 12 */
1676 return SNMP_INTEGER (oi->state);
1677 break;
1678 case OSPFIFDESIGNATEDROUTER: /* 13 */
1679 return SNMP_IPADDRESS (DR (oi));
1680 break;
1681 case OSPFIFBACKUPDESIGNATEDROUTER: /* 14 */
1682 return SNMP_IPADDRESS (BDR (oi));
1683 break;
1684 case OSPFIFEVENTS: /* 15 */
1685 return SNMP_INTEGER (oi->state_change);
1686 break;
1687 case OSPFIFAUTHKEY: /* 16 */
1688 *var_len = 0;
1689 return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
1690 break;
1691 case OSPFIFSTATUS: /* 17 */
1692 return SNMP_INTEGER (SNMP_VALID);
1693 break;
1694 case OSPFIFMULTICASTFORWARDING: /* 18 */
1695#define ospf_snmp_multiforward_blocked 1
1696#define ospf_snmp_multiforward_multicast 2
1697#define ospf_snmp_multiforward_unicast 3
1698 return SNMP_INTEGER (ospf_snmp_multiforward_blocked);
1699 break;
1700 case OSPFIFDEMAND: /* 19 */
1701 return SNMP_INTEGER (SNMP_FALSE);
1702 break;
1703 case OSPFIFAUTHTYPE: /* 20 */
1704 if (oi->area)
1705 return SNMP_INTEGER (oi->area->auth_type);
1706 else
1707 return SNMP_INTEGER (0);
1708 break;
1709 default:
1710 return NULL;
1711 break;
1712 }
1713 return NULL;
1714}
1715
1716#define OSPF_SNMP_METRIC_VALUE 1
1717
1718struct interface *
1719ospfIfMetricLookup (struct variable *v, oid *name, size_t *length,
1720 struct in_addr *ifaddr, unsigned int *ifindex, int exact)
1721{
paul6c835672004-10-11 11:00:30 +00001722 unsigned int len;
paul718e3742002-12-13 20:15:29 +00001723 int ifaddr_next = 0;
1724 int ifindex_next = 0;
1725 struct interface *ifp;
1726 oid *offset;
1727 int metric;
1728
1729 if (exact)
1730 {
1731 if (*length != v->namelen + IN_ADDR_SIZE + 1 + 1)
1732 return NULL;
1733
1734 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr);
1735 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1736 metric = name[v->namelen + IN_ADDR_SIZE + 1];
1737
1738 if (metric != OSPF_SNMP_METRIC_VALUE)
1739 return NULL;
1740
1741 return ospf_snmp_if_lookup (ifaddr, ifindex);
1742 }
1743 else
1744 {
1745 len = *length - v->namelen;
1746 if (len >= IN_ADDR_SIZE)
1747 len = IN_ADDR_SIZE;
1748 else
1749 ifaddr_next = 1;
1750
1751 oid2in_addr (name + v->namelen, len, ifaddr);
1752
1753 len = *length - v->namelen - IN_ADDR_SIZE;
1754 if (len >= 1)
1755 len = 1;
1756 else
1757 ifindex_next = 1;
1758
1759 if (len == 1)
1760 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1761
1762 ifp = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next,
1763 ifindex_next);
1764 if (ifp)
1765 {
1766 *length = v->namelen + IN_ADDR_SIZE + 1 + 1;
1767 offset = name + v->namelen;
1768 oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE);
1769 offset += IN_ADDR_SIZE;
1770 *offset = *ifindex;
1771 offset++;
1772 *offset = OSPF_SNMP_METRIC_VALUE;
1773 return ifp;
1774 }
1775 }
1776 return NULL;
1777}
1778
1779static u_char *
1780ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact,
1781 size_t *var_len, WriteMethod **write_method)
1782{
1783 /* Currently we support metric 1 only. */
1784 struct interface *ifp;
1785 unsigned int ifindex;
1786 struct in_addr ifaddr;
1787 struct ospf_interface *oi;
paul020709f2003-04-04 02:44:16 +00001788 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001789
1790 ifindex = 0;
1791 memset (&ifaddr, 0, sizeof (struct in_addr));
1792
1793 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001794 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001795 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001796 return NULL;
1797
1798 ifp = ospfIfMetricLookup (v, name, length, &ifaddr, &ifindex, exact);
1799 if (ifp == NULL)
1800 return NULL;
1801
paul68980082003-03-25 05:07:42 +00001802 oi = ospf_if_lookup_by_local_addr (ospf, ifp, ifaddr);
paul718e3742002-12-13 20:15:29 +00001803 if (oi == NULL)
1804 return NULL;
1805
1806 /* Return the current value of the variable */
1807 switch (v->magic)
1808 {
1809 case OSPFIFMETRICIPADDRESS:
1810 return SNMP_IPADDRESS (ifaddr);
1811 break;
1812 case OSPFIFMETRICADDRESSLESSIF:
1813 return SNMP_INTEGER (ifindex);
1814 break;
1815 case OSPFIFMETRICTOS:
1816 return SNMP_INTEGER (0);
1817 break;
1818 case OSPFIFMETRICVALUE:
1819 return SNMP_INTEGER (OSPF_SNMP_METRIC_VALUE);
1820 break;
1821 case OSPFIFMETRICSTATUS:
1822 return SNMP_INTEGER (1);
1823 break;
1824 default:
1825 return NULL;
1826 break;
1827 }
1828 return NULL;
1829}
1830
1831struct route_table *ospf_snmp_vl_table;
1832
1833void
1834ospf_snmp_vl_add (struct ospf_vl_data *vl_data)
1835{
1836 struct prefix_ls lp;
1837 struct route_node *rn;
1838
1839 memset (&lp, 0, sizeof (struct prefix_ls));
1840 lp.family = 0;
1841 lp.prefixlen = 64;
1842 lp.id = vl_data->vl_area_id;
1843 lp.adv_router = vl_data->vl_peer;
1844
1845 rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp);
1846 rn->info = vl_data;
1847}
1848
1849void
1850ospf_snmp_vl_delete (struct ospf_vl_data *vl_data)
1851{
1852 struct prefix_ls lp;
1853 struct route_node *rn;
1854
1855 memset (&lp, 0, sizeof (struct prefix_ls));
1856 lp.family = 0;
1857 lp.prefixlen = 64;
1858 lp.id = vl_data->vl_area_id;
1859 lp.adv_router = vl_data->vl_peer;
1860
1861 rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
1862 if (! rn)
1863 return;
1864 rn->info = NULL;
1865 route_unlock_node (rn);
1866 route_unlock_node (rn);
1867}
1868
1869struct ospf_vl_data *
1870ospf_snmp_vl_lookup (struct in_addr *area_id, struct in_addr *neighbor)
1871{
1872 struct prefix_ls lp;
1873 struct route_node *rn;
1874 struct ospf_vl_data *vl_data;
1875
1876 memset (&lp, 0, sizeof (struct prefix_ls));
1877 lp.family = 0;
1878 lp.prefixlen = 64;
1879 lp.id = *area_id;
1880 lp.adv_router = *neighbor;
1881
1882 rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
1883 if (rn)
1884 {
1885 vl_data = rn->info;
1886 route_unlock_node (rn);
1887 return vl_data;
1888 }
1889 return NULL;
1890}
1891
1892struct ospf_vl_data *
1893ospf_snmp_vl_lookup_next (struct in_addr *area_id, struct in_addr *neighbor,
1894 int first)
1895{
1896 struct prefix_ls lp;
1897 struct route_node *rn;
1898 struct ospf_vl_data *vl_data;
1899
1900 memset (&lp, 0, sizeof (struct prefix_ls));
1901 lp.family = 0;
1902 lp.prefixlen = 64;
1903 lp.id = *area_id;
1904 lp.adv_router = *neighbor;
1905
1906 if (first)
1907 rn = route_top (ospf_snmp_vl_table);
1908 else
1909 {
1910 rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp);
1911 rn = route_next (rn);
1912 }
1913
1914 for (; rn; rn = route_next (rn))
1915 if (rn->info)
1916 break;
1917
1918 if (rn && rn->info)
1919 {
1920 vl_data = rn->info;
1921 *area_id = vl_data->vl_area_id;
1922 *neighbor = vl_data->vl_peer;
1923 route_unlock_node (rn);
1924 return vl_data;
1925 }
1926 return NULL;
1927}
1928
1929struct ospf_vl_data *
1930ospfVirtIfLookup (struct variable *v, oid *name, size_t *length,
1931 struct in_addr *area_id, struct in_addr *neighbor, int exact)
1932{
1933 int first;
paul6c835672004-10-11 11:00:30 +00001934 unsigned int len;
paul718e3742002-12-13 20:15:29 +00001935 struct ospf_vl_data *vl_data;
1936
1937 if (exact)
1938 {
1939 if (*length != v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE)
1940 return NULL;
1941
1942 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, area_id);
1943 oid2in_addr (name + v->namelen + IN_ADDR_SIZE, IN_ADDR_SIZE, neighbor);
1944
1945 return ospf_snmp_vl_lookup (area_id, neighbor);
1946 }
1947 else
1948 {
1949 first = 0;
1950
1951 len = *length - v->namelen;
1952 if (len <= 0)
1953 first = 1;
1954 if (len > IN_ADDR_SIZE)
1955 len = IN_ADDR_SIZE;
1956 oid2in_addr (name + v->namelen, len, area_id);
1957
1958 len = *length - v->namelen - IN_ADDR_SIZE;
1959 if (len > IN_ADDR_SIZE)
1960 len = IN_ADDR_SIZE;
1961 oid2in_addr (name + v->namelen + IN_ADDR_SIZE, len, neighbor);
1962
1963 vl_data = ospf_snmp_vl_lookup_next (area_id, neighbor, first);
1964
1965 if (vl_data)
1966 {
1967 *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
1968 oid_copy_addr (name + v->namelen, area_id, IN_ADDR_SIZE);
1969 oid_copy_addr (name + v->namelen + IN_ADDR_SIZE, neighbor,
1970 IN_ADDR_SIZE);
1971 return vl_data;
1972 }
1973 }
1974 return NULL;
1975}
1976
1977static u_char *
1978ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact,
1979 size_t *var_len, WriteMethod **write_method)
1980{
1981 struct ospf_vl_data *vl_data;
1982 struct ospf_interface *oi;
1983 struct in_addr area_id;
1984 struct in_addr neighbor;
1985
1986 memset (&area_id, 0, sizeof (struct in_addr));
1987 memset (&neighbor, 0, sizeof (struct in_addr));
1988
1989 vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
1990 if (! vl_data)
1991 return NULL;
1992 oi = vl_data->vl_oi;
1993 if (! oi)
1994 return NULL;
1995
1996 /* Return the current value of the variable */
1997 switch (v->magic)
1998 {
1999 case OSPFVIRTIFAREAID:
2000 return SNMP_IPADDRESS (area_id);
2001 break;
2002 case OSPFVIRTIFNEIGHBOR:
2003 return SNMP_IPADDRESS (neighbor);
2004 break;
2005 case OSPFVIRTIFTRANSITDELAY:
2006 return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
2007 break;
2008 case OSPFVIRTIFRETRANSINTERVAL:
2009 return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
2010 break;
2011 case OSPFVIRTIFHELLOINTERVAL:
2012 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
2013 break;
2014 case OSPFVIRTIFRTRDEADINTERVAL:
2015 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
2016 break;
2017 case OSPFVIRTIFSTATE:
2018 return SNMP_INTEGER (oi->state);
2019 break;
2020 case OSPFVIRTIFEVENTS:
2021 return SNMP_INTEGER (oi->state_change);
2022 break;
2023 case OSPFVIRTIFAUTHKEY:
2024 *var_len = 0;
2025 return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
2026 break;
2027 case OSPFVIRTIFSTATUS:
2028 return SNMP_INTEGER (SNMP_VALID);
2029 break;
2030 case OSPFVIRTIFAUTHTYPE:
2031 if (oi->area)
2032 return SNMP_INTEGER (oi->area->auth_type);
2033 else
2034 return SNMP_INTEGER (0);
2035 break;
2036 default:
2037 return NULL;
2038 break;
2039 }
2040 return NULL;
2041}
2042
2043struct ospf_neighbor *
paul68980082003-03-25 05:07:42 +00002044ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr,
2045 unsigned int *ifindex)
paul718e3742002-12-13 20:15:29 +00002046{
paul1eb8ef22005-04-07 07:30:20 +00002047 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002048 struct ospf_interface *oi;
2049 struct ospf_neighbor *nbr;
2050 struct route_node *rn;
2051
paul1eb8ef22005-04-07 07:30:20 +00002052 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
paul718e3742002-12-13 20:15:29 +00002053 {
2054 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
2055 if ((nbr = rn->info) != NULL
2056 && nbr != oi->nbr_self
2057 && nbr->state != NSM_Down
2058 && nbr->src.s_addr != 0)
2059 {
2060 if (IPV4_ADDR_SAME (&nbr->src, nbr_addr))
2061 {
2062 route_unlock_node (rn);
2063 return nbr;
2064 }
2065 }
2066 }
2067 return NULL;
2068}
2069
2070struct ospf_neighbor *
2071ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex,
2072 int first)
2073{
2074 struct listnode *nn;
2075 struct ospf_interface *oi;
2076 struct ospf_neighbor *nbr;
2077 struct route_node *rn;
2078 struct ospf_neighbor *min = NULL;
paul020709f2003-04-04 02:44:16 +00002079 struct ospf *ospf = ospf;
paul718e3742002-12-13 20:15:29 +00002080
paul020709f2003-04-04 02:44:16 +00002081 ospf = ospf_lookup ();
paul1eb8ef22005-04-07 07:30:20 +00002082
2083 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, nn, oi))
paul718e3742002-12-13 20:15:29 +00002084 {
2085 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
2086 if ((nbr = rn->info) != NULL
2087 && nbr != oi->nbr_self
2088 && nbr->state != NSM_Down
2089 && nbr->src.s_addr != 0)
2090 {
2091 if (first)
2092 {
2093 if (! min)
2094 min = nbr;
2095 else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
2096 min = nbr;
2097 }
2098 else if (ntohl (nbr->src.s_addr) > ntohl (nbr_addr->s_addr))
2099 {
2100 if (! min)
2101 min = nbr;
2102 else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
2103 min = nbr;
2104 }
2105 }
2106 }
2107 if (min)
2108 {
2109 *nbr_addr = min->src;
2110 *ifindex = 0;
2111 return min;
2112 }
2113 return NULL;
2114}
2115
2116struct ospf_neighbor *
2117ospfNbrLookup (struct variable *v, oid *name, size_t *length,
2118 struct in_addr *nbr_addr, unsigned int *ifindex, int exact)
2119{
paul6c835672004-10-11 11:00:30 +00002120 unsigned int len;
paul718e3742002-12-13 20:15:29 +00002121 int first;
2122 struct ospf_neighbor *nbr;
paul020709f2003-04-04 02:44:16 +00002123 struct ospf *ospf;
2124
2125 ospf = ospf_lookup ();
paul718e3742002-12-13 20:15:29 +00002126
hasso1b639042005-03-27 13:32:25 +00002127 if (! ospf)
2128 return NULL;
2129
paul718e3742002-12-13 20:15:29 +00002130 if (exact)
2131 {
2132 if (*length != v->namelen + IN_ADDR_SIZE + 1)
2133 return NULL;
2134
2135 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, nbr_addr);
2136 *ifindex = name[v->namelen + IN_ADDR_SIZE];
2137
paul68980082003-03-25 05:07:42 +00002138 return ospf_snmp_nbr_lookup (ospf, nbr_addr, ifindex);
paul718e3742002-12-13 20:15:29 +00002139 }
2140 else
2141 {
2142 first = 0;
2143 len = *length - v->namelen;
2144
2145 if (len <= 0)
2146 first = 1;
2147
2148 if (len > IN_ADDR_SIZE)
2149 len = IN_ADDR_SIZE;
2150
2151 oid2in_addr (name + v->namelen, len, nbr_addr);
2152
2153 len = *length - v->namelen - IN_ADDR_SIZE;
2154 if (len >= 1)
2155 *ifindex = name[v->namelen + IN_ADDR_SIZE];
2156
2157 nbr = ospf_snmp_nbr_lookup_next (nbr_addr, ifindex, first);
2158
2159 if (nbr)
2160 {
2161 *length = v->namelen + IN_ADDR_SIZE + 1;
2162 oid_copy_addr (name + v->namelen, nbr_addr, IN_ADDR_SIZE);
2163 name[v->namelen + IN_ADDR_SIZE] = *ifindex;
2164 return nbr;
2165 }
2166 }
2167 return NULL;
2168}
2169
2170static u_char *
2171ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
2172 size_t *var_len, WriteMethod **write_method)
2173{
2174 struct in_addr nbr_addr;
2175 unsigned int ifindex;
2176 struct ospf_neighbor *nbr;
2177 struct ospf_interface *oi;
2178
2179 memset (&nbr_addr, 0, sizeof (struct in_addr));
2180 ifindex = 0;
2181
2182 nbr = ospfNbrLookup (v, name, length, &nbr_addr, &ifindex, exact);
2183 if (! nbr)
2184 return NULL;
2185 oi = nbr->oi;
2186 if (! oi)
2187 return NULL;
2188
2189 /* Return the current value of the variable */
2190 switch (v->magic)
2191 {
2192 case OSPFNBRIPADDR:
2193 return SNMP_IPADDRESS (nbr_addr);
2194 break;
2195 case OSPFNBRADDRESSLESSINDEX:
2196 return SNMP_INTEGER (ifindex);
2197 break;
2198 case OSPFNBRRTRID:
2199 return SNMP_IPADDRESS (nbr->router_id);
2200 break;
2201 case OSPFNBROPTIONS:
2202 return SNMP_INTEGER (oi->nbr_self->options);
2203 break;
2204 case OSPFNBRPRIORITY:
2205 return SNMP_INTEGER (nbr->priority);
2206 break;
2207 case OSPFNBRSTATE:
2208 return SNMP_INTEGER (nbr->state);
2209 break;
2210 case OSPFNBREVENTS:
2211 return SNMP_INTEGER (nbr->state_change);
2212 break;
2213 case OSPFNBRLSRETRANSQLEN:
2214 return SNMP_INTEGER (ospf_ls_retransmit_count (nbr));
2215 break;
2216 case OSPFNBMANBRSTATUS:
2217 return SNMP_INTEGER (SNMP_VALID);
2218 break;
2219 case OSPFNBMANBRPERMANENCE:
2220 return SNMP_INTEGER (2);
2221 break;
2222 case OSPFNBRHELLOSUPPRESSED:
2223 return SNMP_INTEGER (SNMP_FALSE);
2224 break;
2225 default:
2226 return NULL;
2227 break;
2228 }
2229 return NULL;
2230}
2231
2232static u_char *
2233ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
2234 size_t *var_len, WriteMethod **write_method)
2235{
2236 struct ospf_vl_data *vl_data;
2237 struct in_addr area_id;
2238 struct in_addr neighbor;
paul020709f2003-04-04 02:44:16 +00002239 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002240
2241 memset (&area_id, 0, sizeof (struct in_addr));
2242 memset (&neighbor, 0, sizeof (struct in_addr));
2243
2244 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00002245 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00002246 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00002247 return NULL;
2248
2249 vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
2250 if (! vl_data)
2251 return NULL;
2252
2253 /* Return the current value of the variable */
2254 switch (v->magic)
2255 {
2256 case OSPFVIRTNBRAREA:
2257 return (u_char *) NULL;
2258 break;
2259 case OSPFVIRTNBRRTRID:
2260 return (u_char *) NULL;
2261 break;
2262 case OSPFVIRTNBRIPADDR:
2263 return (u_char *) NULL;
2264 break;
2265 case OSPFVIRTNBROPTIONS:
2266 return (u_char *) NULL;
2267 break;
2268 case OSPFVIRTNBRSTATE:
2269 return (u_char *) NULL;
2270 break;
2271 case OSPFVIRTNBREVENTS:
2272 return (u_char *) NULL;
2273 break;
2274 case OSPFVIRTNBRLSRETRANSQLEN:
2275 return (u_char *) NULL;
2276 break;
2277 case OSPFVIRTNBRHELLOSUPPRESSED:
2278 return (u_char *) NULL;
2279 break;
2280 default:
2281 return NULL;
2282 break;
2283 }
2284 return NULL;
2285}
2286
2287struct ospf_lsa *
2288ospfExtLsdbLookup (struct variable *v, oid *name, size_t *length, u_char *type,
2289 struct in_addr *ls_id, struct in_addr *router_id, int exact)
2290{
2291 int first;
2292 oid *offset;
2293 int offsetlen;
2294 u_char lsa_type;
paul6c835672004-10-11 11:00:30 +00002295 unsigned int len;
paul718e3742002-12-13 20:15:29 +00002296 struct ospf_lsa *lsa;
paul020709f2003-04-04 02:44:16 +00002297 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002298
paul020709f2003-04-04 02:44:16 +00002299 ospf = ospf_lookup ();
paul718e3742002-12-13 20:15:29 +00002300 if (exact)
2301 {
2302 if (*length != v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
2303 return NULL;
2304
2305 offset = name + v->namelen;
2306
2307 /* Make it sure given value match to type. */
2308 lsa_type = *offset;
2309 offset++;
2310
2311 if (lsa_type != *type)
2312 return NULL;
2313
2314 /* LS ID. */
2315 oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
2316 offset += IN_ADDR_SIZE;
2317
2318 /* Router ID. */
2319 oid2in_addr (offset, IN_ADDR_SIZE, router_id);
2320
paul68980082003-03-25 05:07:42 +00002321 return ospf_lsdb_lookup_by_id (ospf->lsdb, *type, *ls_id, *router_id);
paul718e3742002-12-13 20:15:29 +00002322 }
2323 else
2324 {
2325 /* Get variable length. */
2326 first = 0;
2327 offset = name + v->namelen;
2328 offsetlen = *length - v->namelen;
2329
2330 /* LSA type value. */
2331 lsa_type = *offset;
2332 offset++;
2333 offsetlen--;
2334
2335 if (offsetlen <= 0 || lsa_type < OSPF_AS_EXTERNAL_LSA)
2336 first = 1;
2337
2338 /* LS ID. */
2339 len = offsetlen;
2340 if (len > IN_ADDR_SIZE)
2341 len = IN_ADDR_SIZE;
2342
2343 oid2in_addr (offset, len, ls_id);
2344
2345 offset += IN_ADDR_SIZE;
2346 offsetlen -= IN_ADDR_SIZE;
2347
2348 /* Router ID. */
2349 len = offsetlen;
2350 if (len > IN_ADDR_SIZE)
2351 len = IN_ADDR_SIZE;
2352
2353 oid2in_addr (offset, len, router_id);
2354
paul68980082003-03-25 05:07:42 +00002355 lsa = ospf_lsdb_lookup_by_id_next (ospf->lsdb, *type, *ls_id,
paul718e3742002-12-13 20:15:29 +00002356 *router_id, first);
2357
2358 if (lsa)
2359 {
2360 /* Fill in length. */
2361 *length = v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE;
2362
2363 /* Fill in value. */
2364 offset = name + v->namelen;
2365
2366 *offset = OSPF_AS_EXTERNAL_LSA;
2367 offset++;
2368 oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
2369 offset += IN_ADDR_SIZE;
2370 oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
2371
2372 return lsa;
2373 }
2374 }
2375 return NULL;
2376}
2377
2378static u_char *
2379ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
2380 size_t *var_len, WriteMethod **write_method)
2381{
2382 struct ospf_lsa *lsa;
2383 struct lsa_header *lsah;
2384 u_char type;
2385 struct in_addr ls_id;
2386 struct in_addr router_id;
paul020709f2003-04-04 02:44:16 +00002387 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002388
2389 type = OSPF_AS_EXTERNAL_LSA;
2390 memset (&ls_id, 0, sizeof (struct in_addr));
2391 memset (&router_id, 0, sizeof (struct in_addr));
2392
2393 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00002394 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00002395 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00002396 return NULL;
2397
2398 lsa = ospfExtLsdbLookup (v, name, length, &type, &ls_id, &router_id, exact);
2399 if (! lsa)
2400 return NULL;
2401
2402 lsah = lsa->data;
2403
2404 /* Return the current value of the variable */
2405 switch (v->magic)
2406 {
2407 case OSPFEXTLSDBTYPE:
2408 return SNMP_INTEGER (OSPF_AS_EXTERNAL_LSA);
2409 break;
2410 case OSPFEXTLSDBLSID:
2411 return SNMP_IPADDRESS (lsah->id);
2412 break;
2413 case OSPFEXTLSDBROUTERID:
2414 return SNMP_IPADDRESS (lsah->adv_router);
2415 break;
2416 case OSPFEXTLSDBSEQUENCE:
2417 return SNMP_INTEGER (lsah->ls_seqnum);
2418 break;
2419 case OSPFEXTLSDBAGE:
2420 return SNMP_INTEGER (lsah->ls_age);
2421 break;
2422 case OSPFEXTLSDBCHECKSUM:
2423 return SNMP_INTEGER (lsah->checksum);
2424 break;
2425 case OSPFEXTLSDBADVERTISEMENT:
2426 *var_len = ntohs (lsah->length);
2427 return (u_char *) lsah;
2428 break;
2429 default:
2430 return NULL;
2431 break;
2432 }
2433 return NULL;
2434}
2435
2436static u_char *
2437ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length,
2438 int exact, size_t *var_len, WriteMethod **write_method)
2439{
2440 /* Return the current value of the variable */
2441 switch (v->magic)
2442 {
2443 case OSPFAREAAGGREGATEAREAID:
2444 return (u_char *) NULL;
2445 break;
2446 case OSPFAREAAGGREGATELSDBTYPE:
2447 return (u_char *) NULL;
2448 break;
2449 case OSPFAREAAGGREGATENET:
2450 return (u_char *) NULL;
2451 break;
2452 case OSPFAREAAGGREGATEMASK:
2453 return (u_char *) NULL;
2454 break;
2455 case OSPFAREAAGGREGATESTATUS:
2456 return (u_char *) NULL;
2457 break;
2458 case OSPFAREAAGGREGATEEFFECT:
2459 return (u_char *) NULL;
2460 break;
2461 default:
2462 return NULL;
2463 break;
2464 }
2465 return NULL;
2466}
2467
2468/* Register OSPF2-MIB. */
2469void
2470ospf_snmp_init ()
2471{
2472 ospf_snmp_iflist = list_new ();
2473 ospf_snmp_vl_table = route_table_init ();
hassoc75105a2004-10-13 10:33:26 +00002474 smux_init (om->master);
paul718e3742002-12-13 20:15:29 +00002475 REGISTER_MIB("mibII/ospf", ospf_variables, variable, ospf_oid);
paul718e3742002-12-13 20:15:29 +00002476}
2477#endif /* HAVE_SNMP */