source: rtems/cpukit/libnetworking/kern/kern_mib.c @ 1e039fb3

5
Last change on this file since 1e039fb3 was cb68253, checked in by Sebastian Huber <sebastian.huber@…>, on 09/07/18 at 04:19:02

network: Use kernel/user space header files

Add and use <machine/rtems-bsd-kernel-space.h> and
<machine/rtems-bsd-user-space.h> similar to the libbsd to avoid command
line defines and defines scattered throught the code base.

Simplify cpukit/libnetworking/Makefile.am.

Update #3375.

  • Property mode set to 100644
File size: 12.7 KB
Line 
1#include <machine/rtems-bsd-kernel-space.h>
2
3/*-
4 * Copyright (c) 1982, 1986, 1989, 1993
5 *      The Regents of the University of California.  All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Mike Karels at Berkeley Software Design, Inc.
9 *
10 * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
11 * project, to make these variables more userfriendly.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 *    notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 *    notice, this list of conditions and the following disclaimer in the
20 *    documentation and/or other materials provided with the distribution.
21 * 4. Neither the name of the University nor the names of its contributors
22 *    may be used to endorse or promote products derived from this software
23 *    without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 *      @(#)kern_sysctl.c       8.4 (Berkeley) 4/14/94
38 * $FreeBSD: src/sys/kern/kern_mib.c,v 1.74 2005/02/28 21:42:56 wes Exp $
39 */
40
41
42#ifndef __rtems__
43#include "opt_posix.h"
44#endif
45
46#include <sys/param.h>
47#include <sys/kernel.h>
48#include <sys/systm.h>
49#include <sys/sysctl.h>
50#include <sys/proc.h>
51#ifndef __rtems__
52#include <sys/lock.h>
53#include <sys/mutex.h>
54#include <sys/jail.h>
55#include <sys/smp.h>
56#endif
57#include <sys/unistd.h>
58
59#ifdef __rtems__
60char machine[] = "SET ME";
61char osrelease[] = RTEMS_VERSION;
62char ostype[] = "RTEMS";
63#endif
64
65SYSCTL_NODE(, 0,          sysctl, CTLFLAG_RW, 0,
66        "Sysctl internal magic");
67SYSCTL_NODE(, CTL_KERN,   kern,   CTLFLAG_RW, 0,
68        "High kernel, proc, limits &c");
69#ifndef __rtems__
70SYSCTL_NODE(, CTL_VM,     vm,     CTLFLAG_RW, 0,
71        "Virtual memory");
72SYSCTL_NODE(, CTL_VFS,    vfs,     CTLFLAG_RW, 0,
73        "File system");
74#endif
75SYSCTL_NODE(, CTL_NET,    net,    CTLFLAG_RW, 0,
76        "Network, (see socket.h)");
77#ifndef __rtems__
78SYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
79        "Debugging");
80SYSCTL_NODE(_debug, OID_AUTO,  sizeof,  CTLFLAG_RW, 0,
81        "Sizeof various things");
82SYSCTL_NODE(, CTL_HW,     hw,     CTLFLAG_RW, 0,
83        "hardware");
84SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
85        "machine dependent");
86SYSCTL_NODE(, CTL_USER,   user,   CTLFLAG_RW, 0,
87        "user-level");
88SYSCTL_NODE(, CTL_P1003_1B,  p1003_1b,   CTLFLAG_RW, 0,
89        "p1003_1b, (see p1003_1b.h)");
90
91SYSCTL_NODE(, OID_AUTO,  compat, CTLFLAG_RW, 0,
92        "Compatibility code");
93SYSCTL_NODE(, OID_AUTO, security, CTLFLAG_RW, 0,
94        "Security");
95#ifdef REGRESSION
96SYSCTL_NODE(, OID_AUTO, regression, CTLFLAG_RW, 0,
97     "Regression test MIB");
98#endif
99
100SYSCTL_STRING(_kern, OID_AUTO, ident, CTLFLAG_RD,
101    kern_ident, 0, "Kernel identifier");
102#endif /* __rtems__ */
103
104SYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD,
105    osrelease, 0, "Operating system release");
106
107SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD,
108    0, BSD, "Operating system revision");
109
110#ifndef __rtems__
111SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD,
112    version, 0, "Kernel version");
113#endif
114
115SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD,
116    ostype, 0, "Operating system type");
117
118#ifndef __rtems__
119extern int osreldate;
120SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD,
121    &osreldate, 0, "Operating system release date");
122
123SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD,
124    &maxproc, 0, "Maximum number of processes");
125
126SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid, CTLFLAG_RW,
127    &maxprocperuid, 0, "Maximum processes allowed per userid");
128
129SYSCTL_INT(_kern, OID_AUTO, maxusers, CTLFLAG_RD,
130    &maxusers, 0, "Hint for kernel tuning");
131
132SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD,
133    0, ARG_MAX, "Maximum bytes of argument to execve(2)");
134
135SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD,
136    0, _POSIX_VERSION, "Version of POSIX attempting to comply to");
137
138SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD,
139    0, NGROUPS_MAX, "Maximum number of groups a user can belong to");
140
141SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD,
142    0, 1, "Whether job control is available");
143
144#ifdef _POSIX_SAVED_IDS
145SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
146    0, 1, "Whether saved set-group/user ID is available");
147#else
148SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD,
149    0, 0, "Whether saved set-group/user ID is available");
150#endif
151
152char kernelname[MAXPATHLEN] = "/kernel";        /* XXX bloat */
153
154SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile, CTLFLAG_RW,
155    kernelname, sizeof kernelname, "Name of kernel file booted");
156
157#ifdef SMP
158SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
159    &mp_ncpus, 0, "Number of active CPUs");
160#else
161SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD,
162    0, 1, "Number of active CPUs");
163#endif
164
165SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD,
166    0, BYTE_ORDER, "System byte order");
167
168SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD,
169    0, PAGE_SIZE, "System memory page size");
170
171static int
172sysctl_hw_physmem(SYSCTL_HANDLER_ARGS)
173{
174        u_long val;
175
176        val = ctob(physmem);
177        return (sysctl_handle_long(oidp, &val, 0, req));
178}
179
180SYSCTL_PROC(_hw, HW_PHYSMEM, physmem, CTLTYPE_ULONG | CTLFLAG_RD,
181        0, 0, sysctl_hw_physmem, "LU", "");
182
183static int
184sysctl_hw_usermem(SYSCTL_HANDLER_ARGS)
185{
186        u_long val;
187
188        val = ctob(physmem - cnt.v_wire_count);
189        return (sysctl_handle_long(oidp, &val, 0, req));
190}
191
192SYSCTL_PROC(_hw, HW_USERMEM, usermem, CTLTYPE_ULONG | CTLFLAG_RD,
193        0, 0, sysctl_hw_usermem, "LU", "");
194
195SYSCTL_ULONG(_hw, OID_AUTO, availpages, CTLFLAG_RD, &physmem, 0, "");
196
197static char     machine_arch[] = MACHINE_ARCH;
198SYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
199    machine_arch, 0, "System architecture");
200
201char hostname[MAXHOSTNAMELEN];
202
203static int
204sysctl_hostname(SYSCTL_HANDLER_ARGS)
205{
206        struct prison *pr;
207        char tmphostname[MAXHOSTNAMELEN];
208        int error;
209
210        pr = req->td->td_ucred->cr_prison;
211        if (pr != NULL) {
212                if (!jail_set_hostname_allowed && req->newptr)
213                        return (EPERM);
214                /*
215                 * Process is in jail, so make a local copy of jail
216                 * hostname to get/set so we don't have to hold the jail
217                 * mutex during the sysctl copyin/copyout activities.
218                 */
219                mtx_lock(&pr->pr_mtx);
220                bcopy(pr->pr_host, tmphostname, MAXHOSTNAMELEN);
221                mtx_unlock(&pr->pr_mtx);
222
223                error = sysctl_handle_string(oidp, tmphostname,
224                    sizeof pr->pr_host, req);
225
226                if (req->newptr != NULL && error == 0) {
227                        /*
228                         * Copy the locally set hostname to the jail, if
229                         * appropriate.
230                         */
231                        mtx_lock(&pr->pr_mtx);
232                        bcopy(tmphostname, pr->pr_host, MAXHOSTNAMELEN);
233                        mtx_unlock(&pr->pr_mtx);
234                }
235        } else
236                error = sysctl_handle_string(oidp,
237                    hostname, sizeof hostname, req);
238        return (error);
239}
240
241SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname,
242       CTLTYPE_STRING|CTLFLAG_RW|CTLFLAG_PRISON,
243       0, 0, sysctl_hostname, "A", "Hostname");
244
245static int      regression_securelevel_nonmonotonic = 0;
246
247#ifdef REGRESSION
248SYSCTL_INT(_regression, OID_AUTO, securelevel_nonmonotonic, CTLFLAG_RW,
249    &regression_securelevel_nonmonotonic, 0, "securelevel may be lowered");
250#endif
251
252int securelevel = -1;
253struct mtx securelevel_mtx;
254
255MTX_SYSINIT(securelevel_lock, &securelevel_mtx, "securelevel mutex lock",
256    MTX_DEF);
257
258static int
259sysctl_kern_securelvl(SYSCTL_HANDLER_ARGS)
260{
261        struct prison *pr;
262        int error, level;
263
264        pr = req->td->td_ucred->cr_prison;
265
266        /*
267         * If the process is in jail, return the maximum of the global and
268         * local levels; otherwise, return the global level.
269         */
270        if (pr != NULL) {
271                mtx_lock(&pr->pr_mtx);
272                level = imax(securelevel, pr->pr_securelevel);
273                mtx_unlock(&pr->pr_mtx);
274        } else
275                level = securelevel;
276        error = sysctl_handle_int(oidp, &level, 0, req);
277        if (error || !req->newptr)
278                return (error);
279        /*
280         * Permit update only if the new securelevel exceeds the
281         * global level, and local level if any.
282         */
283        if (pr != NULL) {
284                mtx_lock(&pr->pr_mtx);
285                if (!regression_securelevel_nonmonotonic &&
286                    (level < imax(securelevel, pr->pr_securelevel))) {
287                        mtx_unlock(&pr->pr_mtx);
288                        return (EPERM);
289                }
290                pr->pr_securelevel = level;
291                mtx_unlock(&pr->pr_mtx);
292        } else {
293                mtx_lock(&securelevel_mtx);
294                if (!regression_securelevel_nonmonotonic &&
295                    (level < securelevel)) {
296                        mtx_unlock(&securelevel_mtx);
297                        return (EPERM);
298                }
299                securelevel = level;
300                mtx_unlock(&securelevel_mtx);
301        }
302        return (error);
303}
304
305SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel,
306    CTLTYPE_INT|CTLFLAG_RW|CTLFLAG_PRISON, 0, 0, sysctl_kern_securelvl,
307    "I", "Current secure level");
308
309char domainname[MAXHOSTNAMELEN];
310SYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW,
311    &domainname, sizeof(domainname), "Name of the current YP/NIS domain");
312
313u_long hostid;
314SYSCTL_ULONG(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "Host ID");
315
316/*
317 * This is really cheating.  These actually live in the libc, something
318 * which I'm not quite sure is a good idea anyway, but in order for
319 * getnext and friends to actually work, we define dummies here.
320 */
321SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD,
322    "", 0, "PATH that finds all the standard utilities");
323SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD,
324    0, 0, "Max ibase/obase values in bc(1)");
325SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD,
326    0, 0, "Max array size in bc(1)");
327SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD,
328    0, 0, "Max scale value in bc(1)");
329SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD,
330    0, 0, "Max string length in bc(1)");
331SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD,
332    0, 0, "Maximum number of weights assigned to an LC_COLLATE locale entry");
333SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
334SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD,
335    0, 0, "Max length (bytes) of a text-processing utility's input line");
336SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD,
337    0, 0, "Maximum number of repeats of a regexp permitted");
338SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD,
339    0, 0,
340    "The version of POSIX 1003.2 with which the system attempts to comply");
341SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD,
342    0, 0, "Whether C development supports the C bindings option");
343SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD,
344    0, 0, "Whether system supports the C development utilities option");
345SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD,
346    0, 0, "");
347SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD,
348    0, 0, "Whether system supports FORTRAN development utilities");
349SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD,
350    0, 0, "Whether system supports FORTRAN runtime utilities");
351SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD,
352    0, 0, "Whether system supports creation of locales");
353SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD,
354    0, 0, "Whether system supports software development utilities");
355SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD,
356    0, 0, "Whether system supports the user portability utilities");
357SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD,
358    0, 0, "Min Maximum number of streams a process may have open at one time");
359SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD,
360    0, 0, "Min Maximum number of types supported for timezone names");
361
362#include <sys/vnode.h>
363SYSCTL_INT(_debug_sizeof, OID_AUTO, vnode, CTLFLAG_RD,
364    0, sizeof(struct vnode), "sizeof(struct vnode)");
365
366SYSCTL_INT(_debug_sizeof, OID_AUTO, proc, CTLFLAG_RD,
367    0, sizeof(struct proc), "sizeof(struct proc)");
368
369#include <sys/conf.h>
370SYSCTL_INT(_debug_sizeof, OID_AUTO, cdev, CTLFLAG_RD,
371    0, sizeof(struct cdev), "sizeof(struct cdev)");
372
373#include <sys/bio.h>
374#include <sys/buf.h>
375SYSCTL_INT(_debug_sizeof, OID_AUTO, bio, CTLFLAG_RD,
376    0, sizeof(struct bio), "sizeof(struct bio)");
377SYSCTL_INT(_debug_sizeof, OID_AUTO, buf, CTLFLAG_RD,
378    0, sizeof(struct buf), "sizeof(struct buf)");
379
380#include <sys/user.h>
381SYSCTL_INT(_debug_sizeof, OID_AUTO, kinfo_proc, CTLFLAG_RD,
382    0, sizeof(struct kinfo_proc), "sizeof(struct kinfo_proc)");
383
384#endif /* __rtems__ */
Note: See TracBrowser for help on using the repository browser.