17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/param.h> 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include <sys/user.h> 327c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 337c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 347c478bd9Sstevel@tonic-gate #include <sys/file.h> 357c478bd9Sstevel@tonic-gate #include <sys/stream.h> 367c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 377c478bd9Sstevel@tonic-gate #include <sys/strsubr.h> 387c478bd9Sstevel@tonic-gate #include <sys/dlpi.h> 397c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 407c478bd9Sstevel@tonic-gate #include <sys/socket.h> 417c478bd9Sstevel@tonic-gate #include <sys/sockio.h> 427c478bd9Sstevel@tonic-gate #include <net/if.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #include <sys/cred.h> 457c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #include <sys/sad.h> 487c478bd9Sstevel@tonic-gate #include <sys/kstr.h> 497c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 507c478bd9Sstevel@tonic-gate #include <sys/bootprops.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #include <sys/errno.h> 537c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 547c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 557c478bd9Sstevel@tonic-gate #include <sys/sunldi.h> 567c478bd9Sstevel@tonic-gate #include <sys/esunddi.h> 577c478bd9Sstevel@tonic-gate #include <sys/promif.h> 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate #include <netinet/in.h> 607c478bd9Sstevel@tonic-gate #include <netinet/ip6.h> 617c478bd9Sstevel@tonic-gate #include <netinet/icmp6.h> 627c478bd9Sstevel@tonic-gate #include <netinet/sctp.h> 637c478bd9Sstevel@tonic-gate #include <inet/common.h> 647c478bd9Sstevel@tonic-gate #include <inet/ip.h> 657c478bd9Sstevel@tonic-gate #include <inet/ip6.h> 667c478bd9Sstevel@tonic-gate #include <inet/tcp.h> 677c478bd9Sstevel@tonic-gate #include <inet/sctp_ip.h> 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate #include <sys/strlog.h> 707c478bd9Sstevel@tonic-gate #include <sys/log.h> 717c478bd9Sstevel@tonic-gate #include <sys/ethernet.h> 727c478bd9Sstevel@tonic-gate #include <sys/ddi_implfuncs.h> 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate #include <sys/dld.h> 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * Debug Macros 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate int strplumbdebug = 0; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate #define DBG0(_f) \ 827c478bd9Sstevel@tonic-gate if (strplumbdebug != 0) \ 837c478bd9Sstevel@tonic-gate printf("strplumb: " _f) 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate #define DBG1(_f, _a) \ 867c478bd9Sstevel@tonic-gate if (strplumbdebug != 0) \ 877c478bd9Sstevel@tonic-gate printf("strplumb: " _f, (_a)) 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate #define DBG2(_f, _a, _b) \ 907c478bd9Sstevel@tonic-gate if (strplumbdebug != 0) \ 917c478bd9Sstevel@tonic-gate printf("strplumb: " _f, (_a), (_b)) 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #define DBG3(_f, _a, _b, _c) \ 947c478bd9Sstevel@tonic-gate if (strplumbdebug != 0) \ 957c478bd9Sstevel@tonic-gate printf("strplumb: " _f, (_a), (_b), (_c)) 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 997c478bd9Sstevel@tonic-gate */ 1007c478bd9Sstevel@tonic-gate #define STRPLUMB_IDENT "STREAMS Plumbing Module v%I%" 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = { 1037c478bd9Sstevel@tonic-gate &mod_miscops, 1047c478bd9Sstevel@tonic-gate STRPLUMB_IDENT 1057c478bd9Sstevel@tonic-gate }; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1087c478bd9Sstevel@tonic-gate MODREV_1, 1097c478bd9Sstevel@tonic-gate &modlmisc, 1107c478bd9Sstevel@tonic-gate NULL 1117c478bd9Sstevel@tonic-gate }; 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate int 1147c478bd9Sstevel@tonic-gate _init(void) 1157c478bd9Sstevel@tonic-gate { 1167c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 1177c478bd9Sstevel@tonic-gate } 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate int 1207c478bd9Sstevel@tonic-gate _fini(void) 1217c478bd9Sstevel@tonic-gate { 1227c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1237c478bd9Sstevel@tonic-gate } 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate int 1267c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1277c478bd9Sstevel@tonic-gate { 1287c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1297c478bd9Sstevel@tonic-gate } 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate #define ARP "arp" 1327c478bd9Sstevel@tonic-gate #define TCP "tcp" 1337c478bd9Sstevel@tonic-gate #define TCP6 "tcp6" 1347c478bd9Sstevel@tonic-gate #define UDP "udp" 1357c478bd9Sstevel@tonic-gate #define UDP6 "udp6" 1367c478bd9Sstevel@tonic-gate #define SCTP "sctp" 1377c478bd9Sstevel@tonic-gate #define SCTP6 "sctp6" 1387c478bd9Sstevel@tonic-gate #define ICMP "icmp" 1397c478bd9Sstevel@tonic-gate #define ICMP6 "icmp6" 1407c478bd9Sstevel@tonic-gate #define IP "ip" 1417c478bd9Sstevel@tonic-gate #define IP6 "ip6" 1427c478bd9Sstevel@tonic-gate #define TIMOD "timod" 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate #define UDPDEV "/devices/pseudo/udp@0:udp" 1457c478bd9Sstevel@tonic-gate #define TCP6DEV "/devices/pseudo/tcp6@0:tcp6" 1467c478bd9Sstevel@tonic-gate #define SCTP6DEV "/devices/pseudo/sctp6@0:sctp6" 1477c478bd9Sstevel@tonic-gate #define IP6DEV "/devices/pseudo/ip6@0:ip6" 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate typedef struct strplumb_modspec { 1507c478bd9Sstevel@tonic-gate char *sm_type; 1517c478bd9Sstevel@tonic-gate char *sm_name; 1527c478bd9Sstevel@tonic-gate } strplumb_modspec_t; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate static strplumb_modspec_t strplumb_modlist[] = { 1557c478bd9Sstevel@tonic-gate { "drv", DLD_DRIVER_NAME }, 1567c478bd9Sstevel@tonic-gate { "drv", IP }, 1577c478bd9Sstevel@tonic-gate { "drv", IP6 }, 1587c478bd9Sstevel@tonic-gate { "drv", TCP }, 1597c478bd9Sstevel@tonic-gate { "drv", TCP6 }, 1607c478bd9Sstevel@tonic-gate { "drv", UDP }, 1617c478bd9Sstevel@tonic-gate { "drv", UDP6 }, 1627c478bd9Sstevel@tonic-gate { "drv", SCTP }, 1637c478bd9Sstevel@tonic-gate { "drv", SCTP6 }, 1647c478bd9Sstevel@tonic-gate { "drv", ICMP }, 1657c478bd9Sstevel@tonic-gate { "drv", ICMP6 }, 1667c478bd9Sstevel@tonic-gate { "drv", ARP }, 1677c478bd9Sstevel@tonic-gate { "strmod", TIMOD } 1687c478bd9Sstevel@tonic-gate }; 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * Called from swapgeneric.c:loadrootmodules() in the network boot case. 1727c478bd9Sstevel@tonic-gate */ 1737c478bd9Sstevel@tonic-gate int 1747c478bd9Sstevel@tonic-gate strplumb_load(void) 1757c478bd9Sstevel@tonic-gate { 1767c478bd9Sstevel@tonic-gate uint_t i; 1777c478bd9Sstevel@tonic-gate strplumb_modspec_t *p; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate DBG0("loading modules\n"); 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate for (i = 0, p = strplumb_modlist; 1827c478bd9Sstevel@tonic-gate i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]); 1837c478bd9Sstevel@tonic-gate i++, p++) { 1847c478bd9Sstevel@tonic-gate if (modloadonly(p->sm_type, p->sm_name) < 0) { 1857c478bd9Sstevel@tonic-gate printf("strplumb: failed to load %s/%s\n", 1867c478bd9Sstevel@tonic-gate p->sm_type, p->sm_name); 1877c478bd9Sstevel@tonic-gate return (EFAULT); 1887c478bd9Sstevel@tonic-gate } 1897c478bd9Sstevel@tonic-gate } 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate return (0); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate static int 1957c478bd9Sstevel@tonic-gate strplumb_init(void) 1967c478bd9Sstevel@tonic-gate { 1977c478bd9Sstevel@tonic-gate uint_t i; 1987c478bd9Sstevel@tonic-gate strplumb_modspec_t *p; 1997c478bd9Sstevel@tonic-gate int err; 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate DBG0("initializing modules\n"); 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate for (i = 0, p = strplumb_modlist; 2047c478bd9Sstevel@tonic-gate i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]); 2057c478bd9Sstevel@tonic-gate i++, p++) { 2067c478bd9Sstevel@tonic-gate if (strcmp(p->sm_type, "drv") == 0) 2077c478bd9Sstevel@tonic-gate err = (i_ddi_attach_pseudo_node(p->sm_name) != NULL) ? 2087c478bd9Sstevel@tonic-gate 0 : EFAULT; 2097c478bd9Sstevel@tonic-gate else 2107c478bd9Sstevel@tonic-gate err = (modload(p->sm_type, p->sm_name) < 0) ? 2117c478bd9Sstevel@tonic-gate EFAULT : 0; 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate if (err != 0) { 2147c478bd9Sstevel@tonic-gate printf("strplumb: failed to initialize %s/%s\n", 2157c478bd9Sstevel@tonic-gate p->sm_type, p->sm_name); 2167c478bd9Sstevel@tonic-gate return (err); 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate } 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate return (0); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate static int 2247c478bd9Sstevel@tonic-gate strplumb_autopush(void) 2257c478bd9Sstevel@tonic-gate { 2267c478bd9Sstevel@tonic-gate major_t maj; 2277c478bd9Sstevel@tonic-gate minor_t min; 2287c478bd9Sstevel@tonic-gate char *mods[5]; 2297c478bd9Sstevel@tonic-gate uint_t anchor = 1; 2307c478bd9Sstevel@tonic-gate int err; 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate min = (minor_t)-1; 2337c478bd9Sstevel@tonic-gate mods[1] = NULL; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * UDP 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate DBG0("setting up udp autopush\n"); 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate mods[0] = UDP; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(UDP); 2437c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, &anchor, 2447c478bd9Sstevel@tonic-gate mods)) != 0) { 2457c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/UDP) failed: %d\n", err); 2467c478bd9Sstevel@tonic-gate return (err); 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(UDP6); 2507c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, &anchor, 2517c478bd9Sstevel@tonic-gate mods)) != 0) { 2527c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/UDP6) failed: %d\n", err); 2537c478bd9Sstevel@tonic-gate return (err); 2547c478bd9Sstevel@tonic-gate } 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate /* 2577c478bd9Sstevel@tonic-gate * ICMP 2587c478bd9Sstevel@tonic-gate */ 2597c478bd9Sstevel@tonic-gate DBG0("setting up icmp autopush\n"); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate mods[0] = ICMP; 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(ICMP); 2647c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, NULL, 2657c478bd9Sstevel@tonic-gate mods)) != 0) { 2667c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/ICMP) failed: %d\n", err); 2677c478bd9Sstevel@tonic-gate return (err); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(ICMP6); 2717c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, NULL, 2727c478bd9Sstevel@tonic-gate mods)) != 0) { 2737c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/ICMP6) failed: %d\n", err); 2747c478bd9Sstevel@tonic-gate return (err); 2757c478bd9Sstevel@tonic-gate } 2767c478bd9Sstevel@tonic-gate 2777c478bd9Sstevel@tonic-gate /* 2787c478bd9Sstevel@tonic-gate * ARP 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate DBG0("setting up arp autopush\n"); 2817c478bd9Sstevel@tonic-gate 2827c478bd9Sstevel@tonic-gate mods[0] = ARP; 2837c478bd9Sstevel@tonic-gate 2847c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(ARP); 2857c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, &anchor, 2867c478bd9Sstevel@tonic-gate mods)) != 0) { 2877c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/ARP) failed: %d\n", err); 2887c478bd9Sstevel@tonic-gate return (err); 2897c478bd9Sstevel@tonic-gate } 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate return (0); 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate static int 2957c478bd9Sstevel@tonic-gate strplumb_sctpq(ldi_ident_t li) 2967c478bd9Sstevel@tonic-gate { 2977c478bd9Sstevel@tonic-gate ldi_handle_t lh = NULL; 2987c478bd9Sstevel@tonic-gate int err; 2997c478bd9Sstevel@tonic-gate int rval; 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate DBG0("configuring SCTP default queue\n"); 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(SCTP6DEV, FREAD|FWRITE, CRED(), &lh, 3047c478bd9Sstevel@tonic-gate li)) != 0) { 3057c478bd9Sstevel@tonic-gate printf("strplumb: open of SCTP6DEV failed: %d\n", err); 3067c478bd9Sstevel@tonic-gate return (err); 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, SCTP_IOC_DEFAULT_Q, (intptr_t)0, FKIOCTL, 3107c478bd9Sstevel@tonic-gate CRED(), &rval)) != 0) { 3117c478bd9Sstevel@tonic-gate printf("strplumb: failed to set SCTP default queue: %d\n", 3127c478bd9Sstevel@tonic-gate err); 3137c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 3147c478bd9Sstevel@tonic-gate return (err); 3157c478bd9Sstevel@tonic-gate } 3167c478bd9Sstevel@tonic-gate 3177c478bd9Sstevel@tonic-gate return (0); 3187c478bd9Sstevel@tonic-gate } 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate static int 3217c478bd9Sstevel@tonic-gate strplumb_tcpq(ldi_ident_t li) 3227c478bd9Sstevel@tonic-gate { 3237c478bd9Sstevel@tonic-gate ldi_handle_t lh = NULL; 3247c478bd9Sstevel@tonic-gate ldi_handle_t ip_lh = NULL; 3257c478bd9Sstevel@tonic-gate int err; 3267c478bd9Sstevel@tonic-gate int rval; 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate DBG0("configuring TCP default queue\n"); 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate /* 3317c478bd9Sstevel@tonic-gate * We open IP6DEV here because we need to have it open to in 3327c478bd9Sstevel@tonic-gate * order to open TCP6DEV successfully. 3337c478bd9Sstevel@tonic-gate */ 3347c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(IP6DEV, FREAD|FWRITE, CRED(), &ip_lh, 3357c478bd9Sstevel@tonic-gate li)) != 0) { 3367c478bd9Sstevel@tonic-gate printf("strplumb: open of IP6DEV failed: %d\n", err); 3377c478bd9Sstevel@tonic-gate return (err); 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate /* 3417c478bd9Sstevel@tonic-gate * We set the tcp default queue to IPv6 because IPv4 falls back to 3427c478bd9Sstevel@tonic-gate * IPv6 when it can't find a client, but IPv6 does not fall back to 3437c478bd9Sstevel@tonic-gate * IPv4. 3447c478bd9Sstevel@tonic-gate */ 3457c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(TCP6DEV, FREAD|FWRITE, CRED(), &lh, 3467c478bd9Sstevel@tonic-gate li)) != 0) { 3477c478bd9Sstevel@tonic-gate printf("strplumb: open of TCP6DEV failed: %d\n", err); 3487c478bd9Sstevel@tonic-gate goto done; 3497c478bd9Sstevel@tonic-gate } 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, TCP_IOC_DEFAULT_Q, (intptr_t)0, FKIOCTL, 3527c478bd9Sstevel@tonic-gate CRED(), &rval)) != 0) { 3537c478bd9Sstevel@tonic-gate printf("strplumb: failed to set TCP default queue: %d\n", 3547c478bd9Sstevel@tonic-gate err); 3557c478bd9Sstevel@tonic-gate goto done; 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate done: 3597c478bd9Sstevel@tonic-gate (void) ldi_close(ip_lh, FREAD|FWRITE, CRED()); 3607c478bd9Sstevel@tonic-gate return (err); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate 3637c478bd9Sstevel@tonic-gate static int 3647c478bd9Sstevel@tonic-gate create_gldv3_linkobj(ldi_ident_t li, char *driver, int instance) 3657c478bd9Sstevel@tonic-gate { 3667c478bd9Sstevel@tonic-gate ldi_handle_t lh; 3677c478bd9Sstevel@tonic-gate int err; 3687c478bd9Sstevel@tonic-gate struct strioctl iocb; 3697c478bd9Sstevel@tonic-gate int rval; 3707c478bd9Sstevel@tonic-gate dld_ioc_create_t dic; 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate /* 3737c478bd9Sstevel@tonic-gate * gld v3 driver. open the DLD control node. 3747c478bd9Sstevel@tonic-gate */ 3757c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(DLD_CONTROL_DEV, FREAD|FWRITE, CRED(), &lh, 3767c478bd9Sstevel@tonic-gate li)) != 0) { 3777c478bd9Sstevel@tonic-gate printf("strplumb: open CTLDEV failed: %d\n", err); 3787c478bd9Sstevel@tonic-gate return (ENXIO); 3797c478bd9Sstevel@tonic-gate } 3807c478bd9Sstevel@tonic-gate 3817c478bd9Sstevel@tonic-gate (void) snprintf(dic.dic_name, sizeof (dic.dic_name) - 1, "%s%d", 3827c478bd9Sstevel@tonic-gate driver, instance); 3837c478bd9Sstevel@tonic-gate (void) snprintf(dic.dic_dev, sizeof (dic.dic_dev) - 1, "%s%d", 3847c478bd9Sstevel@tonic-gate driver, instance); 3857c478bd9Sstevel@tonic-gate dic.dic_port = 0; 3867c478bd9Sstevel@tonic-gate dic.dic_vid = 0; 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate iocb.ic_cmd = DLDIOCCREATE; 3897c478bd9Sstevel@tonic-gate iocb.ic_timout = 15; 3907c478bd9Sstevel@tonic-gate iocb.ic_len = sizeof (dic); 3917c478bd9Sstevel@tonic-gate iocb.ic_dp = (char *)&dic; 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate /* 3947c478bd9Sstevel@tonic-gate * Try to create a data-link interface with the same name as the 3957c478bd9Sstevel@tonic-gate * device. 3967c478bd9Sstevel@tonic-gate */ 3977c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), 3987c478bd9Sstevel@tonic-gate &rval)) != 0) { 3997c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "strplumb: DLDIOCCREATE failed: %d\n", err); 4007c478bd9Sstevel@tonic-gate return (ENXIO); 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate 4037c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 4047c478bd9Sstevel@tonic-gate return (0); 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate /* 4087c478bd9Sstevel@tonic-gate * Can be set in /etc/system in the case of local booting. See comment below. 4097c478bd9Sstevel@tonic-gate */ 4107c478bd9Sstevel@tonic-gate char *ndev_name = 0; 4117c478bd9Sstevel@tonic-gate int ndev_unit = 0; 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate /* 4147c478bd9Sstevel@tonic-gate * If we booted diskless then strplumb() will have been called from 4157c478bd9Sstevel@tonic-gate * swapgeneric.c:rootconf(). All we can do in that case is plumb the 4167c478bd9Sstevel@tonic-gate * network device that we booted from. 4177c478bd9Sstevel@tonic-gate * 4187c478bd9Sstevel@tonic-gate * If we booted from a local disk, we will have been called from main(), 4197c478bd9Sstevel@tonic-gate * and normally we defer the plumbing of interfaces until network/physical. 4207c478bd9Sstevel@tonic-gate * This can be overridden by setting "ndev_name" in /etc/system. 4217c478bd9Sstevel@tonic-gate */ 4227c478bd9Sstevel@tonic-gate static int 4237c478bd9Sstevel@tonic-gate resolve_boot_path(ldi_ident_t li) 4247c478bd9Sstevel@tonic-gate { 4257c478bd9Sstevel@tonic-gate char *devpath = NULL; 4267c478bd9Sstevel@tonic-gate dev_info_t *dip; 4277c478bd9Sstevel@tonic-gate const char *driver; 4287c478bd9Sstevel@tonic-gate int instance; 4297c478bd9Sstevel@tonic-gate int err; 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate if (strncmp(rootfs.bo_fstype, "nfs", 3) == 0) 4327c478bd9Sstevel@tonic-gate devpath = rootfs.bo_name; 4337c478bd9Sstevel@tonic-gate #ifndef __sparc 4347c478bd9Sstevel@tonic-gate else 4357c478bd9Sstevel@tonic-gate devpath = strplumb_get_netdev_path(); 4367c478bd9Sstevel@tonic-gate #endif 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate if (devpath != NULL) { 4397c478bd9Sstevel@tonic-gate DBG1("resolving boot-path: %s\n", devpath); 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate /* 4427c478bd9Sstevel@tonic-gate * Hold the devi since this is the root device. 4437c478bd9Sstevel@tonic-gate */ 4447c478bd9Sstevel@tonic-gate if ((dip = e_ddi_hold_devi_by_path(devpath, 0)) == NULL) { 4457c478bd9Sstevel@tonic-gate printf("strplumb: unable to hold root device: %s\n", 4467c478bd9Sstevel@tonic-gate devpath); 4477c478bd9Sstevel@tonic-gate return (ENXIO); 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate 4507c478bd9Sstevel@tonic-gate driver = ddi_driver_name(dip); 4517c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip); 4527c478bd9Sstevel@tonic-gate } else { 4537c478bd9Sstevel@tonic-gate if (ndev_name == NULL) 4547c478bd9Sstevel@tonic-gate return (ENODEV); 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate DBG2("using ndev_name (%s) ndev_unit (%d)\n", ndev_name, 4577c478bd9Sstevel@tonic-gate ndev_unit); 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate if (i_ddi_attach_hw_nodes(ndev_name) != DDI_SUCCESS) { 4607c478bd9Sstevel@tonic-gate printf("strplumb: cannot load ndev_name '%s'\n", 4617c478bd9Sstevel@tonic-gate ndev_name); 4627c478bd9Sstevel@tonic-gate return (ENXIO); 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate driver = ndev_name; 4667c478bd9Sstevel@tonic-gate instance = ndev_unit; 4677c478bd9Sstevel@tonic-gate } 4687c478bd9Sstevel@tonic-gate 4697c478bd9Sstevel@tonic-gate /* legcy driver, use clone to open */ 4707c478bd9Sstevel@tonic-gate if (!GLDV3_DRV(ddi_name_to_major((char *)driver))) { 4717c478bd9Sstevel@tonic-gate (void) snprintf(rootfs.bo_devname, BO_MAXOBJNAME, 4727c478bd9Sstevel@tonic-gate "/devices/pseudo/clone@0:%s", driver); 4737c478bd9Sstevel@tonic-gate (void) snprintf(rootfs.bo_ifname, BO_MAXOBJNAME, "%s%d", 4747c478bd9Sstevel@tonic-gate driver, instance); 4757c478bd9Sstevel@tonic-gate rootfs.bo_ppa = instance; 4767c478bd9Sstevel@tonic-gate return (0); 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /* GLDv3: create link object so open with succeed later */ 4807c478bd9Sstevel@tonic-gate err = create_gldv3_linkobj(li, (char *)driver, instance); 4817c478bd9Sstevel@tonic-gate if (err != 0) { 4827c478bd9Sstevel@tonic-gate return (err); 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate (void) snprintf(rootfs.bo_devname, BO_MAXOBJNAME, 4867c478bd9Sstevel@tonic-gate "/devices/pseudo/dld@0:%s", driver); 4877c478bd9Sstevel@tonic-gate (void) snprintf(rootfs.bo_ifname, BO_MAXOBJNAME, "%s%d", 4887c478bd9Sstevel@tonic-gate driver, instance); 4897c478bd9Sstevel@tonic-gate rootfs.bo_ppa = instance; 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate return (err); 4927c478bd9Sstevel@tonic-gate } 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate static int 4957c478bd9Sstevel@tonic-gate getifflags(ldi_handle_t lh, struct lifreq *lifrp) 4967c478bd9Sstevel@tonic-gate { 4977c478bd9Sstevel@tonic-gate struct strioctl iocb; 4987c478bd9Sstevel@tonic-gate int rval; 4997c478bd9Sstevel@tonic-gate 5007c478bd9Sstevel@tonic-gate iocb.ic_cmd = SIOCGLIFFLAGS; 5017c478bd9Sstevel@tonic-gate iocb.ic_timout = 15; 5027c478bd9Sstevel@tonic-gate iocb.ic_len = sizeof (struct lifreq); 5037c478bd9Sstevel@tonic-gate iocb.ic_dp = (char *)lifrp; 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate return (ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), &rval)); 5067c478bd9Sstevel@tonic-gate 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate static int 5107c478bd9Sstevel@tonic-gate setifname(ldi_handle_t lh, struct lifreq *lifrp) 5117c478bd9Sstevel@tonic-gate { 5127c478bd9Sstevel@tonic-gate struct strioctl iocb; 5137c478bd9Sstevel@tonic-gate int rval; 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate iocb.ic_cmd = SIOCSLIFNAME; 5167c478bd9Sstevel@tonic-gate iocb.ic_timout = 15; 5177c478bd9Sstevel@tonic-gate iocb.ic_len = sizeof (struct lifreq); 5187c478bd9Sstevel@tonic-gate iocb.ic_dp = (char *)lifrp; 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate return (ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), &rval)); 5217c478bd9Sstevel@tonic-gate } 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate static int 5247c478bd9Sstevel@tonic-gate strplumb_dev(ldi_ident_t li) 5257c478bd9Sstevel@tonic-gate { 5267c478bd9Sstevel@tonic-gate ldi_handle_t lh = NULL; 5277c478bd9Sstevel@tonic-gate ldi_handle_t mux_lh = NULL; 5287c478bd9Sstevel@tonic-gate int err; 5297c478bd9Sstevel@tonic-gate struct lifreq lifr; 5307c478bd9Sstevel@tonic-gate struct ifreq ifr; 5317c478bd9Sstevel@tonic-gate int rval; 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate bzero(&lifr, sizeof (struct lifreq)); 5347c478bd9Sstevel@tonic-gate bzero(&ifr, sizeof (ifr)); 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate /* 5377c478bd9Sstevel@tonic-gate * Now set up the links. Ultimately, we should have two streams 5387c478bd9Sstevel@tonic-gate * permanently linked underneath UDP (which is actually IP with UDP 5397c478bd9Sstevel@tonic-gate * autopushed). One stream consists of the ARP-[ifname] combination, 5407c478bd9Sstevel@tonic-gate * while the other consists of ARP-IP-[ifname]. The second combination 5417c478bd9Sstevel@tonic-gate * seems a little weird, but is linked underneath UDP just to keep it 5427c478bd9Sstevel@tonic-gate * around. 5437c478bd9Sstevel@tonic-gate * 5447c478bd9Sstevel@tonic-gate * We pin underneath UDP here to match what is done in ifconfig(1m); 5457c478bd9Sstevel@tonic-gate * otherwise, ifconfig will be unable to unplumb the stream (the major 5467c478bd9Sstevel@tonic-gate * number and mux id must both match for a successful I_PUNLINK). 5477c478bd9Sstevel@tonic-gate * 5487c478bd9Sstevel@tonic-gate * There are subtleties in the plumbing which make it essential to 5497c478bd9Sstevel@tonic-gate * follow the logic used in ifconfig(1m) very closely. 5507c478bd9Sstevel@tonic-gate */ 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate /* 5537c478bd9Sstevel@tonic-gate * Plumb UDP-ARP-IP-<dev> 5547c478bd9Sstevel@tonic-gate */ 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(rootfs.bo_devname, FREAD|FWRITE, CRED(), 5577c478bd9Sstevel@tonic-gate &lh, li)) != 0) { 5587c478bd9Sstevel@tonic-gate printf("strplumb: open %s failed: %d\n", rootfs.bo_devname, 5597c478bd9Sstevel@tonic-gate err); 5607c478bd9Sstevel@tonic-gate goto done; 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)IP, FKIOCTL, CRED(), 5657c478bd9Sstevel@tonic-gate &rval)) != 0) { 5667c478bd9Sstevel@tonic-gate printf("strplumb: push IP failed: %d\n", err); 5677c478bd9Sstevel@tonic-gate goto done; 5687c478bd9Sstevel@tonic-gate } 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate if ((err = getifflags(lh, &lifr)) != 0) 5717c478bd9Sstevel@tonic-gate goto done; 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate lifr.lifr_flags |= IFF_IPV4; 5747c478bd9Sstevel@tonic-gate lifr.lifr_flags &= ~IFF_IPV6; 5757c478bd9Sstevel@tonic-gate 5767c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)ARP, FKIOCTL, CRED(), 5777c478bd9Sstevel@tonic-gate &rval)) != 0) { 5787c478bd9Sstevel@tonic-gate printf("strplumb: push ARP failed: %d\n", err); 5797c478bd9Sstevel@tonic-gate goto done; 5807c478bd9Sstevel@tonic-gate } 5817c478bd9Sstevel@tonic-gate 5827c478bd9Sstevel@tonic-gate (void) strlcpy(lifr.lifr_name, rootfs.bo_ifname, 5837c478bd9Sstevel@tonic-gate sizeof (lifr.lifr_name)); 5847c478bd9Sstevel@tonic-gate lifr.lifr_ppa = rootfs.bo_ppa; 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate if ((err = setifname(lh, &lifr)) != 0) 5877c478bd9Sstevel@tonic-gate goto done; 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate /* Get the flags and check if ARP is needed */ 5907c478bd9Sstevel@tonic-gate if ((err = getifflags(lh, &lifr)) != 0) { 5917c478bd9Sstevel@tonic-gate printf("strplumb: getifflags %s IP failed, error %d\n", 5927c478bd9Sstevel@tonic-gate lifr.lifr_name, err); 5937c478bd9Sstevel@tonic-gate goto done; 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate /* Pop out ARP if not needed */ 5977c478bd9Sstevel@tonic-gate if (lifr.lifr_flags & IFF_NOARP) { 5987c478bd9Sstevel@tonic-gate err = ldi_ioctl(lh, I_POP, (intptr_t)0, FKIOCTL, CRED(), 5997c478bd9Sstevel@tonic-gate &rval); 6007c478bd9Sstevel@tonic-gate if (err != 0) { 6017c478bd9Sstevel@tonic-gate printf("strplumb: pop ARP failed, error %d\n", err); 6027c478bd9Sstevel@tonic-gate goto done; 6037c478bd9Sstevel@tonic-gate } 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(UDPDEV, FREAD|FWRITE, CRED(), &mux_lh, 6077c478bd9Sstevel@tonic-gate li)) != 0) { 6087c478bd9Sstevel@tonic-gate printf("strplumb: open of UDPDEV failed: %d\n", err); 6097c478bd9Sstevel@tonic-gate goto done; 6107c478bd9Sstevel@tonic-gate } 6117c478bd9Sstevel@tonic-gate 6127c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(mux_lh, I_PLINK, (intptr_t)lh, 6137c478bd9Sstevel@tonic-gate FREAD|FWRITE|FNOCTTY|FKIOCTL, CRED(), 6147c478bd9Sstevel@tonic-gate &(ifr.ifr_ip_muxid))) != 0) { 6157c478bd9Sstevel@tonic-gate printf("strplumb: plink UDP-ARP-IP-%s failed: %d\n", 6167c478bd9Sstevel@tonic-gate rootfs.bo_ifname, err); 6177c478bd9Sstevel@tonic-gate goto done; 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate DBG2("UDP-ARP-IP-%s muxid: %d\n", rootfs.bo_ifname, ifr.ifr_ip_muxid); 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 6237c478bd9Sstevel@tonic-gate lh = NULL; 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate /* 6267c478bd9Sstevel@tonic-gate * Plumb UDP-ARP-<dev> 6277c478bd9Sstevel@tonic-gate */ 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(rootfs.bo_devname, FREAD|FWRITE, CRED(), 6307c478bd9Sstevel@tonic-gate &lh, li)) != 0) { 6317c478bd9Sstevel@tonic-gate printf("strplumb: open %s failed: %d\n", rootfs.bo_devname, 6327c478bd9Sstevel@tonic-gate err); 6337c478bd9Sstevel@tonic-gate goto done; 6347c478bd9Sstevel@tonic-gate } 6357c478bd9Sstevel@tonic-gate 6367c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)ARP, FKIOCTL, CRED(), 6377c478bd9Sstevel@tonic-gate &rval)) != 0) { 6387c478bd9Sstevel@tonic-gate printf("strplumb: push ARP failed: %d\n", err); 6397c478bd9Sstevel@tonic-gate goto done; 6407c478bd9Sstevel@tonic-gate } 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate if ((err = setifname(lh, &lifr)) != 0) 6437c478bd9Sstevel@tonic-gate goto done; 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(mux_lh, I_PLINK, (intptr_t)lh, 6467c478bd9Sstevel@tonic-gate FREAD|FWRITE|FNOCTTY|FKIOCTL, CRED(), 6477c478bd9Sstevel@tonic-gate &(ifr.ifr_arp_muxid))) != 0) { 6487c478bd9Sstevel@tonic-gate printf("strplumb: plink UDP-ARP-%s failed: %d\n", 6497c478bd9Sstevel@tonic-gate rootfs.bo_ifname, err); 6507c478bd9Sstevel@tonic-gate goto done; 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate DBG2("UDP-ARP-%s muxid: %d\n", rootfs.bo_ifname, ifr.ifr_arp_muxid); 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate /* 6567c478bd9Sstevel@tonic-gate * Cache the mux ids. 6577c478bd9Sstevel@tonic-gate */ 6587c478bd9Sstevel@tonic-gate (void) strlcpy(ifr.ifr_name, rootfs.bo_ifname, sizeof (ifr.ifr_name)); 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(mux_lh, SIOCSIFMUXID, (intptr_t)&ifr, FKIOCTL, 6617c478bd9Sstevel@tonic-gate CRED(), &rval)) != 0) { 6627c478bd9Sstevel@tonic-gate printf("strplumb: SIOCSIFMUXID failed: %d\n", err); 6637c478bd9Sstevel@tonic-gate goto done; 6647c478bd9Sstevel@tonic-gate } 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate done: 6677c478bd9Sstevel@tonic-gate if (lh != NULL) 6687c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate if (mux_lh != NULL) 6717c478bd9Sstevel@tonic-gate (void) ldi_close(mux_lh, FREAD|FWRITE, CRED()); 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate return (err); 6747c478bd9Sstevel@tonic-gate } 6757c478bd9Sstevel@tonic-gate 6767c478bd9Sstevel@tonic-gate /* 6777c478bd9Sstevel@tonic-gate * Do streams plumbing for internet protocols. 6787c478bd9Sstevel@tonic-gate */ 6797c478bd9Sstevel@tonic-gate int 6807c478bd9Sstevel@tonic-gate strplumb(void) 6817c478bd9Sstevel@tonic-gate { 6827c478bd9Sstevel@tonic-gate ldi_ident_t li; 6837c478bd9Sstevel@tonic-gate int err; 6847c478bd9Sstevel@tonic-gate 6857c478bd9Sstevel@tonic-gate if ((err = strplumb_init()) != 0) 6867c478bd9Sstevel@tonic-gate return (err); 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate if ((err = strplumb_autopush()) != 0) 6897c478bd9Sstevel@tonic-gate return (err); 6907c478bd9Sstevel@tonic-gate 6917c478bd9Sstevel@tonic-gate if ((err = ldi_ident_from_mod(&modlinkage, &li)) != 0) 6927c478bd9Sstevel@tonic-gate return (err); 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate if ((err = strplumb_sctpq(li)) != 0) 6957c478bd9Sstevel@tonic-gate goto done; 6967c478bd9Sstevel@tonic-gate 6977c478bd9Sstevel@tonic-gate if ((err = strplumb_tcpq(li)) != 0) 6987c478bd9Sstevel@tonic-gate goto done; 6997c478bd9Sstevel@tonic-gate 7007c478bd9Sstevel@tonic-gate if ((err = resolve_boot_path(li)) != 0) 7017c478bd9Sstevel@tonic-gate goto done; 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate DBG1("rootfs.bo_devname: %s\n", rootfs.bo_devname); 7047c478bd9Sstevel@tonic-gate DBG1("rootfs.bo_ifname: %s\n", rootfs.bo_ifname); 7057c478bd9Sstevel@tonic-gate DBG1("rootfs.bo_ppa: %d\n", rootfs.bo_ppa); 7067c478bd9Sstevel@tonic-gate 7077c478bd9Sstevel@tonic-gate if ((err = strplumb_dev(li)) != 0) 7087c478bd9Sstevel@tonic-gate goto done; 7097c478bd9Sstevel@tonic-gate 7107c478bd9Sstevel@tonic-gate done: 7117c478bd9Sstevel@tonic-gate ldi_ident_release(li); 7127c478bd9Sstevel@tonic-gate 7137c478bd9Sstevel@tonic-gate return (err); 7147c478bd9Sstevel@tonic-gate } 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate /* multiboot: diskless boot interface discovery */ 7177c478bd9Sstevel@tonic-gate 7187c478bd9Sstevel@tonic-gate #ifndef __sparc 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate static uchar_t boot_macaddr[16]; 7217c478bd9Sstevel@tonic-gate static int boot_maclen; 7227c478bd9Sstevel@tonic-gate static uchar_t *getmacaddr(dev_info_t *dip, int *maclen); 7237c478bd9Sstevel@tonic-gate static int matchmac(dev_info_t *dip, void *arg); 7247c478bd9Sstevel@tonic-gate extern int dl_attach(ldi_handle_t lh, int unit); 7257c478bd9Sstevel@tonic-gate extern int dl_bind(ldi_handle_t lh, uint_t sap, uint_t max_conn, 7267c478bd9Sstevel@tonic-gate uint_t service, uint_t conn_mgmt); 7277c478bd9Sstevel@tonic-gate extern int dl_phys_addr(ldi_handle_t lh, struct ether_addr *eaddr); 7287c478bd9Sstevel@tonic-gate 7297c478bd9Sstevel@tonic-gate char * 7307c478bd9Sstevel@tonic-gate strplumb_get_netdev_path(void) 7317c478bd9Sstevel@tonic-gate { 7327c478bd9Sstevel@tonic-gate char *macstr, *devpath = NULL; 7337c478bd9Sstevel@tonic-gate uchar_t *bootp; 7347c478bd9Sstevel@tonic-gate uint_t bootp_len, len; 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 7377c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, BP_BOOT_MAC, &macstr) == DDI_SUCCESS) { 7387c478bd9Sstevel@tonic-gate /* 7397c478bd9Sstevel@tonic-gate * hard coded ether mac len for booting floppy on 7407c478bd9Sstevel@tonic-gate * machines with old cards 7417c478bd9Sstevel@tonic-gate */ 7427c478bd9Sstevel@tonic-gate boot_maclen = ether_aton(macstr, boot_macaddr); 7437c478bd9Sstevel@tonic-gate if (boot_maclen != 6) { 7447c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 7457c478bd9Sstevel@tonic-gate "malformed boot_mac property, %d bytes", 7467c478bd9Sstevel@tonic-gate boot_maclen); 7477c478bd9Sstevel@tonic-gate } 7487c478bd9Sstevel@tonic-gate ddi_prop_free(macstr); 7497c478bd9Sstevel@tonic-gate } else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ddi_root_node(), 7507c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, BP_BOOTP_RESPONSE, &bootp, &bootp_len) 7517c478bd9Sstevel@tonic-gate == DDI_SUCCESS) { 7527c478bd9Sstevel@tonic-gate 7537c478bd9Sstevel@tonic-gate /* 7547c478bd9Sstevel@tonic-gate * These offsets are defined by dhcp standard 7557c478bd9Sstevel@tonic-gate * Should use structure offsets 7567c478bd9Sstevel@tonic-gate */ 7577c478bd9Sstevel@tonic-gate boot_maclen = *(bootp + 2); 7587c478bd9Sstevel@tonic-gate ASSERT(boot_maclen <= 16); 7597c478bd9Sstevel@tonic-gate (void) bcopy(bootp + 28, boot_macaddr, boot_maclen); 7607c478bd9Sstevel@tonic-gate 7617c478bd9Sstevel@tonic-gate /* encode to ascii string to match what sparc OBP exports */ 762*66b4fb87Ssetje dhcack = kmem_zalloc(bootp_len * 2 + IFNAMSIZ + 2, KM_SLEEP); 7637c478bd9Sstevel@tonic-gate (void) octet_to_hexascii(bootp, bootp_len, dhcack + IFNAMSIZ, 7647c478bd9Sstevel@tonic-gate &len); 7657c478bd9Sstevel@tonic-gate ASSERT(len < bootp_len * 2 + 2); 7667c478bd9Sstevel@tonic-gate ddi_prop_free(bootp); 7677c478bd9Sstevel@tonic-gate } else 7687c478bd9Sstevel@tonic-gate return (NULL); 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), matchmac, (void *)&devpath); 7717c478bd9Sstevel@tonic-gate return (devpath); 7727c478bd9Sstevel@tonic-gate } 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate /* 7757c478bd9Sstevel@tonic-gate * Get boot path from the boot_mac address 7767c478bd9Sstevel@tonic-gate */ 7777c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 7787c478bd9Sstevel@tonic-gate static int 7797c478bd9Sstevel@tonic-gate matchmac(dev_info_t *dip, void *arg) 7807c478bd9Sstevel@tonic-gate { 7817c478bd9Sstevel@tonic-gate char **devpathp = (char **)arg; 7827c478bd9Sstevel@tonic-gate char *model_str; 7837c478bd9Sstevel@tonic-gate uchar_t *macaddr; 7847c478bd9Sstevel@tonic-gate int maclen; 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate /* XXX Should use "device-type" per IEEE 1275 */ 7877c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0, 7887c478bd9Sstevel@tonic-gate "model", &model_str) != DDI_SUCCESS) 7897c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate if (strcmp(model_str, "Ethernet controller") != 0) { 7927c478bd9Sstevel@tonic-gate ddi_prop_free(model_str); 7937c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 7947c478bd9Sstevel@tonic-gate } 7957c478bd9Sstevel@tonic-gate ddi_prop_free(model_str); 7967c478bd9Sstevel@tonic-gate 7977c478bd9Sstevel@tonic-gate /* We have a network device now */ 7987c478bd9Sstevel@tonic-gate if (i_ddi_attach_node_hierarchy(dip) != DDI_SUCCESS) { 7997c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 8007c478bd9Sstevel@tonic-gate } 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate ASSERT(boot_maclen != 0); 8037c478bd9Sstevel@tonic-gate macaddr = getmacaddr(dip, &maclen); 8047c478bd9Sstevel@tonic-gate if (macaddr == NULL) 8057c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 8067c478bd9Sstevel@tonic-gate 8077c478bd9Sstevel@tonic-gate if (maclen != boot_maclen || 8087c478bd9Sstevel@tonic-gate bcmp(macaddr, boot_macaddr, maclen) != 0) { 8097c478bd9Sstevel@tonic-gate kmem_free(macaddr, maclen); 8107c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 8117c478bd9Sstevel@tonic-gate } 8127c478bd9Sstevel@tonic-gate 8137c478bd9Sstevel@tonic-gate /* found hardware with the mac address */ 8147c478bd9Sstevel@tonic-gate (void) localetheraddr((struct ether_addr *)macaddr, NULL); 8157c478bd9Sstevel@tonic-gate kmem_free(macaddr, maclen); 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate *devpathp = kmem_alloc(MAXPATHLEN, KM_SLEEP); 8187c478bd9Sstevel@tonic-gate (void) ddi_pathname(dip, *devpathp); 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate /* fill in the name portion of dhcack */ 8217c478bd9Sstevel@tonic-gate if (dhcack) 8227c478bd9Sstevel@tonic-gate (void) snprintf(dhcack, IFNAMSIZ, "%s%d", 8237c478bd9Sstevel@tonic-gate ddi_driver_name(dip), i_ddi_devi_get_ppa(dip)); 8247c478bd9Sstevel@tonic-gate return (DDI_WALK_TERMINATE); 8257c478bd9Sstevel@tonic-gate } 8267c478bd9Sstevel@tonic-gate 8277c478bd9Sstevel@tonic-gate static uchar_t * 8287c478bd9Sstevel@tonic-gate getmacaddr_gldv3(char *drv, int inst, int *maclenp) 8297c478bd9Sstevel@tonic-gate { 8307c478bd9Sstevel@tonic-gate char ifname[16]; 8317c478bd9Sstevel@tonic-gate mac_handle_t mh; 8327c478bd9Sstevel@tonic-gate uchar_t *macaddr; 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate (void) snprintf(ifname, sizeof (ifname), "%s%d", drv, inst); 8357c478bd9Sstevel@tonic-gate if (mac_open(ifname, 0, &mh) < 0) { 8367c478bd9Sstevel@tonic-gate return (NULL); 8377c478bd9Sstevel@tonic-gate } 8387c478bd9Sstevel@tonic-gate *maclenp = sizeof (struct ether_addr); 8397c478bd9Sstevel@tonic-gate macaddr = kmem_alloc(*maclenp, KM_SLEEP); 8407c478bd9Sstevel@tonic-gate mac_unicst_get(mh, macaddr); 8417c478bd9Sstevel@tonic-gate mac_close(mh); 8427c478bd9Sstevel@tonic-gate 8437c478bd9Sstevel@tonic-gate return (macaddr); 8447c478bd9Sstevel@tonic-gate } 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate static uchar_t * 8477c478bd9Sstevel@tonic-gate getmacaddr(dev_info_t *dip, int *maclenp) 8487c478bd9Sstevel@tonic-gate { 8497c478bd9Sstevel@tonic-gate int rc, ppa; 8507c478bd9Sstevel@tonic-gate ldi_ident_t li; 8517c478bd9Sstevel@tonic-gate ldi_handle_t lh; 8527c478bd9Sstevel@tonic-gate char *drv_name = (char *)ddi_driver_name(dip); 8537c478bd9Sstevel@tonic-gate char *clonepath; 8547c478bd9Sstevel@tonic-gate uchar_t *macaddr = NULL; 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate /* a simpler way to get mac address for GLDv3 drivers */ 8577c478bd9Sstevel@tonic-gate if (GLDV3_DRV(ddi_name_to_major(drv_name))) { 8587c478bd9Sstevel@tonic-gate return (getmacaddr_gldv3(drv_name, ddi_get_instance(dip), 8597c478bd9Sstevel@tonic-gate maclenp)); 8607c478bd9Sstevel@tonic-gate } 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate if (rc = ldi_ident_from_mod(&modlinkage, &li)) { 8637c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 8647c478bd9Sstevel@tonic-gate "getmacaddr: ldi_ident_from_mod failed: %d\n", rc); 8657c478bd9Sstevel@tonic-gate return (NULL); 8667c478bd9Sstevel@tonic-gate } 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate clonepath = kmem_alloc(MAXPATHLEN, KM_SLEEP); 8697c478bd9Sstevel@tonic-gate (void) snprintf(clonepath, MAXPATHLEN, 8707c478bd9Sstevel@tonic-gate "/devices/pseudo/clone@0:%s", drv_name); 8717c478bd9Sstevel@tonic-gate 8727c478bd9Sstevel@tonic-gate rc = ldi_open_by_name(clonepath, FREAD|FWRITE, CRED(), &lh, li); 8737c478bd9Sstevel@tonic-gate ldi_ident_release(li); 8747c478bd9Sstevel@tonic-gate if (rc) { 8757c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 8767c478bd9Sstevel@tonic-gate "getmacaddr: ldi_open_by_name(%s) failed: %d\n", 8777c478bd9Sstevel@tonic-gate clonepath, rc); 8787c478bd9Sstevel@tonic-gate kmem_free(clonepath, MAXPATHLEN); 8797c478bd9Sstevel@tonic-gate return (NULL); 8807c478bd9Sstevel@tonic-gate } 8817c478bd9Sstevel@tonic-gate kmem_free(clonepath, MAXPATHLEN); 8827c478bd9Sstevel@tonic-gate 8837c478bd9Sstevel@tonic-gate ppa = i_ddi_devi_get_ppa(dip); 8847c478bd9Sstevel@tonic-gate if ((dl_attach(lh, ppa) != 0) || 8857c478bd9Sstevel@tonic-gate (dl_bind(lh, ETHERTYPE_IP, 0, DL_CLDLS, 0) != 0)) { 8867c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 8877c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 8887c478bd9Sstevel@tonic-gate "getmacaddr: dl_attach/bind(%s%d) failed: %d\n", 8897c478bd9Sstevel@tonic-gate drv_name, ppa, rc); 8907c478bd9Sstevel@tonic-gate return (NULL); 8917c478bd9Sstevel@tonic-gate } 8927c478bd9Sstevel@tonic-gate *maclenp = sizeof (struct ether_addr); 8937c478bd9Sstevel@tonic-gate macaddr = kmem_alloc(*maclenp, KM_SLEEP); 8947c478bd9Sstevel@tonic-gate if (dl_phys_addr(lh, (struct ether_addr *)macaddr) != 0) { 8957c478bd9Sstevel@tonic-gate kmem_free(macaddr, *maclenp); 8967c478bd9Sstevel@tonic-gate macaddr = NULL; 8977c478bd9Sstevel@tonic-gate *maclenp = 0; 8987c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 8997c478bd9Sstevel@tonic-gate "getmacaddr: dl_macaddr(%s%d) failed: %d\n", 9007c478bd9Sstevel@tonic-gate drv_name, ppa, rc); 9017c478bd9Sstevel@tonic-gate } 9027c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 9037c478bd9Sstevel@tonic-gate return (macaddr); 9047c478bd9Sstevel@tonic-gate } 9057c478bd9Sstevel@tonic-gate 9067c478bd9Sstevel@tonic-gate #endif /* !__sparc */ 907