sysctl.h revision 11863
1/*
2 * Copyright (c) 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 * 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.
16 * 3. All advertising materials mentioning features or use of this software
17 *    must display the following acknowledgement:
18 *	This product includes software developed by the University of
19 *	California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 *    may be used to endorse or promote products derived from this software
22 *    without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
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 *	@(#)sysctl.h	8.1 (Berkeley) 6/2/93
37 * $Id: sysctl.h,v 1.24 1995/07/10 08:39:49 davidg Exp $
38 */
39
40#ifndef _SYS_SYSCTL_H_
41#define	_SYS_SYSCTL_H_
42
43
44/*
45 * These are for the eproc structure defined below.
46 */
47#ifndef KERNEL
48#include <sys/time.h>
49#include <sys/ucred.h>
50#include <sys/proc.h>
51#include <vm/vm.h>
52#endif
53
54/*
55 * Definitions for sysctl call.  The sysctl call uses a hierarchical name
56 * for objects that can be examined or modified.  The name is expressed as
57 * a sequence of integers.  Like a file path name, the meaning of each
58 * component depends on its place in the hierarchy.  The top-level and kern
59 * identifiers are defined here, and other identifiers are defined in the
60 * respective subsystem header files.
61 */
62
63#define CTL_MAXNAME	12	/* largest number of components supported */
64
65/*
66 * Each subsystem defined by sysctl defines a list of variables
67 * for that subsystem. Each name is either a node with further
68 * levels defined below it, or it is a leaf of some particular
69 * type given below. Each sysctl level defines a set of name/type
70 * pairs to be used by sysctl(1) in manipulating the subsystem.
71 */
72struct ctlname {
73	char	*ctl_name;	/* subsystem name */
74	int	ctl_type;	/* type of name */
75};
76
77#define CTLTYPE		0xf	/* Mask */
78#define	CTLTYPE_NODE	1	/* name is a node */
79#define	CTLTYPE_INT	2	/* name describes an integer */
80#define	CTLTYPE_STRING	3	/* name describes a string */
81#define	CTLTYPE_QUAD	4	/* name describes a 64-bit number */
82#define	CTLTYPE_OPAQUE	5	/* name describes a structure */
83#define	CTLTYPE_STRUCT	CTLTYPE_OPAQUE	/* name describes a structure */
84
85#define CTLFLAG_RD	0x80000000	/* Allow reads of variable */
86#define CTLFLAG_WR	0x40000000	/* Allow writes to the variable */
87#define CTLFLAG_RW	(CTLFLAG_RD|CTLFLAG_WR)
88#define CTLFLAG_XLT	0x20000000	/* Variable is xlated by function */
89#define CTLFLAG_NOLOCK	0x10000000	/* XXX Don't Lock */
90
91#define CTLBEFORE	0
92#define CTLAFTER	1
93
94
95struct sysctl_oid {
96	int		oid_number;
97	int		oid_kind;
98	void		*oid_arg1;
99	int		oid_arg2;
100	char		*oid_name;
101	int 		(*oid_handler)(struct sysctl_oid *, int, int);
102};
103typedef int (*sysctl_handler)(struct sysctl_oid *, int, int);
104
105/* This is the "raw" function for a mib-oid */
106#define SYSCTL_OID(parent,number,name,kind,arg1,arg2,handler,descr) \
107	static const struct sysctl_oid sysctl__##parent##_##name = { \
108		number, kind, arg1, arg2, #name, handler }; \
109	TEXT_SET(sysctl_##parent, sysctl__##parent##_##name);
110
111/* This makes a node from which other oids can hang */
112#define SYSCTL_NODE(parent,number,name,handler,descr) \
113	extern struct linker_set sysctl_##parent##_##name; \
114	SYSCTL_OID(parent,number,name, CTLTYPE_NODE, \
115		(void*)&sysctl_##parent##_##name,0,handler,descr); \
116	TEXT_SET(sysctl_##parent##_##name, sysctl__##parent##_##name);
117
118/* This is a string len can be 0 to indicate '\0' termination */
119#define SYSCTL_STRING(parent,number,name,access,arg,len,handler,descr) \
120	SYSCTL_OID(parent,number,name, CTLTYPE_STRING|access,\
121		arg,len,handler,descr);
122
123/* This is a integer, if ptr is NULL, val is returned */
124#define SYSCTL_INT(parent,number,name,access,ptr,val,handler,descr) \
125	SYSCTL_OID(parent,number,name,CTLTYPE_INT|access,\
126		ptr,val,handler,descr);
127
128/* This is anything, specified by a pointer and a lenth */
129#define SYSCTL_OPAQUE(parent,number,name,access,ptr,len,handler,descr) \
130	SYSCTL_OID(parent,number,name,CTLTYPE_OPAQUE|access,\
131		ptr,len,handler,descr);
132
133/* This is a struct, specified by a pointer and type */
134#define SYSCTL_STRUCT(parent,number,name,access,ptr,type,handler,descr) \
135	SYSCTL_OID(parent,number,name,CTLTYPE_OPAQUE|access,\
136		ptr,sizeof(struct type),handler,descr);
137
138/* Needs a proc.  Specify by pointer and arg */
139#define SYSCTL_PROC(parent,number,name,access,ptr,arg,handler,descr) \
140	SYSCTL_OID(parent,number,name,CTLTYPE_PROC|access,\
141		ptr,arg,handler,descr);
142
143/*
144 * Top-level identifiers
145 */
146#define	CTL_UNSPEC	0		/* unused */
147#define	CTL_KERN	1		/* "high kernel": proc, limits */
148#define	CTL_VM		2		/* virtual memory */
149#define	CTL_FS		3		/* file system, mount type is next */
150#define	CTL_NET		4		/* network, see socket.h */
151#define	CTL_DEBUG	5		/* debugging parameters */
152#define	CTL_HW		6		/* generic cpu/io */
153#define	CTL_MACHDEP	7		/* machine dependent */
154#define	CTL_USER	8		/* user-level */
155#define	CTL_MAXID	9		/* number of valid top-level ids */
156
157#define CTL_NAMES { \
158	{ 0, 0 }, \
159	{ "kern", CTLTYPE_NODE }, \
160	{ "vm", CTLTYPE_NODE }, \
161	{ "fs", CTLTYPE_NODE }, \
162	{ "net", CTLTYPE_NODE }, \
163	{ "debug", CTLTYPE_NODE }, \
164	{ "hw", CTLTYPE_NODE }, \
165	{ "machdep", CTLTYPE_NODE }, \
166	{ "user", CTLTYPE_NODE }, \
167}
168
169/*
170 * CTL_KERN identifiers
171 */
172#define	KERN_OSTYPE	 	 1	/* string: system version */
173#define	KERN_OSRELEASE	 	 2	/* string: system release */
174#define	KERN_OSREV	 	 3	/* int: system revision */
175#define	KERN_VERSION	 	 4	/* string: compile time info */
176#define	KERN_MAXVNODES	 	 5	/* int: max vnodes */
177#define	KERN_MAXPROC	 	 6	/* int: max processes */
178#define	KERN_MAXFILES	 	 7	/* int: max open files */
179#define	KERN_ARGMAX	 	 8	/* int: max arguments to exec */
180#define	KERN_SECURELVL	 	 9	/* int: system security level */
181#define	KERN_HOSTNAME		10	/* string: hostname */
182#define	KERN_HOSTID		11	/* int: host identifier */
183#define	KERN_CLOCKRATE		12	/* struct: struct clockrate */
184#define	KERN_VNODE		13	/* struct: vnode structures */
185#define	KERN_PROC		14	/* struct: process entries */
186#define	KERN_FILE		15	/* struct: file entries */
187#define	KERN_PROF		16	/* node: kernel profiling info */
188#define	KERN_POSIX1		17	/* int: POSIX.1 version */
189#define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
190#define	KERN_JOB_CONTROL	19	/* int: is job control available */
191#define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
192#define	KERN_BOOTTIME		21	/* struct: time kernel was booted */
193#define KERN_DOMAINNAME		22	/* string: YP domain name */
194#define KERN_UPDATEINTERVAL	23	/* int: update process sleep time */
195#define KERN_OSRELDATE		24	/* int: OS release date */
196#define KERN_NTP_PLL		25	/* node: NTP PLL control */
197#define	KERN_BOOTFILE		26	/* string: name of booted kernel */
198#define	KERN_MAXFILESPERPROC	27	/* int: max open files per proc */
199#define	KERN_MAXPROCPERUID 	28	/* int: max processes per uid */
200#define KERN_DUMPDEV		29	/* dev_t: device to dump on */
201#define KERN_MAXID              30      /* number of valid kern ids */
202
203#define CTL_KERN_NAMES { \
204	{ 0, 0 }, \
205	{ "ostype", CTLTYPE_STRING }, \
206	{ "osrelease", CTLTYPE_STRING }, \
207	{ "osrevision", CTLTYPE_INT }, \
208	{ "version", CTLTYPE_STRING }, \
209	{ "maxvnodes", CTLTYPE_INT }, \
210	{ "maxproc", CTLTYPE_INT }, \
211	{ "maxfiles", CTLTYPE_INT }, \
212	{ "argmax", CTLTYPE_INT }, \
213	{ "securelevel", CTLTYPE_INT }, \
214	{ "hostname", CTLTYPE_STRING }, \
215	{ "hostid", CTLTYPE_INT }, \
216	{ "clockrate", CTLTYPE_STRUCT }, \
217	{ "vnode", CTLTYPE_STRUCT }, \
218	{ "proc", CTLTYPE_STRUCT }, \
219	{ "file", CTLTYPE_STRUCT }, \
220	{ "profiling", CTLTYPE_NODE }, \
221	{ "posix1version", CTLTYPE_INT }, \
222	{ "ngroups", CTLTYPE_INT }, \
223	{ "job_control", CTLTYPE_INT }, \
224	{ "saved_ids", CTLTYPE_INT }, \
225	{ "boottime", CTLTYPE_STRUCT }, \
226	{ "domainname", CTLTYPE_STRING }, \
227	{ "update", CTLTYPE_INT }, \
228	{ "osreldate", CTLTYPE_INT }, \
229        { "ntp_pll", CTLTYPE_NODE }, \
230	{ "bootfile", CTLTYPE_STRING }, \
231	{ "maxfilesperproc", CTLTYPE_INT }, \
232	{ "maxprocperuid", CTLTYPE_INT }, \
233	{ "dumpdev", CTLTYPE_STRUCT }, /* we lie; don't print as int */ \
234}
235
236/*
237 * CTL_FS identifiers
238 */
239#define FS_VFSCONF		0	/* get configured filesystems */
240#define FS_MAXID		1	/* number of items */
241
242#define CTL_FS_NAMES { \
243	{ "vfsconf", CTLTYPE_STRUCT }, \
244}
245
246/*
247 * KERN_PROC subtypes
248 */
249#define KERN_PROC_ALL		0	/* everything */
250#define	KERN_PROC_PID		1	/* by process id */
251#define	KERN_PROC_PGRP		2	/* by process group id */
252#define	KERN_PROC_SESSION	3	/* by session of pid */
253#define	KERN_PROC_TTY		4	/* by controlling tty */
254#define	KERN_PROC_UID		5	/* by effective uid */
255#define	KERN_PROC_RUID		6	/* by real uid */
256
257/*
258 * KERN_PROC subtype ops return arrays of augmented proc structures:
259 */
260struct kinfo_proc {
261	struct	proc kp_proc;			/* proc structure */
262	struct	eproc {
263		struct	proc *e_paddr;		/* address of proc */
264		struct	session *e_sess;	/* session pointer */
265		struct	pcred e_pcred;		/* process credentials */
266		struct	ucred e_ucred;		/* current credentials */
267		struct	vmspace e_vm;		/* address space */
268		pid_t	e_ppid;			/* parent process id */
269		pid_t	e_pgid;			/* process group id */
270		short	e_jobc;			/* job control counter */
271		dev_t	e_tdev;			/* controlling tty dev */
272		pid_t	e_tpgid;		/* tty process group id */
273		struct	session *e_tsess;	/* tty session pointer */
274#define	WMESGLEN	7
275		char	e_wmesg[WMESGLEN+1];	/* wchan message */
276		segsz_t e_xsize;		/* text size */
277		short	e_xrssize;		/* text rss */
278		short	e_xccount;		/* text references */
279		short	e_xswrss;
280		long	e_flag;
281#define	EPROC_CTTY	0x01	/* controlling tty vnode active */
282#define	EPROC_SLEADER	0x02	/* session leader */
283		char	e_login[MAXLOGNAME];	/* setlogin() name */
284		long	e_spare[4];
285	} kp_eproc;
286};
287
288/*
289 * CTL_HW identifiers
290 */
291#define	HW_MACHINE	 1		/* string: machine class */
292#define	HW_MODEL	 2		/* string: specific machine model */
293#define	HW_NCPU		 3		/* int: number of cpus */
294#define	HW_BYTEORDER	 4		/* int: machine byte order */
295#define	HW_PHYSMEM	 5		/* int: total memory */
296#define	HW_USERMEM	 6		/* int: non-kernel memory */
297#define	HW_PAGESIZE	 7		/* int: software page size */
298#define	HW_DISKNAMES	 8		/* strings: disk drive names */
299#define	HW_DISKSTATS	 9		/* struct: diskstats[] */
300#define HW_FLOATINGPT	10		/* int: has HW floating point? */
301#define HW_DEVCONF	11		/* node: device configuration */
302#define	HW_MAXID	12		/* number of valid hw ids */
303
304#define CTL_HW_NAMES { \
305	{ 0, 0 }, \
306	{ "machine", CTLTYPE_STRING }, \
307	{ "model", CTLTYPE_STRING }, \
308	{ "ncpu", CTLTYPE_INT }, \
309	{ "byteorder", CTLTYPE_INT }, \
310	{ "physmem", CTLTYPE_INT }, \
311	{ "usermem", CTLTYPE_INT }, \
312	{ "pagesize", CTLTYPE_INT }, \
313	{ "disknames", CTLTYPE_STRUCT }, \
314	{ "diskstats", CTLTYPE_STRUCT }, \
315	{ "floatingpoint", CTLTYPE_INT }, \
316	{ "devconf", CTLTYPE_NODE }, \
317}
318
319/*
320 * CTL_USER definitions
321 */
322#define	USER_CS_PATH		 1	/* string: _CS_PATH */
323#define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
324#define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
325#define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
326#define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
327#define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
328#define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
329#define	USER_LINE_MAX		 8	/* int: LINE_MAX */
330#define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
331#define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
332#define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
333#define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
334#define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
335#define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
336#define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
337#define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
338#define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
339#define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
340#define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
341#define	USER_TZNAME_MAX		20	/* int: POSIX2_TZNAME_MAX */
342#define	USER_MAXID		21	/* number of valid user ids */
343
344#define	CTL_USER_NAMES { \
345	{ 0, 0 }, \
346	{ "cs_path", CTLTYPE_STRING }, \
347	{ "bc_base_max", CTLTYPE_INT }, \
348	{ "bc_dim_max", CTLTYPE_INT }, \
349	{ "bc_scale_max", CTLTYPE_INT }, \
350	{ "bc_string_max", CTLTYPE_INT }, \
351	{ "coll_weights_max", CTLTYPE_INT }, \
352	{ "expr_nest_max", CTLTYPE_INT }, \
353	{ "line_max", CTLTYPE_INT }, \
354	{ "re_dup_max", CTLTYPE_INT }, \
355	{ "posix2_version", CTLTYPE_INT }, \
356	{ "posix2_c_bind", CTLTYPE_INT }, \
357	{ "posix2_c_dev", CTLTYPE_INT }, \
358	{ "posix2_char_term", CTLTYPE_INT }, \
359	{ "posix2_fort_dev", CTLTYPE_INT }, \
360	{ "posix2_fort_run", CTLTYPE_INT }, \
361	{ "posix2_localedef", CTLTYPE_INT }, \
362	{ "posix2_sw_dev", CTLTYPE_INT }, \
363	{ "posix2_upe", CTLTYPE_INT }, \
364	{ "stream_max", CTLTYPE_INT }, \
365	{ "tzname_max", CTLTYPE_INT }, \
366}
367
368/*
369 * CTL_DEBUG definitions
370 *
371 * Second level identifier specifies which debug variable.
372 * Third level identifier specifies which stucture component.
373 */
374#define	CTL_DEBUG_NAME		0	/* string: variable name */
375#define	CTL_DEBUG_VALUE		1	/* int: variable value */
376#define	CTL_DEBUG_MAXID		20
377
378#ifdef	KERNEL
379#if	defined(DEBUG) || defined(DIAGNOSTIC)
380/*
381 * CTL_DEBUG variables.
382 *
383 * These are declared as separate variables so that they can be
384 * individually initialized at the location of their associated
385 * variable. The loader prevents multiple use by issuing errors
386 * if a variable is initialized in more than one place. They are
387 * aggregated into an array in debug_sysctl(), so that it can
388 * conveniently locate them when querried. If more debugging
389 * variables are added, they must also be declared here and also
390 * entered into the array.
391 */
392struct ctldebug {
393	char	*debugname;	/* name of debugging variable */
394	int	*debugvar;	/* pointer to debugging variable */
395};
396extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
397extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
398extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
399extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
400#endif	/* DEBUG */
401
402extern char	cpu_model[];
403extern int	hw_float;
404extern char	machine[];
405extern char	osrelease[];
406extern char	ostype[];
407
408/*
409 * Internal sysctl function calling convention:
410 *
411 *	(*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen, p);
412 *
413 * The name parameter points at the next component of the name to be
414 * interpreted.  The namelen parameter is the number of integers in
415 * the name.
416 */
417typedef int (sysctlfn)
418    __P((int *, u_int, void *, size_t *, void *, size_t, struct proc *));
419
420sysctlfn cpu_sysctl;
421sysctlfn dev_sysctl;
422sysctlfn fs_sysctl;
423sysctlfn hw_sysctl;
424sysctlfn kern_sysctl;
425sysctlfn net_sysctl;
426sysctlfn ntp_sysctl;
427sysctlfn vm_sysctl;
428
429int sysctl_int __P((void *, size_t *, void *, size_t, int *));
430int sysctl_rdint __P((void *, size_t *, void *, int));
431int sysctl_string __P((void *, size_t *, void *, size_t, char *, int));
432int sysctl_rdstring __P((void *, size_t *, void *, char *));
433int sysctl_rdstruct __P((void *, size_t *, void *, void *, int));
434int sysctl_struct __P((void *oldp, size_t *, void *, size_t, void *, int));
435void fill_eproc __P((struct proc *, struct eproc *));
436
437int	sysctl_clockrate __P((char *, size_t*));
438int	sysctl_vnode __P((char *, size_t*));
439int	sysctl_file __P((char *, size_t*));
440int	sysctl_doproc __P((int *, u_int, char *, size_t*));
441int	sysctl_doprof __P((int *, u_int, void *, size_t *, void *, size_t));
442
443#else	/* !KERNEL */
444#include <sys/cdefs.h>
445
446__BEGIN_DECLS
447int	sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
448__END_DECLS
449#endif	/* KERNEL */
450
451#endif	/* !_SYS_SYSCTL_H_ */
452