init_sysctl_base.c revision 1.1.14.1 1 1.1.14.1 yamt /* $NetBSD: init_sysctl_base.c,v 1.1.14.1 2014/05/22 11:41:03 yamt Exp $ */
2 1.1 pooka
3 1.1 pooka /*-
4 1.1 pooka * Copyright (c) 2003, 2007, 2008, 2009 The NetBSD Foundation, Inc.
5 1.1 pooka * All rights reserved.
6 1.1 pooka *
7 1.1 pooka * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pooka * by Andrew Brown, and by Andrew Doran.
9 1.1 pooka *
10 1.1 pooka * Redistribution and use in source and binary forms, with or without
11 1.1 pooka * modification, are permitted provided that the following conditions
12 1.1 pooka * are met:
13 1.1 pooka * 1. Redistributions of source code must retain the above copyright
14 1.1 pooka * notice, this list of conditions and the following disclaimer.
15 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pooka * notice, this list of conditions and the following disclaimer in the
17 1.1 pooka * documentation and/or other materials provided with the distribution.
18 1.1 pooka *
19 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 pooka * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 pooka * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 pooka * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 pooka * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 pooka * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 pooka * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pooka * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 pooka * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 pooka * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 pooka * POSSIBILITY OF SUCH DAMAGE.
30 1.1 pooka */
31 1.1 pooka
32 1.1 pooka #include <sys/cdefs.h>
33 1.1.14.1 yamt __KERNEL_RCSID(0, "$NetBSD: init_sysctl_base.c,v 1.1.14.1 2014/05/22 11:41:03 yamt Exp $");
34 1.1 pooka
35 1.1 pooka #include <sys/param.h>
36 1.1 pooka #include <sys/sysctl.h>
37 1.1.14.1 yamt #include <sys/kernel.h>
38 1.1.14.1 yamt #include <sys/disklabel.h>
39 1.1.14.1 yamt
40 1.1.14.1 yamt static int sysctl_setlen(SYSCTLFN_PROTO);
41 1.1 pooka
42 1.1 pooka /*
43 1.1 pooka * sets up the base nodes...
44 1.1 pooka */
45 1.1.14.1 yamt void
46 1.1.14.1 yamt sysctl_basenode_init(void)
47 1.1 pooka {
48 1.1 pooka
49 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
50 1.1 pooka CTLFLAG_PERMANENT,
51 1.1 pooka CTLTYPE_NODE, "kern",
52 1.1 pooka SYSCTL_DESCR("High kernel"),
53 1.1 pooka NULL, 0, NULL, 0,
54 1.1 pooka CTL_KERN, CTL_EOL);
55 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
56 1.1 pooka CTLFLAG_PERMANENT,
57 1.1 pooka CTLTYPE_NODE, "vm",
58 1.1 pooka SYSCTL_DESCR("Virtual memory"),
59 1.1 pooka NULL, 0, NULL, 0,
60 1.1 pooka CTL_VM, CTL_EOL);
61 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
62 1.1 pooka CTLFLAG_PERMANENT,
63 1.1 pooka CTLTYPE_NODE, "vfs",
64 1.1 pooka SYSCTL_DESCR("Filesystem"),
65 1.1 pooka NULL, 0, NULL, 0,
66 1.1 pooka CTL_VFS, CTL_EOL);
67 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
68 1.1 pooka CTLFLAG_PERMANENT,
69 1.1 pooka CTLTYPE_NODE, "net",
70 1.1 pooka SYSCTL_DESCR("Networking"),
71 1.1 pooka NULL, 0, NULL, 0,
72 1.1 pooka CTL_NET, CTL_EOL);
73 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
74 1.1 pooka CTLFLAG_PERMANENT,
75 1.1 pooka CTLTYPE_NODE, "debug",
76 1.1 pooka SYSCTL_DESCR("Debugging"),
77 1.1 pooka NULL, 0, NULL, 0,
78 1.1 pooka CTL_DEBUG, CTL_EOL);
79 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
80 1.1 pooka CTLFLAG_PERMANENT,
81 1.1 pooka CTLTYPE_NODE, "hw",
82 1.1 pooka SYSCTL_DESCR("Generic CPU, I/O"),
83 1.1 pooka NULL, 0, NULL, 0,
84 1.1 pooka CTL_HW, CTL_EOL);
85 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
86 1.1 pooka CTLFLAG_PERMANENT,
87 1.1 pooka CTLTYPE_NODE, "machdep",
88 1.1 pooka SYSCTL_DESCR("Machine dependent"),
89 1.1 pooka NULL, 0, NULL, 0,
90 1.1 pooka CTL_MACHDEP, CTL_EOL);
91 1.1 pooka /*
92 1.1 pooka * this node is inserted so that the sysctl nodes in libc can
93 1.1 pooka * operate.
94 1.1 pooka */
95 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
96 1.1 pooka CTLFLAG_PERMANENT,
97 1.1 pooka CTLTYPE_NODE, "user",
98 1.1 pooka SYSCTL_DESCR("User-level"),
99 1.1 pooka NULL, 0, NULL, 0,
100 1.1 pooka CTL_USER, CTL_EOL);
101 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
102 1.1 pooka CTLFLAG_PERMANENT,
103 1.1 pooka CTLTYPE_NODE, "ddb",
104 1.1 pooka SYSCTL_DESCR("In-kernel debugger"),
105 1.1 pooka NULL, 0, NULL, 0,
106 1.1 pooka CTL_DDB, CTL_EOL);
107 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
108 1.1 pooka CTLFLAG_PERMANENT,
109 1.1 pooka CTLTYPE_NODE, "proc",
110 1.1 pooka SYSCTL_DESCR("Per-process"),
111 1.1 pooka NULL, 0, NULL, 0,
112 1.1 pooka CTL_PROC, CTL_EOL);
113 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
114 1.1 pooka CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
115 1.1 pooka CTLTYPE_NODE, "vendor",
116 1.1 pooka SYSCTL_DESCR("Vendor specific"),
117 1.1 pooka NULL, 0, NULL, 0,
118 1.1 pooka CTL_VENDOR, CTL_EOL);
119 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
120 1.1 pooka CTLFLAG_PERMANENT,
121 1.1 pooka CTLTYPE_NODE, "emul",
122 1.1 pooka SYSCTL_DESCR("Emulation settings"),
123 1.1 pooka NULL, 0, NULL, 0,
124 1.1 pooka CTL_EMUL, CTL_EOL);
125 1.1.14.1 yamt sysctl_createv(NULL, 0, NULL, NULL,
126 1.1 pooka CTLFLAG_PERMANENT,
127 1.1 pooka CTLTYPE_NODE, "security",
128 1.1 pooka SYSCTL_DESCR("Security"),
129 1.1 pooka NULL, 0, NULL, 0,
130 1.1 pooka CTL_SECURITY, CTL_EOL);
131 1.1 pooka }
132 1.1.14.1 yamt
133 1.1.14.1 yamt /*
134 1.1.14.1 yamt * now add some nodes which both rump kernel and standard
135 1.1.14.1 yamt * NetBSD both need, as rump cannot use sys/kern/init_sysctl.c
136 1.1.14.1 yamt */
137 1.1.14.1 yamt SYSCTL_SETUP(sysctl_kernbase_setup, "sysctl kern subtree base setup")
138 1.1.14.1 yamt {
139 1.1.14.1 yamt
140 1.1.14.1 yamt sysctl_createv(clog, 0, NULL, NULL,
141 1.1.14.1 yamt CTLFLAG_PERMANENT,
142 1.1.14.1 yamt CTLTYPE_STRING, "ostype",
143 1.1.14.1 yamt SYSCTL_DESCR("Operating system type"),
144 1.1.14.1 yamt NULL, 0, __UNCONST(&ostype), 0,
145 1.1.14.1 yamt CTL_KERN, KERN_OSTYPE, CTL_EOL);
146 1.1.14.1 yamt sysctl_createv(clog, 0, NULL, NULL,
147 1.1.14.1 yamt CTLFLAG_PERMANENT,
148 1.1.14.1 yamt CTLTYPE_STRING, "osrelease",
149 1.1.14.1 yamt SYSCTL_DESCR("Operating system release"),
150 1.1.14.1 yamt NULL, 0, __UNCONST(&osrelease), 0,
151 1.1.14.1 yamt CTL_KERN, KERN_OSRELEASE, CTL_EOL);
152 1.1.14.1 yamt sysctl_createv(clog, 0, NULL, NULL,
153 1.1.14.1 yamt CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
154 1.1.14.1 yamt CTLTYPE_INT, "osrevision",
155 1.1.14.1 yamt SYSCTL_DESCR("Operating system revision"),
156 1.1.14.1 yamt NULL, __NetBSD_Version__, NULL, 0,
157 1.1.14.1 yamt CTL_KERN, KERN_OSREV, CTL_EOL);
158 1.1.14.1 yamt sysctl_createv(clog, 0, NULL, NULL,
159 1.1.14.1 yamt CTLFLAG_PERMANENT,
160 1.1.14.1 yamt CTLTYPE_STRING, "version",
161 1.1.14.1 yamt SYSCTL_DESCR("Kernel version"),
162 1.1.14.1 yamt NULL, 0, __UNCONST(&version), 0,
163 1.1.14.1 yamt CTL_KERN, KERN_VERSION, CTL_EOL);
164 1.1.14.1 yamt sysctl_createv(clog, 0, NULL, NULL,
165 1.1.14.1 yamt CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
166 1.1.14.1 yamt CTLTYPE_STRING, "hostname",
167 1.1.14.1 yamt SYSCTL_DESCR("System hostname"),
168 1.1.14.1 yamt sysctl_setlen, 0, hostname, MAXHOSTNAMELEN,
169 1.1.14.1 yamt CTL_KERN, KERN_HOSTNAME, CTL_EOL);
170 1.1.14.1 yamt sysctl_createv(clog, 0, NULL, NULL,
171 1.1.14.1 yamt CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
172 1.1.14.1 yamt CTLTYPE_STRING, "domainname",
173 1.1.14.1 yamt SYSCTL_DESCR("YP domain name"),
174 1.1.14.1 yamt sysctl_setlen, 0, domainname, MAXHOSTNAMELEN,
175 1.1.14.1 yamt CTL_KERN, KERN_DOMAINNAME, CTL_EOL);
176 1.1.14.1 yamt sysctl_createv(clog, 0, NULL, NULL,
177 1.1.14.1 yamt CTLFLAG_PERMANENT|CTLFLAG_IMMEDIATE,
178 1.1.14.1 yamt CTLTYPE_INT, "rawpartition",
179 1.1.14.1 yamt SYSCTL_DESCR("Raw partition of a disk"),
180 1.1.14.1 yamt NULL, RAW_PART, NULL, 0,
181 1.1.14.1 yamt CTL_KERN, KERN_RAWPARTITION, CTL_EOL);
182 1.1.14.1 yamt }
183 1.1.14.1 yamt
184 1.1.14.1 yamt /*
185 1.1.14.1 yamt * sysctl helper function for kern.hostname and kern.domainnname.
186 1.1.14.1 yamt * resets the relevant recorded length when the underlying name is
187 1.1.14.1 yamt * changed.
188 1.1.14.1 yamt */
189 1.1.14.1 yamt static int
190 1.1.14.1 yamt sysctl_setlen(SYSCTLFN_ARGS)
191 1.1.14.1 yamt {
192 1.1.14.1 yamt int error;
193 1.1.14.1 yamt
194 1.1.14.1 yamt error = sysctl_lookup(SYSCTLFN_CALL(rnode));
195 1.1.14.1 yamt if (error || newp == NULL)
196 1.1.14.1 yamt return (error);
197 1.1.14.1 yamt
198 1.1.14.1 yamt switch (rnode->sysctl_num) {
199 1.1.14.1 yamt case KERN_HOSTNAME:
200 1.1.14.1 yamt hostnamelen = strlen((const char*)rnode->sysctl_data);
201 1.1.14.1 yamt break;
202 1.1.14.1 yamt case KERN_DOMAINNAME:
203 1.1.14.1 yamt domainnamelen = strlen((const char*)rnode->sysctl_data);
204 1.1.14.1 yamt break;
205 1.1.14.1 yamt }
206 1.1.14.1 yamt
207 1.1.14.1 yamt return (0);
208 1.1.14.1 yamt }
209