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.
27 #include <net-snmp/net-snmp-config.h>
28 #endif /*HAVE_NETSNMP*/
32 #include <snmp_impl.h>
39 #include "ospf6_proto.h"
40 #include "ospf6_lsa.h"
41 #include "ospf6_lsdb.h"
42 #include "ospf6_route.h"
43 #include "ospf6_top.h"
44 #include "ospf6_area.h"
45 #include "ospf6_interface.h"
46 #include "ospf6_message.h"
47 #include "ospf6_neighbor.h"
51 #define OSPFv3MIB 1,3,6,1,3,102
53 /* OSPFv3 MIB General Group values. */
54 #define OSPFv3ROUTERID 1
55 #define OSPFv3ADMINSTAT 2
56 #define OSPFv3VERSIONNUMBER 3
57 #define OSPFv3AREABDRRTRSTATUS 4
58 #define OSPFv3ASBDRRTRSTATUS 5
59 #define OSPFv3ASSCOPELSACOUNT 6
60 #define OSPFv3ASSCOPELSACHECKSUMSUM 7
61 #define OSPFv3ORIGINATENEWLSAS 8
62 #define OSPFv3RXNEWLSAS 9
63 #define OSPFv3EXTLSACOUNT 10
64 #define OSPFv3EXTAREALSDBLIMIT 11
65 #define OSPFv3MULTICASTEXTENSIONS 12
66 #define OSPFv3EXITOVERFLOWINTERVAL 13
67 #define OSPFv3DEMANDEXTENSIONS 14
68 #define OSPFv3TRAFFICENGINEERINGSUPPORT 15
69 #define OSPFv3REFERENCEBANDWIDTH 16
70 #define OSPFv3RESTARTSUPPORT 17
71 #define OSPFv3RESTARTINTERVAL 18
72 #define OSPFv3RESTARTSTATUS 19
73 #define OSPFv3RESTARTAGE 20
74 #define OSPFv3RESTARTEXITREASON 21
76 /* OSPFv3 MIB Area Table values. */
77 #define OSPFv3AREAID 1
78 #define OSPFv3IMPORTASEXTERN 2
79 #define OSPFv3AREASPFRUNS 3
80 #define OSPFv3AREABDRRTRCOUNT 4
81 #define OSPFv3AREAASBDRRTRCOUNT 5
82 #define OSPFv3AREASCOPELSACOUNT 6
83 #define OSPFv3AREASCOPELSACKSUMSUM 7
84 #define OSPFv3AREASUMMARY 8
85 #define OSPFv3AREASTATUS 9
86 #define OSPFv3STUBMETRIC 10
87 #define OSPFv3AREANSSATRANSLATORROLE 11
88 #define OSPFv3AREANSSATRANSLATORSTATE 12
89 #define OSPFv3AREANSSATRANSLATORSTABILITYINTERVAL 13
90 #define OSPFv3AREANSSATRANSLATOREVENTS 14
91 #define OSPFv3AREASTUBMETRICTYPE 15
93 /* OSPFv3 MIB Area Lsdb Table values. */
94 #define OSPFv3AREALSDBAREAID 1
95 #define OSPFv3AREALSDBTYPE 2
96 #define OSPFv3AREALSDBROUTERID 3
97 #define OSPFv3AREALSDBLSID 4
98 #define OSPFv3AREALSDBSEQUENCE 5
99 #define OSPFv3AREALSDBAGE 6
100 #define OSPFv3AREALSDBCHECKSUM 7
101 #define OSPFv3AREALSDBADVERTISEMENT 8
102 #define OSPFv3AREALSDBTYPEKNOWN 9
104 /* SYNTAX Status from OSPF-MIB. */
105 #define OSPF_STATUS_ENABLED 1
106 #define OSPF_STATUS_DISABLED 2
108 /* SNMP value hack. */
109 #define COUNTER ASN_COUNTER
110 #define INTEGER ASN_INTEGER
111 #define GAUGE ASN_GAUGE
112 #define TIMETICKS ASN_TIMETICKS
113 #define IPADDRESS ASN_IPADDRESS
114 #define STRING ASN_OCTET_STR
116 /* For return values e.g. SNMP_INTEGER macro */
119 static struct in_addr tmp
;
120 #define INT32_INADDR(x) \
121 (tmp.s_addr = (x), tmp)
123 /* OSPFv3-MIB instances. */
124 oid ospfv3_oid
[] = { OSPFv3MIB
};
126 /* empty ID 0.0.0.0 e.g. empty router-id */
127 static struct in_addr ospf6_empty_id
= {0};
129 /* Hook functions. */
130 static u_char
*ospfv3GeneralGroup ();
131 static u_char
*ospfv3AreaEntry ();
132 static u_char
*ospfv3AreaLsdbEntry ();
134 struct variable ospfv3_variables
[] =
136 /* OSPF general variables */
137 {OSPFv3ROUTERID
, IPADDRESS
, RWRITE
, ospfv3GeneralGroup
,
139 {OSPFv3ADMINSTAT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
141 {OSPFv3VERSIONNUMBER
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
143 {OSPFv3AREABDRRTRSTATUS
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
145 {OSPFv3ASBDRRTRSTATUS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
147 {OSPFv3ASSCOPELSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
,
149 {OSPFv3ASSCOPELSACHECKSUMSUM
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
151 {OSPFv3ORIGINATENEWLSAS
, COUNTER
, RONLY
, ospfv3GeneralGroup
,
153 {OSPFv3RXNEWLSAS
, COUNTER
, RONLY
, ospfv3GeneralGroup
,
155 {OSPFv3EXTLSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
,
157 {OSPFv3EXTAREALSDBLIMIT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
159 {OSPFv3MULTICASTEXTENSIONS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
161 {OSPFv3EXITOVERFLOWINTERVAL
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
163 {OSPFv3DEMANDEXTENSIONS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
165 {OSPFv3TRAFFICENGINEERINGSUPPORT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
167 {OSPFv3REFERENCEBANDWIDTH
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
169 {OSPFv3RESTARTSUPPORT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
171 {OSPFv3RESTARTINTERVAL
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
173 {OSPFv3RESTARTSTATUS
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
175 {OSPFv3RESTARTAGE
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
177 {OSPFv3RESTARTEXITREASON
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
180 /* OSPFv3 Area Data Structure */
181 {OSPFv3AREAID
, IPADDRESS
, RONLY
, ospfv3AreaEntry
,
183 {OSPFv3IMPORTASEXTERN
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
185 {OSPFv3AREASPFRUNS
, COUNTER
, RONLY
, ospfv3AreaEntry
,
187 {OSPFv3AREABDRRTRCOUNT
, GAUGE
, RONLY
, ospfv3AreaEntry
,
189 {OSPFv3AREAASBDRRTRCOUNT
, GAUGE
, RONLY
, ospfv3AreaEntry
,
191 {OSPFv3AREASCOPELSACOUNT
, GAUGE
, RONLY
, ospfv3AreaEntry
,
193 {OSPFv3AREASCOPELSACKSUMSUM
, INTEGER
, RONLY
, ospfv3AreaEntry
,
195 {OSPFv3AREASUMMARY
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
197 {OSPFv3AREASTATUS
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
199 {OSPFv3STUBMETRIC
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
201 {OSPFv3AREANSSATRANSLATORROLE
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
203 {OSPFv3AREANSSATRANSLATORSTATE
, INTEGER
, RONLY
, ospfv3AreaEntry
,
205 {OSPFv3AREANSSATRANSLATORSTABILITYINTERVAL
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
207 {OSPFv3AREANSSATRANSLATOREVENTS
, COUNTER
, RONLY
, ospfv3AreaEntry
,
209 {OSPFv3AREASTUBMETRICTYPE
, INTEGER
, RWRITE
, ospfv3AreaEntry
,
212 {OSPFv3AREALSDBAREAID
, IPADDRESS
, RONLY
, ospfv3AreaLsdbEntry
,
214 {OSPFv3AREALSDBTYPE
, GAUGE
, RONLY
, ospfv3AreaLsdbEntry
,
216 {OSPFv3AREALSDBROUTERID
, IPADDRESS
, RONLY
, ospfv3AreaLsdbEntry
,
218 {OSPFv3AREALSDBLSID
, IPADDRESS
, RONLY
, ospfv3AreaLsdbEntry
,
220 {OSPFv3AREALSDBSEQUENCE
, INTEGER
, RONLY
, ospfv3AreaLsdbEntry
,
222 {OSPFv3AREALSDBAGE
, INTEGER
, RONLY
, ospfv3AreaLsdbEntry
,
224 {OSPFv3AREALSDBCHECKSUM
, INTEGER
, RONLY
, ospfv3AreaLsdbEntry
,
226 {OSPFv3AREALSDBADVERTISEMENT
, STRING
, RONLY
, ospfv3AreaLsdbEntry
,
228 {OSPFv3AREALSDBTYPEKNOWN
, INTEGER
, RONLY
, ospfv3AreaLsdbEntry
,
234 ospfv3GeneralGroup (struct variable
*v
, oid
*name
, size_t *length
,
235 int exact
, size_t *var_len
, WriteMethod
**write_method
)
237 /* Check whether the instance identifier is valid */
238 if (smux_header_generic (v
, name
, length
, exact
, var_len
, write_method
)
242 /* Return the current value of the variable */
245 case OSPFv3ROUTERID
: /* 1*/
246 /* Router-ID of this OSPF instance. */
248 return SNMP_IPADDRESS (INT32_INADDR (ospf6
->router_id
));
250 return SNMP_IPADDRESS (ospf6_empty_id
);
252 case OSPFv3ADMINSTAT
: /* 2*/
254 case OSPFv3VERSIONNUMBER
: /* 3*/
256 case OSPFv3AREABDRRTRSTATUS
: /* 4*/
258 case OSPFv3ASBDRRTRSTATUS
: /* 5*/
260 case OSPFv3ASSCOPELSACOUNT
: /* 6*/
262 case OSPFv3ASSCOPELSACHECKSUMSUM
: /* 7*/
264 case OSPFv3ORIGINATENEWLSAS
: /* 8*/
266 case OSPFv3RXNEWLSAS
: /* 9*/
268 case OSPFv3EXTLSACOUNT
: /*10*/
270 case OSPFv3EXTAREALSDBLIMIT
: /*11*/
272 case OSPFv3MULTICASTEXTENSIONS
: /*12*/
274 case OSPFv3EXITOVERFLOWINTERVAL
: /*13*/
276 case OSPFv3DEMANDEXTENSIONS
: /*14*/
278 case OSPFv3TRAFFICENGINEERINGSUPPORT
: /*15*/
280 case OSPFv3REFERENCEBANDWIDTH
: /*16*/
282 case OSPFv3RESTARTSUPPORT
: /*17*/
284 case OSPFv3RESTARTINTERVAL
: /*18*/
286 case OSPFv3RESTARTSTATUS
: /*19*/
288 case OSPFv3RESTARTAGE
: /*20*/
290 case OSPFv3RESTARTEXITREASON
: /*21*/
299 ospfv3AreaEntry (struct variable
*v
, oid
*name
, size_t *length
,
300 int exact
, size_t *var_len
, WriteMethod
**write_method
)
302 struct ospf6_area
*oa
, *area
= NULL
;
303 u_int32_t area_id
= 0;
304 struct listnode
*node
;
310 len
= *length
- v
->namelen
;
311 len
= (len
>= sizeof (u_int32_t
) ? sizeof (u_int32_t
) : 0);
312 if (exact
&& len
!= sizeof (u_int32_t
))
315 oid2in_addr (name
+ v
->namelen
, len
, (struct in_addr
*) &area_id
);
317 zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%d",
318 inet_ntoa (* (struct in_addr
*) &area_id
),
319 exact
, len
, *length
);
321 for (ALL_LIST_ELEMENTS_RO (ospf6
->area_list
, node
, oa
))
325 if (len
== 0) /* return first area entry */
327 else if (exact
&& ntohl (oa
->area_id
) == ntohl (area_id
))
329 else if (ntohl (oa
->area_id
) > ntohl (area_id
))
337 *length
= v
->namelen
+ sizeof (u_int32_t
);
338 oid_copy_addr (name
+ v
->namelen
, (struct in_addr
*) &area
->area_id
,
341 zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%d",
342 inet_ntoa (* (struct in_addr
*) &area
->area_id
),
343 exact
, len
, *length
);
347 case OSPFv3AREAID
: /* 1*/
348 return SNMP_IPADDRESS (INT32_INADDR (area
->area_id
));
350 case OSPFv3IMPORTASEXTERN
: /* 2*/
351 return SNMP_INTEGER (ospf6
->external_table
->count
);
361 ospfv3AreaLsdbEntry (struct variable
*v
, oid
*name
, size_t *length
,
362 int exact
, size_t *var_len
, WriteMethod
**write_method
)
364 struct ospf6_lsa
*lsa
= NULL
;
365 struct in_addr area_id
;
368 struct in_addr adv_router
;
372 char a
[16], b
[16], c
[16];
373 struct ospf6_area
*oa
;
374 struct listnode
*node
;
376 memset (&area_id
, 0, sizeof (struct in_addr
));
378 memset (&id
, 0, sizeof (struct in_addr
));
379 memset (&adv_router
, 0, sizeof (struct in_addr
));
381 /* Check OSPFv3 instance. */
385 /* Get variable length. */
386 offset
= name
+ v
->namelen
;
387 offsetlen
= *length
- v
->namelen
;
389 #define OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET \
390 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
392 if (exact
&& offsetlen
!= OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET
)
396 len
= (offsetlen
< IN_ADDR_SIZE
? offsetlen
: IN_ADDR_SIZE
);
398 oid2in_addr (offset
, len
, &area_id
);
403 len
= (offsetlen
< 1 ? offsetlen
: 1);
405 type
= htons (*offset
);
409 /* Parse Router-ID */
410 len
= (offsetlen
< IN_ADDR_SIZE
? offsetlen
: IN_ADDR_SIZE
);
412 oid2in_addr (offset
, len
, &adv_router
);
417 len
= (offsetlen
< IN_ADDR_SIZE
? offsetlen
: IN_ADDR_SIZE
);
419 oid2in_addr (offset
, len
, &id
);
423 inet_ntop (AF_INET
, &area_id
, a
, sizeof (a
));
424 inet_ntop (AF_INET
, &adv_router
, b
, sizeof (b
));
425 inet_ntop (AF_INET
, &id
, c
, sizeof (c
));
426 zlog_debug ("SNMP access by lsdb: area=%s exact=%d length=%d magic=%d"
427 " type=%#x adv_router=%s id=%s",
428 a
, exact
, *length
, v
->magic
, ntohs (type
), b
, c
);
432 oa
= ospf6_area_lookup (area_id
.s_addr
, ospf6
);
433 lsa
= ospf6_lsdb_lookup (type
, id
.s_addr
, adv_router
.s_addr
, oa
->lsdb
);
437 for (ALL_LIST_ELEMENTS_RO (ospf6
->area_list
, node
, oa
))
441 if (ntohl (oa
->area_id
) < ntohl (area_id
.s_addr
))
444 lsa
= ospf6_lsdb_lookup_next (type
, id
.s_addr
, adv_router
.s_addr
,
449 memset (&id
, 0, sizeof (struct in_addr
));
450 memset (&adv_router
, 0, sizeof (struct in_addr
));
457 zlog_debug ("SNMP respond: No LSA to return");
460 oa
= OSPF6_AREA (lsa
->lsdb
->data
);
462 zlog_debug ("SNMP respond: area: %s lsa: %s", oa
->name
, lsa
->name
);
464 /* Add Index (AreaId, Type, RouterId, Lsid) */
465 *length
= v
->namelen
+ OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET
;
466 offset
= name
+ v
->namelen
;
467 oid_copy_addr (offset
, (struct in_addr
*) &oa
->area_id
, IN_ADDR_SIZE
);
468 offset
+= IN_ADDR_SIZE
;
469 *offset
= ntohs (lsa
->header
->type
);
471 oid_copy_addr (offset
, (struct in_addr
*) &lsa
->header
->adv_router
,
473 offset
+= IN_ADDR_SIZE
;
474 oid_copy_addr (offset
, (struct in_addr
*) &lsa
->header
->id
, IN_ADDR_SIZE
);
475 offset
+= IN_ADDR_SIZE
;
477 /* Return the current value of the variable */
480 case OSPFv3AREALSDBAREAID
: /* 1 */
481 area_id
.s_addr
= OSPF6_AREA (lsa
->lsdb
->data
)->area_id
;
482 return SNMP_IPADDRESS (area_id
);
484 case OSPFv3AREALSDBTYPE
: /* 2 */
485 return SNMP_INTEGER (ntohs (lsa
->header
->type
));
487 case OSPFv3AREALSDBROUTERID
: /* 3 */
488 adv_router
.s_addr
= lsa
->header
->adv_router
;
489 return SNMP_IPADDRESS (adv_router
);
491 case OSPFv3AREALSDBLSID
: /* 4 */
492 id
.s_addr
= lsa
->header
->id
;
493 return SNMP_IPADDRESS (id
);
495 case OSPFv3AREALSDBSEQUENCE
: /* 5 */
496 return SNMP_INTEGER (lsa
->header
->seqnum
);
498 case OSPFv3AREALSDBAGE
: /* 6 */
499 ospf6_lsa_age_current (lsa
);
500 return SNMP_INTEGER (lsa
->header
->age
);
502 case OSPFv3AREALSDBCHECKSUM
: /* 7 */
503 return SNMP_INTEGER (lsa
->header
->checksum
);
505 case OSPFv3AREALSDBADVERTISEMENT
: /* 8 */
506 *var_len
= ntohs (lsa
->header
->length
);
507 return (u_char
*) lsa
->header
;
509 case OSPFv3AREALSDBTYPEKNOWN
: /* 9 */
510 return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa
->header
->type
) ?
511 SNMP_TRUE
: SNMP_FALSE
);
521 /* Register OSPFv3-MIB. */
523 ospf6_snmp_init (struct thread_master
*master
)
526 REGISTER_MIB ("OSPFv3MIB", ospfv3_variables
, variable
, ospfv3_oid
);
529 #endif /* HAVE_SNMP */