xref: /onnv-gate/usr/src/uts/common/io/strplumb.c (revision 10822:2a6b5dc1374c)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52343Sseb  * Common Development and Distribution License (the "License").
62343Sseb  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*10822SJack.Meng@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #include	<sys/param.h>
270Sstevel@tonic-gate #include	<sys/types.h>
280Sstevel@tonic-gate #include	<sys/user.h>
290Sstevel@tonic-gate #include	<sys/vfs.h>
300Sstevel@tonic-gate #include	<sys/vnode.h>
310Sstevel@tonic-gate #include	<sys/file.h>
320Sstevel@tonic-gate #include	<sys/stream.h>
330Sstevel@tonic-gate #include	<sys/stropts.h>
340Sstevel@tonic-gate #include	<sys/strsubr.h>
350Sstevel@tonic-gate #include	<sys/dlpi.h>
360Sstevel@tonic-gate #include	<sys/vnode.h>
370Sstevel@tonic-gate #include	<sys/socket.h>
380Sstevel@tonic-gate #include	<sys/sockio.h>
390Sstevel@tonic-gate #include	<net/if.h>
400Sstevel@tonic-gate 
410Sstevel@tonic-gate #include	<sys/cred.h>
420Sstevel@tonic-gate #include	<sys/sysmacros.h>
430Sstevel@tonic-gate 
440Sstevel@tonic-gate #include	<sys/sad.h>
450Sstevel@tonic-gate #include	<sys/kstr.h>
460Sstevel@tonic-gate #include	<sys/bootconf.h>
470Sstevel@tonic-gate #include	<sys/bootprops.h>
480Sstevel@tonic-gate 
490Sstevel@tonic-gate #include	<sys/errno.h>
500Sstevel@tonic-gate #include	<sys/modctl.h>
510Sstevel@tonic-gate #include	<sys/sunddi.h>
520Sstevel@tonic-gate #include	<sys/sunldi.h>
530Sstevel@tonic-gate #include	<sys/esunddi.h>
540Sstevel@tonic-gate #include	<sys/promif.h>
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #include	<netinet/in.h>
570Sstevel@tonic-gate #include	<netinet/ip6.h>
580Sstevel@tonic-gate #include	<netinet/icmp6.h>
590Sstevel@tonic-gate #include	<netinet/sctp.h>
600Sstevel@tonic-gate #include	<inet/common.h>
610Sstevel@tonic-gate #include	<inet/ip.h>
620Sstevel@tonic-gate #include	<inet/ip6.h>
630Sstevel@tonic-gate #include	<inet/tcp.h>
640Sstevel@tonic-gate #include	<inet/sctp_ip.h>
658348SEric.Yu@Sun.COM #include	<inet/udp_impl.h>
660Sstevel@tonic-gate 
670Sstevel@tonic-gate #include	<sys/strlog.h>
680Sstevel@tonic-gate #include	<sys/log.h>
690Sstevel@tonic-gate #include	<sys/ethernet.h>
700Sstevel@tonic-gate #include	<sys/ddi_implfuncs.h>
710Sstevel@tonic-gate 
720Sstevel@tonic-gate #include	<sys/dld.h>
738275SEric Cheng #include	<sys/mac_client.h>
740Sstevel@tonic-gate 
750Sstevel@tonic-gate /*
760Sstevel@tonic-gate  * Debug Macros
770Sstevel@tonic-gate  */
780Sstevel@tonic-gate int	strplumbdebug = 0;
790Sstevel@tonic-gate 
808194SJack.Meng@Sun.COM extern ib_boot_prop_t *iscsiboot_prop;
818194SJack.Meng@Sun.COM 
820Sstevel@tonic-gate #define	DBG0(_f) \
830Sstevel@tonic-gate 	if (strplumbdebug != 0) \
840Sstevel@tonic-gate 		printf("strplumb: " _f)
850Sstevel@tonic-gate 
860Sstevel@tonic-gate #define	DBG1(_f, _a) \
870Sstevel@tonic-gate 	if (strplumbdebug != 0) \
880Sstevel@tonic-gate 		printf("strplumb: " _f, (_a))
890Sstevel@tonic-gate 
900Sstevel@tonic-gate #define	DBG2(_f, _a, _b) \
910Sstevel@tonic-gate 	if (strplumbdebug != 0) \
920Sstevel@tonic-gate 		printf("strplumb: " _f, (_a), (_b))
930Sstevel@tonic-gate 
940Sstevel@tonic-gate #define	DBG3(_f, _a, _b, _c) \
950Sstevel@tonic-gate 	if (strplumbdebug != 0) \
960Sstevel@tonic-gate 		printf("strplumb: " _f, (_a), (_b), (_c))
970Sstevel@tonic-gate 
980Sstevel@tonic-gate /*
990Sstevel@tonic-gate  * Module linkage information for the kernel.
1000Sstevel@tonic-gate  */
1015648Ssetje #define	STRPLUMB_IDENT	"STREAMS Plumbing Module"
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate static struct modlmisc modlmisc = {
1040Sstevel@tonic-gate 	&mod_miscops,
1050Sstevel@tonic-gate 	STRPLUMB_IDENT
1060Sstevel@tonic-gate };
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate static struct modlinkage modlinkage = {
1090Sstevel@tonic-gate 	MODREV_1,
1100Sstevel@tonic-gate 	&modlmisc,
1110Sstevel@tonic-gate 	NULL
1120Sstevel@tonic-gate };
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate int
1150Sstevel@tonic-gate _init(void)
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate 	return (mod_install(&modlinkage));
1180Sstevel@tonic-gate }
1190Sstevel@tonic-gate 
1200Sstevel@tonic-gate int
1210Sstevel@tonic-gate _fini(void)
1220Sstevel@tonic-gate {
1230Sstevel@tonic-gate 	return (mod_remove(&modlinkage));
1240Sstevel@tonic-gate }
1250Sstevel@tonic-gate 
1260Sstevel@tonic-gate int
1270Sstevel@tonic-gate _info(struct modinfo *modinfop)
1280Sstevel@tonic-gate {
1290Sstevel@tonic-gate 	return (mod_info(&modlinkage, modinfop));
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate #define	ARP		"arp"
1330Sstevel@tonic-gate #define	TCP		"tcp"
1340Sstevel@tonic-gate #define	TCP6		"tcp6"
1350Sstevel@tonic-gate #define	UDP		"udp"
1360Sstevel@tonic-gate #define	UDP6		"udp6"
1370Sstevel@tonic-gate #define	SCTP		"sctp"
1380Sstevel@tonic-gate #define	SCTP6		"sctp6"
1390Sstevel@tonic-gate #define	ICMP		"icmp"
1400Sstevel@tonic-gate #define	ICMP6		"icmp6"
1410Sstevel@tonic-gate #define	IP		"ip"
1420Sstevel@tonic-gate #define	IP6		"ip6"
1430Sstevel@tonic-gate #define	TIMOD		"timod"
1440Sstevel@tonic-gate 
1450Sstevel@tonic-gate #define	UDPDEV		"/devices/pseudo/udp@0:udp"
1460Sstevel@tonic-gate #define	TCP6DEV		"/devices/pseudo/tcp6@0:tcp6"
1478194SJack.Meng@Sun.COM #define	UDP6DEV		"/devices/pseudo/udp6@0:udp6"
1480Sstevel@tonic-gate #define	SCTP6DEV	"/devices/pseudo/sctp6@0:sctp6"
1490Sstevel@tonic-gate #define	IP6DEV		"/devices/pseudo/ip6@0:ip6"
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate typedef struct strplumb_modspec {
1520Sstevel@tonic-gate 	char	*sm_type;
1530Sstevel@tonic-gate 	char	*sm_name;
1540Sstevel@tonic-gate } strplumb_modspec_t;
1550Sstevel@tonic-gate 
1560Sstevel@tonic-gate static strplumb_modspec_t	strplumb_modlist[] = {
1570Sstevel@tonic-gate 	{ "drv", DLD_DRIVER_NAME },
1580Sstevel@tonic-gate 	{ "drv", IP },
1590Sstevel@tonic-gate 	{ "drv", IP6 },
1600Sstevel@tonic-gate 	{ "drv", TCP },
1610Sstevel@tonic-gate 	{ "drv", TCP6 },
1620Sstevel@tonic-gate 	{ "drv", UDP },
1630Sstevel@tonic-gate 	{ "drv", UDP6 },
1640Sstevel@tonic-gate 	{ "drv", SCTP },
1650Sstevel@tonic-gate 	{ "drv", SCTP6 },
1660Sstevel@tonic-gate 	{ "drv", ICMP },
1670Sstevel@tonic-gate 	{ "drv", ICMP6 },
1680Sstevel@tonic-gate 	{ "drv", ARP },
1690Sstevel@tonic-gate 	{ "strmod", TIMOD }
1700Sstevel@tonic-gate };
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate /*
1730Sstevel@tonic-gate  * Called from swapgeneric.c:loadrootmodules() in the network boot case.
1740Sstevel@tonic-gate  */
1750Sstevel@tonic-gate int
1760Sstevel@tonic-gate strplumb_load(void)
1770Sstevel@tonic-gate {
1780Sstevel@tonic-gate 	uint_t			i;
1790Sstevel@tonic-gate 	strplumb_modspec_t	*p;
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	DBG0("loading modules\n");
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 	for (i = 0, p = strplumb_modlist;
1840Sstevel@tonic-gate 	    i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]);
1850Sstevel@tonic-gate 	    i++, p++) {
1860Sstevel@tonic-gate 		if (modloadonly(p->sm_type, p->sm_name) < 0) {
1870Sstevel@tonic-gate 			printf("strplumb: failed to load %s/%s\n",
1880Sstevel@tonic-gate 			    p->sm_type, p->sm_name);
1890Sstevel@tonic-gate 			return (EFAULT);
1900Sstevel@tonic-gate 		}
1910Sstevel@tonic-gate 	}
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	return (0);
1940Sstevel@tonic-gate }
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate static int
1970Sstevel@tonic-gate strplumb_init(void)
1980Sstevel@tonic-gate {
1990Sstevel@tonic-gate 	uint_t			i;
2000Sstevel@tonic-gate 	strplumb_modspec_t	*p;
2010Sstevel@tonic-gate 	int			err;
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	DBG0("initializing modules\n");
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	for (i = 0, p = strplumb_modlist;
2060Sstevel@tonic-gate 	    i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]);
2070Sstevel@tonic-gate 	    i++, p++) {
2080Sstevel@tonic-gate 		if (strcmp(p->sm_type, "drv") == 0)
2090Sstevel@tonic-gate 			err = (i_ddi_attach_pseudo_node(p->sm_name) != NULL) ?
2100Sstevel@tonic-gate 			    0 : EFAULT;
2110Sstevel@tonic-gate 		else
2120Sstevel@tonic-gate 			err = (modload(p->sm_type, p->sm_name) < 0) ?
2130Sstevel@tonic-gate 			    EFAULT : 0;
2140Sstevel@tonic-gate 
2150Sstevel@tonic-gate 		if (err != 0)  {
2160Sstevel@tonic-gate 			printf("strplumb: failed to initialize %s/%s\n",
2170Sstevel@tonic-gate 			    p->sm_type, p->sm_name);
2180Sstevel@tonic-gate 			return (err);
2190Sstevel@tonic-gate 		}
2200Sstevel@tonic-gate 	}
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	return (0);
2230Sstevel@tonic-gate }
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate static int
2260Sstevel@tonic-gate strplumb_autopush(void)
2270Sstevel@tonic-gate {
2280Sstevel@tonic-gate 	major_t		maj;
2290Sstevel@tonic-gate 	minor_t		min;
2300Sstevel@tonic-gate 	char		*mods[5];
2310Sstevel@tonic-gate 	uint_t		anchor = 1;
2320Sstevel@tonic-gate 	int		err;
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate 	min = (minor_t)-1;
2350Sstevel@tonic-gate 	mods[1] = NULL;
2360Sstevel@tonic-gate 
2370Sstevel@tonic-gate 	/*
2380Sstevel@tonic-gate 	 * ARP
2390Sstevel@tonic-gate 	 */
2400Sstevel@tonic-gate 	DBG0("setting up arp autopush\n");
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 	mods[0] = ARP;
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 	maj = ddi_name_to_major(ARP);
2450Sstevel@tonic-gate 	if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, &anchor,
2460Sstevel@tonic-gate 	    mods)) != 0) {
2470Sstevel@tonic-gate 		printf("strplumb: kstr_autopush(SET/ARP) failed: %d\n", err);
2480Sstevel@tonic-gate 		return (err);
2490Sstevel@tonic-gate 	}
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	return (0);
2520Sstevel@tonic-gate }
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate static int
2550Sstevel@tonic-gate strplumb_sctpq(ldi_ident_t li)
2560Sstevel@tonic-gate {
2570Sstevel@tonic-gate 	ldi_handle_t	lh = NULL;
2580Sstevel@tonic-gate 	int		err;
2590Sstevel@tonic-gate 	int		rval;
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 	DBG0("configuring SCTP default queue\n");
2620Sstevel@tonic-gate 
2630Sstevel@tonic-gate 	if ((err = ldi_open_by_name(SCTP6DEV, FREAD|FWRITE, CRED(), &lh,
2640Sstevel@tonic-gate 	    li)) != 0) {
2650Sstevel@tonic-gate 		printf("strplumb: open of SCTP6DEV failed: %d\n", err);
2660Sstevel@tonic-gate 		return (err);
2670Sstevel@tonic-gate 	}
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	if ((err = ldi_ioctl(lh, SCTP_IOC_DEFAULT_Q, (intptr_t)0, FKIOCTL,
2700Sstevel@tonic-gate 	    CRED(), &rval)) != 0) {
2710Sstevel@tonic-gate 		printf("strplumb: failed to set SCTP default queue: %d\n",
2720Sstevel@tonic-gate 		    err);
2730Sstevel@tonic-gate 		(void) ldi_close(lh, FREAD|FWRITE, CRED());
2740Sstevel@tonic-gate 		return (err);
2750Sstevel@tonic-gate 	}
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate 	return (0);
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate static int
2810Sstevel@tonic-gate strplumb_tcpq(ldi_ident_t li)
2820Sstevel@tonic-gate {
2830Sstevel@tonic-gate 	ldi_handle_t	lh = NULL;
2840Sstevel@tonic-gate 	ldi_handle_t	ip_lh = NULL;
2850Sstevel@tonic-gate 	int		err;
2860Sstevel@tonic-gate 	int		rval;
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 	DBG0("configuring TCP default queue\n");
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	/*
2910Sstevel@tonic-gate 	 * We open IP6DEV here because we need to have it open to in
2920Sstevel@tonic-gate 	 * order to open TCP6DEV successfully.
2930Sstevel@tonic-gate 	 */
2940Sstevel@tonic-gate 	if ((err = ldi_open_by_name(IP6DEV, FREAD|FWRITE, CRED(), &ip_lh,
2950Sstevel@tonic-gate 	    li)) != 0) {
2960Sstevel@tonic-gate 		printf("strplumb: open of IP6DEV failed: %d\n", err);
2970Sstevel@tonic-gate 		return (err);
2980Sstevel@tonic-gate 	}
2990Sstevel@tonic-gate 
3000Sstevel@tonic-gate 	/*
3010Sstevel@tonic-gate 	 * We set the tcp default queue to IPv6 because IPv4 falls back to
3020Sstevel@tonic-gate 	 * IPv6 when it can't find a client, but IPv6 does not fall back to
3030Sstevel@tonic-gate 	 * IPv4.
3040Sstevel@tonic-gate 	 */
3050Sstevel@tonic-gate 	if ((err = ldi_open_by_name(TCP6DEV, FREAD|FWRITE, CRED(), &lh,
3060Sstevel@tonic-gate 	    li)) != 0) {
3070Sstevel@tonic-gate 		printf("strplumb: open of TCP6DEV failed: %d\n", err);
3080Sstevel@tonic-gate 		goto done;
3090Sstevel@tonic-gate 	}
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 	if ((err = ldi_ioctl(lh, TCP_IOC_DEFAULT_Q, (intptr_t)0, FKIOCTL,
3120Sstevel@tonic-gate 	    CRED(), &rval)) != 0) {
3130Sstevel@tonic-gate 		printf("strplumb: failed to set TCP default queue: %d\n",
3140Sstevel@tonic-gate 		    err);
3150Sstevel@tonic-gate 		goto done;
3160Sstevel@tonic-gate 	}
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate done:
3190Sstevel@tonic-gate 	(void) ldi_close(ip_lh, FREAD|FWRITE, CRED());
3200Sstevel@tonic-gate 	return (err);
3210Sstevel@tonic-gate }
3220Sstevel@tonic-gate 
3230Sstevel@tonic-gate /*
3240Sstevel@tonic-gate  * Can be set in /etc/system in the case of local booting. See comment below.
3250Sstevel@tonic-gate  */
3260Sstevel@tonic-gate char	*ndev_name = 0;
3270Sstevel@tonic-gate int	ndev_unit = 0;
3280Sstevel@tonic-gate 
3290Sstevel@tonic-gate /*
3300Sstevel@tonic-gate  * If we booted diskless then strplumb() will have been called from
3310Sstevel@tonic-gate  * swapgeneric.c:rootconf(). All we can do in that case is plumb the
3320Sstevel@tonic-gate  * network device that we booted from.
3330Sstevel@tonic-gate  *
3340Sstevel@tonic-gate  * If we booted from a local disk, we will have been called from main(),
3350Sstevel@tonic-gate  * and normally we defer the plumbing of interfaces until network/physical.
3360Sstevel@tonic-gate  * This can be overridden by setting "ndev_name" in /etc/system.
3370Sstevel@tonic-gate  */
3380Sstevel@tonic-gate static int
339269Sericheng resolve_boot_path(void)
3400Sstevel@tonic-gate {
3415710Ssetje 	char			*devpath;
3420Sstevel@tonic-gate 	dev_info_t		*dip;
3430Sstevel@tonic-gate 	const char		*driver;
3440Sstevel@tonic-gate 	int			instance;
3455648Ssetje #ifdef	_OBP
3465648Ssetje 	char			stripped_path[OBP_MAXPATHLEN];
3475648Ssetje #endif
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	if (strncmp(rootfs.bo_fstype, "nfs", 3) == 0)
3500Sstevel@tonic-gate 		devpath = rootfs.bo_name;
3510Sstevel@tonic-gate 	else
3520Sstevel@tonic-gate 		devpath = strplumb_get_netdev_path();
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate 	if (devpath != NULL) {
3550Sstevel@tonic-gate 		DBG1("resolving boot-path: %s\n", devpath);
3565710Ssetje #ifdef _OBP
3575710Ssetje 		/*
3585710Ssetje 		 * OBP passes options e.g, "net:dhcp"
3595710Ssetje 		 * remove them here
3605710Ssetje 		 */
3615710Ssetje 		prom_strip_options(devpath, stripped_path);
3625710Ssetje 		devpath = stripped_path;
3635710Ssetje #endif
3640Sstevel@tonic-gate 		/*
3650Sstevel@tonic-gate 		 * Hold the devi since this is the root device.
3660Sstevel@tonic-gate 		 */
3670Sstevel@tonic-gate 		if ((dip = e_ddi_hold_devi_by_path(devpath, 0)) == NULL) {
3680Sstevel@tonic-gate 			printf("strplumb: unable to hold root device: %s\n",
3690Sstevel@tonic-gate 			    devpath);
3700Sstevel@tonic-gate 			return (ENXIO);
3710Sstevel@tonic-gate 		}
3720Sstevel@tonic-gate 
3730Sstevel@tonic-gate 		driver = ddi_driver_name(dip);
3740Sstevel@tonic-gate 		instance = ddi_get_instance(dip);
3750Sstevel@tonic-gate 	} else {
3760Sstevel@tonic-gate 		if (ndev_name == NULL)
3770Sstevel@tonic-gate 			return (ENODEV);
3780Sstevel@tonic-gate 
3790Sstevel@tonic-gate 		DBG2("using ndev_name (%s) ndev_unit (%d)\n", ndev_name,
3800Sstevel@tonic-gate 		    ndev_unit);
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 		if (i_ddi_attach_hw_nodes(ndev_name) != DDI_SUCCESS) {
3830Sstevel@tonic-gate 			printf("strplumb: cannot load ndev_name '%s'\n",
3840Sstevel@tonic-gate 			    ndev_name);
3850Sstevel@tonic-gate 			return (ENXIO);
3860Sstevel@tonic-gate 		}
3870Sstevel@tonic-gate 
3880Sstevel@tonic-gate 		driver = ndev_name;
3890Sstevel@tonic-gate 		instance = ndev_unit;
3900Sstevel@tonic-gate 	}
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate 	(void) snprintf(rootfs.bo_devname, BO_MAXOBJNAME,
393269Sericheng 	    "/devices/pseudo/clone@0:%s", driver);
3940Sstevel@tonic-gate 	(void) snprintf(rootfs.bo_ifname, BO_MAXOBJNAME, "%s%d",
3950Sstevel@tonic-gate 	    driver, instance);
3960Sstevel@tonic-gate 	rootfs.bo_ppa = instance;
397269Sericheng 	return (0);
3980Sstevel@tonic-gate }
3990Sstevel@tonic-gate 
4000Sstevel@tonic-gate static int
4010Sstevel@tonic-gate getifflags(ldi_handle_t lh, struct lifreq *lifrp)
4020Sstevel@tonic-gate {
4030Sstevel@tonic-gate 	struct strioctl	iocb;
4040Sstevel@tonic-gate 	int		rval;
4050Sstevel@tonic-gate 
4060Sstevel@tonic-gate 	iocb.ic_cmd = SIOCGLIFFLAGS;
4070Sstevel@tonic-gate 	iocb.ic_timout = 15;
4080Sstevel@tonic-gate 	iocb.ic_len = sizeof (struct lifreq);
4090Sstevel@tonic-gate 	iocb.ic_dp = (char *)lifrp;
4100Sstevel@tonic-gate 
4110Sstevel@tonic-gate 	return (ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), &rval));
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate }
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate static int
4160Sstevel@tonic-gate setifname(ldi_handle_t lh, struct lifreq *lifrp)
4170Sstevel@tonic-gate {
4180Sstevel@tonic-gate 	struct strioctl	iocb;
4190Sstevel@tonic-gate 	int		rval;
4200Sstevel@tonic-gate 
4210Sstevel@tonic-gate 	iocb.ic_cmd = SIOCSLIFNAME;
4220Sstevel@tonic-gate 	iocb.ic_timout = 15;
4230Sstevel@tonic-gate 	iocb.ic_len = sizeof (struct lifreq);
4240Sstevel@tonic-gate 	iocb.ic_dp = (char *)lifrp;
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate 	return (ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), &rval));
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate 
4290Sstevel@tonic-gate static int
4300Sstevel@tonic-gate strplumb_dev(ldi_ident_t li)
4310Sstevel@tonic-gate {
4320Sstevel@tonic-gate 	ldi_handle_t	lh = NULL;
4330Sstevel@tonic-gate 	ldi_handle_t	mux_lh = NULL;
4340Sstevel@tonic-gate 	int		err;
4350Sstevel@tonic-gate 	struct lifreq	lifr;
4360Sstevel@tonic-gate 	struct ifreq	ifr;
4370Sstevel@tonic-gate 	int		rval;
4388194SJack.Meng@Sun.COM 	int		af = 0;
4398194SJack.Meng@Sun.COM 	char		*name = NULL;
4400Sstevel@tonic-gate 
4410Sstevel@tonic-gate 	bzero(&lifr, sizeof (struct lifreq));
4420Sstevel@tonic-gate 	bzero(&ifr, sizeof (ifr));
4430Sstevel@tonic-gate 
4448194SJack.Meng@Sun.COM 	if (iscsiboot_prop != NULL) {
4458194SJack.Meng@Sun.COM 		af = iscsiboot_prop->boot_nic.sin_family;
4468194SJack.Meng@Sun.COM 	}
4478194SJack.Meng@Sun.COM 
4480Sstevel@tonic-gate 	/*
4490Sstevel@tonic-gate 	 * Now set up the links. Ultimately, we should have two streams
4500Sstevel@tonic-gate 	 * permanently linked underneath UDP (which is actually IP with UDP
4510Sstevel@tonic-gate 	 * autopushed). One stream consists of the ARP-[ifname] combination,
4520Sstevel@tonic-gate 	 * while the other consists of ARP-IP-[ifname]. The second combination
4530Sstevel@tonic-gate 	 * seems a little weird, but is linked underneath UDP just to keep it
4540Sstevel@tonic-gate 	 * around.
4550Sstevel@tonic-gate 	 *
4560Sstevel@tonic-gate 	 * We pin underneath UDP here to match what is done in ifconfig(1m);
4570Sstevel@tonic-gate 	 * otherwise, ifconfig will be unable to unplumb the stream (the major
4580Sstevel@tonic-gate 	 * number and mux id must both match for a successful I_PUNLINK).
4590Sstevel@tonic-gate 	 *
4600Sstevel@tonic-gate 	 * There are subtleties in the plumbing which make it essential to
4610Sstevel@tonic-gate 	 * follow the logic used in ifconfig(1m) very closely.
4620Sstevel@tonic-gate 	 */
4630Sstevel@tonic-gate 
4640Sstevel@tonic-gate 	/*
4650Sstevel@tonic-gate 	 * Plumb UDP-ARP-IP-<dev>
4660Sstevel@tonic-gate 	 */
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 	if ((err = ldi_open_by_name(rootfs.bo_devname, FREAD|FWRITE, CRED(),
4690Sstevel@tonic-gate 	    &lh, li)) != 0) {
4700Sstevel@tonic-gate 		printf("strplumb: open %s failed: %d\n", rootfs.bo_devname,
4710Sstevel@tonic-gate 		    err);
4720Sstevel@tonic-gate 		goto done;
4730Sstevel@tonic-gate 	}
4740Sstevel@tonic-gate 
4750Sstevel@tonic-gate 
4760Sstevel@tonic-gate 	if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)IP, FKIOCTL, CRED(),
4770Sstevel@tonic-gate 	    &rval)) != 0) {
4780Sstevel@tonic-gate 		printf("strplumb: push IP failed: %d\n", err);
4790Sstevel@tonic-gate 		goto done;
4800Sstevel@tonic-gate 	}
4810Sstevel@tonic-gate 
4820Sstevel@tonic-gate 	if ((err = getifflags(lh, &lifr)) != 0)
4830Sstevel@tonic-gate 		goto done;
4840Sstevel@tonic-gate 
4858194SJack.Meng@Sun.COM 	if (af == 0 || af == AF_INET) {
4868194SJack.Meng@Sun.COM 		lifr.lifr_flags |= IFF_IPV4;
4878194SJack.Meng@Sun.COM 		lifr.lifr_flags &= ~IFF_IPV6;
4888194SJack.Meng@Sun.COM 		name = UDPDEV;
4898194SJack.Meng@Sun.COM 	} else {
4908194SJack.Meng@Sun.COM 		/*
4918194SJack.Meng@Sun.COM 		 * iscsi boot is used with ipv6 enabled
4928194SJack.Meng@Sun.COM 		 */
4938194SJack.Meng@Sun.COM 		lifr.lifr_flags |= IFF_IPV6;
4948194SJack.Meng@Sun.COM 		lifr.lifr_flags &= ~IFF_IPV4;
4958194SJack.Meng@Sun.COM 		name = UDP6DEV;
4968194SJack.Meng@Sun.COM 	}
4970Sstevel@tonic-gate 	if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)ARP, FKIOCTL, CRED(),
4980Sstevel@tonic-gate 	    &rval)) != 0) {
4990Sstevel@tonic-gate 		printf("strplumb: push ARP failed: %d\n", err);
5000Sstevel@tonic-gate 		goto done;
5010Sstevel@tonic-gate 	}
5020Sstevel@tonic-gate 
5030Sstevel@tonic-gate 	(void) strlcpy(lifr.lifr_name, rootfs.bo_ifname,
5040Sstevel@tonic-gate 	    sizeof (lifr.lifr_name));
5050Sstevel@tonic-gate 	lifr.lifr_ppa = rootfs.bo_ppa;
5060Sstevel@tonic-gate 
5070Sstevel@tonic-gate 	if ((err = setifname(lh, &lifr)) != 0)
5080Sstevel@tonic-gate 		goto done;
5090Sstevel@tonic-gate 
5100Sstevel@tonic-gate 	/* Get the flags and check if ARP is needed */
5110Sstevel@tonic-gate 	if ((err = getifflags(lh, &lifr)) != 0) {
5120Sstevel@tonic-gate 		printf("strplumb: getifflags %s IP failed, error %d\n",
5130Sstevel@tonic-gate 		    lifr.lifr_name, err);
5140Sstevel@tonic-gate 		goto done;
5150Sstevel@tonic-gate 	}
5160Sstevel@tonic-gate 
5170Sstevel@tonic-gate 	/* Pop out ARP if not needed */
5188194SJack.Meng@Sun.COM 	if (lifr.lifr_flags & (IFF_NOARP | IFF_IPV6)) {
5190Sstevel@tonic-gate 		err = ldi_ioctl(lh, I_POP, (intptr_t)0, FKIOCTL, CRED(),
5200Sstevel@tonic-gate 		    &rval);
5210Sstevel@tonic-gate 		if (err != 0) {
5220Sstevel@tonic-gate 			printf("strplumb: pop ARP failed, error %d\n", err);
5230Sstevel@tonic-gate 			goto done;
5240Sstevel@tonic-gate 		}
5250Sstevel@tonic-gate 	}
5260Sstevel@tonic-gate 
5278194SJack.Meng@Sun.COM 	if ((err = ldi_open_by_name(name, FREAD|FWRITE, CRED(), &mux_lh,
5280Sstevel@tonic-gate 	    li)) != 0) {
5298194SJack.Meng@Sun.COM 		printf("strplumb: open of %s failed: %d\n", name, err);
5300Sstevel@tonic-gate 		goto done;
5310Sstevel@tonic-gate 	}
5320Sstevel@tonic-gate 
5330Sstevel@tonic-gate 	if ((err = ldi_ioctl(mux_lh, I_PLINK, (intptr_t)lh,
5340Sstevel@tonic-gate 	    FREAD|FWRITE|FNOCTTY|FKIOCTL, CRED(),
5350Sstevel@tonic-gate 	    &(ifr.ifr_ip_muxid))) != 0) {
5360Sstevel@tonic-gate 		printf("strplumb: plink UDP-ARP-IP-%s failed: %d\n",
5370Sstevel@tonic-gate 		    rootfs.bo_ifname, err);
5380Sstevel@tonic-gate 		goto done;
5390Sstevel@tonic-gate 	}
5400Sstevel@tonic-gate 
5418194SJack.Meng@Sun.COM 	if (af == AF_INET6) {
5428194SJack.Meng@Sun.COM 		goto done;
5438194SJack.Meng@Sun.COM 	}
5448194SJack.Meng@Sun.COM 
5450Sstevel@tonic-gate 	DBG2("UDP-ARP-IP-%s muxid: %d\n", rootfs.bo_ifname, ifr.ifr_ip_muxid);
5460Sstevel@tonic-gate 
5470Sstevel@tonic-gate 	(void) ldi_close(lh, FREAD|FWRITE, CRED());
5480Sstevel@tonic-gate 	lh = NULL;
5490Sstevel@tonic-gate 
5500Sstevel@tonic-gate 	/*
5510Sstevel@tonic-gate 	 * Plumb UDP-ARP-<dev>
5520Sstevel@tonic-gate 	 */
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate 	if ((err = ldi_open_by_name(rootfs.bo_devname, FREAD|FWRITE, CRED(),
5550Sstevel@tonic-gate 	    &lh, li)) != 0) {
5560Sstevel@tonic-gate 		printf("strplumb: open %s failed: %d\n", rootfs.bo_devname,
5570Sstevel@tonic-gate 		    err);
5580Sstevel@tonic-gate 		goto done;
5590Sstevel@tonic-gate 	}
5600Sstevel@tonic-gate 
5610Sstevel@tonic-gate 	if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)ARP, FKIOCTL, CRED(),
5620Sstevel@tonic-gate 	    &rval)) != 0) {
5630Sstevel@tonic-gate 		printf("strplumb: push ARP failed: %d\n", err);
5640Sstevel@tonic-gate 		goto done;
5650Sstevel@tonic-gate 	}
5660Sstevel@tonic-gate 
5670Sstevel@tonic-gate 	if ((err = setifname(lh, &lifr)) != 0)
5680Sstevel@tonic-gate 		goto done;
5690Sstevel@tonic-gate 
5700Sstevel@tonic-gate 	if ((err = ldi_ioctl(mux_lh, I_PLINK, (intptr_t)lh,
5710Sstevel@tonic-gate 	    FREAD|FWRITE|FNOCTTY|FKIOCTL, CRED(),
5720Sstevel@tonic-gate 	    &(ifr.ifr_arp_muxid))) != 0) {
5730Sstevel@tonic-gate 		printf("strplumb: plink UDP-ARP-%s failed: %d\n",
5740Sstevel@tonic-gate 		    rootfs.bo_ifname, err);
5750Sstevel@tonic-gate 		goto done;
5760Sstevel@tonic-gate 	}
5770Sstevel@tonic-gate 
5780Sstevel@tonic-gate 	DBG2("UDP-ARP-%s muxid: %d\n", rootfs.bo_ifname, ifr.ifr_arp_muxid);
5790Sstevel@tonic-gate 
5800Sstevel@tonic-gate 	/*
5810Sstevel@tonic-gate 	 * Cache the mux ids.
5820Sstevel@tonic-gate 	 */
5830Sstevel@tonic-gate 	(void) strlcpy(ifr.ifr_name, rootfs.bo_ifname, sizeof (ifr.ifr_name));
5840Sstevel@tonic-gate 
5850Sstevel@tonic-gate 	if ((err = ldi_ioctl(mux_lh, SIOCSIFMUXID, (intptr_t)&ifr, FKIOCTL,
5860Sstevel@tonic-gate 	    CRED(), &rval)) != 0) {
5870Sstevel@tonic-gate 		printf("strplumb: SIOCSIFMUXID failed: %d\n", err);
5880Sstevel@tonic-gate 		goto done;
5890Sstevel@tonic-gate 	}
5900Sstevel@tonic-gate 
5910Sstevel@tonic-gate done:
5920Sstevel@tonic-gate 	if (lh != NULL)
5930Sstevel@tonic-gate 		(void) ldi_close(lh, FREAD|FWRITE, CRED());
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate 	if (mux_lh != NULL)
5960Sstevel@tonic-gate 		(void) ldi_close(mux_lh, FREAD|FWRITE, CRED());
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate 	return (err);
5990Sstevel@tonic-gate }
6000Sstevel@tonic-gate 
6010Sstevel@tonic-gate /*
6020Sstevel@tonic-gate  * Do streams plumbing for internet protocols.
6030Sstevel@tonic-gate  */
6040Sstevel@tonic-gate int
6050Sstevel@tonic-gate strplumb(void)
6060Sstevel@tonic-gate {
6070Sstevel@tonic-gate 	ldi_ident_t	li;
6080Sstevel@tonic-gate 	int		err;
6090Sstevel@tonic-gate 
6100Sstevel@tonic-gate 	if ((err = strplumb_init()) != 0)
6110Sstevel@tonic-gate 		return (err);
6120Sstevel@tonic-gate 
6130Sstevel@tonic-gate 	if ((err = strplumb_autopush()) != 0)
6140Sstevel@tonic-gate 		return (err);
6150Sstevel@tonic-gate 
6160Sstevel@tonic-gate 	if ((err = ldi_ident_from_mod(&modlinkage, &li)) != 0)
6170Sstevel@tonic-gate 		return (err);
6180Sstevel@tonic-gate 
6193448Sdh155122 	/*
6203448Sdh155122 	 * Setup the TCP and SCTP default queues for the global stack.
6213448Sdh155122 	 * tcp/sctp_stack_init will do this for additional stack instances.
6223448Sdh155122 	 */
6230Sstevel@tonic-gate 	if ((err = strplumb_sctpq(li)) != 0)
6240Sstevel@tonic-gate 		goto done;
6250Sstevel@tonic-gate 
6260Sstevel@tonic-gate 	if ((err = strplumb_tcpq(li)) != 0)
6270Sstevel@tonic-gate 		goto done;
6280Sstevel@tonic-gate 
629269Sericheng 	if ((err = resolve_boot_path()) != 0)
6300Sstevel@tonic-gate 		goto done;
6310Sstevel@tonic-gate 
6320Sstevel@tonic-gate 	DBG1("rootfs.bo_devname: %s\n", rootfs.bo_devname);
6330Sstevel@tonic-gate 	DBG1("rootfs.bo_ifname: %s\n", rootfs.bo_ifname);
6340Sstevel@tonic-gate 	DBG1("rootfs.bo_ppa: %d\n", rootfs.bo_ppa);
6350Sstevel@tonic-gate 
6360Sstevel@tonic-gate 	if ((err = strplumb_dev(li)) != 0)
6370Sstevel@tonic-gate 		goto done;
6380Sstevel@tonic-gate 
6390Sstevel@tonic-gate done:
6400Sstevel@tonic-gate 	ldi_ident_release(li);
6410Sstevel@tonic-gate 
6420Sstevel@tonic-gate 	return (err);
6430Sstevel@tonic-gate }
6440Sstevel@tonic-gate 
6450Sstevel@tonic-gate /* multiboot:  diskless boot interface discovery */
6460Sstevel@tonic-gate 
6475648Ssetje #ifndef	_OBP
6480Sstevel@tonic-gate 
6490Sstevel@tonic-gate static uchar_t boot_macaddr[16];
6500Sstevel@tonic-gate static int boot_maclen;
6515895Syz147064 static uchar_t *getmacaddr(dev_info_t *dip, size_t *maclenp);
6520Sstevel@tonic-gate static int matchmac(dev_info_t *dip, void *arg);
6530Sstevel@tonic-gate 
6545648Ssetje #endif  /* !_OBP */
6554172Ssetje 
6560Sstevel@tonic-gate char *
6570Sstevel@tonic-gate strplumb_get_netdev_path(void)
6580Sstevel@tonic-gate {
6595710Ssetje #ifdef	_OBP
660*10822SJack.Meng@Sun.COM 	char		fstype[OBP_MAXPROPNAME];
661*10822SJack.Meng@Sun.COM 	static char	iscsi_network_path[BO_MAXOBJNAME]	= {0};
662*10822SJack.Meng@Sun.COM 	int		proplen;
663*10822SJack.Meng@Sun.COM 	char		*p	= NULL;
6645710Ssetje 
6655710Ssetje 	if (bop_getprop("fstype", fstype) == -1)
6665710Ssetje 		return (NULL);
6675710Ssetje 
6685710Ssetje 	if (strncmp(fstype, "nfs", 3) == 0)
6695710Ssetje 		return (prom_bootpath());
670*10822SJack.Meng@Sun.COM 	else if (iscsiboot_prop != NULL) {
671*10822SJack.Meng@Sun.COM 		proplen =  BOP_GETPROPLEN(bootops,
672*10822SJack.Meng@Sun.COM 		    BP_ISCSI_NETWORK_BOOTPATH);
673*10822SJack.Meng@Sun.COM 		if (proplen > 0) {
674*10822SJack.Meng@Sun.COM 			if (BOP_GETPROP(bootops,
675*10822SJack.Meng@Sun.COM 			    BP_ISCSI_NETWORK_BOOTPATH,
676*10822SJack.Meng@Sun.COM 			    iscsi_network_path) > 0) {
677*10822SJack.Meng@Sun.COM 				p = strchr(iscsi_network_path, ':');
678*10822SJack.Meng@Sun.COM 				if (p != NULL) {
679*10822SJack.Meng@Sun.COM 					*p = '\0';
680*10822SJack.Meng@Sun.COM 				}
681*10822SJack.Meng@Sun.COM 				return (iscsi_network_path);
682*10822SJack.Meng@Sun.COM 			}
683*10822SJack.Meng@Sun.COM 		}
684*10822SJack.Meng@Sun.COM 	}
685*10822SJack.Meng@Sun.COM 	return (NULL);
6865710Ssetje #else
6875710Ssetje 
6880Sstevel@tonic-gate 	char *macstr, *devpath = NULL;
6890Sstevel@tonic-gate 	uchar_t *bootp;
6905648Ssetje 	uint_t bootp_len;
6910Sstevel@tonic-gate 
6920Sstevel@tonic-gate 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
6930Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, BP_BOOT_MAC, &macstr) == DDI_SUCCESS) {
6940Sstevel@tonic-gate 		/*
6950Sstevel@tonic-gate 		 * hard coded ether mac len for booting floppy on
6960Sstevel@tonic-gate 		 * machines with old cards
6970Sstevel@tonic-gate 		 */
6980Sstevel@tonic-gate 		boot_maclen = ether_aton(macstr, boot_macaddr);
6990Sstevel@tonic-gate 		if (boot_maclen != 6) {
7000Sstevel@tonic-gate 			cmn_err(CE_WARN,
7010Sstevel@tonic-gate 			    "malformed boot_mac property, %d bytes",
7020Sstevel@tonic-gate 			    boot_maclen);
7030Sstevel@tonic-gate 		}
7040Sstevel@tonic-gate 		ddi_prop_free(macstr);
7050Sstevel@tonic-gate 	} else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ddi_root_node(),
7060Sstevel@tonic-gate 	    DDI_PROP_DONTPASS, BP_BOOTP_RESPONSE, &bootp, &bootp_len)
7070Sstevel@tonic-gate 	    == DDI_SUCCESS) {
7080Sstevel@tonic-gate 
7090Sstevel@tonic-gate 		/*
7100Sstevel@tonic-gate 		 * These offsets are defined by dhcp standard
7110Sstevel@tonic-gate 		 * Should use structure offsets
7120Sstevel@tonic-gate 		 */
7130Sstevel@tonic-gate 		boot_maclen = *(bootp + 2);
7140Sstevel@tonic-gate 		ASSERT(boot_maclen <= 16);
7155648Ssetje 		bcopy(bootp + 28, boot_macaddr, boot_maclen);
7160Sstevel@tonic-gate 
7175648Ssetje 		dhcack = kmem_alloc(bootp_len, KM_SLEEP);
7185648Ssetje 		bcopy(bootp, dhcack, bootp_len);
7195648Ssetje 		dhcacklen = bootp_len;
7205648Ssetje 
7210Sstevel@tonic-gate 		ddi_prop_free(bootp);
7228194SJack.Meng@Sun.COM 	} else  if (iscsiboot_prop != NULL) {
7238194SJack.Meng@Sun.COM 		bcopy(iscsiboot_prop->boot_nic.nic_mac,
7248194SJack.Meng@Sun.COM 		    boot_macaddr, IB_BOOT_MACLEN);
7258194SJack.Meng@Sun.COM 		boot_maclen = IB_BOOT_MACLEN;
7268194SJack.Meng@Sun.COM 	} else {
7270Sstevel@tonic-gate 		return (NULL);
7288194SJack.Meng@Sun.COM 	}
7290Sstevel@tonic-gate 
7300Sstevel@tonic-gate 	ddi_walk_devs(ddi_root_node(), matchmac, (void *)&devpath);
7310Sstevel@tonic-gate 	return (devpath);
7324172Ssetje 
7335710Ssetje #endif  /* _OBP */
7340Sstevel@tonic-gate }
7350Sstevel@tonic-gate 
7365648Ssetje #ifndef _OBP
7374172Ssetje 
7380Sstevel@tonic-gate /*
7390Sstevel@tonic-gate  * Get boot path from the boot_mac address
7400Sstevel@tonic-gate  */
7410Sstevel@tonic-gate /*ARGSUSED*/
7420Sstevel@tonic-gate static int
7430Sstevel@tonic-gate matchmac(dev_info_t *dip, void *arg)
7440Sstevel@tonic-gate {
7450Sstevel@tonic-gate 	char **devpathp = (char **)arg;
7460Sstevel@tonic-gate 	char *model_str;
7470Sstevel@tonic-gate 	uchar_t *macaddr;
7485895Syz147064 	size_t maclen;
7490Sstevel@tonic-gate 
7500Sstevel@tonic-gate 	/* XXX Should use "device-type" per IEEE 1275 */
7510Sstevel@tonic-gate 	if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0,
7520Sstevel@tonic-gate 	    "model", &model_str) != DDI_SUCCESS)
7530Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
7540Sstevel@tonic-gate 
7550Sstevel@tonic-gate 	if (strcmp(model_str, "Ethernet controller") != 0) {
7560Sstevel@tonic-gate 		ddi_prop_free(model_str);
7570Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
7580Sstevel@tonic-gate 	}
7590Sstevel@tonic-gate 	ddi_prop_free(model_str);
7600Sstevel@tonic-gate 
7610Sstevel@tonic-gate 	/* We have a network device now */
7620Sstevel@tonic-gate 	if (i_ddi_attach_node_hierarchy(dip) != DDI_SUCCESS) {
7630Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
7640Sstevel@tonic-gate 	}
7650Sstevel@tonic-gate 
7660Sstevel@tonic-gate 	ASSERT(boot_maclen != 0);
7670Sstevel@tonic-gate 	macaddr = getmacaddr(dip, &maclen);
7680Sstevel@tonic-gate 	if (macaddr == NULL)
7690Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
7700Sstevel@tonic-gate 
7710Sstevel@tonic-gate 	if (maclen != boot_maclen ||
7720Sstevel@tonic-gate 	    bcmp(macaddr, boot_macaddr, maclen) != 0) {
7730Sstevel@tonic-gate 		kmem_free(macaddr, maclen);
7740Sstevel@tonic-gate 		return (DDI_WALK_CONTINUE);
7750Sstevel@tonic-gate 	}
7760Sstevel@tonic-gate 
7770Sstevel@tonic-gate 	/* found hardware with the mac address */
7780Sstevel@tonic-gate 	(void) localetheraddr((struct ether_addr *)macaddr, NULL);
7790Sstevel@tonic-gate 	kmem_free(macaddr, maclen);
7800Sstevel@tonic-gate 
7810Sstevel@tonic-gate 	*devpathp = kmem_alloc(MAXPATHLEN, KM_SLEEP);
7820Sstevel@tonic-gate 	(void) ddi_pathname(dip, *devpathp);
7830Sstevel@tonic-gate 
7845648Ssetje 	/* fill in dhcifname */
7855648Ssetje 	if (dhcack) {
7865648Ssetje 		(void) snprintf(dhcifname, IFNAMSIZ, "%s%d",
7870Sstevel@tonic-gate 		    ddi_driver_name(dip), i_ddi_devi_get_ppa(dip));
7885648Ssetje 	}
7890Sstevel@tonic-gate 	return (DDI_WALK_TERMINATE);
7900Sstevel@tonic-gate }
7910Sstevel@tonic-gate 
7920Sstevel@tonic-gate static uchar_t *
7935895Syz147064 getmacaddr(dev_info_t *dip, size_t *maclenp)
7940Sstevel@tonic-gate {
7950Sstevel@tonic-gate 	int rc, ppa;
7960Sstevel@tonic-gate 	ldi_ident_t li;
7970Sstevel@tonic-gate 	ldi_handle_t lh;
7985895Syz147064 	const char *drv_name = ddi_driver_name(dip);
7990Sstevel@tonic-gate 	char *clonepath;
8000Sstevel@tonic-gate 	uchar_t *macaddr = NULL;
8010Sstevel@tonic-gate 
8020Sstevel@tonic-gate 	if (rc = ldi_ident_from_mod(&modlinkage, &li)) {
8030Sstevel@tonic-gate 		cmn_err(CE_WARN,
8040Sstevel@tonic-gate 		    "getmacaddr: ldi_ident_from_mod failed: %d\n", rc);
8050Sstevel@tonic-gate 		return (NULL);
8060Sstevel@tonic-gate 	}
8070Sstevel@tonic-gate 
8080Sstevel@tonic-gate 	clonepath = kmem_alloc(MAXPATHLEN, KM_SLEEP);
8090Sstevel@tonic-gate 	(void) snprintf(clonepath, MAXPATHLEN,
8100Sstevel@tonic-gate 	    "/devices/pseudo/clone@0:%s", drv_name);
8110Sstevel@tonic-gate 
8120Sstevel@tonic-gate 	rc = ldi_open_by_name(clonepath, FREAD|FWRITE, CRED(), &lh, li);
8130Sstevel@tonic-gate 	ldi_ident_release(li);
8140Sstevel@tonic-gate 	if (rc) {
8150Sstevel@tonic-gate 		cmn_err(CE_WARN,
8160Sstevel@tonic-gate 		    "getmacaddr: ldi_open_by_name(%s) failed: %d\n",
8170Sstevel@tonic-gate 		    clonepath, rc);
8180Sstevel@tonic-gate 		kmem_free(clonepath, MAXPATHLEN);
8190Sstevel@tonic-gate 		return (NULL);
8200Sstevel@tonic-gate 	}
8210Sstevel@tonic-gate 	kmem_free(clonepath, MAXPATHLEN);
8220Sstevel@tonic-gate 
8230Sstevel@tonic-gate 	ppa = i_ddi_devi_get_ppa(dip);
8245895Syz147064 	if ((dl_attach(lh, ppa, NULL) != 0) ||
8255895Syz147064 	    (dl_bind(lh, ETHERTYPE_IP, NULL) != 0)) {
8260Sstevel@tonic-gate 		(void) ldi_close(lh, FREAD|FWRITE, CRED());
8270Sstevel@tonic-gate 		cmn_err(CE_WARN,
8280Sstevel@tonic-gate 		    "getmacaddr: dl_attach/bind(%s%d) failed: %d\n",
8290Sstevel@tonic-gate 		    drv_name, ppa, rc);
8300Sstevel@tonic-gate 		return (NULL);
8310Sstevel@tonic-gate 	}
8325895Syz147064 
8335895Syz147064 	*maclenp = ETHERADDRL;
8345895Syz147064 	macaddr = kmem_alloc(ETHERADDRL, KM_SLEEP);
8355895Syz147064 	if (dl_phys_addr(lh, macaddr, maclenp, NULL) != 0 ||
8365895Syz147064 	    *maclenp != ETHERADDRL) {
8375895Syz147064 		kmem_free(macaddr, ETHERADDRL);
8380Sstevel@tonic-gate 		macaddr = NULL;
8390Sstevel@tonic-gate 		*maclenp = 0;
8400Sstevel@tonic-gate 		cmn_err(CE_WARN,
8415895Syz147064 		    "getmacaddr: dl_phys_addr(%s%d) failed: %d\n",
8420Sstevel@tonic-gate 		    drv_name, ppa, rc);
8430Sstevel@tonic-gate 	}
8440Sstevel@tonic-gate 	(void) ldi_close(lh, FREAD|FWRITE, CRED());
8450Sstevel@tonic-gate 	return (macaddr);
8460Sstevel@tonic-gate }
8475648Ssetje #endif	/* !_OBP */
848