sad.c (64248fb8) | sad.c (f4b3ec61) |
---|---|
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* | 1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE --- 5 unchanged lines hidden (view full) --- 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21/* |
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. | 22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. |
23 * Use is subject to license terms. 24 */ 25 26#pragma ident "%Z%%M% %I% %E% SMI" 27 28/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 29/* All Rights Reserved */ 30 --- 18 unchanged lines hidden (view full) --- 49#include <sys/ddi.h> 50#include <sys/sunddi.h> 51#include <sys/stat.h> 52#include <sys/cmn_err.h> 53#include <sys/systm.h> 54#include <sys/modctl.h> 55#include <sys/priv_names.h> 56#include <sys/sysmacros.h> | 23 * Use is subject to license terms. 24 */ 25 26#pragma ident "%Z%%M% %I% %E% SMI" 27 28/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 29/* All Rights Reserved */ 30 --- 18 unchanged lines hidden (view full) --- 49#include <sys/ddi.h> 50#include <sys/sunddi.h> 51#include <sys/stat.h> 52#include <sys/cmn_err.h> 53#include <sys/systm.h> 54#include <sys/modctl.h> 55#include <sys/priv_names.h> 56#include <sys/sysmacros.h> |
57#include <sys/zone.h> |
|
57 58static int sadopen(queue_t *, dev_t *, int, int, cred_t *); 59static int sadclose(queue_t *, int, cred_t *); 60static int sadwput(queue_t *qp, mblk_t *mp); 61 62static int sad_info(dev_info_t *, ddi_info_cmd_t, void *, void **); 63static int sad_attach(dev_info_t *, ddi_attach_cmd_t); 64 --- 116 unchanged lines hidden (view full) --- 181sadopen( 182 queue_t *qp, /* pointer to read queue */ 183 dev_t *devp, /* major/minor device of stream */ 184 int flag, /* file open flags */ 185 int sflag, /* stream open flags */ 186 cred_t *credp) /* user credentials */ 187{ 188 int i; | 58 59static int sadopen(queue_t *, dev_t *, int, int, cred_t *); 60static int sadclose(queue_t *, int, cred_t *); 61static int sadwput(queue_t *qp, mblk_t *mp); 62 63static int sad_info(dev_info_t *, ddi_info_cmd_t, void *, void **); 64static int sad_attach(dev_info_t *, ddi_attach_cmd_t); 65 --- 116 unchanged lines hidden (view full) --- 182sadopen( 183 queue_t *qp, /* pointer to read queue */ 184 dev_t *devp, /* major/minor device of stream */ 185 int flag, /* file open flags */ 186 int sflag, /* stream open flags */ 187 cred_t *credp) /* user credentials */ 188{ 189 int i; |
190 netstack_t *ns; 191 str_stack_t *ss; |
|
189 190 if (sflag) /* no longer called from clone driver */ 191 return (EINVAL); 192 | 192 193 if (sflag) /* no longer called from clone driver */ 194 return (EINVAL); 195 |
196 ns = netstack_find_by_cred(credp); 197 ASSERT(ns != NULL); 198 ss = ns->netstack_str; 199 ASSERT(ss != NULL); 200 |
|
193 /* 194 * Both USRMIN and ADMMIN are clone interfaces. 195 */ | 201 /* 202 * Both USRMIN and ADMMIN are clone interfaces. 203 */ |
196 for (i = 0; i < sadcnt; i++) 197 if (saddev[i].sa_qp == NULL) | 204 for (i = 0; i < ss->ss_sadcnt; i++) 205 if (ss->ss_saddev[i].sa_qp == NULL) |
198 break; | 206 break; |
199 if (i >= sadcnt) /* no such device */ | 207 if (i >= ss->ss_sadcnt) { /* no such device */ 208 netstack_rele(ss->ss_netstack); |
200 return (ENXIO); | 209 return (ENXIO); |
201 | 210 } |
202 switch (getminor(*devp)) { 203 case USRMIN: /* mere mortal */ | 211 switch (getminor(*devp)) { 212 case USRMIN: /* mere mortal */ |
204 saddev[i].sa_flags = 0; | 213 ss->ss_saddev[i].sa_flags = 0; |
205 break; 206 207 case ADMMIN: /* privileged user */ | 214 break; 215 216 case ADMMIN: /* privileged user */ |
208 saddev[i].sa_flags = SADPRIV; | 217 ss->ss_saddev[i].sa_flags = SADPRIV; |
209 break; 210 211 default: | 218 break; 219 220 default: |
221 netstack_rele(ss->ss_netstack); |
|
212 return (EINVAL); 213 } 214 | 222 return (EINVAL); 223 } 224 |
215 saddev[i].sa_qp = qp; 216 qp->q_ptr = (caddr_t)&saddev[i]; 217 WR(qp)->q_ptr = (caddr_t)&saddev[i]; | 225 ss->ss_saddev[i].sa_qp = qp; 226 ss->ss_saddev[i].sa_ss = ss; 227 qp->q_ptr = (caddr_t)&ss->ss_saddev[i]; 228 WR(qp)->q_ptr = (caddr_t)&ss->ss_saddev[i]; |
218 219 /* 220 * NOTE: should the ADMMIN or USRMIN minors change 221 * then so should the offset of 2 below 222 * Both USRMIN and ADMMIN are clone interfaces and 223 * therefore their minor numbers (0 and 1) are reserved. 224 */ 225 *devp = makedevice(getemajor(*devp), i + 2); --- 13 unchanged lines hidden (view full) --- 239 cred_t *credp) /* user credentials */ 240{ 241 struct saddev *sadp; 242 243 qprocsoff(qp); 244 sadp = (struct saddev *)qp->q_ptr; 245 sadp->sa_qp = NULL; 246 sadp->sa_addr = NULL; | 229 230 /* 231 * NOTE: should the ADMMIN or USRMIN minors change 232 * then so should the offset of 2 below 233 * Both USRMIN and ADMMIN are clone interfaces and 234 * therefore their minor numbers (0 and 1) are reserved. 235 */ 236 *devp = makedevice(getemajor(*devp), i + 2); --- 13 unchanged lines hidden (view full) --- 250 cred_t *credp) /* user credentials */ 251{ 252 struct saddev *sadp; 253 254 qprocsoff(qp); 255 sadp = (struct saddev *)qp->q_ptr; 256 sadp->sa_qp = NULL; 257 sadp->sa_addr = NULL; |
258 netstack_rele(sadp->sa_ss->ss_netstack); 259 sadp->sa_ss = NULL; |
|
247 qp->q_ptr = NULL; 248 WR(qp)->q_ptr = NULL; 249 return (0); 250} 251 252/* 253 * sadwput() - 254 * Write side put procedure. --- 122 unchanged lines hidden (view full) --- 377{ 378 int i, ret; 379 struct copyresp *csp; 380 struct strapush *sap = NULL; 381 struct autopush *ap, *ap_tmp; 382 struct saddev *sadp; 383 uint_t size; 384 dev_t dev; | 260 qp->q_ptr = NULL; 261 WR(qp)->q_ptr = NULL; 262 return (0); 263} 264 265/* 266 * sadwput() - 267 * Write side put procedure. --- 122 unchanged lines hidden (view full) --- 390{ 391 int i, ret; 392 struct copyresp *csp; 393 struct strapush *sap = NULL; 394 struct autopush *ap, *ap_tmp; 395 struct saddev *sadp; 396 uint_t size; 397 dev_t dev; |
398 str_stack_t *ss; |
|
385 | 399 |
400 sadp = (struct saddev *)qp->q_ptr; 401 ss = sadp->sa_ss; 402 |
|
386 csp = (struct copyresp *)mp->b_rptr; 387 if (csp->cp_rval) { /* if there was an error */ 388 freemsg(mp); 389 return; 390 } 391 if (mp->b_cont) { 392 /* 393 * sap needed only if mp->b_cont is set. figure out the --- 37 unchanged lines hidden (view full) --- 431 ap->ap_anchor = sap->sap_anchor; 432 for (i = 0; i < MIN(sap->sap_npush, MAXAPUSH); i++) 433 (void) strncpy(ap->ap_list[i], 434 sap->sap_list[i], FMNAMESZ); 435 436 /* sanity check the request */ 437 if (((ret = sad_ap_verify(ap)) != 0) || 438 ((ret = valid_major(ap->ap_major)) != 0)) { | 403 csp = (struct copyresp *)mp->b_rptr; 404 if (csp->cp_rval) { /* if there was an error */ 405 freemsg(mp); 406 return; 407 } 408 if (mp->b_cont) { 409 /* 410 * sap needed only if mp->b_cont is set. figure out the --- 37 unchanged lines hidden (view full) --- 448 ap->ap_anchor = sap->sap_anchor; 449 for (i = 0; i < MIN(sap->sap_npush, MAXAPUSH); i++) 450 (void) strncpy(ap->ap_list[i], 451 sap->sap_list[i], FMNAMESZ); 452 453 /* sanity check the request */ 454 if (((ret = sad_ap_verify(ap)) != 0) || 455 ((ret = valid_major(ap->ap_major)) != 0)) { |
439 sad_ap_rele(ap); | 456 sad_ap_rele(ap, ss); |
440 miocnak(qp, mp, 0, ret); 441 return; 442 } 443 444 /* check for overlapping configs */ | 457 miocnak(qp, mp, 0, ret); 458 return; 459 } 460 461 /* check for overlapping configs */ |
445 mutex_enter(&sad_lock); 446 if ((ap_tmp = sad_ap_find(&ap->ap_common)) != NULL) { | 462 mutex_enter(&ss->ss_sad_lock); 463 ap_tmp = sad_ap_find(&ap->ap_common, ss); 464 if (ap_tmp != NULL) { |
447 /* already configured */ | 465 /* already configured */ |
448 mutex_exit(&sad_lock); 449 sad_ap_rele(ap_tmp); 450 sad_ap_rele(ap); | 466 mutex_exit(&ss->ss_sad_lock); 467 sad_ap_rele(ap_tmp, ss); 468 sad_ap_rele(ap, ss); |
451 miocnak(qp, mp, 0, EEXIST); 452 return; 453 } 454 455 /* add the new config to our hash */ | 469 miocnak(qp, mp, 0, EEXIST); 470 return; 471 } 472 473 /* add the new config to our hash */ |
456 sad_ap_insert(ap); 457 mutex_exit(&sad_lock); | 474 sad_ap_insert(ap, ss); 475 mutex_exit(&ss->ss_sad_lock); |
458 miocack(qp, mp, 0, 0); 459 return; 460 461 case SAP_CLEAR: 462 /* sanity check the request */ 463 if (ret = valid_major(sap->sap_major)) { 464 miocnak(qp, mp, 0, ret); 465 return; 466 } 467 468 /* search for a matching config */ | 476 miocack(qp, mp, 0, 0); 477 return; 478 479 case SAP_CLEAR: 480 /* sanity check the request */ 481 if (ret = valid_major(sap->sap_major)) { 482 miocnak(qp, mp, 0, ret); 483 return; 484 } 485 486 /* search for a matching config */ |
469 if ((ap = sad_ap_find_by_dev(dev)) == NULL) { | 487 if ((ap = sad_ap_find_by_dev(dev, ss)) == NULL) { |
470 /* no config found */ 471 miocnak(qp, mp, 0, ENODEV); 472 return; 473 } 474 475 /* 476 * If we matched a SAP_RANGE config 477 * the minor passed in must match the 478 * beginning of the range exactly. 479 */ 480 if ((ap->ap_type == SAP_RANGE) && 481 (ap->ap_minor != sap->sap_minor)) { | 488 /* no config found */ 489 miocnak(qp, mp, 0, ENODEV); 490 return; 491 } 492 493 /* 494 * If we matched a SAP_RANGE config 495 * the minor passed in must match the 496 * beginning of the range exactly. 497 */ 498 if ((ap->ap_type == SAP_RANGE) && 499 (ap->ap_minor != sap->sap_minor)) { |
482 sad_ap_rele(ap); | 500 sad_ap_rele(ap, ss); |
483 miocnak(qp, mp, 0, ERANGE); 484 return; 485 } 486 487 /* 488 * If we matched a SAP_ALL config 489 * the minor passed in must be 0. 490 */ 491 if ((ap->ap_type == SAP_ALL) && 492 (sap->sap_minor != 0)) { | 501 miocnak(qp, mp, 0, ERANGE); 502 return; 503 } 504 505 /* 506 * If we matched a SAP_ALL config 507 * the minor passed in must be 0. 508 */ 509 if ((ap->ap_type == SAP_ALL) && 510 (sap->sap_minor != 0)) { |
493 sad_ap_rele(ap); | 511 sad_ap_rele(ap, ss); |
494 miocnak(qp, mp, 0, EINVAL); 495 return; 496 } 497 498 /* 499 * make sure someone else hasn't already 500 * removed this config from the hash. 501 */ | 512 miocnak(qp, mp, 0, EINVAL); 513 return; 514 } 515 516 /* 517 * make sure someone else hasn't already 518 * removed this config from the hash. 519 */ |
502 mutex_enter(&sad_lock); 503 ap_tmp = sad_ap_find(&ap->ap_common); | 520 mutex_enter(&ss->ss_sad_lock); 521 ap_tmp = sad_ap_find(&ap->ap_common, ss); |
504 if (ap_tmp != ap) { | 522 if (ap_tmp != ap) { |
505 mutex_exit(&sad_lock); 506 sad_ap_rele(ap_tmp); 507 sad_ap_rele(ap); | 523 mutex_exit(&ss->ss_sad_lock); 524 sad_ap_rele(ap_tmp, ss); 525 sad_ap_rele(ap, ss); |
508 miocnak(qp, mp, 0, ENODEV); 509 return; | 526 miocnak(qp, mp, 0, ENODEV); 527 return; |
510 } else | 528 } |
511 512 /* remove the config from the hash and return */ | 529 530 /* remove the config from the hash and return */ |
513 sad_ap_remove(ap); 514 mutex_exit(&sad_lock); | 531 sad_ap_remove(ap, ss); 532 mutex_exit(&ss->ss_sad_lock); |
515 516 /* 517 * Release thrice, once for sad_ap_find_by_dev(), 518 * once for sad_ap_find(), and once to free. 519 */ | 533 534 /* 535 * Release thrice, once for sad_ap_find_by_dev(), 536 * once for sad_ap_find(), and once to free. 537 */ |
520 sad_ap_rele(ap); 521 sad_ap_rele(ap); 522 sad_ap_rele(ap); | 538 sad_ap_rele(ap, ss); 539 sad_ap_rele(ap, ss); 540 sad_ap_rele(ap, ss); |
523 miocack(qp, mp, 0, 0); 524 return; 525 } /* switch (sap_cmd) */ 526 /*NOTREACHED*/ 527 528 case SAD_CMD(SAD_GAP): 529 switch ((long)csp->cp_private) { 530 531 case GETSTRUCT: 532 /* sanity check the request */ 533 if (ret = valid_major(sap->sap_major)) { 534 miocnak(qp, mp, 0, ret); 535 return; 536 } 537 538 /* search for a matching config */ | 541 miocack(qp, mp, 0, 0); 542 return; 543 } /* switch (sap_cmd) */ 544 /*NOTREACHED*/ 545 546 case SAD_CMD(SAD_GAP): 547 switch ((long)csp->cp_private) { 548 549 case GETSTRUCT: 550 /* sanity check the request */ 551 if (ret = valid_major(sap->sap_major)) { 552 miocnak(qp, mp, 0, ret); 553 return; 554 } 555 556 /* search for a matching config */ |
539 if ((ap = sad_ap_find_by_dev(dev)) == NULL) { | 557 if ((ap = sad_ap_find_by_dev(dev, ss)) == NULL) { |
540 /* no config found */ 541 miocnak(qp, mp, 0, ENODEV); 542 return; 543 } 544 545 /* copy out the contents of the config */ 546 sap->sap_common = ap->ap_common; 547 if (SAD_VER(csp->cp_cmd) > 0) 548 sap->sap_anchor = ap->ap_anchor; 549 for (i = 0; i < ap->ap_npush; i++) 550 (void) strcpy(sap->sap_list[i], ap->ap_list[i]); 551 for (; i < MAXAPUSH; i++) 552 bzero(sap->sap_list[i], FMNAMESZ + 1); | 558 /* no config found */ 559 miocnak(qp, mp, 0, ENODEV); 560 return; 561 } 562 563 /* copy out the contents of the config */ 564 sap->sap_common = ap->ap_common; 565 if (SAD_VER(csp->cp_cmd) > 0) 566 sap->sap_anchor = ap->ap_anchor; 567 for (i = 0; i < ap->ap_npush; i++) 568 (void) strcpy(sap->sap_list[i], ap->ap_list[i]); 569 for (; i < MAXAPUSH; i++) 570 bzero(sap->sap_list[i], FMNAMESZ + 1); |
571 mutex_exit(&ss->ss_sad_lock); |
|
553 554 /* release our hold on the config */ | 572 573 /* release our hold on the config */ |
555 sad_ap_rele(ap); | 574 sad_ap_rele(ap, ss); |
556 557 /* copyout the results */ 558 if (SAD_VER(csp->cp_cmd) == 1) 559 size = STRAPUSH_V1_LEN; 560 else 561 size = STRAPUSH_V0_LEN; 562 | 575 576 /* copyout the results */ 577 if (SAD_VER(csp->cp_cmd) == 1) 578 size = STRAPUSH_V1_LEN; 579 else 580 size = STRAPUSH_V0_LEN; 581 |
563 sadp = (struct saddev *)qp->q_ptr; | |
564 mcopyout(mp, (void *)GETRESULT, size, sadp->sa_addr, 565 NULL); 566 qreply(qp, mp); 567 return; 568 case GETRESULT: 569 miocack(qp, mp, 0, 0); 570 return; 571 --- 127 unchanged lines hidden --- | 582 mcopyout(mp, (void *)GETRESULT, size, sadp->sa_addr, 583 NULL); 584 qreply(qp, mp); 585 return; 586 case GETRESULT: 587 miocack(qp, mp, 0, 0); 588 return; 589 --- 127 unchanged lines hidden --- |