Deleted Added
full compact
kern_sysctl.c (12429) kern_sysctl.c (12623)
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Karels at Berkeley Software Design, Inc.
7 *
1/*-
2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Mike Karels at Berkeley Software Design, Inc.
7 *
8 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
9 * project, to make these variables more userfriendly.
10 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.

--- 13 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.

--- 13 unchanged lines hidden (view full) ---

32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)kern_sysctl.c 8.4 (Berkeley) 4/14/94
37 * $Id: kern_sysctl.c,v 1.51 1995/11/16 18:59:49 phk Exp $
40 * $Id: kern_sysctl.c,v 1.52 1995/11/20 12:42:03 phk Exp $
38 */
39
41 */
42
40/*
41 * sysctl system call.
42 */
43
44#include <sys/param.h>
45#include <sys/systm.h>
46#include <sys/sysproto.h>
47#include <sys/kernel.h>
48#include <sys/vnode.h>
49#include <sys/unistd.h>
50#include <sys/conf.h>
51#include <sys/sysctl.h>
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/sysproto.h>
46#include <sys/kernel.h>
47#include <sys/vnode.h>
48#include <sys/unistd.h>
49#include <sys/conf.h>
50#include <sys/sysctl.h>
51#include <sys/malloc.h>
52
53/*
54 * Locking and stats
55 */
56static struct sysctl_lock {
57 int sl_lock;
58 int sl_want;
59 int sl_locked;
60} memlock;
61
62static int sysctl_root SYSCTL_HANDLER_ARGS;
63
64extern struct linker_set sysctl_;
65
52
53/*
54 * Locking and stats
55 */
56static struct sysctl_lock {
57 int sl_lock;
58 int sl_want;
59 int sl_locked;
60} memlock;
61
62static int sysctl_root SYSCTL_HANDLER_ARGS;
63
64extern struct linker_set sysctl_;
65
66/* BEGIN_MIB */
66/*
67 * MIB definitions. XXX Very few of these, if any, belong here.
68 */
67SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
68 "Sysctl internal magic");
69SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0,
70 "High kernel, proc, limits &c");
71SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0,
72 "Virtual memory");
73SYSCTL_NODE(, CTL_FS, fs, CTLFLAG_RW, 0,
74 "File system");

--- 14 unchanged lines hidden (view full) ---

89
90SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, version, 0, "");
91
92SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD, ostype, 0, "");
93
94extern int osreldate;
95SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD, &osreldate, 0, "");
96
69SYSCTL_NODE(, 0, sysctl, CTLFLAG_RW, 0,
70 "Sysctl internal magic");
71SYSCTL_NODE(, CTL_KERN, kern, CTLFLAG_RW, 0,
72 "High kernel, proc, limits &c");
73SYSCTL_NODE(, CTL_VM, vm, CTLFLAG_RW, 0,
74 "Virtual memory");
75SYSCTL_NODE(, CTL_FS, fs, CTLFLAG_RW, 0,
76 "File system");

--- 14 unchanged lines hidden (view full) ---

91
92SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, version, 0, "");
93
94SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD, ostype, 0, "");
95
96extern int osreldate;
97SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD, &osreldate, 0, "");
98
97SYSCTL_INT(_kern, KERN_MAXVNODES, maxvnodes, CTLFLAG_RD, &desiredvnodes, 0, "");
98
99SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD, &maxproc, 0, "");
100
101SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid,
102 CTLFLAG_RD, &maxprocperuid, 0, "");
103
104SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD, 0, ARG_MAX, "");
105
106SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD, 0, _POSIX_VERSION, "");

--- 8 unchanged lines hidden (view full) ---

115SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 0, "");
116#endif
117
118char kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */
119
120SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile,
121 CTLFLAG_RW, kernelname, sizeof kernelname, "");
122
99SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD, &maxproc, 0, "");
100
101SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid,
102 CTLFLAG_RD, &maxprocperuid, 0, "");
103
104SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD, 0, ARG_MAX, "");
105
106SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD, 0, _POSIX_VERSION, "");

--- 8 unchanged lines hidden (view full) ---

115SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 0, "");
116#endif
117
118char kernelname[MAXPATHLEN] = "/kernel"; /* XXX bloat */
119
120SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile,
121 CTLFLAG_RW, kernelname, sizeof kernelname, "");
122
123SYSCTL_STRUCT(_kern, KERN_BOOTTIME, boottime,
124 CTLFLAG_RW, &boottime, timeval, "");
125
126SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
127
128SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, cpu_model, 0, "");
129
130SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 0, 1, "");
131
132SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD, 0, BYTE_ORDER, "");
133
134SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD, 0, PAGE_SIZE, "");
135
123SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 0, 1, "");
124
125SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD, 0, BYTE_ORDER, "");
126
127SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD, 0, PAGE_SIZE, "");
128
136/* END_MIB */
137
138extern int vfs_update_wakeup;
139extern int vfs_update_interval;
140static int
141sysctl_kern_updateinterval SYSCTL_HANDLER_ARGS
142{
143 int error = sysctl_handle_int(oidp,
144 oidp->oid_arg1, oidp->oid_arg2, req);
145 if (!error)
146 wakeup(&vfs_update_wakeup);
147 return error;
148}
149
150SYSCTL_PROC(_kern, KERN_UPDATEINTERVAL, update, CTLTYPE_INT|CTLFLAG_RW,
151 &vfs_update_interval, 0, sysctl_kern_updateinterval, "");
152
153
154char hostname[MAXHOSTNAMELEN];
155
156SYSCTL_STRING(_kern, KERN_HOSTNAME, hostname, CTLFLAG_RW,
157 hostname, sizeof(hostname), "");
158
159int securelevel = -1;
160
161static int

--- 7 unchanged lines hidden (view full) ---

169 return (error);
170 if (level < securelevel && req->p->p_pid != 1)
171 return (EPERM);
172 securelevel = level;
173 return (error);
174}
175
176SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, CTLTYPE_INT|CTLFLAG_RW,
129char hostname[MAXHOSTNAMELEN];
130
131SYSCTL_STRING(_kern, KERN_HOSTNAME, hostname, CTLFLAG_RW,
132 hostname, sizeof(hostname), "");
133
134int securelevel = -1;
135
136static int

--- 7 unchanged lines hidden (view full) ---

