# BRCM_VERSION=3
[bcm963xx.git] / userapps / opensource / net-snmp / agent / mibgroup / smux / snmp_ospf.c
1 /*
2  * $Id: snmp_ospf.c,v 1.1.1.1 2005/04/29 01:45:14 echo Exp $ 
3  */
4
5 /*
6  * Smux module authored by Rohit Dube.
7  */
8
9 #include <net-snmp/net-snmp-config.h>
10
11 #include <stdio.h>
12 #if HAVE_STDLIB_H
13 #include <stdlib.h>
14 #endif
15 #if HAVE_STRING_H
16 #include <string.h>
17 #else
18 #include <strings.h>
19 #endif
20 #if HAVE_UNISTD_H
21 #include <unistd.h>
22 #endif
23 #if HAVE_ERR_H
24 #include <err.h>
25 #endif
26 #if TIME_WITH_SYS_TIME
27 # include <sys/time.h>
28 # include <time.h>
29 #else
30 # if HAVE_SYS_TIME_H
31 #  include <sys/time.h>
32 # else
33 #  include <time.h>
34 # endif
35 #endif
36 #include <errno.h>
37 #include <netdb.h>
38
39 #include <sys/stat.h>
40 #include <sys/socket.h>
41 #if HAVE_SYS_FILIO_H
42 #include <sys/filio.h>
43 #endif
44
45 #if HAVE_NETINET_IN_H
46 #include <netinet/in.h>
47 #endif
48
49 #include <net-snmp/net-snmp-includes.h>
50 #include <net-snmp/agent/net-snmp-agent-includes.h>
51 #include "smux.h"
52 #include "snmp_ospf.h"
53
54 static oid      max_ospf_mib[] = { 1, 3, 6, 1, 2, 1, 14, 14, 1, 6, 0 };
55 static oid      min_ospf_mib[] =
56     { 1, 3, 6, 1, 2, 1, 14, 1, 1, 0, 0, 0, 0 };
57 extern u_char   smux_type;
58
59 struct variable13 ospf_variables[] = {
60     {ospfRouterId, ASN_IPADDRESS, RWRITE, var_ospf, 3, {1, 1, 1}},
61     {ospfAdminStat, ASN_INTEGER, RWRITE, var_ospf, 3, {1, 1, 2}},
62     {ospfVersionNumber, ASN_INTEGER, RONLY, var_ospf, 3, {1, 1, 3}},
63     {ospfAreaBdrRtrStatus, ASN_INTEGER, RONLY, var_ospf, 3, {1, 1, 4}},
64     {ospfASBdrRtrStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {1, 1, 5}},
65     {ospfExternLsaCount, ASN_GAUGE, RONLY, var_ospf, 3, {1, 1, 6}},
66     {ospfExternLsaCksumSum, ASN_INTEGER, RONLY, var_ospf, 3, {1, 1, 7}},
67     {ospfTOSSupport, ASN_INTEGER, RWRITE, var_ospf, 3, {1, 1, 8}},
68     {ospfOriginateNewLsas, ASN_COUNTER, RONLY, var_ospf, 3, {1, 1, 9}},
69     {ospfRxNewLsas, ASN_COUNTER, RONLY, var_ospf, 3, {1, 1, 10, 0}},
70     {ospfExtLsdbLimit, ASN_INTEGER, RWRITE, var_ospf, 3, {1, 1, 11}},
71     {ospfMulticastExtensions, ASN_INTEGER, RWRITE, var_ospf, 3,
72      {1, 1, 12}},
73     {ospfAreaId, ASN_IPADDRESS, RONLY, var_ospf, 3, {2, 1, 1}},
74     {ospfAuthType, ASN_INTEGER, RWRITE, var_ospf, 3, {2, 1, 2}},
75     {ospfImportAsExtern, ASN_INTEGER, RWRITE, var_ospf, 3, {2, 1, 3}},
76     {ospfSpfRuns, ASN_COUNTER, RONLY, var_ospf, 3, {2, 1, 4}},
77     {ospfAreaBdrRtrCount, ASN_GAUGE, RONLY, var_ospf, 3, {2, 1, 5}},
78     {ospfAsBdrRtrCount, ASN_GAUGE, RONLY, var_ospf, 3, {2, 1, 6}},
79     {ospfAreaLsaCount, ASN_GAUGE, RONLY, var_ospf, 3, {2, 1, 7}},
80     {ospfAreaLsaCksumSum, ASN_INTEGER, RONLY, var_ospf, 3, {2, 1, 8}},
81     {ospfAreaSummary, ASN_INTEGER, RWRITE, var_ospf, 3, {2, 1, 9}},
82     {ospfAreaStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {2, 1, 10}},
83     {ospfStubAreaId, ASN_IPADDRESS, RONLY, var_ospf, 3, {3, 1, 1}},
84     {ospfStubTOS, ASN_INTEGER, RONLY, var_ospf, 3, {3, 1, 2}},
85     {ospfStubMetric, ASN_INTEGER, RWRITE, var_ospf, 3, {3, 1, 3}},
86     {ospfStubStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {3, 1, 4}},
87     {ospfStubMetricType, ASN_INTEGER, RWRITE, var_ospf, 3, {3, 1, 5}},
88     {ospfLsdbAreaId, ASN_IPADDRESS, RONLY, var_ospf, 3, {4, 1, 1}},
89     {ospfLsdbType, ASN_INTEGER, RONLY, var_ospf, 3, {4, 1, 2}},
90     {ospfLsdbLsid, ASN_IPADDRESS, RONLY, var_ospf, 3, {4, 1, 3}},
91     {ospfLsdbRouterId, ASN_IPADDRESS, RONLY, var_ospf, 3, {4, 1, 4}},
92     {ospfLsdbSequence, ASN_INTEGER, RONLY, var_ospf, 3, {4, 1, 5}},
93     {ospfLsdbAge, ASN_INTEGER, RONLY, var_ospf, 3, {4, 1, 6}},
94     {ospfLsdbChecksum, ASN_INTEGER, RONLY, var_ospf, 3, {4, 1, 7}},
95     {ospfLsdbAdvertisement, ASN_OCTET_STR, RONLY, var_ospf, 3, {4, 1, 8}},
96     {ospfAreaRangeAreaId, ASN_IPADDRESS, RONLY, var_ospf, 3, {5, 1, 1}},
97     {ospfAreaRangeNet, ASN_IPADDRESS, RONLY, var_ospf, 3, {5, 1, 2}},
98     {ospfAreaRangeMask, ASN_IPADDRESS, RWRITE, var_ospf, 3, {5, 1, 3}},
99     {ospfAreaRangeStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {5, 1, 4}},
100     {ospfAreaRangeEffect, ASN_INTEGER, RWRITE, var_ospf, 3, {5, 1, 5}},
101     {ospfHostIpAddress, ASN_IPADDRESS, RONLY, var_ospf, 3, {6, 1, 1}},
102     {ospfHostTOS, ASN_INTEGER, RONLY, var_ospf, 3, {6, 1, 2}},
103     {ospfHostMetric, ASN_INTEGER, RWRITE, var_ospf, 3, {6, 1, 3}},
104     {ospfHostStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {6, 1, 4}},
105     {ospfHostAreaID, ASN_IPADDRESS, RONLY, var_ospf, 3, {6, 1, 5}},
106     {ospfIfIpAddress, ASN_IPADDRESS, RONLY, var_ospf, 3, {7, 1, 1}},
107     {ospfAddressLessIf, ASN_INTEGER, RONLY, var_ospf, 3, {7, 1, 2}},
108     {ospfIfAreaId, ASN_IPADDRESS, RWRITE, var_ospf, 3, {7, 1, 3}},
109     {ospfIfType, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 4}},
110     {ospfIfAdminStat, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 5}},
111     {ospfIfRtrPriority, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 6}},
112     {ospfIfTransitDelay, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 7}},
113     {ospfIfRetransInterval, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 8}},
114     {ospfIfHelloInterval, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 9}},
115     {ospfIfRtrDeadInterval, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 10}},
116     {ospfIfPollInterval, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 11}},
117     {ospfIfState, ASN_INTEGER, RONLY, var_ospf, 3, {7, 1, 12}},
118     {ospfIfDesignatedRouter, ASN_IPADDRESS, RONLY, var_ospf, 3,
119      {7, 1, 13}},
120     {ospfIfBackupDesignatedRouter, ASN_IPADDRESS, RONLY, var_ospf, 3,
121      {7, 1, 14}},
122     {ospfIfEvents, ASN_COUNTER, RONLY, var_ospf, 3, {7, 1, 15}},
123     {ospfIfAuthKey, ASN_OCTET_STR, RWRITE, var_ospf, 3, {7, 1, 16}},
124     {ospfIfStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {7, 1, 17}},
125     {ospfIfMulticastForwarding, ASN_INTEGER, RWRITE, var_ospf, 3,
126      {7, 1, 18}},
127     {ospfIfMetricIpAddress, ASN_IPADDRESS, RONLY, var_ospf, 3, {8, 1, 1}},
128     {ospfIfMetricAddressLessIf, ASN_INTEGER, RONLY, var_ospf, 3,
129      {8, 1, 2}},
130     {ospfIfMetricTOS, ASN_INTEGER, RONLY, var_ospf, 3, {8, 1, 3}},
131     {ospfIfMetricValue, ASN_INTEGER, RWRITE, var_ospf, 3, {8, 1, 4}},
132     {ospfIfMetricStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {8, 1, 5}},
133     {ospfVirtIfAreaId, ASN_IPADDRESS, RONLY, var_ospf, 3, {9, 1, 1}},
134     {ospfVirtIfNeighbor, ASN_IPADDRESS, RONLY, var_ospf, 3, {9, 1, 2}},
135     {ospfVirtIfTransitDelay, ASN_INTEGER, RWRITE, var_ospf, 3, {9, 1, 3}},
136     {ospfVirtIfRetransInterval, ASN_INTEGER, RWRITE, var_ospf, 3,
137      {9, 1, 4}},
138     {ospfVirtIfHelloInterval, ASN_INTEGER, RWRITE, var_ospf, 3, {9, 1, 5}},
139     {ospfVirtIfRtrDeadInterval, ASN_INTEGER, RWRITE, var_ospf, 3,
140      {9, 1, 6}},
141     {ospfVirtIfState, ASN_INTEGER, RONLY, var_ospf, 3, {9, 1, 7}},
142     {ospfVirtIfEvents, ASN_COUNTER, RONLY, var_ospf, 3, {9, 1, 8}},
143     {ospfVirtIfAuthKey, ASN_OCTET_STR, RWRITE, var_ospf, 3, {9, 1, 9}},
144     {ospfVirtIfStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {9, 1, 10}},
145     {ospfNbrIpAddr, ASN_IPADDRESS, RONLY, var_ospf, 3, {10, 1, 1}},
146     {ospfNbrAddressLessIndex, ASN_INTEGER, RONLY, var_ospf, 3, {10, 1, 2}},
147     {ospfNbrRtrId, ASN_IPADDRESS, RONLY, var_ospf, 3, {10, 1, 3}},
148     {ospfNbrOptions, ASN_INTEGER, RONLY, var_ospf, 3, {10, 1, 4}},
149     {ospfNbrPriority, ASN_INTEGER, RWRITE, var_ospf, 3, {10, 1, 5}},
150     {ospfNbrState, ASN_INTEGER, RONLY, var_ospf, 3, {10, 1, 6}},
151     {ospfNbrEvents, ASN_COUNTER, RONLY, var_ospf, 3, {10, 1, 7}},
152     {ospfNbrLsRetransQLen, ASN_GAUGE, RONLY, var_ospf, 3, {10, 1, 8}},
153     {ospfNbmaNbrStatus, ASN_INTEGER, RWRITE, var_ospf, 3, {10, 1, 9}},
154     {ospfNbmaNbrPermanence, ASN_INTEGER, RWRITE, var_ospf, 3, {10, 1, 10}},
155     {ospfVirtNbrArea, ASN_IPADDRESS, RONLY, var_ospf, 3, {11, 1, 1}},
156     {ospfVirtNbrRtrId, ASN_IPADDRESS, RONLY, var_ospf, 3, {11, 1, 2}},
157     {ospfVirtNbrIpAddr, ASN_IPADDRESS, RONLY, var_ospf, 3, {11, 1, 3}},
158     {ospfVirtNbrOptions, ASN_INTEGER, RONLY, var_ospf, 3, {11, 1, 4}},
159     {ospfVirtNbrState, ASN_INTEGER, RONLY, var_ospf, 3, {11, 1, 5}},
160     {ospfVirtNbrEvents, ASN_COUNTER, RONLY, var_ospf, 3, {11, 1, 6}},
161     {ospfVirtNbrLsRetransQLen, ASN_GAUGE, RONLY, var_ospf, 3, {11, 1, 7}},
162     {ospfExtLsdbType, ASN_INTEGER, RONLY, var_ospf, 3, {12, 1, 1}},
163     {ospfExtLsdbLsid, ASN_IPADDRESS, RONLY, var_ospf, 3, {12, 1, 2}},
164     {ospfExtLsdbRouterId, ASN_IPADDRESS, RONLY, var_ospf, 3, {12, 1, 3}},
165     {ospfExtLsdbSequence, ASN_INTEGER, RONLY, var_ospf, 3, {12, 1, 4}},
166     {ospfExtLsdbAge, ASN_INTEGER, RONLY, var_ospf, 3, {12, 1, 5}},
167     {ospfExtLsdbChecksum, ASN_INTEGER, RONLY, var_ospf, 3, {12, 1, 6}},
168     {ospfExtLsdbAdvertisement, ASN_OCTET_STR, RONLY, var_ospf, 3,
169      {12, 1, 7}},
170     {ospfAreaAggregateAreaID, ASN_IPADDRESS, RONLY, var_ospf, 3,
171      {14, 1, 1}},
172     {ospfAreaAggregateLsdbType, ASN_INTEGER, RONLY, var_ospf, 3,
173      {14, 1, 2}},
174     {ospfAreaAggregateNet, ASN_IPADDRESS, RONLY, var_ospf, 3, {14, 1, 3}},
175     {ospfAreaAggregateMask, ASN_IPADDRESS, RWRITE, var_ospf, 3,
176      {14, 1, 4}},
177     {ospfAreaAggregateStatus, ASN_INTEGER, RWRITE, var_ospf, 3,
178      {14, 1, 5}},
179     {ospfAreaAggregateEffect, ASN_INTEGER, RWRITE, var_ospf, 3, {14, 1, 6}}
180 };
181
182 oid             ospf_variables_oid[] = { MIB, 14 };
183
184 void
185 init_snmp_ospf(void)
186 {
187     REGISTER_MIB("smux/snmp_ospf", ospf_variables, variable13,
188                  ospf_variables_oid);
189 }
190
191 u_char         *
192 var_ospf(struct variable *vp,
193          oid * name,
194          int *length, int exact, int *var_len, WriteMethod ** write_method)
195 {
196     u_char         *var;
197     int             result;
198
199     DEBUGMSGTL(("smux/snmp_ospf",
200                 "[var_ospf] var len %d, oid requested Len %d-", *var_len,
201                 *length));
202     DEBUGMSGOID(("smux/snmp_ospf", name, *length));
203     DEBUGMSG(("smux/snmp_ospf", "\n"));
204
205     /*
206      * Pass on the request to Gated.
207      * If the request sent out was a get next, check to see if
208      * it lies in the ospf range. If it doesn't, return NULL.
209      * In either case, make sure that errors are checked on the
210      * returned packets.
211      */
212
213     /*
214      * No writes for now 
215      */
216     *write_method = NULL;
217
218     /*
219      * Donot allow access to the peer stuff as it crashes gated.
220      * However A GetNext on the last 23.3.1.9 variable will force gated into
221      * the peer stuff and cause it to crash.
222      * The only way to fix this is to either solve the Gated problem, or 
223      * remove the peer variables from Gated itself and cause it to return
224      * NULL at the crossing. Currently doing the later.
225      */
226
227     /*
228      * Reject GET and GETNEXT for anything above ospfifconf range 
229      */
230     result = snmp_oid_compare(name, *length, max_ospf_mib,
231                               sizeof(max_ospf_mib) / sizeof(u_int));
232
233     if (result >= 0) {
234         DEBUGMSGTL(("smux/snmp_ospf", "Over shot\n"));
235         return NULL;
236     }
237
238     /*
239      * for GETs we need to be in the ospf range so reject anything below 
240      */
241     result = snmp_oid_compare(name, *length, min_ospf_mib,
242                               sizeof(min_ospf_mib) / sizeof(u_int));
243     if (exact && (result < 0)) {
244         DEBUGMSGTL(("smux/snmp_ospf",
245                     "Exact but doesn't match length %d, size %d\n",
246                     *length, sizeof(min_ospf_mib)));
247         return NULL;
248     }
249
250     /*
251      * On return, 'var' points to the value returned which is of length
252      * '*var_len'. 'name' points to the new (same as the one passed in for 
253      * GETs) oid which has 'length' suboids.
254      * 'smux_type' contains the type of the variable.
255      */
256     var = smux_snmp_process(exact, name, length, var_len);
257
258     DEBUGMSGTL(("smux/snmp_ospf",
259                 "[var_ospf] var len %d, oid obtained Len %d-", *var_len,
260                 *length));
261     DEBUGMSGOID(("smux/snmp_ospf", name, *length));
262     DEBUGMSG(("smux/snmp_ospf", "\n"));
263
264     vp->type = smux_type;
265
266     /*
267      * XXX Need a mechanism to return errors in gated's responses 
268      */
269
270     if (var == NULL)
271         return NULL;
272
273     /*
274      * Any resullt returned should be within the ospf tree.
275      * ospf_mib - static u_int ospf_mib[] = {1, 3, 6, 1, 2, 1, 14};
276      */
277     if (memcmp(ospf_mib, name, sizeof(ospf_mib)) != 0) {
278         return NULL;
279     } else {
280         return var;
281     }
282 }