Debian Codegraph @

agent/mibgroup/ip-mib/data_access/scalars_linux.c

raw
1 /*
2 * Arp MIB architecture support
3 *
4 * $Id$
5 */
6 #include <net-snmp/net-snmp-config.h>
7 #include <net-snmp/net-snmp-includes.h>
8 #include <net-snmp/agent/net-snmp-agent-includes.h>
9
10 #include <net-snmp/data_access/ip_scalars.h>
11
12 netsnmp_feature_require(register_num_file_instance);
13
14 static const char ipfw_name[] = "/proc/sys/net/ipv4/conf/all/forwarding";
15 static const char ipttl_name[] = "/proc/sys/net/ipv4/ip_default_ttl";
16 static const char ipfw6_name[] = "/proc/sys/net/ipv6/conf/all/forwarding";
17 static const char iphop6_name[] = "/proc/sys/net/ipv6/conf/all/hop_limit";
18
19 int
20 netsnmp_arch_ip_scalars_ipForwarding_get(u_long *value)
21 {
22 FILE *filep;
23 int rc;
24
25 if (NULL == value)
26 return -1;
27
28
29 filep = fopen(ipfw_name, "r");
30 if (NULL == filep) {
31 DEBUGMSGTL(("access:ipForwarding", "could not open %s\n",
32 ipfw_name));
33 return -2;
34 }
35
36 rc = fscanf(filep, "%lu", value);
37 fclose(filep);
38 if (1 != rc) {
39 DEBUGMSGTL(("access:ipForwarding", "could not read %s\n",
40 ipfw_name));
41 return -3;
42 }
43
44 if ((0 != *value) && (1 != *value)) {
45 DEBUGMSGTL(("access:ipForwarding", "unexpected value %ld in %s\n",
46 *value, ipfw_name));
47 return -4;
48 }
49
50 return 0;
51 }
52
53 int
54 netsnmp_arch_ip_scalars_ipForwarding_set(u_long value)
55 {
56 FILE *filep;
57 int rc;
58
59 if (1 == value)
60 ;
61 else if (2 == value)
62 value = 0;
63 else {
64 DEBUGMSGTL(("access:ipForwarding", "bad value %ld for %s\n",
65 value, ipfw_name));
66 return SNMP_ERR_WRONGVALUE;
67 }
68
69 filep = fopen(ipfw_name, "w");
70 if (NULL == filep) {
71 DEBUGMSGTL(("access:ipForwarding", "could not open %s\n",
72 ipfw_name));
73 return SNMP_ERR_RESOURCEUNAVAILABLE;
74 }
75
76 rc = fprintf(filep, "%ld", value);
77 fclose(filep);
78 if (1 != rc) {
79 DEBUGMSGTL(("access:ipForwarding", "could not write %s\n",
80 ipfw_name));
81 return SNMP_ERR_GENERR;
82 }
83
84 return 0;
85 }
86
87 int
88 netsnmp_arch_ip_scalars_ipDefaultTTL_get(u_long *value)
89 {
90 FILE *filep;
91 int rc;
92
93 if (NULL == value)
94 return -1;
95
96
97 filep = fopen(ipttl_name, "r");
98 if (NULL == filep) {
99 DEBUGMSGTL(("access:ipDefaultTTL", "could not open %s\n",
100 ipttl_name));
101 return -2;
102 }
103
104 rc = fscanf(filep, "%lu", value);
105 fclose(filep);
106 if (1 != rc) {
107 DEBUGMSGTL(("access:ipDefaultTTL", "could not read %s\n",
108 ipttl_name));
109 return -3;
110 }
111
112 if ((0 == *value) || (255 < *value)) {
113 DEBUGMSGTL(("access:ipDefaultTTL", "unexpected value %ld in %s\n",
114 *value, ipttl_name));
115 return -4;
116 }
117
118 return 0;
119 }
120
121 int
122 netsnmp_arch_ip_scalars_ipDefaultTTL_set(u_long value)
123 {
124 FILE *filep;
125 int rc;
126
127 if (value == 0 || value > 255) {
128 DEBUGMSGTL(("access:ipDefaultTTL", "bad value %ld for %s\n",
129 value, ipttl_name));
130 return SNMP_ERR_WRONGVALUE;
131 }
132
133 filep = fopen(ipttl_name, "w");
134 if (NULL == filep) {
135 DEBUGMSGTL(("access:ipDefaultTTL", "could not open %s\n",
136 ipttl_name));
137 return SNMP_ERR_RESOURCEUNAVAILABLE;
138 }
139
140 rc = fprintf(filep, "%ld", value);
141 fclose(filep);
142 if (1 != rc) {
143 DEBUGMSGTL(("access:ipDefaultTTL", "could not write %s\n",
144 ipttl_name));
145 return SNMP_ERR_GENERR;
146 }
147
148 return 0;
149 }
150
151 int
152 netsnmp_arch_ip_scalars_ipv6IpForwarding_get(u_long *value)
153 {
154 FILE *filep;
155 int rc;
156
157 if (NULL == value)
158 return -1;
159
160
161 filep = fopen(ipfw6_name, "r");
162 if (NULL == filep) {
163 DEBUGMSGTL(("access:ipv6IpForwarding", "could not open %s\n",
164 ipfw6_name));
165 return -2;
166 }
167
168 rc = fscanf(filep, "%lu", value);
169 fclose(filep);
170 if (1 != rc) {
171 DEBUGMSGTL(("access:ipv6IpForwarding", "could not read %s\n",
172 ipfw6_name));
173 return -3;
174 }
175
176 if ((0 != *value) && (1 != *value)) {
177 DEBUGMSGTL(("access:ipv6IpForwarding", "unexpected value %ld in %s\n",
178 *value, ipfw6_name));
179 return -4;
180 }
181
182 return 0;
183 }
184
185 int
186 netsnmp_arch_ip_scalars_ipv6IpForwarding_set(u_long value)
187 {
188 FILE *filep;
189 int rc;
190
191 if (1 == value)
192 ;
193 else if (2 == value)
194 value = 0;
195 else {
196 DEBUGMSGTL(("access:ipv6IpForwarding",
197 "bad value %ld for ipv6IpForwarding\n", value));
198 return SNMP_ERR_WRONGVALUE;
199 }
200
201 filep = fopen(ipfw6_name, "w");
202 if (NULL == filep) {
203 DEBUGMSGTL(("access:ipv6IpForwarding", "could not open %s\n",
204 ipfw6_name));
205 return SNMP_ERR_RESOURCEUNAVAILABLE;
206 }
207
208 rc = fprintf(filep, "%ld", value);
209 fclose(filep);
210 if (1 != rc) {
211 DEBUGMSGTL(("access:ipv6IpForwarding", "could not write %s\n",
212 ipfw6_name));
213 return SNMP_ERR_GENERR;
214 }
215
216 return 0;
217 }
218
219 int
220 netsnmp_arch_ip_scalars_ipv6IpDefaultHopLimit_get(u_long *value)
221 {
222 FILE *filep;
223 int rc;
224
225 if (NULL == value)
226 return -1;
227
228
229 filep = fopen(iphop6_name, "r");
230 if (NULL == filep) {
231 DEBUGMSGTL(("access:ipDefaultHopLimit", "could not open %s\n",
232 iphop6_name));
233 return -2;
234 }
235
236 rc = fscanf(filep, "%lu", value);
237 fclose(filep);
238 if (1 != rc) {
239 DEBUGMSGTL(("access:ipDefaultHopLimit", "could not read %s\n",
240 iphop6_name));
241 return -3;
242 }
243
244 if ((0 == *value) || (255 < *value)) {
245 DEBUGMSGTL(("access:ipDefaultHopLimit", "unexpected value %ld in %s\n",
246 *value, iphop6_name));
247 return -4;
248 }
249
250 return 0;
251 }
252
253 int
254 netsnmp_arch_ip_scalars_ipv6IpDefaultHopLimit_set(u_long value)
255 {
256 FILE *filep;
257 int rc;
258
259 if (value == 0 || value > 255) {
260 DEBUGMSGTL(("access:ipDefaultHopLimit", "bad value %ld for %s\n",
261 value, iphop6_name));
262 return SNMP_ERR_WRONGVALUE;
263 }
264
265 filep = fopen(iphop6_name, "w");
266 if (NULL == filep) {
267 DEBUGMSGTL(("access:ipDefaultHopLimit", "could not open %s\n",
268 iphop6_name));
269 return SNMP_ERR_RESOURCEUNAVAILABLE;
270 }
271
272 rc = fprintf(filep, "%ld", value);
273 fclose(filep);
274 if (1 != rc) {
275 DEBUGMSGTL(("access:ipDefaultHopLimit", "could not write %s\n",
276 iphop6_name));
277 return SNMP_ERR_GENERR;
278 }
279
280 return 0;
281 }
282
283 void
284 netsnmp_arch_ip_scalars_register_handlers(void)
285 {
286 static oid ipReasmTimeout_oid[] = { 1, 3, 6, 1, 2, 1, 4, 13, 0 };
287
288 netsnmp_register_num_file_instance
289 ("ipReasmTimeout",
290 ipReasmTimeout_oid, OID_LENGTH(ipReasmTimeout_oid),
291 "/proc/sys/net/ipv4/ipfrag_time", ASN_INTEGER,
292 HANDLER_CAN_RONLY, NULL, NULL);
293
294 }