Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/io/strplumb.c
+++ new/usr/src/uts/common/io/strplumb.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/param.h>
27 27 #include <sys/types.h>
28 28 #include <sys/user.h>
29 29 #include <sys/vfs.h>
30 30 #include <sys/vnode.h>
31 31 #include <sys/file.h>
32 32 #include <sys/stream.h>
33 33 #include <sys/stropts.h>
34 34 #include <sys/strsubr.h>
35 35 #include <sys/dlpi.h>
36 36 #include <sys/vnode.h>
37 37 #include <sys/socket.h>
38 38 #include <sys/sockio.h>
39 39 #include <net/if.h>
40 40
41 41 #include <sys/cred.h>
42 42 #include <sys/sysmacros.h>
43 43
44 44 #include <sys/sad.h>
45 45 #include <sys/kstr.h>
46 46 #include <sys/bootconf.h>
47 47 #include <sys/bootprops.h>
48 48
49 49 #include <sys/errno.h>
50 50 #include <sys/modctl.h>
51 51 #include <sys/sunddi.h>
52 52 #include <sys/sunldi.h>
53 53 #include <sys/esunddi.h>
54 54 #include <sys/promif.h>
55 55
56 56 #include <sys/strlog.h>
57 57 #include <sys/log.h>
58 58 #include <sys/ethernet.h>
59 59 #include <sys/ddi_implfuncs.h>
60 60
61 61 #include <sys/dld.h>
62 62 #include <sys/mac_client.h>
63 63
64 64 /*
65 65 * Debug Macros
66 66 */
67 67 int strplumbdebug = 0;
68 68
69 69 extern ib_boot_prop_t *iscsiboot_prop;
70 70
71 71 #define DBG0(_f) \
72 72 if (strplumbdebug != 0) \
73 73 printf("strplumb: " _f)
74 74
75 75 #define DBG1(_f, _a) \
76 76 if (strplumbdebug != 0) \
77 77 printf("strplumb: " _f, (_a))
78 78
79 79 #define DBG2(_f, _a, _b) \
80 80 if (strplumbdebug != 0) \
81 81 printf("strplumb: " _f, (_a), (_b))
82 82
83 83 #define DBG3(_f, _a, _b, _c) \
84 84 if (strplumbdebug != 0) \
85 85 printf("strplumb: " _f, (_a), (_b), (_c))
86 86
87 87 /*
88 88 * Module linkage information for the kernel.
↓ open down ↓ |
88 lines elided |
↑ open up ↑ |
89 89 */
90 90 #define STRPLUMB_IDENT "STREAMS Plumbing Module"
91 91
92 92 static struct modlmisc modlmisc = {
93 93 &mod_miscops,
94 94 STRPLUMB_IDENT
95 95 };
96 96
97 97 static struct modlinkage modlinkage = {
98 98 MODREV_1,
99 - &modlmisc,
100 - NULL
99 + { &modlmisc, NULL }
101 100 };
102 101
103 102 int
104 103 _init(void)
105 104 {
106 105 return (mod_install(&modlinkage));
107 106 }
108 107
109 108 int
110 109 _fini(void)
111 110 {
112 111 return (mod_remove(&modlinkage));
113 112 }
114 113
115 114 int
116 115 _info(struct modinfo *modinfop)
117 116 {
118 117 return (mod_info(&modlinkage, modinfop));
119 118 }
120 119
121 120 #define ARP "arp"
122 121 #define TCP "tcp"
123 122 #define TCP6 "tcp6"
124 123 #define UDP "udp"
125 124 #define UDP6 "udp6"
126 125 #define ICMP "icmp"
127 126 #define ICMP6 "icmp6"
128 127 #define IP "ip"
129 128 #define IP6 "ip6"
130 129 #define TIMOD "timod"
131 130
132 131 #define UDPDEV "/devices/pseudo/udp@0:udp"
133 132 #define TCP6DEV "/devices/pseudo/tcp6@0:tcp6"
134 133 #define UDP6DEV "/devices/pseudo/udp6@0:udp6"
135 134 #define IP6DEV "/devices/pseudo/ip6@0:ip6"
136 135
137 136 typedef struct strplumb_modspec {
138 137 char *sm_type;
139 138 char *sm_name;
140 139 } strplumb_modspec_t;
141 140
142 141 static strplumb_modspec_t strplumb_modlist[] = {
143 142 { "drv", DLD_DRIVER_NAME },
144 143 { "drv", IP },
145 144 { "drv", IP6 },
146 145 { "drv", TCP },
147 146 { "drv", TCP6 },
148 147 { "drv", UDP },
149 148 { "drv", UDP6 },
150 149 { "drv", ICMP },
151 150 { "drv", ICMP6 },
152 151 { "drv", ARP },
153 152 { "strmod", TIMOD }
154 153 };
155 154
156 155 /*
157 156 * Called from swapgeneric.c:loadrootmodules() in the network boot case.
158 157 */
159 158 int
160 159 strplumb_load(void)
161 160 {
162 161 uint_t i;
163 162 strplumb_modspec_t *p;
164 163
165 164 DBG0("loading modules\n");
166 165
167 166 for (i = 0, p = strplumb_modlist;
168 167 i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]);
169 168 i++, p++) {
170 169 if (modloadonly(p->sm_type, p->sm_name) < 0) {
171 170 printf("strplumb: failed to load %s/%s\n",
172 171 p->sm_type, p->sm_name);
173 172 return (EFAULT);
174 173 }
175 174 }
176 175
177 176 return (0);
178 177 }
179 178
180 179 static int
181 180 strplumb_init(void)
182 181 {
183 182 uint_t i;
184 183 strplumb_modspec_t *p;
185 184 int err;
186 185
187 186 DBG0("initializing modules\n");
188 187
189 188 for (i = 0, p = strplumb_modlist;
190 189 i < sizeof (strplumb_modlist) / sizeof (strplumb_modlist[0]);
191 190 i++, p++) {
192 191 if (strcmp(p->sm_type, "drv") == 0)
193 192 err = (i_ddi_attach_pseudo_node(p->sm_name) != NULL) ?
194 193 0 : EFAULT;
195 194 else
196 195 err = (modload(p->sm_type, p->sm_name) < 0) ?
197 196 EFAULT : 0;
198 197
199 198 if (err != 0) {
200 199 printf("strplumb: failed to initialize %s/%s\n",
201 200 p->sm_type, p->sm_name);
202 201 return (err);
203 202 }
204 203 }
205 204
206 205 return (0);
207 206 }
208 207
209 208 /*
210 209 * Can be set in /etc/system in the case of local booting. See comment below.
211 210 */
212 211 char *ndev_name = 0;
213 212 int ndev_unit = 0;
214 213
215 214 /*
216 215 * If we booted diskless then strplumb() will have been called from
217 216 * swapgeneric.c:rootconf(). All we can do in that case is plumb the
218 217 * network device that we booted from.
219 218 *
220 219 * If we booted from a local disk, we will have been called from main(),
221 220 * and normally we defer the plumbing of interfaces until network/physical.
222 221 * This can be overridden by setting "ndev_name" in /etc/system.
223 222 */
224 223 static int
225 224 resolve_boot_path(void)
226 225 {
227 226 char *devpath;
228 227 dev_info_t *dip;
229 228 const char *driver;
230 229 int instance;
231 230 #ifdef _OBP
232 231 char stripped_path[OBP_MAXPATHLEN];
233 232 #endif
234 233
235 234 if (strncmp(rootfs.bo_fstype, "nfs", 3) == 0)
236 235 devpath = rootfs.bo_name;
237 236 else
238 237 devpath = strplumb_get_netdev_path();
239 238
240 239 if (devpath != NULL) {
241 240 DBG1("resolving boot-path: %s\n", devpath);
242 241 #ifdef _OBP
243 242 /*
244 243 * OBP passes options e.g, "net:dhcp"
245 244 * remove them here
246 245 */
247 246 prom_strip_options(devpath, stripped_path);
248 247 devpath = stripped_path;
249 248 #endif
250 249 /*
251 250 * Hold the devi since this is the root device.
252 251 */
253 252 if ((dip = e_ddi_hold_devi_by_path(devpath, 0)) == NULL) {
254 253 printf("strplumb: unable to hold root device: %s\n",
255 254 devpath);
256 255 return (ENXIO);
257 256 }
258 257
259 258 driver = ddi_driver_name(dip);
260 259 instance = ddi_get_instance(dip);
261 260 } else {
262 261 if (ndev_name == NULL)
263 262 return (ENODEV);
264 263
265 264 DBG2("using ndev_name (%s) ndev_unit (%d)\n", ndev_name,
266 265 ndev_unit);
267 266
268 267 if (i_ddi_attach_hw_nodes(ndev_name) != DDI_SUCCESS) {
269 268 printf("strplumb: cannot load ndev_name '%s'\n",
270 269 ndev_name);
271 270 return (ENXIO);
272 271 }
273 272
274 273 driver = ndev_name;
275 274 instance = ndev_unit;
276 275 }
277 276
278 277 (void) snprintf(rootfs.bo_devname, BO_MAXOBJNAME,
279 278 "/devices/pseudo/clone@0:%s", driver);
280 279 (void) snprintf(rootfs.bo_ifname, BO_MAXOBJNAME, "%s%d",
281 280 driver, instance);
282 281 rootfs.bo_ppa = instance;
283 282 return (0);
284 283 }
285 284
286 285 static int
287 286 getifflags(ldi_handle_t lh, struct lifreq *lifrp)
288 287 {
289 288 struct strioctl iocb;
290 289 int rval;
291 290
292 291 iocb.ic_cmd = SIOCGLIFFLAGS;
293 292 iocb.ic_timout = 15;
294 293 iocb.ic_len = sizeof (struct lifreq);
295 294 iocb.ic_dp = (char *)lifrp;
296 295
297 296 return (ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), &rval));
298 297
299 298 }
300 299
301 300 static int
302 301 setifname(ldi_handle_t lh, struct lifreq *lifrp)
303 302 {
304 303 struct strioctl iocb;
305 304 int rval;
306 305
307 306 iocb.ic_cmd = SIOCSLIFNAME;
308 307 iocb.ic_timout = 15;
309 308 iocb.ic_len = sizeof (struct lifreq);
310 309 iocb.ic_dp = (char *)lifrp;
311 310
312 311 return (ldi_ioctl(lh, I_STR, (intptr_t)&iocb, FKIOCTL, CRED(), &rval));
313 312 }
314 313
315 314 static int
316 315 strplumb_dev(ldi_ident_t li)
317 316 {
318 317 ldi_handle_t lh = NULL;
319 318 ldi_handle_t mux_lh = NULL;
320 319 int err;
321 320 struct lifreq lifr;
322 321 struct ifreq ifr;
323 322 int rval;
324 323 int af = 0;
325 324 char *name = NULL;
326 325
327 326 bzero(&lifr, sizeof (struct lifreq));
328 327 bzero(&ifr, sizeof (ifr));
329 328
330 329 if (iscsiboot_prop != NULL) {
331 330 af = iscsiboot_prop->boot_nic.sin_family;
332 331 }
333 332
334 333 /*
335 334 * Now set up the links. Ultimately, we should have two streams
336 335 * permanently linked under UDP. One stream consists of the
337 336 * ARP-[ifname] combination, while the other consists of IP-[ifname].
338 337 *
339 338 * We pin underneath UDP here to match what is done in ifconfig(1m);
340 339 * otherwise, ifconfig will be unable to unplumb the stream (the major
341 340 * number and mux id must both match for a successful I_PUNLINK).
342 341 *
343 342 * There are subtleties in the plumbing which make it essential to
344 343 * follow the logic used in ifconfig(1m) very closely.
345 344 */
346 345
347 346 /*
348 347 * Plumb UDP-IP-<dev>
349 348 */
350 349
351 350 if ((err = ldi_open_by_name(rootfs.bo_devname, FREAD|FWRITE, CRED(),
352 351 &lh, li)) != 0) {
353 352 printf("strplumb: open %s failed: %d\n", rootfs.bo_devname,
354 353 err);
355 354 goto done;
356 355 }
357 356
358 357
359 358 if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)IP, FKIOCTL, CRED(),
360 359 &rval)) != 0) {
361 360 printf("strplumb: push IP failed: %d\n", err);
362 361 goto done;
363 362 }
364 363
365 364 if ((err = getifflags(lh, &lifr)) != 0)
366 365 goto done;
367 366
368 367 if (af == 0 || af == AF_INET) {
369 368 lifr.lifr_flags |= IFF_IPV4;
370 369 lifr.lifr_flags &= ~IFF_IPV6;
371 370 name = UDPDEV;
372 371 } else {
373 372 /*
374 373 * iscsi boot is used with ipv6 enabled
375 374 */
376 375 lifr.lifr_flags |= IFF_IPV6;
377 376 lifr.lifr_flags &= ~IFF_IPV4;
378 377 name = UDP6DEV;
379 378 }
380 379 (void) strlcpy(lifr.lifr_name, rootfs.bo_ifname,
381 380 sizeof (lifr.lifr_name));
382 381 lifr.lifr_ppa = rootfs.bo_ppa;
383 382
384 383 if ((err = setifname(lh, &lifr)) != 0)
385 384 goto done;
386 385
387 386 /* get the flags and check if ARP is needed */
388 387 if ((err = getifflags(lh, &lifr)) != 0) {
389 388 printf("strplumb: getifflags %s IP failed, error %d\n",
390 389 lifr.lifr_name, err);
391 390 goto done;
392 391 }
393 392 if ((err = ldi_open_by_name(name, FREAD|FWRITE, CRED(), &mux_lh,
394 393 li)) != 0) {
395 394 printf("strplumb: open of %s failed: %d\n", name, err);
396 395 goto done;
397 396 }
398 397 if ((err = ldi_ioctl(mux_lh, I_PLINK, (intptr_t)lh,
399 398 FREAD|FWRITE|FNOCTTY|FKIOCTL, CRED(),
400 399 &(ifr.ifr_ip_muxid))) != 0) {
401 400 printf("strplumb: plink UDP-ARP-IP-%s failed: %d\n",
402 401 rootfs.bo_ifname, err);
403 402 goto done;
404 403 }
405 404
406 405 /* if ARP is not needed, we are done */
407 406 if (lifr.lifr_flags & (IFF_NOARP | IFF_IPV6))
408 407 goto done;
409 408
410 409 DBG2("UDP-ARP-IP-%s muxid: %d\n", rootfs.bo_ifname, ifr.ifr_ip_muxid);
411 410
412 411 (void) ldi_close(lh, FREAD|FWRITE, CRED());
413 412 lh = NULL;
414 413
415 414 /*
416 415 * Plumb UDP-ARP-<dev>
417 416 */
418 417
419 418 if ((err = ldi_open_by_name(rootfs.bo_devname, FREAD|FWRITE, CRED(),
420 419 &lh, li)) != 0) {
421 420 printf("strplumb: open %s failed: %d\n", rootfs.bo_devname,
422 421 err);
423 422 goto done;
424 423 }
425 424
426 425 if ((err = ldi_ioctl(lh, I_PUSH, (intptr_t)ARP, FKIOCTL, CRED(),
427 426 &rval)) != 0) {
428 427 printf("strplumb: push ARP failed: %d\n", err);
429 428 goto done;
430 429 }
431 430
432 431 if ((err = setifname(lh, &lifr)) != 0)
433 432 goto done;
434 433
435 434 if ((err = ldi_ioctl(mux_lh, I_PLINK, (intptr_t)lh,
436 435 FREAD|FWRITE|FNOCTTY|FKIOCTL, CRED(),
437 436 &(ifr.ifr_arp_muxid))) != 0) {
438 437 printf("strplumb: plink UDP-ARP-%s failed: %d\n",
439 438 rootfs.bo_ifname, err);
440 439 goto done;
441 440 }
442 441
443 442 DBG2("UDP-ARP-%s muxid: %d\n", rootfs.bo_ifname, ifr.ifr_arp_muxid);
444 443
445 444 /*
446 445 * Cache the mux ids.
447 446 */
448 447 (void) strlcpy(ifr.ifr_name, rootfs.bo_ifname, sizeof (ifr.ifr_name));
449 448
450 449 if ((err = ldi_ioctl(mux_lh, SIOCSIFMUXID, (intptr_t)&ifr, FKIOCTL,
451 450 CRED(), &rval)) != 0) {
452 451 printf("strplumb: SIOCSIFMUXID failed: %d\n", err);
453 452 goto done;
454 453 }
455 454
456 455 done:
457 456 if (lh != NULL)
458 457 (void) ldi_close(lh, FREAD|FWRITE, CRED());
459 458
460 459 if (mux_lh != NULL)
461 460 (void) ldi_close(mux_lh, FREAD|FWRITE, CRED());
462 461
463 462 return (err);
464 463 }
465 464
466 465 /*
467 466 * Do streams plumbing for internet protocols.
468 467 */
469 468 int
470 469 strplumb(void)
471 470 {
472 471 ldi_ident_t li;
473 472 int err;
474 473
475 474 if ((err = strplumb_init()) != 0)
476 475 return (err);
477 476
478 477 if ((err = ldi_ident_from_mod(&modlinkage, &li)) != 0)
479 478 return (err);
480 479
481 480 if ((err = resolve_boot_path()) != 0)
482 481 goto done;
483 482
484 483 DBG1("rootfs.bo_devname: %s\n", rootfs.bo_devname);
485 484 DBG1("rootfs.bo_ifname: %s\n", rootfs.bo_ifname);
486 485 DBG1("rootfs.bo_ppa: %d\n", rootfs.bo_ppa);
487 486
488 487 if ((err = strplumb_dev(li)) != 0)
489 488 goto done;
490 489
491 490 done:
492 491 ldi_ident_release(li);
493 492
494 493 return (err);
495 494 }
496 495
497 496 /* multiboot: diskless boot interface discovery */
498 497
499 498 #ifndef _OBP
500 499
501 500 static uchar_t boot_macaddr[16];
502 501 static int boot_maclen;
503 502 static uchar_t *getmacaddr(dev_info_t *dip, size_t *maclenp);
504 503 static int matchmac(dev_info_t *dip, void *arg);
505 504
506 505 #endif /* !_OBP */
507 506
508 507 char *
509 508 strplumb_get_netdev_path(void)
510 509 {
511 510 #ifdef _OBP
512 511 char fstype[OBP_MAXPROPNAME];
513 512 static char iscsi_network_path[BO_MAXOBJNAME] = {0};
514 513 int proplen;
515 514 char *p = NULL;
516 515
517 516 if (bop_getprop("fstype", fstype) == -1)
518 517 return (NULL);
519 518
520 519 if (strncmp(fstype, "nfs", 3) == 0)
521 520 return (prom_bootpath());
522 521 else if (iscsiboot_prop != NULL) {
523 522 proplen = BOP_GETPROPLEN(bootops,
524 523 BP_ISCSI_NETWORK_BOOTPATH);
525 524 if (proplen > 0) {
526 525 if (BOP_GETPROP(bootops,
527 526 BP_ISCSI_NETWORK_BOOTPATH,
528 527 iscsi_network_path) > 0) {
529 528 p = strchr(iscsi_network_path, ':');
530 529 if (p != NULL) {
531 530 *p = '\0';
532 531 }
533 532 return (iscsi_network_path);
534 533 }
535 534 }
536 535 }
537 536 return (NULL);
538 537 #else
539 538
540 539 char *macstr, *devpath = NULL;
541 540 uchar_t *bootp;
542 541 uint_t bootp_len;
543 542
544 543 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(),
545 544 DDI_PROP_DONTPASS, BP_BOOT_MAC, &macstr) == DDI_SUCCESS) {
546 545 /*
547 546 * hard coded ether mac len for booting floppy on
548 547 * machines with old cards
549 548 */
550 549 boot_maclen = ether_aton(macstr, boot_macaddr);
551 550 if (boot_maclen != 6) {
552 551 cmn_err(CE_WARN,
553 552 "malformed boot_mac property, %d bytes",
554 553 boot_maclen);
555 554 }
556 555 ddi_prop_free(macstr);
557 556 } else if (ddi_prop_lookup_byte_array(DDI_DEV_T_ANY, ddi_root_node(),
558 557 DDI_PROP_DONTPASS, BP_BOOTP_RESPONSE, &bootp, &bootp_len)
559 558 == DDI_SUCCESS) {
560 559
561 560 /*
562 561 * These offsets are defined by dhcp standard
563 562 * Should use structure offsets
564 563 */
565 564 boot_maclen = *(bootp + 2);
566 565 ASSERT(boot_maclen <= 16);
567 566 bcopy(bootp + 28, boot_macaddr, boot_maclen);
568 567
569 568 dhcack = kmem_alloc(bootp_len, KM_SLEEP);
570 569 bcopy(bootp, dhcack, bootp_len);
571 570 dhcacklen = bootp_len;
572 571
573 572 ddi_prop_free(bootp);
574 573 } else if (iscsiboot_prop != NULL) {
575 574 bcopy(iscsiboot_prop->boot_nic.nic_mac,
576 575 boot_macaddr, IB_BOOT_MACLEN);
577 576 boot_maclen = IB_BOOT_MACLEN;
578 577 } else {
579 578 return (NULL);
580 579 }
581 580
582 581 ddi_walk_devs(ddi_root_node(), matchmac, (void *)&devpath);
583 582 return (devpath);
584 583
585 584 #endif /* _OBP */
586 585 }
587 586
588 587 #ifndef _OBP
589 588
590 589 /*
591 590 * Get boot path from the boot_mac address
592 591 */
593 592 /*ARGSUSED*/
594 593 static int
595 594 matchmac(dev_info_t *dip, void *arg)
596 595 {
597 596 char **devpathp = (char **)arg;
598 597 char *model_str;
599 598 uchar_t *macaddr;
600 599 size_t maclen;
601 600
602 601 /* XXX Should use "device-type" per IEEE 1275 */
603 602 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0,
604 603 "model", &model_str) != DDI_SUCCESS)
605 604 return (DDI_WALK_CONTINUE);
606 605
607 606 if (strcmp(model_str, "Ethernet controller") != 0) {
608 607 ddi_prop_free(model_str);
609 608 return (DDI_WALK_CONTINUE);
610 609 }
611 610 ddi_prop_free(model_str);
612 611
613 612 /* We have a network device now */
614 613 if (i_ddi_attach_node_hierarchy(dip) != DDI_SUCCESS) {
615 614 return (DDI_WALK_CONTINUE);
616 615 }
617 616
618 617 ASSERT(boot_maclen != 0);
619 618 macaddr = getmacaddr(dip, &maclen);
620 619 if (macaddr == NULL)
621 620 return (DDI_WALK_CONTINUE);
622 621
623 622 if (maclen != boot_maclen ||
624 623 bcmp(macaddr, boot_macaddr, maclen) != 0) {
625 624 kmem_free(macaddr, maclen);
626 625 return (DDI_WALK_CONTINUE);
627 626 }
628 627
629 628 /* found hardware with the mac address */
630 629 (void) localetheraddr((struct ether_addr *)macaddr, NULL);
631 630 kmem_free(macaddr, maclen);
632 631
633 632 *devpathp = kmem_alloc(MAXPATHLEN, KM_SLEEP);
634 633 (void) ddi_pathname(dip, *devpathp);
635 634
636 635 /* fill in dhcifname */
637 636 if (dhcack) {
638 637 (void) snprintf(dhcifname, IFNAMSIZ, "%s%d",
639 638 ddi_driver_name(dip), i_ddi_devi_get_ppa(dip));
640 639 }
641 640 return (DDI_WALK_TERMINATE);
642 641 }
643 642
644 643 static uchar_t *
645 644 getmacaddr(dev_info_t *dip, size_t *maclenp)
646 645 {
647 646 int rc, ppa;
648 647 ldi_ident_t li;
649 648 ldi_handle_t lh;
650 649 const char *drv_name = ddi_driver_name(dip);
651 650 char *clonepath;
652 651 uchar_t *macaddr = NULL;
653 652
654 653 if (rc = ldi_ident_from_mod(&modlinkage, &li)) {
655 654 cmn_err(CE_WARN,
656 655 "getmacaddr: ldi_ident_from_mod failed: %d\n", rc);
657 656 return (NULL);
658 657 }
659 658
660 659 clonepath = kmem_alloc(MAXPATHLEN, KM_SLEEP);
661 660 (void) snprintf(clonepath, MAXPATHLEN,
662 661 "/devices/pseudo/clone@0:%s", drv_name);
663 662
664 663 rc = ldi_open_by_name(clonepath, FREAD|FWRITE, CRED(), &lh, li);
665 664 ldi_ident_release(li);
666 665 if (rc) {
667 666 cmn_err(CE_WARN,
668 667 "getmacaddr: ldi_open_by_name(%s) failed: %d\n",
669 668 clonepath, rc);
670 669 kmem_free(clonepath, MAXPATHLEN);
671 670 return (NULL);
672 671 }
673 672 kmem_free(clonepath, MAXPATHLEN);
674 673
675 674 ppa = i_ddi_devi_get_ppa(dip);
676 675 if ((dl_attach(lh, ppa, NULL) != 0) ||
677 676 (dl_bind(lh, ETHERTYPE_IP, NULL) != 0)) {
678 677 (void) ldi_close(lh, FREAD|FWRITE, CRED());
679 678 cmn_err(CE_WARN,
680 679 "getmacaddr: dl_attach/bind(%s%d) failed: %d\n",
681 680 drv_name, ppa, rc);
682 681 return (NULL);
683 682 }
684 683
685 684 *maclenp = ETHERADDRL;
686 685 macaddr = kmem_alloc(ETHERADDRL, KM_SLEEP);
687 686 if (dl_phys_addr(lh, macaddr, maclenp, NULL) != 0 ||
688 687 *maclenp != ETHERADDRL) {
689 688 kmem_free(macaddr, ETHERADDRL);
690 689 macaddr = NULL;
691 690 *maclenp = 0;
692 691 cmn_err(CE_WARN,
693 692 "getmacaddr: dl_phys_addr(%s%d) failed: %d\n",
694 693 drv_name, ppa, rc);
695 694 }
696 695 (void) ldi_close(lh, FREAD|FWRITE, CRED());
697 696 return (macaddr);
698 697 }
699 698 #endif /* !_OBP */
↓ open down ↓ |
589 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX