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