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 /* Zebra enterprise ospf6d MIB */
54 #define OSPF6DOID 1,3,6,1,4,1,3317,1,2,6
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
79 /* OSPFv3 MIB Area Table values. */
80 #define OSPFv3AREAID 1
81 #define OSPFv3IMPORTASEXTERN 2
83 /* SYNTAX Status from OSPF-MIB. */
84 #define OSPF_STATUS_ENABLED 1
85 #define OSPF_STATUS_DISABLED 2
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
95 /* For return values e.g. SNMP_INTEGER macro */
98 static struct in_addr tmp
;
99 #define INT32_INADDR(x) \
100 (tmp.s_addr = (x), tmp)
102 /* OSPFv3-MIB instances. */
103 oid ospfv3_oid
[] = { OSPFv3MIB
};
104 oid ospf6d_oid
[] = { OSPF6DOID
};
106 /* empty ID 0.0.0.0 e.g. empty router-id */
107 static struct in_addr ospf6_empty_id
= {0};
109 /* Hook functions. */
110 static u_char
*ospfv3GeneralGroup ();
111 static u_char
*ospfv3AreaEntry ();
113 struct variable ospfv3_variables
[] =
115 /* OSPF general variables */
116 {OSPFv3ROUTERID
, IPADDRESS
, RWRITE
, ospfv3GeneralGroup
,
118 {OSPFv3ADMINSTAT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
120 {OSPFv3VERSIONNUMBER
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
122 {OSPFv3AREABDRRTRSTATUS
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
124 {OSPFv3ASBDRRTRSTATUS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
126 {OSPFv3ASSCOPELSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
,
128 {OSPFv3ASSCOPELSACHECKSUMSUM
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
130 {OSPFv3ORIGINATENEWLSAS
, COUNTER
, RONLY
, ospfv3GeneralGroup
,
132 {OSPFv3RXNEWLSAS
, COUNTER
, RONLY
, ospfv3GeneralGroup
,
134 {OSPFv3EXTLSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
,
136 {OSPFv3EXTAREALSDBLIMIT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
138 {OSPFv3MULTICASTEXTENSIONS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
140 {OSPFv3EXITOVERFLOWINTERVAL
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
142 {OSPFv3DEMANDEXTENSIONS
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
144 {OSPFv3TRAFFICENGINEERINGSUPPORT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
146 {OSPFv3REFERENCEBANDWIDTH
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
148 {OSPFv3RESTARTSUPPORT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
150 {OSPFv3RESTARTINTERVAL
, INTEGER
, RWRITE
, ospfv3GeneralGroup
,
152 {OSPFv3RESTARTSTATUS
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
154 {OSPFv3RESTARTAGE
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
156 {OSPFv3RESTARTEXITREASON
, INTEGER
, RONLY
, ospfv3GeneralGroup
,
159 /* OSPFv3 Area Data Structure */
160 {OSPFv3AREAID
, IPADDRESS
, RONLY
, ospfv3AreaEntry
,
162 {OSPFv3IMPORTASEXTERN
, INTEGER
, RONLY
, ospfv3AreaEntry
,
167 ospfv3GeneralGroup (struct variable
*v
, oid
*name
, size_t *length
,
168 int exact
, size_t *var_len
, WriteMethod
**write_method
)
170 /* Check whether the instance identifier is valid */
171 if (smux_header_generic (v
, name
, length
, exact
, var_len
, write_method
)
175 /* Return the current value of the variable */
178 case OSPFv3ROUTERID
: /* 1*/
179 /* Router-ID of this OSPF instance. */
181 return SNMP_IPADDRESS (INT32_INADDR (ospf6
->router_id
));
183 return SNMP_IPADDRESS (ospf6_empty_id
);
185 case OSPFv3ADMINSTAT
: /* 2*/
187 case OSPFv3VERSIONNUMBER
: /* 3*/
189 case OSPFv3AREABDRRTRSTATUS
: /* 4*/
191 case OSPFv3ASBDRRTRSTATUS
: /* 5*/
193 case OSPFv3ASSCOPELSACOUNT
: /* 6*/
195 case OSPFv3ASSCOPELSACHECKSUMSUM
: /* 7*/
197 case OSPFv3ORIGINATENEWLSAS
: /* 8*/
199 case OSPFv3RXNEWLSAS
: /* 9*/
201 case OSPFv3EXTLSACOUNT
: /*10*/
203 case OSPFv3EXTAREALSDBLIMIT
: /*11*/
205 case OSPFv3MULTICASTEXTENSIONS
: /*12*/
207 case OSPFv3EXITOVERFLOWINTERVAL
: /*13*/
209 case OSPFv3DEMANDEXTENSIONS
: /*14*/
211 case OSPFv3TRAFFICENGINEERINGSUPPORT
: /*15*/
213 case OSPFv3REFERENCEBANDWIDTH
: /*16*/
215 case OSPFv3RESTARTSUPPORT
: /*17*/
217 case OSPFv3RESTARTINTERVAL
: /*18*/
219 case OSPFv3RESTARTSTATUS
: /*19*/
221 case OSPFv3RESTARTAGE
: /*20*/
223 case OSPFv3RESTARTEXITREASON
: /*21*/
232 ospfv3AreaEntry (struct variable
*v
, oid
*name
, size_t *length
,
233 int exact
, size_t *var_len
, WriteMethod
**write_method
)
235 struct ospf6_area
*oa
, *area
= NULL
;
236 u_int32_t area_id
= 0;
237 struct listnode
*node
;
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
))
248 oid2in_addr (name
+ v
->namelen
, len
, (struct in_addr
*) &area_id
);
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
);
254 for (node
= listhead (ospf6
->area_list
); node
; nextnode (node
))
256 oa
= (struct ospf6_area
*) getdata (node
);
259 if (len
== 0) /* return first area entry */
261 else if (exact
&& ntohl (oa
->area_id
) == ntohl (area_id
))
263 else if (ntohl (oa
->area_id
) > ntohl (area_id
))
271 *length
= v
->namelen
+ sizeof (u_int32_t
);
272 oid_copy_addr (name
+ v
->namelen
, (struct in_addr
*) &area
->area_id
,
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
);
281 case OSPFv3AREAID
: /* 1*/
282 return SNMP_IPADDRESS (INT32_INADDR (area
->area_id
));
284 case OSPFv3IMPORTASEXTERN
: /* 2*/
285 return SNMP_INTEGER (ospf6
->external_table
->count
);
294 /* Register OSPFv3-MIB. */
296 ospf6_snmp_init (struct thread_master
*master
)
298 smux_init (master
, ospf6d_oid
, sizeof (ospf6d_oid
) / sizeof (oid
));
299 REGISTER_MIB ("OSPFv3MIB", ospfv3_variables
, variable
, ospfv3_oid
);
303 #endif /* HAVE_SNMP */