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