144 return (error);
145 if (level < securelevel && req->p->p_pid != 1)
146 return (EPERM);
147 securelevel = level;
148 return (error);
149}
150
151SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, CTLTYPE_INT|CTLFLAG_RW,
177 0, 0, sysctl_kern_securelvl, "");
152 0, 0, sysctl_kern_securelvl, "I", "");
178
153
179static int
180sysctl_kern_dumpdev SYSCTL_HANDLER_ARGS
181{
182 int error;
183 dev_t ndumpdev;
154char domainname[MAXHOSTNAMELEN];
155SYSCTL_STRING(_kern, KERN_DOMAINNAME, domainname, CTLFLAG_RW,
156 &domainname, sizeof(domainname), "");
184
157
185 ndumpdev = dumpdev;
186 error = sysctl_handle_opaque(oidp, &ndumpdev, sizeof ndumpdev, req);
187 if (!error && ndumpdev != dumpdev) {
188 error = setdumpdev(ndumpdev);
189 }
190 return (error);
191}
158long hostid;
159/* Some trouble here, if sizeof (int) != sizeof (long) */
160SYSCTL_INT(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "");
192
161
193SYSCTL_PROC(_kern, KERN_DUMPDEV, dumpdev, CTLTYPE_OPAQUE|CTLFLAG_RW,
194 0, sizeof dumpdev, sysctl_kern_dumpdev, "");
162/*
163 * End of MIB definitions.
164 */
195
165
196static int
197sysctl_hw_physmem SYSCTL_HANDLER_ARGS
198{
199 int error = sysctl_handle_int(oidp, 0, ctob(physmem), req);
200 return (error);
201}
166/*
167 * Initialization of the MIB tree.
168 *
169 * Order by number in each linker_set.
170 */
202
171
203SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_INT|CTLFLAG_RD,
204 0, 0, sysctl_hw_physmem, "");
205
206static int
172static int
207sysctl_hw_usermem SYSCTL_HANDLER_ARGS
208{
209 int error = sysctl_handle_int(oidp, 0,
210 ctob(physmem - cnt.v_wire_count), req);
211 return (error);
212}
213
214SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_INT|CTLFLAG_RD,
215 0, 0, sysctl_hw_usermem, "");
216
217/* END_MIB */
218
219static int
220sysctl_order_cmp(const void *a, const void *b)
221{
222 const struct sysctl_oid **pa, **pb;
223
224 pa = (const struct sysctl_oid **)a;
225 pb = (const struct sysctl_oid **)b;
226 if (*pa == NULL)
227 return (1);
228 if (*pb == NULL)
229 return (-1);
230 return ((*pa)->oid_number - (*pb)->oid_number);
231}
232
233static void
234sysctl_order(void *arg)
235{
173sysctl_order_cmp(const void *a, const void *b)
174{
175 const struct sysctl_oid **pa, **pb;
176
177 pa = (const struct sysctl_oid **)a;
178 pb = (const struct sysctl_oid **)b;
179 if (*pa == NULL)
180 return (1);
181 if (*pb == NULL)
182 return (-1);
183 return ((*pa)->oid_number - (*pb)->oid_number);
184}
185
186static void
187sysctl_order(void *arg)
188{
236 int j;
189 int j, k;
237 struct linker_set *l = (struct linker_set *) arg;
238 struct sysctl_oid **oidpp;
239
190 struct linker_set *l = (struct linker_set *) arg;
191 struct sysctl_oid **oidpp;
192
193 /* First, find the highest oid we have */
240 j = l->ls_length;
241 oidpp = (struct sysctl_oid **) l->ls_items;
194 j = l->ls_length;
195 oidpp = (struct sysctl_oid **) l->ls_items;
196 for (k = 0; j--; oidpp++)
197 if (*oidpp && (*oidpp)->oid_number > k)
198 k = (*oidpp)->oid_number;
199
200 /* Next, replace all OID_AUTO oids with new numbers */
201 j = l->ls_length;
202 oidpp = (struct sysctl_oid **) l->ls_items;
203 k += 100;
204 for (; j--; oidpp++)
205 if (*oidpp && (*oidpp)->oid_number == OID_AUTO)
206 (*oidpp)->oid_number = k++;
207
208 /* Finally: sort by oid */
209 j = l->ls_length;
210 oidpp = (struct sysctl_oid **) l->ls_items;
242 for (; j--; oidpp++) {
243 if (!*oidpp)
244 continue;
245 if ((*oidpp)->oid_arg1 == arg) {
246 *oidpp = 0;
247 continue;
248 }
249 if (((*oidpp)->oid_kind & CTLTYPE) == CTLTYPE_NODE)
250 if (!(*oidpp)->oid_handler)
251 sysctl_order((*oidpp)->oid_arg1);
252 }
253 qsort(l->ls_items, l->ls_length, sizeof l->ls_items[0],
254 sysctl_order_cmp);
255}
256
257SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_order, &sysctl_);
258
211 for (; j--; oidpp++) {
212 if (!*oidpp)
213 continue;
214 if ((*oidpp)->oid_arg1 == arg) {
215 *oidpp = 0;
216 continue;
217 }
218 if (((*oidpp)->oid_kind & CTLTYPE) == CTLTYPE_NODE)
219 if (!(*oidpp)->oid_handler)
220 sysctl_order((*oidpp)->oid_arg1);
221 }
222 qsort(l->ls_items, l->ls_length, sizeof l->ls_items[0],
223 sysctl_order_cmp);
224}
225
226SYSINIT(sysctl, SI_SUB_KMEM, SI_ORDER_ANY, sysctl_order, &sysctl_);
227
228/*
229 * "Staff-functions"
230 *
231 * {0,0} printf the entire MIB-tree.
232 * {0,1,...} return the name of the "..." OID.
233 * {0,2,...} return the next OID.
234 * {0,3} return the OID of the name in "new"
235 * {0,4,...} return the format info for the "..." OID.
236 */
237
259static void
260sysctl_sysctl_debug_dump_node(struct linker_set *l, int i)
261{
262 int j, k;
263 struct sysctl_oid **oidpp;
264
265 j = l->ls_length;
266 oidpp = (struct sysctl_oid **) l->ls_items;

--- 34 unchanged lines hidden (view full) ---

301 case CTLTYPE_QUAD: printf(" Quad\n"); break;
302 case CTLTYPE_OPAQUE: printf(" Opaque/struct\n"); break;
303 default: printf("\n");
304 }
305
306 }
307}
308
238static void
239sysctl_sysctl_debug_dump_node(struct linker_set *l, int i)
240{
241 int j, k;
242 struct sysctl_oid **oidpp;
243
244 j = l->ls_length;
245 oidpp = (struct sysctl_oid **) l->ls_items;

--- 34 unchanged lines hidden (view full) ---

280 case CTLTYPE_QUAD: printf(" Quad\n"); break;
281 case CTLTYPE_OPAQUE: printf(" Opaque/struct\n"); break;
282 default: printf("\n");
283 }
284
285 }
286}
287
309
310static int
311sysctl_sysctl_debug SYSCTL_HANDLER_ARGS
312{
313 sysctl_sysctl_debug_dump_node(&sysctl_, 0);
314 return ENOENT;
315}
316
317SYSCTL_PROC(_sysctl, 0, debug, CTLTYPE_STRING|CTLFLAG_RD,
288static int
289sysctl_sysctl_debug SYSCTL_HANDLER_ARGS
290{
291 sysctl_sysctl_debug_dump_node(&sysctl_, 0);
292 return ENOENT;
293}
294
295SYSCTL_PROC(_sysctl, 0, debug, CTLTYPE_STRING|CTLFLAG_RD,
318 0, 0, sysctl_sysctl_debug, "");
296 0, 0, sysctl_sysctl_debug, "-", "");
319
297
320char domainname[MAXHOSTNAMELEN];
321SYSCTL_STRING(_kern, KERN_DOMAINNAME, domainname, CTLFLAG_RW,
322 &domainname, sizeof(domainname), "");
298static int
299sysctl_sysctl_name SYSCTL_HANDLER_ARGS
300{
301 int *name = (int *) arg1;
302 u_int namelen = arg2;
303 int i, j, error = 0;
304 struct sysctl_oid **oidpp;
305 struct linker_set *lsp = &sysctl_;
306 char buf[10];
323
307
324long hostid;
325/* Some trouble here, if sizeof (int) != sizeof (long) */
326SYSCTL_INT(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "");
308 while (namelen) {
309 if (!lsp) {
310 sprintf(buf,"%d",*name);
311 if (req->oldidx)
312 error = SYSCTL_OUT(req, ".", 1);
313 if (!error)
314 error = SYSCTL_OUT(req, buf, strlen(buf));
315 if (error)
316 return (error);
317 namelen--;
318 name++;
319 continue;
320 }
321 oidpp = (struct sysctl_oid **) lsp->ls_items;
322 j = lsp->ls_length;
323 lsp = 0;
324 for (i = 0; i < j; i++, oidpp++) {
325 if (*oidpp && ((*oidpp)->oid_number != *name))
326 continue;
327
327
328 if (req->oldidx)
329 error = SYSCTL_OUT(req, ".", 1);
330 if (!error)
331 error = SYSCTL_OUT(req, (*oidpp)->oid_name,
332 strlen((*oidpp)->oid_name));
333 if (error)
334 return (error);
335
336 namelen--;
337 name++;
338
339 if (((*oidpp)->oid_kind & CTLTYPE) != CTLTYPE_NODE)
340 break;
341
342 if ((*oidpp)->oid_handler)
343 break;
344
345 lsp = (struct linker_set*)(*oidpp)->oid_arg1;
346 break;
347 }
348 }
349 return (SYSCTL_OUT(req, "", 1));
350}
351
352SYSCTL_NODE(_sysctl, 1, name, CTLFLAG_RD, sysctl_sysctl_name, "");
353
354static int
355sysctl_sysctl_next_ls (struct linker_set *lsp, int *name, u_int namelen,
356 int *next, int *len, int level, struct sysctl_oid **oidp)
357{
358 int i, j;
359 struct sysctl_oid **oidpp;
360
361 oidpp = (struct sysctl_oid **) lsp->ls_items;
362 j = lsp->ls_length;
363 *len = level;
364 for (i = 0; i < j; i++, oidpp++) {
365 if (!*oidpp)
366 continue;
367
368 *next = (*oidpp)->oid_number;
369 *oidp = *oidpp;
370
371 if (!namelen) {
372 if (((*oidpp)->oid_kind & CTLTYPE) != CTLTYPE_NODE)
373 return 0;
374 if ((*oidpp)->oid_handler)
375 /* We really should call the handler here...*/
376 return 0;
377 lsp = (struct linker_set*)(*oidpp)->oid_arg1;
378 return (sysctl_sysctl_next_ls (lsp, 0, 0, next+1,
379 len, level+1, oidp));
380 }
381
382 if ((*oidpp)->oid_number < *name)
383 continue;
384
385 if ((*oidpp)->oid_number > *name) {
386 if (((*oidpp)->oid_kind & CTLTYPE) != CTLTYPE_NODE)
387 return 0;
388 if ((*oidpp)->oid_handler)
389 return 0;
390 lsp = (struct linker_set*)(*oidpp)->oid_arg1;
391 if (!sysctl_sysctl_next_ls (lsp, name+1, namelen-1,
392 next+1, len, level+1, oidp))
393 return (0);
394 namelen = 1;
395 *len = level;
396 continue;
397 }
398 if (((*oidpp)->oid_kind & CTLTYPE) != CTLTYPE_NODE)
399 continue;
400
401 if ((*oidpp)->oid_handler)
402 continue;
403
404 lsp = (struct linker_set*)(*oidpp)->oid_arg1;
405 if (!sysctl_sysctl_next_ls (lsp, name+1, namelen-1, next+1,
406 len, level+1, oidp))
407 return (0);
408 namelen = 1;
409 *len = level;
410 }
411 return 1;
412}
413
414static int
415sysctl_sysctl_next SYSCTL_HANDLER_ARGS
416{
417 int *name = (int *) arg1;
418 u_int namelen = arg2;
419 int i, j, error;
420 struct sysctl_oid *oid;
421 struct linker_set *lsp = &sysctl_;
422 int newoid[CTL_MAXNAME];
423
424 i = sysctl_sysctl_next_ls (lsp, name, namelen, newoid, &j, 1, &oid);
425 if (i)
426 return ENOENT;
427 error = SYSCTL_OUT(req, &oid->oid_kind, sizeof oid->oid_kind);
428 if (!error)
429 error =SYSCTL_OUT(req, newoid, j * sizeof (int));
430 return (error);
431}
432
433SYSCTL_NODE(_sysctl, 2, next, CTLFLAG_RD, sysctl_sysctl_next, "");
434
435static int
436name2oid (char *name, int *oid, int *len, struct sysctl_oid **oidp)
437{
438 int i, j;
439 struct sysctl_oid **oidpp;
440 struct linker_set *lsp = &sysctl_;
441 char *p;
442
443 if (!*name)
444 return ENOENT;
445
446 p = name + strlen(name) - 1 ;
447 if (*p == '.')
448 *p = '\0';
449
450 *len = 0;
451
452 for (p = name; *p && *p != '.'; p++)
453 ;
454 i = *p;
455 if (i == '.')
456 *p = '\0';
457
458 j = lsp->ls_length;
459 oidpp = (struct sysctl_oid **) lsp->ls_items;
460
461 while (j-- && *len < CTL_MAXNAME) {
462 if (!*oidpp)
463 continue;
464 if (strcmp(name, (*oidpp)->oid_name)) {
465 oidpp++;
466 continue;
467 }
468 *oid++ = (*oidpp)->oid_number;
469 (*len)++;
470
471 if (!i) {
472 if (oidp)
473 *oidp = *oidpp;
474 return (0);
475 }
476
477 if (((*oidpp)->oid_kind & CTLTYPE) != CTLTYPE_NODE)
478 break;
479
480 if ((*oidpp)->oid_handler)
481 break;
482
483 lsp = (struct linker_set*)(*oidpp)->oid_arg1;
484 j = lsp->ls_length;
485 oidpp = (struct sysctl_oid **)lsp->ls_items;
486 name = p+1;
487 for (p = name; *p && *p != '.'; p++)
488 ;
489 i = *p;
490 if (i == '.')
491 *p = '\0';
492 }
493 return ENOENT;
494}
495
496static int
497sysctl_sysctl_name2oid SYSCTL_HANDLER_ARGS
498{
499 char *p;
500 int error, oid[CTL_MAXNAME], len;
501 struct sysctl_oid *op = 0;
502
503 if (!req->newlen)
504 return ENOENT;
505
506 p = malloc(req->newlen+1, M_SYSCTL, M_WAITOK);
507
508 error = SYSCTL_IN(req, p, req->newlen);
509 if (error) {
510 free(p, M_SYSCTL);
511 return (error);
512 }
513
514 p [req->newlen] = '\0';
515
516 error = name2oid(p, oid, &len, &op);
517
518 free(p, M_SYSCTL);
519
520 if (error)
521 return (error);
522
523 error = SYSCTL_OUT(req, &op->oid_kind, sizeof op->oid_kind);
524 if (!error)
525 error = SYSCTL_OUT(req, oid, len * sizeof *oid);
526 return (error);
527}
528
529SYSCTL_PROC(_sysctl, 3, name2oid, CTLFLAG_RW, 0, 0,
530 sysctl_sysctl_name2oid, "I", "");
531
532static int
533sysctl_sysctl_oidfmt SYSCTL_HANDLER_ARGS
534{
535 int *name = (int *) arg1;
536 u_int namelen = arg2;
537 int indx, j;
538 struct sysctl_oid **oidpp;
539 struct linker_set *lsp = &sysctl_;
540
541 j = lsp->ls_length;
542 oidpp = (struct sysctl_oid **) lsp->ls_items;
543
544 indx = 0;
545 while (j-- && indx < CTL_MAXNAME) {
546 if (*oidpp && ((*oidpp)->oid_number == name[indx])) {
547 indx++;
548 if (((*oidpp)->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
549 if ((*oidpp)->oid_handler)
550 goto found;
551 if (indx == namelen)
552 return ENOENT;
553 lsp = (struct linker_set*)(*oidpp)->oid_arg1;
554 j = lsp->ls_length;
555 oidpp = (struct sysctl_oid **)lsp->ls_items;
556 } else {
557 if (indx != namelen)
558 return EISDIR;
559 goto found;
560 }
561 } else {
562 oidpp++;
563 }
564 }
565 return ENOENT;
566found:
567 if (!(*oidpp)->oid_fmt)
568 return ENOENT;
569 return (SYSCTL_OUT(req, (*oidpp)->oid_fmt,
570 strlen((*oidpp)->oid_fmt)+1));
571}
572
573
574SYSCTL_NODE(_sysctl, 4, oidfmt, CTLFLAG_RD, sysctl_sysctl_oidfmt, "");
575
328/*
576/*
577 * Default "handler" functions.
578 */
579
580/*
329 * Handle an integer, signed or unsigned.
330 * Two cases:
331 * a variable: point arg1 at it.
332 * a constant: pass it in arg2.
333 */
334
335int
336sysctl_handle_int SYSCTL_HANDLER_ARGS

--- 139 unchanged lines hidden (view full) ---

476 * Traverse our tree, and find the right node, execute whatever it points
477 * at, and return the resulting error code.
478 */
479
480int
481sysctl_root SYSCTL_HANDLER_ARGS
482{
483 int *name = (int *) arg1;
581 * Handle an integer, signed or unsigned.
582 * Two cases:
583 * a variable: point arg1 at it.
584 * a constant: pass it in arg2.
585 */
586
587int
588sysctl_handle_int SYSCTL_HANDLER_ARGS

--- 139 unchanged lines hidden (view full) ---

728 * Traverse our tree, and find the right node, execute whatever it points
729 * at, and return the resulting error code.
730 */
731
732int
733sysctl_root SYSCTL_HANDLER_ARGS
734{
735 int *name = (int *) arg1;
484 int namelen = arg2;
736 u_int namelen = arg2;
485 int indx, i, j;
486 struct sysctl_oid **oidpp;
487 struct linker_set *lsp = &sysctl_;
488
489 j = lsp->ls_length;
490 oidpp = (struct sysctl_oid **) lsp->ls_items;
491
492 indx = 0;

--- 361 unchanged lines hidden ---
737 int indx, i, j;
738 struct sysctl_oid **oidpp;
739 struct linker_set *lsp = &sysctl_;
740
741 j = lsp->ls_length;
742 oidpp = (struct sysctl_oid **) lsp->ls_items;
743
744 indx = 0;

--- 361 unchanged lines hidden ---