Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / net-snmp / agent / mibgroup / smux / snmp_rip2.c
1 /*
2  * $Id: snmp_rip2.c,v 5.0 2002/04/20 07:30:06 hardaker 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_rip2.h"
53
54 static oid      max_rip_mib[] =
55     { 1, 3, 6, 1, 2, 1, 23, 3, 1, 9, 255, 255, 255, 255 };
56 static oid      min_rip_mib[] = { 1, 3, 6, 1, 2, 1, 23, 1, 1, 0 };
57 extern u_char   smux_type;
58
59 struct variable13 rip2_variables[] = {
60     {RIP2GLOBALROUTECHANGES, ASN_COUNTER, RONLY, var_rip2, 2, {1, 1}},
61     {RIP2GLOBALQUERIES, ASN_COUNTER, RONLY, var_rip2, 2, {1, 2}},
62     {RIP2IFSTATADDRESS, ASN_IPADDRESS, RONLY, var_rip2, 3, {2, 1, 1}},
63     {RIP2IFSTATRCVBADPKTS, ASN_COUNTER, RONLY, var_rip2, 3, {2, 1, 2}},
64     {RIP2IFSTATRCVBADROUTES, ASN_COUNTER, RONLY, var_rip2, 3, {2, 1, 3}},
65     {RIP2IFSTATSENTUPDATES, ASN_COUNTER, RONLY, var_rip2, 3, {2, 1, 4}},
66     {RIP2IFSTATSTATUS, ASN_INTEGER, RWRITE, var_rip2, 3, {2, 1, 5}},
67     {RIP2IFCONFADDRESS, ASN_IPADDRESS, RONLY, var_rip2, 3, {3, 1, 1}},
68     {RIP2IFCONFDOMAIN, ASN_OCTET_STR, RWRITE, var_rip2, 3, {3, 1, 2}},
69     {RIP2IFCONFAUTHTYPE, ASN_INTEGER, RWRITE, var_rip2, 3, {3, 1, 3}},
70     {RIP2IFCONFAUTHKEY, ASN_OCTET_STR, RWRITE, var_rip2, 3, {3, 1, 4}},
71     {RIP2IFCONFSEND, ASN_INTEGER, RWRITE, var_rip2, 3, {3, 1, 5}},
72     {RIP2IFCONFRECEIVE, ASN_INTEGER, RWRITE, var_rip2, 3, {3, 1, 6}},
73     {RIP2IFCONFDEFAULTMETRIC, ASN_INTEGER, RWRITE, var_rip2, 3, {3, 1, 7}},
74     {RIP2IFCONFSTATUS, ASN_INTEGER, RWRITE, var_rip2, 3, {3, 1, 8}},
75     {RIP2IFCONFSRCADDRESS, ASN_IPADDRESS, RWRITE, var_rip2, 3, {3, 1, 9}},
76     {RIP2PEERADDRESS, ASN_IPADDRESS, RONLY, var_rip2, 3, {4, 1, 1}},
77     {RIP2PEERDOMAIN, ASN_OCTET_STR, RONLY, var_rip2, 3, {4, 1, 2}},
78     {RIP2PEERLASTUPDATE, ASN_TIMETICKS, RONLY, var_rip2, 3, {4, 1, 3}},
79     {RIP2PEERVERSION, ASN_INTEGER, RONLY, var_rip2, 3, {4, 1, 4}},
80     {RIP2PEERRCVBADPKTS, ASN_COUNTER, RONLY, var_rip2, 3, {4, 1, 5}},
81     {RIP2PEERRCVBADROUTES, ASN_COUNTER, RONLY, var_rip2, 3, {4, 1, 6}}
82 };
83
84 oid             rip2_variables_oid[] = { MIB, 23 };
85
86 void
87 init_snmp_rip2(void)
88 {
89     REGISTER_MIB("smux/snmp_rip2", rip2_variables, variable13,
90                  rip2_variables_oid);
91 }
92
93 u_char         *
94 var_rip2(struct variable *vp,
95          oid * name,
96          int *length, int exact, int *var_len, WriteMethod ** write_method)
97 {
98     u_char         *var;
99     int             result;
100
101     DEBUGMSGTL(("smux/snmp_rip2",
102                 "[var_rip2] var len %d, oid requested Len %d-", *var_len,
103                 *length));
104     DEBUGMSGOID(("smux/snmp_rip2", name, *length));
105     DEBUGMSG(("smux/snmp_rip2", "\n"));
106
107     /*
108      * Pass on the request to Gated.
109      * If the request sent out was a get next, check to see if
110      * it lies in the rip2 range. If it doesn't, return NULL.
111      * In either case, make sure that errors are checked on the
112      * returned packets.
113      */
114
115     /*
116      * No writes for now 
117      */
118     *write_method = NULL;
119
120     /*
121      * Donot allow access to the peer stuff as it crashes gated.
122      * However A GetNext on the last 23.3.1.9 variable will force gated into
123      * the peer stuff and cause it to crash.
124      * The only way to fix this is to either solve the Gated problem, or 
125      * remove the peer variables from Gated itself and cause it to return
126      * NULL at the crossing. Currently doing the later.
127      */
128
129     /*
130      * Reject GET and GETNEXT for anything above rip2ifconf range 
131      */
132     result = snmp_oid_compare(name, *length, max_rip_mib,
133                               sizeof(max_rip_mib) / sizeof(u_int));
134
135     if (result >= 0) {
136         DEBUGMSGTL(("smux/snmp_rip2", "Over shot\n"));
137         return NULL;
138     }
139
140     /*
141      * for GETs we need to be in the rip2 range so reject anything below 
142      */
143     result = snmp_oid_compare(name, *length, min_rip_mib,
144                               sizeof(min_rip_mib) / sizeof(u_int));
145     if (exact && (result < 0)) {
146         DEBUGMSGTL(("smux/snmp_rip2",
147                     "Exact but doesn't match length %d, size %d\n",
148                     *length, sizeof(min_rip_mib)));
149         return NULL;
150     }
151
152     /*
153      * On return, 'var' points to the value returned which is of length
154      * '*var_len'. 'name' points to the new (same as the one passed in for 
155      * GETs) oid which has 'length' suboids.
156      * 'smux_type' contains the type of the variable.
157      */
158     var = smux_snmp_process(exact, name, length, var_len);
159
160     DEBUGMSGTL(("smux/snmp_rip2",
161                 "[var_rip2] var len %d, oid obtained Len %d-", *var_len,
162                 *length));
163     DEBUGMSGOID(("smux/snmp_rip2", name, *length));
164     DEBUGMSG(("smux/snmp_rip2", "\n"));
165
166     vp->type = smux_type;
167
168     /*
169      * XXX Need a mechanism to return errors in gated's responses 
170      */
171
172     if (var == NULL)
173         return NULL;
174
175     /*
176      * Any resullt returned should be within the rip2 tree.
177      * rip_mib - static u_int rip_mib[] = {1, 3, 6, 1, 2, 1, 23};
178      */
179     if (memcmp(rip_mib, name, sizeof(rip_mib)) != 0) {
180         return NULL;
181     } else {
182         return var;
183     }
184 }