Debian Codegraph @

agent/mibgroup/smux/snmp_rip2.c

raw
1 /*
2 * $Id$
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 #ifdef HAVE_STDLIB_H
13 #include <stdlib.h>
14 #endif
15 #ifdef HAVE_STRING_H
16 #include <string.h>
17 #else
18 #include <strings.h>
19 #endif
20 #ifdef HAVE_UNISTD_H
21 #include <unistd.h>
22 #endif
23 #ifdef HAVE_ERR_H
24 #include <err.h>
25 #endif
26 #ifdef TIME_WITH_SYS_TIME
27 # include <sys/time.h>
28 # include <time.h>
29 #else
30 # ifdef 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 #ifdef HAVE_SYS_FILIO_H
42 #include <sys/filio.h>
43 #endif
44
45 #ifdef 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
58 struct variable13 rip2_variables[] = {
59 {RIP2GLOBALROUTECHANGES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY,
60 var_rip2, 2, {1, 1}},
61 {RIP2GLOBALQUERIES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY,
62 var_rip2, 2, {1, 2}},
63 {RIP2IFSTATADDRESS, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY,
64 var_rip2, 3, {2, 1, 1}},
65 {RIP2IFSTATRCVBADPKTS, ASN_COUNTER, NETSNMP_OLDAPI_RONLY,
66 var_rip2, 3, {2, 1, 2}},
67 {RIP2IFSTATRCVBADROUTES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY,
68 var_rip2, 3, {2, 1, 3}},
69 {RIP2IFSTATSENTUPDATES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY,
70 var_rip2, 3, {2, 1, 4}},
71 {RIP2IFSTATSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
72 var_rip2, 3, {2, 1, 5}},
73 {RIP2IFCONFADDRESS, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY,
74 var_rip2, 3, {3, 1, 1}},
75 {RIP2IFCONFDOMAIN, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE,
76 var_rip2, 3, {3, 1, 2}},
77 {RIP2IFCONFAUTHTYPE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
78 var_rip2, 3, {3, 1, 3}},
79 {RIP2IFCONFAUTHKEY, ASN_OCTET_STR, NETSNMP_OLDAPI_RWRITE,
80 var_rip2, 3, {3, 1, 4}},
81 {RIP2IFCONFSEND, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
82 var_rip2, 3, {3, 1, 5}},
83 {RIP2IFCONFRECEIVE, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
84 var_rip2, 3, {3, 1, 6}},
85 {RIP2IFCONFDEFAULTMETRIC, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
86 var_rip2, 3, {3, 1, 7}},
87 {RIP2IFCONFSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RWRITE,
88 var_rip2, 3, {3, 1, 8}},
89 {RIP2IFCONFSRCADDRESS, ASN_IPADDRESS, NETSNMP_OLDAPI_RWRITE,
90 var_rip2, 3, {3, 1, 9}},
91 {RIP2PEERADDRESS, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY,
92 var_rip2, 3, {4, 1, 1}},
93 {RIP2PEERDOMAIN, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY,
94 var_rip2, 3, {4, 1, 2}},
95 {RIP2PEERLASTUPDATE, ASN_TIMETICKS, NETSNMP_OLDAPI_RONLY,
96 var_rip2, 3, {4, 1, 3}},
97 {RIP2PEERVERSION, ASN_INTEGER, NETSNMP_OLDAPI_RONLY,
98 var_rip2, 3, {4, 1, 4}},
99 {RIP2PEERRCVBADPKTS, ASN_COUNTER, NETSNMP_OLDAPI_RONLY,
100 var_rip2, 3, {4, 1, 5}},
101 {RIP2PEERRCVBADROUTES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY,
102 var_rip2, 3, {4, 1, 6}}
103 };
104
105 oid rip2_variables_oid[] = { NETSNMP_MIB2_OID, 23 };
106
107 void
108 init_snmp_rip2(void)
109 {
110 REGISTER_MIB("smux/snmp_rip2", rip2_variables, variable13,
111 rip2_variables_oid);
112 }
113
114 u_char *
115 var_rip2(struct variable *vp,
116 oid * name,
117 int *length, int exact, int *var_len, WriteMethod ** write_method)
118 {
119 u_char *var;
120 int result;
121
122 DEBUGMSGTL(("smux/snmp_rip2",
123 "[var_rip2] var len %d, oid requested Len %d-", *var_len,
124 *length));
125 DEBUGMSGOID(("smux/snmp_rip2", name, *length));
126 DEBUGMSG(("smux/snmp_rip2", "\n"));
127
128 /*
129 * Pass on the request to Gated.
130 * If the request sent out was a get next, check to see if
131 * it lies in the rip2 range. If it doesn't, return NULL.
132 * In either case, make sure that errors are checked on the
133 * returned packets.
134 */
135
136 /*
137 * No writes for now
138 */
139 *write_method = NULL;
140
141 /*
142 * Donot allow access to the peer stuff as it crashes gated.
143 * However A GetNext on the last 23.3.1.9 variable will force gated into
144 * the peer stuff and cause it to crash.
145 * The only way to fix this is to either solve the Gated problem, or
146 * remove the peer variables from Gated itself and cause it to return
147 * NULL at the crossing. Currently doing the later.
148 */
149
150 /*
151 * Reject GET and GETNEXT for anything above rip2ifconf range
152 */
153 result = snmp_oid_compare(name, *length, max_rip_mib,
154 sizeof(max_rip_mib) / sizeof(u_int));
155
156 if (result >= 0) {
157 DEBUGMSGTL(("smux/snmp_rip2", "Over shot\n"));
158 return NULL;
159 }
160
161 /*
162 * for GETs we need to be in the rip2 range so reject anything below
163 */
164 result = snmp_oid_compare(name, *length, min_rip_mib,
165 sizeof(min_rip_mib) / sizeof(u_int));
166 if (exact && (result < 0)) {
167 DEBUGMSGTL(("smux/snmp_rip2",
168 "Exact but doesn't match length %d, size %d\n",
169 *length, sizeof(min_rip_mib)));
170 return NULL;
171 }
172
173 /*
174 * On return, 'var' points to the value returned which is of length
175 * '*var_len'. 'name' points to the new (same as the one passed in for
176 * GETs) oid which has 'length' suboids.
177 * 'smux_type' contains the type of the variable.
178 */
179 var = smux_snmp_process(exact, name, length, var_len);
180
181 DEBUGMSGTL(("smux/snmp_rip2",
182 "[var_rip2] var len %d, oid obtained Len %d-", *var_len,
183 *length));
184 DEBUGMSGOID(("smux/snmp_rip2", name, *length));
185 DEBUGMSG(("smux/snmp_rip2", "\n"));
186
187 vp->type = smux_type;
188
189 /*
190 * XXX Need a mechanism to return errors in gated's responses
191 */
192
193 if (var == NULL)
194 return NULL;
195
196 /*
197 * Any resullt returned should be within the rip2 tree.
198 * rip_mib - static u_int rip_mib[] = {1, 3, 6, 1, 2, 1, 23};
199 */
200 if (memcmp(rip_mib, name, sizeof(rip_mib)) != 0) {
201 return NULL;
202 } else {
203 return var;
204 }
205 }