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 * 4. Neither the name of the University nor the names of its contributors
17 *    may be used to endorse or promote products derived from this software
18 *    without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 *	@(#)sysctl.h	8.1 (Berkeley) 6/2/93
33 * $FreeBSD: stable/11/sys/sys/sysctl.h 354762 2019-11-16 00:33:02Z scottl $
34 */
35
36#ifndef _SYS_SYSCTL_H_
37#define	_SYS_SYSCTL_H_
38
39#include <sys/queue.h>
40
41struct thread;
42/*
43 * Definitions for sysctl call.  The sysctl call uses a hierarchical name
44 * for objects that can be examined or modified.  The name is expressed as
45 * a sequence of integers.  Like a file path name, the meaning of each
46 * component depends on its place in the hierarchy.  The top-level and kern
47 * identifiers are defined here, and other identifiers are defined in the
48 * respective subsystem header files.
49 */
50
51#define	CTL_MAXNAME	24	/* largest number of components supported */
52
53/*
54 * Each subsystem defined by sysctl defines a list of variables
55 * for that subsystem. Each name is either a node with further
56 * levels defined below it, or it is a leaf of some particular
57 * type given below. Each sysctl level defines a set of name/type
58 * pairs to be used by sysctl(8) in manipulating the subsystem.
59 */
60struct ctlname {
61	char	*ctl_name;	/* subsystem name */
62	int	 ctl_type;	/* type of name */
63};
64
65#define	CTLTYPE		0xf	/* mask for the type */
66#define	CTLTYPE_NODE	1	/* name is a node */
67#define	CTLTYPE_INT	2	/* name describes an integer */
68#define	CTLTYPE_STRING	3	/* name describes a string */
69#define	CTLTYPE_S64	4	/* name describes a signed 64-bit number */
70#define	CTLTYPE_OPAQUE	5	/* name describes a structure */
71#define	CTLTYPE_STRUCT	CTLTYPE_OPAQUE	/* name describes a structure */
72#define	CTLTYPE_UINT	6	/* name describes an unsigned integer */
73#define	CTLTYPE_LONG	7	/* name describes a long */
74#define	CTLTYPE_ULONG	8	/* name describes an unsigned long */
75#define	CTLTYPE_U64	9	/* name describes an unsigned 64-bit number */
76#define	CTLTYPE_U8	0xa	/* name describes an unsigned 8-bit number */
77#define	CTLTYPE_U16	0xb	/* name describes an unsigned 16-bit number */
78#define	CTLTYPE_S8	0xc	/* name describes a signed 8-bit number */
79#define	CTLTYPE_S16	0xd	/* name describes a signed 16-bit number */
80#define	CTLTYPE_S32	0xe	/* name describes a signed 32-bit number */
81#define	CTLTYPE_U32	0xf	/* name describes an unsigned 32-bit number */
82
83#define	CTLFLAG_RD	0x80000000	/* Allow reads of variable */
84#define	CTLFLAG_WR	0x40000000	/* Allow writes to the variable */
85#define	CTLFLAG_RW	(CTLFLAG_RD|CTLFLAG_WR)
86#define	CTLFLAG_DORMANT	0x20000000	/* This sysctl is not active yet */
87#define	CTLFLAG_ANYBODY	0x10000000	/* All users can set this var */
88#define	CTLFLAG_SECURE	0x08000000	/* Permit set only if securelevel<=0 */
89#define	CTLFLAG_PRISON	0x04000000	/* Prisoned roots can fiddle */
90#define	CTLFLAG_DYN	0x02000000	/* Dynamic oid - can be freed */
91#define	CTLFLAG_SKIP	0x01000000	/* Skip this sysctl when listing */
92#define	CTLMASK_SECURE	0x00F00000	/* Secure level */
93#define	CTLFLAG_TUN	0x00080000	/* Default value is loaded from getenv() */
94#define	CTLFLAG_RDTUN	(CTLFLAG_RD|CTLFLAG_TUN)
95#define	CTLFLAG_RWTUN	(CTLFLAG_RW|CTLFLAG_TUN)
96#define	CTLFLAG_MPSAFE	0x00040000	/* Handler is MP safe */
97#define	CTLFLAG_VNET	0x00020000	/* Prisons with vnet can fiddle */
98#define	CTLFLAG_DYING	0x00010000	/* Oid is being removed */
99#define	CTLFLAG_CAPRD	0x00008000	/* Can be read in capability mode */
100#define	CTLFLAG_CAPWR	0x00004000	/* Can be written in capability mode */
101#define	CTLFLAG_STATS	0x00002000	/* Statistics, not a tuneable */
102#define	CTLFLAG_NOFETCH	0x00001000	/* Don't fetch tunable from getenv() */
103#define	CTLFLAG_CAPRW	(CTLFLAG_CAPRD|CTLFLAG_CAPWR)
104
105/*
106 * Secure level.   Note that CTLFLAG_SECURE == CTLFLAG_SECURE1.
107 *
108 * Secure when the securelevel is raised to at least N.
109 */
110#define	CTLSHIFT_SECURE	20
111#define	CTLFLAG_SECURE1	(CTLFLAG_SECURE | (0 << CTLSHIFT_SECURE))
112#define	CTLFLAG_SECURE2	(CTLFLAG_SECURE | (1 << CTLSHIFT_SECURE))
113#define	CTLFLAG_SECURE3	(CTLFLAG_SECURE | (2 << CTLSHIFT_SECURE))
114
115/*
116 * USE THIS instead of a hardwired number from the categories below
117 * to get dynamically assigned sysctl entries using the linker-set
118 * technology. This is the way nearly all new sysctl variables should
119 * be implemented.
120 * e.g. SYSCTL_INT(_parent, OID_AUTO, name, CTLFLAG_RW, &variable, 0, "");
121 */
122#define	OID_AUTO	(-1)
123
124/*
125 * The starting number for dynamically-assigned entries.  WARNING!
126 * ALL static sysctl entries should have numbers LESS than this!
127 */
128#define	CTL_AUTO_START	0x100
129
130#ifdef _KERNEL
131#include <sys/linker_set.h>
132
133#ifdef KLD_MODULE
134/* XXX allow overspecification of type in external kernel modules */
135#define	SYSCTL_CT_ASSERT_MASK CTLTYPE
136#else
137#define	SYSCTL_CT_ASSERT_MASK 0
138#endif
139
140#define	SYSCTL_HANDLER_ARGS struct sysctl_oid *oidp, void *arg1,	\
141	intmax_t arg2, struct sysctl_req *req
142
143/* definitions for sysctl_req 'lock' member */
144#define	REQ_UNWIRED	1
145#define	REQ_WIRED	2
146
147/* definitions for sysctl_req 'flags' member */
148#if defined(__amd64__) || defined(__powerpc64__) ||\
149    (defined(__mips__) && defined(__mips_n64))
150#define	SCTL_MASK32	1	/* 32 bit emulation */
151#endif
152
153/*
154 * This describes the access space for a sysctl request.  This is needed
155 * so that we can use the interface from the kernel or from user-space.
156 */
157struct sysctl_req {
158	struct thread	*td;		/* used for access checking */
159	int		 lock;		/* wiring state */
160	void		*oldptr;
161	size_t		 oldlen;
162	size_t		 oldidx;
163	int		(*oldfunc)(struct sysctl_req *, const void *, size_t);
164	void		*newptr;
165	size_t		 newlen;
166	size_t		 newidx;
167	int		(*newfunc)(struct sysctl_req *, void *, size_t);
168	size_t		 validlen;
169	int		 flags;
170};
171
172SLIST_HEAD(sysctl_oid_list, sysctl_oid);
173
174/*
175 * This describes one "oid" in the MIB tree.  Potentially more nodes can
176 * be hidden behind it, expanded by the handler.
177 */
178struct sysctl_oid {
179	struct sysctl_oid_list oid_children;
180	struct sysctl_oid_list *oid_parent;
181	SLIST_ENTRY(sysctl_oid) oid_link;
182	int		 oid_number;
183	u_int		 oid_kind;
184	void		*oid_arg1;
185	intmax_t	 oid_arg2;
186	const char	*oid_name;
187	int		(*oid_handler)(SYSCTL_HANDLER_ARGS);
188	const char	*oid_fmt;
189	int		 oid_refcnt;
190	u_int		 oid_running;
191	const char	*oid_descr;
192};
193
194#define	SYSCTL_IN(r, p, l)	(r->newfunc)(r, p, l)
195#define	SYSCTL_OUT(r, p, l)	(r->oldfunc)(r, p, l)
196#define	SYSCTL_OUT_STR(r, p)	(r->oldfunc)(r, p, strlen(p) + 1)
197
198int sysctl_handle_bool(SYSCTL_HANDLER_ARGS);
199int sysctl_handle_8(SYSCTL_HANDLER_ARGS);
200int sysctl_handle_16(SYSCTL_HANDLER_ARGS);
201int sysctl_handle_32(SYSCTL_HANDLER_ARGS);
202int sysctl_handle_64(SYSCTL_HANDLER_ARGS);
203int sysctl_handle_int(SYSCTL_HANDLER_ARGS);
204int sysctl_msec_to_ticks(SYSCTL_HANDLER_ARGS);
205int sysctl_handle_long(SYSCTL_HANDLER_ARGS);
206int sysctl_handle_string(SYSCTL_HANDLER_ARGS);
207int sysctl_handle_opaque(SYSCTL_HANDLER_ARGS);
208int sysctl_handle_counter_u64(SYSCTL_HANDLER_ARGS);
209int sysctl_handle_counter_u64_array(SYSCTL_HANDLER_ARGS);
210
211int sysctl_handle_uma_zone_max(SYSCTL_HANDLER_ARGS);
212int sysctl_handle_uma_zone_cur(SYSCTL_HANDLER_ARGS);
213
214int sysctl_sec_to_timeval(SYSCTL_HANDLER_ARGS);
215
216int sysctl_dpcpu_int(SYSCTL_HANDLER_ARGS);
217int sysctl_dpcpu_long(SYSCTL_HANDLER_ARGS);
218int sysctl_dpcpu_quad(SYSCTL_HANDLER_ARGS);
219
220/*
221 * These functions are used to add/remove an oid from the mib.
222 */
223void sysctl_register_oid(struct sysctl_oid *oidp);
224void sysctl_register_disabled_oid(struct sysctl_oid *oidp);
225void sysctl_enable_oid(struct sysctl_oid *oidp);
226void sysctl_unregister_oid(struct sysctl_oid *oidp);
227
228/* Declare a static oid to allow child oids to be added to it. */
229#define	SYSCTL_DECL(name)			\
230	extern struct sysctl_oid sysctl__##name
231
232/* Hide these in macros. */
233#define	SYSCTL_CHILDREN(oid_ptr)		(&(oid_ptr)->oid_children)
234#define	SYSCTL_PARENT(oid_ptr)					\
235    (((oid_ptr)->oid_parent != &sysctl__children) ?		\
236	__containerof((oid_ptr)->oid_parent, struct sysctl_oid,	\
237	oid_children) : (struct sysctl_oid *)NULL)
238#define	SYSCTL_STATIC_CHILDREN(oid_name)	(&sysctl__##oid_name.oid_children)
239
240/* === Structs and macros related to context handling. === */
241
242/* All dynamically created sysctls can be tracked in a context list. */
243struct sysctl_ctx_entry {
244	struct sysctl_oid *entry;
245	TAILQ_ENTRY(sysctl_ctx_entry) link;
246};
247
248TAILQ_HEAD(sysctl_ctx_list, sysctl_ctx_entry);
249
250#define	SYSCTL_NODE_CHILDREN(parent, name) \
251	sysctl__##parent##_##name.oid_children
252
253#ifndef NO_SYSCTL_DESCR
254#define	__DESCR(d) d
255#else
256#define	__DESCR(d) ""
257#endif
258
259/* This macro is only for internal use */
260#define	SYSCTL_OID_RAW(id, parent_child_head, nbr, name, kind, a1, a2, handler, fmt, descr) \
261	struct sysctl_oid id = {					\
262		.oid_parent = (parent_child_head),			\
263		.oid_children = SLIST_HEAD_INITIALIZER(&id.oid_children), \
264		.oid_number = (nbr),					\
265		.oid_kind = (kind),					\
266		.oid_arg1 = (a1),					\
267		.oid_arg2 = (a2),					\
268		.oid_name = (name),					\
269		.oid_handler = (handler),				\
270		.oid_fmt = (fmt),					\
271		.oid_descr = __DESCR(descr)				\
272	};								\
273	DATA_SET(sysctl_set, id)
274
275/* This constructs a static "raw" MIB oid. */
276#define	SYSCTL_OID(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
277    static SYSCTL_OID_RAW(sysctl__##parent##_##name, \
278	SYSCTL_CHILDREN(&sysctl__##parent), \
279	nbr, #name, kind, a1, a2, handler, fmt, descr)
280
281/* This constructs a global "raw" MIB oid. */
282#define	SYSCTL_OID_GLOBAL(parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
283    SYSCTL_OID_RAW(sysctl__##parent##_##name, \
284	SYSCTL_CHILDREN(&sysctl__##parent),	\
285	nbr, #name, kind, a1, a2, handler, fmt, descr)
286
287#define	SYSCTL_ADD_OID(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, descr) \
288	sysctl_add_oid(ctx, parent, nbr, name, kind, a1, a2, handler, fmt, __DESCR(descr))
289
290/* This constructs a root node from which other nodes can hang. */
291#define	SYSCTL_ROOT_NODE(nbr, name, access, handler, descr)	\
292	SYSCTL_OID_RAW(sysctl___##name, &sysctl__children,	\
293	    nbr, #name, CTLTYPE_NODE|(access), NULL, 0,		\
294	    handler, "N", descr);				\
295	CTASSERT(((access) & CTLTYPE) == 0 ||			\
296	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
297
298/* This constructs a node from which other oids can hang. */
299#define	SYSCTL_NODE(parent, nbr, name, access, handler, descr)		\
300	SYSCTL_OID_GLOBAL(parent, nbr, name, CTLTYPE_NODE|(access),	\
301	    NULL, 0, handler, "N", descr);				\
302	CTASSERT(((access) & CTLTYPE) == 0 ||				\
303	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE)
304
305#define	SYSCTL_ADD_NODE(ctx, parent, nbr, name, access, handler, descr)	\
306({									\
307	CTASSERT(((access) & CTLTYPE) == 0 ||				\
308	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
309	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_NODE|(access),	\
310	    NULL, 0, handler, "N", __DESCR(descr));			\
311})
312
313#define	SYSCTL_ADD_ROOT_NODE(ctx, nbr, name, access, handler, descr)	\
314({									\
315	CTASSERT(((access) & CTLTYPE) == 0 ||				\
316	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_NODE);	\
317	sysctl_add_oid(ctx, &sysctl__children, nbr, name,		\
318	    CTLTYPE_NODE|(access),					\
319	    NULL, 0, handler, "N", __DESCR(descr));			\
320})
321
322/* Oid for a string.  len can be 0 to indicate '\0' termination. */
323#define	SYSCTL_STRING(parent, nbr, name, access, arg, len, descr)	\
324	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access),		\
325	    arg, len, sysctl_handle_string, "A", descr);		\
326	CTASSERT(((access) & CTLTYPE) == 0 ||				\
327	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
328
329#define	SYSCTL_ADD_STRING(ctx, parent, nbr, name, access, arg, len, descr) \
330({									\
331	char *__arg = (arg);						\
332	CTASSERT(((access) & CTLTYPE) == 0 ||				\
333	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING);	\
334	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access),	\
335	    __arg, len, sysctl_handle_string, "A", __DESCR(descr));	\
336})
337
338/* Oid for a constant '\0' terminated string. */
339#define	SYSCTL_CONST_STRING(parent, nbr, name, access, arg, descr)	\
340	SYSCTL_OID(parent, nbr, name, CTLTYPE_STRING|(access),		\
341	    __DECONST(char *, arg), 0, sysctl_handle_string, "A", descr); \
342	CTASSERT(!(access & CTLFLAG_WR));				\
343	CTASSERT(((access) & CTLTYPE) == 0 ||				\
344	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING)
345
346#define	SYSCTL_ADD_CONST_STRING(ctx, parent, nbr, name, access, arg, descr) \
347({									\
348	char *__arg = __DECONST(char *, arg);				\
349	CTASSERT(!(access & CTLFLAG_WR));				\
350	CTASSERT(((access) & CTLTYPE) == 0 ||				\
351	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_STRING);	\
352	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_STRING|(access),	\
353	    __arg, 0, sysctl_handle_string, "A", __DESCR(descr));	\
354})
355
356/* Oid for a bool.  If ptr is NULL, val is returned. */
357#define	SYSCTL_NULL_BOOL_PTR ((bool *)NULL)
358#define	SYSCTL_BOOL(parent, nbr, name, access, ptr, val, descr)	\
359	SYSCTL_OID(parent, nbr, name,				\
360	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
361	    ptr, val, sysctl_handle_bool, "CU", descr);		\
362	CTASSERT(((access) & CTLTYPE) == 0 &&			\
363	    sizeof(bool) == sizeof(*(ptr)))
364
365#define	SYSCTL_ADD_BOOL(ctx, parent, nbr, name, access, ptr, val, descr) \
366({									\
367	bool *__ptr = (ptr);						\
368	CTASSERT(((access) & CTLTYPE) == 0);				\
369	sysctl_add_oid(ctx, parent, nbr, name,				\
370	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
371	    __ptr, val, sysctl_handle_bool, "CU", __DESCR(descr));	\
372})
373
374/* Oid for a signed 8-bit int.  If ptr is NULL, val is returned. */
375#define	SYSCTL_NULL_S8_PTR ((int8_t *)NULL)
376#define	SYSCTL_S8(parent, nbr, name, access, ptr, val, descr)	\
377	SYSCTL_OID(parent, nbr, name,				\
378	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),		\
379	    ptr, val, sysctl_handle_8, "C", descr);		\
380	CTASSERT((((access) & CTLTYPE) == 0 ||			\
381	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8) && \
382	    sizeof(int8_t) == sizeof(*(ptr)))
383
384#define	SYSCTL_ADD_S8(ctx, parent, nbr, name, access, ptr, val, descr)	\
385({									\
386	int8_t *__ptr = (ptr);						\
387	CTASSERT(((access) & CTLTYPE) == 0 ||				\
388	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S8);		\
389	sysctl_add_oid(ctx, parent, nbr, name,				\
390	    CTLTYPE_S8 | CTLFLAG_MPSAFE | (access),			\
391	    __ptr, val, sysctl_handle_8, "C", __DESCR(descr));	\
392})
393
394/* Oid for an unsigned 8-bit int.  If ptr is NULL, val is returned. */
395#define	SYSCTL_NULL_U8_PTR ((uint8_t *)NULL)
396#define	SYSCTL_U8(parent, nbr, name, access, ptr, val, descr)	\
397	SYSCTL_OID(parent, nbr, name,				\
398	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),		\
399	    ptr, val, sysctl_handle_8, "CU", descr);		\
400	CTASSERT((((access) & CTLTYPE) == 0 ||			\
401	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8) && \
402	    sizeof(uint8_t) == sizeof(*(ptr)))
403
404#define	SYSCTL_ADD_U8(ctx, parent, nbr, name, access, ptr, val, descr)	\
405({									\
406	uint8_t *__ptr = (ptr);						\
407	CTASSERT(((access) & CTLTYPE) == 0 ||				\
408	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U8);		\
409	sysctl_add_oid(ctx, parent, nbr, name,				\
410	    CTLTYPE_U8 | CTLFLAG_MPSAFE | (access),			\
411	    __ptr, val, sysctl_handle_8, "CU", __DESCR(descr));	\
412})
413
414/* Oid for a signed 16-bit int.  If ptr is NULL, val is returned. */
415#define	SYSCTL_NULL_S16_PTR ((int16_t *)NULL)
416#define	SYSCTL_S16(parent, nbr, name, access, ptr, val, descr)	\
417	SYSCTL_OID(parent, nbr, name,				\
418	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),		\
419	    ptr, val, sysctl_handle_16, "S", descr);		\
420	CTASSERT((((access) & CTLTYPE) == 0 ||			\
421	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16) && \
422	    sizeof(int16_t) == sizeof(*(ptr)))
423
424#define	SYSCTL_ADD_S16(ctx, parent, nbr, name, access, ptr, val, descr)	\
425({									\
426	int16_t *__ptr = (ptr);						\
427	CTASSERT(((access) & CTLTYPE) == 0 ||				\
428	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S16);		\
429	sysctl_add_oid(ctx, parent, nbr, name,				\
430	    CTLTYPE_S16 | CTLFLAG_MPSAFE | (access),			\
431	    __ptr, val, sysctl_handle_16, "S", __DESCR(descr));	\
432})
433
434/* Oid for an unsigned 16-bit int.  If ptr is NULL, val is returned. */
435#define	SYSCTL_NULL_U16_PTR ((uint16_t *)NULL)
436#define	SYSCTL_U16(parent, nbr, name, access, ptr, val, descr)	\
437	SYSCTL_OID(parent, nbr, name,				\
438	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),		\
439	    ptr, val, sysctl_handle_16, "SU", descr);		\
440	CTASSERT((((access) & CTLTYPE) == 0 ||			\
441	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16) && \
442	    sizeof(uint16_t) == sizeof(*(ptr)))
443
444#define	SYSCTL_ADD_U16(ctx, parent, nbr, name, access, ptr, val, descr)	\
445({									\
446	uint16_t *__ptr = (ptr);					\
447	CTASSERT(((access) & CTLTYPE) == 0 ||				\
448	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U16);		\
449	sysctl_add_oid(ctx, parent, nbr, name,				\
450	    CTLTYPE_U16 | CTLFLAG_MPSAFE | (access),			\
451	    __ptr, val, sysctl_handle_16, "SU", __DESCR(descr));	\
452})
453
454/* Oid for a signed 32-bit int.  If ptr is NULL, val is returned. */
455#define	SYSCTL_NULL_S32_PTR ((int32_t *)NULL)
456#define	SYSCTL_S32(parent, nbr, name, access, ptr, val, descr)	\
457	SYSCTL_OID(parent, nbr, name,				\
458	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),		\
459	    ptr, val, sysctl_handle_32, "I", descr);		\
460	CTASSERT((((access) & CTLTYPE) == 0 ||			\
461	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32) && \
462	    sizeof(int32_t) == sizeof(*(ptr)))
463
464#define	SYSCTL_ADD_S32(ctx, parent, nbr, name, access, ptr, val, descr)	\
465({									\
466	int32_t *__ptr = (ptr);						\
467	CTASSERT(((access) & CTLTYPE) == 0 ||				\
468	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S32);		\
469	sysctl_add_oid(ctx, parent, nbr, name,				\
470	    CTLTYPE_S32 | CTLFLAG_MPSAFE | (access),			\
471	    __ptr, val, sysctl_handle_32, "I", __DESCR(descr));	\
472})
473
474/* Oid for an unsigned 32-bit int.  If ptr is NULL, val is returned. */
475#define	SYSCTL_NULL_U32_PTR ((uint32_t *)NULL)
476#define	SYSCTL_U32(parent, nbr, name, access, ptr, val, descr)	\
477	SYSCTL_OID(parent, nbr, name,				\
478	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),		\
479	    ptr, val, sysctl_handle_32, "IU", descr);		\
480	CTASSERT((((access) & CTLTYPE) == 0 ||			\
481	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32) && \
482	    sizeof(uint32_t) == sizeof(*(ptr)))
483
484#define	SYSCTL_ADD_U32(ctx, parent, nbr, name, access, ptr, val, descr)	\
485({									\
486	uint32_t *__ptr = (ptr);					\
487	CTASSERT(((access) & CTLTYPE) == 0 ||				\
488	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U32);		\
489	sysctl_add_oid(ctx, parent, nbr, name,				\
490	    CTLTYPE_U32 | CTLFLAG_MPSAFE | (access),			\
491	    __ptr, val, sysctl_handle_32, "IU", __DESCR(descr));	\
492})
493
494/* Oid for a signed 64-bit int.  If ptr is NULL, val is returned. */
495#define	SYSCTL_NULL_S64_PTR ((int64_t *)NULL)
496#define	SYSCTL_S64(parent, nbr, name, access, ptr, val, descr)	\
497	SYSCTL_OID(parent, nbr, name,				\
498	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
499	    ptr, val, sysctl_handle_64, "Q", descr);		\
500	CTASSERT((((access) & CTLTYPE) == 0 ||			\
501	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
502	    sizeof(int64_t) == sizeof(*(ptr)))
503
504#define	SYSCTL_ADD_S64(ctx, parent, nbr, name, access, ptr, val, descr)	\
505({									\
506	int64_t *__ptr = (ptr);						\
507	CTASSERT(((access) & CTLTYPE) == 0 ||				\
508	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
509	sysctl_add_oid(ctx, parent, nbr, name,				\
510	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
511	    __ptr, val, sysctl_handle_64, "Q", __DESCR(descr));	\
512})
513
514/* Oid for an unsigned 64-bit int.  If ptr is NULL, val is returned. */
515#define	SYSCTL_NULL_U64_PTR ((uint64_t *)NULL)
516#define	SYSCTL_U64(parent, nbr, name, access, ptr, val, descr)	\
517	SYSCTL_OID(parent, nbr, name,				\
518	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
519	    ptr, val, sysctl_handle_64, "QU", descr);		\
520	CTASSERT((((access) & CTLTYPE) == 0 ||			\
521	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) && \
522	    sizeof(uint64_t) == sizeof(*(ptr)))
523
524#define	SYSCTL_ADD_U64(ctx, parent, nbr, name, access, ptr, val, descr)	\
525({									\
526	uint64_t *__ptr = (ptr);					\
527	CTASSERT(((access) & CTLTYPE) == 0 ||				\
528	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
529	sysctl_add_oid(ctx, parent, nbr, name,				\
530	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
531	    __ptr, val, sysctl_handle_64, "QU", __DESCR(descr));	\
532})
533
534/* Oid for an int.  If ptr is SYSCTL_NULL_INT_PTR, val is returned. */
535#define	SYSCTL_NULL_INT_PTR ((int *)NULL)
536#define	SYSCTL_INT(parent, nbr, name, access, ptr, val, descr)	\
537	SYSCTL_OID(parent, nbr, name,				\
538	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),		\
539	    ptr, val, sysctl_handle_int, "I", descr);		\
540	CTASSERT((((access) & CTLTYPE) == 0 ||			\
541	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT) && \
542	    sizeof(int) == sizeof(*(ptr)))
543
544#define	SYSCTL_ADD_INT(ctx, parent, nbr, name, access, ptr, val, descr)	\
545({									\
546	int *__ptr = (ptr);						\
547	CTASSERT(((access) & CTLTYPE) == 0 ||				\
548	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
549	sysctl_add_oid(ctx, parent, nbr, name,				\
550	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
551	    __ptr, val, sysctl_handle_int, "I", __DESCR(descr));	\
552})
553
554/* Oid for an unsigned int.  If ptr is NULL, val is returned. */
555#define	SYSCTL_NULL_UINT_PTR ((unsigned *)NULL)
556#define	SYSCTL_UINT(parent, nbr, name, access, ptr, val, descr)	\
557	SYSCTL_OID(parent, nbr, name,				\
558	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
559	    ptr, val, sysctl_handle_int, "IU", descr);		\
560	CTASSERT((((access) & CTLTYPE) == 0 ||			\
561	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT) && \
562	    sizeof(unsigned) == sizeof(*(ptr)))
563
564#define	SYSCTL_ADD_UINT(ctx, parent, nbr, name, access, ptr, val, descr) \
565({									\
566	unsigned *__ptr = (ptr);					\
567	CTASSERT(((access) & CTLTYPE) == 0 ||				\
568	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_UINT);	\
569	sysctl_add_oid(ctx, parent, nbr, name,				\
570	    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),			\
571	    __ptr, val, sysctl_handle_int, "IU", __DESCR(descr));	\
572})
573
574/* Oid for a long.  The pointer must be non NULL. */
575#define	SYSCTL_NULL_LONG_PTR ((long *)NULL)
576#define	SYSCTL_LONG(parent, nbr, name, access, ptr, val, descr)	\
577	SYSCTL_OID(parent, nbr, name,				\
578	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),		\
579	    ptr, val, sysctl_handle_long, "L", descr);		\
580	CTASSERT((((access) & CTLTYPE) == 0 ||			\
581	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG) && \
582	    sizeof(long) == sizeof(*(ptr)))
583
584#define	SYSCTL_ADD_LONG(ctx, parent, nbr, name, access, ptr, descr)	\
585({									\
586	long *__ptr = (ptr);						\
587	CTASSERT(((access) & CTLTYPE) == 0 ||				\
588	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_LONG);	\
589	sysctl_add_oid(ctx, parent, nbr, name,				\
590	    CTLTYPE_LONG | CTLFLAG_MPSAFE | (access),			\
591	    __ptr, 0, sysctl_handle_long, "L", __DESCR(descr));		\
592})
593
594/* Oid for an unsigned long.  The pointer must be non NULL. */
595#define	SYSCTL_NULL_ULONG_PTR ((unsigned long *)NULL)
596#define	SYSCTL_ULONG(parent, nbr, name, access, ptr, val, descr)	\
597	SYSCTL_OID(parent, nbr, name,					\
598	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
599	    ptr, val, sysctl_handle_long, "LU", descr);			\
600	CTASSERT((((access) & CTLTYPE) == 0 ||				\
601	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG) &&	\
602	    sizeof(unsigned long) == sizeof(*(ptr)))
603
604#define	SYSCTL_ADD_ULONG(ctx, parent, nbr, name, access, ptr, descr)	\
605({									\
606	unsigned long *__ptr = (ptr);					\
607	CTASSERT(((access) & CTLTYPE) == 0 ||				\
608	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_ULONG);	\
609	sysctl_add_oid(ctx, parent, nbr, name,				\
610	    CTLTYPE_ULONG | CTLFLAG_MPSAFE | (access),			\
611	    __ptr, 0, sysctl_handle_long, "LU", __DESCR(descr));	\
612})
613
614/* Oid for a quad.  The pointer must be non NULL. */
615#define	SYSCTL_NULL_QUAD_PTR ((int64_t *)NULL)
616#define	SYSCTL_QUAD(parent, nbr, name, access, ptr, val, descr)	\
617	SYSCTL_OID(parent, nbr, name,				\
618	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),		\
619	    ptr, val, sysctl_handle_64, "Q", descr);		\
620	CTASSERT((((access) & CTLTYPE) == 0 ||			\
621	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64) && \
622	    sizeof(int64_t) == sizeof(*(ptr)))
623
624#define	SYSCTL_ADD_QUAD(ctx, parent, nbr, name, access, ptr, descr)	\
625({									\
626	int64_t *__ptr = (ptr);						\
627	CTASSERT(((access) & CTLTYPE) == 0 ||				\
628	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_S64);		\
629	sysctl_add_oid(ctx, parent, nbr, name,				\
630	    CTLTYPE_S64 | CTLFLAG_MPSAFE | (access),			\
631	    __ptr, 0, sysctl_handle_64, "Q", __DESCR(descr));		\
632})
633
634#define	SYSCTL_NULL_UQUAD_PTR ((uint64_t *)NULL)
635#define	SYSCTL_UQUAD(parent, nbr, name, access, ptr, val, descr)	\
636	SYSCTL_OID(parent, nbr, name,					\
637	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
638	     ptr, val, sysctl_handle_64, "QU", descr);			\
639	CTASSERT((((access) & CTLTYPE) == 0 ||				\
640	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
641	    sizeof(uint64_t) == sizeof(*(ptr)))
642
643#define	SYSCTL_ADD_UQUAD(ctx, parent, nbr, name, access, ptr, descr)	\
644({									\
645	uint64_t *__ptr = (ptr);					\
646	CTASSERT(((access) & CTLTYPE) == 0 ||				\
647	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
648	sysctl_add_oid(ctx, parent, nbr, name,				\
649	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
650	    __ptr, 0, sysctl_handle_64, "QU", __DESCR(descr));		\
651})
652
653/* Oid for a CPU dependent variable */
654#define	SYSCTL_ADD_UAUTO(ctx, parent, nbr, name, access, ptr, descr)	\
655({									\
656	struct sysctl_oid *__ret;					\
657	CTASSERT((sizeof(uint64_t) == sizeof(*(ptr)) ||			\
658	    sizeof(unsigned) == sizeof(*(ptr))) &&			\
659	    ((access) & CTLTYPE) == 0);					\
660	if (sizeof(uint64_t) == sizeof(*(ptr))) {			\
661		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
662		    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),		\
663		    (ptr), 0, sysctl_handle_64, "QU",			\
664		    __DESCR(descr));					\
665	} else {							\
666		__ret = sysctl_add_oid(ctx, parent, nbr, name,		\
667		    CTLTYPE_UINT | CTLFLAG_MPSAFE | (access),		\
668		    (ptr), 0, sysctl_handle_int, "IU",			\
669		    __DESCR(descr));					\
670	}								\
671	__ret;								\
672})
673
674/* Oid for a 64-bit unsigned counter(9).  The pointer must be non NULL. */
675#define	SYSCTL_COUNTER_U64(parent, nbr, name, access, ptr, descr)	\
676	SYSCTL_OID(parent, nbr, name,					\
677	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
678	    (ptr), 0, sysctl_handle_counter_u64, "QU", descr);		\
679	CTASSERT((((access) & CTLTYPE) == 0 ||				\
680	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64) &&	\
681	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
682	    sizeof(uint64_t) == sizeof(**(ptr)))
683
684#define	SYSCTL_ADD_COUNTER_U64(ctx, parent, nbr, name, access, ptr, descr) \
685({									\
686	counter_u64_t *__ptr = (ptr);					\
687	CTASSERT(((access) & CTLTYPE) == 0 ||				\
688	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_U64);		\
689	sysctl_add_oid(ctx, parent, nbr, name,				\
690	    CTLTYPE_U64 | CTLFLAG_MPSAFE | (access),			\
691	    __ptr, 0, sysctl_handle_counter_u64, "QU", __DESCR(descr));	\
692})
693
694/* Oid for an array of counter(9)s.  The pointer and length must be non zero. */
695#define	SYSCTL_COUNTER_U64_ARRAY(parent, nbr, name, access, ptr, len, descr) \
696	SYSCTL_OID(parent, nbr, name,					\
697	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
698	    (ptr), (len), sysctl_handle_counter_u64_array, "S", descr);	\
699	CTASSERT((((access) & CTLTYPE) == 0 ||				\
700	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE) &&	\
701	    sizeof(counter_u64_t) == sizeof(*(ptr)) &&			\
702	    sizeof(uint64_t) == sizeof(**(ptr)))
703
704#define	SYSCTL_ADD_COUNTER_U64_ARRAY(ctx, parent, nbr, name, access,	\
705    ptr, len, descr)							\
706({									\
707	counter_u64_t *__ptr = (ptr);					\
708	CTASSERT(((access) & CTLTYPE) == 0 ||				\
709	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
710	sysctl_add_oid(ctx, parent, nbr, name,				\
711	    CTLTYPE_OPAQUE | CTLFLAG_MPSAFE | (access),			\
712	    __ptr, len, sysctl_handle_counter_u64_array, "S",		\
713	    __DESCR(descr));						\
714})
715
716/* Oid for an opaque object.  Specified by a pointer and a length. */
717#define	SYSCTL_OPAQUE(parent, nbr, name, access, ptr, len, fmt, descr)	\
718	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
719	    ptr, len, sysctl_handle_opaque, fmt, descr);		\
720	CTASSERT(((access) & CTLTYPE) == 0 ||				\
721	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
722
723#define	SYSCTL_ADD_OPAQUE(ctx, parent, nbr, name, access, ptr, len, fmt, descr)	\
724({									\
725	CTASSERT(((access) & CTLTYPE) == 0 ||				\
726	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
727	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
728	    ptr, len, sysctl_handle_opaque, fmt, __DESCR(descr));	\
729})
730
731/* Oid for a struct.  Specified by a pointer and a type. */
732#define	SYSCTL_STRUCT(parent, nbr, name, access, ptr, type, descr)	\
733	SYSCTL_OID(parent, nbr, name, CTLTYPE_OPAQUE|(access),		\
734	    ptr, sizeof(struct type), sysctl_handle_opaque,		\
735	    "S," #type, descr);						\
736	CTASSERT(((access) & CTLTYPE) == 0 ||				\
737	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE)
738
739#define	SYSCTL_ADD_STRUCT(ctx, parent, nbr, name, access, ptr, type, descr) \
740({									\
741	CTASSERT(((access) & CTLTYPE) == 0 ||				\
742	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_OPAQUE);	\
743	sysctl_add_oid(ctx, parent, nbr, name, CTLTYPE_OPAQUE|(access),	\
744	    (ptr), sizeof(struct type),					\
745	    sysctl_handle_opaque, "S," #type, __DESCR(descr));		\
746})
747
748/* Oid for a procedure.  Specified by a pointer and an arg. */
749#define	SYSCTL_PROC(parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
750	SYSCTL_OID(parent, nbr, name, (access),				\
751	    ptr, arg, handler, fmt, descr);				\
752	CTASSERT(((access) & CTLTYPE) != 0)
753
754#define	SYSCTL_ADD_PROC(ctx, parent, nbr, name, access, ptr, arg, handler, fmt, descr) \
755({									\
756	CTASSERT(((access) & CTLTYPE) != 0);				\
757	sysctl_add_oid(ctx, parent, nbr, name, (access),		\
758	    (ptr), (arg), (handler), (fmt), __DESCR(descr));		\
759})
760
761/* Oid to handle limits on uma(9) zone specified by pointer. */
762#define	SYSCTL_UMA_MAX(parent, nbr, name, access, ptr, descr)	\
763	SYSCTL_OID(parent, nbr, name,				\
764	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),		\
765	    (ptr), 0, sysctl_handle_uma_zone_max, "I", descr);	\
766	CTASSERT(((access) & CTLTYPE) == 0 ||			\
767	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
768
769#define	SYSCTL_ADD_UMA_MAX(ctx, parent, nbr, name, access, ptr, descr)	\
770({									\
771	uma_zone_t __ptr = (ptr);					\
772	CTASSERT(((access) & CTLTYPE) == 0 ||				\
773	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
774	sysctl_add_oid(ctx, parent, nbr, name,				\
775	    CTLTYPE_INT | CTLFLAG_MPSAFE | (access),			\
776	    __ptr, 0, sysctl_handle_uma_zone_max, "I", __DESCR(descr));	\
777})
778
779/* Oid to obtain current use of uma(9) zone specified by pointer. */
780#define	SYSCTL_UMA_CUR(parent, nbr, name, access, ptr, descr)		\
781	SYSCTL_OID(parent, nbr, name,					\
782	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
783	    (ptr), 0, sysctl_handle_uma_zone_cur, "I", descr);		\
784	CTASSERT(((access) & CTLTYPE) == 0 ||				\
785	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
786
787#define	SYSCTL_ADD_UMA_CUR(ctx, parent, nbr, name, access, ptr, descr)	\
788({									\
789	uma_zone_t __ptr = (ptr);					\
790	CTASSERT(((access) & CTLTYPE) == 0 ||				\
791	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
792	sysctl_add_oid(ctx, parent, nbr, name,				\
793	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
794	    __ptr, 0, sysctl_handle_uma_zone_cur, "I", __DESCR(descr));	\
795})
796
797/* OID expressing a struct timeval as seconds */
798#define	SYSCTL_TIMEVAL_SEC(parent, nbr, name, access, ptr, descr)	\
799	SYSCTL_OID(parent, nbr, name,					\
800	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
801	    (ptr), 0, sysctl_sec_to_timeval, "I", descr);		\
802	CTASSERT(((access) & CTLTYPE) == 0 ||				\
803	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT)
804#define	SYSCTL_ADD_TIMEVAL_SEC(ctx, parent, nbr, name, access, ptr, descr) \
805({									\
806	struct timeval *__ptr = (ptr);					\
807	CTASSERT(((access) & CTLTYPE) == 0 ||				\
808	    ((access) & SYSCTL_CT_ASSERT_MASK) == CTLTYPE_INT);		\
809	sysctl_add_oid(ctx, parent, nbr, name,				\
810	    CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RD | (access),	\
811	    __ptr, 0, sysctl_sec_to_timeval, "I", __DESCR(descr),	\
812	    NULL);							\
813})
814
815/*
816 * A macro to generate a read-only sysctl to indicate the presence of optional
817 * kernel features.
818 */
819#define	FEATURE(name, desc)						\
820	SYSCTL_INT(_kern_features, OID_AUTO, name, CTLFLAG_RD | CTLFLAG_CAPRD, \
821	    SYSCTL_NULL_INT_PTR, 1, desc)
822
823#endif /* _KERNEL */
824
825/*
826 * Top-level identifiers
827 */
828#define	CTL_UNSPEC	0		/* unused */
829#define	CTL_KERN	1		/* "high kernel": proc, limits */
830#define	CTL_VM		2		/* virtual memory */
831#define	CTL_VFS		3		/* filesystem, mount type is next */
832#define	CTL_NET		4		/* network, see socket.h */
833#define	CTL_DEBUG	5		/* debugging parameters */
834#define	CTL_HW		6		/* generic cpu/io */
835#define	CTL_MACHDEP	7		/* machine dependent */
836#define	CTL_USER	8		/* user-level */
837#define	CTL_P1003_1B	9		/* POSIX 1003.1B */
838
839/*
840 * CTL_KERN identifiers
841 */
842#define	KERN_OSTYPE		 1	/* string: system version */
843#define	KERN_OSRELEASE		 2	/* string: system release */
844#define	KERN_OSREV		 3	/* int: system revision */
845#define	KERN_VERSION		 4	/* string: compile time info */
846#define	KERN_MAXVNODES		 5	/* int: max vnodes */
847#define	KERN_MAXPROC		 6	/* int: max processes */
848#define	KERN_MAXFILES		 7	/* int: max open files */
849#define	KERN_ARGMAX		 8	/* int: max arguments to exec */
850#define	KERN_SECURELVL		 9	/* int: system security level */
851#define	KERN_HOSTNAME		10	/* string: hostname */
852#define	KERN_HOSTID		11	/* int: host identifier */
853#define	KERN_CLOCKRATE		12	/* struct: struct clockrate */
854#define	KERN_VNODE		13	/* struct: vnode structures */
855#define	KERN_PROC		14	/* struct: process entries */
856#define	KERN_FILE		15	/* struct: file entries */
857#define	KERN_PROF		16	/* node: kernel profiling info */
858#define	KERN_POSIX1		17	/* int: POSIX.1 version */
859#define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
860#define	KERN_JOB_CONTROL	19	/* int: is job control available */
861#define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
862#define	KERN_BOOTTIME		21	/* struct: time kernel was booted */
863#define	KERN_NISDOMAINNAME	22	/* string: YP domain name */
864#define	KERN_UPDATEINTERVAL	23	/* int: update process sleep time */
865#define	KERN_OSRELDATE		24	/* int: kernel release date */
866#define	KERN_NTP_PLL		25	/* node: NTP PLL control */
867#define	KERN_BOOTFILE		26	/* string: name of booted kernel */
868#define	KERN_MAXFILESPERPROC	27	/* int: max open files per proc */
869#define	KERN_MAXPROCPERUID	28	/* int: max processes per uid */
870#define	KERN_DUMPDEV		29	/* struct cdev *: device to dump on */
871#define	KERN_IPC		30	/* node: anything related to IPC */
872#define	KERN_DUMMY		31	/* unused */
873#define	KERN_PS_STRINGS		32	/* int: address of PS_STRINGS */
874#define	KERN_USRSTACK		33	/* int: address of USRSTACK */
875#define	KERN_LOGSIGEXIT		34	/* int: do we log sigexit procs? */
876#define	KERN_IOV_MAX		35	/* int: value of UIO_MAXIOV */
877#define	KERN_HOSTUUID		36	/* string: host UUID identifier */
878#define	KERN_ARND		37	/* int: from arc4rand() */
879/*
880 * KERN_PROC subtypes
881 */
882#define	KERN_PROC_ALL		0	/* everything */
883#define	KERN_PROC_PID		1	/* by process id */
884#define	KERN_PROC_PGRP		2	/* by process group id */
885#define	KERN_PROC_SESSION	3	/* by session of pid */
886#define	KERN_PROC_TTY		4	/* by controlling tty */
887#define	KERN_PROC_UID		5	/* by effective uid */
888#define	KERN_PROC_RUID		6	/* by real uid */
889#define	KERN_PROC_ARGS		7	/* get/set arguments/proctitle */
890#define	KERN_PROC_PROC		8	/* only return procs */
891#define	KERN_PROC_SV_NAME	9	/* get syscall vector name */
892#define	KERN_PROC_RGID		10	/* by real group id */
893#define	KERN_PROC_GID		11	/* by effective group id */
894#define	KERN_PROC_PATHNAME	12	/* path to executable */
895#define	KERN_PROC_OVMMAP	13	/* Old VM map entries for process */
896#define	KERN_PROC_OFILEDESC	14	/* Old file descriptors for process */
897#define	KERN_PROC_KSTACK	15	/* Kernel stacks for process */
898#define	KERN_PROC_INC_THREAD	0x10	/*
899					 * modifier for pid, pgrp, tty,
900					 * uid, ruid, gid, rgid and proc
901					 * This effectively uses 16-31
902					 */
903#define	KERN_PROC_VMMAP		32	/* VM map entries for process */
904#define	KERN_PROC_FILEDESC	33	/* File descriptors for process */
905#define	KERN_PROC_GROUPS	34	/* process groups */
906#define	KERN_PROC_ENV		35	/* get environment */
907#define	KERN_PROC_AUXV		36	/* get ELF auxiliary vector */
908#define	KERN_PROC_RLIMIT	37	/* process resource limits */
909#define	KERN_PROC_PS_STRINGS	38	/* get ps_strings location */
910#define	KERN_PROC_UMASK		39	/* process umask */
911#define	KERN_PROC_OSREL		40	/* osreldate for process binary */
912#define	KERN_PROC_SIGTRAMP	41	/* signal trampoline location */
913#define	KERN_PROC_CWD		42	/* process current working directory */
914#define	KERN_PROC_NFDS		43	/* number of open file descriptors */
915
916/*
917 * KERN_IPC identifiers
918 */
919#define	KIPC_MAXSOCKBUF		1	/* int: max size of a socket buffer */
920#define	KIPC_SOCKBUF_WASTE	2	/* int: wastage factor in sockbuf */
921#define	KIPC_SOMAXCONN		3	/* int: max length of connection q */
922#define	KIPC_MAX_LINKHDR	4	/* int: max length of link header */
923#define	KIPC_MAX_PROTOHDR	5	/* int: max length of network header */
924#define	KIPC_MAX_HDR		6	/* int: max total length of headers */
925#define	KIPC_MAX_DATALEN	7	/* int: max length of data? */
926
927/*
928 * CTL_HW identifiers
929 */
930#define	HW_MACHINE	 1		/* string: machine class */
931#define	HW_MODEL	 2		/* string: specific machine model */
932#define	HW_NCPU		 3		/* int: number of cpus */
933#define	HW_BYTEORDER	 4		/* int: machine byte order */
934#define	HW_PHYSMEM	 5		/* int: total memory */
935#define	HW_USERMEM	 6		/* int: non-kernel memory */
936#define	HW_PAGESIZE	 7		/* int: software page size */
937#define	HW_DISKNAMES	 8		/* strings: disk drive names */
938#define	HW_DISKSTATS	 9		/* struct: diskstats[] */
939#define	HW_FLOATINGPT	10		/* int: has HW floating point? */
940#define	HW_MACHINE_ARCH	11		/* string: machine architecture */
941#define	HW_REALMEM	12		/* int: 'real' memory */
942
943/*
944 * CTL_USER definitions
945 */
946#define	USER_CS_PATH		 1	/* string: _CS_PATH */
947#define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
948#define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
949#define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
950#define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
951#define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
952#define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
953#define	USER_LINE_MAX		 8	/* int: LINE_MAX */
954#define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
955#define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
956#define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
957#define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
958#define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
959#define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
960#define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
961#define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
962#define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
963#define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
964#define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
965#define	USER_TZNAME_MAX		20	/* int: POSIX2_TZNAME_MAX */
966
967#define	CTL_P1003_1B_ASYNCHRONOUS_IO		1	/* boolean */
968#define	CTL_P1003_1B_MAPPED_FILES		2	/* boolean */
969#define	CTL_P1003_1B_MEMLOCK			3	/* boolean */
970#define	CTL_P1003_1B_MEMLOCK_RANGE		4	/* boolean */
971#define	CTL_P1003_1B_MEMORY_PROTECTION		5	/* boolean */
972#define	CTL_P1003_1B_MESSAGE_PASSING		6	/* boolean */
973#define	CTL_P1003_1B_PRIORITIZED_IO		7	/* boolean */
974#define	CTL_P1003_1B_PRIORITY_SCHEDULING	8	/* boolean */
975#define	CTL_P1003_1B_REALTIME_SIGNALS		9	/* boolean */
976#define	CTL_P1003_1B_SEMAPHORES			10	/* boolean */
977#define	CTL_P1003_1B_FSYNC			11	/* boolean */
978#define	CTL_P1003_1B_SHARED_MEMORY_OBJECTS	12	/* boolean */
979#define	CTL_P1003_1B_SYNCHRONIZED_IO		13	/* boolean */
980#define	CTL_P1003_1B_TIMERS			14	/* boolean */
981#define	CTL_P1003_1B_AIO_LISTIO_MAX		15	/* int */
982#define	CTL_P1003_1B_AIO_MAX			16	/* int */
983#define	CTL_P1003_1B_AIO_PRIO_DELTA_MAX		17	/* int */
984#define	CTL_P1003_1B_DELAYTIMER_MAX		18	/* int */
985#define	CTL_P1003_1B_MQ_OPEN_MAX		19	/* int */
986#define	CTL_P1003_1B_PAGESIZE			20	/* int */
987#define	CTL_P1003_1B_RTSIG_MAX			21	/* int */
988#define	CTL_P1003_1B_SEM_NSEMS_MAX		22	/* int */
989#define	CTL_P1003_1B_SEM_VALUE_MAX		23	/* int */
990#define	CTL_P1003_1B_SIGQUEUE_MAX		24	/* int */
991#define	CTL_P1003_1B_TIMER_MAX			25	/* int */
992
993#define	CTL_P1003_1B_MAXID		26
994
995#ifdef _KERNEL
996
997/*
998 * Declare some common oids.
999 */
1000extern struct sysctl_oid_list sysctl__children;
1001SYSCTL_DECL(_kern);
1002SYSCTL_DECL(_kern_features);
1003SYSCTL_DECL(_kern_ipc);
1004SYSCTL_DECL(_kern_proc);
1005SYSCTL_DECL(_kern_sched);
1006SYSCTL_DECL(_kern_sched_stats);
1007SYSCTL_DECL(_sysctl);
1008SYSCTL_DECL(_vm);
1009SYSCTL_DECL(_vm_stats);
1010SYSCTL_DECL(_vm_stats_misc);
1011SYSCTL_DECL(_vfs);
1012SYSCTL_DECL(_net);
1013SYSCTL_DECL(_debug);
1014SYSCTL_DECL(_debug_sizeof);
1015SYSCTL_DECL(_dev);
1016SYSCTL_DECL(_hw);
1017SYSCTL_DECL(_hw_bus);
1018SYSCTL_DECL(_hw_bus_devices);
1019SYSCTL_DECL(_hw_bus_info);
1020SYSCTL_DECL(_machdep);
1021SYSCTL_DECL(_machdep_mitigations);
1022SYSCTL_DECL(_user);
1023SYSCTL_DECL(_compat);
1024SYSCTL_DECL(_regression);
1025SYSCTL_DECL(_security);
1026SYSCTL_DECL(_security_bsd);
1027
1028extern char	machine[];
1029extern char	osrelease[];
1030extern char	ostype[];
1031extern char	kern_ident[];
1032
1033/* Dynamic oid handling */
1034struct sysctl_oid *sysctl_add_oid(struct sysctl_ctx_list *clist,
1035	    struct sysctl_oid_list *parent, int nbr, const char *name, int kind,
1036	    void *arg1, intmax_t arg2, int (*handler)(SYSCTL_HANDLER_ARGS),
1037	    const char *fmt, const char *descr);
1038int	sysctl_remove_name(struct sysctl_oid *parent, const char *name, int del,
1039	    int recurse);
1040void	sysctl_rename_oid(struct sysctl_oid *oidp, const char *name);
1041int	sysctl_move_oid(struct sysctl_oid *oidp,
1042	    struct sysctl_oid_list *parent);
1043int	sysctl_remove_oid(struct sysctl_oid *oidp, int del, int recurse);
1044int	sysctl_ctx_init(struct sysctl_ctx_list *clist);
1045int	sysctl_ctx_free(struct sysctl_ctx_list *clist);
1046struct	sysctl_ctx_entry *sysctl_ctx_entry_add(struct sysctl_ctx_list *clist,
1047	    struct sysctl_oid *oidp);
1048struct	sysctl_ctx_entry *sysctl_ctx_entry_find(struct sysctl_ctx_list *clist,
1049	    struct sysctl_oid *oidp);
1050int	sysctl_ctx_entry_del(struct sysctl_ctx_list *clist,
1051	    struct sysctl_oid *oidp);
1052
1053int	kernel_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1054	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1055	    int flags);
1056int	kernel_sysctlbyname(struct thread *td, char *name, void *old,
1057	    size_t *oldlenp, void *new, size_t newlen, size_t *retval,
1058	    int flags);
1059int	userland_sysctl(struct thread *td, int *name, u_int namelen, void *old,
1060	    size_t *oldlenp, int inkernel, void *new, size_t newlen,
1061	    size_t *retval, int flags);
1062int	sysctl_find_oid(int *name, u_int namelen, struct sysctl_oid **noid,
1063	    int *nindx, struct sysctl_req *req);
1064void	sysctl_wlock(void);
1065void	sysctl_wunlock(void);
1066int	sysctl_wire_old_buffer(struct sysctl_req *req, size_t len);
1067
1068struct sbuf;
1069struct sbuf *sbuf_new_for_sysctl(struct sbuf *, char *, int,
1070	    struct sysctl_req *);
1071#else	/* !_KERNEL */
1072#include <sys/cdefs.h>
1073
1074__BEGIN_DECLS
1075int	sysctl(const int *, u_int, void *, size_t *, const void *, size_t);
1076int	sysctlbyname(const char *, void *, size_t *, const void *, size_t);
1077int	sysctlnametomib(const char *, int *, size_t *);
1078__END_DECLS
1079#endif	/* _KERNEL */
1080
1081#endif	/* !_SYS_SYSCTL_H_ */
1082