]> git.proxmox.com Git - mirror_frr.git/blame - ospf6d/ospf6_snmp.c
pimd: A buffer may be used uninited
[mirror_frr.git] / ospf6d / ospf6_snmp.c
CommitLineData
ef1bbf5c 1/* OSPFv3 SNMP support
2 * Copyright (C) 2004 Yasuhiro Ohara
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
896014f4
DL
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
ef1bbf5c 19 */
20
21#include <zebra.h>
22
ef1bbf5c 23#include <net-snmp/net-snmp-config.h>
fb62a3ce 24#include <net-snmp/net-snmp-includes.h>
ef1bbf5c 25
26#include "log.h"
27#include "vty.h"
28#include "linklist.h"
d11f748b
DL
29#include "vector.h"
30#include "vrf.h"
ef1bbf5c 31#include "smux.h"
5986b66b
DL
32#include "libfrr.h"
33#include "version.h"
ef1bbf5c 34
35#include "ospf6_proto.h"
36#include "ospf6_lsa.h"
37#include "ospf6_lsdb.h"
38#include "ospf6_route.h"
39#include "ospf6_top.h"
40#include "ospf6_area.h"
41#include "ospf6_interface.h"
42#include "ospf6_message.h"
43#include "ospf6_neighbor.h"
1cc5e682
DL
44#include "ospf6_abr.h"
45#include "ospf6_asbr.h"
ef1bbf5c 46#include "ospf6d.h"
3012671f 47
ef1bbf5c 48/* OSPFv3-MIB */
0f0ab518 49#define OSPFv3MIB 1,3,6,1,2,1,191
ef1bbf5c 50
ef1bbf5c 51/* OSPFv3 MIB General Group values. */
52#define OSPFv3ROUTERID 1
53#define OSPFv3ADMINSTAT 2
54#define OSPFv3VERSIONNUMBER 3
55#define OSPFv3AREABDRRTRSTATUS 4
56#define OSPFv3ASBDRRTRSTATUS 5
57#define OSPFv3ASSCOPELSACOUNT 6
58#define OSPFv3ASSCOPELSACHECKSUMSUM 7
59#define OSPFv3ORIGINATENEWLSAS 8
60#define OSPFv3RXNEWLSAS 9
61#define OSPFv3EXTLSACOUNT 10
62#define OSPFv3EXTAREALSDBLIMIT 11
0f0ab518
VB
63#define OSPFv3EXITOVERFLOWINTERVAL 12
64#define OSPFv3DEMANDEXTENSIONS 13
65#define OSPFv3REFERENCEBANDWIDTH 14
66#define OSPFv3RESTARTSUPPORT 15
67#define OSPFv3RESTARTINTERVAL 16
68#define OSPFv3RESTARTSTRICTLSACHECKING 17
69#define OSPFv3RESTARTSTATUS 18
70#define OSPFv3RESTARTAGE 19
71#define OSPFv3RESTARTEXITREASON 20
72#define OSPFv3NOTIFICATIONENABLE 21
73#define OSPFv3STUBROUTERSUPPORT 22
74#define OSPFv3STUBROUTERADVERTISEMENT 23
75#define OSPFv3DISCONTINUITYTIME 24
76#define OSPFv3RESTARTTIME 25
77
78/* OSPFv3 MIB Area Table values: ospfv3AreaTable */
ef1bbf5c 79#define OSPFv3IMPORTASEXTERN 2
2680aa2b 80#define OSPFv3AREASPFRUNS 3
81#define OSPFv3AREABDRRTRCOUNT 4
82#define OSPFv3AREAASBDRRTRCOUNT 5
83#define OSPFv3AREASCOPELSACOUNT 6
84#define OSPFv3AREASCOPELSACKSUMSUM 7
85#define OSPFv3AREASUMMARY 8
0f0ab518
VB
86#define OSPFv3AREAROWSTATUS 9
87#define OSPFv3AREASTUBMETRIC 10
2680aa2b 88#define OSPFv3AREANSSATRANSLATORROLE 11
89#define OSPFv3AREANSSATRANSLATORSTATE 12
0f0ab518 90#define OSPFv3AREANSSATRANSLATORSTABINTERVAL 13
2680aa2b 91#define OSPFv3AREANSSATRANSLATOREVENTS 14
92#define OSPFv3AREASTUBMETRICTYPE 15
0f0ab518 93#define OSPFv3AREATEENABLED 16
2680aa2b 94
c349bb86
VB
95/* OSPFv3 MIB * Lsdb Table values: ospfv3*LsdbTable */
96#define OSPFv3WWLSDBSEQUENCE 1
97#define OSPFv3WWLSDBAGE 2
98#define OSPFv3WWLSDBCHECKSUM 3
99#define OSPFv3WWLSDBADVERTISEMENT 4
100#define OSPFv3WWLSDBTYPEKNOWN 5
101
102/* Three first bits are to identify column */
103#define OSPFv3WWCOLUMN 0x7
104/* Then we use other bits to identify table */
105#define OSPFv3WWASTABLE (1 << 3)
106#define OSPFv3WWAREATABLE (1 << 4)
107#define OSPFv3WWLINKTABLE (1 << 5)
108#define OSPFv3WWVIRTLINKTABLE (1 << 6)
0f0ab518
VB
109
110/* OSPFv3 MIB Host Table values: ospfv3HostTable */
111#define OSPFv3HOSTMETRIC 3
112#define OSPFv3HOSTROWSTATUS 4
113#define OSPFv3HOSTAREAID 5
114
115/* OSPFv3 MIB Interface Table values: ospfv3IfTable */
116#define OSPFv3IFAREAID 3
117#define OSPFv3IFTYPE 4
118#define OSPFv3IFADMINSTATUS 5
119#define OSPFv3IFRTRPRIORITY 6
120#define OSPFv3IFTRANSITDELAY 7
121#define OSPFv3IFRETRANSINTERVAL 8
122#define OSPFv3IFHELLOINTERVAL 9
123#define OSPFv3IFRTRDEADINTERVAL 10
124#define OSPFv3IFPOLLINTERVAL 11
125#define OSPFv3IFSTATE 12
126#define OSPFv3IFDESIGNATEDROUTER 13
127#define OSPFv3IFBACKUPDESIGNATEDROUTER 14
128#define OSPFv3IFEVENTS 15
129#define OSPFv3IFROWSTATUS 16
130#define OSPFv3IFDEMAND 17
131#define OSPFv3IFMETRICVALUE 18
132#define OSPFv3IFLINKSCOPELSACOUNT 19
133#define OSPFv3IFLINKLSACKSUMSUM 20
134#define OSPFv3IFDEMANDNBRPROBE 21
135#define OSPFv3IFDEMANDNBRPROBERETRANSLIMIT 22
136#define OSPFv3IFDEMANDNBRPROBEINTERVAL 23
137#define OSPFv3IFTEDISABLED 24
138#define OSPFv3IFLINKLSASUPPRESSION 25
139
140/* OSPFv3 MIB Virtual Interface Table values: ospfv3VirtIfTable */
141#define OSPFv3VIRTIFINDEX 3
142#define OSPFv3VIRTIFINSTID 4
143#define OSPFv3VIRTIFTRANSITDELAY 5
144#define OSPFv3VIRTIFRETRANSINTERVAL 6
145#define OSPFv3VIRTIFHELLOINTERVAL 7
146#define OSPFv3VIRTIFRTRDEADINTERVAL 8
147#define OSPFv3VIRTIFSTATE 9
148#define OSPFv3VIRTIFEVENTS 10
149#define OSPFv3VIRTIFROWSTATUS 11
150#define OSPFv3VIRTIFLINKSCOPELSACOUNT 12
151#define OSPFv3VIRTIFLINKLSACKSUMSUM 13
152
153/* OSPFv3 MIB Neighbors Table values: ospfv3NbrTable */
154#define OSPFv3NBRADDRESSTYPE 4
155#define OSPFv3NBRADDRESS 5
156#define OSPFv3NBROPTIONS 6
157#define OSPFv3NBRPRIORITY 7
158#define OSPFv3NBRSTATE 8
159#define OSPFv3NBREVENTS 9
160#define OSPFv3NBRLSRETRANSQLEN 10
161#define OSPFv3NBRHELLOSUPPRESSED 11
162#define OSPFv3NBRIFID 12
163#define OSPFv3NBRRESTARTHELPERSTATUS 13
164#define OSPFv3NBRRESTARTHELPERAGE 14
165#define OSPFv3NBRRESTARTHELPEREXITREASON 15
166
167/* OSPFv3 MIB Configured Neighbors Table values: ospfv3CfgNbrTable */
168#define OSPFv3CFGNBRPRIORITY 5
169#define OSPFv3CFGNBRROWSTATUS 6
170
171/* OSPFv3 MIB Virtual Neighbors Table values: ospfv3VirtNbrTable */
172#define OSPFv3VIRTNBRIFINDEX 3
173#define OSPFv3VIRTNBRIFINSTID 4
174#define OSPFv3VIRTNBRADDRESSTYPE 5
175#define OSPFv3VIRTNBRADDRESS 6
176#define OSPFv3VIRTNBROPTIONS 7
177#define OSPFv3VIRTNBRSTATE 8
178#define OSPFv3VIRTNBREVENTS 9
179#define OSPFv3VIRTNBRLSRETRANSQLEN 10
180#define OSPFv3VIRTNBRHELLOSUPPRESSED 11
181#define OSPFv3VIRTNBRIFID 12
182#define OSPFv3VIRTNBRRESTARTHELPERSTATUS 13
183#define OSPFv3VIRTNBRRESTARTHELPERAGE 14
184#define OSPFv3VIRTNBRRESTARTHELPEREXITREASON 15
185
186/* OSPFv3 MIB Area Aggregate Table values: ospfv3AreaAggregateTable */
187#define OSPFv3AREAAGGREGATEROWSTATUS 6
188#define OSPFv3AREAAGGREGATEEFFECT 7
189#define OSPFv3AREAAGGREGATEROUTETAG 8
190
ef1bbf5c 191/* SYNTAX Status from OSPF-MIB. */
192#define OSPF_STATUS_ENABLED 1
193#define OSPF_STATUS_DISABLED 2
194
195/* SNMP value hack. */
196#define COUNTER ASN_COUNTER
197#define INTEGER ASN_INTEGER
198#define GAUGE ASN_GAUGE
0f0ab518 199#define UNSIGNED ASN_UNSIGNED
ef1bbf5c 200#define TIMETICKS ASN_TIMETICKS
201#define IPADDRESS ASN_IPADDRESS
202#define STRING ASN_OCTET_STR
203
204/* For return values e.g. SNMP_INTEGER macro */
205SNMP_LOCAL_VARIABLES
206
ef1bbf5c 207/* OSPFv3-MIB instances. */
d62a17ae 208static oid ospfv3_oid[] = {OSPFv3MIB};
209static oid ospfv3_trap_oid[] = {OSPFv3MIB, 0};
ef1bbf5c 210
ef1bbf5c 211/* Hook functions. */
d7c0a89a
QY
212static uint8_t *ospfv3GeneralGroup(struct variable *, oid *, size_t *, int,
213 size_t *, WriteMethod **);
214static uint8_t *ospfv3AreaEntry(struct variable *, oid *, size_t *, int,
215 size_t *, WriteMethod **);
216static uint8_t *ospfv3WwLsdbEntry(struct variable *, oid *, size_t *, int,
d62a17ae 217 size_t *, WriteMethod **);
d7c0a89a 218static uint8_t *ospfv3NbrEntry(struct variable *, oid *, size_t *, int,
d62a17ae 219 size_t *, WriteMethod **);
d7c0a89a 220static uint8_t *ospfv3IfEntry(struct variable *, oid *, size_t *, int, size_t *,
d62a17ae 221 WriteMethod **);
d62a17ae 222
223static struct variable ospfv3_variables[] = {
224 /* OSPF general variables */
225 {OSPFv3ROUTERID, UNSIGNED, RWRITE, ospfv3GeneralGroup, 3, {1, 1, 1}},
226 {OSPFv3ADMINSTAT, INTEGER, RWRITE, ospfv3GeneralGroup, 3, {1, 1, 2}},
227 {OSPFv3VERSIONNUMBER, INTEGER, RONLY, ospfv3GeneralGroup, 3, {1, 1, 3}},
228 {OSPFv3AREABDRRTRSTATUS,
229 INTEGER,
230 RONLY,
231 ospfv3GeneralGroup,
232 3,
233 {1, 1, 4}},
234 {OSPFv3ASBDRRTRSTATUS,
235 INTEGER,
236 RWRITE,
237 ospfv3GeneralGroup,
238 3,
239 {1, 1, 5}},
240 {OSPFv3ASSCOPELSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup, 3, {1, 1, 6}},
241 {OSPFv3ASSCOPELSACHECKSUMSUM,
242 UNSIGNED,
243 RONLY,
244 ospfv3GeneralGroup,
245 3,
246 {1, 1, 7}},
247 {OSPFv3ORIGINATENEWLSAS,
248 COUNTER,
249 RONLY,
250 ospfv3GeneralGroup,
251 3,
252 {1, 1, 8}},
253 {OSPFv3RXNEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup, 3, {1, 1, 9}},
254 {OSPFv3EXTLSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup, 3, {1, 1, 10}},
255 {OSPFv3EXTAREALSDBLIMIT,
256 INTEGER,
257 RWRITE,
258 ospfv3GeneralGroup,
259 3,
260 {1, 1, 11}},
261 {OSPFv3EXITOVERFLOWINTERVAL,
262 UNSIGNED,
263 RWRITE,
264 ospfv3GeneralGroup,
265 3,
266 {1, 1, 12}},
267 {OSPFv3DEMANDEXTENSIONS,
268 INTEGER,
269 RWRITE,
270 ospfv3GeneralGroup,
271 3,
272 {1, 1, 13}},
273 {OSPFv3REFERENCEBANDWIDTH,
274 UNSIGNED,
275 RWRITE,
276 ospfv3GeneralGroup,
277 3,
278 {1, 1, 14}},
279 {OSPFv3RESTARTSUPPORT,
280 INTEGER,
281 RWRITE,
282 ospfv3GeneralGroup,
283 3,
284 {1, 1, 15}},
285 {OSPFv3RESTARTINTERVAL,
286 UNSIGNED,
287 RWRITE,
288 ospfv3GeneralGroup,
289 3,
290 {1, 1, 16}},
291 {OSPFv3RESTARTSTRICTLSACHECKING,
292 INTEGER,
293 RWRITE,
294 ospfv3GeneralGroup,
295 3,
296 {1, 1, 17}},
297 {OSPFv3RESTARTSTATUS,
298 INTEGER,
299 RONLY,
300 ospfv3GeneralGroup,
301 3,
302 {1, 1, 18}},
303 {OSPFv3RESTARTAGE, UNSIGNED, RONLY, ospfv3GeneralGroup, 3, {1, 1, 19}},
304 {OSPFv3RESTARTEXITREASON,
305 INTEGER,
306 RONLY,
307 ospfv3GeneralGroup,
308 3,
309 {1, 1, 20}},
310 {OSPFv3NOTIFICATIONENABLE,
311 INTEGER,
312 RWRITE,
313 ospfv3GeneralGroup,
314 3,
315 {1, 1, 21}},
316 {OSPFv3STUBROUTERSUPPORT,
317 INTEGER,
318 RONLY,
319 ospfv3GeneralGroup,
320 3,
321 {1, 1, 22}},
322 {OSPFv3STUBROUTERADVERTISEMENT,
323 INTEGER,
324 RWRITE,
325 ospfv3GeneralGroup,
326 3,
327 {1, 1, 23}},
328 {OSPFv3DISCONTINUITYTIME,
329 TIMETICKS,
330 RONLY,
331 ospfv3GeneralGroup,
332 3,
333 {1, 1, 24}},
334 {OSPFv3RESTARTTIME,
335 TIMETICKS,
336 RONLY,
337 ospfv3GeneralGroup,
338 3,
339 {1, 1, 25}},
340
341 /* OSPFv3 Area Data Structure */
342 {OSPFv3IMPORTASEXTERN,
343 INTEGER,
344 RWRITE,
345 ospfv3AreaEntry,
346 4,
347 {1, 2, 1, 2}},
348 {OSPFv3AREASPFRUNS, COUNTER, RONLY, ospfv3AreaEntry, 4, {1, 2, 1, 3}},
349 {OSPFv3AREABDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry, 4, {1, 2, 1, 4}},
350 {OSPFv3AREAASBDRRTRCOUNT,
351 GAUGE,
352 RONLY,
353 ospfv3AreaEntry,
354 4,
355 {1, 2, 1, 5}},
356 {OSPFv3AREASCOPELSACOUNT,
357 GAUGE,
358 RONLY,
359 ospfv3AreaEntry,
360 4,
361 {1, 2, 1, 6}},
362 {OSPFv3AREASCOPELSACKSUMSUM,
363 UNSIGNED,
364 RONLY,
365 ospfv3AreaEntry,
366 4,
367 {1, 2, 1, 7}},
368 {OSPFv3AREASUMMARY, INTEGER, RWRITE, ospfv3AreaEntry, 4, {1, 2, 1, 8}},
369 {OSPFv3AREAROWSTATUS,
370 INTEGER,
371 RWRITE,
372 ospfv3AreaEntry,
373 4,
374 {1, 2, 1, 9}},
375 {OSPFv3AREASTUBMETRIC,
376 INTEGER,
377 RWRITE,
378 ospfv3AreaEntry,
379 4,
380 {1, 2, 1, 10}},
381 {OSPFv3AREANSSATRANSLATORROLE,
382 INTEGER,
383 RWRITE,
384 ospfv3AreaEntry,
385 4,
386 {1, 2, 1, 11}},
387 {OSPFv3AREANSSATRANSLATORSTATE,
388 INTEGER,
389 RONLY,
390 ospfv3AreaEntry,
391 4,
392 {1, 2, 1, 12}},
393 {OSPFv3AREANSSATRANSLATORSTABINTERVAL,
394 UNSIGNED,
395 RWRITE,
396 ospfv3AreaEntry,
397 4,
398 {1, 2, 1, 13}},
399 {OSPFv3AREANSSATRANSLATOREVENTS,
400 COUNTER,
401 RONLY,
402 ospfv3AreaEntry,
403 4,
404 {1, 2, 1, 14}},
405 {OSPFv3AREASTUBMETRICTYPE,
406 INTEGER,
407 RWRITE,
408 ospfv3AreaEntry,
409 4,
410 {1, 2, 1, 15}},
411 {OSPFv3AREATEENABLED,
412 INTEGER,
413 RWRITE,
414 ospfv3AreaEntry,
415 4,
416 {1, 2, 1, 16}},
417
418 /* OSPFv3 AS LSDB */
419 {OSPFv3WWLSDBSEQUENCE | OSPFv3WWASTABLE,
420 INTEGER,
421 RONLY,
422 ospfv3WwLsdbEntry,
423 4,
424 {1, 3, 1, 4}},
425 {OSPFv3WWLSDBAGE | OSPFv3WWASTABLE,
426 UNSIGNED,
427 RONLY,
428 ospfv3WwLsdbEntry,
429 4,
430 {1, 3, 1, 5}},
431 {OSPFv3WWLSDBCHECKSUM | OSPFv3WWASTABLE,
432 INTEGER,
433 RONLY,
434 ospfv3WwLsdbEntry,
435 4,
436 {1, 3, 1, 6}},
437 {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWASTABLE,
438 STRING,
439 RONLY,
440 ospfv3WwLsdbEntry,
441 4,
442 {1, 3, 1, 7}},
443 {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWASTABLE,
444 INTEGER,
445 RONLY,
446 ospfv3WwLsdbEntry,
447 4,
448 {1, 3, 1, 8}},
449
450 /* OSPFv3 Area LSDB */
451 {OSPFv3WWLSDBSEQUENCE | OSPFv3WWAREATABLE,
452 INTEGER,
453 RONLY,
454 ospfv3WwLsdbEntry,
455 4,
456 {1, 4, 1, 5}},
457 {OSPFv3WWLSDBAGE | OSPFv3WWAREATABLE,
458 UNSIGNED,
459 RONLY,
460 ospfv3WwLsdbEntry,
461 4,
462 {1, 4, 1, 6}},
463 {OSPFv3WWLSDBCHECKSUM | OSPFv3WWAREATABLE,
464 INTEGER,
465 RONLY,
466 ospfv3WwLsdbEntry,
467 4,
468 {1, 4, 1, 7}},
469 {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWAREATABLE,
470 STRING,
471 RONLY,
472 ospfv3WwLsdbEntry,
473 4,
474 {1, 4, 1, 8}},
475 {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWAREATABLE,
476 INTEGER,
477 RONLY,
478 ospfv3WwLsdbEntry,
479 4,
480 {1, 4, 1, 9}},
481
482 /* OSPFv3 Link LSDB */
483 {OSPFv3WWLSDBSEQUENCE | OSPFv3WWLINKTABLE,
484 INTEGER,
485 RONLY,
486 ospfv3WwLsdbEntry,
487 4,
488 {1, 5, 1, 6}},
489 {OSPFv3WWLSDBAGE | OSPFv3WWLINKTABLE,
490 UNSIGNED,
491 RONLY,
492 ospfv3WwLsdbEntry,
493 4,
494 {1, 5, 1, 7}},
495 {OSPFv3WWLSDBCHECKSUM | OSPFv3WWLINKTABLE,
496 INTEGER,
497 RONLY,
498 ospfv3WwLsdbEntry,
499 4,
500 {1, 5, 1, 8}},
501 {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWLINKTABLE,
502 STRING,
503 RONLY,
504 ospfv3WwLsdbEntry,
505 4,
506 {1, 5, 1, 9}},
507 {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWLINKTABLE,
508 INTEGER,
509 RONLY,
510 ospfv3WwLsdbEntry,
511 4,
512 {1, 5, 1, 10}},
513
514 /* OSPFv3 interfaces */
515 {OSPFv3IFAREAID, UNSIGNED, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 3}},
516 {OSPFv3IFTYPE, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 4}},
517 {OSPFv3IFADMINSTATUS, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 5}},
518 {OSPFv3IFRTRPRIORITY, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 6}},
519 {OSPFv3IFTRANSITDELAY, UNSIGNED, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 7}},
520 {OSPFv3IFRETRANSINTERVAL,
521 UNSIGNED,
522 RONLY,
523 ospfv3IfEntry,
524 4,
525 {1, 7, 1, 8}},
526 {OSPFv3IFHELLOINTERVAL, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 9}},
527 {OSPFv3IFRTRDEADINTERVAL,
528 UNSIGNED,
529 RONLY,
530 ospfv3IfEntry,
531 4,
532 {1, 7, 1, 10}},
533 {OSPFv3IFPOLLINTERVAL,
534 UNSIGNED,
535 RONLY,
536 ospfv3IfEntry,
537 4,
538 {1, 7, 1, 11}},
539 {OSPFv3IFSTATE, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 12}},
540 {OSPFv3IFDESIGNATEDROUTER,
541 UNSIGNED,
542 RONLY,
543 ospfv3IfEntry,
544 4,
545 {1, 7, 1, 13}},
546 {OSPFv3IFBACKUPDESIGNATEDROUTER,
547 UNSIGNED,
548 RONLY,
549 ospfv3IfEntry,
550 4,
551 {1, 7, 1, 14}},
552 {OSPFv3IFEVENTS, COUNTER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 15}},
553 {OSPFv3IFROWSTATUS, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 16}},
554 {OSPFv3IFDEMAND, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 17}},
555 {OSPFv3IFMETRICVALUE, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 18}},
556 {OSPFv3IFLINKSCOPELSACOUNT,
557 GAUGE,
558 RONLY,
559 ospfv3IfEntry,
560 4,
561 {1, 7, 1, 19}},
562 {OSPFv3IFLINKLSACKSUMSUM,
563 UNSIGNED,
564 RONLY,
565 ospfv3IfEntry,
566 4,
567 {1, 7, 1, 20}},
568 {OSPFv3IFDEMANDNBRPROBE,
569 INTEGER,
570 RONLY,
571 ospfv3IfEntry,
572 4,
573 {1, 7, 1, 21}},
574 {OSPFv3IFDEMANDNBRPROBERETRANSLIMIT,
575 UNSIGNED,
576 RONLY,
577 ospfv3IfEntry,
578 4,
579 {1, 7, 1, 22}},
580 {OSPFv3IFDEMANDNBRPROBEINTERVAL,
581 UNSIGNED,
582 RONLY,
583 ospfv3IfEntry,
584 4,
585 {1, 7, 1, 23}},
586 {OSPFv3IFTEDISABLED, INTEGER, RONLY, ospfv3IfEntry, 4, {1, 7, 1, 24}},
587 {OSPFv3IFLINKLSASUPPRESSION,
588 INTEGER,
589 RONLY,
590 ospfv3IfEntry,
591 4,
592 {1, 7, 1, 25}},
593
594 /* OSPFv3 neighbors */
595 {OSPFv3NBRADDRESSTYPE, INTEGER, RONLY, ospfv3NbrEntry, 4, {1, 9, 1, 4}},
596 {OSPFv3NBRADDRESS, STRING, RONLY, ospfv3NbrEntry, 4, {1, 9, 1, 5}},
597 {OSPFv3NBROPTIONS, INTEGER, RONLY, ospfv3NbrEntry, 4, {1, 9, 1, 6}},
598 {OSPFv3NBRPRIORITY, INTEGER, RONLY, ospfv3NbrEntry, 4, {1, 9, 1, 7}},
599 {OSPFv3NBRSTATE, INTEGER, RONLY, ospfv3NbrEntry, 4, {1, 9, 1, 8}},
600 {OSPFv3NBREVENTS, COUNTER, RONLY, ospfv3NbrEntry, 4, {1, 9, 1, 9}},
601 {OSPFv3NBRLSRETRANSQLEN,
602 GAUGE,
603 RONLY,
604 ospfv3NbrEntry,
605 4,
606 {1, 9, 1, 10}},
607 {OSPFv3NBRHELLOSUPPRESSED,
608 INTEGER,
609 RONLY,
610 ospfv3NbrEntry,
611 4,
612 {1, 9, 1, 11}},
613 {OSPFv3NBRIFID, INTEGER, RONLY, ospfv3NbrEntry, 4, {1, 9, 1, 12}},
614 {OSPFv3NBRRESTARTHELPERSTATUS,
615 INTEGER,
616 RONLY,
617 ospfv3NbrEntry,
618 4,
619 {1, 9, 1, 13}},
620 {OSPFv3NBRRESTARTHELPERAGE,
621 UNSIGNED,
622 RONLY,
623 ospfv3NbrEntry,
624 4,
625 {1, 9, 1, 14}},
626 {OSPFv3NBRRESTARTHELPEREXITREASON,
627 INTEGER,
628 RONLY,
629 ospfv3NbrEntry,
630 4,
631 {1, 9, 1, 15}},
ef1bbf5c 632};
633
d7c0a89a
QY
634static uint8_t *ospfv3GeneralGroup(struct variable *v, oid *name,
635 size_t *length, int exact, size_t *var_len,
636 WriteMethod **write_method)
ef1bbf5c 637{
d7c0a89a
QY
638 uint16_t sum;
639 uint32_t count;
2e37407f 640 struct ospf6_lsa *lsa = NULL, *lsanext;
beadc736 641 struct ospf6 *ospf6;
d62a17ae 642
beadc736 643 ospf6 = ospf6_lookup_by_vrf_id(VRF_DEFAULT);
d62a17ae 644 /* Check whether the instance identifier is valid */
645 if (smux_header_generic(v, name, length, exact, var_len, write_method)
646 == MATCH_FAILED)
647 return NULL;
648
649 /* Return the current value of the variable */
650 switch (v->magic) {
651 case OSPFv3ROUTERID:
652 /* Router-ID of this OSPF instance. */
653 if (ospf6)
654 return SNMP_INTEGER(ntohl(ospf6->router_id));
655 return SNMP_INTEGER(0);
656 case OSPFv3ADMINSTAT:
657 if (ospf6)
658 return SNMP_INTEGER(
659 CHECK_FLAG(ospf6->flag, OSPF6_DISABLED)
660 ? OSPF_STATUS_DISABLED
661 : OSPF_STATUS_ENABLED);
662 return SNMP_INTEGER(OSPF_STATUS_DISABLED);
663 case OSPFv3VERSIONNUMBER:
664 return SNMP_INTEGER(3);
665 case OSPFv3AREABDRRTRSTATUS:
666 if (ospf6)
667 return SNMP_INTEGER(ospf6_is_router_abr(ospf6)
668 ? SNMP_TRUE
669 : SNMP_FALSE);
670 return SNMP_INTEGER(SNMP_FALSE);
671 case OSPFv3ASBDRRTRSTATUS:
672 if (ospf6)
673 return SNMP_INTEGER(ospf6_asbr_is_asbr(ospf6)
674 ? SNMP_TRUE
675 : SNMP_FALSE);
676 return SNMP_INTEGER(SNMP_FALSE);
677 case OSPFv3ASSCOPELSACOUNT:
678 if (ospf6)
679 return SNMP_INTEGER(ospf6->lsdb->count);
680 return SNMP_INTEGER(0);
681 case OSPFv3ASSCOPELSACHECKSUMSUM:
682 if (ospf6) {
683 sum = 0;
2e37407f 684 for (ALL_LSDB(ospf6->lsdb, lsa, lsanext))
d62a17ae 685 sum += ntohs(lsa->header->checksum);
686 return SNMP_INTEGER(sum);
687 }
688 return SNMP_INTEGER(0);
689 case OSPFv3ORIGINATENEWLSAS:
690 return SNMP_INTEGER(
691 0); /* Don't know where to get this value... */
692 case OSPFv3RXNEWLSAS:
693 return SNMP_INTEGER(
694 0); /* Don't know where to get this value... */
695 case OSPFv3EXTLSACOUNT:
696 if (ospf6) {
697 count = 0;
698 for (ALL_LSDB_TYPED(ospf6->lsdb,
699 htons(OSPF6_LSTYPE_AS_EXTERNAL),
700 lsa))
701 count += 1;
702 return SNMP_INTEGER(count);
703 }
704 return SNMP_INTEGER(0);
705 case OSPFv3EXTAREALSDBLIMIT:
706 return SNMP_INTEGER(-1);
707 case OSPFv3EXITOVERFLOWINTERVAL:
708 return SNMP_INTEGER(0); /* Not supported */
709 case OSPFv3DEMANDEXTENSIONS:
710 return SNMP_INTEGER(0); /* Not supported */
711 case OSPFv3REFERENCEBANDWIDTH:
712 if (ospf6)
713 return SNMP_INTEGER(ospf6->ref_bandwidth);
714 /* Otherwise, like for "not implemented". */
715 /* fallthru */
716 case OSPFv3RESTARTSUPPORT:
717 case OSPFv3RESTARTINTERVAL:
718 case OSPFv3RESTARTSTRICTLSACHECKING:
719 case OSPFv3RESTARTSTATUS:
720 case OSPFv3RESTARTAGE:
721 case OSPFv3RESTARTEXITREASON:
722 case OSPFv3NOTIFICATIONENABLE:
723 case OSPFv3STUBROUTERSUPPORT:
724 case OSPFv3STUBROUTERADVERTISEMENT:
725 case OSPFv3DISCONTINUITYTIME:
726 case OSPFv3RESTARTTIME:
727 /* TODO: Not implemented */
728 return NULL;
729 }
730 return NULL;
ef1bbf5c 731}
732
d7c0a89a
QY
733static uint8_t *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length,
734 int exact, size_t *var_len,
735 WriteMethod **write_method)
ef1bbf5c 736{
d62a17ae 737 struct ospf6_area *oa, *area = NULL;
2e37407f 738 struct ospf6_lsa *lsa = NULL, *lsanext;
d7c0a89a
QY
739 uint32_t area_id = 0;
740 uint32_t count;
741 uint16_t sum;
d62a17ae 742 struct listnode *node;
743 unsigned int len;
744 char a[16];
745 struct ospf6_route *ro;
beadc736 746 struct ospf6 *ospf6;
747
748 ospf6 = ospf6_lookup_by_vrf_id(VRF_DEFAULT);
d62a17ae 749
750 if (ospf6 == NULL)
751 return NULL;
752
753 if (smux_header_table(v, name, length, exact, var_len, write_method)
754 == MATCH_FAILED)
755 return NULL;
756
757 len = *length - v->namelen;
758 len = (len >= 1 ? 1 : 0);
759 if (exact && len != 1)
760 return NULL;
761 if (len)
762 area_id = htonl(name[v->namelen]);
763
764 inet_ntop(AF_INET, &area_id, a, sizeof(a));
765 zlog_debug("SNMP access by area: %s, exact=%d len=%d length=%lu", a,
d7c0a89a 766 exact, len, (unsigned long)*length);
d62a17ae 767
768 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) {
769 if (area == NULL) {
770 if (len == 0) /* return first area entry */
771 area = oa;
772 else if (exact && ntohl(oa->area_id) == ntohl(area_id))
773 area = oa;
774 else if (ntohl(oa->area_id) > ntohl(area_id))
775 area = oa;
776 }
777 }
778
779 if (area == NULL)
780 return NULL;
781
782 *length = v->namelen + 1;
783 name[v->namelen] = ntohl(area->area_id);
784
785 inet_ntop(AF_INET, &area->area_id, a, sizeof(a));
786 zlog_debug("SNMP found area: %s, exact=%d len=%d length=%lu", a, exact,
d7c0a89a 787 len, (unsigned long)*length);
d62a17ae 788
789 switch (v->magic) {
790 case OSPFv3IMPORTASEXTERN:
791 /* No NSSA support */
792 return SNMP_INTEGER(IS_AREA_STUB(area) ? 2 : 1);
793 case OSPFv3AREASPFRUNS:
794 return SNMP_INTEGER(area->spf_calculation);
795 case OSPFv3AREABDRRTRCOUNT:
796 case OSPFv3AREAASBDRRTRCOUNT:
797 count = 0;
798 for (ro = ospf6_route_head(ospf6->brouter_table); ro;
799 ro = ospf6_route_next(ro)) {
800 if (ntohl(ro->path.area_id) != ntohl(area->area_id))
801 continue;
802 if (v->magic == OSPFv3AREABDRRTRCOUNT
803 && CHECK_FLAG(ro->path.router_bits,
804 OSPF6_ROUTER_BIT_B))
805 count++;
806 if (v->magic == OSPFv3AREAASBDRRTRCOUNT
807 && CHECK_FLAG(ro->path.router_bits,
808 OSPF6_ROUTER_BIT_E))
809 count++;
810 }
811 return SNMP_INTEGER(count);
812 case OSPFv3AREASCOPELSACOUNT:
813 return SNMP_INTEGER(area->lsdb->count);
814 case OSPFv3AREASCOPELSACKSUMSUM:
815 sum = 0;
2e37407f 816 for (ALL_LSDB(area->lsdb, lsa, lsanext))
d62a17ae 817 sum += ntohs(lsa->header->checksum);
818 return SNMP_INTEGER(sum);
819 case OSPFv3AREASUMMARY:
820 return SNMP_INTEGER(2); /* sendAreaSummary */
821 case OSPFv3AREAROWSTATUS:
822 return SNMP_INTEGER(1); /* Active */
823 case OSPFv3AREASTUBMETRIC:
824 case OSPFv3AREANSSATRANSLATORROLE:
825 case OSPFv3AREANSSATRANSLATORSTATE:
826 case OSPFv3AREANSSATRANSLATORSTABINTERVAL:
827 case OSPFv3AREANSSATRANSLATOREVENTS:
828 case OSPFv3AREASTUBMETRICTYPE:
829 case OSPFv3AREATEENABLED:
830 /* Not implemented. */
831 return NULL;
832 }
833 return NULL;
ef1bbf5c 834}
835
d62a17ae 836static int if_icmp_func(struct interface *ifp1, struct interface *ifp2)
c349bb86 837{
d62a17ae 838 return (ifp1->ifindex - ifp2->ifindex);
c349bb86
VB
839}
840
d7c0a89a
QY
841static uint8_t *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length,
842 int exact, size_t *var_len,
843 WriteMethod **write_method)
2680aa2b 844{
c5d28568 845 struct vrf *vrf;
d62a17ae 846 struct ospf6_lsa *lsa = NULL;
847 ifindex_t ifindex;
848 uint32_t area_id, id, instid, adv_router;
d7c0a89a 849 uint16_t type;
d62a17ae 850 int len;
851 oid *offset;
852 int offsetlen;
853 struct ospf6_area *oa = NULL;
854 struct listnode *node;
855 struct interface *iif;
856 struct ospf6_interface *oi = NULL;
857 struct list *ifslist;
beadc736 858 struct ospf6 *ospf6;
859
860 ospf6 = ospf6_lookup_by_vrf_id(VRF_DEFAULT);
d62a17ae 861
862 if (smux_header_table(v, name, length, exact, var_len, write_method)
863 == MATCH_FAILED)
864 return NULL;
865
866 instid = ifindex = area_id = type = id = adv_router = 0;
867
868 /* Check OSPFv3 instance. */
869 if (ospf6 == NULL)
870 return NULL;
871
c5d28568 872 vrf = vrf_lookup_by_id(ospf6->vrf_id);
d62a17ae 873 /* Get variable length. */
874 offset = name + v->namelen;
875 offsetlen = *length - v->namelen;
876
877 if (exact && (v->magic & OSPFv3WWASTABLE) && offsetlen != 3)
878 return NULL;
879 if (exact && (v->magic & OSPFv3WWAREATABLE) && offsetlen != 4)
880 return NULL;
881 if (exact && (v->magic & OSPFv3WWLINKTABLE) && offsetlen != 5)
882 return NULL;
883
884 if (v->magic & OSPFv3WWLINKTABLE) {
885 /* Parse ifindex */
886 len = (offsetlen < 1 ? 0 : 1);
887 if (len)
888 ifindex = *offset;
889 offset += len;
890 offsetlen -= len;
891
892 /* Parse instance ID */
893 len = (offsetlen < 1 ? 0 : 1);
894 if (len)
895 instid = *offset;
896 offset += len;
897 offsetlen -= len;
898 } else if (v->magic & OSPFv3WWAREATABLE) {
899 /* Parse area-id */
900 len = (offsetlen < 1 ? 0 : 1);
901 if (len)
902 area_id = htonl(*offset);
903 offset += len;
904 offsetlen -= len;
c349bb86 905 }
d62a17ae 906
907 /* Parse type */
908 len = (offsetlen < 1 ? 0 : 1);
909 if (len)
910 type = htons(*offset);
911 offset += len;
912 offsetlen -= len;
913
914 /* Parse Router-ID */
915 len = (offsetlen < 1 ? 0 : 1);
916 if (len)
917 adv_router = htonl(*offset);
918 offset += len;
919 offsetlen -= len;
920
921 /* Parse LS-ID */
922 len = (offsetlen < 1 ? 0 : 1);
923 if (len)
924 id = htonl(*offset);
925 offset += len;
996c9314 926 // offsetlen -= len; // Add back in if we need it again
d62a17ae 927
928 if (exact) {
929 if (v->magic & OSPFv3WWASTABLE) {
930 lsa = ospf6_lsdb_lookup(type, id, adv_router,
931 ospf6->lsdb);
932 } else if (v->magic & OSPFv3WWAREATABLE) {
933 oa = ospf6_area_lookup(area_id, ospf6);
934 if (!oa)
935 return NULL;
936 lsa = ospf6_lsdb_lookup(type, id, adv_router, oa->lsdb);
937 } else if (v->magic & OSPFv3WWLINKTABLE) {
c5d28568
K
938 oi = ospf6_interface_lookup_by_ifindex(ifindex,
939 ospf6->vrf_id);
d62a17ae 940 if (!oi || oi->instance_id != instid)
941 return NULL;
942 lsa = ospf6_lsdb_lookup(type, id, adv_router, oi->lsdb);
943 }
944 } else {
945 if (v->magic & OSPFv3WWASTABLE) {
946 if (ospf6->lsdb->count)
947 lsa = ospf6_lsdb_lookup_next(
948 type, id, adv_router, ospf6->lsdb);
949 } else if (v->magic & OSPFv3WWAREATABLE)
950 for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) {
951 if (oa->area_id < area_id)
952 continue;
953
954 if (oa->lsdb->count)
955 lsa = ospf6_lsdb_lookup_next(
956 type, id, adv_router, oa->lsdb);
957 if (lsa)
958 break;
959 type = 0;
960 id = 0;
961 adv_router = 0;
962 }
963 else if (v->magic & OSPFv3WWLINKTABLE) {
964 /* We build a sorted list of interfaces */
965 ifslist = list_new();
966 if (!ifslist)
967 return NULL;
968 ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
451fda4f 969 FOR_ALL_INTERFACES (vrf, iif)
d62a17ae 970 listnode_add_sort(ifslist, iif);
971
972 for (ALL_LIST_ELEMENTS_RO(ifslist, node, iif)) {
973 if (!iif->ifindex)
974 continue;
975 oi = ospf6_interface_lookup_by_ifindex(
c5d28568 976 iif->ifindex, iif->vrf_id);
d62a17ae 977 if (!oi)
978 continue;
979 if (iif->ifindex < ifindex)
980 continue;
981 if (oi->instance_id < instid)
982 continue;
983
984 if (oi->lsdb->count)
985 lsa = ospf6_lsdb_lookup_next(
986 type, id, adv_router, oi->lsdb);
987 if (lsa)
988 break;
989 type = 0;
990 id = 0;
991 adv_router = 0;
992 oi = NULL;
993 }
994
995 list_delete_all_node(ifslist);
996 }
997 }
998
999 if (!lsa)
1000 return NULL;
1001
1002 /* Add indexes */
1003 if (v->magic & OSPFv3WWASTABLE) {
1004 *length = v->namelen + 3;
1005 offset = name + v->namelen;
1006 } else if (v->magic & OSPFv3WWAREATABLE) {
1007 *length = v->namelen + 4;
1008 offset = name + v->namelen;
1009 *offset = ntohl(oa->area_id);
1010 offset++;
1011 } else if (v->magic & OSPFv3WWLINKTABLE) {
1012 *length = v->namelen + 5;
1013 offset = name + v->namelen;
1014 *offset = oi->interface->ifindex;
1015 offset++;
1016 *offset = oi->instance_id;
1017 offset++;
1018 }
1019 *offset = ntohs(lsa->header->type);
1020 offset++;
1021 *offset = ntohl(lsa->header->adv_router);
1022 offset++;
1023 *offset = ntohl(lsa->header->id);
1024 offset++;
1025
1026 /* Return the current value of the variable */
1027 switch (v->magic & OSPFv3WWCOLUMN) {
1028 case OSPFv3WWLSDBSEQUENCE:
1029 return SNMP_INTEGER(ntohl(lsa->header->seqnum));
d62a17ae 1030 case OSPFv3WWLSDBAGE:
1031 ospf6_lsa_age_current(lsa);
1032 return SNMP_INTEGER(ntohs(lsa->header->age));
d62a17ae 1033 case OSPFv3WWLSDBCHECKSUM:
1034 return SNMP_INTEGER(ntohs(lsa->header->checksum));
d62a17ae 1035 case OSPFv3WWLSDBADVERTISEMENT:
1036 *var_len = ntohs(lsa->header->length);
d7c0a89a 1037 return (uint8_t *)lsa->header;
d62a17ae 1038 case OSPFv3WWLSDBTYPEKNOWN:
1039 return SNMP_INTEGER(OSPF6_LSA_IS_KNOWN(lsa->header->type)
1040 ? SNMP_TRUE
1041 : SNMP_FALSE);
1042 break;
1043 }
1044 return NULL;
2680aa2b 1045}
1046
d7c0a89a
QY
1047static uint8_t *ospfv3IfEntry(struct variable *v, oid *name, size_t *length,
1048 int exact, size_t *var_len,
1049 WriteMethod **write_method)
3bc4f84e 1050{
c5d28568 1051 struct vrf *vrf;
d62a17ae 1052 ifindex_t ifindex = 0;
1053 unsigned int instid = 0;
1054 struct ospf6_interface *oi = NULL;
2e37407f 1055 struct ospf6_lsa *lsa = NULL, *lsanext;
d62a17ae 1056 struct interface *iif;
1057 struct listnode *i;
1058 struct list *ifslist;
1059 oid *offset;
1060 int offsetlen, len;
d7c0a89a 1061 uint32_t sum;
beadc736 1062 struct ospf6 *ospf6;
1063
1064 ospf6 = ospf6_lookup_by_vrf_id(VRF_DEFAULT);
d62a17ae 1065
1066 if (smux_header_table(v, name, length, exact, var_len, write_method)
1067 == MATCH_FAILED)
1068 return NULL;
1069
1070 /* Check OSPFv3 instance. */
1071 if (ospf6 == NULL)
1072 return NULL;
1073
c5d28568 1074 vrf = vrf_lookup_by_id(ospf6->vrf_id);
d62a17ae 1075 /* Get variable length. */
1076 offset = name + v->namelen;
1077 offsetlen = *length - v->namelen;
1078
1079 if (exact && offsetlen != 2)
1080 return NULL;
1081
1082 /* Parse if index */
1083 len = (offsetlen < 1 ? 0 : 1);
1084 if (len)
1085 ifindex = *offset;
1086 offset += len;
1087 offsetlen -= len;
1088
1089 /* Parse instance ID */
1090 len = (offsetlen < 1 ? 0 : 1);
1091 if (len)
1092 instid = *offset;
996c9314
LB
1093 // offset += len; // Add back in if we ever start using again
1094 // offsetlen -= len;
d62a17ae 1095
1096 if (exact) {
c5d28568 1097 oi = ospf6_interface_lookup_by_ifindex(ifindex, ospf6->vrf_id);
d62a17ae 1098 if (!oi || oi->instance_id != instid)
1099 return NULL;
1100 } else {
1101 /* We build a sorted list of interfaces */
1102 ifslist = list_new();
1103 if (!ifslist)
1104 return NULL;
1105 ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
451fda4f 1106 FOR_ALL_INTERFACES (vrf, iif)
d62a17ae 1107 listnode_add_sort(ifslist, iif);
1108
1109 for (ALL_LIST_ELEMENTS_RO(ifslist, i, iif)) {
1110 if (!iif->ifindex)
1111 continue;
c5d28568
K
1112 oi = ospf6_interface_lookup_by_ifindex(iif->ifindex,
1113 iif->vrf_id);
d62a17ae 1114 if (!oi)
1115 continue;
1116 if (iif->ifindex > ifindex
1117 || (iif->ifindex == ifindex
1118 && (oi->instance_id > instid)))
1119 break;
1120 oi = NULL;
1121 }
1122
1123 list_delete_all_node(ifslist);
1124 }
1125
1126 if (!oi)
1127 return NULL;
1128
1129 /* Add Index (IfIndex, IfInstId) */
1130 *length = v->namelen + 2;
1131 offset = name + v->namelen;
1132 *offset = oi->interface->ifindex;
1133 offset++;
1134 *offset = oi->instance_id;
1135 offset++;
1136
1137 /* Return the current value of the variable */
1138 switch (v->magic) {
1139 case OSPFv3IFAREAID:
1140 if (oi->area)
1141 return SNMP_INTEGER(ntohl(oi->area->area_id));
1142 break;
1143 case OSPFv3IFTYPE:
e5973353 1144 if (oi->type == OSPF_IFTYPE_BROADCAST)
d62a17ae 1145 return SNMP_INTEGER(1);
e5973353 1146 else if (oi->type == OSPF_IFTYPE_POINTOPOINT)
d62a17ae 1147 return SNMP_INTEGER(3);
1148 else
1149 break; /* Unknown, don't put anything */
1150 case OSPFv3IFADMINSTATUS:
1151 if (oi->area)
1152 return SNMP_INTEGER(OSPF_STATUS_ENABLED);
1153 return SNMP_INTEGER(OSPF_STATUS_DISABLED);
1154 case OSPFv3IFRTRPRIORITY:
1155 return SNMP_INTEGER(oi->priority);
1156 case OSPFv3IFTRANSITDELAY:
1157 return SNMP_INTEGER(oi->transdelay);
1158 case OSPFv3IFRETRANSINTERVAL:
1159 return SNMP_INTEGER(oi->rxmt_interval);
1160 case OSPFv3IFHELLOINTERVAL:
1161 return SNMP_INTEGER(oi->hello_interval);
1162 case OSPFv3IFRTRDEADINTERVAL:
1163 return SNMP_INTEGER(oi->dead_interval);
1164 case OSPFv3IFPOLLINTERVAL:
1165 /* No support for NBMA */
1166 break;
1167 case OSPFv3IFSTATE:
1168 return SNMP_INTEGER(oi->state);
1169 case OSPFv3IFDESIGNATEDROUTER:
1170 return SNMP_INTEGER(ntohl(oi->drouter));
1171 case OSPFv3IFBACKUPDESIGNATEDROUTER:
1172 return SNMP_INTEGER(ntohl(oi->bdrouter));
1173 case OSPFv3IFEVENTS:
1174 return SNMP_INTEGER(oi->state_change);
1175 case OSPFv3IFROWSTATUS:
1176 return SNMP_INTEGER(1);
1177 case OSPFv3IFDEMAND:
1178 return SNMP_INTEGER(SNMP_FALSE);
1179 case OSPFv3IFMETRICVALUE:
1180 return SNMP_INTEGER(oi->cost);
1181 case OSPFv3IFLINKSCOPELSACOUNT:
1182 return SNMP_INTEGER(oi->lsdb->count);
1183 case OSPFv3IFLINKLSACKSUMSUM:
1184 sum = 0;
2e37407f 1185 for (ALL_LSDB(oi->lsdb, lsa, lsanext))
d62a17ae 1186 sum += ntohs(lsa->header->checksum);
1187 return SNMP_INTEGER(sum);
1188 case OSPFv3IFDEMANDNBRPROBE:
1189 case OSPFv3IFDEMANDNBRPROBERETRANSLIMIT:
1190 case OSPFv3IFDEMANDNBRPROBEINTERVAL:
1191 case OSPFv3IFTEDISABLED:
1192 case OSPFv3IFLINKLSASUPPRESSION:
1193 /* Not implemented. Only works if all the last ones are not
1194 implemented! */
1195 return NULL;
1196 }
1197
1198 /* Try an internal getnext. Some columns are missing in this table. */
1199 if (!exact && (name[*length - 1] < MAX_SUBID))
1200 return ospfv3IfEntry(v, name, length, exact, var_len,
1201 write_method);
1202 return NULL;
3bc4f84e
VB
1203}
1204
d7c0a89a
QY
1205static uint8_t *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length,
1206 int exact, size_t *var_len,
1207 WriteMethod **write_method)
061bc735 1208{
c5d28568 1209 struct vrf *vrf;
d62a17ae 1210 ifindex_t ifindex = 0;
1211 unsigned int instid, rtrid;
1212 struct ospf6_interface *oi = NULL;
1213 struct ospf6_neighbor *on = NULL;
1214 struct interface *iif;
1215 struct listnode *i, *j;
1216 struct list *ifslist;
1217 oid *offset;
1218 int offsetlen, len;
beadc736 1219 struct ospf6 *ospf6;
1220
1221 ospf6 = ospf6_lookup_by_vrf_id(VRF_DEFAULT);
d62a17ae 1222
1223 if (smux_header_table(v, name, length, exact, var_len, write_method)
1224 == MATCH_FAILED)
1225 return NULL;
1226
1227 instid = rtrid = 0;
1228
1229 /* Check OSPFv3 instance. */
1230 if (ospf6 == NULL)
1231 return NULL;
1232
c5d28568 1233 vrf = vrf_lookup_by_id(ospf6->vrf_id);
d62a17ae 1234 /* Get variable length. */
1235 offset = name + v->namelen;
1236 offsetlen = *length - v->namelen;
1237
1238 if (exact && offsetlen != 3)
1239 return NULL;
1240
1241 /* Parse if index */
1242 len = (offsetlen < 1 ? 0 : 1);
1243 if (len)
1244 ifindex = *offset;
1245 offset += len;
1246 offsetlen -= len;
1247
1248 /* Parse instance ID */
1249 len = (offsetlen < 1 ? 0 : 1);
1250 if (len)
1251 instid = *offset;
1252 offset += len;
1253 offsetlen -= len;
1254
1255 /* Parse router ID */
1256 len = (offsetlen < 1 ? 0 : 1);
1257 if (len)
1258 rtrid = htonl(*offset);
996c9314
LB
1259 // offset += len; // Add back in if we ever start looking at data
1260 // offsetlen -= len;
d62a17ae 1261
1262 if (exact) {
c5d28568 1263 oi = ospf6_interface_lookup_by_ifindex(ifindex, ospf6->vrf_id);
d62a17ae 1264 if (!oi || oi->instance_id != instid)
1265 return NULL;
1266 on = ospf6_neighbor_lookup(rtrid, oi);
1267 } else {
1268 /* We build a sorted list of interfaces */
1269 ifslist = list_new();
1270 if (!ifslist)
1271 return NULL;
1272 ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
451fda4f 1273 FOR_ALL_INTERFACES (vrf, iif)
d62a17ae 1274 listnode_add_sort(ifslist, iif);
1275
1276 for (ALL_LIST_ELEMENTS_RO(ifslist, i, iif)) {
1277 if (!iif->ifindex)
1278 continue;
c5d28568
K
1279 oi = ospf6_interface_lookup_by_ifindex(iif->ifindex,
1280 iif->vrf_id);
d62a17ae 1281 if (!oi)
1282 continue;
1283 for (ALL_LIST_ELEMENTS_RO(oi->neighbor_list, j, on)) {
1284 if (iif->ifindex > ifindex
1285 || (iif->ifindex == ifindex
1286 && (oi->instance_id > instid
1287 || (oi->instance_id == instid
1288 && ntohl(on->router_id)
1289 > ntohl(rtrid)))))
1290 break;
1291 }
1292 if (on)
1293 break;
1294 oi = NULL;
1295 on = NULL;
1296 }
1297
1298 list_delete_all_node(ifslist);
1299 }
1300
1301 if (!oi || !on)
1302 return NULL;
1303
1304 /* Add Index (IfIndex, IfInstId, RtrId) */
1305 *length = v->namelen + 3;
1306 offset = name + v->namelen;
1307 *offset = oi->interface->ifindex;
1308 offset++;
1309 *offset = oi->instance_id;
1310 offset++;
1311 *offset = ntohl(on->router_id);
1312 offset++;
1313
1314 /* Return the current value of the variable */
1315 switch (v->magic) {
1316 case OSPFv3NBRADDRESSTYPE:
1317 return SNMP_INTEGER(2); /* IPv6 only */
1318 case OSPFv3NBRADDRESS:
1319 *var_len = sizeof(struct in6_addr);
d7c0a89a 1320 return (uint8_t *)&on->linklocal_addr;
d62a17ae 1321 case OSPFv3NBROPTIONS:
1322 return SNMP_INTEGER(on->options[2]);
1323 case OSPFv3NBRPRIORITY:
1324 return SNMP_INTEGER(on->priority);
1325 case OSPFv3NBRSTATE:
1326 return SNMP_INTEGER(on->state);
1327 case OSPFv3NBREVENTS:
1328 return SNMP_INTEGER(on->state_change);
1329 case OSPFv3NBRLSRETRANSQLEN:
1330 return SNMP_INTEGER(on->retrans_list->count);
1331 case OSPFv3NBRHELLOSUPPRESSED:
1332 return SNMP_INTEGER(SNMP_FALSE);
1333 case OSPFv3NBRIFID:
1334 return SNMP_INTEGER(on->ifindex);
1335 case OSPFv3NBRRESTARTHELPERSTATUS:
1336 case OSPFv3NBRRESTARTHELPERAGE:
1337 case OSPFv3NBRRESTARTHELPEREXITREASON:
1338 /* Not implemented. Only works if all the last ones are not
1339 implemented! */
1340 return NULL;
1341 }
1342
1343 return NULL;
061bc735
VB
1344}
1345
bf836661
VB
1346/* OSPF Traps. */
1347#define NBRSTATECHANGE 2
1348#define IFSTATECHANGE 10
1349
d62a17ae 1350static struct trap_object ospf6NbrTrapList[] = {
1351 {-3, {1, 1, OSPFv3ROUTERID}},
1352 {4, {1, 9, 1, OSPFv3NBRADDRESSTYPE}},
1353 {4, {1, 9, 1, OSPFv3NBRADDRESS}},
1354 {4, {1, 9, 1, OSPFv3NBRSTATE}}};
bf836661 1355
d62a17ae 1356static struct trap_object ospf6IfTrapList[] = {
1357 {-3, {1, 1, OSPFv3ROUTERID}},
1358 {4, {1, 7, 1, OSPFv3IFSTATE}},
1359 {4, {1, 7, 1, OSPFv3IFADMINSTATUS}},
1360 {4, {1, 7, 1, OSPFv3IFAREAID}}};
bf836661 1361
d62a17ae 1362static int ospf6TrapNbrStateChange(struct ospf6_neighbor *on, int next_state,
1363 int prev_state)
bf836661 1364{
d62a17ae 1365 oid index[3];
1366
1367 /* Terminal state or regression */
1368 if ((next_state != OSPF6_NEIGHBOR_FULL)
1369 && (next_state != OSPF6_NEIGHBOR_TWOWAY)
1370 && (next_state >= prev_state))
1371 return 0;
1372
1373 index[0] = on->ospf6_if->interface->ifindex;
1374 index[1] = on->ospf6_if->instance_id;
1375 index[2] = ntohl(on->router_id);
1376
97b5d752
QY
1377 smux_trap(ospfv3_variables, array_size(ospfv3_variables),
1378 ospfv3_trap_oid, array_size(ospfv3_trap_oid), ospfv3_oid,
0d6f7fd6 1379 sizeof(ospfv3_oid) / sizeof(oid), index, 3, ospf6NbrTrapList,
97b5d752 1380 array_size(ospf6NbrTrapList), NBRSTATECHANGE);
d62a17ae 1381 return 0;
bf836661
VB
1382}
1383
d62a17ae 1384static int ospf6TrapIfStateChange(struct ospf6_interface *oi, int next_state,
1385 int prev_state)
bf836661 1386{
d62a17ae 1387 oid index[2];
1388
1389 /* Terminal state or regression */
1390 if ((next_state != OSPF6_INTERFACE_POINTTOPOINT)
1391 && (next_state != OSPF6_INTERFACE_DROTHER)
1392 && (next_state != OSPF6_INTERFACE_BDR)
1393 && (next_state != OSPF6_INTERFACE_DR) && (next_state >= prev_state))
1394 return 0;
1395
1396 index[0] = oi->interface->ifindex;
1397 index[1] = oi->instance_id;
1398
97b5d752
QY
1399 smux_trap(ospfv3_variables, array_size(ospfv3_variables),
1400 ospfv3_trap_oid, array_size(ospfv3_trap_oid), ospfv3_oid,
0d6f7fd6 1401 sizeof(ospfv3_oid) / sizeof(oid), index, 2, ospf6IfTrapList,
97b5d752 1402 array_size(ospf6IfTrapList), IFSTATECHANGE);
d62a17ae 1403 return 0;
bf836661
VB
1404}
1405
ef1bbf5c 1406/* Register OSPFv3-MIB. */
d62a17ae 1407static int ospf6_snmp_init(struct thread_master *master)
ef1bbf5c 1408{
d62a17ae 1409 smux_init(master);
1410 REGISTER_MIB("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
1411 return 0;
ef1bbf5c 1412}
1413
d62a17ae 1414static int ospf6_snmp_module_init(void)
5986b66b 1415{
d62a17ae 1416 hook_register(ospf6_interface_change, ospf6TrapIfStateChange);
1417 hook_register(ospf6_neighbor_change, ospf6TrapNbrStateChange);
1418 hook_register(frr_late_init, ospf6_snmp_init);
1419 return 0;
5986b66b 1420}
ef1bbf5c 1421
d62a17ae 1422FRR_MODULE_SETUP(.name = "ospf6d_snmp", .version = FRR_VERSION,
1423 .description = "ospf6d AgentX SNMP module",
1424 .init = ospf6_snmp_module_init, )