1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/param.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/user.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/file.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/stream.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/strsubr.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/dlpi.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/socket.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/sockio.h> 42*7c478bd9Sstevel@tonic-gate #include <net/if.h> 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate #include <sys/cred.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate #include <sys/sad.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/kstr.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 50*7c478bd9Sstevel@tonic-gate #include <sys/bootprops.h> 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate #include <sys/errno.h> 53*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 54*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 55*7c478bd9Sstevel@tonic-gate #include <sys/sunldi.h> 56*7c478bd9Sstevel@tonic-gate #include <sys/esunddi.h> 57*7c478bd9Sstevel@tonic-gate #include <sys/promif.h> 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate #include <netinet/in.h> 60*7c478bd9Sstevel@tonic-gate #include <netinet/ip6.h> 61*7c478bd9Sstevel@tonic-gate #include <netinet/icmp6.h> 62*7c478bd9Sstevel@tonic-gate #include <netinet/sctp.h> 63*7c478bd9Sstevel@tonic-gate #include <inet/common.h> 64*7c478bd9Sstevel@tonic-gate #include <inet/ip.h> 65*7c478bd9Sstevel@tonic-gate #include <inet/ip6.h> 66*7c478bd9Sstevel@tonic-gate #include <inet/tcp.h> 67*7c478bd9Sstevel@tonic-gate #include <inet/sctp_ip.h> 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate #include <sys/strlog.h> 70*7c478bd9Sstevel@tonic-gate #include <sys/log.h> 71*7c478bd9Sstevel@tonic-gate #include <sys/ethernet.h> 72*7c478bd9Sstevel@tonic-gate #include <sys/ddi_implfuncs.h> 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate #include <sys/dld.h> 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate /* 77*7c478bd9Sstevel@tonic-gate * Debug Macros 78*7c478bd9Sstevel@tonic-gate */ 79*7c478bd9Sstevel@tonic-gate int strplumbdebug = 0; 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate #define DBG0(_f) \ 82*7c478bd9Sstevel@tonic-gate if (strplumbdebug != 0) \ 83*7c478bd9Sstevel@tonic-gate printf("strplumb: " _f) 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate #define DBG1(_f, _a) \ 86*7c478bd9Sstevel@tonic-gate if (strplumbdebug != 0) \ 87*7c478bd9Sstevel@tonic-gate printf("strplumb: " _f, (_a)) 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate #define DBG2(_f, _a, _b) \ 90*7c478bd9Sstevel@tonic-gate if (strplumbdebug != 0) \ 91*7c478bd9Sstevel@tonic-gate printf("strplumb: " _f, (_a), (_b)) 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate #define DBG3(_f, _a, _b, _c) \ 94*7c478bd9Sstevel@tonic-gate if (strplumbdebug != 0) \ 95*7c478bd9Sstevel@tonic-gate printf("strplumb: " _f, (_a), (_b), (_c)) 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate /* 98*7c478bd9Sstevel@tonic-gate * Module linkage information for the kernel. 99*7c478bd9Sstevel@tonic-gate */ 100*7c478bd9Sstevel@tonic-gate #define STRPLUMB_IDENT "STREAMS Plumbing Module v%I%" 101*7c478bd9Sstevel@tonic-gate 102*7c478bd9Sstevel@tonic-gate static struct modlmisc modlmisc = { 103*7c478bd9Sstevel@tonic-gate &mod_miscops, 104*7c478bd9Sstevel@tonic-gate STRPLUMB_IDENT 105*7c478bd9Sstevel@tonic-gate }; 106*7c478bd9Sstevel@tonic-gate 107*7c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 108*7c478bd9Sstevel@tonic-gate MODREV_1, 109*7c478bd9Sstevel@tonic-gate &modlmisc, 110*7c478bd9Sstevel@tonic-gate NULL 111*7c478bd9Sstevel@tonic-gate }; 112*7c478bd9Sstevel@tonic-gate 113*7c478bd9Sstevel@tonic-gate int 114*7c478bd9Sstevel@tonic-gate _init(void) 115*7c478bd9Sstevel@tonic-gate { 116*7c478bd9Sstevel@tonic-gate return (mod_install(&modlinkage)); 117*7c478bd9Sstevel@tonic-gate } 118*7c478bd9Sstevel@tonic-gate 119*7c478bd9Sstevel@tonic-gate int 120*7c478bd9Sstevel@tonic-gate _fini(void) 121*7c478bd9Sstevel@tonic-gate { 122*7c478bd9Sstevel@tonic-gate return (mod_remove(&modlinkage)); 123*7c478bd9Sstevel@tonic-gate } 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate int 126*7c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 127*7c478bd9Sstevel@tonic-gate { 128*7c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 129*7c478bd9Sstevel@tonic-gate } 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate #define ARP "arp" 132*7c478bd9Sstevel@tonic-gate #define TCP "tcp" 133*7c478bd9Sstevel@tonic-gate #define TCP6 "tcp6" 134*7c478bd9Sstevel@tonic-gate #define UDP "udp" 135*7c478bd9Sstevel@tonic-gate #define UDP6 "udp6" 136*7c478bd9Sstevel@tonic-gate #define SCTP "sctp" 137*7c478bd9Sstevel@tonic-gate #define SCTP6 "sctp6" 138*7c478bd9Sstevel@tonic-gate #define ICMP "icmp" 139*7c478bd9Sstevel@tonic-gate #define ICMP6 "icmp6" 140*7c478bd9Sstevel@tonic-gate #define IP "ip" 141*7c478bd9Sstevel@tonic-gate #define IP6 "ip6" 142*7c478bd9Sstevel@tonic-gate #define TIMOD "timod" 143*7c478bd9Sstevel@tonic-gate 144*7c478bd9Sstevel@tonic-gate #define UDPDEV "/devices/pseudo/udp@0:udp" 145*7c478bd9Sstevel@tonic-gate #define TCP6DEV "/devices/pseudo/tcp6@0:tcp6" 146*7c478bd9Sstevel@tonic-gate #define SCTP6DEV "/devices/pseudo/sctp6@0:sctp6" 147*7c478bd9Sstevel@tonic-gate #define IP6DEV "/devices/pseudo/ip6@0:ip6" 148*7c478bd9Sstevel@tonic-gate 149*7c478bd9Sstevel@tonic-gate typedef struct strplumb_modspec { 150*7c478bd9Sstevel@tonic-gate char *sm_type; 151*7c478bd9Sstevel@tonic-gate char *sm_name; 152*7c478bd9Sstevel@tonic-gate } strplumb_modspec_t; 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate static strplumb_modspec_t strplumb_modlist[] = { 155*7c478bd9Sstevel@tonic-gate { "drv", DLD_DRIVER_NAME }, 156*7c478bd9Sstevel@tonic-gate { "drv", IP }, 157*7c478bd9Sstevel@tonic-gate { "drv", IP6 }, 158*7c478bd9Sstevel@tonic-gate { "drv", TCP }, 159*7c478bd9Sstevel@tonic-gate { "drv", TCP6 }, 160*7c478bd9Sstevel@tonic-gate { "drv", UDP }, 161*7c478bd9Sstevel@tonic-gate { "drv", UDP6 }, 162*7c478bd9Sstevel@tonic-gate { "drv", SCTP }, 163*7c478bd9Sstevel@tonic-gate { "drv", SCTP6 }, 164*7c478bd9Sstevel@tonic-gate { "drv", ICMP }, 165*7c478bd9Sstevel@tonic-gate { "drv", ICMP6 }, 166*7c478bd9Sstevel@tonic-gate { "drv", ARP }, 167*7c478bd9Sstevel@tonic-gate { "strmod", TIMOD } 168*7c478bd9Sstevel@tonic-gate }; 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate /* 171*7c478bd9Sstevel@tonic-gate * Called from swapgeneric.c:loadrootmodules() in the network boot case. 172*7c478bd9Sstevel@tonic-gate */ 173*7c478bd9Sstevel@tonic-gate int 174*7c478bd9Sstevel@tonic-gate strplumb_load(void) 175*7c478bd9Sstevel@tonic-gate { 176*7c478bd9Sstevel@tonic-gate uint_t i; 177*7c478bd9Sstevel@tonic-gate strplumb_modspec_t *p; 178*7c478bd9Sstevel@tonic-gate 179*7c478bd9Sstevel@tonic-gate DBG0("loading modules\n"); 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate for (i = 0, p = strplumb_modlist; 182*7c478bd9Sstevel@tonic-gate i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]); 183*7c478bd9Sstevel@tonic-gate i++, p++) { 184*7c478bd9Sstevel@tonic-gate if (modloadonly(p->sm_type, p->sm_name) < 0) { 185*7c478bd9Sstevel@tonic-gate printf("strplumb: failed to load %s/%s\n", 186*7c478bd9Sstevel@tonic-gate p->sm_type, p->sm_name); 187*7c478bd9Sstevel@tonic-gate return (EFAULT); 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate } 190*7c478bd9Sstevel@tonic-gate 191*7c478bd9Sstevel@tonic-gate return (0); 192*7c478bd9Sstevel@tonic-gate } 193*7c478bd9Sstevel@tonic-gate 194*7c478bd9Sstevel@tonic-gate static int 195*7c478bd9Sstevel@tonic-gate strplumb_init(void) 196*7c478bd9Sstevel@tonic-gate { 197*7c478bd9Sstevel@tonic-gate uint_t i; 198*7c478bd9Sstevel@tonic-gate strplumb_modspec_t *p; 199*7c478bd9Sstevel@tonic-gate int err; 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate DBG0("initializing modules\n"); 202*7c478bd9Sstevel@tonic-gate 203*7c478bd9Sstevel@tonic-gate for (i = 0, p = strplumb_modlist; 204*7c478bd9Sstevel@tonic-gate i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]); 205*7c478bd9Sstevel@tonic-gate i++, p++) { 206*7c478bd9Sstevel@tonic-gate if (strcmp(p->sm_type, "drv") == 0) 207*7c478bd9Sstevel@tonic-gate err = (i_ddi_attach_pseudo_node(p->sm_name) != NULL) ? 208*7c478bd9Sstevel@tonic-gate 0 : EFAULT; 209*7c478bd9Sstevel@tonic-gate else 210*7c478bd9Sstevel@tonic-gate err = (modload(p->sm_type, p->sm_name) < 0) ? 211*7c478bd9Sstevel@tonic-gate EFAULT : 0; 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate if (err != 0) { 214*7c478bd9Sstevel@tonic-gate printf("strplumb: failed to initialize %s/%s\n", 215*7c478bd9Sstevel@tonic-gate p->sm_type, p->sm_name); 216*7c478bd9Sstevel@tonic-gate return (err); 217*7c478bd9Sstevel@tonic-gate } 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate return (0); 221*7c478bd9Sstevel@tonic-gate } 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gate static int 224*7c478bd9Sstevel@tonic-gate strplumb_autopush(void) 225*7c478bd9Sstevel@tonic-gate { 226*7c478bd9Sstevel@tonic-gate major_t maj; 227*7c478bd9Sstevel@tonic-gate minor_t min; 228*7c478bd9Sstevel@tonic-gate char *mods[5]; 229*7c478bd9Sstevel@tonic-gate uint_t anchor = 1; 230*7c478bd9Sstevel@tonic-gate int err; 231*7c478bd9Sstevel@tonic-gate 232*7c478bd9Sstevel@tonic-gate min = (minor_t)-1; 233*7c478bd9Sstevel@tonic-gate mods[1] = NULL; 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate /* 236*7c478bd9Sstevel@tonic-gate * UDP 237*7c478bd9Sstevel@tonic-gate */ 238*7c478bd9Sstevel@tonic-gate DBG0("setting up udp autopush\n"); 239*7c478bd9Sstevel@tonic-gate 240*7c478bd9Sstevel@tonic-gate mods[0] = UDP; 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(UDP); 243*7c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, &anchor, 244*7c478bd9Sstevel@tonic-gate mods)) != 0) { 245*7c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/UDP) failed: %d\n", err); 246*7c478bd9Sstevel@tonic-gate return (err); 247*7c478bd9Sstevel@tonic-gate } 248*7c478bd9Sstevel@tonic-gate 249*7c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(UDP6); 250*7c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, &anchor, 251*7c478bd9Sstevel@tonic-gate mods)) != 0) { 252*7c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/UDP6) failed: %d\n", err); 253*7c478bd9Sstevel@tonic-gate return (err); 254*7c478bd9Sstevel@tonic-gate } 255*7c478bd9Sstevel@tonic-gate 256*7c478bd9Sstevel@tonic-gate /* 257*7c478bd9Sstevel@tonic-gate * ICMP 258*7c478bd9Sstevel@tonic-gate */ 259*7c478bd9Sstevel@tonic-gate DBG0("setting up icmp autopush\n"); 260*7c478bd9Sstevel@tonic-gate 261*7c478bd9Sstevel@tonic-gate mods[0] = ICMP; 262*7c478bd9Sstevel@tonic-gate 263*7c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(ICMP); 264*7c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, NULL, 265*7c478bd9Sstevel@tonic-gate mods)) != 0) { 266*7c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/ICMP) failed: %d\n", err); 267*7c478bd9Sstevel@tonic-gate return (err); 268*7c478bd9Sstevel@tonic-gate } 269*7c478bd9Sstevel@tonic-gate 270*7c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(ICMP6); 271*7c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, NULL, 272*7c478bd9Sstevel@tonic-gate mods)) != 0) { 273*7c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/ICMP6) failed: %d\n", err); 274*7c478bd9Sstevel@tonic-gate return (err); 275*7c478bd9Sstevel@tonic-gate } 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate /* 278*7c478bd9Sstevel@tonic-gate * ARP 279*7c478bd9Sstevel@tonic-gate */ 280*7c478bd9Sstevel@tonic-gate DBG0("setting up arp autopush\n"); 281*7c478bd9Sstevel@tonic-gate 282*7c478bd9Sstevel@tonic-gate mods[0] = ARP; 283*7c478bd9Sstevel@tonic-gate 284*7c478bd9Sstevel@tonic-gate maj = ddi_name_to_major(ARP); 285*7c478bd9Sstevel@tonic-gate if ((err = kstr_autopush(SET_AUTOPUSH, &maj, &min, NULL, &anchor, 286*7c478bd9Sstevel@tonic-gate mods)) != 0) { 287*7c478bd9Sstevel@tonic-gate printf("strplumb: kstr_autopush(SET/ARP) failed: %d\n", err); 288*7c478bd9Sstevel@tonic-gate return (err); 289*7c478bd9Sstevel@tonic-gate } 290*7c478bd9Sstevel@tonic-gate 291*7c478bd9Sstevel@tonic-gate return (0); 292*7c478bd9Sstevel@tonic-gate } 293*7c478bd9Sstevel@tonic-gate 294*7c478bd9Sstevel@tonic-gate static int 295*7c478bd9Sstevel@tonic-gate strplumb_sctpq(ldi_ident_t li) 296*7c478bd9Sstevel@tonic-gate { 297*7c478bd9Sstevel@tonic-gate ldi_handle_t lh = NULL; 298*7c478bd9Sstevel@tonic-gate int err; 299*7c478bd9Sstevel@tonic-gate int rval; 300*7c478bd9Sstevel@tonic-gate 301*7c478bd9Sstevel@tonic-gate DBG0("configuring SCTP default queue\n"); 302*7c478bd9Sstevel@tonic-gate 303*7c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(SCTP6DEV, FREAD|FWRITE, CRED(), &lh, 304*7c478bd9Sstevel@tonic-gate li)) != 0) { 305*7c478bd9Sstevel@tonic-gate printf("strplumb: open of SCTP6DEV failed: %d\n", err); 306*7c478bd9Sstevel@tonic-gate return (err); 307*7c478bd9Sstevel@tonic-gate } 308*7c478bd9Sstevel@tonic-gate 309*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, SCTP_IOC_DEFAULT_Q, (intptr_t)0, FKIOCTL, 310*7c478bd9Sstevel@tonic-gate CRED(), &rval)) != 0) { 311*7c478bd9Sstevel@tonic-gate printf("strplumb: failed to set SCTP default queue: %d\n", 312*7c478bd9Sstevel@tonic-gate err); 313*7c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 314*7c478bd9Sstevel@tonic-gate return (err); 315*7c478bd9Sstevel@tonic-gate } 316*7c478bd9Sstevel@tonic-gate 317*7c478bd9Sstevel@tonic-gate return (0); 318*7c478bd9Sstevel@tonic-gate } 319*7c478bd9Sstevel@tonic-gate 320*7c478bd9Sstevel@tonic-gate static int 321*7c478bd9Sstevel@tonic-gate strplumb_tcpq(ldi_ident_t li) 322*7c478bd9Sstevel@tonic-gate { 323*7c478bd9Sstevel@tonic-gate ldi_handle_t lh = NULL; 324*7c478bd9Sstevel@tonic-gate ldi_handle_t ip_lh = NULL; 325*7c478bd9Sstevel@tonic-gate int err; 326*7c478bd9Sstevel@tonic-gate int rval; 327*7c478bd9Sstevel@tonic-gate 328*7c478bd9Sstevel@tonic-gate DBG0("configuring TCP default queue\n"); 329*7c478bd9Sstevel@tonic-gate 330*7c478bd9Sstevel@tonic-gate /* 331*7c478bd9Sstevel@tonic-gate * We open IP6DEV here because we need to have it open to in 332*7c478bd9Sstevel@tonic-gate * order to open TCP6DEV successfully. 333*7c478bd9Sstevel@tonic-gate */ 334*7c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(IP6DEV, FREAD|FWRITE, CRED(), &ip_lh, 335*7c478bd9Sstevel@tonic-gate li)) != 0) { 336*7c478bd9Sstevel@tonic-gate printf("strplumb: open of IP6DEV failed: %d\n", err); 337*7c478bd9Sstevel@tonic-gate return (err); 338*7c478bd9Sstevel@tonic-gate } 339*7c478bd9Sstevel@tonic-gate 340*7c478bd9Sstevel@tonic-gate /* 341*7c478bd9Sstevel@tonic-gate * We set the tcp default queue to IPv6 because IPv4 falls back to 342*7c478bd9Sstevel@tonic-gate * IPv6 when it can't find a client, but IPv6 does not fall back to 343*7c478bd9Sstevel@tonic-gate * IPv4. 344*7c478bd9Sstevel@tonic-gate */ 345*7c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(TCP6DEV, FREAD|FWRITE, CRED(), &lh, 346*7c478bd9Sstevel@tonic-gate li)) != 0) { 347*7c478bd9Sstevel@tonic-gate printf("strplumb: open of TCP6DEV failed: %d\n", err); 348*7c478bd9Sstevel@tonic-gate goto done; 349*7c478bd9Sstevel@tonic-gate } 350*7c478bd9Sstevel@tonic-gate 351*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, TCP_IOC_DEFAULT_Q, (intptr_t)0, FKIOCTL, 352*7c478bd9Sstevel@tonic-gate CRED(), &rval)) != 0) { 353*7c478bd9Sstevel@tonic-gate printf("strplumb: failed to set TCP default queue: %d\n", 354*7c478bd9Sstevel@tonic-gate err); 355*7c478bd9Sstevel@tonic-gate goto done; 356*7c478bd9Sstevel@tonic-gate } 357*7c478bd9Sstevel@tonic-gate 358*7c478bd9Sstevel@tonic-gate done: 359*7c478bd9Sstevel@tonic-gate (void) ldi_close(ip_lh, FREAD|FWRITE, CRED()); 360*7c478bd9Sstevel@tonic-gate return (err); 361*7c478bd9Sstevel@tonic-gate } 362*7c478bd9Sstevel@tonic-gate 363*7c478bd9Sstevel@tonic-gate static int 364*7c478bd9Sstevel@tonic-gate create_gldv3_linkobj(ldi_ident_t li, char *driver, int instance) 365*7c478bd9Sstevel@tonic-gate { 366*7c478bd9Sstevel@tonic-gate ldi_handle_t lh; 367*7c478bd9Sstevel@tonic-gate int err; 368*7c478bd9Sstevel@tonic-gate struct strioctl iocb; 369*7c478bd9Sstevel@tonic-gate int rval; 370*7c478bd9Sstevel@tonic-gate dld_ioc_create_t dic; 371*7c478bd9Sstevel@tonic-gate 372*7c478bd9Sstevel@tonic-gate /* 373*7c478bd9Sstevel@tonic-gate * gld v3 driver. open the DLD control node. 374*7c478bd9Sstevel@tonic-gate */ 375*7c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(DLD_CONTROL_DEV, FREAD|FWRITE, CRED(), &lh, 376*7c478bd9Sstevel@tonic-gate li)) != 0) { 377*7c478bd9Sstevel@tonic-gate printf("strplumb: open CTLDEV failed: %d\n", err); 378*7c478bd9Sstevel@tonic-gate return (ENXIO); 379*7c478bd9Sstevel@tonic-gate } 380*7c478bd9Sstevel@tonic-gate 381*7c478bd9Sstevel@tonic-gate (void) snprintf(dic.dic_name, sizeof (dic.dic_name) - 1, "%s%d", 382*7c478bd9Sstevel@tonic-gate driver, instance); 383*7c478bd9Sstevel@tonic-gate (void) snprintf(dic.dic_dev, sizeof (dic.dic_dev) - 1, "%s%d", 384*7c478bd9Sstevel@tonic-gate driver, instance); 385*7c478bd9Sstevel@tonic-gate dic.dic_port = 0; 386*7c478bd9Sstevel@tonic-gate dic.dic_vid = 0; 387*7c478bd9Sstevel@tonic-gate 388*7c478bd9Sstevel@tonic-gate iocb.ic_cmd = DLDIOCCREATE; 389*7c478bd9Sstevel@tonic-gate iocb.ic_timout = 15; 390*7c478bd9Sstevel@tonic-gate iocb.ic_len = sizeof (dic); 391*7c478bd9Sstevel@tonic-gate iocb.ic_dp = (char *)&dic; 392*7c478bd9Sstevel@tonic-gate 393*7c478bd9Sstevel@tonic-gate /* 394*7c478bd9Sstevel@tonic-gate * Try to create a data-link interface with the same name as the 395*7c478bd9Sstevel@tonic-gate * device. 396*7c478bd9Sstevel@tonic-gate */ 397*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), 398*7c478bd9Sstevel@tonic-gate &rval)) != 0) { 399*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "strplumb: DLDIOCCREATE failed: %d\n", err); 400*7c478bd9Sstevel@tonic-gate return (ENXIO); 401*7c478bd9Sstevel@tonic-gate } 402*7c478bd9Sstevel@tonic-gate 403*7c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 404*7c478bd9Sstevel@tonic-gate return (0); 405*7c478bd9Sstevel@tonic-gate } 406*7c478bd9Sstevel@tonic-gate 407*7c478bd9Sstevel@tonic-gate /* 408*7c478bd9Sstevel@tonic-gate * Can be set in /etc/system in the case of local booting. See comment below. 409*7c478bd9Sstevel@tonic-gate */ 410*7c478bd9Sstevel@tonic-gate char *ndev_name = 0; 411*7c478bd9Sstevel@tonic-gate int ndev_unit = 0; 412*7c478bd9Sstevel@tonic-gate 413*7c478bd9Sstevel@tonic-gate /* 414*7c478bd9Sstevel@tonic-gate * If we booted diskless then strplumb() will have been called from 415*7c478bd9Sstevel@tonic-gate * swapgeneric.c:rootconf(). All we can do in that case is plumb the 416*7c478bd9Sstevel@tonic-gate * network device that we booted from. 417*7c478bd9Sstevel@tonic-gate * 418*7c478bd9Sstevel@tonic-gate * If we booted from a local disk, we will have been called from main(), 419*7c478bd9Sstevel@tonic-gate * and normally we defer the plumbing of interfaces until network/physical. 420*7c478bd9Sstevel@tonic-gate * This can be overridden by setting "ndev_name" in /etc/system. 421*7c478bd9Sstevel@tonic-gate */ 422*7c478bd9Sstevel@tonic-gate static int 423*7c478bd9Sstevel@tonic-gate resolve_boot_path(ldi_ident_t li) 424*7c478bd9Sstevel@tonic-gate { 425*7c478bd9Sstevel@tonic-gate char *devpath = NULL; 426*7c478bd9Sstevel@tonic-gate dev_info_t *dip; 427*7c478bd9Sstevel@tonic-gate const char *driver; 428*7c478bd9Sstevel@tonic-gate int instance; 429*7c478bd9Sstevel@tonic-gate int err; 430*7c478bd9Sstevel@tonic-gate 431*7c478bd9Sstevel@tonic-gate if (strncmp(rootfs.bo_fstype, "nfs", 3) == 0) 432*7c478bd9Sstevel@tonic-gate devpath = rootfs.bo_name; 433*7c478bd9Sstevel@tonic-gate #ifndef __sparc 434*7c478bd9Sstevel@tonic-gate else 435*7c478bd9Sstevel@tonic-gate devpath = strplumb_get_netdev_path(); 436*7c478bd9Sstevel@tonic-gate #endif 437*7c478bd9Sstevel@tonic-gate 438*7c478bd9Sstevel@tonic-gate if (devpath != NULL) { 439*7c478bd9Sstevel@tonic-gate DBG1("resolving boot-path: %s\n", devpath); 440*7c478bd9Sstevel@tonic-gate 441*7c478bd9Sstevel@tonic-gate /* 442*7c478bd9Sstevel@tonic-gate * Hold the devi since this is the root device. 443*7c478bd9Sstevel@tonic-gate */ 444*7c478bd9Sstevel@tonic-gate if ((dip = e_ddi_hold_devi_by_path(devpath, 0)) == NULL) { 445*7c478bd9Sstevel@tonic-gate printf("strplumb: unable to hold root device: %s\n", 446*7c478bd9Sstevel@tonic-gate devpath); 447*7c478bd9Sstevel@tonic-gate return (ENXIO); 448*7c478bd9Sstevel@tonic-gate } 449*7c478bd9Sstevel@tonic-gate 450*7c478bd9Sstevel@tonic-gate driver = ddi_driver_name(dip); 451*7c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip); 452*7c478bd9Sstevel@tonic-gate } else { 453*7c478bd9Sstevel@tonic-gate if (ndev_name == NULL) 454*7c478bd9Sstevel@tonic-gate return (ENODEV); 455*7c478bd9Sstevel@tonic-gate 456*7c478bd9Sstevel@tonic-gate DBG2("using ndev_name (%s) ndev_unit (%d)\n", ndev_name, 457*7c478bd9Sstevel@tonic-gate ndev_unit); 458*7c478bd9Sstevel@tonic-gate 459*7c478bd9Sstevel@tonic-gate if (i_ddi_attach_hw_nodes(ndev_name) != DDI_SUCCESS) { 460*7c478bd9Sstevel@tonic-gate printf("strplumb: cannot load ndev_name '%s'\n", 461*7c478bd9Sstevel@tonic-gate ndev_name); 462*7c478bd9Sstevel@tonic-gate return (ENXIO); 463*7c478bd9Sstevel@tonic-gate } 464*7c478bd9Sstevel@tonic-gate 465*7c478bd9Sstevel@tonic-gate driver = ndev_name; 466*7c478bd9Sstevel@tonic-gate instance = ndev_unit; 467*7c478bd9Sstevel@tonic-gate } 468*7c478bd9Sstevel@tonic-gate 469*7c478bd9Sstevel@tonic-gate /* legcy driver, use clone to open */ 470*7c478bd9Sstevel@tonic-gate if (!GLDV3_DRV(ddi_name_to_major((char *)driver))) { 471*7c478bd9Sstevel@tonic-gate (void) snprintf(rootfs.bo_devname, BO_MAXOBJNAME, 472*7c478bd9Sstevel@tonic-gate "/devices/pseudo/clone@0:%s", driver); 473*7c478bd9Sstevel@tonic-gate (void) snprintf(rootfs.bo_ifname, BO_MAXOBJNAME, "%s%d", 474*7c478bd9Sstevel@tonic-gate driver, instance); 475*7c478bd9Sstevel@tonic-gate rootfs.bo_ppa = instance; 476*7c478bd9Sstevel@tonic-gate return (0); 477*7c478bd9Sstevel@tonic-gate } 478*7c478bd9Sstevel@tonic-gate 479*7c478bd9Sstevel@tonic-gate /* GLDv3: create link object so open with succeed later */ 480*7c478bd9Sstevel@tonic-gate err = create_gldv3_linkobj(li, (char *)driver, instance); 481*7c478bd9Sstevel@tonic-gate if (err != 0) { 482*7c478bd9Sstevel@tonic-gate return (err); 483*7c478bd9Sstevel@tonic-gate } 484*7c478bd9Sstevel@tonic-gate 485*7c478bd9Sstevel@tonic-gate (void) snprintf(rootfs.bo_devname, BO_MAXOBJNAME, 486*7c478bd9Sstevel@tonic-gate "/devices/pseudo/dld@0:%s", driver); 487*7c478bd9Sstevel@tonic-gate (void) snprintf(rootfs.bo_ifname, BO_MAXOBJNAME, "%s%d", 488*7c478bd9Sstevel@tonic-gate driver, instance); 489*7c478bd9Sstevel@tonic-gate rootfs.bo_ppa = instance; 490*7c478bd9Sstevel@tonic-gate 491*7c478bd9Sstevel@tonic-gate return (err); 492*7c478bd9Sstevel@tonic-gate } 493*7c478bd9Sstevel@tonic-gate 494*7c478bd9Sstevel@tonic-gate static int 495*7c478bd9Sstevel@tonic-gate getifflags(ldi_handle_t lh, struct lifreq *lifrp) 496*7c478bd9Sstevel@tonic-gate { 497*7c478bd9Sstevel@tonic-gate struct strioctl iocb; 498*7c478bd9Sstevel@tonic-gate int rval; 499*7c478bd9Sstevel@tonic-gate 500*7c478bd9Sstevel@tonic-gate iocb.ic_cmd = SIOCGLIFFLAGS; 501*7c478bd9Sstevel@tonic-gate iocb.ic_timout = 15; 502*7c478bd9Sstevel@tonic-gate iocb.ic_len = sizeof (struct lifreq); 503*7c478bd9Sstevel@tonic-gate iocb.ic_dp = (char *)lifrp; 504*7c478bd9Sstevel@tonic-gate 505*7c478bd9Sstevel@tonic-gate return (ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), &rval)); 506*7c478bd9Sstevel@tonic-gate 507*7c478bd9Sstevel@tonic-gate } 508*7c478bd9Sstevel@tonic-gate 509*7c478bd9Sstevel@tonic-gate static int 510*7c478bd9Sstevel@tonic-gate setifname(ldi_handle_t lh, struct lifreq *lifrp) 511*7c478bd9Sstevel@tonic-gate { 512*7c478bd9Sstevel@tonic-gate struct strioctl iocb; 513*7c478bd9Sstevel@tonic-gate int rval; 514*7c478bd9Sstevel@tonic-gate 515*7c478bd9Sstevel@tonic-gate iocb.ic_cmd = SIOCSLIFNAME; 516*7c478bd9Sstevel@tonic-gate iocb.ic_timout = 15; 517*7c478bd9Sstevel@tonic-gate iocb.ic_len = sizeof (struct lifreq); 518*7c478bd9Sstevel@tonic-gate iocb.ic_dp = (char *)lifrp; 519*7c478bd9Sstevel@tonic-gate 520*7c478bd9Sstevel@tonic-gate return (ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), &rval)); 521*7c478bd9Sstevel@tonic-gate } 522*7c478bd9Sstevel@tonic-gate 523*7c478bd9Sstevel@tonic-gate static int 524*7c478bd9Sstevel@tonic-gate strplumb_dev(ldi_ident_t li) 525*7c478bd9Sstevel@tonic-gate { 526*7c478bd9Sstevel@tonic-gate ldi_handle_t lh = NULL; 527*7c478bd9Sstevel@tonic-gate ldi_handle_t mux_lh = NULL; 528*7c478bd9Sstevel@tonic-gate int err; 529*7c478bd9Sstevel@tonic-gate struct lifreq lifr; 530*7c478bd9Sstevel@tonic-gate struct ifreq ifr; 531*7c478bd9Sstevel@tonic-gate int rval; 532*7c478bd9Sstevel@tonic-gate 533*7c478bd9Sstevel@tonic-gate bzero(&lifr, sizeof (struct lifreq)); 534*7c478bd9Sstevel@tonic-gate bzero(&ifr, sizeof (ifr)); 535*7c478bd9Sstevel@tonic-gate 536*7c478bd9Sstevel@tonic-gate /* 537*7c478bd9Sstevel@tonic-gate * Now set up the links. Ultimately, we should have two streams 538*7c478bd9Sstevel@tonic-gate * permanently linked underneath UDP (which is actually IP with UDP 539*7c478bd9Sstevel@tonic-gate * autopushed). One stream consists of the ARP-[ifname] combination, 540*7c478bd9Sstevel@tonic-gate * while the other consists of ARP-IP-[ifname]. The second combination 541*7c478bd9Sstevel@tonic-gate * seems a little weird, but is linked underneath UDP just to keep it 542*7c478bd9Sstevel@tonic-gate * around. 543*7c478bd9Sstevel@tonic-gate * 544*7c478bd9Sstevel@tonic-gate * We pin underneath UDP here to match what is done in ifconfig(1m); 545*7c478bd9Sstevel@tonic-gate * otherwise, ifconfig will be unable to unplumb the stream (the major 546*7c478bd9Sstevel@tonic-gate * number and mux id must both match for a successful I_PUNLINK). 547*7c478bd9Sstevel@tonic-gate * 548*7c478bd9Sstevel@tonic-gate * There are subtleties in the plumbing which make it essential to 549*7c478bd9Sstevel@tonic-gate * follow the logic used in ifconfig(1m) very closely. 550*7c478bd9Sstevel@tonic-gate */ 551*7c478bd9Sstevel@tonic-gate 552*7c478bd9Sstevel@tonic-gate /* 553*7c478bd9Sstevel@tonic-gate * Plumb UDP-ARP-IP-<dev> 554*7c478bd9Sstevel@tonic-gate */ 555*7c478bd9Sstevel@tonic-gate 556*7c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(rootfs.bo_devname, FREAD|FWRITE, CRED(), 557*7c478bd9Sstevel@tonic-gate &lh, li)) != 0) { 558*7c478bd9Sstevel@tonic-gate printf("strplumb: open %s failed: %d\n", rootfs.bo_devname, 559*7c478bd9Sstevel@tonic-gate err); 560*7c478bd9Sstevel@tonic-gate goto done; 561*7c478bd9Sstevel@tonic-gate } 562*7c478bd9Sstevel@tonic-gate 563*7c478bd9Sstevel@tonic-gate 564*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)IP, FKIOCTL, CRED(), 565*7c478bd9Sstevel@tonic-gate &rval)) != 0) { 566*7c478bd9Sstevel@tonic-gate printf("strplumb: push IP failed: %d\n", err); 567*7c478bd9Sstevel@tonic-gate goto done; 568*7c478bd9Sstevel@tonic-gate } 569*7c478bd9Sstevel@tonic-gate 570*7c478bd9Sstevel@tonic-gate if ((err = getifflags(lh, &lifr)) != 0) 571*7c478bd9Sstevel@tonic-gate goto done; 572*7c478bd9Sstevel@tonic-gate 573*7c478bd9Sstevel@tonic-gate lifr.lifr_flags |= IFF_IPV4; 574*7c478bd9Sstevel@tonic-gate lifr.lifr_flags &= ~IFF_IPV6; 575*7c478bd9Sstevel@tonic-gate 576*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)ARP, FKIOCTL, CRED(), 577*7c478bd9Sstevel@tonic-gate &rval)) != 0) { 578*7c478bd9Sstevel@tonic-gate printf("strplumb: push ARP failed: %d\n", err); 579*7c478bd9Sstevel@tonic-gate goto done; 580*7c478bd9Sstevel@tonic-gate } 581*7c478bd9Sstevel@tonic-gate 582*7c478bd9Sstevel@tonic-gate (void) strlcpy(lifr.lifr_name, rootfs.bo_ifname, 583*7c478bd9Sstevel@tonic-gate sizeof (lifr.lifr_name)); 584*7c478bd9Sstevel@tonic-gate lifr.lifr_ppa = rootfs.bo_ppa; 585*7c478bd9Sstevel@tonic-gate 586*7c478bd9Sstevel@tonic-gate if ((err = setifname(lh, &lifr)) != 0) 587*7c478bd9Sstevel@tonic-gate goto done; 588*7c478bd9Sstevel@tonic-gate 589*7c478bd9Sstevel@tonic-gate /* Get the flags and check if ARP is needed */ 590*7c478bd9Sstevel@tonic-gate if ((err = getifflags(lh, &lifr)) != 0) { 591*7c478bd9Sstevel@tonic-gate printf("strplumb: getifflags %s IP failed, error %d\n", 592*7c478bd9Sstevel@tonic-gate lifr.lifr_name, err); 593*7c478bd9Sstevel@tonic-gate goto done; 594*7c478bd9Sstevel@tonic-gate } 595*7c478bd9Sstevel@tonic-gate 596*7c478bd9Sstevel@tonic-gate /* Pop out ARP if not needed */ 597*7c478bd9Sstevel@tonic-gate if (lifr.lifr_flags & IFF_NOARP) { 598*7c478bd9Sstevel@tonic-gate err = ldi_ioctl(lh, I_POP, (intptr_t)0, FKIOCTL, CRED(), 599*7c478bd9Sstevel@tonic-gate &rval); 600*7c478bd9Sstevel@tonic-gate if (err != 0) { 601*7c478bd9Sstevel@tonic-gate printf("strplumb: pop ARP failed, error %d\n", err); 602*7c478bd9Sstevel@tonic-gate goto done; 603*7c478bd9Sstevel@tonic-gate } 604*7c478bd9Sstevel@tonic-gate } 605*7c478bd9Sstevel@tonic-gate 606*7c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(UDPDEV, FREAD|FWRITE, CRED(), &mux_lh, 607*7c478bd9Sstevel@tonic-gate li)) != 0) { 608*7c478bd9Sstevel@tonic-gate printf("strplumb: open of UDPDEV failed: %d\n", err); 609*7c478bd9Sstevel@tonic-gate goto done; 610*7c478bd9Sstevel@tonic-gate } 611*7c478bd9Sstevel@tonic-gate 612*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(mux_lh, I_PLINK, (intptr_t)lh, 613*7c478bd9Sstevel@tonic-gate FREAD|FWRITE|FNOCTTY|FKIOCTL, CRED(), 614*7c478bd9Sstevel@tonic-gate &(ifr.ifr_ip_muxid))) != 0) { 615*7c478bd9Sstevel@tonic-gate printf("strplumb: plink UDP-ARP-IP-%s failed: %d\n", 616*7c478bd9Sstevel@tonic-gate rootfs.bo_ifname, err); 617*7c478bd9Sstevel@tonic-gate goto done; 618*7c478bd9Sstevel@tonic-gate } 619*7c478bd9Sstevel@tonic-gate 620*7c478bd9Sstevel@tonic-gate DBG2("UDP-ARP-IP-%s muxid: %d\n", rootfs.bo_ifname, ifr.ifr_ip_muxid); 621*7c478bd9Sstevel@tonic-gate 622*7c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 623*7c478bd9Sstevel@tonic-gate lh = NULL; 624*7c478bd9Sstevel@tonic-gate 625*7c478bd9Sstevel@tonic-gate /* 626*7c478bd9Sstevel@tonic-gate * Plumb UDP-ARP-<dev> 627*7c478bd9Sstevel@tonic-gate */ 628*7c478bd9Sstevel@tonic-gate 629*7c478bd9Sstevel@tonic-gate if ((err = ldi_open_by_name(rootfs.bo_devname, FREAD|FWRITE, CRED(), 630*7c478bd9Sstevel@tonic-gate &lh, li)) != 0) { 631*7c478bd9Sstevel@tonic-gate printf("strplumb: open %s failed: %d\n", rootfs.bo_devname, 632*7c478bd9Sstevel@tonic-gate err); 633*7c478bd9Sstevel@tonic-gate goto done; 634*7c478bd9Sstevel@tonic-gate } 635*7c478bd9Sstevel@tonic-gate 636*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)ARP, FKIOCTL, CRED(), 637*7c478bd9Sstevel@tonic-gate &rval)) != 0) { 638*7c478bd9Sstevel@tonic-gate printf("strplumb: push ARP failed: %d\n", err); 639*7c478bd9Sstevel@tonic-gate goto done; 640*7c478bd9Sstevel@tonic-gate } 641*7c478bd9Sstevel@tonic-gate 642*7c478bd9Sstevel@tonic-gate if ((err = setifname(lh, &lifr)) != 0) 643*7c478bd9Sstevel@tonic-gate goto done; 644*7c478bd9Sstevel@tonic-gate 645*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(mux_lh, I_PLINK, (intptr_t)lh, 646*7c478bd9Sstevel@tonic-gate FREAD|FWRITE|FNOCTTY|FKIOCTL, CRED(), 647*7c478bd9Sstevel@tonic-gate &(ifr.ifr_arp_muxid))) != 0) { 648*7c478bd9Sstevel@tonic-gate printf("strplumb: plink UDP-ARP-%s failed: %d\n", 649*7c478bd9Sstevel@tonic-gate rootfs.bo_ifname, err); 650*7c478bd9Sstevel@tonic-gate goto done; 651*7c478bd9Sstevel@tonic-gate } 652*7c478bd9Sstevel@tonic-gate 653*7c478bd9Sstevel@tonic-gate DBG2("UDP-ARP-%s muxid: %d\n", rootfs.bo_ifname, ifr.ifr_arp_muxid); 654*7c478bd9Sstevel@tonic-gate 655*7c478bd9Sstevel@tonic-gate /* 656*7c478bd9Sstevel@tonic-gate * Cache the mux ids. 657*7c478bd9Sstevel@tonic-gate */ 658*7c478bd9Sstevel@tonic-gate (void) strlcpy(ifr.ifr_name, rootfs.bo_ifname, sizeof (ifr.ifr_name)); 659*7c478bd9Sstevel@tonic-gate 660*7c478bd9Sstevel@tonic-gate if ((err = ldi_ioctl(mux_lh, SIOCSIFMUXID, (intptr_t)&ifr, FKIOCTL, 661*7c478bd9Sstevel@tonic-gate CRED(), &rval)) != 0) { 662*7c478bd9Sstevel@tonic-gate printf("strplumb: SIOCSIFMUXID failed: %d\n", err); 663*7c478bd9Sstevel@tonic-gate goto done; 664*7c478bd9Sstevel@tonic-gate } 665*7c478bd9Sstevel@tonic-gate 666*7c478bd9Sstevel@tonic-gate done: 667*7c478bd9Sstevel@tonic-gate if (lh != NULL) 668*7c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 669*7c478bd9Sstevel@tonic-gate 670*7c478bd9Sstevel@tonic-gate if (mux_lh != NULL) 671*7c478bd9Sstevel@tonic-gate (void) ldi_close(mux_lh, FREAD|FWRITE, CRED()); 672*7c478bd9Sstevel@tonic-gate 673*7c478bd9Sstevel@tonic-gate return (err); 674*7c478bd9Sstevel@tonic-gate } 675*7c478bd9Sstevel@tonic-gate 676*7c478bd9Sstevel@tonic-gate /* 677*7c478bd9Sstevel@tonic-gate * Do streams plumbing for internet protocols. 678*7c478bd9Sstevel@tonic-gate */ 679*7c478bd9Sstevel@tonic-gate int 680*7c478bd9Sstevel@tonic-gate strplumb(void) 681*7c478bd9Sstevel@tonic-gate { 682*7c478bd9Sstevel@tonic-gate ldi_ident_t li; 683*7c478bd9Sstevel@tonic-gate int err; 684*7c478bd9Sstevel@tonic-gate 685*7c478bd9Sstevel@tonic-gate if ((err = strplumb_init()) != 0) 686*7c478bd9Sstevel@tonic-gate return (err); 687*7c478bd9Sstevel@tonic-gate 688*7c478bd9Sstevel@tonic-gate if ((err = strplumb_autopush()) != 0) 689*7c478bd9Sstevel@tonic-gate return (err); 690*7c478bd9Sstevel@tonic-gate 691*7c478bd9Sstevel@tonic-gate if ((err = ldi_ident_from_mod(&modlinkage, &li)) != 0) 692*7c478bd9Sstevel@tonic-gate return (err); 693*7c478bd9Sstevel@tonic-gate 694*7c478bd9Sstevel@tonic-gate if ((err = strplumb_sctpq(li)) != 0) 695*7c478bd9Sstevel@tonic-gate goto done; 696*7c478bd9Sstevel@tonic-gate 697*7c478bd9Sstevel@tonic-gate if ((err = strplumb_tcpq(li)) != 0) 698*7c478bd9Sstevel@tonic-gate goto done; 699*7c478bd9Sstevel@tonic-gate 700*7c478bd9Sstevel@tonic-gate if ((err = resolve_boot_path(li)) != 0) 701*7c478bd9Sstevel@tonic-gate goto done; 702*7c478bd9Sstevel@tonic-gate 703*7c478bd9Sstevel@tonic-gate DBG1("rootfs.bo_devname: %s\n", rootfs.bo_devname); 704*7c478bd9Sstevel@tonic-gate DBG1("rootfs.bo_ifname: %s\n", rootfs.bo_ifname); 705*7c478bd9Sstevel@tonic-gate DBG1("rootfs.bo_ppa: %d\n", rootfs.bo_ppa); 706*7c478bd9Sstevel@tonic-gate 707*7c478bd9Sstevel@tonic-gate if ((err = strplumb_dev(li)) != 0) 708*7c478bd9Sstevel@tonic-gate goto done; 709*7c478bd9Sstevel@tonic-gate 710*7c478bd9Sstevel@tonic-gate done: 711*7c478bd9Sstevel@tonic-gate ldi_ident_release(li); 712*7c478bd9Sstevel@tonic-gate 713*7c478bd9Sstevel@tonic-gate return (err); 714*7c478bd9Sstevel@tonic-gate } 715*7c478bd9Sstevel@tonic-gate 716*7c478bd9Sstevel@tonic-gate /* multiboot: diskless boot interface discovery */ 717*7c478bd9Sstevel@tonic-gate 718*7c478bd9Sstevel@tonic-gate #ifndef __sparc 719*7c478bd9Sstevel@tonic-gate 720*7c478bd9Sstevel@tonic-gate static uchar_t boot_macaddr[16]; 721*7c478bd9Sstevel@tonic-gate static int boot_maclen; 722*7c478bd9Sstevel@tonic-gate static uchar_t *getmacaddr(dev_info_t *dip, int *maclen); 723*7c478bd9Sstevel@tonic-gate static int matchmac(dev_info_t *dip, void *arg); 724*7c478bd9Sstevel@tonic-gate extern int dl_attach(ldi_handle_t lh, int unit); 725*7c478bd9Sstevel@tonic-gate extern int dl_bind(ldi_handle_t lh, uint_t sap, uint_t max_conn, 726*7c478bd9Sstevel@tonic-gate uint_t service, uint_t conn_mgmt); 727*7c478bd9Sstevel@tonic-gate extern int dl_phys_addr(ldi_handle_t lh, struct ether_addr *eaddr); 728*7c478bd9Sstevel@tonic-gate 729*7c478bd9Sstevel@tonic-gate char * 730*7c478bd9Sstevel@tonic-gate strplumb_get_netdev_path(void) 731*7c478bd9Sstevel@tonic-gate { 732*7c478bd9Sstevel@tonic-gate char *macstr, *devpath = NULL; 733*7c478bd9Sstevel@tonic-gate uchar_t *bootp; 734*7c478bd9Sstevel@tonic-gate uint_t bootp_len, len; 735*7c478bd9Sstevel@tonic-gate 736*7c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 737*7c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, BP_BOOT_MAC, &macstr) == DDI_SUCCESS) { 738*7c478bd9Sstevel@tonic-gate /* 739*7c478bd9Sstevel@tonic-gate * hard coded ether mac len for booting floppy on 740*7c478bd9Sstevel@tonic-gate * machines with old cards 741*7c478bd9Sstevel@tonic-gate */ 742*7c478bd9Sstevel@tonic-gate boot_maclen = ether_aton(macstr, boot_macaddr); 743*7c478bd9Sstevel@tonic-gate if (boot_maclen != 6) { 744*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 745*7c478bd9Sstevel@tonic-gate "malformed boot_mac property, %d bytes", 746*7c478bd9Sstevel@tonic-gate boot_maclen); 747*7c478bd9Sstevel@tonic-gate } 748*7c478bd9Sstevel@tonic-gate ddi_prop_free(macstr); 749*7c478bd9Sstevel@tonic-gate } else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ddi_root_node(), 750*7c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, BP_BOOTP_RESPONSE, &bootp, &bootp_len) 751*7c478bd9Sstevel@tonic-gate == DDI_SUCCESS) { 752*7c478bd9Sstevel@tonic-gate 753*7c478bd9Sstevel@tonic-gate /* 754*7c478bd9Sstevel@tonic-gate * These offsets are defined by dhcp standard 755*7c478bd9Sstevel@tonic-gate * Should use structure offsets 756*7c478bd9Sstevel@tonic-gate */ 757*7c478bd9Sstevel@tonic-gate boot_maclen = *(bootp + 2); 758*7c478bd9Sstevel@tonic-gate ASSERT(boot_maclen <= 16); 759*7c478bd9Sstevel@tonic-gate (void) bcopy(bootp + 28, boot_macaddr, boot_maclen); 760*7c478bd9Sstevel@tonic-gate 761*7c478bd9Sstevel@tonic-gate /* encode to ascii string to match what sparc OBP exports */ 762*7c478bd9Sstevel@tonic-gate dhcack = kmem_alloc(bootp_len * 2 + IFNAMSIZ + 2, KM_SLEEP); 763*7c478bd9Sstevel@tonic-gate (void) octet_to_hexascii(bootp, bootp_len, dhcack + IFNAMSIZ, 764*7c478bd9Sstevel@tonic-gate &len); 765*7c478bd9Sstevel@tonic-gate ASSERT(len < bootp_len * 2 + 2); 766*7c478bd9Sstevel@tonic-gate ddi_prop_free(bootp); 767*7c478bd9Sstevel@tonic-gate } else 768*7c478bd9Sstevel@tonic-gate return (NULL); 769*7c478bd9Sstevel@tonic-gate 770*7c478bd9Sstevel@tonic-gate ddi_walk_devs(ddi_root_node(), matchmac, (void *)&devpath); 771*7c478bd9Sstevel@tonic-gate return (devpath); 772*7c478bd9Sstevel@tonic-gate } 773*7c478bd9Sstevel@tonic-gate 774*7c478bd9Sstevel@tonic-gate /* 775*7c478bd9Sstevel@tonic-gate * Get boot path from the boot_mac address 776*7c478bd9Sstevel@tonic-gate */ 777*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 778*7c478bd9Sstevel@tonic-gate static int 779*7c478bd9Sstevel@tonic-gate matchmac(dev_info_t *dip, void *arg) 780*7c478bd9Sstevel@tonic-gate { 781*7c478bd9Sstevel@tonic-gate char **devpathp = (char **)arg; 782*7c478bd9Sstevel@tonic-gate char *model_str; 783*7c478bd9Sstevel@tonic-gate uchar_t *macaddr; 784*7c478bd9Sstevel@tonic-gate int maclen; 785*7c478bd9Sstevel@tonic-gate 786*7c478bd9Sstevel@tonic-gate /* XXX Should use "device-type" per IEEE 1275 */ 787*7c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0, 788*7c478bd9Sstevel@tonic-gate "model", &model_str) != DDI_SUCCESS) 789*7c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 790*7c478bd9Sstevel@tonic-gate 791*7c478bd9Sstevel@tonic-gate if (strcmp(model_str, "Ethernet controller") != 0) { 792*7c478bd9Sstevel@tonic-gate ddi_prop_free(model_str); 793*7c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 794*7c478bd9Sstevel@tonic-gate } 795*7c478bd9Sstevel@tonic-gate ddi_prop_free(model_str); 796*7c478bd9Sstevel@tonic-gate 797*7c478bd9Sstevel@tonic-gate /* We have a network device now */ 798*7c478bd9Sstevel@tonic-gate if (i_ddi_attach_node_hierarchy(dip) != DDI_SUCCESS) { 799*7c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 800*7c478bd9Sstevel@tonic-gate } 801*7c478bd9Sstevel@tonic-gate 802*7c478bd9Sstevel@tonic-gate ASSERT(boot_maclen != 0); 803*7c478bd9Sstevel@tonic-gate macaddr = getmacaddr(dip, &maclen); 804*7c478bd9Sstevel@tonic-gate if (macaddr == NULL) 805*7c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 806*7c478bd9Sstevel@tonic-gate 807*7c478bd9Sstevel@tonic-gate if (maclen != boot_maclen || 808*7c478bd9Sstevel@tonic-gate bcmp(macaddr, boot_macaddr, maclen) != 0) { 809*7c478bd9Sstevel@tonic-gate kmem_free(macaddr, maclen); 810*7c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 811*7c478bd9Sstevel@tonic-gate } 812*7c478bd9Sstevel@tonic-gate 813*7c478bd9Sstevel@tonic-gate /* found hardware with the mac address */ 814*7c478bd9Sstevel@tonic-gate (void) localetheraddr((struct ether_addr *)macaddr, NULL); 815*7c478bd9Sstevel@tonic-gate kmem_free(macaddr, maclen); 816*7c478bd9Sstevel@tonic-gate 817*7c478bd9Sstevel@tonic-gate *devpathp = kmem_alloc(MAXPATHLEN, KM_SLEEP); 818*7c478bd9Sstevel@tonic-gate (void) ddi_pathname(dip, *devpathp); 819*7c478bd9Sstevel@tonic-gate 820*7c478bd9Sstevel@tonic-gate /* fill in the name portion of dhcack */ 821*7c478bd9Sstevel@tonic-gate if (dhcack) 822*7c478bd9Sstevel@tonic-gate (void) snprintf(dhcack, IFNAMSIZ, "%s%d", 823*7c478bd9Sstevel@tonic-gate ddi_driver_name(dip), i_ddi_devi_get_ppa(dip)); 824*7c478bd9Sstevel@tonic-gate return (DDI_WALK_TERMINATE); 825*7c478bd9Sstevel@tonic-gate } 826*7c478bd9Sstevel@tonic-gate 827*7c478bd9Sstevel@tonic-gate static uchar_t * 828*7c478bd9Sstevel@tonic-gate getmacaddr_gldv3(char *drv, int inst, int *maclenp) 829*7c478bd9Sstevel@tonic-gate { 830*7c478bd9Sstevel@tonic-gate char ifname[16]; 831*7c478bd9Sstevel@tonic-gate mac_handle_t mh; 832*7c478bd9Sstevel@tonic-gate uchar_t *macaddr; 833*7c478bd9Sstevel@tonic-gate 834*7c478bd9Sstevel@tonic-gate (void) snprintf(ifname, sizeof (ifname), "%s%d", drv, inst); 835*7c478bd9Sstevel@tonic-gate if (mac_open(ifname, 0, &mh) < 0) { 836*7c478bd9Sstevel@tonic-gate return (NULL); 837*7c478bd9Sstevel@tonic-gate } 838*7c478bd9Sstevel@tonic-gate *maclenp = sizeof (struct ether_addr); 839*7c478bd9Sstevel@tonic-gate macaddr = kmem_alloc(*maclenp, KM_SLEEP); 840*7c478bd9Sstevel@tonic-gate mac_unicst_get(mh, macaddr); 841*7c478bd9Sstevel@tonic-gate mac_close(mh); 842*7c478bd9Sstevel@tonic-gate 843*7c478bd9Sstevel@tonic-gate return (macaddr); 844*7c478bd9Sstevel@tonic-gate } 845*7c478bd9Sstevel@tonic-gate 846*7c478bd9Sstevel@tonic-gate static uchar_t * 847*7c478bd9Sstevel@tonic-gate getmacaddr(dev_info_t *dip, int *maclenp) 848*7c478bd9Sstevel@tonic-gate { 849*7c478bd9Sstevel@tonic-gate int rc, ppa; 850*7c478bd9Sstevel@tonic-gate ldi_ident_t li; 851*7c478bd9Sstevel@tonic-gate ldi_handle_t lh; 852*7c478bd9Sstevel@tonic-gate char *drv_name = (char *)ddi_driver_name(dip); 853*7c478bd9Sstevel@tonic-gate char *clonepath; 854*7c478bd9Sstevel@tonic-gate uchar_t *macaddr = NULL; 855*7c478bd9Sstevel@tonic-gate 856*7c478bd9Sstevel@tonic-gate /* a simpler way to get mac address for GLDv3 drivers */ 857*7c478bd9Sstevel@tonic-gate if (GLDV3_DRV(ddi_name_to_major(drv_name))) { 858*7c478bd9Sstevel@tonic-gate return (getmacaddr_gldv3(drv_name, ddi_get_instance(dip), 859*7c478bd9Sstevel@tonic-gate maclenp)); 860*7c478bd9Sstevel@tonic-gate } 861*7c478bd9Sstevel@tonic-gate 862*7c478bd9Sstevel@tonic-gate if (rc = ldi_ident_from_mod(&modlinkage, &li)) { 863*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 864*7c478bd9Sstevel@tonic-gate "getmacaddr: ldi_ident_from_mod failed: %d\n", rc); 865*7c478bd9Sstevel@tonic-gate return (NULL); 866*7c478bd9Sstevel@tonic-gate } 867*7c478bd9Sstevel@tonic-gate 868*7c478bd9Sstevel@tonic-gate clonepath = kmem_alloc(MAXPATHLEN, KM_SLEEP); 869*7c478bd9Sstevel@tonic-gate (void) snprintf(clonepath, MAXPATHLEN, 870*7c478bd9Sstevel@tonic-gate "/devices/pseudo/clone@0:%s", drv_name); 871*7c478bd9Sstevel@tonic-gate 872*7c478bd9Sstevel@tonic-gate rc = ldi_open_by_name(clonepath, FREAD|FWRITE, CRED(), &lh, li); 873*7c478bd9Sstevel@tonic-gate ldi_ident_release(li); 874*7c478bd9Sstevel@tonic-gate if (rc) { 875*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 876*7c478bd9Sstevel@tonic-gate "getmacaddr: ldi_open_by_name(%s) failed: %d\n", 877*7c478bd9Sstevel@tonic-gate clonepath, rc); 878*7c478bd9Sstevel@tonic-gate kmem_free(clonepath, MAXPATHLEN); 879*7c478bd9Sstevel@tonic-gate return (NULL); 880*7c478bd9Sstevel@tonic-gate } 881*7c478bd9Sstevel@tonic-gate kmem_free(clonepath, MAXPATHLEN); 882*7c478bd9Sstevel@tonic-gate 883*7c478bd9Sstevel@tonic-gate ppa = i_ddi_devi_get_ppa(dip); 884*7c478bd9Sstevel@tonic-gate if ((dl_attach(lh, ppa) != 0) || 885*7c478bd9Sstevel@tonic-gate (dl_bind(lh, ETHERTYPE_IP, 0, DL_CLDLS, 0) != 0)) { 886*7c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 887*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 888*7c478bd9Sstevel@tonic-gate "getmacaddr: dl_attach/bind(%s%d) failed: %d\n", 889*7c478bd9Sstevel@tonic-gate drv_name, ppa, rc); 890*7c478bd9Sstevel@tonic-gate return (NULL); 891*7c478bd9Sstevel@tonic-gate } 892*7c478bd9Sstevel@tonic-gate *maclenp = sizeof (struct ether_addr); 893*7c478bd9Sstevel@tonic-gate macaddr = kmem_alloc(*maclenp, KM_SLEEP); 894*7c478bd9Sstevel@tonic-gate if (dl_phys_addr(lh, (struct ether_addr *)macaddr) != 0) { 895*7c478bd9Sstevel@tonic-gate kmem_free(macaddr, *maclenp); 896*7c478bd9Sstevel@tonic-gate macaddr = NULL; 897*7c478bd9Sstevel@tonic-gate *maclenp = 0; 898*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 899*7c478bd9Sstevel@tonic-gate "getmacaddr: dl_macaddr(%s%d) failed: %d\n", 900*7c478bd9Sstevel@tonic-gate drv_name, ppa, rc); 901*7c478bd9Sstevel@tonic-gate } 902*7c478bd9Sstevel@tonic-gate (void) ldi_close(lh, FREAD|FWRITE, CRED()); 903*7c478bd9Sstevel@tonic-gate return (macaddr); 904*7c478bd9Sstevel@tonic-gate } 905*7c478bd9Sstevel@tonic-gate 906*7c478bd9Sstevel@tonic-gate #endif /* !__sparc */ 907