4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All rights reserved. */
29 #include <sys/param.h>
30 #include <sys/types.h>
31 #include <sys/sysmacros.h>
32 #include <sys/systm.h>
33 #include <sys/tuneable.h>
34 #include <sys/errno.h>
36 #include <sys/utsname.h>
37 #include <sys/systeminfo.h>
38 #include <sys/unistd.h>
39 #include <sys/debug.h>
40 #include <sys/bootconf.h>
41 #include <sys/socket.h>
42 #include <sys/policy.h>
44 #include <sys/sunddi.h>
45 #include <sys/promif.h>
47 #include <sys/model.h>
48 #include <netinet/inetutil.h>
50 static void get_netif_name(char *, char *);
53 systeminfo(int command
, char *buf
, long count
)
58 char hostidp
[HW_HOSTID_LEN
];
60 if (count
< 0 && command
!= SI_SET_HOSTNAME
&&
61 command
!= SI_SET_SRPC_DOMAIN
)
62 return (set_errno(EINVAL
));
65 * Deal with the common "get a string" case first.
69 kstr
= utsname
.sysname
;
72 kstr
= uts_nodename();
75 kstr
= utsname
.release
;
78 kstr
= utsname
.version
;
81 kstr
= utsname
.machine
;
84 case SI_ARCHITECTURE_64
:
85 case SI_ARCHITECTURE_K
:
88 case SI_ARCHITECTURE_32
:
90 kstr
= architecture_32
;
92 case SI_ARCHITECTURE_NATIVE
:
93 kstr
= get_udatamodel() == DATAMODEL_NATIVE
?
94 architecture
: architecture_32
;
97 case SI_ARCHITECTURE_K
:
98 case SI_ARCHITECTURE_32
:
100 case SI_ARCHITECTURE_NATIVE
:
105 (void) snprintf(hostidp
, sizeof (hostidp
), "%u",
106 zone_get_hostid(curzone
));
113 kstr
= curproc
->p_zone
->zone_domain
;
127 strcnt
= strlen(kstr
);
129 if (count
<= strcnt
) {
131 if (subyte(buf
+ getcnt
, 0) < 0)
132 return (set_errno(EFAULT
));
136 if (copyout(kstr
, buf
, getcnt
))
137 return (set_errno(EFAULT
));
146 unsigned int tlen
, octlen
;
148 if (dhcack
== NULL
) {
153 * If the interface didn't have a name (bindable
154 * driver) to begin with, it might have one now.
155 * So, re-run strplumb_get_netdev_path() to see
156 * if one can be established at this time.
158 if (netdev_path
== NULL
|| netdev_path
[0] == '\0') {
159 netdev_path
= strplumb_get_netdev_path();
162 * If the interface name has not yet been resolved
163 * and a validnetdev_path[] was stashed by
164 * loadrootmodules in swapgeneric.c, or established
165 * above, resolve the interface name now.
167 if (dhcifname
[0] == '\0' &&
168 netdev_path
!= NULL
&& netdev_path
[0] != '\0') {
169 get_netif_name(netdev_path
, dhcifname
);
174 * IFNAMESIZ array of dhcp i/f
175 * hexascii representation of dhcp reply
177 octlen
= dhcacklen
* 2 + 1;
178 tlen
= octlen
+ IFNAMSIZ
;
179 tmp
= kmem_alloc(tlen
, KM_SLEEP
);
180 (void) strncpy(tmp
, dhcifname
, IFNAMSIZ
);
181 if (octet_to_hexascii(dhcack
, dhcacklen
,
182 &tmp
[IFNAMSIZ
], &octlen
) != 0) {
183 kmem_free(tmp
, tlen
);
187 strcnt
= IFNAMSIZ
+ octlen
;
192 if (count
<= strcnt
) {
194 if (subyte((buf
+ getcnt
), 0) < 0)
199 if (copyout(tmp
, buf
, getcnt
))
203 kmem_free(tmp
, tlen
);
207 kmem_free(tmp
, tlen
);
212 case SI_SET_HOSTNAME
:
218 if ((error
= secpolicy_systeminfo(CRED())) != 0)
221 name_to_use
= uts_nodename();
222 if ((error
= copyinstr(buf
, name
, SYS_NMLN
, &len
)) != 0)
226 * Must be non-NULL string and string
227 * must be less than SYS_NMLN chars.
229 if (len
< 2 || (len
== SYS_NMLN
&& name
[SYS_NMLN
-1] != '\0')) {
235 * Copy the name into the relevant zone's nodename.
237 (void) strcpy(name_to_use
, name
);
240 * Notify other interested parties that the nodename was set
242 if (name_to_use
== utsname
.nodename
) /* global zone nodename */
248 case SI_SET_SRPC_DOMAIN
:
253 if ((error
= secpolicy_systeminfo(CRED())) != 0)
255 if ((error
= copyinstr(buf
, name
, SYS_NMLN
, &len
)) != 0)
258 * If string passed in is longer than length
259 * allowed for domain name, fail.
261 if (len
== SYS_NMLN
&& name
[SYS_NMLN
-1] != '\0') {
266 (void) strcpy(curproc
->p_zone
->zone_domain
, name
);
275 return (set_errno(error
));
279 * i_path_find_node: Internal routine used by path_to_devinfo
280 * to locate a given nodeid in the device tree.
282 struct i_path_findnode
{
288 i_path_find_node(dev_info_t
*dev
, void *arg
)
290 struct i_path_findnode
*f
= (struct i_path_findnode
*)arg
;
293 if (ddi_get_nodeid(dev
) == (int)f
->nodeid
) {
295 return (DDI_WALK_TERMINATE
);
297 return (DDI_WALK_CONTINUE
);
301 * Return the devinfo node to a boot device
304 path_to_devinfo(char *path
)
306 struct i_path_findnode fn
;
307 extern dev_info_t
*top_devinfo
;
310 * Get the nodeid of the given pathname, if such a mapping exists.
313 fn
.nodeid
= prom_finddevice(path
);
314 if (fn
.nodeid
!= OBP_BADNODE
) {
316 * Find the nodeid in our copy of the device tree and return
317 * whatever name we used to bind this node to a driver.
319 ddi_walk_devs(top_devinfo
, i_path_find_node
, (void *)(&fn
));
326 * Determine the network interface name from the device path argument.
329 get_netif_name(char *devname
, char *ifname
)
336 dip
= path_to_devinfo(devname
);
338 cmn_err(CE_WARN
, "get_netif_name: "
339 "can't bind driver for '%s'\n", devname
);
343 ndev
= ddi_driver_major(dip
);
345 cmn_err(CE_WARN
, "get_netif_name: "
346 "no driver bound to '%s'\n", devname
);
350 name
= ddi_major_to_name(ndev
);
352 cmn_err(CE_WARN
, "get_netif_name: "
353 "no name for major number %d\n", ndev
);
357 unit
= i_ddi_devi_get_ppa(dip
);
359 cmn_err(CE_WARN
, "get_netif_name: "
360 "illegal unit number %d\n", unit
);
364 (void) snprintf(ifname
, IFNAMSIZ
, "%s%d", name
, unit
);