blob: 78435de562d4e71381b5227da664d5188d1ad6d4 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* OSPFv2 SNMP support
vincentba682532005-09-29 13:52:57 +00002 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
paul718e3742002-12-13 20:15:29 +00003 * Copyright (C) 2000 IP Infusion Inc.
4 *
5 * Written by Kunihiro Ishiguro <kunihiro@zebra.org>
6 *
7 * This file is part of GNU Zebra.
8 *
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 * 02111-1307, USA.
23 */
24
25#include <zebra.h>
26
27#ifdef HAVE_SNMP
paul07661cb2003-03-18 00:03:05 +000028#include <net-snmp/net-snmp-config.h>
Joakim Tjernlundfb62a3c2008-05-13 20:03:32 +020029#include <net-snmp/net-snmp-includes.h>
paul718e3742002-12-13 20:15:29 +000030
31#include "if.h"
32#include "log.h"
33#include "prefix.h"
34#include "table.h"
35#include "command.h"
36#include "memory.h"
37#include "smux.h"
38
39#include "ospfd/ospfd.h"
40#include "ospfd/ospf_interface.h"
41#include "ospfd/ospf_asbr.h"
42#include "ospfd/ospf_lsa.h"
43#include "ospfd/ospf_lsdb.h"
44#include "ospfd/ospf_abr.h"
45#include "ospfd/ospf_neighbor.h"
46#include "ospfd/ospf_nsm.h"
47#include "ospfd/ospf_flood.h"
vincente6217872005-09-29 13:56:14 +000048#include "ospfd/ospf_ism.h"
Andrew J. Schorr9aecfae2006-06-24 20:05:02 +000049#include "ospfd/ospf_dump.h"
Chris Caputo0be8dfb2009-06-02 18:40:07 +010050#include "ospfd/ospf_snmp.h"
David Lamparter6b0655a2014-06-04 06:53:35 +020051
paul718e3742002-12-13 20:15:29 +000052/* 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
David Lamparter6b0655a2014-06-04 06:53:35 +0200207
paul718e3742002-12-13 20:15:29 +0000208/* Declare static local variables for convenience. */
209SNMP_LOCAL_VARIABLES
210
211/* OSPF-MIB instances. */
212oid ospf_oid [] = { OSPF2MIB };
Vincent Bernatb7c0d062012-05-25 11:17:01 +0200213oid ospf_trap_oid [] = { OSPF2MIB, 16, 2 }; /* Not reverse mappable! */
paul718e3742002-12-13 20:15:29 +0000214
215/* IP address 0.0.0.0. */
216static struct in_addr ospf_empty_addr = {0};
217
218/* Hook functions. */
Chris Caputo0be8dfb2009-06-02 18:40:07 +0100219static u_char *ospfGeneralGroup (struct variable *, oid *, size_t *,
220 int, size_t *, WriteMethod **);
221static u_char *ospfAreaEntry (struct variable *, oid *, size_t *, int,
222 size_t *, WriteMethod **);
223static u_char *ospfStubAreaEntry (struct variable *, oid *, size_t *,
224 int, size_t *, WriteMethod **);
225static u_char *ospfLsdbEntry (struct variable *, oid *, size_t *, int,
226 size_t *, WriteMethod **);
227static u_char *ospfAreaRangeEntry (struct variable *, oid *, size_t *, int,
228 size_t *, WriteMethod **);
229static u_char *ospfHostEntry (struct variable *, oid *, size_t *, int,
230 size_t *, WriteMethod **);
231static u_char *ospfIfEntry (struct variable *, oid *, size_t *, int,
232 size_t *, WriteMethod **);
233static u_char *ospfIfMetricEntry (struct variable *, oid *, size_t *, int,
234 size_t *, WriteMethod **);
235static u_char *ospfVirtIfEntry (struct variable *, oid *, size_t *, int,
236 size_t *, WriteMethod **);
237static u_char *ospfNbrEntry (struct variable *, oid *, size_t *, int,
238 size_t *, WriteMethod **);
239static u_char *ospfVirtNbrEntry (struct variable *, oid *, size_t *, int,
240 size_t *, WriteMethod **);
241static u_char *ospfExtLsdbEntry (struct variable *, oid *, size_t *, int,
242 size_t *, WriteMethod **);
243static u_char *ospfAreaAggregateEntry (struct variable *, oid *, size_t *,
244 int, size_t *, WriteMethod **);
paul718e3742002-12-13 20:15:29 +0000245
246struct variable ospf_variables[] =
247{
248 /* OSPF general variables */
249 {OSPFROUTERID, IPADDRESS, RWRITE, ospfGeneralGroup,
250 2, {1, 1}},
251 {OSPFADMINSTAT, INTEGER, RWRITE, ospfGeneralGroup,
252 2, {1, 2}},
253 {OSPFVERSIONNUMBER, INTEGER, RONLY, ospfGeneralGroup,
254 2, {1, 3}},
255 {OSPFAREABDRRTRSTATUS, INTEGER, RONLY, ospfGeneralGroup,
256 2, {1, 4}},
257 {OSPFASBDRRTRSTATUS, INTEGER, RWRITE, ospfGeneralGroup,
258 2, {1, 5}},
259 {OSPFEXTERNLSACOUNT, GAUGE, RONLY, ospfGeneralGroup,
260 2, {1, 6}},
261 {OSPFEXTERNLSACKSUMSUM, INTEGER, RONLY, ospfGeneralGroup,
262 2, {1, 7}},
263 {OSPFTOSSUPPORT, INTEGER, RWRITE, ospfGeneralGroup,
264 2, {1, 8}},
265 {OSPFORIGINATENEWLSAS, COUNTER, RONLY, ospfGeneralGroup,
266 2, {1, 9}},
267 {OSPFRXNEWLSAS, COUNTER, RONLY, ospfGeneralGroup,
268 2, {1, 10}},
269 {OSPFEXTLSDBLIMIT, INTEGER, RWRITE, ospfGeneralGroup,
270 2, {1, 11}},
271 {OSPFMULTICASTEXTENSIONS, INTEGER, RWRITE, ospfGeneralGroup,
272 2, {1, 12}},
273 {OSPFEXITOVERFLOWINTERVAL, INTEGER, RWRITE, ospfGeneralGroup,
274 2, {1, 13}},
275 {OSPFDEMANDEXTENSIONS, INTEGER, RWRITE, ospfGeneralGroup,
276 2, {1, 14}},
277
278 /* OSPF area data structure. */
279 {OSPFAREAID, IPADDRESS, RONLY, ospfAreaEntry,
280 3, {2, 1, 1}},
281 {OSPFAUTHTYPE, INTEGER, RWRITE, ospfAreaEntry,
282 3, {2, 1, 2}},
283 {OSPFIMPORTASEXTERN, INTEGER, RWRITE, ospfAreaEntry,
284 3, {2, 1, 3}},
285 {OSPFSPFRUNS, COUNTER, RONLY, ospfAreaEntry,
286 3, {2, 1, 4}},
287 {OSPFAREABDRRTRCOUNT, GAUGE, RONLY, ospfAreaEntry,
288 3, {2, 1, 5}},
289 {OSPFASBDRRTRCOUNT, GAUGE, RONLY, ospfAreaEntry,
290 3, {2, 1, 6}},
291 {OSPFAREALSACOUNT, GAUGE, RONLY, ospfAreaEntry,
292 3, {2, 1, 7}},
293 {OSPFAREALSACKSUMSUM, INTEGER, RONLY, ospfAreaEntry,
294 3, {2, 1, 8}},
295 {OSPFAREASUMMARY, INTEGER, RWRITE, ospfAreaEntry,
296 3, {2, 1, 9}},
297 {OSPFAREASTATUS, INTEGER, RWRITE, ospfAreaEntry,
298 3, {2, 1, 10}},
299
300 /* OSPF stub area information. */
301 {OSPFSTUBAREAID, IPADDRESS, RONLY, ospfStubAreaEntry,
302 3, {3, 1, 1}},
303 {OSPFSTUBTOS, INTEGER, RONLY, ospfStubAreaEntry,
304 3, {3, 1, 2}},
305 {OSPFSTUBMETRIC, INTEGER, RWRITE, ospfStubAreaEntry,
306 3, {3, 1, 3}},
307 {OSPFSTUBSTATUS, INTEGER, RWRITE, ospfStubAreaEntry,
308 3, {3, 1, 4}},
309 {OSPFSTUBMETRICTYPE, INTEGER, RWRITE, ospfStubAreaEntry,
310 3, {3, 1, 5}},
311
312 /* OSPF link state database. */
313 {OSPFLSDBAREAID, IPADDRESS, RONLY, ospfLsdbEntry,
314 3, {4, 1, 1}},
315 {OSPFLSDBTYPE, INTEGER, RONLY, ospfLsdbEntry,
316 3, {4, 1, 2}},
317 {OSPFLSDBLSID, IPADDRESS, RONLY, ospfLsdbEntry,
318 3, {4, 1, 3}},
319 {OSPFLSDBROUTERID, IPADDRESS, RONLY, ospfLsdbEntry,
320 3, {4, 1, 4}},
321 {OSPFLSDBSEQUENCE, INTEGER, RONLY, ospfLsdbEntry,
322 3, {4, 1, 5}},
323 {OSPFLSDBAGE, INTEGER, RONLY, ospfLsdbEntry,
324 3, {4, 1, 6}},
325 {OSPFLSDBCHECKSUM, INTEGER, RONLY, ospfLsdbEntry,
326 3, {4, 1, 7}},
327 {OSPFLSDBADVERTISEMENT, STRING, RONLY, ospfLsdbEntry,
328 3, {4, 1, 8}},
329
330 /* Area range table. */
331 {OSPFAREARANGEAREAID, IPADDRESS, RONLY, ospfAreaRangeEntry,
332 3, {5, 1, 1}},
333 {OSPFAREARANGENET, IPADDRESS, RONLY, ospfAreaRangeEntry,
334 3, {5, 1, 2}},
335 {OSPFAREARANGEMASK, IPADDRESS, RWRITE, ospfAreaRangeEntry,
336 3, {5, 1, 3}},
337 {OSPFAREARANGESTATUS, INTEGER, RWRITE, ospfAreaRangeEntry,
338 3, {5, 1, 4}},
339 {OSPFAREARANGEEFFECT, INTEGER, RWRITE, ospfAreaRangeEntry,
340 3, {5, 1, 5}},
341
342 /* OSPF host table. */
343 {OSPFHOSTIPADDRESS, IPADDRESS, RONLY, ospfHostEntry,
344 3, {6, 1, 1}},
345 {OSPFHOSTTOS, INTEGER, RONLY, ospfHostEntry,
346 3, {6, 1, 2}},
347 {OSPFHOSTMETRIC, INTEGER, RWRITE, ospfHostEntry,
348 3, {6, 1, 3}},
349 {OSPFHOSTSTATUS, INTEGER, RWRITE, ospfHostEntry,
350 3, {6, 1, 4}},
351 {OSPFHOSTAREAID, IPADDRESS, RONLY, ospfHostEntry,
352 3, {6, 1, 5}},
353
354 /* OSPF interface table. */
355 {OSPFIFIPADDRESS, IPADDRESS, RONLY, ospfIfEntry,
356 3, {7, 1, 1}},
357 {OSPFADDRESSLESSIF, INTEGER, RONLY, ospfIfEntry,
358 3, {7, 1, 2}},
359 {OSPFIFAREAID, IPADDRESS, RWRITE, ospfIfEntry,
360 3, {7, 1, 3}},
361 {OSPFIFTYPE, INTEGER, RWRITE, ospfIfEntry,
362 3, {7, 1, 4}},
363 {OSPFIFADMINSTAT, INTEGER, RWRITE, ospfIfEntry,
364 3, {7, 1, 5}},
365 {OSPFIFRTRPRIORITY, INTEGER, RWRITE, ospfIfEntry,
366 3, {7, 1, 6}},
367 {OSPFIFTRANSITDELAY, INTEGER, RWRITE, ospfIfEntry,
368 3, {7, 1, 7}},
369 {OSPFIFRETRANSINTERVAL, INTEGER, RWRITE, ospfIfEntry,
370 3, {7, 1, 8}},
371 {OSPFIFHELLOINTERVAL, INTEGER, RWRITE, ospfIfEntry,
372 3, {7, 1, 9}},
373 {OSPFIFRTRDEADINTERVAL, INTEGER, RWRITE, ospfIfEntry,
374 3, {7, 1, 10}},
375 {OSPFIFPOLLINTERVAL, INTEGER, RWRITE, ospfIfEntry,
376 3, {7, 1, 11}},
377 {OSPFIFSTATE, INTEGER, RONLY, ospfIfEntry,
378 3, {7, 1, 12}},
379 {OSPFIFDESIGNATEDROUTER, IPADDRESS, RONLY, ospfIfEntry,
380 3, {7, 1, 13}},
381 {OSPFIFBACKUPDESIGNATEDROUTER, IPADDRESS, RONLY, ospfIfEntry,
382 3, {7, 1, 14}},
383 {OSPFIFEVENTS, COUNTER, RONLY, ospfIfEntry,
384 3, {7, 1, 15}},
385 {OSPFIFAUTHKEY, STRING, RWRITE, ospfIfEntry,
386 3, {7, 1, 16}},
387 {OSPFIFSTATUS, INTEGER, RWRITE, ospfIfEntry,
388 3, {7, 1, 17}},
389 {OSPFIFMULTICASTFORWARDING, INTEGER, RWRITE, ospfIfEntry,
390 3, {7, 1, 18}},
391 {OSPFIFDEMAND, INTEGER, RWRITE, ospfIfEntry,
392 3, {7, 1, 19}},
393 {OSPFIFAUTHTYPE, INTEGER, RWRITE, ospfIfEntry,
394 3, {7, 1, 20}},
395
396 /* OSPF interface metric table. */
397 {OSPFIFMETRICIPADDRESS, IPADDRESS, RONLY, ospfIfMetricEntry,
398 3, {8, 1, 1}},
399 {OSPFIFMETRICADDRESSLESSIF, INTEGER, RONLY, ospfIfMetricEntry,
400 3, {8, 1, 2}},
401 {OSPFIFMETRICTOS, INTEGER, RONLY, ospfIfMetricEntry,
402 3, {8, 1, 3}},
403 {OSPFIFMETRICVALUE, INTEGER, RWRITE, ospfIfMetricEntry,
404 3, {8, 1, 4}},
405 {OSPFIFMETRICSTATUS, INTEGER, RWRITE, ospfIfMetricEntry,
406 3, {8, 1, 5}},
407
408 /* OSPF virtual interface table. */
409 {OSPFVIRTIFAREAID, IPADDRESS, RONLY, ospfVirtIfEntry,
410 3, {9, 1, 1}},
411 {OSPFVIRTIFNEIGHBOR, IPADDRESS, RONLY, ospfVirtIfEntry,
412 3, {9, 1, 2}},
413 {OSPFVIRTIFTRANSITDELAY, INTEGER, RWRITE, ospfVirtIfEntry,
414 3, {9, 1, 3}},
415 {OSPFVIRTIFRETRANSINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
416 3, {9, 1, 4}},
417 {OSPFVIRTIFHELLOINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
418 3, {9, 1, 5}},
419 {OSPFVIRTIFRTRDEADINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
420 3, {9, 1, 6}},
421 {OSPFVIRTIFSTATE, INTEGER, RONLY, ospfVirtIfEntry,
422 3, {9, 1, 7}},
423 {OSPFVIRTIFEVENTS, COUNTER, RONLY, ospfVirtIfEntry,
424 3, {9, 1, 8}},
425 {OSPFVIRTIFAUTHKEY, STRING, RWRITE, ospfVirtIfEntry,
426 3, {9, 1, 9}},
427 {OSPFVIRTIFSTATUS, INTEGER, RWRITE, ospfVirtIfEntry,
428 3, {9, 1, 10}},
429 {OSPFVIRTIFAUTHTYPE, INTEGER, RWRITE, ospfVirtIfEntry,
430 3, {9, 1, 11}},
431
432 /* OSPF neighbor table. */
433 {OSPFNBRIPADDR, IPADDRESS, RONLY, ospfNbrEntry,
434 3, {10, 1, 1}},
435 {OSPFNBRADDRESSLESSINDEX, INTEGER, RONLY, ospfNbrEntry,
436 3, {10, 1, 2}},
437 {OSPFNBRRTRID, IPADDRESS, RONLY, ospfNbrEntry,
438 3, {10, 1, 3}},
439 {OSPFNBROPTIONS, INTEGER, RONLY, ospfNbrEntry,
440 3, {10, 1, 4}},
441 {OSPFNBRPRIORITY, INTEGER, RWRITE, ospfNbrEntry,
442 3, {10, 1, 5}},
443 {OSPFNBRSTATE, INTEGER, RONLY, ospfNbrEntry,
444 3, {10, 1, 6}},
445 {OSPFNBREVENTS, COUNTER, RONLY, ospfNbrEntry,
446 3, {10, 1, 7}},
447 {OSPFNBRLSRETRANSQLEN, GAUGE, RONLY, ospfNbrEntry,
448 3, {10, 1, 8}},
449 {OSPFNBMANBRSTATUS, INTEGER, RWRITE, ospfNbrEntry,
450 3, {10, 1, 9}},
451 {OSPFNBMANBRPERMANENCE, INTEGER, RONLY, ospfNbrEntry,
452 3, {10, 1, 10}},
453 {OSPFNBRHELLOSUPPRESSED, INTEGER, RONLY, ospfNbrEntry,
454 3, {10, 1, 11}},
455
456 /* OSPF virtual neighbor table. */
457 {OSPFVIRTNBRAREA, IPADDRESS, RONLY, ospfVirtNbrEntry,
458 3, {11, 1, 1}},
459 {OSPFVIRTNBRRTRID, IPADDRESS, RONLY, ospfVirtNbrEntry,
460 3, {11, 1, 2}},
461 {OSPFVIRTNBRIPADDR, IPADDRESS, RONLY, ospfVirtNbrEntry,
462 3, {11, 1, 3}},
463 {OSPFVIRTNBROPTIONS, INTEGER, RONLY, ospfVirtNbrEntry,
464 3, {11, 1, 4}},
465 {OSPFVIRTNBRSTATE, INTEGER, RONLY, ospfVirtNbrEntry,
466 3, {11, 1, 5}},
467 {OSPFVIRTNBREVENTS, COUNTER, RONLY, ospfVirtNbrEntry,
468 3, {11, 1, 6}},
469 {OSPFVIRTNBRLSRETRANSQLEN, INTEGER, RONLY, ospfVirtNbrEntry,
470 3, {11, 1, 7}},
471 {OSPFVIRTNBRHELLOSUPPRESSED, INTEGER, RONLY, ospfVirtNbrEntry,
472 3, {11, 1, 8}},
473
474 /* OSPF link state database, external. */
475 {OSPFEXTLSDBTYPE, INTEGER, RONLY, ospfExtLsdbEntry,
476 3, {12, 1, 1}},
477 {OSPFEXTLSDBLSID, IPADDRESS, RONLY, ospfExtLsdbEntry,
478 3, {12, 1, 2}},
479 {OSPFEXTLSDBROUTERID, IPADDRESS, RONLY, ospfExtLsdbEntry,
480 3, {12, 1, 3}},
481 {OSPFEXTLSDBSEQUENCE, INTEGER, RONLY, ospfExtLsdbEntry,
482 3, {12, 1, 4}},
483 {OSPFEXTLSDBAGE, INTEGER, RONLY, ospfExtLsdbEntry,
484 3, {12, 1, 5}},
485 {OSPFEXTLSDBCHECKSUM, INTEGER, RONLY, ospfExtLsdbEntry,
486 3, {12, 1, 6}},
487 {OSPFEXTLSDBADVERTISEMENT, STRING, RONLY, ospfExtLsdbEntry,
488 3, {12, 1, 7}},
489
490 /* OSPF area aggregate table. */
491 {OSPFAREAAGGREGATEAREAID, IPADDRESS, RONLY, ospfAreaAggregateEntry,
492 3, {14, 1, 1}},
493 {OSPFAREAAGGREGATELSDBTYPE, INTEGER, RONLY, ospfAreaAggregateEntry,
494 3, {14, 1, 2}},
495 {OSPFAREAAGGREGATENET, IPADDRESS, RONLY, ospfAreaAggregateEntry,
496 3, {14, 1, 3}},
497 {OSPFAREAAGGREGATEMASK, IPADDRESS, RONLY, ospfAreaAggregateEntry,
498 3, {14, 1, 4}},
499 {OSPFAREAAGGREGATESTATUS, INTEGER, RWRITE, ospfAreaAggregateEntry,
500 3, {14, 1, 5}},
501 {OSPFAREAAGGREGATEEFFECT, INTEGER, RWRITE, ospfAreaAggregateEntry,
502 3, {14, 1, 6}}
503};
David Lamparter6b0655a2014-06-04 06:53:35 +0200504
paul718e3742002-12-13 20:15:29 +0000505/* The administrative status of OSPF. When OSPF is enbled on at least
506 one interface return 1. */
Chris Caputo0be8dfb2009-06-02 18:40:07 +0100507static int
paul68980082003-03-25 05:07:42 +0000508ospf_admin_stat (struct ospf *ospf)
paul718e3742002-12-13 20:15:29 +0000509{
paulaa20c6f2004-10-07 14:19:36 +0000510 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000511 struct ospf_interface *oi;
512
paul68980082003-03-25 05:07:42 +0000513 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000514 return 0;
515
paul1eb8ef22005-04-07 07:30:20 +0000516 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
517 if (oi && oi->address)
518 return 1;
paul718e3742002-12-13 20:15:29 +0000519
paul718e3742002-12-13 20:15:29 +0000520 return 0;
521}
522
523static u_char *
524ospfGeneralGroup (struct variable *v, oid *name, size_t *length,
525 int exact, size_t *var_len, WriteMethod **write_method)
526{
paul020709f2003-04-04 02:44:16 +0000527 struct ospf *ospf;
528
529 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +0000530
paul718e3742002-12-13 20:15:29 +0000531 /* Check whether the instance identifier is valid */
532 if (smux_header_generic (v, name, length, exact, var_len, write_method)
533 == MATCH_FAILED)
534 return NULL;
535
536 /* Return the current value of the variable */
537 switch (v->magic)
538 {
539 case OSPFROUTERID: /* 1 */
540 /* Router-ID of this OSPF instance. */
paul68980082003-03-25 05:07:42 +0000541 if (ospf)
542 return SNMP_IPADDRESS (ospf->router_id);
paul718e3742002-12-13 20:15:29 +0000543 else
544 return SNMP_IPADDRESS (ospf_empty_addr);
545 break;
546 case OSPFADMINSTAT: /* 2 */
547 /* The administrative status of OSPF in the router. */
paul68980082003-03-25 05:07:42 +0000548 if (ospf_admin_stat (ospf))
paul718e3742002-12-13 20:15:29 +0000549 return SNMP_INTEGER (OSPF_STATUS_ENABLED);
550 else
551 return SNMP_INTEGER (OSPF_STATUS_DISABLED);
552 break;
553 case OSPFVERSIONNUMBER: /* 3 */
554 /* OSPF version 2. */
555 return SNMP_INTEGER (OSPF_VERSION);
556 break;
557 case OSPFAREABDRRTRSTATUS: /* 4 */
558 /* Area Border router status. */
paul68980082003-03-25 05:07:42 +0000559 if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ABR))
paul718e3742002-12-13 20:15:29 +0000560 return SNMP_INTEGER (SNMP_TRUE);
561 else
562 return SNMP_INTEGER (SNMP_FALSE);
563 break;
564 case OSPFASBDRRTRSTATUS: /* 5 */
565 /* AS Border router status. */
paul68980082003-03-25 05:07:42 +0000566 if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ASBR))
paul718e3742002-12-13 20:15:29 +0000567 return SNMP_INTEGER (SNMP_TRUE);
568 else
569 return SNMP_INTEGER (SNMP_FALSE);
570 break;
571 case OSPFEXTERNLSACOUNT: /* 6 */
572 /* External LSA counts. */
paul68980082003-03-25 05:07:42 +0000573 if (ospf)
574 return SNMP_INTEGER (ospf_lsdb_count_all (ospf->lsdb));
paul718e3742002-12-13 20:15:29 +0000575 else
576 return SNMP_INTEGER (0);
577 break;
578 case OSPFEXTERNLSACKSUMSUM: /* 7 */
579 /* External LSA checksum. */
580 return SNMP_INTEGER (0);
581 break;
582 case OSPFTOSSUPPORT: /* 8 */
583 /* TOS is not supported. */
584 return SNMP_INTEGER (SNMP_FALSE);
585 break;
586 case OSPFORIGINATENEWLSAS: /* 9 */
587 /* The number of new link-state advertisements. */
paul68980082003-03-25 05:07:42 +0000588 if (ospf)
589 return SNMP_INTEGER (ospf->lsa_originate_count);
paul718e3742002-12-13 20:15:29 +0000590 else
591 return SNMP_INTEGER (0);
592 break;
593 case OSPFRXNEWLSAS: /* 10 */
594 /* The number of link-state advertisements received determined
595 to be new instantiations. */
paul68980082003-03-25 05:07:42 +0000596 if (ospf)
597 return SNMP_INTEGER (ospf->rx_lsa_count);
paul718e3742002-12-13 20:15:29 +0000598 else
599 return SNMP_INTEGER (0);
600 break;
601 case OSPFEXTLSDBLIMIT: /* 11 */
602 /* There is no limit for the number of non-default
603 AS-external-LSAs. */
604 return SNMP_INTEGER (-1);
605 break;
606 case OSPFMULTICASTEXTENSIONS: /* 12 */
607 /* Multicast Extensions to OSPF is not supported. */
608 return SNMP_INTEGER (0);
609 break;
610 case OSPFEXITOVERFLOWINTERVAL: /* 13 */
611 /* Overflow is not supported. */
612 return SNMP_INTEGER (0);
613 break;
614 case OSPFDEMANDEXTENSIONS: /* 14 */
615 /* Demand routing is not supported. */
616 return SNMP_INTEGER (SNMP_FALSE);
617 break;
618 default:
619 return NULL;
620 }
621 return NULL;
622}
623
Chris Caputo0be8dfb2009-06-02 18:40:07 +0100624static struct ospf_area *
paul68980082003-03-25 05:07:42 +0000625ospf_area_lookup_next (struct ospf *ospf, struct in_addr *area_id, int first)
paul718e3742002-12-13 20:15:29 +0000626{
627 struct ospf_area *area;
paulaa20c6f2004-10-07 14:19:36 +0000628 struct listnode *node;
paul718e3742002-12-13 20:15:29 +0000629
paul020709f2003-04-04 02:44:16 +0000630 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000631 return NULL;
632
633 if (first)
634 {
paul68980082003-03-25 05:07:42 +0000635 node = listhead (ospf->areas);
paul718e3742002-12-13 20:15:29 +0000636 if (node)
637 {
paul1eb8ef22005-04-07 07:30:20 +0000638 area = listgetdata (node);
paul718e3742002-12-13 20:15:29 +0000639 *area_id = area->area_id;
640 return area;
641 }
642 return NULL;
643 }
paul1eb8ef22005-04-07 07:30:20 +0000644 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000645 {
paul718e3742002-12-13 20:15:29 +0000646 if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))
647 {
648 *area_id = area->area_id;
649 return area;
650 }
651 }
652 return NULL;
653}
654
Chris Caputo0be8dfb2009-06-02 18:40:07 +0100655static struct ospf_area *
paul718e3742002-12-13 20:15:29 +0000656ospfAreaLookup (struct variable *v, oid name[], size_t *length,
657 struct in_addr *addr, int exact)
658{
paul020709f2003-04-04 02:44:16 +0000659 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000660 struct ospf_area *area;
paul68980082003-03-25 05:07:42 +0000661 int len;
paul718e3742002-12-13 20:15:29 +0000662
paul020709f2003-04-04 02:44:16 +0000663 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +0000664 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000665 return NULL;
666
667 if (exact)
668 {
669 /* Length is insufficient to lookup OSPF area. */
670 if (*length - v->namelen != sizeof (struct in_addr))
671 return NULL;
672
673 oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);
674
paul68980082003-03-25 05:07:42 +0000675 area = ospf_area_lookup_by_area_id (ospf, *addr);
paul718e3742002-12-13 20:15:29 +0000676
677 return area;
678 }
679 else
680 {
681 len = *length - v->namelen;
682 if (len > 4)
683 len = 4;
684
685 oid2in_addr (name + v->namelen, len, addr);
686
paul68980082003-03-25 05:07:42 +0000687 area = ospf_area_lookup_next (ospf, addr, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +0000688
689 if (area == NULL)
690 return NULL;
691
692 oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));
693 *length = sizeof (struct in_addr) + v->namelen;
694
695 return area;
696 }
697 return NULL;
698}
699
700static u_char *
701ospfAreaEntry (struct variable *v, oid *name, size_t *length, int exact,
702 size_t *var_len, WriteMethod **write_method)
703{
704 struct ospf_area *area;
705 struct in_addr addr;
706
Vincent Bernat8046ba62012-05-31 13:30:28 +0200707 if (smux_header_table(v, name, length, exact, var_len, write_method)
708 == MATCH_FAILED)
709 return NULL;
710
paul718e3742002-12-13 20:15:29 +0000711 memset (&addr, 0, sizeof (struct in_addr));
712
713 area = ospfAreaLookup (v, name, length, &addr, exact);
714 if (! area)
715 return NULL;
716
717 /* Return the current value of the variable */
718 switch (v->magic)
719 {
720 case OSPFAREAID: /* 1 */
721 return SNMP_IPADDRESS (area->area_id);
722 break;
723 case OSPFAUTHTYPE: /* 2 */
724 return SNMP_INTEGER (area->auth_type);
725 break;
726 case OSPFIMPORTASEXTERN: /* 3 */
727 return SNMP_INTEGER (area->external_routing + 1);
728 break;
729 case OSPFSPFRUNS: /* 4 */
730 return SNMP_INTEGER (area->spf_calculation);
731 break;
732 case OSPFAREABDRRTRCOUNT: /* 5 */
733 return SNMP_INTEGER (area->abr_count);
734 break;
735 case OSPFASBDRRTRCOUNT: /* 6 */
736 return SNMP_INTEGER (area->asbr_count);
737 break;
738 case OSPFAREALSACOUNT: /* 7 */
739 return SNMP_INTEGER (area->lsdb->total);
740 break;
741 case OSPFAREALSACKSUMSUM: /* 8 */
742 return SNMP_INTEGER (0);
743 break;
744 case OSPFAREASUMMARY: /* 9 */
745#define OSPF_noAreaSummary 1
746#define OSPF_sendAreaSummary 2
747 if (area->no_summary)
748 return SNMP_INTEGER (OSPF_noAreaSummary);
749 else
750 return SNMP_INTEGER (OSPF_sendAreaSummary);
751 break;
752 case OSPFAREASTATUS: /* 10 */
753 return SNMP_INTEGER (SNMP_VALID);
754 break;
755 default:
756 return NULL;
757 break;
758 }
759 return NULL;
760}
761
Chris Caputo0be8dfb2009-06-02 18:40:07 +0100762static struct ospf_area *
paul718e3742002-12-13 20:15:29 +0000763ospf_stub_area_lookup_next (struct in_addr *area_id, int first)
764{
765 struct ospf_area *area;
paulaa20c6f2004-10-07 14:19:36 +0000766 struct listnode *node;
paul020709f2003-04-04 02:44:16 +0000767 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000768
paul020709f2003-04-04 02:44:16 +0000769 ospf = ospf_lookup ();
770 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000771 return NULL;
772
paul1eb8ef22005-04-07 07:30:20 +0000773 for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
paul718e3742002-12-13 20:15:29 +0000774 {
paul718e3742002-12-13 20:15:29 +0000775 if (area->external_routing == OSPF_AREA_STUB)
776 {
777 if (first)
778 {
779 *area_id = area->area_id;
780 return area;
781 }
782 else if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))
783 {
784 *area_id = area->area_id;
785 return area;
786 }
787 }
788 }
789 return NULL;
790}
791
Chris Caputo0be8dfb2009-06-02 18:40:07 +0100792static struct ospf_area *
paul718e3742002-12-13 20:15:29 +0000793ospfStubAreaLookup (struct variable *v, oid name[], size_t *length,
794 struct in_addr *addr, int exact)
795{
paul020709f2003-04-04 02:44:16 +0000796 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000797 struct ospf_area *area;
paul68980082003-03-25 05:07:42 +0000798 int len;
paul718e3742002-12-13 20:15:29 +0000799
paul020709f2003-04-04 02:44:16 +0000800 ospf = ospf_lookup ();
801 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +0000802 return NULL;
803
804 /* Exact lookup. */
805 if (exact)
806 {
807 /* ospfStubAreaID + ospfStubTOS. */
808 if (*length != v->namelen + sizeof (struct in_addr) + 1)
809 return NULL;
810
811 /* Check ospfStubTOS is zero. */
812 if (name[*length - 1] != 0)
813 return NULL;
814
815 oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);
816
paul68980082003-03-25 05:07:42 +0000817 area = ospf_area_lookup_by_area_id (ospf, *addr);
paul718e3742002-12-13 20:15:29 +0000818
819 if (area->external_routing == OSPF_AREA_STUB)
820 return area;
821 else
822 return NULL;
823 }
824 else
825 {
826 len = *length - v->namelen;
827 if (len > 4)
828 len = 4;
829
830 oid2in_addr (name + v->namelen, len, addr);
831
832 area = ospf_stub_area_lookup_next (addr, len == 0 ? 1 : 0);
833
834 if (area == NULL)
835 return NULL;
836
837 oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));
838 /* Set TOS 0. */
839 name[v->namelen + sizeof (struct in_addr)] = 0;
840 *length = v->namelen + sizeof (struct in_addr) + 1;
841
842 return area;
843 }
844 return NULL;
845}
846
847static u_char *
848ospfStubAreaEntry (struct variable *v, oid *name, size_t *length,
849 int exact, size_t *var_len, WriteMethod **write_method)
850{
851 struct ospf_area *area;
852 struct in_addr addr;
853
Vincent Bernat8046ba62012-05-31 13:30:28 +0200854 if (smux_header_table(v, name, length, exact, var_len, write_method)
855 == MATCH_FAILED)
856 return NULL;
857
paul718e3742002-12-13 20:15:29 +0000858 memset (&addr, 0, sizeof (struct in_addr));
859
860 area = ospfStubAreaLookup (v, name, length, &addr, exact);
861 if (! area)
862 return NULL;
863
864 /* Return the current value of the variable */
865 switch (v->magic)
866 {
867 case OSPFSTUBAREAID: /* 1 */
868 /* OSPF stub area id. */
869 return SNMP_IPADDRESS (area->area_id);
870 break;
871 case OSPFSTUBTOS: /* 2 */
872 /* TOS value is not supported. */
873 return SNMP_INTEGER (0);
874 break;
875 case OSPFSTUBMETRIC: /* 3 */
876 /* Default cost to stub area. */
877 return SNMP_INTEGER (area->default_cost);
878 break;
879 case OSPFSTUBSTATUS: /* 4 */
880 /* Status of the stub area. */
881 return SNMP_INTEGER (SNMP_VALID);
882 break;
883 case OSPFSTUBMETRICTYPE: /* 5 */
884 /* OSPF Metric type. */
885#define OSPF_ospfMetric 1
886#define OSPF_comparableCost 2
887#define OSPF_nonComparable 3
888 return SNMP_INTEGER (OSPF_ospfMetric);
889 break;
890 default:
891 return NULL;
892 break;
893 }
894 return NULL;
895}
896
Chris Caputo0be8dfb2009-06-02 18:40:07 +0100897static struct ospf_lsa *
paul718e3742002-12-13 20:15:29 +0000898lsdb_lookup_next (struct ospf_area *area, u_char *type, int type_next,
899 struct in_addr *ls_id, int ls_id_next,
900 struct in_addr *router_id, int router_id_next)
901{
902 struct ospf_lsa *lsa;
903 int i;
904
905 if (type_next)
906 i = OSPF_MIN_LSA;
907 else
908 i = *type;
909
vincentba682532005-09-29 13:52:57 +0000910 /* Sanity check, if LSA type unknwon
911 merley skip any LSA */
912 if ((i < OSPF_MIN_LSA) || (i >= OSPF_MAX_LSA))
913 {
914 zlog_debug("Strange request with LSA type %d\n", i);
915 return NULL;
916 }
917
paul718e3742002-12-13 20:15:29 +0000918 for (; i < OSPF_MAX_LSA; i++)
919 {
920 *type = i;
921
922 lsa = ospf_lsdb_lookup_by_id_next (area->lsdb, *type, *ls_id, *router_id,
923 ls_id_next);
924 if (lsa)
925 return lsa;
926
927 ls_id_next = 1;
928 }
929 return NULL;
930}
931
Chris Caputo0be8dfb2009-06-02 18:40:07 +0100932static struct ospf_lsa *
paul718e3742002-12-13 20:15:29 +0000933ospfLsdbLookup (struct variable *v, oid *name, size_t *length,
934 struct in_addr *area_id, u_char *type,
935 struct in_addr *ls_id, struct in_addr *router_id, int exact)
936{
paul020709f2003-04-04 02:44:16 +0000937 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +0000938 struct ospf_area *area;
939 struct ospf_lsa *lsa;
Jorge Boncompte [DTI2]7939e012012-04-09 18:03:57 +0200940 int len;
paul718e3742002-12-13 20:15:29 +0000941 int type_next;
942 int ls_id_next;
943 int router_id_next;
944 oid *offset;
945 int offsetlen;
946
paul020709f2003-04-04 02:44:16 +0000947 ospf = ospf_lookup ();
948
paul718e3742002-12-13 20:15:29 +0000949#define OSPF_LSDB_ENTRY_OFFSET \
950 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
951
952 if (exact)
953 {
954 /* Area ID + Type + LS ID + Router ID. */
955 if (*length - v->namelen != OSPF_LSDB_ENTRY_OFFSET)
956 return NULL;
957
958 /* Set OID offset for Area ID. */
959 offset = name + v->namelen;
960
961 /* Lookup area first. */
962 oid2in_addr (offset, IN_ADDR_SIZE, area_id);
paul68980082003-03-25 05:07:42 +0000963 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +0000964 if (! area)
965 return NULL;
966 offset += IN_ADDR_SIZE;
967
968 /* Type. */
969 *type = *offset;
970 offset++;
971
972 /* LS ID. */
973 oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
974 offset += IN_ADDR_SIZE;
975
976 /* Router ID. */
977 oid2in_addr (offset, IN_ADDR_SIZE, router_id);
978
979 /* Lookup LSDB. */
980 return ospf_lsdb_lookup_by_id (area->lsdb, *type, *ls_id, *router_id);
981 }
982 else
983 {
984 /* Get variable length. */
985 offset = name + v->namelen;
986 offsetlen = *length - v->namelen;
987 len = offsetlen;
988
David Lamparterdfee58f2015-03-04 06:44:57 +0100989 if (len > (int)IN_ADDR_SIZE)
paul718e3742002-12-13 20:15:29 +0000990 len = IN_ADDR_SIZE;
991
992 oid2in_addr (offset, len, area_id);
993
994 /* First we search area. */
995 if (len == IN_ADDR_SIZE)
paul68980082003-03-25 05:07:42 +0000996 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +0000997 else
Jorge Boncompte [DTI2]7939e012012-04-09 18:03:57 +0200998 area = ospf_area_lookup_next (ospf, area_id, 1);
paul718e3742002-12-13 20:15:29 +0000999
1000 if (area == NULL)
1001 return NULL;
1002
1003 do
1004 {
1005 /* Next we lookup type. */
Jorge Boncompte [DTI2]7939e012012-04-09 18:03:57 +02001006 offset += len;
1007 offsetlen -= len;
paul718e3742002-12-13 20:15:29 +00001008 len = offsetlen;
1009
1010 if (len <= 0)
1011 type_next = 1;
1012 else
1013 {
1014 len = 1;
1015 type_next = 0;
1016 *type = *offset;
1017 }
1018
1019 /* LS ID. */
1020 offset++;
1021 offsetlen--;
1022 len = offsetlen;
1023
1024 if (len <= 0)
1025 ls_id_next = 1;
1026 else
1027 {
1028 ls_id_next = 0;
David Lamparterdfee58f2015-03-04 06:44:57 +01001029 if (len > (int)IN_ADDR_SIZE)
paul718e3742002-12-13 20:15:29 +00001030 len = IN_ADDR_SIZE;
1031
1032 oid2in_addr (offset, len, ls_id);
1033 }
1034
1035 /* Router ID. */
1036 offset += IN_ADDR_SIZE;
1037 offsetlen -= IN_ADDR_SIZE;
1038 len = offsetlen;
1039
1040 if (len <= 0)
1041 router_id_next = 1;
1042 else
1043 {
1044 router_id_next = 0;
David Lamparterdfee58f2015-03-04 06:44:57 +01001045 if (len > (int)IN_ADDR_SIZE)
paul718e3742002-12-13 20:15:29 +00001046 len = IN_ADDR_SIZE;
1047
1048 oid2in_addr (offset, len, router_id);
1049 }
1050
1051 lsa = lsdb_lookup_next (area, type, type_next, ls_id, ls_id_next,
1052 router_id, router_id_next);
1053
1054 if (lsa)
1055 {
1056 /* Fill in length. */
1057 *length = v->namelen + OSPF_LSDB_ENTRY_OFFSET;
1058
1059 /* Fill in value. */
1060 offset = name + v->namelen;
1061 oid_copy_addr (offset, area_id, IN_ADDR_SIZE);
1062 offset += IN_ADDR_SIZE;
1063 *offset = lsa->data->type;
1064 offset++;
1065 oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
1066 offset += IN_ADDR_SIZE;
1067 oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
1068
1069 return lsa;
1070 }
1071 }
paul68980082003-03-25 05:07:42 +00001072 while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL);
paul718e3742002-12-13 20:15:29 +00001073 }
1074 return NULL;
1075}
1076
1077static u_char *
1078ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
1079 size_t *var_len, WriteMethod **write_method)
1080{
1081 struct ospf_lsa *lsa;
1082 struct lsa_header *lsah;
1083 struct in_addr area_id;
1084 u_char type;
1085 struct in_addr ls_id;
1086 struct in_addr router_id;
paul020709f2003-04-04 02:44:16 +00001087 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001088
Vincent Bernat8046ba62012-05-31 13:30:28 +02001089 if (smux_header_table(v, name, length, exact, var_len, write_method)
1090 == MATCH_FAILED)
1091 return NULL;
1092
paul718e3742002-12-13 20:15:29 +00001093 /* INDEX { ospfLsdbAreaId, ospfLsdbType,
1094 ospfLsdbLsid, ospfLsdbRouterId } */
1095
1096 memset (&area_id, 0, sizeof (struct in_addr));
1097 type = 0;
1098 memset (&ls_id, 0, sizeof (struct in_addr));
1099 memset (&router_id, 0, sizeof (struct in_addr));
1100
1101 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001102 ospf = ospf_lookup ();
1103 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001104 return NULL;
1105
1106 lsa = ospfLsdbLookup (v, name, length, &area_id, &type, &ls_id, &router_id,
1107 exact);
1108 if (! lsa)
1109 return NULL;
1110
1111 lsah = lsa->data;
1112
1113 /* Return the current value of the variable */
1114 switch (v->magic)
1115 {
1116 case OSPFLSDBAREAID: /* 1 */
1117 return SNMP_IPADDRESS (lsa->area->area_id);
1118 break;
1119 case OSPFLSDBTYPE: /* 2 */
1120 return SNMP_INTEGER (lsah->type);
1121 break;
1122 case OSPFLSDBLSID: /* 3 */
1123 return SNMP_IPADDRESS (lsah->id);
1124 break;
1125 case OSPFLSDBROUTERID: /* 4 */
1126 return SNMP_IPADDRESS (lsah->adv_router);
1127 break;
1128 case OSPFLSDBSEQUENCE: /* 5 */
1129 return SNMP_INTEGER (lsah->ls_seqnum);
1130 break;
1131 case OSPFLSDBAGE: /* 6 */
1132 return SNMP_INTEGER (lsah->ls_age);
1133 break;
1134 case OSPFLSDBCHECKSUM: /* 7 */
1135 return SNMP_INTEGER (lsah->checksum);
1136 break;
1137 case OSPFLSDBADVERTISEMENT: /* 8 */
1138 *var_len = ntohs (lsah->length);
1139 return (u_char *) lsah;
1140 break;
1141 default:
1142 return NULL;
1143 break;
1144 }
1145 return NULL;
1146}
1147
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001148static struct ospf_area_range *
paul718e3742002-12-13 20:15:29 +00001149ospfAreaRangeLookup (struct variable *v, oid *name, size_t *length,
1150 struct in_addr *area_id, struct in_addr *range_net,
1151 int exact)
1152{
1153 oid *offset;
1154 int offsetlen;
David Lamparterdfee58f2015-03-04 06:44:57 +01001155 int len;
paul020709f2003-04-04 02:44:16 +00001156 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001157 struct ospf_area *area;
1158 struct ospf_area_range *range;
1159 struct prefix_ipv4 p;
1160 p.family = AF_INET;
1161 p.prefixlen = IPV4_MAX_BITLEN;
1162
paul020709f2003-04-04 02:44:16 +00001163 ospf = ospf_lookup ();
1164
paul718e3742002-12-13 20:15:29 +00001165 if (exact)
1166 {
1167 /* Area ID + Range Network. */
1168 if (v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE != *length)
1169 return NULL;
1170
1171 /* Set OID offset for Area ID. */
1172 offset = name + v->namelen;
1173
1174 /* Lookup area first. */
1175 oid2in_addr (offset, IN_ADDR_SIZE, area_id);
1176
paul68980082003-03-25 05:07:42 +00001177 area = ospf_area_lookup_by_area_id (ospf, *area_id);
paul718e3742002-12-13 20:15:29 +00001178 if (! area)
1179 return NULL;
1180
1181 offset += IN_ADDR_SIZE;
1182
1183 /* Lookup area range. */
1184 oid2in_addr (offset, IN_ADDR_SIZE, range_net);
1185 p.prefix = *range_net;
1186
1187 return ospf_area_range_lookup (area, &p);
1188 }
1189 else
1190 {
1191 /* Set OID offset for Area ID. */
1192 offset = name + v->namelen;
1193 offsetlen = *length - v->namelen;
1194
1195 len = offsetlen;
David Lamparterdfee58f2015-03-04 06:44:57 +01001196 if (len > (int)IN_ADDR_SIZE)
paul718e3742002-12-13 20:15:29 +00001197 len = IN_ADDR_SIZE;
1198
1199 oid2in_addr (offset, len, area_id);
1200
1201 /* First we search area. */
1202 if (len == IN_ADDR_SIZE)
paul68980082003-03-25 05:07:42 +00001203 area = ospf_area_lookup_by_area_id (ospf,*area_id);
paul718e3742002-12-13 20:15:29 +00001204 else
paul68980082003-03-25 05:07:42 +00001205 area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +00001206
1207 if (area == NULL)
1208 return NULL;
1209
1210 do
1211 {
1212 offset += IN_ADDR_SIZE;
1213 offsetlen -= IN_ADDR_SIZE;
1214 len = offsetlen;
1215
1216 if (len < 0)
1217 len = 0;
David Lamparterdfee58f2015-03-04 06:44:57 +01001218 if (len > (int)IN_ADDR_SIZE)
paul718e3742002-12-13 20:15:29 +00001219 len = IN_ADDR_SIZE;
1220
1221 oid2in_addr (offset, len, range_net);
1222
1223 range = ospf_area_range_lookup_next (area, range_net,
1224 len == 0 ? 1 : 0);
1225
1226 if (range)
1227 {
1228 /* Fill in length. */
1229 *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
1230
1231 /* Fill in value. */
1232 offset = name + v->namelen;
1233 oid_copy_addr (offset, area_id, IN_ADDR_SIZE);
1234 offset += IN_ADDR_SIZE;
1235 oid_copy_addr (offset, range_net, IN_ADDR_SIZE);
1236
1237 return range;
1238 }
1239 }
paul68980082003-03-25 05:07:42 +00001240 while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL);
paul718e3742002-12-13 20:15:29 +00001241 }
1242 return NULL;
1243}
1244
1245static u_char *
1246ospfAreaRangeEntry (struct variable *v, oid *name, size_t *length, int exact,
1247 size_t *var_len, WriteMethod **write_method)
1248{
1249 struct ospf_area_range *range;
1250 struct in_addr area_id;
1251 struct in_addr range_net;
1252 struct in_addr mask;
paul020709f2003-04-04 02:44:16 +00001253 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001254
Vincent Bernat8046ba62012-05-31 13:30:28 +02001255 if (smux_header_table(v, name, length, exact, var_len, write_method)
1256 == MATCH_FAILED)
1257 return NULL;
1258
paul718e3742002-12-13 20:15:29 +00001259 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001260 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001261 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001262 return NULL;
1263
1264 memset (&area_id, 0, IN_ADDR_SIZE);
1265 memset (&range_net, 0, IN_ADDR_SIZE);
1266
1267 range = ospfAreaRangeLookup (v, name, length, &area_id, &range_net, exact);
1268 if (! range)
1269 return NULL;
1270
1271 /* Convert prefixlen to network mask format. */
1272 masklen2ip (range->subst_masklen, &mask);
1273
1274 /* Return the current value of the variable */
1275 switch (v->magic)
1276 {
1277 case OSPFAREARANGEAREAID: /* 1 */
1278 return SNMP_IPADDRESS (area_id);
1279 break;
1280 case OSPFAREARANGENET: /* 2 */
1281 return SNMP_IPADDRESS (range_net);
1282 break;
1283 case OSPFAREARANGEMASK: /* 3 */
1284 return SNMP_IPADDRESS (mask);
1285 break;
1286 case OSPFAREARANGESTATUS: /* 4 */
1287 return SNMP_INTEGER (SNMP_VALID);
1288 break;
1289 case OSPFAREARANGEEFFECT: /* 5 */
1290#define OSPF_advertiseMatching 1
1291#define OSPF_doNotAdvertiseMatching 2
1292 return SNMP_INTEGER (OSPF_advertiseMatching);
1293 break;
1294 default:
1295 return NULL;
1296 break;
1297 }
1298 return NULL;
1299}
1300
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001301static struct ospf_nbr_nbma *
paul718e3742002-12-13 20:15:29 +00001302ospfHostLookup (struct variable *v, oid *name, size_t *length,
1303 struct in_addr *addr, int exact)
1304{
1305 int len;
1306 struct ospf_nbr_nbma *nbr_nbma;
paul020709f2003-04-04 02:44:16 +00001307 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001308
paul020709f2003-04-04 02:44:16 +00001309 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001310 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001311 return NULL;
1312
1313 if (exact)
1314 {
1315 /* INDEX { ospfHostIpAddress, ospfHostTOS } */
1316 if (*length != v->namelen + IN_ADDR_SIZE + 1)
1317 return NULL;
1318
1319 /* Check ospfHostTOS. */
1320 if (name[*length - 1] != 0)
1321 return NULL;
1322
1323 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, addr);
1324
paul68980082003-03-25 05:07:42 +00001325 nbr_nbma = ospf_nbr_nbma_lookup (ospf, *addr);
paul718e3742002-12-13 20:15:29 +00001326
1327 return nbr_nbma;
1328 }
1329 else
1330 {
1331 len = *length - v->namelen;
1332 if (len > 4)
1333 len = 4;
1334
1335 oid2in_addr (name + v->namelen, len, addr);
1336
paul68980082003-03-25 05:07:42 +00001337 nbr_nbma = ospf_nbr_nbma_lookup_next (ospf, addr, len == 0 ? 1 : 0);
paul718e3742002-12-13 20:15:29 +00001338
1339 if (nbr_nbma == NULL)
1340 return NULL;
1341
1342 oid_copy_addr (name + v->namelen, addr, IN_ADDR_SIZE);
1343
1344 /* Set TOS 0. */
1345 name[v->namelen + IN_ADDR_SIZE] = 0;
1346
1347 *length = v->namelen + IN_ADDR_SIZE + 1;
1348
1349 return nbr_nbma;
1350 }
1351 return NULL;
1352}
1353
1354static u_char *
1355ospfHostEntry (struct variable *v, oid *name, size_t *length, int exact,
1356 size_t *var_len, WriteMethod **write_method)
1357{
1358 struct ospf_nbr_nbma *nbr_nbma;
1359 struct ospf_interface *oi;
1360 struct in_addr addr;
paul020709f2003-04-04 02:44:16 +00001361 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001362
Vincent Bernat8046ba62012-05-31 13:30:28 +02001363 if (smux_header_table(v, name, length, exact, var_len, write_method)
1364 == MATCH_FAILED)
1365 return NULL;
1366
paul718e3742002-12-13 20:15:29 +00001367 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001368 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001369 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001370 return NULL;
1371
1372 memset (&addr, 0, sizeof (struct in_addr));
1373
1374 nbr_nbma = ospfHostLookup (v, name, length, &addr, exact);
1375 if (nbr_nbma == NULL)
1376 return NULL;
1377
1378 oi = nbr_nbma->oi;
1379
1380 /* Return the current value of the variable */
1381 switch (v->magic)
1382 {
1383 case OSPFHOSTIPADDRESS: /* 1 */
1384 return SNMP_IPADDRESS (nbr_nbma->addr);
1385 break;
1386 case OSPFHOSTTOS: /* 2 */
1387 return SNMP_INTEGER (0);
1388 break;
1389 case OSPFHOSTMETRIC: /* 3 */
1390 if (oi)
1391 return SNMP_INTEGER (oi->output_cost);
1392 else
1393 return SNMP_INTEGER (1);
1394 break;
1395 case OSPFHOSTSTATUS: /* 4 */
1396 return SNMP_INTEGER (SNMP_VALID);
1397 break;
1398 case OSPFHOSTAREAID: /* 5 */
1399 if (oi && oi->area)
1400 return SNMP_IPADDRESS (oi->area->area_id);
1401 else
1402 return SNMP_IPADDRESS (ospf_empty_addr);
1403 break;
1404 default:
1405 return NULL;
1406 break;
1407 }
1408 return NULL;
1409}
David Lamparter6b0655a2014-06-04 06:53:35 +02001410
paul718e3742002-12-13 20:15:29 +00001411struct list *ospf_snmp_iflist;
1412
1413struct ospf_snmp_if
1414{
1415 struct in_addr addr;
1416 unsigned int ifindex;
1417 struct interface *ifp;
1418};
1419
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001420static struct ospf_snmp_if *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08001421ospf_snmp_if_new (void)
paul718e3742002-12-13 20:15:29 +00001422{
Stephen Hemminger393deb92008-08-18 14:13:29 -07001423 return XCALLOC (0, sizeof (struct ospf_snmp_if));
paul718e3742002-12-13 20:15:29 +00001424}
1425
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001426static void
paul718e3742002-12-13 20:15:29 +00001427ospf_snmp_if_free (struct ospf_snmp_if *osif)
1428{
1429 XFREE (0, osif);
1430}
1431
1432void
1433ospf_snmp_if_delete (struct interface *ifp)
1434{
paul1eb8ef22005-04-07 07:30:20 +00001435 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00001436 struct ospf_snmp_if *osif;
1437
paul1eb8ef22005-04-07 07:30:20 +00001438 for (ALL_LIST_ELEMENTS (ospf_snmp_iflist, node, nnode, osif))
paul718e3742002-12-13 20:15:29 +00001439 {
1440 if (osif->ifp == ifp)
1441 {
paul1eb8ef22005-04-07 07:30:20 +00001442 list_delete_node (ospf_snmp_iflist, node);
paul718e3742002-12-13 20:15:29 +00001443 ospf_snmp_if_free (osif);
1444 return;
1445 }
1446 }
1447}
1448
1449void
1450ospf_snmp_if_update (struct interface *ifp)
1451{
paul1eb8ef22005-04-07 07:30:20 +00001452 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001453 struct listnode *pn;
1454 struct connected *ifc;
1455 struct prefix *p;
1456 struct ospf_snmp_if *osif;
1457 struct in_addr *addr;
1458 unsigned int ifindex;
1459
1460 ospf_snmp_if_delete (ifp);
1461
1462 p = NULL;
1463 addr = NULL;
1464 ifindex = 0;
1465
1466 /* Lookup first IPv4 address entry. */
paul1eb8ef22005-04-07 07:30:20 +00001467 for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
paul718e3742002-12-13 20:15:29 +00001468 {
Andrew J. Schorre4529632006-12-12 19:18:21 +00001469 p = CONNECTED_ID(ifc);
paul718e3742002-12-13 20:15:29 +00001470
1471 if (p->family == AF_INET)
1472 {
1473 addr = &p->u.prefix4;
1474 break;
1475 }
1476 }
1477 if (! addr)
1478 ifindex = ifp->ifindex;
1479
1480 /* Add interface to the list. */
1481 pn = NULL;
paul1eb8ef22005-04-07 07:30:20 +00001482 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif))
paul718e3742002-12-13 20:15:29 +00001483 {
1484 if (addr)
1485 {
vincent77df1f72005-10-06 07:46:22 +00001486 /* Usual interfaces --> Sort them based on interface IPv4 addresses */
paul718e3742002-12-13 20:15:29 +00001487 if (ntohl (osif->addr.s_addr) > ntohl (addr->s_addr))
1488 break;
1489 }
1490 else
1491 {
vincent77df1f72005-10-06 07:46:22 +00001492 /* Unnumbered interfaces --> Sort them based on interface indexes */
paul718e3742002-12-13 20:15:29 +00001493 if (osif->addr.s_addr != 0 || osif->ifindex > ifindex)
1494 break;
1495 }
paul1eb8ef22005-04-07 07:30:20 +00001496 pn = node;
paul718e3742002-12-13 20:15:29 +00001497 }
1498
1499 osif = ospf_snmp_if_new ();
vincent77df1f72005-10-06 07:46:22 +00001500 if (addr) /* Usual interface */
1501 {
paul718e3742002-12-13 20:15:29 +00001502 osif->addr = *addr;
vincent77df1f72005-10-06 07:46:22 +00001503
1504 /* This field is used for storing ospfAddressLessIf OID value,
1505 * conform to RFC1850 OSPF-MIB specification, it must be 0 for
1506 * usual interface */
1507 osif->ifindex = 0;
1508 }
1509 else /* Unnumbered interface */
paul718e3742002-12-13 20:15:29 +00001510 osif->ifindex = ifindex;
1511 osif->ifp = ifp;
1512
1513 listnode_add_after (ospf_snmp_iflist, pn, osif);
1514}
1515
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001516static int
vincent77df1f72005-10-06 07:46:22 +00001517ospf_snmp_is_if_have_addr (struct interface *ifp)
1518{
vincent77df1f72005-10-06 07:46:22 +00001519 struct listnode *nn;
1520 struct connected *ifc;
1521
1522 /* Is this interface having any connected IPv4 address ? */
1523 for (ALL_LIST_ELEMENTS_RO (ifp->connected, nn, ifc))
1524 {
Andrew J. Schorre4529632006-12-12 19:18:21 +00001525 if (CONNECTED_PREFIX(ifc)->family == AF_INET)
vincent77df1f72005-10-06 07:46:22 +00001526 return 1;
1527 }
1528
1529 return 0;
1530}
1531
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001532static struct ospf_interface *
paul718e3742002-12-13 20:15:29 +00001533ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex)
1534{
paul1eb8ef22005-04-07 07:30:20 +00001535 struct listnode *node;
paul718e3742002-12-13 20:15:29 +00001536 struct ospf_snmp_if *osif;
vincent77df1f72005-10-06 07:46:22 +00001537 struct ospf_interface *oi = NULL;
1538 struct ospf *ospf = ospf_lookup ();
paul718e3742002-12-13 20:15:29 +00001539
paul1eb8ef22005-04-07 07:30:20 +00001540 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif))
paul718e3742002-12-13 20:15:29 +00001541 {
1542 if (ifaddr->s_addr)
vincent77df1f72005-10-06 07:46:22 +00001543 {
1544 if (IPV4_ADDR_SAME (&osif->addr, ifaddr))
1545 oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
1546 }
paul718e3742002-12-13 20:15:29 +00001547 else
vincent77df1f72005-10-06 07:46:22 +00001548 {
1549 if (osif->ifindex == *ifindex)
1550 oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
1551 }
paul718e3742002-12-13 20:15:29 +00001552 }
vincent77df1f72005-10-06 07:46:22 +00001553 return oi;
paul718e3742002-12-13 20:15:29 +00001554}
1555
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001556static struct ospf_interface *
paul718e3742002-12-13 20:15:29 +00001557ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex,
1558 int ifaddr_next, int ifindex_next)
1559{
1560 struct ospf_snmp_if *osif;
1561 struct listnode *nn;
vincent77df1f72005-10-06 07:46:22 +00001562 struct ospf *ospf = ospf_lookup ();
1563 struct ospf_interface *oi = NULL;
paul718e3742002-12-13 20:15:29 +00001564
vincent77df1f72005-10-06 07:46:22 +00001565 if (ospf == NULL)
1566 return NULL;
1567
1568 /* No instance is specified --> Return the first OSPF interface */
paul718e3742002-12-13 20:15:29 +00001569 if (ifaddr_next)
1570 {
vincent77df1f72005-10-06 07:46:22 +00001571 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, nn, osif))
paul718e3742002-12-13 20:15:29 +00001572 {
paul1eb8ef22005-04-07 07:30:20 +00001573 osif = listgetdata (nn);
paul718e3742002-12-13 20:15:29 +00001574 *ifaddr = osif->addr;
1575 *ifindex = osif->ifindex;
vincent77df1f72005-10-06 07:46:22 +00001576 /* Because no instance is specified, we don't care about the kind of
1577 * interface (usual or unnumbered), just returning the first valid
1578 * OSPF interface */
1579 oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
1580 if (oi)
1581 return (oi);
paul718e3742002-12-13 20:15:29 +00001582 }
1583 return NULL;
1584 }
1585
vincent77df1f72005-10-06 07:46:22 +00001586 /* An instance is specified --> Return the next OSPF interface */
paul1eb8ef22005-04-07 07:30:20 +00001587 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, nn, osif))
paul718e3742002-12-13 20:15:29 +00001588 {
vincent77df1f72005-10-06 07:46:22 +00001589 /* Usual interface */
1590 if (ifaddr->s_addr)
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001591 {
1592 /* The interface must have valid AF_INET connected address */
1593 /* it must have lager IPv4 address value than the lookup entry */
1594 if ((ospf_snmp_is_if_have_addr(osif->ifp)) &&
1595 (ntohl (osif->addr.s_addr) > ntohl (ifaddr->s_addr)))
1596 {
1597 *ifaddr = osif->addr;
1598 *ifindex = osif->ifindex;
vincent77df1f72005-10-06 07:46:22 +00001599
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001600 /* and it must be an OSPF interface */
1601 oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
1602 if (oi)
1603 return oi;
1604 }
1605 }
vincent77df1f72005-10-06 07:46:22 +00001606 /* Unnumbered interface */
1607 else
1608 /* The interface must NOT have valid AF_INET connected address */
1609 /* it must have lager interface index than the lookup entry */
1610 if ((!ospf_snmp_is_if_have_addr(osif->ifp)) &&
1611 (osif->ifindex > *ifindex))
1612 {
1613 *ifaddr = osif->addr;
1614 *ifindex = osif->ifindex;
1615
1616 /* and it must be an OSPF interface */
1617 oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
1618 if (oi)
1619 return oi;
1620 }
paul718e3742002-12-13 20:15:29 +00001621 }
1622 return NULL;
1623}
1624
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001625static int
paul718e3742002-12-13 20:15:29 +00001626ospf_snmp_iftype (struct interface *ifp)
1627{
1628#define ospf_snmp_iftype_broadcast 1
1629#define ospf_snmp_iftype_nbma 2
1630#define ospf_snmp_iftype_pointToPoint 3
1631#define ospf_snmp_iftype_pointToMultipoint 5
1632 if (if_is_broadcast (ifp))
1633 return ospf_snmp_iftype_broadcast;
1634 if (if_is_pointopoint (ifp))
1635 return ospf_snmp_iftype_pointToPoint;
1636 return ospf_snmp_iftype_broadcast;
1637}
1638
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001639static struct ospf_interface *
paul718e3742002-12-13 20:15:29 +00001640ospfIfLookup (struct variable *v, oid *name, size_t *length,
1641 struct in_addr *ifaddr, unsigned int *ifindex, int exact)
1642{
paul6c835672004-10-11 11:00:30 +00001643 unsigned int len;
paul718e3742002-12-13 20:15:29 +00001644 int ifaddr_next = 0;
1645 int ifindex_next = 0;
vincent77df1f72005-10-06 07:46:22 +00001646 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +00001647 oid *offset;
1648
1649 if (exact)
1650 {
1651 if (*length != v->namelen + IN_ADDR_SIZE + 1)
1652 return NULL;
1653
1654 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr);
1655 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1656
1657 return ospf_snmp_if_lookup (ifaddr, ifindex);
1658 }
1659 else
1660 {
1661 len = *length - v->namelen;
1662 if (len >= IN_ADDR_SIZE)
1663 len = IN_ADDR_SIZE;
1664 if (len <= 0)
1665 ifaddr_next = 1;
1666
1667 oid2in_addr (name + v->namelen, len, ifaddr);
1668
1669 len = *length - v->namelen - IN_ADDR_SIZE;
1670 if (len >= 1)
1671 len = 1;
1672 else
1673 ifindex_next = 1;
1674
1675 if (len == 1)
1676 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1677
vincent77df1f72005-10-06 07:46:22 +00001678 oi = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next,
paul718e3742002-12-13 20:15:29 +00001679 ifindex_next);
vincent77df1f72005-10-06 07:46:22 +00001680 if (oi)
paul718e3742002-12-13 20:15:29 +00001681 {
1682 *length = v->namelen + IN_ADDR_SIZE + 1;
1683 offset = name + v->namelen;
1684 oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE);
1685 offset += IN_ADDR_SIZE;
1686 *offset = *ifindex;
vincent77df1f72005-10-06 07:46:22 +00001687 return oi;
paul718e3742002-12-13 20:15:29 +00001688 }
1689 }
1690 return NULL;
1691}
1692
1693static u_char *
1694ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact,
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001695 size_t *var_len, WriteMethod **write_method)
paul718e3742002-12-13 20:15:29 +00001696{
paul718e3742002-12-13 20:15:29 +00001697 unsigned int ifindex;
1698 struct in_addr ifaddr;
1699 struct ospf_interface *oi;
paul020709f2003-04-04 02:44:16 +00001700 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001701
Vincent Bernat8046ba62012-05-31 13:30:28 +02001702 if (smux_header_table(v, name, length, exact, var_len, write_method)
1703 == MATCH_FAILED)
1704 return NULL;
1705
paul718e3742002-12-13 20:15:29 +00001706 ifindex = 0;
1707 memset (&ifaddr, 0, sizeof (struct in_addr));
1708
1709 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001710 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001711 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001712 return NULL;
1713
vincent77df1f72005-10-06 07:46:22 +00001714 oi = ospfIfLookup (v, name, length, &ifaddr, &ifindex, exact);
paul718e3742002-12-13 20:15:29 +00001715 if (oi == NULL)
1716 return NULL;
1717
1718 /* Return the current value of the variable */
1719 switch (v->magic)
1720 {
1721 case OSPFIFIPADDRESS: /* 1 */
1722 return SNMP_IPADDRESS (ifaddr);
1723 break;
1724 case OSPFADDRESSLESSIF: /* 2 */
1725 return SNMP_INTEGER (ifindex);
1726 break;
1727 case OSPFIFAREAID: /* 3 */
1728 if (oi->area)
1729 return SNMP_IPADDRESS (oi->area->area_id);
1730 else
1731 return SNMP_IPADDRESS (ospf_empty_addr);
1732 break;
1733 case OSPFIFTYPE: /* 4 */
vincent77df1f72005-10-06 07:46:22 +00001734 return SNMP_INTEGER (ospf_snmp_iftype (oi->ifp));
paul718e3742002-12-13 20:15:29 +00001735 break;
1736 case OSPFIFADMINSTAT: /* 5 */
1737 if (oi)
1738 return SNMP_INTEGER (OSPF_STATUS_ENABLED);
1739 else
1740 return SNMP_INTEGER (OSPF_STATUS_DISABLED);
1741 break;
1742 case OSPFIFRTRPRIORITY: /* 6 */
1743 return SNMP_INTEGER (PRIORITY (oi));
1744 break;
1745 case OSPFIFTRANSITDELAY: /* 7 */
1746 return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
1747 break;
1748 case OSPFIFRETRANSINTERVAL: /* 8 */
1749 return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
1750 break;
1751 case OSPFIFHELLOINTERVAL: /* 9 */
1752 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
1753 break;
1754 case OSPFIFRTRDEADINTERVAL: /* 10 */
1755 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
1756 break;
1757 case OSPFIFPOLLINTERVAL: /* 11 */
1758 return SNMP_INTEGER (OSPF_POLL_INTERVAL_DEFAULT);
1759 break;
1760 case OSPFIFSTATE: /* 12 */
vincentba682532005-09-29 13:52:57 +00001761 return SNMP_INTEGER (ISM_SNMP(oi->state));
paul718e3742002-12-13 20:15:29 +00001762 break;
1763 case OSPFIFDESIGNATEDROUTER: /* 13 */
1764 return SNMP_IPADDRESS (DR (oi));
1765 break;
1766 case OSPFIFBACKUPDESIGNATEDROUTER: /* 14 */
1767 return SNMP_IPADDRESS (BDR (oi));
1768 break;
1769 case OSPFIFEVENTS: /* 15 */
1770 return SNMP_INTEGER (oi->state_change);
1771 break;
1772 case OSPFIFAUTHKEY: /* 16 */
1773 *var_len = 0;
1774 return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
1775 break;
1776 case OSPFIFSTATUS: /* 17 */
1777 return SNMP_INTEGER (SNMP_VALID);
1778 break;
1779 case OSPFIFMULTICASTFORWARDING: /* 18 */
1780#define ospf_snmp_multiforward_blocked 1
1781#define ospf_snmp_multiforward_multicast 2
1782#define ospf_snmp_multiforward_unicast 3
1783 return SNMP_INTEGER (ospf_snmp_multiforward_blocked);
1784 break;
1785 case OSPFIFDEMAND: /* 19 */
1786 return SNMP_INTEGER (SNMP_FALSE);
1787 break;
1788 case OSPFIFAUTHTYPE: /* 20 */
1789 if (oi->area)
1790 return SNMP_INTEGER (oi->area->auth_type);
1791 else
1792 return SNMP_INTEGER (0);
1793 break;
1794 default:
1795 return NULL;
1796 break;
1797 }
1798 return NULL;
1799}
1800
1801#define OSPF_SNMP_METRIC_VALUE 1
1802
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001803static struct ospf_interface *
paul718e3742002-12-13 20:15:29 +00001804ospfIfMetricLookup (struct variable *v, oid *name, size_t *length,
1805 struct in_addr *ifaddr, unsigned int *ifindex, int exact)
1806{
paul6c835672004-10-11 11:00:30 +00001807 unsigned int len;
paul718e3742002-12-13 20:15:29 +00001808 int ifaddr_next = 0;
1809 int ifindex_next = 0;
vincent77df1f72005-10-06 07:46:22 +00001810 struct ospf_interface *oi;
paul718e3742002-12-13 20:15:29 +00001811 oid *offset;
1812 int metric;
1813
1814 if (exact)
1815 {
1816 if (*length != v->namelen + IN_ADDR_SIZE + 1 + 1)
1817 return NULL;
1818
1819 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr);
1820 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1821 metric = name[v->namelen + IN_ADDR_SIZE + 1];
1822
1823 if (metric != OSPF_SNMP_METRIC_VALUE)
1824 return NULL;
1825
1826 return ospf_snmp_if_lookup (ifaddr, ifindex);
1827 }
1828 else
1829 {
1830 len = *length - v->namelen;
1831 if (len >= IN_ADDR_SIZE)
1832 len = IN_ADDR_SIZE;
1833 else
1834 ifaddr_next = 1;
1835
1836 oid2in_addr (name + v->namelen, len, ifaddr);
1837
1838 len = *length - v->namelen - IN_ADDR_SIZE;
1839 if (len >= 1)
1840 len = 1;
1841 else
1842 ifindex_next = 1;
1843
1844 if (len == 1)
1845 *ifindex = name[v->namelen + IN_ADDR_SIZE];
1846
vincent77df1f72005-10-06 07:46:22 +00001847 oi = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next,
paul718e3742002-12-13 20:15:29 +00001848 ifindex_next);
vincent77df1f72005-10-06 07:46:22 +00001849 if (oi)
paul718e3742002-12-13 20:15:29 +00001850 {
1851 *length = v->namelen + IN_ADDR_SIZE + 1 + 1;
1852 offset = name + v->namelen;
1853 oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE);
1854 offset += IN_ADDR_SIZE;
1855 *offset = *ifindex;
1856 offset++;
1857 *offset = OSPF_SNMP_METRIC_VALUE;
vincent77df1f72005-10-06 07:46:22 +00001858 return oi;
paul718e3742002-12-13 20:15:29 +00001859 }
1860 }
1861 return NULL;
1862}
1863
1864static u_char *
1865ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact,
1866 size_t *var_len, WriteMethod **write_method)
1867{
1868 /* Currently we support metric 1 only. */
paul718e3742002-12-13 20:15:29 +00001869 unsigned int ifindex;
1870 struct in_addr ifaddr;
1871 struct ospf_interface *oi;
paul020709f2003-04-04 02:44:16 +00001872 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00001873
Vincent Bernat8046ba62012-05-31 13:30:28 +02001874 if (smux_header_table(v, name, length, exact, var_len, write_method)
1875 == MATCH_FAILED)
1876 return NULL;
1877
paul718e3742002-12-13 20:15:29 +00001878 ifindex = 0;
1879 memset (&ifaddr, 0, sizeof (struct in_addr));
1880
1881 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00001882 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00001883 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00001884 return NULL;
1885
vincent77df1f72005-10-06 07:46:22 +00001886 oi = ospfIfMetricLookup (v, name, length, &ifaddr, &ifindex, exact);
paul718e3742002-12-13 20:15:29 +00001887 if (oi == NULL)
1888 return NULL;
1889
1890 /* Return the current value of the variable */
1891 switch (v->magic)
1892 {
1893 case OSPFIFMETRICIPADDRESS:
1894 return SNMP_IPADDRESS (ifaddr);
1895 break;
1896 case OSPFIFMETRICADDRESSLESSIF:
1897 return SNMP_INTEGER (ifindex);
1898 break;
1899 case OSPFIFMETRICTOS:
1900 return SNMP_INTEGER (0);
1901 break;
1902 case OSPFIFMETRICVALUE:
1903 return SNMP_INTEGER (OSPF_SNMP_METRIC_VALUE);
1904 break;
1905 case OSPFIFMETRICSTATUS:
1906 return SNMP_INTEGER (1);
1907 break;
1908 default:
1909 return NULL;
1910 break;
1911 }
1912 return NULL;
1913}
David Lamparter6b0655a2014-06-04 06:53:35 +02001914
paul718e3742002-12-13 20:15:29 +00001915struct route_table *ospf_snmp_vl_table;
1916
1917void
1918ospf_snmp_vl_add (struct ospf_vl_data *vl_data)
1919{
1920 struct prefix_ls lp;
1921 struct route_node *rn;
1922
1923 memset (&lp, 0, sizeof (struct prefix_ls));
1924 lp.family = 0;
1925 lp.prefixlen = 64;
1926 lp.id = vl_data->vl_area_id;
1927 lp.adv_router = vl_data->vl_peer;
1928
1929 rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp);
Joakim Tjernlund4de398e2010-03-08 13:58:14 +01001930 if (rn->info)
1931 route_unlock_node (rn);
1932
paul718e3742002-12-13 20:15:29 +00001933 rn->info = vl_data;
1934}
1935
1936void
1937ospf_snmp_vl_delete (struct ospf_vl_data *vl_data)
1938{
1939 struct prefix_ls lp;
1940 struct route_node *rn;
1941
1942 memset (&lp, 0, sizeof (struct prefix_ls));
1943 lp.family = 0;
1944 lp.prefixlen = 64;
1945 lp.id = vl_data->vl_area_id;
1946 lp.adv_router = vl_data->vl_peer;
1947
1948 rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
1949 if (! rn)
1950 return;
1951 rn->info = NULL;
1952 route_unlock_node (rn);
1953 route_unlock_node (rn);
1954}
1955
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001956static struct ospf_vl_data *
paul718e3742002-12-13 20:15:29 +00001957ospf_snmp_vl_lookup (struct in_addr *area_id, struct in_addr *neighbor)
1958{
1959 struct prefix_ls lp;
1960 struct route_node *rn;
1961 struct ospf_vl_data *vl_data;
1962
1963 memset (&lp, 0, sizeof (struct prefix_ls));
1964 lp.family = 0;
1965 lp.prefixlen = 64;
1966 lp.id = *area_id;
1967 lp.adv_router = *neighbor;
1968
1969 rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
1970 if (rn)
1971 {
1972 vl_data = rn->info;
1973 route_unlock_node (rn);
1974 return vl_data;
1975 }
1976 return NULL;
1977}
1978
Chris Caputo0be8dfb2009-06-02 18:40:07 +01001979static struct ospf_vl_data *
paul718e3742002-12-13 20:15:29 +00001980ospf_snmp_vl_lookup_next (struct in_addr *area_id, struct in_addr *neighbor,
1981 int first)
1982{
1983 struct prefix_ls lp;
1984 struct route_node *rn;
1985 struct ospf_vl_data *vl_data;
1986
1987 memset (&lp, 0, sizeof (struct prefix_ls));
1988 lp.family = 0;
1989 lp.prefixlen = 64;
1990 lp.id = *area_id;
1991 lp.adv_router = *neighbor;
1992
1993 if (first)
1994 rn = route_top (ospf_snmp_vl_table);
1995 else
1996 {
Joakim Tjernlundc9b07582010-03-08 13:58:11 +01001997 rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
1998 if (!rn)
1999 return NULL;
paul718e3742002-12-13 20:15:29 +00002000 rn = route_next (rn);
2001 }
2002
2003 for (; rn; rn = route_next (rn))
2004 if (rn->info)
2005 break;
2006
2007 if (rn && rn->info)
2008 {
2009 vl_data = rn->info;
2010 *area_id = vl_data->vl_area_id;
2011 *neighbor = vl_data->vl_peer;
2012 route_unlock_node (rn);
2013 return vl_data;
2014 }
2015 return NULL;
2016}
2017
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002018static struct ospf_vl_data *
paul718e3742002-12-13 20:15:29 +00002019ospfVirtIfLookup (struct variable *v, oid *name, size_t *length,
2020 struct in_addr *area_id, struct in_addr *neighbor, int exact)
2021{
2022 int first;
paul6c835672004-10-11 11:00:30 +00002023 unsigned int len;
paul718e3742002-12-13 20:15:29 +00002024 struct ospf_vl_data *vl_data;
2025
2026 if (exact)
2027 {
2028 if (*length != v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE)
2029 return NULL;
2030
2031 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, area_id);
2032 oid2in_addr (name + v->namelen + IN_ADDR_SIZE, IN_ADDR_SIZE, neighbor);
2033
2034 return ospf_snmp_vl_lookup (area_id, neighbor);
2035 }
2036 else
2037 {
2038 first = 0;
2039
2040 len = *length - v->namelen;
2041 if (len <= 0)
2042 first = 1;
2043 if (len > IN_ADDR_SIZE)
2044 len = IN_ADDR_SIZE;
2045 oid2in_addr (name + v->namelen, len, area_id);
2046
2047 len = *length - v->namelen - IN_ADDR_SIZE;
2048 if (len > IN_ADDR_SIZE)
2049 len = IN_ADDR_SIZE;
2050 oid2in_addr (name + v->namelen + IN_ADDR_SIZE, len, neighbor);
2051
2052 vl_data = ospf_snmp_vl_lookup_next (area_id, neighbor, first);
2053
2054 if (vl_data)
2055 {
2056 *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
2057 oid_copy_addr (name + v->namelen, area_id, IN_ADDR_SIZE);
2058 oid_copy_addr (name + v->namelen + IN_ADDR_SIZE, neighbor,
2059 IN_ADDR_SIZE);
2060 return vl_data;
2061 }
2062 }
2063 return NULL;
2064}
2065
2066static u_char *
2067ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact,
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002068 size_t *var_len, WriteMethod **write_method)
paul718e3742002-12-13 20:15:29 +00002069{
2070 struct ospf_vl_data *vl_data;
2071 struct ospf_interface *oi;
2072 struct in_addr area_id;
2073 struct in_addr neighbor;
2074
Vincent Bernat8046ba62012-05-31 13:30:28 +02002075 if (smux_header_table(v, name, length, exact, var_len, write_method)
2076 == MATCH_FAILED)
2077 return NULL;
2078
paul718e3742002-12-13 20:15:29 +00002079 memset (&area_id, 0, sizeof (struct in_addr));
2080 memset (&neighbor, 0, sizeof (struct in_addr));
2081
2082 vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
2083 if (! vl_data)
2084 return NULL;
2085 oi = vl_data->vl_oi;
2086 if (! oi)
2087 return NULL;
2088
2089 /* Return the current value of the variable */
2090 switch (v->magic)
2091 {
2092 case OSPFVIRTIFAREAID:
2093 return SNMP_IPADDRESS (area_id);
2094 break;
2095 case OSPFVIRTIFNEIGHBOR:
2096 return SNMP_IPADDRESS (neighbor);
2097 break;
2098 case OSPFVIRTIFTRANSITDELAY:
2099 return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
2100 break;
2101 case OSPFVIRTIFRETRANSINTERVAL:
2102 return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
2103 break;
2104 case OSPFVIRTIFHELLOINTERVAL:
2105 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
2106 break;
2107 case OSPFVIRTIFRTRDEADINTERVAL:
2108 return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
2109 break;
2110 case OSPFVIRTIFSTATE:
2111 return SNMP_INTEGER (oi->state);
2112 break;
2113 case OSPFVIRTIFEVENTS:
2114 return SNMP_INTEGER (oi->state_change);
2115 break;
2116 case OSPFVIRTIFAUTHKEY:
2117 *var_len = 0;
2118 return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
2119 break;
2120 case OSPFVIRTIFSTATUS:
2121 return SNMP_INTEGER (SNMP_VALID);
2122 break;
2123 case OSPFVIRTIFAUTHTYPE:
2124 if (oi->area)
2125 return SNMP_INTEGER (oi->area->auth_type);
2126 else
2127 return SNMP_INTEGER (0);
2128 break;
2129 default:
2130 return NULL;
2131 break;
2132 }
2133 return NULL;
2134}
David Lamparter6b0655a2014-06-04 06:53:35 +02002135
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002136static struct ospf_neighbor *
paul68980082003-03-25 05:07:42 +00002137ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr,
2138 unsigned int *ifindex)
paul718e3742002-12-13 20:15:29 +00002139{
paul1eb8ef22005-04-07 07:30:20 +00002140 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002141 struct ospf_interface *oi;
2142 struct ospf_neighbor *nbr;
2143 struct route_node *rn;
2144
paul1eb8ef22005-04-07 07:30:20 +00002145 for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
paul718e3742002-12-13 20:15:29 +00002146 {
2147 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
2148 if ((nbr = rn->info) != NULL
2149 && nbr != oi->nbr_self
vincent5e4914c2005-09-29 16:34:30 +00002150/* If EXACT match is needed, provide ALL entry found
paul718e3742002-12-13 20:15:29 +00002151 && nbr->state != NSM_Down
vincent5e4914c2005-09-29 16:34:30 +00002152 */
paul718e3742002-12-13 20:15:29 +00002153 && nbr->src.s_addr != 0)
2154 {
2155 if (IPV4_ADDR_SAME (&nbr->src, nbr_addr))
2156 {
2157 route_unlock_node (rn);
2158 return nbr;
2159 }
2160 }
2161 }
2162 return NULL;
2163}
2164
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002165static struct ospf_neighbor *
paul718e3742002-12-13 20:15:29 +00002166ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex,
2167 int first)
2168{
2169 struct listnode *nn;
2170 struct ospf_interface *oi;
2171 struct ospf_neighbor *nbr;
2172 struct route_node *rn;
2173 struct ospf_neighbor *min = NULL;
paul020709f2003-04-04 02:44:16 +00002174 struct ospf *ospf = ospf;
paul718e3742002-12-13 20:15:29 +00002175
paul020709f2003-04-04 02:44:16 +00002176 ospf = ospf_lookup ();
paul1eb8ef22005-04-07 07:30:20 +00002177
2178 for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, nn, oi))
paul718e3742002-12-13 20:15:29 +00002179 {
2180 for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
2181 if ((nbr = rn->info) != NULL
2182 && nbr != oi->nbr_self
2183 && nbr->state != NSM_Down
2184 && nbr->src.s_addr != 0)
2185 {
2186 if (first)
2187 {
2188 if (! min)
2189 min = nbr;
2190 else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
2191 min = nbr;
2192 }
2193 else if (ntohl (nbr->src.s_addr) > ntohl (nbr_addr->s_addr))
2194 {
2195 if (! min)
2196 min = nbr;
2197 else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
2198 min = nbr;
2199 }
2200 }
2201 }
2202 if (min)
2203 {
2204 *nbr_addr = min->src;
2205 *ifindex = 0;
2206 return min;
2207 }
2208 return NULL;
2209}
2210
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002211static struct ospf_neighbor *
paul718e3742002-12-13 20:15:29 +00002212ospfNbrLookup (struct variable *v, oid *name, size_t *length,
2213 struct in_addr *nbr_addr, unsigned int *ifindex, int exact)
2214{
paul6c835672004-10-11 11:00:30 +00002215 unsigned int len;
paul718e3742002-12-13 20:15:29 +00002216 int first;
2217 struct ospf_neighbor *nbr;
paul020709f2003-04-04 02:44:16 +00002218 struct ospf *ospf;
2219
2220 ospf = ospf_lookup ();
paul718e3742002-12-13 20:15:29 +00002221
hasso1b639042005-03-27 13:32:25 +00002222 if (! ospf)
2223 return NULL;
2224
paul718e3742002-12-13 20:15:29 +00002225 if (exact)
2226 {
2227 if (*length != v->namelen + IN_ADDR_SIZE + 1)
2228 return NULL;
2229
2230 oid2in_addr (name + v->namelen, IN_ADDR_SIZE, nbr_addr);
2231 *ifindex = name[v->namelen + IN_ADDR_SIZE];
2232
paul68980082003-03-25 05:07:42 +00002233 return ospf_snmp_nbr_lookup (ospf, nbr_addr, ifindex);
paul718e3742002-12-13 20:15:29 +00002234 }
2235 else
2236 {
2237 first = 0;
2238 len = *length - v->namelen;
2239
2240 if (len <= 0)
2241 first = 1;
2242
2243 if (len > IN_ADDR_SIZE)
2244 len = IN_ADDR_SIZE;
2245
2246 oid2in_addr (name + v->namelen, len, nbr_addr);
2247
2248 len = *length - v->namelen - IN_ADDR_SIZE;
2249 if (len >= 1)
2250 *ifindex = name[v->namelen + IN_ADDR_SIZE];
2251
2252 nbr = ospf_snmp_nbr_lookup_next (nbr_addr, ifindex, first);
2253
2254 if (nbr)
2255 {
2256 *length = v->namelen + IN_ADDR_SIZE + 1;
2257 oid_copy_addr (name + v->namelen, nbr_addr, IN_ADDR_SIZE);
2258 name[v->namelen + IN_ADDR_SIZE] = *ifindex;
2259 return nbr;
2260 }
2261 }
2262 return NULL;
2263}
2264
Andrew J. Schorrad81f8c2007-03-14 22:05:18 +00002265/* map internal quagga neighbor states to official MIB values:
2266
2267ospfNbrState OBJECT-TYPE
2268 SYNTAX INTEGER {
2269 down (1),
2270 attempt (2),
2271 init (3),
2272 twoWay (4),
2273 exchangeStart (5),
2274 exchange (6),
2275 loading (7),
2276 full (8)
2277 }
2278*/
2279static int32_t
2280ospf_snmp_neighbor_state(u_char nst)
2281{
2282 switch (nst)
2283 {
2284 case NSM_Attempt:
2285 return 2;
2286 case NSM_Init:
2287 return 3;
2288 case NSM_TwoWay:
2289 return 4;
2290 case NSM_ExStart:
2291 return 5;
2292 case NSM_Exchange:
2293 return 6;
2294 case NSM_Loading:
2295 return 7;
2296 case NSM_Full:
2297 return 8;
2298 default:
2299 return 1; /* down */
2300 }
2301}
2302
paul718e3742002-12-13 20:15:29 +00002303static u_char *
2304ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002305 size_t *var_len, WriteMethod **write_method)
paul718e3742002-12-13 20:15:29 +00002306{
2307 struct in_addr nbr_addr;
2308 unsigned int ifindex;
2309 struct ospf_neighbor *nbr;
2310 struct ospf_interface *oi;
2311
Vincent Bernat8046ba62012-05-31 13:30:28 +02002312 if (smux_header_table(v, name, length, exact, var_len, write_method)
2313 == MATCH_FAILED)
2314 return NULL;
2315
paul718e3742002-12-13 20:15:29 +00002316 memset (&nbr_addr, 0, sizeof (struct in_addr));
2317 ifindex = 0;
2318
2319 nbr = ospfNbrLookup (v, name, length, &nbr_addr, &ifindex, exact);
2320 if (! nbr)
2321 return NULL;
2322 oi = nbr->oi;
2323 if (! oi)
2324 return NULL;
2325
2326 /* Return the current value of the variable */
2327 switch (v->magic)
2328 {
2329 case OSPFNBRIPADDR:
2330 return SNMP_IPADDRESS (nbr_addr);
2331 break;
2332 case OSPFNBRADDRESSLESSINDEX:
2333 return SNMP_INTEGER (ifindex);
2334 break;
2335 case OSPFNBRRTRID:
2336 return SNMP_IPADDRESS (nbr->router_id);
2337 break;
2338 case OSPFNBROPTIONS:
2339 return SNMP_INTEGER (oi->nbr_self->options);
2340 break;
2341 case OSPFNBRPRIORITY:
2342 return SNMP_INTEGER (nbr->priority);
2343 break;
2344 case OSPFNBRSTATE:
Andrew J. Schorrad81f8c2007-03-14 22:05:18 +00002345 return SNMP_INTEGER (ospf_snmp_neighbor_state(nbr->state));
paul718e3742002-12-13 20:15:29 +00002346 break;
2347 case OSPFNBREVENTS:
2348 return SNMP_INTEGER (nbr->state_change);
2349 break;
2350 case OSPFNBRLSRETRANSQLEN:
2351 return SNMP_INTEGER (ospf_ls_retransmit_count (nbr));
2352 break;
2353 case OSPFNBMANBRSTATUS:
2354 return SNMP_INTEGER (SNMP_VALID);
2355 break;
2356 case OSPFNBMANBRPERMANENCE:
2357 return SNMP_INTEGER (2);
2358 break;
2359 case OSPFNBRHELLOSUPPRESSED:
2360 return SNMP_INTEGER (SNMP_FALSE);
2361 break;
2362 default:
2363 return NULL;
2364 break;
2365 }
2366 return NULL;
2367}
David Lamparter6b0655a2014-06-04 06:53:35 +02002368
paul718e3742002-12-13 20:15:29 +00002369static u_char *
2370ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002371 size_t *var_len, WriteMethod **write_method)
paul718e3742002-12-13 20:15:29 +00002372{
2373 struct ospf_vl_data *vl_data;
2374 struct in_addr area_id;
2375 struct in_addr neighbor;
paul020709f2003-04-04 02:44:16 +00002376 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002377
Vincent Bernat8046ba62012-05-31 13:30:28 +02002378 if (smux_header_table(v, name, length, exact, var_len, write_method)
2379 == MATCH_FAILED)
2380 return NULL;
2381
paul718e3742002-12-13 20:15:29 +00002382 memset (&area_id, 0, sizeof (struct in_addr));
2383 memset (&neighbor, 0, sizeof (struct in_addr));
2384
2385 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00002386 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00002387 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00002388 return NULL;
2389
2390 vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
2391 if (! vl_data)
2392 return NULL;
2393
2394 /* Return the current value of the variable */
2395 switch (v->magic)
2396 {
2397 case OSPFVIRTNBRAREA:
2398 return (u_char *) NULL;
2399 break;
2400 case OSPFVIRTNBRRTRID:
2401 return (u_char *) NULL;
2402 break;
2403 case OSPFVIRTNBRIPADDR:
2404 return (u_char *) NULL;
2405 break;
2406 case OSPFVIRTNBROPTIONS:
2407 return (u_char *) NULL;
2408 break;
2409 case OSPFVIRTNBRSTATE:
2410 return (u_char *) NULL;
2411 break;
2412 case OSPFVIRTNBREVENTS:
2413 return (u_char *) NULL;
2414 break;
2415 case OSPFVIRTNBRLSRETRANSQLEN:
2416 return (u_char *) NULL;
2417 break;
2418 case OSPFVIRTNBRHELLOSUPPRESSED:
2419 return (u_char *) NULL;
2420 break;
2421 default:
2422 return NULL;
2423 break;
2424 }
2425 return NULL;
2426}
David Lamparter6b0655a2014-06-04 06:53:35 +02002427
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002428static struct ospf_lsa *
paul718e3742002-12-13 20:15:29 +00002429ospfExtLsdbLookup (struct variable *v, oid *name, size_t *length, u_char *type,
2430 struct in_addr *ls_id, struct in_addr *router_id, int exact)
2431{
2432 int first;
2433 oid *offset;
2434 int offsetlen;
2435 u_char lsa_type;
paul6c835672004-10-11 11:00:30 +00002436 unsigned int len;
paul718e3742002-12-13 20:15:29 +00002437 struct ospf_lsa *lsa;
paul020709f2003-04-04 02:44:16 +00002438 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002439
paul020709f2003-04-04 02:44:16 +00002440 ospf = ospf_lookup ();
paul718e3742002-12-13 20:15:29 +00002441 if (exact)
2442 {
2443 if (*length != v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
2444 return NULL;
2445
2446 offset = name + v->namelen;
2447
2448 /* Make it sure given value match to type. */
2449 lsa_type = *offset;
2450 offset++;
2451
2452 if (lsa_type != *type)
2453 return NULL;
2454
2455 /* LS ID. */
2456 oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
2457 offset += IN_ADDR_SIZE;
2458
2459 /* Router ID. */
2460 oid2in_addr (offset, IN_ADDR_SIZE, router_id);
2461
paul68980082003-03-25 05:07:42 +00002462 return ospf_lsdb_lookup_by_id (ospf->lsdb, *type, *ls_id, *router_id);
paul718e3742002-12-13 20:15:29 +00002463 }
2464 else
2465 {
2466 /* Get variable length. */
2467 first = 0;
2468 offset = name + v->namelen;
2469 offsetlen = *length - v->namelen;
2470
2471 /* LSA type value. */
2472 lsa_type = *offset;
2473 offset++;
2474 offsetlen--;
2475
2476 if (offsetlen <= 0 || lsa_type < OSPF_AS_EXTERNAL_LSA)
2477 first = 1;
2478
2479 /* LS ID. */
2480 len = offsetlen;
2481 if (len > IN_ADDR_SIZE)
2482 len = IN_ADDR_SIZE;
2483
2484 oid2in_addr (offset, len, ls_id);
2485
2486 offset += IN_ADDR_SIZE;
2487 offsetlen -= IN_ADDR_SIZE;
2488
2489 /* Router ID. */
2490 len = offsetlen;
2491 if (len > IN_ADDR_SIZE)
2492 len = IN_ADDR_SIZE;
2493
2494 oid2in_addr (offset, len, router_id);
2495
paul68980082003-03-25 05:07:42 +00002496 lsa = ospf_lsdb_lookup_by_id_next (ospf->lsdb, *type, *ls_id,
paul718e3742002-12-13 20:15:29 +00002497 *router_id, first);
2498
2499 if (lsa)
2500 {
2501 /* Fill in length. */
2502 *length = v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE;
2503
2504 /* Fill in value. */
2505 offset = name + v->namelen;
2506
2507 *offset = OSPF_AS_EXTERNAL_LSA;
2508 offset++;
2509 oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
2510 offset += IN_ADDR_SIZE;
2511 oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
2512
2513 return lsa;
2514 }
2515 }
2516 return NULL;
2517}
2518
2519static u_char *
2520ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
Chris Caputo0be8dfb2009-06-02 18:40:07 +01002521 size_t *var_len, WriteMethod **write_method)
paul718e3742002-12-13 20:15:29 +00002522{
2523 struct ospf_lsa *lsa;
2524 struct lsa_header *lsah;
2525 u_char type;
2526 struct in_addr ls_id;
2527 struct in_addr router_id;
paul020709f2003-04-04 02:44:16 +00002528 struct ospf *ospf;
paul718e3742002-12-13 20:15:29 +00002529
Vincent Bernat8046ba62012-05-31 13:30:28 +02002530 if (smux_header_table(v, name, length, exact, var_len, write_method)
2531 == MATCH_FAILED)
2532 return NULL;
2533
paul718e3742002-12-13 20:15:29 +00002534 type = OSPF_AS_EXTERNAL_LSA;
2535 memset (&ls_id, 0, sizeof (struct in_addr));
2536 memset (&router_id, 0, sizeof (struct in_addr));
2537
2538 /* Check OSPF instance. */
paul020709f2003-04-04 02:44:16 +00002539 ospf = ospf_lookup ();
paul68980082003-03-25 05:07:42 +00002540 if (ospf == NULL)
paul718e3742002-12-13 20:15:29 +00002541 return NULL;
2542
2543 lsa = ospfExtLsdbLookup (v, name, length, &type, &ls_id, &router_id, exact);
2544 if (! lsa)
2545 return NULL;
2546
2547 lsah = lsa->data;
2548
2549 /* Return the current value of the variable */
2550 switch (v->magic)
2551 {
2552 case OSPFEXTLSDBTYPE:
2553 return SNMP_INTEGER (OSPF_AS_EXTERNAL_LSA);
2554 break;
2555 case OSPFEXTLSDBLSID:
2556 return SNMP_IPADDRESS (lsah->id);
2557 break;
2558 case OSPFEXTLSDBROUTERID:
2559 return SNMP_IPADDRESS (lsah->adv_router);
2560 break;
2561 case OSPFEXTLSDBSEQUENCE:
2562 return SNMP_INTEGER (lsah->ls_seqnum);
2563 break;
2564 case OSPFEXTLSDBAGE:
2565 return SNMP_INTEGER (lsah->ls_age);
2566 break;
2567 case OSPFEXTLSDBCHECKSUM:
2568 return SNMP_INTEGER (lsah->checksum);
2569 break;
2570 case OSPFEXTLSDBADVERTISEMENT:
2571 *var_len = ntohs (lsah->length);
2572 return (u_char *) lsah;
2573 break;
2574 default:
2575 return NULL;
2576 break;
2577 }
2578 return NULL;
2579}
David Lamparter6b0655a2014-06-04 06:53:35 +02002580
paul718e3742002-12-13 20:15:29 +00002581static u_char *
2582ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length,
2583 int exact, size_t *var_len, WriteMethod **write_method)
2584{
Vincent Bernat8046ba62012-05-31 13:30:28 +02002585 if (smux_header_table(v, name, length, exact, var_len, write_method)
2586 == MATCH_FAILED)
2587 return NULL;
2588
paul718e3742002-12-13 20:15:29 +00002589 /* Return the current value of the variable */
2590 switch (v->magic)
2591 {
2592 case OSPFAREAAGGREGATEAREAID:
2593 return (u_char *) NULL;
2594 break;
2595 case OSPFAREAAGGREGATELSDBTYPE:
2596 return (u_char *) NULL;
2597 break;
2598 case OSPFAREAAGGREGATENET:
2599 return (u_char *) NULL;
2600 break;
2601 case OSPFAREAAGGREGATEMASK:
2602 return (u_char *) NULL;
2603 break;
2604 case OSPFAREAAGGREGATESTATUS:
2605 return (u_char *) NULL;
2606 break;
2607 case OSPFAREAAGGREGATEEFFECT:
2608 return (u_char *) NULL;
2609 break;
2610 default:
2611 return NULL;
2612 break;
2613 }
2614 return NULL;
2615}
David Lamparter6b0655a2014-06-04 06:53:35 +02002616
vincent5e4914c2005-09-29 16:34:30 +00002617/* OSPF Traps. */
2618#define IFSTATECHANGE 16
2619#define VIRTIFSTATECHANGE 1
2620#define NBRSTATECHANGE 2
2621#define VIRTNBRSTATECHANGE 3
2622
2623struct trap_object ospfNbrTrapList[] =
2624{
Vincent Bernatb8cf46b2012-05-25 08:56:44 +02002625 {-2, {1, OSPFROUTERID}},
2626 {3, {10, 1, OSPFNBRIPADDR}},
2627 {3, {10, 1, OSPFNBRRTRID}},
2628 {3, {10, 1, OSPFNBRSTATE}}
vincent5e4914c2005-09-29 16:34:30 +00002629};
2630
2631
2632struct trap_object ospfVirtNbrTrapList[] =
2633{
Vincent Bernatb8cf46b2012-05-25 08:56:44 +02002634 {-2, {1, 1}},
2635 {3, {11, 1, OSPFVIRTNBRAREA}},
2636 {3, {11, 1, OSPFVIRTNBRRTRID}},
2637 {3, {11, 1, OSPFVIRTNBRSTATE}}
vincent5e4914c2005-09-29 16:34:30 +00002638};
2639
2640struct trap_object ospfIfTrapList[] =
2641{
Vincent Bernatb8cf46b2012-05-25 08:56:44 +02002642 {-2, {1, OSPFROUTERID}},
2643 {3, {7, 1, OSPFIFIPADDRESS}},
2644 {3, {7, 1, OSPFADDRESSLESSIF}},
2645 {3, {7, 1, OSPFIFSTATE}}
vincent5e4914c2005-09-29 16:34:30 +00002646};
2647
2648struct trap_object ospfVirtIfTrapList[] =
2649{
Vincent Bernatb8cf46b2012-05-25 08:56:44 +02002650 {-2, {1, OSPFROUTERID}},
2651 {3, {9, 1, OSPFVIRTIFAREAID}},
2652 {3, {9, 1, OSPFVIRTIFNEIGHBOR}},
2653 {3, {9, 1, OSPFVIRTIFSTATE}}
vincent5e4914c2005-09-29 16:34:30 +00002654};
2655
2656void
2657ospfTrapNbrStateChange (struct ospf_neighbor *on)
2658{
2659 oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
Andrew J. Schorr9aecfae2006-06-24 20:05:02 +00002660 char msgbuf[16];
vincent5e4914c2005-09-29 16:34:30 +00002661
Andrew J. Schorr9aecfae2006-06-24 20:05:02 +00002662 ospf_nbr_state_message(on, msgbuf, sizeof(msgbuf));
2663 zlog (NULL, LOG_INFO, "ospfTrapNbrStateChange trap sent: %s now %s",
2664 inet_ntoa(on->address.u.prefix4), msgbuf);
vincent5e4914c2005-09-29 16:34:30 +00002665
2666 oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
2667 index[IN_ADDR_SIZE] = 0;
2668
Vincent Bernatb7c0d062012-05-25 11:17:01 +02002669 smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable),
2670 ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid),
2671 ospf_oid, sizeof ospf_oid / sizeof (oid),
vincent5e4914c2005-09-29 16:34:30 +00002672 index, IN_ADDR_SIZE + 1,
2673 ospfNbrTrapList,
2674 sizeof ospfNbrTrapList / sizeof (struct trap_object),
Vincent Bernat4b89e452012-05-24 21:22:01 +02002675 NBRSTATECHANGE);
vincent5e4914c2005-09-29 16:34:30 +00002676}
2677
2678void
2679ospfTrapVirtNbrStateChange (struct ospf_neighbor *on)
2680{
2681 oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
2682
2683 zlog (NULL, LOG_INFO, "ospfTrapVirtNbrStateChange trap sent");
2684
2685 oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
2686 index[IN_ADDR_SIZE] = 0;
2687
Vincent Bernatb7c0d062012-05-25 11:17:01 +02002688 smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable),
2689 ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid),
2690 ospf_oid, sizeof ospf_oid / sizeof (oid),
vincent5e4914c2005-09-29 16:34:30 +00002691 index, IN_ADDR_SIZE + 1,
2692 ospfVirtNbrTrapList,
2693 sizeof ospfVirtNbrTrapList / sizeof (struct trap_object),
Vincent Bernat4b89e452012-05-24 21:22:01 +02002694 VIRTNBRSTATECHANGE);
vincent5e4914c2005-09-29 16:34:30 +00002695}
2696
2697void
2698ospfTrapIfStateChange (struct ospf_interface *oi)
2699{
2700 oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
2701
Andrew J. Schorr9aecfae2006-06-24 20:05:02 +00002702 zlog (NULL, LOG_INFO, "ospfTrapIfStateChange trap sent: %s now %s",
2703 inet_ntoa(oi->address->u.prefix4),
2704 LOOKUP(ospf_ism_state_msg, oi->state));
vincent5e4914c2005-09-29 16:34:30 +00002705
2706 oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
2707 index[IN_ADDR_SIZE] = 0;
2708
Vincent Bernatb7c0d062012-05-25 11:17:01 +02002709 smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable),
2710 ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid),
2711 ospf_oid, sizeof ospf_oid / sizeof (oid),
vincent5e4914c2005-09-29 16:34:30 +00002712 index, IN_ADDR_SIZE + 1,
2713 ospfIfTrapList,
2714 sizeof ospfIfTrapList / sizeof (struct trap_object),
Vincent Bernat4b89e452012-05-24 21:22:01 +02002715 IFSTATECHANGE);
vincent5e4914c2005-09-29 16:34:30 +00002716}
2717
2718void
2719ospfTrapVirtIfStateChange (struct ospf_interface *oi)
2720{
2721 oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
2722
2723 zlog (NULL, LOG_INFO, "ospfTrapVirtIfStateChange trap sent");
2724
2725 oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
2726 index[IN_ADDR_SIZE] = 0;
2727
Vincent Bernatb7c0d062012-05-25 11:17:01 +02002728 smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable),
2729 ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid),
2730 ospf_oid, sizeof ospf_oid / sizeof (oid),
vincent5e4914c2005-09-29 16:34:30 +00002731 index, IN_ADDR_SIZE + 1,
2732 ospfVirtIfTrapList,
2733 sizeof ospfVirtIfTrapList / sizeof (struct trap_object),
Vincent Bernat4b89e452012-05-24 21:22:01 +02002734 VIRTIFSTATECHANGE);
vincent5e4914c2005-09-29 16:34:30 +00002735}
paul718e3742002-12-13 20:15:29 +00002736/* Register OSPF2-MIB. */
2737void
2738ospf_snmp_init ()
2739{
2740 ospf_snmp_iflist = list_new ();
2741 ospf_snmp_vl_table = route_table_init ();
hassoc75105a2004-10-13 10:33:26 +00002742 smux_init (om->master);
paul718e3742002-12-13 20:15:29 +00002743 REGISTER_MIB("mibII/ospf", ospf_variables, variable, ospf_oid);
paul718e3742002-12-13 20:15:29 +00002744}
2745#endif /* HAVE_SNMP */