]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_snmp.c
*: snmp: convert into modules
[mirror_frr.git] / ospf6d / ospf6_snmp.c
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 *
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.
20 */
21
22 #include <zebra.h>
23
24 #include <net-snmp/net-snmp-config.h>
25 #include <net-snmp/net-snmp-includes.h>
26
27 #include "log.h"
28 #include "vty.h"
29 #include "linklist.h"
30 #include "vector.h"
31 #include "vrf.h"
32 #include "smux.h"
33 #include "libfrr.h"
34 #include "version.h"
35
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"
47 #include "ospf6d.h"
48
49 /* OSPFv3-MIB */
50 #define OSPFv3MIB 1,3,6,1,2,1,191
51
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
78
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
95
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
102
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)
110
111 /* OSPFv3 MIB Host Table values: ospfv3HostTable */
112 #define OSPFv3HOSTMETRIC 3
113 #define OSPFv3HOSTROWSTATUS 4
114 #define OSPFv3HOSTAREAID 5
115
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
140
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
153
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
167
168 /* OSPFv3 MIB Configured Neighbors Table values: ospfv3CfgNbrTable */
169 #define OSPFv3CFGNBRPRIORITY 5
170 #define OSPFv3CFGNBRROWSTATUS 6
171
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
186
187 /* OSPFv3 MIB Area Aggregate Table values: ospfv3AreaAggregateTable */
188 #define OSPFv3AREAAGGREGATEROWSTATUS 6
189 #define OSPFv3AREAAGGREGATEEFFECT 7
190 #define OSPFv3AREAAGGREGATEROUTETAG 8
191
192 /* SYNTAX Status from OSPF-MIB. */
193 #define OSPF_STATUS_ENABLED 1
194 #define OSPF_STATUS_DISABLED 2
195
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
204
205 /* For return values e.g. SNMP_INTEGER macro */
206 SNMP_LOCAL_VARIABLES
207
208 /* OSPFv3-MIB instances. */
209 static oid ospfv3_oid [] = { OSPFv3MIB };
210 static oid ospfv3_trap_oid [] = { OSPFv3MIB, 0 };
211
212 /* Hook functions. */
213 static u_char *ospfv3GeneralGroup (struct variable *, oid *, size_t *,
214 int, size_t *, WriteMethod **);
215 static u_char *ospfv3AreaEntry (struct variable *, oid *, size_t *,
216 int, size_t *, WriteMethod **);
217 static u_char *ospfv3WwLsdbEntry (struct variable *, oid *, size_t *,
218 int, size_t *, WriteMethod **);
219 static u_char *ospfv3NbrEntry (struct variable *, oid *, size_t *,
220 int, size_t *, WriteMethod **);
221 static u_char *ospfv3IfEntry (struct variable *, oid *, size_t *,
222 int, size_t *, WriteMethod **);
223
224 static struct variable ospfv3_variables[] =
225 {
226 /* OSPF general variables */
227 {OSPFv3ROUTERID, UNSIGNED, RWRITE, ospfv3GeneralGroup,
228 3, {1, 1, 1}},
229 {OSPFv3ADMINSTAT, INTEGER, RWRITE, ospfv3GeneralGroup,
230 3, {1, 1, 2}},
231 {OSPFv3VERSIONNUMBER, INTEGER, RONLY, ospfv3GeneralGroup,
232 3, {1, 1, 3}},
233 {OSPFv3AREABDRRTRSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
234 3, {1, 1, 4}},
235 {OSPFv3ASBDRRTRSTATUS, INTEGER, RWRITE, ospfv3GeneralGroup,
236 3, {1, 1, 5}},
237 {OSPFv3ASSCOPELSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
238 3, {1, 1, 6}},
239 {OSPFv3ASSCOPELSACHECKSUMSUM,UNSIGNED, RONLY, ospfv3GeneralGroup,
240 3, {1, 1, 7}},
241 {OSPFv3ORIGINATENEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
242 3, {1, 1, 8}},
243 {OSPFv3RXNEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
244 3, {1, 1, 9}},
245 {OSPFv3EXTLSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
246 3, {1, 1, 10}},
247 {OSPFv3EXTAREALSDBLIMIT, INTEGER, RWRITE, ospfv3GeneralGroup,
248 3, {1, 1, 11}},
249 {OSPFv3EXITOVERFLOWINTERVAL, UNSIGNED, RWRITE, ospfv3GeneralGroup,
250 3, {1, 1, 12}},
251 {OSPFv3DEMANDEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup,
252 3, {1, 1, 13}},
253 {OSPFv3REFERENCEBANDWIDTH, UNSIGNED, RWRITE, ospfv3GeneralGroup,
254 3, {1, 1, 14}},
255 {OSPFv3RESTARTSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup,
256 3, {1, 1, 15}},
257 {OSPFv3RESTARTINTERVAL, UNSIGNED, RWRITE, ospfv3GeneralGroup,
258 3, {1, 1, 16}},
259 {OSPFv3RESTARTSTRICTLSACHECKING, INTEGER, RWRITE, ospfv3GeneralGroup,
260 3, {1, 1, 17}},
261 {OSPFv3RESTARTSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
262 3, {1, 1, 18}},
263 {OSPFv3RESTARTAGE, UNSIGNED, RONLY, ospfv3GeneralGroup,
264 3, {1, 1, 19}},
265 {OSPFv3RESTARTEXITREASON, INTEGER, RONLY, ospfv3GeneralGroup,
266 3, {1, 1, 20}},
267 {OSPFv3NOTIFICATIONENABLE, INTEGER, RWRITE, ospfv3GeneralGroup,
268 3, {1, 1, 21}},
269 {OSPFv3STUBROUTERSUPPORT, INTEGER, RONLY, ospfv3GeneralGroup,
270 3, {1, 1, 22}},
271 {OSPFv3STUBROUTERADVERTISEMENT, INTEGER, RWRITE, ospfv3GeneralGroup,
272 3, {1, 1, 23}},
273 {OSPFv3DISCONTINUITYTIME, TIMETICKS, RONLY, ospfv3GeneralGroup,
274 3, {1, 1, 24}},
275 {OSPFv3RESTARTTIME, TIMETICKS, RONLY, ospfv3GeneralGroup,
276 3, {1, 1, 25}},
277
278 /* OSPFv3 Area Data Structure */
279 {OSPFv3IMPORTASEXTERN, INTEGER, RWRITE, ospfv3AreaEntry,
280 4, {1, 2, 1, 2}},
281 {OSPFv3AREASPFRUNS, COUNTER, RONLY, ospfv3AreaEntry,
282 4, {1, 2, 1, 3}},
283 {OSPFv3AREABDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry,
284 4, {1, 2, 1, 4}},
285 {OSPFv3AREAASBDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry,
286 4, {1, 2, 1, 5}},
287 {OSPFv3AREASCOPELSACOUNT, GAUGE, RONLY, ospfv3AreaEntry,
288 4, {1, 2, 1, 6}},
289 {OSPFv3AREASCOPELSACKSUMSUM, UNSIGNED, RONLY, ospfv3AreaEntry,
290 4, {1, 2, 1, 7}},
291 {OSPFv3AREASUMMARY, INTEGER, RWRITE, ospfv3AreaEntry,
292 4, {1, 2, 1, 8}},
293 {OSPFv3AREAROWSTATUS, INTEGER, RWRITE, ospfv3AreaEntry,
294 4, {1, 2, 1, 9}},
295 {OSPFv3AREASTUBMETRIC, INTEGER, RWRITE, ospfv3AreaEntry,
296 4, {1, 2, 1, 10}},
297 {OSPFv3AREANSSATRANSLATORROLE, INTEGER, RWRITE, ospfv3AreaEntry,
298 4, {1, 2, 1, 11}},
299 {OSPFv3AREANSSATRANSLATORSTATE, INTEGER, RONLY, ospfv3AreaEntry,
300 4, {1, 2, 1, 12}},
301 {OSPFv3AREANSSATRANSLATORSTABINTERVAL, UNSIGNED, RWRITE, ospfv3AreaEntry,
302 4, {1, 2, 1, 13}},
303 {OSPFv3AREANSSATRANSLATOREVENTS, COUNTER, RONLY, ospfv3AreaEntry,
304 4, {1, 2, 1, 14}},
305 {OSPFv3AREASTUBMETRICTYPE, INTEGER, RWRITE, ospfv3AreaEntry,
306 4, {1, 2, 1, 15}},
307 {OSPFv3AREATEENABLED, INTEGER, RWRITE, ospfv3AreaEntry,
308 4, {1, 2, 1, 16}},
309
310 /* OSPFv3 AS LSDB */
311 {OSPFv3WWLSDBSEQUENCE | OSPFv3WWASTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
312 4, {1, 3, 1, 4}},
313 {OSPFv3WWLSDBAGE | OSPFv3WWASTABLE, UNSIGNED, RONLY, ospfv3WwLsdbEntry,
314 4, {1, 3, 1, 5}},
315 {OSPFv3WWLSDBCHECKSUM | OSPFv3WWASTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
316 4, {1, 3, 1, 6}},
317 {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWASTABLE, STRING, RONLY, ospfv3WwLsdbEntry,
318 4, {1, 3, 1, 7}},
319 {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWASTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
320 4, {1, 3, 1, 8}},
321
322 /* OSPFv3 Area LSDB */
323 {OSPFv3WWLSDBSEQUENCE | OSPFv3WWAREATABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
324 4, {1, 4, 1, 5}},
325 {OSPFv3WWLSDBAGE | OSPFv3WWAREATABLE, UNSIGNED, RONLY, ospfv3WwLsdbEntry,
326 4, {1, 4, 1, 6}},
327 {OSPFv3WWLSDBCHECKSUM | OSPFv3WWAREATABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
328 4, {1, 4, 1, 7}},
329 {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWAREATABLE, STRING, RONLY, ospfv3WwLsdbEntry,
330 4, {1, 4, 1, 8}},
331 {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWAREATABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
332 4, {1, 4, 1, 9}},
333
334 /* OSPFv3 Link LSDB */
335 {OSPFv3WWLSDBSEQUENCE | OSPFv3WWLINKTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
336 4, {1, 5, 1, 6}},
337 {OSPFv3WWLSDBAGE | OSPFv3WWLINKTABLE, UNSIGNED, RONLY, ospfv3WwLsdbEntry,
338 4, {1, 5, 1, 7}},
339 {OSPFv3WWLSDBCHECKSUM | OSPFv3WWLINKTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
340 4, {1, 5, 1, 8}},
341 {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWLINKTABLE, STRING, RONLY, ospfv3WwLsdbEntry,
342 4, {1, 5, 1, 9}},
343 {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWLINKTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
344 4, {1, 5, 1, 10}},
345
346 /* OSPFv3 interfaces */
347 {OSPFv3IFAREAID, UNSIGNED, RONLY, ospfv3IfEntry,
348 4, {1, 7, 1, 3}},
349 {OSPFv3IFTYPE, INTEGER, RONLY, ospfv3IfEntry,
350 4, {1, 7, 1, 4}},
351 {OSPFv3IFADMINSTATUS, INTEGER, RONLY, ospfv3IfEntry,
352 4, {1, 7, 1, 5}},
353 {OSPFv3IFRTRPRIORITY, INTEGER, RONLY, ospfv3IfEntry,
354 4, {1, 7, 1, 6}},
355 {OSPFv3IFTRANSITDELAY, UNSIGNED, RONLY, ospfv3IfEntry,
356 4, {1, 7, 1, 7}},
357 {OSPFv3IFRETRANSINTERVAL, UNSIGNED, RONLY, ospfv3IfEntry,
358 4, {1, 7, 1, 8}},
359 {OSPFv3IFHELLOINTERVAL, INTEGER, RONLY, ospfv3IfEntry,
360 4, {1, 7, 1, 9}},
361 {OSPFv3IFRTRDEADINTERVAL, UNSIGNED, RONLY, ospfv3IfEntry,
362 4, {1, 7, 1, 10}},
363 {OSPFv3IFPOLLINTERVAL, UNSIGNED, RONLY, ospfv3IfEntry,
364 4, {1, 7, 1, 11}},
365 {OSPFv3IFSTATE, INTEGER, RONLY, ospfv3IfEntry,
366 4, {1, 7, 1, 12}},
367 {OSPFv3IFDESIGNATEDROUTER, UNSIGNED, RONLY, ospfv3IfEntry,
368 4, {1, 7, 1, 13}},
369 {OSPFv3IFBACKUPDESIGNATEDROUTER, UNSIGNED, RONLY, ospfv3IfEntry,
370 4, {1, 7, 1, 14}},
371 {OSPFv3IFEVENTS, COUNTER, RONLY, ospfv3IfEntry,
372 4, {1, 7, 1, 15}},
373 {OSPFv3IFROWSTATUS, INTEGER, RONLY, ospfv3IfEntry,
374 4, {1, 7, 1, 16}},
375 {OSPFv3IFDEMAND, INTEGER, RONLY, ospfv3IfEntry,
376 4, {1, 7, 1, 17}},
377 {OSPFv3IFMETRICVALUE, INTEGER, RONLY, ospfv3IfEntry,
378 4, {1, 7, 1, 18}},
379 {OSPFv3IFLINKSCOPELSACOUNT, GAUGE, RONLY, ospfv3IfEntry,
380 4, {1, 7, 1, 19}},
381 {OSPFv3IFLINKLSACKSUMSUM, UNSIGNED, RONLY, ospfv3IfEntry,
382 4, {1, 7, 1, 20}},
383 {OSPFv3IFDEMANDNBRPROBE, INTEGER, RONLY, ospfv3IfEntry,
384 4, {1, 7, 1, 21}},
385 {OSPFv3IFDEMANDNBRPROBERETRANSLIMIT, UNSIGNED, RONLY, ospfv3IfEntry,
386 4, {1, 7, 1, 22}},
387 {OSPFv3IFDEMANDNBRPROBEINTERVAL, UNSIGNED, RONLY, ospfv3IfEntry,
388 4, {1, 7, 1, 23}},
389 {OSPFv3IFTEDISABLED, INTEGER, RONLY, ospfv3IfEntry,
390 4, {1, 7, 1, 24}},
391 {OSPFv3IFLINKLSASUPPRESSION, INTEGER, RONLY, ospfv3IfEntry,
392 4, {1, 7, 1, 25}},
393
394 /* OSPFv3 neighbors */
395 {OSPFv3NBRADDRESSTYPE, INTEGER, RONLY, ospfv3NbrEntry,
396 4, {1, 9, 1, 4}},
397 {OSPFv3NBRADDRESS, STRING, RONLY, ospfv3NbrEntry,
398 4, {1, 9, 1, 5}},
399 {OSPFv3NBROPTIONS, INTEGER, RONLY, ospfv3NbrEntry,
400 4, {1, 9, 1, 6}},
401 {OSPFv3NBRPRIORITY, INTEGER, RONLY, ospfv3NbrEntry,
402 4, {1, 9, 1, 7}},
403 {OSPFv3NBRSTATE, INTEGER, RONLY, ospfv3NbrEntry,
404 4, {1, 9, 1, 8}},
405 {OSPFv3NBREVENTS, COUNTER, RONLY, ospfv3NbrEntry,
406 4, {1, 9, 1, 9}},
407 {OSPFv3NBRLSRETRANSQLEN, GAUGE, RONLY, ospfv3NbrEntry,
408 4, {1, 9, 1, 10}},
409 {OSPFv3NBRHELLOSUPPRESSED, INTEGER, RONLY, ospfv3NbrEntry,
410 4, {1, 9, 1, 11}},
411 {OSPFv3NBRIFID, INTEGER, RONLY, ospfv3NbrEntry,
412 4, {1, 9, 1, 12}},
413 {OSPFv3NBRRESTARTHELPERSTATUS, INTEGER, RONLY, ospfv3NbrEntry,
414 4, {1, 9, 1, 13}},
415 {OSPFv3NBRRESTARTHELPERAGE, UNSIGNED, RONLY, ospfv3NbrEntry,
416 4, {1, 9, 1, 14}},
417 {OSPFv3NBRRESTARTHELPEREXITREASON, INTEGER, RONLY, ospfv3NbrEntry,
418 4, {1, 9, 1, 15}},
419 };
420
421 static u_char *
422 ospfv3GeneralGroup (struct variable *v, oid *name, size_t *length,
423 int exact, size_t *var_len, WriteMethod **write_method)
424 {
425 u_int16_t sum;
426 u_int32_t count;
427 struct ospf6_lsa *lsa = NULL;
428
429 /* Check whether the instance identifier is valid */
430 if (smux_header_generic (v, name, length, exact, var_len, write_method)
431 == MATCH_FAILED)
432 return NULL;
433
434 /* Return the current value of the variable */
435 switch (v->magic)
436 {
437 case OSPFv3ROUTERID:
438 /* Router-ID of this OSPF instance. */
439 if (ospf6)
440 return SNMP_INTEGER (ntohl (ospf6->router_id));
441 return SNMP_INTEGER (0);
442 case OSPFv3ADMINSTAT:
443 if (ospf6)
444 return SNMP_INTEGER (CHECK_FLAG (ospf6->flag, OSPF6_DISABLED)?
445 OSPF_STATUS_DISABLED:OSPF_STATUS_ENABLED);
446 return SNMP_INTEGER (OSPF_STATUS_DISABLED);
447 case OSPFv3VERSIONNUMBER:
448 return SNMP_INTEGER (3);
449 case OSPFv3AREABDRRTRSTATUS:
450 if (ospf6)
451 return SNMP_INTEGER (ospf6_is_router_abr (ospf6)?SNMP_TRUE:SNMP_FALSE);
452 return SNMP_INTEGER (SNMP_FALSE);
453 case OSPFv3ASBDRRTRSTATUS:
454 if (ospf6)
455 return SNMP_INTEGER (ospf6_asbr_is_asbr (ospf6)?SNMP_TRUE:SNMP_FALSE);
456 return SNMP_INTEGER (SNMP_FALSE);
457 case OSPFv3ASSCOPELSACOUNT:
458 if (ospf6)
459 return SNMP_INTEGER (ospf6->lsdb->count);
460 return SNMP_INTEGER (0);
461 case OSPFv3ASSCOPELSACHECKSUMSUM:
462 if (ospf6)
463 {
464 for (sum = 0, lsa = ospf6_lsdb_head (ospf6->lsdb);
465 lsa;
466 lsa = ospf6_lsdb_next (lsa))
467 sum += ntohs (lsa->header->checksum);
468 return SNMP_INTEGER (sum);
469 }
470 return SNMP_INTEGER (0);
471 case OSPFv3ORIGINATENEWLSAS:
472 return SNMP_INTEGER (0); /* Don't know where to get this value... */
473 case OSPFv3RXNEWLSAS:
474 return SNMP_INTEGER (0); /* Don't know where to get this value... */
475 case OSPFv3EXTLSACOUNT:
476 if (ospf6)
477 {
478 for (count = 0, lsa = ospf6_lsdb_type_head (htons (OSPF6_LSTYPE_AS_EXTERNAL),
479 ospf6->lsdb);
480 lsa;
481 lsa = ospf6_lsdb_type_next (htons (OSPF6_LSTYPE_AS_EXTERNAL),
482 lsa))
483 count += 1;
484 return SNMP_INTEGER (count);
485 }
486 return SNMP_INTEGER (0);
487 case OSPFv3EXTAREALSDBLIMIT:
488 return SNMP_INTEGER (-1);
489 case OSPFv3EXITOVERFLOWINTERVAL:
490 return SNMP_INTEGER (0); /* Not supported */
491 case OSPFv3DEMANDEXTENSIONS:
492 return SNMP_INTEGER (0); /* Not supported */
493 case OSPFv3REFERENCEBANDWIDTH:
494 if (ospf6)
495 return SNMP_INTEGER (ospf6->ref_bandwidth);
496 /* Otherwise, like for "not implemented". */
497 case OSPFv3RESTARTSUPPORT:
498 case OSPFv3RESTARTINTERVAL:
499 case OSPFv3RESTARTSTRICTLSACHECKING:
500 case OSPFv3RESTARTSTATUS:
501 case OSPFv3RESTARTAGE:
502 case OSPFv3RESTARTEXITREASON:
503 case OSPFv3NOTIFICATIONENABLE:
504 case OSPFv3STUBROUTERSUPPORT:
505 case OSPFv3STUBROUTERADVERTISEMENT:
506 case OSPFv3DISCONTINUITYTIME:
507 case OSPFv3RESTARTTIME:
508 /* TODO: Not implemented */
509 return NULL;
510 }
511 return NULL;
512 }
513
514 static u_char *
515 ospfv3AreaEntry (struct variable *v, oid *name, size_t *length,
516 int exact, size_t *var_len, WriteMethod **write_method)
517 {
518 struct ospf6_area *oa, *area = NULL;
519 struct ospf6_lsa *lsa = NULL;
520 u_int32_t area_id = 0;
521 u_int32_t count;
522 u_int16_t sum;
523 struct listnode *node;
524 unsigned int len;
525 char a[16];
526 struct ospf6_route *ro;
527
528 if (ospf6 == NULL)
529 return NULL;
530
531 if (smux_header_table(v, name, length, exact, var_len, write_method)
532 == MATCH_FAILED)
533 return NULL;
534
535 len = *length - v->namelen;
536 len = (len >= 1 ? 1 : 0);
537 if (exact && len != 1)
538 return NULL;
539 if (len)
540 area_id = htonl (name[v->namelen]);
541
542 inet_ntop (AF_INET, &area_id, a, sizeof (a));
543 zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu",
544 a, exact, len, (u_long)*length);
545
546 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
547 {
548 if (area == NULL)
549 {
550 if (len == 0) /* return first area entry */
551 area = oa;
552 else if (exact && ntohl (oa->area_id) == ntohl (area_id))
553 area = oa;
554 else if (ntohl (oa->area_id) > ntohl (area_id))
555 area = oa;
556 }
557 }
558
559 if (area == NULL)
560 return NULL;
561
562 *length = v->namelen + 1;
563 name[v->namelen] = ntohl (area->area_id);
564
565 inet_ntop (AF_INET, &area->area_id, a, sizeof (a));
566 zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu",
567 a, exact, len, (u_long)*length);
568
569 switch (v->magic)
570 {
571 case OSPFv3IMPORTASEXTERN:
572 /* No NSSA support */
573 return SNMP_INTEGER (IS_AREA_STUB(area)?2:1);
574 case OSPFv3AREASPFRUNS:
575 return SNMP_INTEGER (area->spf_calculation);
576 case OSPFv3AREABDRRTRCOUNT:
577 case OSPFv3AREAASBDRRTRCOUNT:
578 count = 0;
579 for (ro = ospf6_route_head (ospf6->brouter_table); ro;
580 ro = ospf6_route_next (ro))
581 {
582 if (ntohl (ro->path.area_id) != ntohl (area->area_id)) continue;
583 if (v->magic == OSPFv3AREABDRRTRCOUNT &&
584 CHECK_FLAG (ro->path.router_bits, OSPF6_ROUTER_BIT_B))
585 count++;
586 if (v->magic == OSPFv3AREAASBDRRTRCOUNT &&
587 CHECK_FLAG (ro->path.router_bits, OSPF6_ROUTER_BIT_E))
588 count++;
589 }
590 return SNMP_INTEGER (count);
591 case OSPFv3AREASCOPELSACOUNT:
592 return SNMP_INTEGER (area->lsdb->count);
593 case OSPFv3AREASCOPELSACKSUMSUM:
594 for (sum = 0, lsa = ospf6_lsdb_head (area->lsdb);
595 lsa;
596 lsa = ospf6_lsdb_next (lsa))
597 sum += ntohs (lsa->header->checksum);
598 return SNMP_INTEGER (sum);
599 case OSPFv3AREASUMMARY:
600 return SNMP_INTEGER (2); /* sendAreaSummary */
601 case OSPFv3AREAROWSTATUS:
602 return SNMP_INTEGER (1); /* Active */
603 case OSPFv3AREASTUBMETRIC:
604 case OSPFv3AREANSSATRANSLATORROLE:
605 case OSPFv3AREANSSATRANSLATORSTATE:
606 case OSPFv3AREANSSATRANSLATORSTABINTERVAL:
607 case OSPFv3AREANSSATRANSLATOREVENTS:
608 case OSPFv3AREASTUBMETRICTYPE:
609 case OSPFv3AREATEENABLED:
610 /* Not implemented. */
611 return NULL;
612 }
613 return NULL;
614 }
615
616 static int
617 if_icmp_func (struct interface *ifp1, struct interface *ifp2)
618 {
619 return (ifp1->ifindex - ifp2->ifindex);
620 }
621
622 static u_char *
623 ospfv3WwLsdbEntry (struct variable *v, oid *name, size_t *length,
624 int exact, size_t *var_len, WriteMethod **write_method)
625 {
626 struct ospf6_lsa *lsa = NULL;
627 ifindex_t ifindex;
628 uint32_t area_id, id, instid, adv_router;
629 u_int16_t type;
630 int len;
631 oid *offset;
632 int offsetlen;
633 struct ospf6_area *oa = NULL;
634 struct listnode *node;
635 struct interface *iif;
636 struct ospf6_interface *oi = NULL;
637 struct list *ifslist;
638
639 if (smux_header_table(v, name, length, exact, var_len, write_method)
640 == MATCH_FAILED)
641 return NULL;
642
643 instid = ifindex = area_id = type = id = adv_router = 0;
644
645 /* Check OSPFv3 instance. */
646 if (ospf6 == NULL)
647 return NULL;
648
649 /* Get variable length. */
650 offset = name + v->namelen;
651 offsetlen = *length - v->namelen;
652
653 if (exact && (v->magic & OSPFv3WWASTABLE) && offsetlen != 3)
654 return NULL;
655 if (exact && (v->magic & OSPFv3WWAREATABLE) && offsetlen != 4)
656 return NULL;
657 if (exact && (v->magic & OSPFv3WWLINKTABLE) && offsetlen != 5)
658 return NULL;
659
660 if (v->magic & OSPFv3WWLINKTABLE)
661 {
662 /* Parse ifindex */
663 len = (offsetlen < 1 ? 0 : 1);
664 if (len)
665 ifindex = *offset;
666 offset += len;
667 offsetlen -= len;
668
669 /* Parse instance ID */
670 len = (offsetlen < 1 ? 0 : 1);
671 if (len)
672 instid = *offset;
673 offset += len;
674 offsetlen -= len;
675 }
676 else if (v->magic & OSPFv3WWAREATABLE)
677 {
678 /* Parse area-id */
679 len = (offsetlen < 1 ? 0 : 1);
680 if (len)
681 area_id = htonl (*offset);
682 offset += len;
683 offsetlen -= len;
684 }
685
686 /* Parse type */
687 len = (offsetlen < 1 ? 0 : 1);
688 if (len)
689 type = htons (*offset);
690 offset += len;
691 offsetlen -= len;
692
693 /* Parse Router-ID */
694 len = (offsetlen < 1 ? 0 : 1);
695 if (len)
696 adv_router = htonl (*offset);
697 offset += len;
698 offsetlen -= len;
699
700 /* Parse LS-ID */
701 len = (offsetlen < 1 ? 0 : 1);
702 if (len)
703 id = htonl (*offset);
704 offset += len;
705 offsetlen -= len;
706
707 if (exact)
708 {
709 if (v->magic & OSPFv3WWASTABLE)
710 {
711 lsa = ospf6_lsdb_lookup (type, id, adv_router, ospf6->lsdb);
712 }
713 else if (v->magic & OSPFv3WWAREATABLE)
714 {
715 oa = ospf6_area_lookup (area_id, ospf6);
716 if (!oa) return NULL;
717 lsa = ospf6_lsdb_lookup (type, id, adv_router, oa->lsdb);
718 }
719 else if (v->magic & OSPFv3WWLINKTABLE)
720 {
721 oi = ospf6_interface_lookup_by_ifindex (ifindex);
722 if (!oi || oi->instance_id != instid) return NULL;
723 lsa = ospf6_lsdb_lookup (type, id, adv_router, oi->lsdb);
724 }
725 }
726 else
727 {
728 if (v->magic & OSPFv3WWASTABLE)
729 {
730 if (ospf6->lsdb->count)
731 lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
732 ospf6->lsdb);
733 }
734 else if (v->magic & OSPFv3WWAREATABLE)
735 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
736 {
737 if (oa->area_id < area_id)
738 continue;
739
740 if (oa->lsdb->count)
741 lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
742 oa->lsdb);
743 if (lsa) break;
744 type = 0;
745 id = 0;
746 adv_router = 0;
747 }
748 else if (v->magic & OSPFv3WWLINKTABLE)
749 {
750 /* We build a sorted list of interfaces */
751 ifslist = list_new ();
752 if (!ifslist) return NULL;
753 ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
754 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, iif))
755 listnode_add_sort (ifslist, iif);
756
757 for (ALL_LIST_ELEMENTS_RO (ifslist, node, iif))
758 {
759 if (!iif->ifindex) continue;
760 oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
761 if (!oi) continue;
762 if (iif->ifindex < ifindex) continue;
763 if (oi->instance_id < instid) continue;
764
765 if (oi->lsdb->count)
766 lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
767 oi->lsdb);
768 if (lsa) break;
769 type = 0;
770 id = 0;
771 adv_router = 0;
772 oi = NULL;
773 }
774
775 list_delete_all_node (ifslist);
776 }
777 }
778
779 if (! lsa)
780 return NULL;
781
782 /* Add indexes */
783 if (v->magic & OSPFv3WWASTABLE)
784 {
785 *length = v->namelen + 3;
786 offset = name + v->namelen;
787 }
788 else if (v->magic & OSPFv3WWAREATABLE)
789 {
790 *length = v->namelen + 4;
791 offset = name + v->namelen;
792 *offset = ntohl (oa->area_id);
793 offset++;
794 }
795 else if (v->magic & OSPFv3WWLINKTABLE)
796 {
797 *length = v->namelen + 5;
798 offset = name + v->namelen;
799 *offset = oi->interface->ifindex;
800 offset++;
801 *offset = oi->instance_id;
802 offset++;
803 }
804 *offset = ntohs (lsa->header->type);
805 offset++;
806 *offset = ntohl (lsa->header->adv_router);
807 offset++;
808 *offset = ntohl (lsa->header->id);
809 offset++;
810
811 /* Return the current value of the variable */
812 switch (v->magic & OSPFv3WWCOLUMN)
813 {
814 case OSPFv3WWLSDBSEQUENCE:
815 return SNMP_INTEGER (ntohl (lsa->header->seqnum));
816 break;
817 case OSPFv3WWLSDBAGE:
818 ospf6_lsa_age_current (lsa);
819 return SNMP_INTEGER (ntohs (lsa->header->age));
820 break;
821 case OSPFv3WWLSDBCHECKSUM:
822 return SNMP_INTEGER (ntohs (lsa->header->checksum));
823 break;
824 case OSPFv3WWLSDBADVERTISEMENT:
825 *var_len = ntohs (lsa->header->length);
826 return (u_char *) lsa->header;
827 break;
828 case OSPFv3WWLSDBTYPEKNOWN:
829 return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ?
830 SNMP_TRUE : SNMP_FALSE);
831 break;
832 }
833 return NULL;
834 }
835
836 static u_char *
837 ospfv3IfEntry (struct variable *v, oid *name, size_t *length,
838 int exact, size_t *var_len, WriteMethod **write_method)
839 {
840 ifindex_t ifindex = 0;
841 unsigned int instid = 0;
842 struct ospf6_interface *oi = NULL;
843 struct ospf6_lsa *lsa = NULL;
844 struct interface *iif;
845 struct listnode *i;
846 struct list *ifslist;
847 oid *offset;
848 int offsetlen, len;
849 u_int32_t sum;
850
851 if (smux_header_table (v, name, length, exact, var_len, write_method)
852 == MATCH_FAILED)
853 return NULL;
854
855 /* Check OSPFv3 instance. */
856 if (ospf6 == NULL)
857 return NULL;
858
859 /* Get variable length. */
860 offset = name + v->namelen;
861 offsetlen = *length - v->namelen;
862
863 if (exact && offsetlen != 2)
864 return NULL;
865
866 /* Parse if index */
867 len = (offsetlen < 1 ? 0 : 1);
868 if (len)
869 ifindex = *offset;
870 offset += len;
871 offsetlen -= len;
872
873 /* Parse instance ID */
874 len = (offsetlen < 1 ? 0 : 1);
875 if (len)
876 instid = *offset;
877 offset += len;
878 offsetlen -= len;
879
880 if (exact)
881 {
882 oi = ospf6_interface_lookup_by_ifindex (ifindex);
883 if (!oi || oi->instance_id != instid) return NULL;
884 }
885 else
886 {
887 /* We build a sorted list of interfaces */
888 ifslist = list_new ();
889 if (!ifslist) return NULL;
890 ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
891 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), i, iif))
892 listnode_add_sort (ifslist, iif);
893
894 for (ALL_LIST_ELEMENTS_RO (ifslist, i, iif))
895 {
896 if (!iif->ifindex) continue;
897 oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
898 if (!oi) continue;
899 if (iif->ifindex > ifindex ||
900 (iif->ifindex == ifindex &&
901 (oi->instance_id > instid)))
902 break;
903 oi = NULL;
904 }
905
906 list_delete_all_node (ifslist);
907 }
908
909 if (!oi) return NULL;
910
911 /* Add Index (IfIndex, IfInstId) */
912 *length = v->namelen + 2;
913 offset = name + v->namelen;
914 *offset = oi->interface->ifindex;
915 offset++;
916 *offset = oi->instance_id;
917 offset++;
918
919 /* Return the current value of the variable */
920 switch (v->magic)
921 {
922 case OSPFv3IFAREAID:
923 if (oi->area)
924 return SNMP_INTEGER (ntohl (oi->area->area_id));
925 break;
926 case OSPFv3IFTYPE:
927 if (if_is_broadcast (oi->interface))
928 return SNMP_INTEGER (1);
929 else if (if_is_pointopoint (oi->interface))
930 return SNMP_INTEGER (3);
931 else break; /* Unknown, don't put anything */
932 case OSPFv3IFADMINSTATUS:
933 if (oi->area)
934 return SNMP_INTEGER (OSPF_STATUS_ENABLED);
935 return SNMP_INTEGER (OSPF_STATUS_DISABLED);
936 case OSPFv3IFRTRPRIORITY:
937 return SNMP_INTEGER (oi->priority);
938 case OSPFv3IFTRANSITDELAY:
939 return SNMP_INTEGER (oi->transdelay);
940 case OSPFv3IFRETRANSINTERVAL:
941 return SNMP_INTEGER (oi->rxmt_interval);
942 case OSPFv3IFHELLOINTERVAL:
943 return SNMP_INTEGER (oi->hello_interval);
944 case OSPFv3IFRTRDEADINTERVAL:
945 return SNMP_INTEGER (oi->dead_interval);
946 case OSPFv3IFPOLLINTERVAL:
947 /* No support for NBMA */
948 break;
949 case OSPFv3IFSTATE:
950 return SNMP_INTEGER (oi->state);
951 case OSPFv3IFDESIGNATEDROUTER:
952 return SNMP_INTEGER (ntohl (oi->drouter));
953 case OSPFv3IFBACKUPDESIGNATEDROUTER:
954 return SNMP_INTEGER (ntohl (oi->bdrouter));
955 case OSPFv3IFEVENTS:
956 return SNMP_INTEGER (oi->state_change);
957 case OSPFv3IFROWSTATUS:
958 return SNMP_INTEGER (1);
959 case OSPFv3IFDEMAND:
960 return SNMP_INTEGER (SNMP_FALSE);
961 case OSPFv3IFMETRICVALUE:
962 return SNMP_INTEGER (oi->cost);
963 case OSPFv3IFLINKSCOPELSACOUNT:
964 return SNMP_INTEGER (oi->lsdb->count);
965 case OSPFv3IFLINKLSACKSUMSUM:
966 for (sum = 0, lsa = ospf6_lsdb_head (oi->lsdb);
967 lsa;
968 lsa = ospf6_lsdb_next (lsa))
969 sum += ntohs (lsa->header->checksum);
970 return SNMP_INTEGER (sum);
971 case OSPFv3IFDEMANDNBRPROBE:
972 case OSPFv3IFDEMANDNBRPROBERETRANSLIMIT:
973 case OSPFv3IFDEMANDNBRPROBEINTERVAL:
974 case OSPFv3IFTEDISABLED:
975 case OSPFv3IFLINKLSASUPPRESSION:
976 /* Not implemented. Only works if all the last ones are not
977 implemented! */
978 return NULL;
979 }
980
981 /* Try an internal getnext. Some columns are missing in this table. */
982 if (!exact && (name[*length-1] < MAX_SUBID))
983 return ospfv3IfEntry(v, name, length,
984 exact, var_len, write_method);
985 return NULL;
986 }
987
988 static u_char *
989 ospfv3NbrEntry (struct variable *v, oid *name, size_t *length,
990 int exact, size_t *var_len, WriteMethod **write_method)
991 {
992 ifindex_t ifindex = 0;
993 unsigned int instid, rtrid;
994 struct ospf6_interface *oi = NULL;
995 struct ospf6_neighbor *on = NULL;
996 struct interface *iif;
997 struct listnode *i, *j;
998 struct list *ifslist;
999 oid *offset;
1000 int offsetlen, len;
1001
1002 if (smux_header_table (v, name, length, exact, var_len, write_method)
1003 == MATCH_FAILED)
1004 return NULL;
1005
1006 instid = rtrid = 0;
1007
1008 /* Check OSPFv3 instance. */
1009 if (ospf6 == NULL)
1010 return NULL;
1011
1012 /* Get variable length. */
1013 offset = name + v->namelen;
1014 offsetlen = *length - v->namelen;
1015
1016 if (exact && offsetlen != 3)
1017 return NULL;
1018
1019 /* Parse if index */
1020 len = (offsetlen < 1 ? 0 : 1);
1021 if (len)
1022 ifindex = *offset;
1023 offset += len;
1024 offsetlen -= len;
1025
1026 /* Parse instance ID */
1027 len = (offsetlen < 1 ? 0 : 1);
1028 if (len)
1029 instid = *offset;
1030 offset += len;
1031 offsetlen -= len;
1032
1033 /* Parse router ID */
1034 len = (offsetlen < 1 ? 0 : 1);
1035 if (len)
1036 rtrid = htonl (*offset);
1037 offset += len;
1038 offsetlen -= len;
1039
1040 if (exact)
1041 {
1042 oi = ospf6_interface_lookup_by_ifindex (ifindex);
1043 if (!oi || oi->instance_id != instid) return NULL;
1044 on = ospf6_neighbor_lookup (rtrid, oi);
1045 }
1046 else
1047 {
1048 /* We build a sorted list of interfaces */
1049 ifslist = list_new ();
1050 if (!ifslist) return NULL;
1051 ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
1052 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), i, iif))
1053 listnode_add_sort (ifslist, iif);
1054
1055 for (ALL_LIST_ELEMENTS_RO (ifslist, i, iif))
1056 {
1057 if (!iif->ifindex) continue;
1058 oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
1059 if (!oi) continue;
1060 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) {
1061 if (iif->ifindex > ifindex ||
1062 (iif->ifindex == ifindex &&
1063 (oi->instance_id > instid ||
1064 (oi->instance_id == instid &&
1065 ntohl (on->router_id) > ntohl (rtrid)))))
1066 break;
1067 }
1068 if (on) break;
1069 oi = NULL;
1070 on = NULL;
1071 }
1072
1073 list_delete_all_node (ifslist);
1074 }
1075
1076 if (!oi || !on) return NULL;
1077
1078 /* Add Index (IfIndex, IfInstId, RtrId) */
1079 *length = v->namelen + 3;
1080 offset = name + v->namelen;
1081 *offset = oi->interface->ifindex;
1082 offset++;
1083 *offset = oi->instance_id;
1084 offset++;
1085 *offset = ntohl (on->router_id);
1086 offset++;
1087
1088 /* Return the current value of the variable */
1089 switch (v->magic)
1090 {
1091 case OSPFv3NBRADDRESSTYPE:
1092 return SNMP_INTEGER (2); /* IPv6 only */
1093 case OSPFv3NBRADDRESS:
1094 *var_len = sizeof (struct in6_addr);
1095 return (u_char *) &on->linklocal_addr;
1096 case OSPFv3NBROPTIONS:
1097 return SNMP_INTEGER (on->options[2]);
1098 case OSPFv3NBRPRIORITY:
1099 return SNMP_INTEGER (on->priority);
1100 case OSPFv3NBRSTATE:
1101 return SNMP_INTEGER (on->state);
1102 case OSPFv3NBREVENTS:
1103 return SNMP_INTEGER (on->state_change);
1104 case OSPFv3NBRLSRETRANSQLEN:
1105 return SNMP_INTEGER (on->retrans_list->count);
1106 case OSPFv3NBRHELLOSUPPRESSED:
1107 return SNMP_INTEGER (SNMP_FALSE);
1108 case OSPFv3NBRIFID:
1109 return SNMP_INTEGER (on->ifindex);
1110 case OSPFv3NBRRESTARTHELPERSTATUS:
1111 case OSPFv3NBRRESTARTHELPERAGE:
1112 case OSPFv3NBRRESTARTHELPEREXITREASON:
1113 /* Not implemented. Only works if all the last ones are not
1114 implemented! */
1115 return NULL;
1116 }
1117
1118 return NULL;
1119 }
1120
1121 /* OSPF Traps. */
1122 #define NBRSTATECHANGE 2
1123 #define IFSTATECHANGE 10
1124
1125 static struct trap_object ospf6NbrTrapList[] =
1126 {
1127 {-3, {1, 1, OSPFv3ROUTERID}},
1128 {4, {1, 9, 1, OSPFv3NBRADDRESSTYPE}},
1129 {4, {1, 9, 1, OSPFv3NBRADDRESS}},
1130 {4, {1, 9, 1, OSPFv3NBRSTATE}}
1131 };
1132
1133 static struct trap_object ospf6IfTrapList[] =
1134 {
1135 {-3, {1, 1, OSPFv3ROUTERID}},
1136 {4, {1, 7, 1, OSPFv3IFSTATE}},
1137 {4, {1, 7, 1, OSPFv3IFADMINSTATUS}},
1138 {4, {1, 7, 1, OSPFv3IFAREAID}}
1139 };
1140
1141 static int
1142 ospf6TrapNbrStateChange (struct ospf6_neighbor *on,
1143 int next_state, int prev_state)
1144 {
1145 oid index[3];
1146
1147 /* Terminal state or regression */
1148 if ((next_state != OSPF6_NEIGHBOR_FULL) &&
1149 (next_state != OSPF6_NEIGHBOR_TWOWAY) &&
1150 (next_state >= prev_state))
1151 return 0;
1152
1153 index[0] = on->ospf6_if->interface->ifindex;
1154 index[1] = on->ospf6_if->instance_id;
1155 index[2] = ntohl (on->router_id);
1156
1157 smux_trap (ospfv3_variables, sizeof ospfv3_variables / sizeof (struct variable),
1158 ospfv3_trap_oid, sizeof ospfv3_trap_oid / sizeof (oid),
1159 ospfv3_oid, sizeof ospfv3_oid / sizeof (oid),
1160 index, 3,
1161 ospf6NbrTrapList,
1162 sizeof ospf6NbrTrapList / sizeof (struct trap_object),
1163 NBRSTATECHANGE);
1164 return 0;
1165 }
1166
1167 static int
1168 ospf6TrapIfStateChange (struct ospf6_interface *oi,
1169 int next_state, int prev_state)
1170 {
1171 oid index[2];
1172
1173 /* Terminal state or regression */
1174 if ((next_state != OSPF6_INTERFACE_POINTTOPOINT) &&
1175 (next_state != OSPF6_INTERFACE_DROTHER) &&
1176 (next_state != OSPF6_INTERFACE_BDR) &&
1177 (next_state != OSPF6_INTERFACE_DR) &&
1178 (next_state >= prev_state))
1179 return 0;
1180
1181 index[0] = oi->interface->ifindex;
1182 index[1] = oi->instance_id;
1183
1184 smux_trap (ospfv3_variables, sizeof ospfv3_variables / sizeof (struct variable),
1185 ospfv3_trap_oid, sizeof ospfv3_trap_oid / sizeof (oid),
1186 ospfv3_oid, sizeof ospfv3_oid / sizeof (oid),
1187 index, 2,
1188 ospf6IfTrapList,
1189 sizeof ospf6IfTrapList / sizeof (struct trap_object),
1190 IFSTATECHANGE);
1191 return 0;
1192 }
1193
1194 /* Register OSPFv3-MIB. */
1195 static int
1196 ospf6_snmp_init (struct thread_master *master)
1197 {
1198 smux_init (master);
1199 REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
1200 return 0;
1201 }
1202
1203 static int
1204 ospf6_snmp_module_init (void)
1205 {
1206 hook_register(ospf6_interface_change, ospf6TrapIfStateChange);
1207 hook_register(ospf6_neighbor_change, ospf6TrapNbrStateChange);
1208 hook_register(frr_late_init, ospf6_snmp_init);
1209 return 0;
1210 }
1211
1212 FRR_MODULE_SETUP(
1213 .name = "ospf6d_snmp",
1214 .version = FRR_VERSION,
1215 .description = "ospf6d AgentX SNMP module",
1216 .init = ospf6_snmp_module_init,
1217 )