blob: edc8bc49808325afc258e868f99f170fd5bab552 [file] [log] [blame]
hassoef1bbf52004-10-08 12:04:21 +00001/* 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#endif /*HAVE_NETSNMP*/
29
30#include <asn1.h>
31#include <snmp.h>
32#include <snmp_impl.h>
33
34#include "log.h"
35#include "vty.h"
36#include "linklist.h"
37#include "smux.h"
38
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"
48#include "ospf6d.h"
49
50/* OSPFv3-MIB */
51#define OSPFv3MIB 1,3,6,1,3,102
52
hassoef1bbf52004-10-08 12:04:21 +000053/* 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
75
76/* OSPFv3 MIB Area Table values. */
77#define OSPFv3AREAID 1
78#define OSPFv3IMPORTASEXTERN 2
79
80/* SYNTAX Status from OSPF-MIB. */
81#define OSPF_STATUS_ENABLED 1
82#define OSPF_STATUS_DISABLED 2
83
84/* SNMP value hack. */
85#define COUNTER ASN_COUNTER
86#define INTEGER ASN_INTEGER
87#define GAUGE ASN_GAUGE
88#define TIMETICKS ASN_TIMETICKS
89#define IPADDRESS ASN_IPADDRESS
90#define STRING ASN_OCTET_STR
91
92/* For return values e.g. SNMP_INTEGER macro */
93SNMP_LOCAL_VARIABLES
94
95static struct in_addr tmp;
96#define INT32_INADDR(x) \
97 (tmp.s_addr = (x), tmp)
98
99/* OSPFv3-MIB instances. */
100oid ospfv3_oid [] = { OSPFv3MIB };
hassoef1bbf52004-10-08 12:04:21 +0000101
102/* empty ID 0.0.0.0 e.g. empty router-id */
103static struct in_addr ospf6_empty_id = {0};
104
105/* Hook functions. */
106static u_char *ospfv3GeneralGroup ();
107static u_char *ospfv3AreaEntry ();
108
109struct variable ospfv3_variables[] =
110{
111 /* OSPF general variables */
112 {OSPFv3ROUTERID, IPADDRESS, RWRITE, ospfv3GeneralGroup,
113 3, {1, 1, 1}},
114 {OSPFv3ADMINSTAT, INTEGER, RWRITE, ospfv3GeneralGroup,
115 3, {1, 1, 2}},
116 {OSPFv3VERSIONNUMBER, INTEGER, RONLY, ospfv3GeneralGroup,
117 3, {1, 1, 3}},
118 {OSPFv3AREABDRRTRSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
119 3, {1, 1, 4}},
120 {OSPFv3ASBDRRTRSTATUS, INTEGER, RWRITE, ospfv3GeneralGroup,
121 3, {1, 1, 5}},
122 {OSPFv3ASSCOPELSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
123 3, {1, 1, 6}},
124 {OSPFv3ASSCOPELSACHECKSUMSUM, INTEGER, RONLY, ospfv3GeneralGroup,
125 3, {1, 1, 7}},
126 {OSPFv3ORIGINATENEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
127 3, {1, 1, 8}},
128 {OSPFv3RXNEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
129 3, {1, 1, 9}},
130 {OSPFv3EXTLSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
131 3, {1, 1, 10}},
132 {OSPFv3EXTAREALSDBLIMIT, INTEGER, RWRITE, ospfv3GeneralGroup,
133 3, {1, 1, 11}},
134 {OSPFv3MULTICASTEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup,
135 3, {1, 1, 12}},
136 {OSPFv3EXITOVERFLOWINTERVAL, INTEGER, RWRITE, ospfv3GeneralGroup,
137 3, {1, 1, 13}},
138 {OSPFv3DEMANDEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup,
139 3, {1, 1, 14}},
140 {OSPFv3TRAFFICENGINEERINGSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup,
141 3, {1, 1, 15}},
142 {OSPFv3REFERENCEBANDWIDTH, INTEGER, RWRITE, ospfv3GeneralGroup,
143 3, {1, 1, 16}},
144 {OSPFv3RESTARTSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup,
145 3, {1, 1, 17}},
146 {OSPFv3RESTARTINTERVAL, INTEGER, RWRITE, ospfv3GeneralGroup,
147 3, {1, 1, 18}},
148 {OSPFv3RESTARTSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
149 3, {1, 1, 19}},
150 {OSPFv3RESTARTAGE, INTEGER, RONLY, ospfv3GeneralGroup,
151 3, {1, 1, 20}},
152 {OSPFv3RESTARTEXITREASON, INTEGER, RONLY, ospfv3GeneralGroup,
153 3, {1, 1, 21}},
154
155 /* OSPFv3 Area Data Structure */
156 {OSPFv3AREAID, IPADDRESS, RONLY, ospfv3AreaEntry,
157 4, {1, 2, 1, 1}},
158 {OSPFv3IMPORTASEXTERN, INTEGER, RONLY, ospfv3AreaEntry,
159 4, {1, 2, 1, 2}},
160};
161
162static u_char *
163ospfv3GeneralGroup (struct variable *v, oid *name, size_t *length,
164 int exact, size_t *var_len, WriteMethod **write_method)
165{
166 /* Check whether the instance identifier is valid */
167 if (smux_header_generic (v, name, length, exact, var_len, write_method)
168 == MATCH_FAILED)
169 return NULL;
170
171 /* Return the current value of the variable */
172 switch (v->magic)
173 {
174 case OSPFv3ROUTERID: /* 1*/
175 /* Router-ID of this OSPF instance. */
176 if (ospf6)
177 return SNMP_IPADDRESS (INT32_INADDR (ospf6->router_id));
178 else
179 return SNMP_IPADDRESS (ospf6_empty_id);
180 break;
181 case OSPFv3ADMINSTAT: /* 2*/
182 break;
183 case OSPFv3VERSIONNUMBER: /* 3*/
184 break;
185 case OSPFv3AREABDRRTRSTATUS: /* 4*/
186 break;
187 case OSPFv3ASBDRRTRSTATUS: /* 5*/
188 break;
189 case OSPFv3ASSCOPELSACOUNT: /* 6*/
190 break;
191 case OSPFv3ASSCOPELSACHECKSUMSUM: /* 7*/
192 break;
193 case OSPFv3ORIGINATENEWLSAS: /* 8*/
194 break;
195 case OSPFv3RXNEWLSAS: /* 9*/
196 break;
197 case OSPFv3EXTLSACOUNT: /*10*/
198 break;
199 case OSPFv3EXTAREALSDBLIMIT: /*11*/
200 break;
201 case OSPFv3MULTICASTEXTENSIONS: /*12*/
202 break;
203 case OSPFv3EXITOVERFLOWINTERVAL: /*13*/
204 break;
205 case OSPFv3DEMANDEXTENSIONS: /*14*/
206 break;
207 case OSPFv3TRAFFICENGINEERINGSUPPORT: /*15*/
208 break;
209 case OSPFv3REFERENCEBANDWIDTH: /*16*/
210 break;
211 case OSPFv3RESTARTSUPPORT: /*17*/
212 break;
213 case OSPFv3RESTARTINTERVAL: /*18*/
214 break;
215 case OSPFv3RESTARTSTATUS: /*19*/
216 break;
217 case OSPFv3RESTARTAGE: /*20*/
218 break;
219 case OSPFv3RESTARTEXITREASON: /*21*/
220 break;
221 default:
222 return NULL;
223 }
224 return NULL;
225}
226
227static u_char *
228ospfv3AreaEntry (struct variable *v, oid *name, size_t *length,
229 int exact, size_t *var_len, WriteMethod **write_method)
230{
231 struct ospf6_area *oa, *area = NULL;
232 u_int32_t area_id = 0;
paul0c083ee2004-10-10 12:54:58 +0000233 struct listnode *node;
234 unsigned int len;
hassoef1bbf52004-10-08 12:04:21 +0000235
236 if (ospf6 == NULL)
237 return NULL;
238
239 len = *length - v->namelen;
240 len = (len >= sizeof (u_int32_t) ? sizeof (u_int32_t) : 0);
241 if (exact && len != sizeof (u_int32_t))
242 return NULL;
243 if (len)
244 oid2in_addr (name + v->namelen, len, (struct in_addr *) &area_id);
245
246 zlog_info ("SNMP access by area: %s, exact=%d len=%d length=%d",
247 inet_ntoa (* (struct in_addr *) &area_id),
248 exact, len, *length);
249
250 for (node = listhead (ospf6->area_list); node; nextnode (node))
251 {
252 oa = (struct ospf6_area *) getdata (node);
253 if (area == NULL)
254 {
255 if (len == 0) /* return first area entry */
256 area = oa;
257 else if (exact && ntohl (oa->area_id) == ntohl (area_id))
258 area = oa;
259 else if (ntohl (oa->area_id) > ntohl (area_id))
260 area = oa;
261 }
262 }
263
264 if (area == NULL)
265 return NULL;
266
267 *length = v->namelen + sizeof (u_int32_t);
268 oid_copy_addr (name + v->namelen, (struct in_addr *) &area->area_id,
269 sizeof (u_int32_t));
270
271 zlog_info ("SNMP found area: %s, exact=%d len=%d length=%d",
272 inet_ntoa (* (struct in_addr *) &area->area_id),
273 exact, len, *length);
274
275 switch (v->magic)
276 {
277 case OSPFv3AREAID: /* 1*/
278 return SNMP_IPADDRESS (INT32_INADDR (area->area_id));
279 break;
280 case OSPFv3IMPORTASEXTERN: /* 2*/
281 return SNMP_INTEGER (ospf6->external_table->count);
282 break;
283 default:
284 return NULL;
285 break;
286 }
287 return NULL;
288}
289
290/* Register OSPFv3-MIB. */
291void
paul0c083ee2004-10-10 12:54:58 +0000292ospf6_snmp_init (struct thread_master *master)
hassoef1bbf52004-10-08 12:04:21 +0000293{
hassoc75105a2004-10-13 10:33:26 +0000294 smux_init (master);
hassoef1bbf52004-10-08 12:04:21 +0000295 REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
hassoef1bbf52004-10-08 12:04:21 +0000296}
297
298#endif /* HAVE_SNMP */
299