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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 #include <door.h>
26 #include <errno.h>
27 #include <assert.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <unistd.h>
31 #include <string.h>
32 #include <strings.h>
33 #include <zone.h>
34 #include <sys/types.h>
35 #include <sys/stat.h>
36 #include <sys/aggr.h>
37 #include <sys/mman.h>
38 #include <fcntl.h>
39 #include <libdladm.h>
40 #include <libdladm_impl.h>
41 #include <libdllink.h>
42 #include <libdlmgmt.h>
511 }
512
513 if (nvp == NULL)
514 return (DLADM_STATUS_NOTFOUND);
515
516 if ((err = nvpair_value_byte_array(nvp, (uchar_t **)&oattrval,
517 &oattrsz)) != NULL) {
518 return (dladm_errno2status(err));
519 }
520
521 *attrszp = oattrsz;
522 if (oattrsz > attrsz)
523 return (DLADM_STATUS_TOOSMALL);
524
525 (void) strlcpy(attr, nvpair_name(nvp), MAXLINKATTRLEN);
526 bcopy(oattrval, attrval, oattrsz);
527 return (DLADM_STATUS_OK);
528 }
529
530 /*
531 * Get the link ID that is associated with the given name.
532 */
533 dladm_status_t
534 dladm_name2info(dladm_handle_t handle, const char *link, datalink_id_t *linkidp,
535 uint32_t *flagp, datalink_class_t *classp, uint32_t *mediap)
536 {
537 dlmgmt_door_getlinkid_t getlinkid;
538 dlmgmt_getlinkid_retval_t retval;
539 datalink_id_t linkid;
540 dladm_status_t status;
541 size_t sz = sizeof (retval);
542
543 getlinkid.ld_cmd = DLMGMT_CMD_GETLINKID;
544 (void) strlcpy(getlinkid.ld_link, link, MAXLINKNAMELEN);
545
546 if ((status = dladm_door_call(handle, &getlinkid, sizeof (getlinkid),
547 &retval, &sz)) != DLADM_STATUS_OK) {
548 return (status);
549 }
550
551 linkid = retval.lr_linkid;
552 if (retval.lr_class == DATALINK_CLASS_PHYS &&
553 retval.lr_flags & DLMGMT_ACTIVE) {
554 /*
555 * An active physical link reported by the dlmgmtd daemon
556 * might not be active anymore. Check and set its real status.
557 */
558 status = i_dladm_phys_status(handle, linkid, &retval.lr_flags);
559 if (status != DLADM_STATUS_OK)
560 return (status);
561 }
562
563 if (linkidp != NULL)
564 *linkidp = linkid;
|
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
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2011, Joyent Inc. All rights reserved.
24 */
25
26 #include <door.h>
27 #include <errno.h>
28 #include <assert.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <unistd.h>
32 #include <string.h>
33 #include <strings.h>
34 #include <zone.h>
35 #include <sys/types.h>
36 #include <sys/stat.h>
37 #include <sys/aggr.h>
38 #include <sys/mman.h>
39 #include <fcntl.h>
40 #include <libdladm.h>
41 #include <libdladm_impl.h>
42 #include <libdllink.h>
43 #include <libdlmgmt.h>
512 }
513
514 if (nvp == NULL)
515 return (DLADM_STATUS_NOTFOUND);
516
517 if ((err = nvpair_value_byte_array(nvp, (uchar_t **)&oattrval,
518 &oattrsz)) != NULL) {
519 return (dladm_errno2status(err));
520 }
521
522 *attrszp = oattrsz;
523 if (oattrsz > attrsz)
524 return (DLADM_STATUS_TOOSMALL);
525
526 (void) strlcpy(attr, nvpair_name(nvp), MAXLINKATTRLEN);
527 bcopy(oattrval, attrval, oattrsz);
528 return (DLADM_STATUS_OK);
529 }
530
531 /*
532 * Get the link ID that is associated with the given name in the current zone.
533 */
534 dladm_status_t
535 dladm_name2info(dladm_handle_t handle, const char *link, datalink_id_t *linkidp,
536 uint32_t *flagp, datalink_class_t *classp, uint32_t *mediap)
537 {
538 return (dladm_zname2info(handle, NULL, link, linkidp, flagp, classp,
539 mediap));
540 }
541
542 /*
543 * Get the link ID that is associated with the given zone/name pair.
544 */
545 dladm_status_t
546 dladm_zname2info(dladm_handle_t handle, const char *zonename, const char *link,
547 datalink_id_t *linkidp, uint32_t *flagp, datalink_class_t *classp,
548 uint32_t *mediap)
549 {
550 dlmgmt_door_getlinkid_t getlinkid;
551 dlmgmt_getlinkid_retval_t retval;
552 datalink_id_t linkid;
553 dladm_status_t status;
554 size_t sz = sizeof (retval);
555
556 getlinkid.ld_cmd = DLMGMT_CMD_GETLINKID;
557 (void) strlcpy(getlinkid.ld_link, link, MAXLINKNAMELEN);
558 if (zonename != NULL)
559 getlinkid.ld_zoneid = getzoneidbyname(zonename);
560 else
561 getlinkid.ld_zoneid = -1;
562
563 if ((status = dladm_door_call(handle, &getlinkid, sizeof (getlinkid),
564 &retval, &sz)) != DLADM_STATUS_OK) {
565 return (status);
566 }
567
568 linkid = retval.lr_linkid;
569 if (retval.lr_class == DATALINK_CLASS_PHYS &&
570 retval.lr_flags & DLMGMT_ACTIVE) {
571 /*
572 * An active physical link reported by the dlmgmtd daemon
573 * might not be active anymore. Check and set its real status.
574 */
575 status = i_dladm_phys_status(handle, linkid, &retval.lr_flags);
576 if (status != DLADM_STATUS_OK)
577 return (status);
578 }
579
580 if (linkidp != NULL)
581 *linkidp = linkid;
|