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.
26 #include <net-snmp/net-snmp-config.h>
27 #include <net-snmp/net-snmp-includes.h>
34 #include "ospf6_proto.h"
35 #include "ospf6_lsa.h"
36 #include "ospf6_lsdb.h"
37 #include "ospf6_route.h"
38 #include "ospf6_top.h"
39 #include "ospf6_area.h"
40 #include "ospf6_interface.h"
41 #include "ospf6_message.h"
42 #include "ospf6_neighbor.h"
44 #include "ospf6_snmp.h"
47 #define OSPFv3MIB 1,3,6,1,3,102
49 /* OSPFv3 MIB General Group values. */
50 #define OSPFv3ROUTERID 1
51 #define OSPFv3ADMINSTAT 2
52 #define OSPFv3VERSIONNUMBER 3
53 #define OSPFv3AREABDRRTRSTATUS 4
54 #define OSPFv3ASBDRRTRSTATUS 5
55 #define OSPFv3ASSCOPELSACOUNT 6
56 #define OSPFv3ASSCOPELSACHECKSUMSUM 7
57 #define OSPFv3ORIGINATENEWLSAS 8
58 #define OSPFv3RXNEWLSAS 9
59 #define OSPFv3EXTLSACOUNT 10
60 #define OSPFv3EXTAREALSDBLIMIT 11
61 #define OSPFv3MULTICASTEXTENSIONS 12
62 #define OSPFv3EXITOVERFLOWINTERVAL 13
63 #define OSPFv3DEMANDEXTENSIONS 14
64 #define OSPFv3TRAFFICENGINEERINGSUPPORT 15
65 #define OSPFv3REFERENCEBANDWIDTH 16
66 #define OSPFv3RESTARTSUPPORT 17
67 #define OSPFv3RESTARTINTERVAL 18
68 #define OSPFv3RESTARTSTATUS 19
69 #define OSPFv3RESTARTAGE 20
70 #define OSPFv3RESTARTEXITREASON 21
72 /* OSPFv3 MIB Area Table values. */
73 #define OSPFv3AREAID 1
74 #define OSPFv3IMPORTASEXTERN 2
75 #define OSPFv3AREASPFRUNS 3
76 #define OSPFv3AREABDRRTRCOUNT 4
77 #define OSPFv3AREAASBDRRTRCOUNT 5
78 #define OSPFv3AREASCOPELSACOUNT 6
79 #define OSPFv3AREASCOPELSACKSUMSUM 7
80 #define OSPFv3AREASUMMARY 8
81 #define OSPFv3AREASTATUS 9
82 #define OSPFv3STUBMETRIC 10
83 #define OSPFv3AREANSSATRANSLATORROLE 11
84 #define OSPFv3AREANSSATRANSLATORSTATE 12
85 #define OSPFv3AREANSSATRANSLATORSTABILITYINTERVAL 13
86 #define OSPFv3AREANSSATRANSLATOREVENTS 14
87 #define OSPFv3AREASTUBMETRICTYPE 15
89 /* OSPFv3 MIB Area Lsdb Table values. */
90 #define OSPFv3AREALSDBAREAID 1
91 #define OSPFv3AREALSDBTYPE 2
92 #define OSPFv3AREALSDBROUTERID 3
93 #define OSPFv3AREALSDBLSID 4
94 #define OSPFv3AREALSDBSEQUENCE 5
95 #define OSPFv3AREALSDBAGE 6
96 #define OSPFv3AREALSDBCHECKSUM 7
97 #define OSPFv3AREALSDBADVERTISEMENT 8
98 #define OSPFv3AREALSDBTYPEKNOWN 9
100 /* SYNTAX Status from OSPF-MIB. */
101 #define OSPF_STATUS_ENABLED 1
102 #define OSPF_STATUS_DISABLED 2
104 /* SNMP value hack. */
105 #define COUNTER ASN_COUNTER
106 #define INTEGER ASN_INTEGER
107 #define GAUGE ASN_GAUGE
108 #define TIMETICKS ASN_TIMETICKS
109 #define IPADDRESS ASN_IPADDRESS
110 #define STRING ASN_OCTET_STR
112 /* For return values e.g. SNMP_INTEGER macro */
115 static struct in_addr tmp
;
116 #define INT32_INADDR(x) \
117 (tmp.s_addr = (x), tmp)
119 /* OSPFv3-MIB instances. */
120 oid ospfv3_oid
[] = { OSPFv3MIB
};
122 /* empty ID 0.0.0.0 e.g. empty router-id */
123 static struct in_addr ospf6_empty_id
= {0};
125 /* Hook functions. */
126 static u_char
*ospfv3GeneralGroup (struct variable
*, oid
*, size_t *,
127 int, size_t *, WriteMethod
**);
128 static u_char
*ospfv3AreaEntry (struct variable
*, oid
*, size_t *,
129 int, size_t *, WriteMethod
**);
130 static u_char
*ospfv3AreaLsdbEntry (struct variable
*, oid
*, size_t *,
131 int, size_t *, WriteMethod
**);
133 struct variable ospfv3_variables
[] =
135 /* OSPF general variables */
136 {OSPFv3ROUTERID
, IPADDRESS
, RWRITE
, ospfv3GeneralGroup
,
138 {OSPFv3ADMINSTAT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
140 {OSPFv3VERSIONNUMBER
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
142 {OSPFv3AREABDRRTRSTATUS
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
144 {OSPFv3ASBDRRTRSTATUS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
146 {OSPFv3ASSCOPELSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
,
148 {OSPFv3ASSCOPELSACHECKSUMSUM
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
150 {OSPFv3ORIGINATENEWLSAS
, COUNTER
, RONLY
, ospfv3GeneralGroup
,
152 {OSPFv3RXNEWLSAS
, COUNTER
, RONLY
, ospfv3GeneralGroup
,
154 {OSPFv3EXTLSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
,
156 {OSPFv3EXTAREALSDBLIMIT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
158 {OSPFv3MULTICASTEXTENSIONS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
160 {OSPFv3EXITOVERFLOWINTERVAL
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
162 {OSPFv3DEMANDEXTENSIONS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
164 {OSPFv3TRAFFICENGINEERINGSUPPORT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
166 {OSPFv3REFERENCEBANDWIDTH
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
168 {OSPFv3RESTARTSUPPORT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
170 {OSPFv3RESTARTINTERVAL
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
172 {OSPFv3RESTARTSTATUS
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
174 {OSPFv3RESTARTAGE
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
176 {OSPFv3RESTARTEXITREASON
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
179 /* OSPFv3 Area Data Structure */
180 {OSPFv3AREAID
, IPADDRESS
, RONLY
, ospfv3AreaEntry
,
182 {OSPFv3IMPORTASEXTERN
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
184 {OSPFv3AREASPFRUNS
, COUNTER
, RONLY
, ospfv3AreaEntry
,
186 {OSPFv3AREABDRRTRCOUNT
, GAUGE
, RONLY
, ospfv3AreaEntry
,
188 {OSPFv3AREAASBDRRTRCOUNT
, GAUGE
, RONLY
, ospfv3AreaEntry
,
190 {OSPFv3AREASCOPELSACOUNT
, GAUGE
, RONLY
, ospfv3AreaEntry
,
192 {OSPFv3AREASCOPELSACKSUMSUM
, INTEGER
, RONLY
, ospfv3AreaEntry
,
194 {OSPFv3AREASUMMARY
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
196 {OSPFv3AREASTATUS
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
198 {OSPFv3STUBMETRIC
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
200 {OSPFv3AREANSSATRANSLATORROLE
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
202 {OSPFv3AREANSSATRANSLATORSTATE
, INTEGER
, RONLY
, ospfv3AreaEntry
,
204 {OSPFv3AREANSSATRANSLATORSTABILITYINTERVAL
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
206 {OSPFv3AREANSSATRANSLATOREVENTS
, COUNTER
, RONLY
, ospfv3AreaEntry
,
208 {OSPFv3AREASTUBMETRICTYPE
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
211 {OSPFv3AREALSDBAREAID
, IPADDRESS
, RONLY
, ospfv3AreaLsdbEntry
,
213 {OSPFv3AREALSDBTYPE
, GAUGE
, RONLY
, ospfv3AreaLsdbEntry
,
215 {OSPFv3AREALSDBROUTERID
, IPADDRESS
, RONLY
, ospfv3AreaLsdbEntry
,
217 {OSPFv3AREALSDBLSID
, IPADDRESS
, RONLY
, ospfv3AreaLsdbEntry
,
219 {OSPFv3AREALSDBSEQUENCE
, INTEGER
, RONLY
, ospfv3AreaLsdbEntry
,
221 {OSPFv3AREALSDBAGE
, INTEGER
, RONLY
, ospfv3AreaLsdbEntry
,
223 {OSPFv3AREALSDBCHECKSUM
, INTEGER
, RONLY
, ospfv3AreaLsdbEntry
,
225 {OSPFv3AREALSDBADVERTISEMENT
, STRING
, RONLY
, ospfv3AreaLsdbEntry
,
227 {OSPFv3AREALSDBTYPEKNOWN
, INTEGER
, RONLY
, ospfv3AreaLsdbEntry
,
233 ospfv3GeneralGroup (struct variable
*v
, oid
*name
, size_t *length
,
234 int exact
, size_t *var_len
, WriteMethod
**write_method
)
236 /* Check whether the instance identifier is valid */
237 if (smux_header_generic (v
, name
, length
, exact
, var_len
, write_method
)
241 /* Return the current value of the variable */
244 case OSPFv3ROUTERID
: /* 1*/
245 /* Router-ID of this OSPF instance. */
247 return SNMP_IPADDRESS (INT32_INADDR (ospf6
->router_id
));
249 return SNMP_IPADDRESS (ospf6_empty_id
);
251 case OSPFv3ADMINSTAT
: /* 2*/
253 case OSPFv3VERSIONNUMBER
: /* 3*/
255 case OSPFv3AREABDRRTRSTATUS
: /* 4*/
257 case OSPFv3ASBDRRTRSTATUS
: /* 5*/
259 case OSPFv3ASSCOPELSACOUNT
: /* 6*/
261 case OSPFv3ASSCOPELSACHECKSUMSUM
: /* 7*/
263 case OSPFv3ORIGINATENEWLSAS
: /* 8*/
265 case OSPFv3RXNEWLSAS
: /* 9*/
267 case OSPFv3EXTLSACOUNT
: /*10*/
269 case OSPFv3EXTAREALSDBLIMIT
: /*11*/
271 case OSPFv3MULTICASTEXTENSIONS
: /*12*/
273 case OSPFv3EXITOVERFLOWINTERVAL
: /*13*/
275 case OSPFv3DEMANDEXTENSIONS
: /*14*/
277 case OSPFv3TRAFFICENGINEERINGSUPPORT
: /*15*/
279 case OSPFv3REFERENCEBANDWIDTH
: /*16*/
281 case OSPFv3RESTARTSUPPORT
: /*17*/
283 case OSPFv3RESTARTINTERVAL
: /*18*/
285 case OSPFv3RESTARTSTATUS
: /*19*/
287 case OSPFv3RESTARTAGE
: /*20*/
289 case OSPFv3RESTARTEXITREASON
: /*21*/
298 ospfv3AreaEntry (struct variable
*v
, oid
*name
, size_t *length
,
299 int exact
, size_t *var_len
, WriteMethod
**write_method
)
301 struct ospf6_area
*oa
, *area
= NULL
;
302 u_int32_t area_id
= 0;
303 struct listnode
*node
;
309 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
313 len
= *length
- v
->namelen
;
314 len
= (len
>= sizeof (u_int32_t
) ? sizeof (u_int32_t
) : 0);
315 if (exact
&& len
!= sizeof (u_int32_t
))
318 oid2in_addr (name
+ v
->namelen
, len
, (struct in_addr
*) &area_id
);
320 zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu",
321 inet_ntoa (* (struct in_addr
*) &area_id
),
322 exact
, len
, (u_long
)*length
);
324 for (ALL_LIST_ELEMENTS_RO (ospf6
->area_list
, node
, oa
))
328 if (len
== 0) /* return first area entry */
330 else if (exact
&& ntohl (oa
->area_id
) == ntohl (area_id
))
332 else if (ntohl (oa
->area_id
) > ntohl (area_id
))
340 *length
= v
->namelen
+ sizeof (u_int32_t
);
341 oid_copy_addr (name
+ v
->namelen
, (struct in_addr
*) &area
->area_id
,
344 zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu",
345 inet_ntoa (* (struct in_addr
*) &area
->area_id
),
346 exact
, len
, (u_long
)*length
);
350 case OSPFv3AREAID
: /* 1*/
351 return SNMP_IPADDRESS (INT32_INADDR (area
->area_id
));
353 case OSPFv3IMPORTASEXTERN
: /* 2*/
354 return SNMP_INTEGER (ospf6
->external_table
->count
);
364 ospfv3AreaLsdbEntry (struct variable
*v
, oid
*name
, size_t *length
,
365 int exact
, size_t *var_len
, WriteMethod
**write_method
)
367 struct ospf6_lsa
*lsa
= NULL
;
368 struct in_addr area_id
;
371 struct in_addr adv_router
;
375 char a
[16], b
[16], c
[16];
376 struct ospf6_area
*oa
;
377 struct listnode
*node
;
379 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
383 memset (&area_id
, 0, sizeof (struct in_addr
));
385 memset (&id
, 0, sizeof (struct in_addr
));
386 memset (&adv_router
, 0, sizeof (struct in_addr
));
388 /* Check OSPFv3 instance. */
392 /* Get variable length. */
393 offset
= name
+ v
->namelen
;
394 offsetlen
= *length
- v
->namelen
;
396 #define OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET \
397 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
399 if (exact
&& offsetlen
!= OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET
)
403 len
= (offsetlen
< IN_ADDR_SIZE
? offsetlen
: IN_ADDR_SIZE
);
405 oid2in_addr (offset
, len
, &area_id
);
410 len
= (offsetlen
< 1 ? offsetlen
: 1);
412 type
= htons (*offset
);
416 /* Parse Router-ID */
417 len
= (offsetlen
< IN_ADDR_SIZE
? offsetlen
: IN_ADDR_SIZE
);
419 oid2in_addr (offset
, len
, &adv_router
);
424 len
= (offsetlen
< IN_ADDR_SIZE
? offsetlen
: IN_ADDR_SIZE
);
426 oid2in_addr (offset
, len
, &id
);
430 inet_ntop (AF_INET
, &area_id
, a
, sizeof (a
));
431 inet_ntop (AF_INET
, &adv_router
, b
, sizeof (b
));
432 inet_ntop (AF_INET
, &id
, c
, sizeof (c
));
433 zlog_debug ("SNMP access by lsdb: area=%s exact=%d length=%lu magic=%d"
434 " type=%#x adv_router=%s id=%s",
435 a
, exact
, (u_long
)*length
, v
->magic
, ntohs (type
), b
, c
);
439 oa
= ospf6_area_lookup (area_id
.s_addr
, ospf6
);
440 lsa
= ospf6_lsdb_lookup (type
, id
.s_addr
, adv_router
.s_addr
, oa
->lsdb
);
444 for (ALL_LIST_ELEMENTS_RO (ospf6
->area_list
, node
, oa
))
448 if (ntohl (oa
->area_id
) < ntohl (area_id
.s_addr
))
451 lsa
= ospf6_lsdb_lookup_next (type
, id
.s_addr
, adv_router
.s_addr
,
456 memset (&id
, 0, sizeof (struct in_addr
));
457 memset (&adv_router
, 0, sizeof (struct in_addr
));
464 zlog_debug ("SNMP respond: No LSA to return");
467 oa
= OSPF6_AREA (lsa
->lsdb
->data
);
469 zlog_debug ("SNMP respond: area: %s lsa: %s", oa
->name
, lsa
->name
);
471 /* Add Index (AreaId, Type, RouterId, Lsid) */
472 *length
= v
->namelen
+ OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET
;
473 offset
= name
+ v
->namelen
;
474 oid_copy_addr (offset
, (struct in_addr
*) &oa
->area_id
, IN_ADDR_SIZE
);
475 offset
+= IN_ADDR_SIZE
;
476 *offset
= ntohs (lsa
->header
->type
);
478 oid_copy_addr (offset
, (struct in_addr
*) &lsa
->header
->adv_router
,
480 offset
+= IN_ADDR_SIZE
;
481 oid_copy_addr (offset
, (struct in_addr
*) &lsa
->header
->id
, IN_ADDR_SIZE
);
482 offset
+= IN_ADDR_SIZE
;
484 /* Return the current value of the variable */
487 case OSPFv3AREALSDBAREAID
: /* 1 */
488 area_id
.s_addr
= OSPF6_AREA (lsa
->lsdb
->data
)->area_id
;
489 return SNMP_IPADDRESS (area_id
);
491 case OSPFv3AREALSDBTYPE
: /* 2 */
492 return SNMP_INTEGER (ntohs (lsa
->header
->type
));
494 case OSPFv3AREALSDBROUTERID
: /* 3 */
495 adv_router
.s_addr
= lsa
->header
->adv_router
;
496 return SNMP_IPADDRESS (adv_router
);
498 case OSPFv3AREALSDBLSID
: /* 4 */
499 id
.s_addr
= lsa
->header
->id
;
500 return SNMP_IPADDRESS (id
);
502 case OSPFv3AREALSDBSEQUENCE
: /* 5 */
503 return SNMP_INTEGER (lsa
->header
->seqnum
);
505 case OSPFv3AREALSDBAGE
: /* 6 */
506 ospf6_lsa_age_current (lsa
);
507 return SNMP_INTEGER (lsa
->header
->age
);
509 case OSPFv3AREALSDBCHECKSUM
: /* 7 */
510 return SNMP_INTEGER (lsa
->header
->checksum
);
512 case OSPFv3AREALSDBADVERTISEMENT
: /* 8 */
513 *var_len
= ntohs (lsa
->header
->length
);
514 return (u_char
*) lsa
->header
;
516 case OSPFv3AREALSDBTYPEKNOWN
: /* 9 */
517 return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa
->header
->type
) ?
518 SNMP_TRUE
: SNMP_FALSE
);
528 /* Register OSPFv3-MIB. */
530 ospf6_snmp_init (struct thread_master
*master
)
533 REGISTER_MIB ("OSPFv3MIB", ospfv3_variables
, variable
, ospfv3_oid
);
536 #endif /* HAVE_SNMP */