]> git.proxmox.com Git - mirror_frr.git/blob - ospf6d/ospf6_snmp.c
Merge branch 'restricted-mode'
[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 #ifdef HAVE_SNMP
25
26 #ifdef HAVE_NETSNMP
27 #include <net-snmp/net-snmp-config.h>
28 #include <net-snmp/net-snmp-includes.h>
29 #else
30 #include <asn1.h>
31 #include <snmp.h>
32 #include <snmp_impl.h>
33 #endif
34
35 #include "log.h"
36 #include "vty.h"
37 #include "linklist.h"
38 #include "smux.h"
39
40 #include "ospf6_proto.h"
41 #include "ospf6_lsa.h"
42 #include "ospf6_lsdb.h"
43 #include "ospf6_route.h"
44 #include "ospf6_top.h"
45 #include "ospf6_area.h"
46 #include "ospf6_interface.h"
47 #include "ospf6_message.h"
48 #include "ospf6_neighbor.h"
49 #include "ospf6d.h"
50
51 /* OSPFv3-MIB */
52 #define OSPFv3MIB 1,3,6,1,3,102
53
54 /* OSPFv3 MIB General Group values. */
55 #define OSPFv3ROUTERID 1
56 #define OSPFv3ADMINSTAT 2
57 #define OSPFv3VERSIONNUMBER 3
58 #define OSPFv3AREABDRRTRSTATUS 4
59 #define OSPFv3ASBDRRTRSTATUS 5
60 #define OSPFv3ASSCOPELSACOUNT 6
61 #define OSPFv3ASSCOPELSACHECKSUMSUM 7
62 #define OSPFv3ORIGINATENEWLSAS 8
63 #define OSPFv3RXNEWLSAS 9
64 #define OSPFv3EXTLSACOUNT 10
65 #define OSPFv3EXTAREALSDBLIMIT 11
66 #define OSPFv3MULTICASTEXTENSIONS 12
67 #define OSPFv3EXITOVERFLOWINTERVAL 13
68 #define OSPFv3DEMANDEXTENSIONS 14
69 #define OSPFv3TRAFFICENGINEERINGSUPPORT 15
70 #define OSPFv3REFERENCEBANDWIDTH 16
71 #define OSPFv3RESTARTSUPPORT 17
72 #define OSPFv3RESTARTINTERVAL 18
73 #define OSPFv3RESTARTSTATUS 19
74 #define OSPFv3RESTARTAGE 20
75 #define OSPFv3RESTARTEXITREASON 21
76
77 /* OSPFv3 MIB Area Table values. */
78 #define OSPFv3AREAID 1
79 #define OSPFv3IMPORTASEXTERN 2
80 #define OSPFv3AREASPFRUNS 3
81 #define OSPFv3AREABDRRTRCOUNT 4
82 #define OSPFv3AREAASBDRRTRCOUNT 5
83 #define OSPFv3AREASCOPELSACOUNT 6
84 #define OSPFv3AREASCOPELSACKSUMSUM 7
85 #define OSPFv3AREASUMMARY 8
86 #define OSPFv3AREASTATUS 9
87 #define OSPFv3STUBMETRIC 10
88 #define OSPFv3AREANSSATRANSLATORROLE 11
89 #define OSPFv3AREANSSATRANSLATORSTATE 12
90 #define OSPFv3AREANSSATRANSLATORSTABILITYINTERVAL 13
91 #define OSPFv3AREANSSATRANSLATOREVENTS 14
92 #define OSPFv3AREASTUBMETRICTYPE 15
93
94 /* OSPFv3 MIB Area Lsdb Table values. */
95 #define OSPFv3AREALSDBAREAID 1
96 #define OSPFv3AREALSDBTYPE 2
97 #define OSPFv3AREALSDBROUTERID 3
98 #define OSPFv3AREALSDBLSID 4
99 #define OSPFv3AREALSDBSEQUENCE 5
100 #define OSPFv3AREALSDBAGE 6
101 #define OSPFv3AREALSDBCHECKSUM 7
102 #define OSPFv3AREALSDBADVERTISEMENT 8
103 #define OSPFv3AREALSDBTYPEKNOWN 9
104
105 /* SYNTAX Status from OSPF-MIB. */
106 #define OSPF_STATUS_ENABLED 1
107 #define OSPF_STATUS_DISABLED 2
108
109 /* SNMP value hack. */
110 #define COUNTER ASN_COUNTER
111 #define INTEGER ASN_INTEGER
112 #define GAUGE ASN_GAUGE
113 #define TIMETICKS ASN_TIMETICKS
114 #define IPADDRESS ASN_IPADDRESS
115 #define STRING ASN_OCTET_STR
116
117 /* For return values e.g. SNMP_INTEGER macro */
118 SNMP_LOCAL_VARIABLES
119
120 static struct in_addr tmp;
121 #define INT32_INADDR(x) \
122 (tmp.s_addr = (x), tmp)
123
124 /* OSPFv3-MIB instances. */
125 oid ospfv3_oid [] = { OSPFv3MIB };
126
127 /* empty ID 0.0.0.0 e.g. empty router-id */
128 static struct in_addr ospf6_empty_id = {0};
129
130 /* Hook functions. */
131 static u_char *ospfv3GeneralGroup ();
132 static u_char *ospfv3AreaEntry ();
133 static u_char *ospfv3AreaLsdbEntry ();
134
135 struct variable ospfv3_variables[] =
136 {
137 /* OSPF general variables */
138 {OSPFv3ROUTERID, IPADDRESS, RWRITE, ospfv3GeneralGroup,
139 3, {1, 1, 1}},
140 {OSPFv3ADMINSTAT, INTEGER, RWRITE, ospfv3GeneralGroup,
141 3, {1, 1, 2}},
142 {OSPFv3VERSIONNUMBER, INTEGER, RONLY, ospfv3GeneralGroup,
143 3, {1, 1, 3}},
144 {OSPFv3AREABDRRTRSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
145 3, {1, 1, 4}},
146 {OSPFv3ASBDRRTRSTATUS, INTEGER, RWRITE, ospfv3GeneralGroup,
147 3, {1, 1, 5}},
148 {OSPFv3ASSCOPELSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
149 3, {1, 1, 6}},
150 {OSPFv3ASSCOPELSACHECKSUMSUM, INTEGER, RONLY, ospfv3GeneralGroup,
151 3, {1, 1, 7}},
152 {OSPFv3ORIGINATENEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
153 3, {1, 1, 8}},
154 {OSPFv3RXNEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
155 3, {1, 1, 9}},
156 {OSPFv3EXTLSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
157 3, {1, 1, 10}},
158 {OSPFv3EXTAREALSDBLIMIT, INTEGER, RWRITE, ospfv3GeneralGroup,
159 3, {1, 1, 11}},
160 {OSPFv3MULTICASTEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup,
161 3, {1, 1, 12}},
162 {OSPFv3EXITOVERFLOWINTERVAL, INTEGER, RWRITE, ospfv3GeneralGroup,
163 3, {1, 1, 13}},
164 {OSPFv3DEMANDEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup,
165 3, {1, 1, 14}},
166 {OSPFv3TRAFFICENGINEERINGSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup,
167 3, {1, 1, 15}},
168 {OSPFv3REFERENCEBANDWIDTH, INTEGER, RWRITE, ospfv3GeneralGroup,
169 3, {1, 1, 16}},
170 {OSPFv3RESTARTSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup,
171 3, {1, 1, 17}},
172 {OSPFv3RESTARTINTERVAL, INTEGER, RWRITE, ospfv3GeneralGroup,
173 3, {1, 1, 18}},
174 {OSPFv3RESTARTSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
175 3, {1, 1, 19}},
176 {OSPFv3RESTARTAGE, INTEGER, RONLY, ospfv3GeneralGroup,
177 3, {1, 1, 20}},
178 {OSPFv3RESTARTEXITREASON, INTEGER, RONLY, ospfv3GeneralGroup,
179 3, {1, 1, 21}},
180
181 /* OSPFv3 Area Data Structure */
182 {OSPFv3AREAID, IPADDRESS, RONLY, ospfv3AreaEntry,
183 4, {1, 2, 1, 1}},
184 {OSPFv3IMPORTASEXTERN, INTEGER, RWRITE, ospfv3AreaEntry,
185 4, {1, 2, 1, 2}},
186 {OSPFv3AREASPFRUNS, COUNTER, RONLY, ospfv3AreaEntry,
187 4, {1, 2, 1, 3}},
188 {OSPFv3AREABDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry,
189 4, {1, 2, 1, 4}},
190 {OSPFv3AREAASBDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry,
191 4, {1, 2, 1, 5}},
192 {OSPFv3AREASCOPELSACOUNT, GAUGE, RONLY, ospfv3AreaEntry,
193 4, {1, 2, 1, 6}},
194 {OSPFv3AREASCOPELSACKSUMSUM, INTEGER, RONLY, ospfv3AreaEntry,
195 4, {1, 2, 1, 7}},
196 {OSPFv3AREASUMMARY, INTEGER, RWRITE, ospfv3AreaEntry,
197 4, {1, 2, 1, 8}},
198 {OSPFv3AREASTATUS, INTEGER, RWRITE, ospfv3AreaEntry,
199 4, {1, 2, 1, 9}},
200 {OSPFv3STUBMETRIC, INTEGER, RWRITE, ospfv3AreaEntry,
201 4, {1, 2, 1, 10}},
202 {OSPFv3AREANSSATRANSLATORROLE, INTEGER, RWRITE, ospfv3AreaEntry,
203 4, {1, 2, 1, 11}},
204 {OSPFv3AREANSSATRANSLATORSTATE, INTEGER, RONLY, ospfv3AreaEntry,
205 4, {1, 2, 1, 12}},
206 {OSPFv3AREANSSATRANSLATORSTABILITYINTERVAL, INTEGER, RWRITE, ospfv3AreaEntry,
207 4, {1, 2, 1, 13}},
208 {OSPFv3AREANSSATRANSLATOREVENTS, COUNTER, RONLY, ospfv3AreaEntry,
209 4, {1, 2, 1, 14}},
210 {OSPFv3AREASTUBMETRICTYPE, INTEGER, RWRITE, ospfv3AreaEntry,
211 4, {1, 2, 1, 15}},
212
213 {OSPFv3AREALSDBAREAID, IPADDRESS, RONLY, ospfv3AreaLsdbEntry,
214 4, {1, 4, 1, 1}},
215 {OSPFv3AREALSDBTYPE, GAUGE, RONLY, ospfv3AreaLsdbEntry,
216 4, {1, 4, 1, 2}},
217 {OSPFv3AREALSDBROUTERID, IPADDRESS, RONLY, ospfv3AreaLsdbEntry,
218 4, {1, 4, 1, 3}},
219 {OSPFv3AREALSDBLSID, IPADDRESS, RONLY, ospfv3AreaLsdbEntry,
220 4, {1, 4, 1, 4}},
221 {OSPFv3AREALSDBSEQUENCE, INTEGER, RONLY, ospfv3AreaLsdbEntry,
222 4, {1, 4, 1, 5}},
223 {OSPFv3AREALSDBAGE, INTEGER, RONLY, ospfv3AreaLsdbEntry,
224 4, {1, 4, 1, 6}},
225 {OSPFv3AREALSDBCHECKSUM, INTEGER, RONLY, ospfv3AreaLsdbEntry,
226 4, {1, 4, 1, 7}},
227 {OSPFv3AREALSDBADVERTISEMENT, STRING, RONLY, ospfv3AreaLsdbEntry,
228 4, {1, 4, 1, 8}},
229 {OSPFv3AREALSDBTYPEKNOWN, INTEGER, RONLY, ospfv3AreaLsdbEntry,
230 4, {1, 4, 1, 9}},
231
232 };
233
234 static u_char *
235 ospfv3GeneralGroup (struct variable *v, oid *name, size_t *length,
236 int exact, size_t *var_len, WriteMethod **write_method)
237 {
238 /* Check whether the instance identifier is valid */
239 if (smux_header_generic (v, name, length, exact, var_len, write_method)
240 == MATCH_FAILED)
241 return NULL;
242
243 /* Return the current value of the variable */
244 switch (v->magic)
245 {
246 case OSPFv3ROUTERID: /* 1*/
247 /* Router-ID of this OSPF instance. */
248 if (ospf6)
249 return SNMP_IPADDRESS (INT32_INADDR (ospf6->router_id));
250 else
251 return SNMP_IPADDRESS (ospf6_empty_id);
252 break;
253 case OSPFv3ADMINSTAT: /* 2*/
254 break;
255 case OSPFv3VERSIONNUMBER: /* 3*/
256 break;
257 case OSPFv3AREABDRRTRSTATUS: /* 4*/
258 break;
259 case OSPFv3ASBDRRTRSTATUS: /* 5*/
260 break;
261 case OSPFv3ASSCOPELSACOUNT: /* 6*/
262 break;
263 case OSPFv3ASSCOPELSACHECKSUMSUM: /* 7*/
264 break;
265 case OSPFv3ORIGINATENEWLSAS: /* 8*/
266 break;
267 case OSPFv3RXNEWLSAS: /* 9*/
268 break;
269 case OSPFv3EXTLSACOUNT: /*10*/
270 break;
271 case OSPFv3EXTAREALSDBLIMIT: /*11*/
272 break;
273 case OSPFv3MULTICASTEXTENSIONS: /*12*/
274 break;
275 case OSPFv3EXITOVERFLOWINTERVAL: /*13*/
276 break;
277 case OSPFv3DEMANDEXTENSIONS: /*14*/
278 break;
279 case OSPFv3TRAFFICENGINEERINGSUPPORT: /*15*/
280 break;
281 case OSPFv3REFERENCEBANDWIDTH: /*16*/
282 break;
283 case OSPFv3RESTARTSUPPORT: /*17*/
284 break;
285 case OSPFv3RESTARTINTERVAL: /*18*/
286 break;
287 case OSPFv3RESTARTSTATUS: /*19*/
288 break;
289 case OSPFv3RESTARTAGE: /*20*/
290 break;
291 case OSPFv3RESTARTEXITREASON: /*21*/
292 break;
293 default:
294 return NULL;
295 }
296 return NULL;
297 }
298
299 static u_char *
300 ospfv3AreaEntry (struct variable *v, oid *name, size_t *length,
301 int exact, size_t *var_len, WriteMethod **write_method)
302 {
303 struct ospf6_area *oa, *area = NULL;
304 u_int32_t area_id = 0;
305 struct listnode *node;
306 unsigned int len;
307
308 if (ospf6 == NULL)
309 return NULL;
310
311 len = *length - v->namelen;
312 len = (len >= sizeof (u_int32_t) ? sizeof (u_int32_t) : 0);
313 if (exact && len != sizeof (u_int32_t))
314 return NULL;
315 if (len)
316 oid2in_addr (name + v->namelen, len, (struct in_addr *) &area_id);
317
318 zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu",
319 inet_ntoa (* (struct in_addr *) &area_id),
320 exact, len, (u_long)*length);
321
322 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
323 {
324 if (area == NULL)
325 {
326 if (len == 0) /* return first area entry */
327 area = oa;
328 else if (exact && ntohl (oa->area_id) == ntohl (area_id))
329 area = oa;
330 else if (ntohl (oa->area_id) > ntohl (area_id))
331 area = oa;
332 }
333 }
334
335 if (area == NULL)
336 return NULL;
337
338 *length = v->namelen + sizeof (u_int32_t);
339 oid_copy_addr (name + v->namelen, (struct in_addr *) &area->area_id,
340 sizeof (u_int32_t));
341
342 zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu",
343 inet_ntoa (* (struct in_addr *) &area->area_id),
344 exact, len, (u_long)*length);
345
346 switch (v->magic)
347 {
348 case OSPFv3AREAID: /* 1*/
349 return SNMP_IPADDRESS (INT32_INADDR (area->area_id));
350 break;
351 case OSPFv3IMPORTASEXTERN: /* 2*/
352 return SNMP_INTEGER (ospf6->external_table->count);
353 break;
354 default:
355 return NULL;
356 break;
357 }
358 return NULL;
359 }
360
361 static u_char *
362 ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length,
363 int exact, size_t *var_len, WriteMethod **write_method)
364 {
365 struct ospf6_lsa *lsa = NULL;
366 struct in_addr area_id;
367 u_int16_t type;
368 struct in_addr id;
369 struct in_addr adv_router;
370 int len;
371 oid *offset;
372 int offsetlen;
373 char a[16], b[16], c[16];
374 struct ospf6_area *oa;
375 struct listnode *node;
376
377 memset (&area_id, 0, sizeof (struct in_addr));
378 type = 0;
379 memset (&id, 0, sizeof (struct in_addr));
380 memset (&adv_router, 0, sizeof (struct in_addr));
381
382 /* Check OSPFv3 instance. */
383 if (ospf6 == NULL)
384 return NULL;
385
386 /* Get variable length. */
387 offset = name + v->namelen;
388 offsetlen = *length - v->namelen;
389
390 #define OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET \
391 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
392
393 if (exact && offsetlen != OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET)
394 return NULL;
395
396 /* Parse area-id */
397 len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE);
398 if (len)
399 oid2in_addr (offset, len, &area_id);
400 offset += len;
401 offsetlen -= len;
402
403 /* Parse type */
404 len = (offsetlen < 1 ? offsetlen : 1);
405 if (len)
406 type = htons (*offset);
407 offset += len;
408 offsetlen -= len;
409
410 /* Parse Router-ID */
411 len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE);
412 if (len)
413 oid2in_addr (offset, len, &adv_router);
414 offset += len;
415 offsetlen -= len;
416
417 /* Parse LS-ID */
418 len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE);
419 if (len)
420 oid2in_addr (offset, len, &id);
421 offset += len;
422 offsetlen -= len;
423
424 inet_ntop (AF_INET, &area_id, a, sizeof (a));
425 inet_ntop (AF_INET, &adv_router, b, sizeof (b));
426 inet_ntop (AF_INET, &id, c, sizeof (c));
427 zlog_debug ("SNMP access by lsdb: area=%s exact=%d length=%lu magic=%d"
428 " type=%#x adv_router=%s id=%s",
429 a, exact, (u_long)*length, v->magic, ntohs (type), b, c);
430
431 if (exact)
432 {
433 oa = ospf6_area_lookup (area_id.s_addr, ospf6);
434 lsa = ospf6_lsdb_lookup (type, id.s_addr, adv_router.s_addr, oa->lsdb);
435 }
436 else
437 {
438 for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
439 {
440 if (lsa)
441 continue;
442 if (ntohl (oa->area_id) < ntohl (area_id.s_addr))
443 continue;
444
445 lsa = ospf6_lsdb_lookup_next (type, id.s_addr, adv_router.s_addr,
446 oa->lsdb);
447 if (! lsa)
448 {
449 type = 0;
450 memset (&id, 0, sizeof (struct in_addr));
451 memset (&adv_router, 0, sizeof (struct in_addr));
452 }
453 }
454 }
455
456 if (! lsa)
457 {
458 zlog_debug ("SNMP respond: No LSA to return");
459 return NULL;
460 }
461 oa = OSPF6_AREA (lsa->lsdb->data);
462
463 zlog_debug ("SNMP respond: area: %s lsa: %s", oa->name, lsa->name);
464
465 /* Add Index (AreaId, Type, RouterId, Lsid) */
466 *length = v->namelen + OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET;
467 offset = name + v->namelen;
468 oid_copy_addr (offset, (struct in_addr *) &oa->area_id, IN_ADDR_SIZE);
469 offset += IN_ADDR_SIZE;
470 *offset = ntohs (lsa->header->type);
471 offset++;
472 oid_copy_addr (offset, (struct in_addr *) &lsa->header->adv_router,
473 IN_ADDR_SIZE);
474 offset += IN_ADDR_SIZE;
475 oid_copy_addr (offset, (struct in_addr *) &lsa->header->id, IN_ADDR_SIZE);
476 offset += IN_ADDR_SIZE;
477
478 /* Return the current value of the variable */
479 switch (v->magic)
480 {
481 case OSPFv3AREALSDBAREAID: /* 1 */
482 area_id.s_addr = OSPF6_AREA (lsa->lsdb->data)->area_id;
483 return SNMP_IPADDRESS (area_id);
484 break;
485 case OSPFv3AREALSDBTYPE: /* 2 */
486 return SNMP_INTEGER (ntohs (lsa->header->type));
487 break;
488 case OSPFv3AREALSDBROUTERID: /* 3 */
489 adv_router.s_addr = lsa->header->adv_router;
490 return SNMP_IPADDRESS (adv_router);
491 break;
492 case OSPFv3AREALSDBLSID: /* 4 */
493 id.s_addr = lsa->header->id;
494 return SNMP_IPADDRESS (id);
495 break;
496 case OSPFv3AREALSDBSEQUENCE: /* 5 */
497 return SNMP_INTEGER (lsa->header->seqnum);
498 break;
499 case OSPFv3AREALSDBAGE: /* 6 */
500 ospf6_lsa_age_current (lsa);
501 return SNMP_INTEGER (lsa->header->age);
502 break;
503 case OSPFv3AREALSDBCHECKSUM: /* 7 */
504 return SNMP_INTEGER (lsa->header->checksum);
505 break;
506 case OSPFv3AREALSDBADVERTISEMENT: /* 8 */
507 *var_len = ntohs (lsa->header->length);
508 return (u_char *) lsa->header;
509 break;
510 case OSPFv3AREALSDBTYPEKNOWN: /* 9 */
511 return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ?
512 SNMP_TRUE : SNMP_FALSE);
513 break;
514 default:
515 return NULL;
516 break;
517 }
518 return NULL;
519 }
520
521
522 /* Register OSPFv3-MIB. */
523 void
524 ospf6_snmp_init (struct thread_master *master)
525 {
526 smux_init (master);
527 REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
528 }
529
530 #endif /* HAVE_SNMP */
531