2 * Copyright (C) 2004 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
24 #include <net-snmp/net-snmp-config.h>
25 #include <net-snmp/net-snmp-includes.h>
36 #include "ospf6_proto.h"
37 #include "ospf6_lsa.h"
38 #include "ospf6_lsdb.h"
39 #include "ospf6_route.h"
40 #include "ospf6_top.h"
41 #include "ospf6_area.h"
42 #include "ospf6_interface.h"
43 #include "ospf6_message.h"
44 #include "ospf6_neighbor.h"
45 #include "ospf6_abr.h"
46 #include "ospf6_asbr.h"
50 #define OSPFv3MIB 1,3,6,1,2,1,191
52 /* OSPFv3 MIB General Group values. */
53 #define OSPFv3ROUTERID 1
54 #define OSPFv3ADMINSTAT 2
55 #define OSPFv3VERSIONNUMBER 3
56 #define OSPFv3AREABDRRTRSTATUS 4
57 #define OSPFv3ASBDRRTRSTATUS 5
58 #define OSPFv3ASSCOPELSACOUNT 6
59 #define OSPFv3ASSCOPELSACHECKSUMSUM 7
60 #define OSPFv3ORIGINATENEWLSAS 8
61 #define OSPFv3RXNEWLSAS 9
62 #define OSPFv3EXTLSACOUNT 10
63 #define OSPFv3EXTAREALSDBLIMIT 11
64 #define OSPFv3EXITOVERFLOWINTERVAL 12
65 #define OSPFv3DEMANDEXTENSIONS 13
66 #define OSPFv3REFERENCEBANDWIDTH 14
67 #define OSPFv3RESTARTSUPPORT 15
68 #define OSPFv3RESTARTINTERVAL 16
69 #define OSPFv3RESTARTSTRICTLSACHECKING 17
70 #define OSPFv3RESTARTSTATUS 18
71 #define OSPFv3RESTARTAGE 19
72 #define OSPFv3RESTARTEXITREASON 20
73 #define OSPFv3NOTIFICATIONENABLE 21
74 #define OSPFv3STUBROUTERSUPPORT 22
75 #define OSPFv3STUBROUTERADVERTISEMENT 23
76 #define OSPFv3DISCONTINUITYTIME 24
77 #define OSPFv3RESTARTTIME 25
79 /* OSPFv3 MIB Area Table values: ospfv3AreaTable */
80 #define OSPFv3IMPORTASEXTERN 2
81 #define OSPFv3AREASPFRUNS 3
82 #define OSPFv3AREABDRRTRCOUNT 4
83 #define OSPFv3AREAASBDRRTRCOUNT 5
84 #define OSPFv3AREASCOPELSACOUNT 6
85 #define OSPFv3AREASCOPELSACKSUMSUM 7
86 #define OSPFv3AREASUMMARY 8
87 #define OSPFv3AREAROWSTATUS 9
88 #define OSPFv3AREASTUBMETRIC 10
89 #define OSPFv3AREANSSATRANSLATORROLE 11
90 #define OSPFv3AREANSSATRANSLATORSTATE 12
91 #define OSPFv3AREANSSATRANSLATORSTABINTERVAL 13
92 #define OSPFv3AREANSSATRANSLATOREVENTS 14
93 #define OSPFv3AREASTUBMETRICTYPE 15
94 #define OSPFv3AREATEENABLED 16
96 /* OSPFv3 MIB * Lsdb Table values: ospfv3*LsdbTable */
97 #define OSPFv3WWLSDBSEQUENCE 1
98 #define OSPFv3WWLSDBAGE 2
99 #define OSPFv3WWLSDBCHECKSUM 3
100 #define OSPFv3WWLSDBADVERTISEMENT 4
101 #define OSPFv3WWLSDBTYPEKNOWN 5
103 /* Three first bits are to identify column */
104 #define OSPFv3WWCOLUMN 0x7
105 /* Then we use other bits to identify table */
106 #define OSPFv3WWASTABLE (1 << 3)
107 #define OSPFv3WWAREATABLE (1 << 4)
108 #define OSPFv3WWLINKTABLE (1 << 5)
109 #define OSPFv3WWVIRTLINKTABLE (1 << 6)
111 /* OSPFv3 MIB Host Table values: ospfv3HostTable */
112 #define OSPFv3HOSTMETRIC 3
113 #define OSPFv3HOSTROWSTATUS 4
114 #define OSPFv3HOSTAREAID 5
116 /* OSPFv3 MIB Interface Table values: ospfv3IfTable */
117 #define OSPFv3IFAREAID 3
118 #define OSPFv3IFTYPE 4
119 #define OSPFv3IFADMINSTATUS 5
120 #define OSPFv3IFRTRPRIORITY 6
121 #define OSPFv3IFTRANSITDELAY 7
122 #define OSPFv3IFRETRANSINTERVAL 8
123 #define OSPFv3IFHELLOINTERVAL 9
124 #define OSPFv3IFRTRDEADINTERVAL 10
125 #define OSPFv3IFPOLLINTERVAL 11
126 #define OSPFv3IFSTATE 12
127 #define OSPFv3IFDESIGNATEDROUTER 13
128 #define OSPFv3IFBACKUPDESIGNATEDROUTER 14
129 #define OSPFv3IFEVENTS 15
130 #define OSPFv3IFROWSTATUS 16
131 #define OSPFv3IFDEMAND 17
132 #define OSPFv3IFMETRICVALUE 18
133 #define OSPFv3IFLINKSCOPELSACOUNT 19
134 #define OSPFv3IFLINKLSACKSUMSUM 20
135 #define OSPFv3IFDEMANDNBRPROBE 21
136 #define OSPFv3IFDEMANDNBRPROBERETRANSLIMIT 22
137 #define OSPFv3IFDEMANDNBRPROBEINTERVAL 23
138 #define OSPFv3IFTEDISABLED 24
139 #define OSPFv3IFLINKLSASUPPRESSION 25
141 /* OSPFv3 MIB Virtual Interface Table values: ospfv3VirtIfTable */
142 #define OSPFv3VIRTIFINDEX 3
143 #define OSPFv3VIRTIFINSTID 4
144 #define OSPFv3VIRTIFTRANSITDELAY 5
145 #define OSPFv3VIRTIFRETRANSINTERVAL 6
146 #define OSPFv3VIRTIFHELLOINTERVAL 7
147 #define OSPFv3VIRTIFRTRDEADINTERVAL 8
148 #define OSPFv3VIRTIFSTATE 9
149 #define OSPFv3VIRTIFEVENTS 10
150 #define OSPFv3VIRTIFROWSTATUS 11
151 #define OSPFv3VIRTIFLINKSCOPELSACOUNT 12
152 #define OSPFv3VIRTIFLINKLSACKSUMSUM 13
154 /* OSPFv3 MIB Neighbors Table values: ospfv3NbrTable */
155 #define OSPFv3NBRADDRESSTYPE 4
156 #define OSPFv3NBRADDRESS 5
157 #define OSPFv3NBROPTIONS 6
158 #define OSPFv3NBRPRIORITY 7
159 #define OSPFv3NBRSTATE 8
160 #define OSPFv3NBREVENTS 9
161 #define OSPFv3NBRLSRETRANSQLEN 10
162 #define OSPFv3NBRHELLOSUPPRESSED 11
163 #define OSPFv3NBRIFID 12
164 #define OSPFv3NBRRESTARTHELPERSTATUS 13
165 #define OSPFv3NBRRESTARTHELPERAGE 14
166 #define OSPFv3NBRRESTARTHELPEREXITREASON 15
168 /* OSPFv3 MIB Configured Neighbors Table values: ospfv3CfgNbrTable */
169 #define OSPFv3CFGNBRPRIORITY 5
170 #define OSPFv3CFGNBRROWSTATUS 6
172 /* OSPFv3 MIB Virtual Neighbors Table values: ospfv3VirtNbrTable */
173 #define OSPFv3VIRTNBRIFINDEX 3
174 #define OSPFv3VIRTNBRIFINSTID 4
175 #define OSPFv3VIRTNBRADDRESSTYPE 5
176 #define OSPFv3VIRTNBRADDRESS 6
177 #define OSPFv3VIRTNBROPTIONS 7
178 #define OSPFv3VIRTNBRSTATE 8
179 #define OSPFv3VIRTNBREVENTS 9
180 #define OSPFv3VIRTNBRLSRETRANSQLEN 10
181 #define OSPFv3VIRTNBRHELLOSUPPRESSED 11
182 #define OSPFv3VIRTNBRIFID 12
183 #define OSPFv3VIRTNBRRESTARTHELPERSTATUS 13
184 #define OSPFv3VIRTNBRRESTARTHELPERAGE 14
185 #define OSPFv3VIRTNBRRESTARTHELPEREXITREASON 15
187 /* OSPFv3 MIB Area Aggregate Table values: ospfv3AreaAggregateTable */
188 #define OSPFv3AREAAGGREGATEROWSTATUS 6
189 #define OSPFv3AREAAGGREGATEEFFECT 7
190 #define OSPFv3AREAAGGREGATEROUTETAG 8
192 /* SYNTAX Status from OSPF-MIB. */
193 #define OSPF_STATUS_ENABLED 1
194 #define OSPF_STATUS_DISABLED 2
196 /* SNMP value hack. */
197 #define COUNTER ASN_COUNTER
198 #define INTEGER ASN_INTEGER
199 #define GAUGE ASN_GAUGE
200 #define UNSIGNED ASN_UNSIGNED
201 #define TIMETICKS ASN_TIMETICKS
202 #define IPADDRESS ASN_IPADDRESS
203 #define STRING ASN_OCTET_STR
205 /* For return values e.g. SNMP_INTEGER macro */
208 /* OSPFv3-MIB instances. */
209 static oid ospfv3_oid
[] = {OSPFv3MIB
};
210 static oid ospfv3_trap_oid
[] = {OSPFv3MIB
, 0};
212 /* Hook functions. */
213 static u_char
*ospfv3GeneralGroup(struct variable
*, oid
*, size_t *, int,
214 size_t *, WriteMethod
**);
215 static u_char
*ospfv3AreaEntry(struct variable
*, oid
*, size_t *, int,
216 size_t *, WriteMethod
**);
217 static u_char
*ospfv3WwLsdbEntry(struct variable
*, oid
*, size_t *, int,
218 size_t *, WriteMethod
**);
219 static u_char
*ospfv3NbrEntry(struct variable
*, oid
*, size_t *, int, size_t *,
221 static u_char
*ospfv3IfEntry(struct variable
*, oid
*, size_t *, int, size_t *,
224 static struct variable ospfv3_variables
[] = {
225 /* OSPF general variables */
226 {OSPFv3ROUTERID
, UNSIGNED
, RWRITE
, ospfv3GeneralGroup
, 3, {1, 1, 1}},
227 {OSPFv3ADMINSTAT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
, 3, {1, 1, 2}},
228 {OSPFv3VERSIONNUMBER
, INTEGER
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 3}},
229 {OSPFv3AREABDRRTRSTATUS
,
235 {OSPFv3ASBDRRTRSTATUS
,
241 {OSPFv3ASSCOPELSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 6}},
242 {OSPFv3ASSCOPELSACHECKSUMSUM
,
248 {OSPFv3ORIGINATENEWLSAS
,
254 {OSPFv3RXNEWLSAS
, COUNTER
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 9}},
255 {OSPFv3EXTLSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 10}},
256 {OSPFv3EXTAREALSDBLIMIT
,
262 {OSPFv3EXITOVERFLOWINTERVAL
,
268 {OSPFv3DEMANDEXTENSIONS
,
274 {OSPFv3REFERENCEBANDWIDTH
,
280 {OSPFv3RESTARTSUPPORT
,
286 {OSPFv3RESTARTINTERVAL
,
292 {OSPFv3RESTARTSTRICTLSACHECKING
,
298 {OSPFv3RESTARTSTATUS
,
304 {OSPFv3RESTARTAGE
, UNSIGNED
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 19}},
305 {OSPFv3RESTARTEXITREASON
,
311 {OSPFv3NOTIFICATIONENABLE
,
317 {OSPFv3STUBROUTERSUPPORT
,
323 {OSPFv3STUBROUTERADVERTISEMENT
,
329 {OSPFv3DISCONTINUITYTIME
,
342 /* OSPFv3 Area Data Structure */
343 {OSPFv3IMPORTASEXTERN
,
349 {OSPFv3AREASPFRUNS
, COUNTER
, RONLY
, ospfv3AreaEntry
, 4, {1, 2, 1, 3}},
350 {OSPFv3AREABDRRTRCOUNT
, GAUGE
, RONLY
, ospfv3AreaEntry
, 4, {1, 2, 1, 4}},
351 {OSPFv3AREAASBDRRTRCOUNT
,
357 {OSPFv3AREASCOPELSACOUNT
,
363 {OSPFv3AREASCOPELSACKSUMSUM
,
369 {OSPFv3AREASUMMARY
, INTEGER
, RWRITE
, ospfv3AreaEntry
, 4, {1, 2, 1, 8}},
370 {OSPFv3AREAROWSTATUS
,
376 {OSPFv3AREASTUBMETRIC
,
382 {OSPFv3AREANSSATRANSLATORROLE
,
388 {OSPFv3AREANSSATRANSLATORSTATE
,
394 {OSPFv3AREANSSATRANSLATORSTABINTERVAL
,
400 {OSPFv3AREANSSATRANSLATOREVENTS
,
406 {OSPFv3AREASTUBMETRICTYPE
,
412 {OSPFv3AREATEENABLED
,
420 {OSPFv3WWLSDBSEQUENCE
| OSPFv3WWASTABLE
,
426 {OSPFv3WWLSDBAGE
| OSPFv3WWASTABLE
,
432 {OSPFv3WWLSDBCHECKSUM
| OSPFv3WWASTABLE
,
438 {OSPFv3WWLSDBADVERTISEMENT
| OSPFv3WWASTABLE
,
444 {OSPFv3WWLSDBTYPEKNOWN
| OSPFv3WWASTABLE
,
451 /* OSPFv3 Area LSDB */
452 {OSPFv3WWLSDBSEQUENCE
| OSPFv3WWAREATABLE
,
458 {OSPFv3WWLSDBAGE
| OSPFv3WWAREATABLE
,
464 {OSPFv3WWLSDBCHECKSUM
| OSPFv3WWAREATABLE
,
470 {OSPFv3WWLSDBADVERTISEMENT
| OSPFv3WWAREATABLE
,
476 {OSPFv3WWLSDBTYPEKNOWN
| OSPFv3WWAREATABLE
,
483 /* OSPFv3 Link LSDB */
484 {OSPFv3WWLSDBSEQUENCE
| OSPFv3WWLINKTABLE
,
490 {OSPFv3WWLSDBAGE
| OSPFv3WWLINKTABLE
,
496 {OSPFv3WWLSDBCHECKSUM
| OSPFv3WWLINKTABLE
,
502 {OSPFv3WWLSDBADVERTISEMENT
| OSPFv3WWLINKTABLE
,
508 {OSPFv3WWLSDBTYPEKNOWN
| OSPFv3WWLINKTABLE
,
515 /* OSPFv3 interfaces */
516 {OSPFv3IFAREAID
, UNSIGNED
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 3}},
517 {OSPFv3IFTYPE
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 4}},
518 {OSPFv3IFADMINSTATUS
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 5}},
519 {OSPFv3IFRTRPRIORITY
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 6}},
520 {OSPFv3IFTRANSITDELAY
, UNSIGNED
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 7}},
521 {OSPFv3IFRETRANSINTERVAL
,
527 {OSPFv3IFHELLOINTERVAL
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 9}},
528 {OSPFv3IFRTRDEADINTERVAL
,
534 {OSPFv3IFPOLLINTERVAL
,
540 {OSPFv3IFSTATE
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 12}},
541 {OSPFv3IFDESIGNATEDROUTER
,
547 {OSPFv3IFBACKUPDESIGNATEDROUTER
,
553 {OSPFv3IFEVENTS
, COUNTER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 15}},
554 {OSPFv3IFROWSTATUS
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 16}},
555 {OSPFv3IFDEMAND
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 17}},
556 {OSPFv3IFMETRICVALUE
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 18}},
557 {OSPFv3IFLINKSCOPELSACOUNT
,
563 {OSPFv3IFLINKLSACKSUMSUM
,
569 {OSPFv3IFDEMANDNBRPROBE
,
575 {OSPFv3IFDEMANDNBRPROBERETRANSLIMIT
,
581 {OSPFv3IFDEMANDNBRPROBEINTERVAL
,
587 {OSPFv3IFTEDISABLED
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 24}},
588 {OSPFv3IFLINKLSASUPPRESSION
,
595 /* OSPFv3 neighbors */
596 {OSPFv3NBRADDRESSTYPE
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 4}},
597 {OSPFv3NBRADDRESS
, STRING
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 5}},
598 {OSPFv3NBROPTIONS
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 6}},
599 {OSPFv3NBRPRIORITY
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 7}},
600 {OSPFv3NBRSTATE
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 8}},
601 {OSPFv3NBREVENTS
, COUNTER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 9}},
602 {OSPFv3NBRLSRETRANSQLEN
,
608 {OSPFv3NBRHELLOSUPPRESSED
,
614 {OSPFv3NBRIFID
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 12}},
615 {OSPFv3NBRRESTARTHELPERSTATUS
,
621 {OSPFv3NBRRESTARTHELPERAGE
,
627 {OSPFv3NBRRESTARTHELPEREXITREASON
,
635 static u_char
*ospfv3GeneralGroup(struct variable
*v
, oid
*name
, size_t *length
,
636 int exact
, size_t *var_len
,
637 WriteMethod
**write_method
)
641 struct ospf6_lsa
*lsa
= NULL
;
643 /* Check whether the instance identifier is valid */
644 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
648 /* Return the current value of the variable */
651 /* Router-ID of this OSPF instance. */
653 return SNMP_INTEGER(ntohl(ospf6
->router_id
));
654 return SNMP_INTEGER(0);
655 case OSPFv3ADMINSTAT
:
658 CHECK_FLAG(ospf6
->flag
, OSPF6_DISABLED
)
659 ? OSPF_STATUS_DISABLED
660 : OSPF_STATUS_ENABLED
);
661 return SNMP_INTEGER(OSPF_STATUS_DISABLED
);
662 case OSPFv3VERSIONNUMBER
:
663 return SNMP_INTEGER(3);
664 case OSPFv3AREABDRRTRSTATUS
:
666 return SNMP_INTEGER(ospf6_is_router_abr(ospf6
)
669 return SNMP_INTEGER(SNMP_FALSE
);
670 case OSPFv3ASBDRRTRSTATUS
:
672 return SNMP_INTEGER(ospf6_asbr_is_asbr(ospf6
)
675 return SNMP_INTEGER(SNMP_FALSE
);
676 case OSPFv3ASSCOPELSACOUNT
:
678 return SNMP_INTEGER(ospf6
->lsdb
->count
);
679 return SNMP_INTEGER(0);
680 case OSPFv3ASSCOPELSACHECKSUMSUM
:
682 for (sum
= 0, lsa
= ospf6_lsdb_head(ospf6
->lsdb
); lsa
;
683 lsa
= ospf6_lsdb_next(lsa
))
684 sum
+= ntohs(lsa
->header
->checksum
);
685 return SNMP_INTEGER(sum
);
687 return SNMP_INTEGER(0);
688 case OSPFv3ORIGINATENEWLSAS
:
690 0); /* Don't know where to get this value... */
691 case OSPFv3RXNEWLSAS
:
693 0); /* Don't know where to get this value... */
694 case OSPFv3EXTLSACOUNT
:
697 lsa
= ospf6_lsdb_type_head(
698 htons(OSPF6_LSTYPE_AS_EXTERNAL
),
700 lsa
; lsa
= ospf6_lsdb_type_next(
701 htons(OSPF6_LSTYPE_AS_EXTERNAL
), lsa
))
703 return SNMP_INTEGER(count
);
705 return SNMP_INTEGER(0);
706 case OSPFv3EXTAREALSDBLIMIT
:
707 return SNMP_INTEGER(-1);
708 case OSPFv3EXITOVERFLOWINTERVAL
:
709 return SNMP_INTEGER(0); /* Not supported */
710 case OSPFv3DEMANDEXTENSIONS
:
711 return SNMP_INTEGER(0); /* Not supported */
712 case OSPFv3REFERENCEBANDWIDTH
:
714 return SNMP_INTEGER(ospf6
->ref_bandwidth
);
715 /* Otherwise, like for "not implemented". */
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 */
733 static u_char
*ospfv3AreaEntry(struct variable
*v
, oid
*name
, size_t *length
,
734 int exact
, size_t *var_len
,
735 WriteMethod
**write_method
)
737 struct ospf6_area
*oa
, *area
= NULL
;
738 struct ospf6_lsa
*lsa
= NULL
;
739 u_int32_t area_id
= 0;
742 struct listnode
*node
;
745 struct ospf6_route
*ro
;
750 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
754 len
= *length
- v
->namelen
;
755 len
= (len
>= 1 ? 1 : 0);
756 if (exact
&& len
!= 1)
759 area_id
= htonl(name
[v
->namelen
]);
761 inet_ntop(AF_INET
, &area_id
, a
, sizeof(a
));
762 zlog_debug("SNMP access by area: %s, exact=%d len=%d length=%lu", a
,
763 exact
, len
, (u_long
)*length
);
765 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, node
, oa
)) {
767 if (len
== 0) /* return first area entry */
769 else if (exact
&& ntohl(oa
->area_id
) == ntohl(area_id
))
771 else if (ntohl(oa
->area_id
) > ntohl(area_id
))
779 *length
= v
->namelen
+ 1;
780 name
[v
->namelen
] = ntohl(area
->area_id
);
782 inet_ntop(AF_INET
, &area
->area_id
, a
, sizeof(a
));
783 zlog_debug("SNMP found area: %s, exact=%d len=%d length=%lu", a
, exact
,
784 len
, (u_long
)*length
);
787 case OSPFv3IMPORTASEXTERN
:
788 /* No NSSA support */
789 return SNMP_INTEGER(IS_AREA_STUB(area
) ? 2 : 1);
790 case OSPFv3AREASPFRUNS
:
791 return SNMP_INTEGER(area
->spf_calculation
);
792 case OSPFv3AREABDRRTRCOUNT
:
793 case OSPFv3AREAASBDRRTRCOUNT
:
795 for (ro
= ospf6_route_head(ospf6
->brouter_table
); ro
;
796 ro
= ospf6_route_next(ro
)) {
797 if (ntohl(ro
->path
.area_id
) != ntohl(area
->area_id
))
799 if (v
->magic
== OSPFv3AREABDRRTRCOUNT
800 && CHECK_FLAG(ro
->path
.router_bits
,
803 if (v
->magic
== OSPFv3AREAASBDRRTRCOUNT
804 && CHECK_FLAG(ro
->path
.router_bits
,
808 return SNMP_INTEGER(count
);
809 case OSPFv3AREASCOPELSACOUNT
:
810 return SNMP_INTEGER(area
->lsdb
->count
);
811 case OSPFv3AREASCOPELSACKSUMSUM
:
812 for (sum
= 0, lsa
= ospf6_lsdb_head(area
->lsdb
); lsa
;
813 lsa
= ospf6_lsdb_next(lsa
))
814 sum
+= ntohs(lsa
->header
->checksum
);
815 return SNMP_INTEGER(sum
);
816 case OSPFv3AREASUMMARY
:
817 return SNMP_INTEGER(2); /* sendAreaSummary */
818 case OSPFv3AREAROWSTATUS
:
819 return SNMP_INTEGER(1); /* Active */
820 case OSPFv3AREASTUBMETRIC
:
821 case OSPFv3AREANSSATRANSLATORROLE
:
822 case OSPFv3AREANSSATRANSLATORSTATE
:
823 case OSPFv3AREANSSATRANSLATORSTABINTERVAL
:
824 case OSPFv3AREANSSATRANSLATOREVENTS
:
825 case OSPFv3AREASTUBMETRICTYPE
:
826 case OSPFv3AREATEENABLED
:
827 /* Not implemented. */
833 static int if_icmp_func(struct interface
*ifp1
, struct interface
*ifp2
)
835 return (ifp1
->ifindex
- ifp2
->ifindex
);
838 static u_char
*ospfv3WwLsdbEntry(struct variable
*v
, oid
*name
, size_t *length
,
839 int exact
, size_t *var_len
,
840 WriteMethod
**write_method
)
842 struct ospf6_lsa
*lsa
= NULL
;
844 uint32_t area_id
, id
, instid
, adv_router
;
849 struct ospf6_area
*oa
= NULL
;
850 struct listnode
*node
;
851 struct interface
*iif
;
852 struct ospf6_interface
*oi
= NULL
;
853 struct list
*ifslist
;
855 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
859 instid
= ifindex
= area_id
= type
= id
= adv_router
= 0;
861 /* Check OSPFv3 instance. */
865 /* Get variable length. */
866 offset
= name
+ v
->namelen
;
867 offsetlen
= *length
- v
->namelen
;
869 if (exact
&& (v
->magic
& OSPFv3WWASTABLE
) && offsetlen
!= 3)
871 if (exact
&& (v
->magic
& OSPFv3WWAREATABLE
) && offsetlen
!= 4)
873 if (exact
&& (v
->magic
& OSPFv3WWLINKTABLE
) && offsetlen
!= 5)
876 if (v
->magic
& OSPFv3WWLINKTABLE
) {
878 len
= (offsetlen
< 1 ? 0 : 1);
884 /* Parse instance ID */
885 len
= (offsetlen
< 1 ? 0 : 1);
890 } else if (v
->magic
& OSPFv3WWAREATABLE
) {
892 len
= (offsetlen
< 1 ? 0 : 1);
894 area_id
= htonl(*offset
);
900 len
= (offsetlen
< 1 ? 0 : 1);
902 type
= htons(*offset
);
906 /* Parse Router-ID */
907 len
= (offsetlen
< 1 ? 0 : 1);
909 adv_router
= htonl(*offset
);
914 len
= (offsetlen
< 1 ? 0 : 1);
921 if (v
->magic
& OSPFv3WWASTABLE
) {
922 lsa
= ospf6_lsdb_lookup(type
, id
, adv_router
,
924 } else if (v
->magic
& OSPFv3WWAREATABLE
) {
925 oa
= ospf6_area_lookup(area_id
, ospf6
);
928 lsa
= ospf6_lsdb_lookup(type
, id
, adv_router
, oa
->lsdb
);
929 } else if (v
->magic
& OSPFv3WWLINKTABLE
) {
930 oi
= ospf6_interface_lookup_by_ifindex(ifindex
);
931 if (!oi
|| oi
->instance_id
!= instid
)
933 lsa
= ospf6_lsdb_lookup(type
, id
, adv_router
, oi
->lsdb
);
936 if (v
->magic
& OSPFv3WWASTABLE
) {
937 if (ospf6
->lsdb
->count
)
938 lsa
= ospf6_lsdb_lookup_next(
939 type
, id
, adv_router
, ospf6
->lsdb
);
940 } else if (v
->magic
& OSPFv3WWAREATABLE
)
941 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, node
, oa
)) {
942 if (oa
->area_id
< area_id
)
946 lsa
= ospf6_lsdb_lookup_next(
947 type
, id
, adv_router
, oa
->lsdb
);
954 else if (v
->magic
& OSPFv3WWLINKTABLE
) {
955 /* We build a sorted list of interfaces */
956 ifslist
= list_new();
959 ifslist
->cmp
= (int (*)(void *, void *))if_icmp_func
;
960 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), node
,
962 listnode_add_sort(ifslist
, iif
);
964 for (ALL_LIST_ELEMENTS_RO(ifslist
, node
, iif
)) {
967 oi
= ospf6_interface_lookup_by_ifindex(
971 if (iif
->ifindex
< ifindex
)
973 if (oi
->instance_id
< instid
)
977 lsa
= ospf6_lsdb_lookup_next(
978 type
, id
, adv_router
, oi
->lsdb
);
987 list_delete_all_node(ifslist
);
995 if (v
->magic
& OSPFv3WWASTABLE
) {
996 *length
= v
->namelen
+ 3;
997 offset
= name
+ v
->namelen
;
998 } else if (v
->magic
& OSPFv3WWAREATABLE
) {
999 *length
= v
->namelen
+ 4;
1000 offset
= name
+ v
->namelen
;
1001 *offset
= ntohl(oa
->area_id
);
1003 } else if (v
->magic
& OSPFv3WWLINKTABLE
) {
1004 *length
= v
->namelen
+ 5;
1005 offset
= name
+ v
->namelen
;
1006 *offset
= oi
->interface
->ifindex
;
1008 *offset
= oi
->instance_id
;
1011 *offset
= ntohs(lsa
->header
->type
);
1013 *offset
= ntohl(lsa
->header
->adv_router
);
1015 *offset
= ntohl(lsa
->header
->id
);
1018 /* Return the current value of the variable */
1019 switch (v
->magic
& OSPFv3WWCOLUMN
) {
1020 case OSPFv3WWLSDBSEQUENCE
:
1021 return SNMP_INTEGER(ntohl(lsa
->header
->seqnum
));
1023 case OSPFv3WWLSDBAGE
:
1024 ospf6_lsa_age_current(lsa
);
1025 return SNMP_INTEGER(ntohs(lsa
->header
->age
));
1027 case OSPFv3WWLSDBCHECKSUM
:
1028 return SNMP_INTEGER(ntohs(lsa
->header
->checksum
));
1030 case OSPFv3WWLSDBADVERTISEMENT
:
1031 *var_len
= ntohs(lsa
->header
->length
);
1032 return (u_char
*)lsa
->header
;
1034 case OSPFv3WWLSDBTYPEKNOWN
:
1035 return SNMP_INTEGER(OSPF6_LSA_IS_KNOWN(lsa
->header
->type
)
1043 static u_char
*ospfv3IfEntry(struct variable
*v
, oid
*name
, size_t *length
,
1044 int exact
, size_t *var_len
,
1045 WriteMethod
**write_method
)
1047 ifindex_t ifindex
= 0;
1048 unsigned int instid
= 0;
1049 struct ospf6_interface
*oi
= NULL
;
1050 struct ospf6_lsa
*lsa
= NULL
;
1051 struct interface
*iif
;
1053 struct list
*ifslist
;
1058 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1062 /* Check OSPFv3 instance. */
1066 /* Get variable length. */
1067 offset
= name
+ v
->namelen
;
1068 offsetlen
= *length
- v
->namelen
;
1070 if (exact
&& offsetlen
!= 2)
1073 /* Parse if index */
1074 len
= (offsetlen
< 1 ? 0 : 1);
1080 /* Parse instance ID */
1081 len
= (offsetlen
< 1 ? 0 : 1);
1088 oi
= ospf6_interface_lookup_by_ifindex(ifindex
);
1089 if (!oi
|| oi
->instance_id
!= instid
)
1092 /* We build a sorted list of interfaces */
1093 ifslist
= list_new();
1096 ifslist
->cmp
= (int (*)(void *, void *))if_icmp_func
;
1097 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), i
, iif
))
1098 listnode_add_sort(ifslist
, iif
);
1100 for (ALL_LIST_ELEMENTS_RO(ifslist
, i
, iif
)) {
1103 oi
= ospf6_interface_lookup_by_ifindex(iif
->ifindex
);
1106 if (iif
->ifindex
> ifindex
1107 || (iif
->ifindex
== ifindex
1108 && (oi
->instance_id
> instid
)))
1113 list_delete_all_node(ifslist
);
1119 /* Add Index (IfIndex, IfInstId) */
1120 *length
= v
->namelen
+ 2;
1121 offset
= name
+ v
->namelen
;
1122 *offset
= oi
->interface
->ifindex
;
1124 *offset
= oi
->instance_id
;
1127 /* Return the current value of the variable */
1129 case OSPFv3IFAREAID
:
1131 return SNMP_INTEGER(ntohl(oi
->area
->area_id
));
1134 if (if_is_broadcast(oi
->interface
))
1135 return SNMP_INTEGER(1);
1136 else if (if_is_pointopoint(oi
->interface
))
1137 return SNMP_INTEGER(3);
1139 break; /* Unknown, don't put anything */
1140 case OSPFv3IFADMINSTATUS
:
1142 return SNMP_INTEGER(OSPF_STATUS_ENABLED
);
1143 return SNMP_INTEGER(OSPF_STATUS_DISABLED
);
1144 case OSPFv3IFRTRPRIORITY
:
1145 return SNMP_INTEGER(oi
->priority
);
1146 case OSPFv3IFTRANSITDELAY
:
1147 return SNMP_INTEGER(oi
->transdelay
);
1148 case OSPFv3IFRETRANSINTERVAL
:
1149 return SNMP_INTEGER(oi
->rxmt_interval
);
1150 case OSPFv3IFHELLOINTERVAL
:
1151 return SNMP_INTEGER(oi
->hello_interval
);
1152 case OSPFv3IFRTRDEADINTERVAL
:
1153 return SNMP_INTEGER(oi
->dead_interval
);
1154 case OSPFv3IFPOLLINTERVAL
:
1155 /* No support for NBMA */
1158 return SNMP_INTEGER(oi
->state
);
1159 case OSPFv3IFDESIGNATEDROUTER
:
1160 return SNMP_INTEGER(ntohl(oi
->drouter
));
1161 case OSPFv3IFBACKUPDESIGNATEDROUTER
:
1162 return SNMP_INTEGER(ntohl(oi
->bdrouter
));
1163 case OSPFv3IFEVENTS
:
1164 return SNMP_INTEGER(oi
->state_change
);
1165 case OSPFv3IFROWSTATUS
:
1166 return SNMP_INTEGER(1);
1167 case OSPFv3IFDEMAND
:
1168 return SNMP_INTEGER(SNMP_FALSE
);
1169 case OSPFv3IFMETRICVALUE
:
1170 return SNMP_INTEGER(oi
->cost
);
1171 case OSPFv3IFLINKSCOPELSACOUNT
:
1172 return SNMP_INTEGER(oi
->lsdb
->count
);
1173 case OSPFv3IFLINKLSACKSUMSUM
:
1174 for (sum
= 0, lsa
= ospf6_lsdb_head(oi
->lsdb
); lsa
;
1175 lsa
= ospf6_lsdb_next(lsa
))
1176 sum
+= ntohs(lsa
->header
->checksum
);
1177 return SNMP_INTEGER(sum
);
1178 case OSPFv3IFDEMANDNBRPROBE
:
1179 case OSPFv3IFDEMANDNBRPROBERETRANSLIMIT
:
1180 case OSPFv3IFDEMANDNBRPROBEINTERVAL
:
1181 case OSPFv3IFTEDISABLED
:
1182 case OSPFv3IFLINKLSASUPPRESSION
:
1183 /* Not implemented. Only works if all the last ones are not
1188 /* Try an internal getnext. Some columns are missing in this table. */
1189 if (!exact
&& (name
[*length
- 1] < MAX_SUBID
))
1190 return ospfv3IfEntry(v
, name
, length
, exact
, var_len
,
1195 static u_char
*ospfv3NbrEntry(struct variable
*v
, oid
*name
, size_t *length
,
1196 int exact
, size_t *var_len
,
1197 WriteMethod
**write_method
)
1199 ifindex_t ifindex
= 0;
1200 unsigned int instid
, rtrid
;
1201 struct ospf6_interface
*oi
= NULL
;
1202 struct ospf6_neighbor
*on
= NULL
;
1203 struct interface
*iif
;
1204 struct listnode
*i
, *j
;
1205 struct list
*ifslist
;
1209 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1215 /* Check OSPFv3 instance. */
1219 /* Get variable length. */
1220 offset
= name
+ v
->namelen
;
1221 offsetlen
= *length
- v
->namelen
;
1223 if (exact
&& offsetlen
!= 3)
1226 /* Parse if index */
1227 len
= (offsetlen
< 1 ? 0 : 1);
1233 /* Parse instance ID */
1234 len
= (offsetlen
< 1 ? 0 : 1);
1240 /* Parse router ID */
1241 len
= (offsetlen
< 1 ? 0 : 1);
1243 rtrid
= htonl(*offset
);
1248 oi
= ospf6_interface_lookup_by_ifindex(ifindex
);
1249 if (!oi
|| oi
->instance_id
!= instid
)
1251 on
= ospf6_neighbor_lookup(rtrid
, oi
);
1253 /* We build a sorted list of interfaces */
1254 ifslist
= list_new();
1257 ifslist
->cmp
= (int (*)(void *, void *))if_icmp_func
;
1258 for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT
), i
, iif
))
1259 listnode_add_sort(ifslist
, iif
);
1261 for (ALL_LIST_ELEMENTS_RO(ifslist
, i
, iif
)) {
1264 oi
= ospf6_interface_lookup_by_ifindex(iif
->ifindex
);
1267 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, j
, on
)) {
1268 if (iif
->ifindex
> ifindex
1269 || (iif
->ifindex
== ifindex
1270 && (oi
->instance_id
> instid
1271 || (oi
->instance_id
== instid
1272 && ntohl(on
->router_id
)
1282 list_delete_all_node(ifslist
);
1288 /* Add Index (IfIndex, IfInstId, RtrId) */
1289 *length
= v
->namelen
+ 3;
1290 offset
= name
+ v
->namelen
;
1291 *offset
= oi
->interface
->ifindex
;
1293 *offset
= oi
->instance_id
;
1295 *offset
= ntohl(on
->router_id
);
1298 /* Return the current value of the variable */
1300 case OSPFv3NBRADDRESSTYPE
:
1301 return SNMP_INTEGER(2); /* IPv6 only */
1302 case OSPFv3NBRADDRESS
:
1303 *var_len
= sizeof(struct in6_addr
);
1304 return (u_char
*)&on
->linklocal_addr
;
1305 case OSPFv3NBROPTIONS
:
1306 return SNMP_INTEGER(on
->options
[2]);
1307 case OSPFv3NBRPRIORITY
:
1308 return SNMP_INTEGER(on
->priority
);
1309 case OSPFv3NBRSTATE
:
1310 return SNMP_INTEGER(on
->state
);
1311 case OSPFv3NBREVENTS
:
1312 return SNMP_INTEGER(on
->state_change
);
1313 case OSPFv3NBRLSRETRANSQLEN
:
1314 return SNMP_INTEGER(on
->retrans_list
->count
);
1315 case OSPFv3NBRHELLOSUPPRESSED
:
1316 return SNMP_INTEGER(SNMP_FALSE
);
1318 return SNMP_INTEGER(on
->ifindex
);
1319 case OSPFv3NBRRESTARTHELPERSTATUS
:
1320 case OSPFv3NBRRESTARTHELPERAGE
:
1321 case OSPFv3NBRRESTARTHELPEREXITREASON
:
1322 /* Not implemented. Only works if all the last ones are not
1331 #define NBRSTATECHANGE 2
1332 #define IFSTATECHANGE 10
1334 static struct trap_object ospf6NbrTrapList
[] = {
1335 {-3, {1, 1, OSPFv3ROUTERID
}},
1336 {4, {1, 9, 1, OSPFv3NBRADDRESSTYPE
}},
1337 {4, {1, 9, 1, OSPFv3NBRADDRESS
}},
1338 {4, {1, 9, 1, OSPFv3NBRSTATE
}}};
1340 static struct trap_object ospf6IfTrapList
[] = {
1341 {-3, {1, 1, OSPFv3ROUTERID
}},
1342 {4, {1, 7, 1, OSPFv3IFSTATE
}},
1343 {4, {1, 7, 1, OSPFv3IFADMINSTATUS
}},
1344 {4, {1, 7, 1, OSPFv3IFAREAID
}}};
1346 static int ospf6TrapNbrStateChange(struct ospf6_neighbor
*on
, int next_state
,
1351 /* Terminal state or regression */
1352 if ((next_state
!= OSPF6_NEIGHBOR_FULL
)
1353 && (next_state
!= OSPF6_NEIGHBOR_TWOWAY
)
1354 && (next_state
>= prev_state
))
1357 index
[0] = on
->ospf6_if
->interface
->ifindex
;
1358 index
[1] = on
->ospf6_if
->instance_id
;
1359 index
[2] = ntohl(on
->router_id
);
1361 smux_trap(ospfv3_variables
,
1362 sizeof ospfv3_variables
/ sizeof(struct variable
),
1363 ospfv3_trap_oid
, sizeof ospfv3_trap_oid
/ sizeof(oid
),
1364 ospfv3_oid
, sizeof ospfv3_oid
/ sizeof(oid
), index
, 3,
1366 sizeof ospf6NbrTrapList
/ sizeof(struct trap_object
),
1371 static int ospf6TrapIfStateChange(struct ospf6_interface
*oi
, int next_state
,
1376 /* Terminal state or regression */
1377 if ((next_state
!= OSPF6_INTERFACE_POINTTOPOINT
)
1378 && (next_state
!= OSPF6_INTERFACE_DROTHER
)
1379 && (next_state
!= OSPF6_INTERFACE_BDR
)
1380 && (next_state
!= OSPF6_INTERFACE_DR
) && (next_state
>= prev_state
))
1383 index
[0] = oi
->interface
->ifindex
;
1384 index
[1] = oi
->instance_id
;
1386 smux_trap(ospfv3_variables
,
1387 sizeof ospfv3_variables
/ sizeof(struct variable
),
1388 ospfv3_trap_oid
, sizeof ospfv3_trap_oid
/ sizeof(oid
),
1389 ospfv3_oid
, sizeof ospfv3_oid
/ sizeof(oid
), index
, 2,
1391 sizeof ospf6IfTrapList
/ sizeof(struct trap_object
),
1396 /* Register OSPFv3-MIB. */
1397 static int ospf6_snmp_init(struct thread_master
*master
)
1400 REGISTER_MIB("OSPFv3MIB", ospfv3_variables
, variable
, ospfv3_oid
);
1404 static int ospf6_snmp_module_init(void)
1406 hook_register(ospf6_interface_change
, ospf6TrapIfStateChange
);
1407 hook_register(ospf6_neighbor_change
, ospf6TrapNbrStateChange
);
1408 hook_register(frr_late_init
, ospf6_snmp_init
);
1412 FRR_MODULE_SETUP(.name
= "ospf6d_snmp", .version
= FRR_VERSION
,
1413 .description
= "ospf6d AgentX SNMP module",
1414 .init
= ospf6_snmp_module_init
, )