15895Syz147064 /* 25895Syz147064 * CDDL HEADER START 35895Syz147064 * 45895Syz147064 * The contents of this file are subject to the terms of the 55895Syz147064 * Common Development and Distribution License (the "License"). 65895Syz147064 * You may not use this file except in compliance with the License. 75895Syz147064 * 85895Syz147064 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95895Syz147064 * or http://www.opensolaris.org/os/licensing. 105895Syz147064 * See the License for the specific language governing permissions 115895Syz147064 * and limitations under the License. 125895Syz147064 * 135895Syz147064 * When distributing Covered Code, include this CDDL HEADER in each 145895Syz147064 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155895Syz147064 * If applicable, add the following below this CDDL HEADER, with the 165895Syz147064 * fields enclosed by brackets "[]" replaced with your own identifying 175895Syz147064 * information: Portions Copyright [yyyy] [name of copyright owner] 185895Syz147064 * 195895Syz147064 * CDDL HEADER END 205895Syz147064 */ 215895Syz147064 /* 225895Syz147064 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 235895Syz147064 * Use is subject to license terms. 245895Syz147064 */ 255895Syz147064 265895Syz147064 #include <door.h> 275895Syz147064 #include <errno.h> 285895Syz147064 #include <assert.h> 295895Syz147064 #include <stdio.h> 305895Syz147064 #include <stdlib.h> 315895Syz147064 #include <unistd.h> 325895Syz147064 #include <string.h> 335895Syz147064 #include <strings.h> 345895Syz147064 #include <sys/types.h> 355895Syz147064 #include <sys/stat.h> 365895Syz147064 #include <sys/aggr.h> 375895Syz147064 #include <fcntl.h> 385895Syz147064 #include <libdladm.h> 395895Syz147064 #include <libdladm_impl.h> 405895Syz147064 #include <libdllink.h> 415895Syz147064 #include <libdlmgmt.h> 425895Syz147064 435895Syz147064 /* 445895Syz147064 * Table of data type sizes indexed by dladm_datatype_t. 455895Syz147064 */ 465895Syz147064 static size_t dladm_datatype_size[] = { 475895Syz147064 0, /* DLADM_TYPE_STR, use strnlen() */ 485895Syz147064 sizeof (boolean_t), /* DLADM_TYPE_BOOLEAN */ 495895Syz147064 sizeof (uint64_t) /* DLADM_TYPE_UINT64 */ 505895Syz147064 }; 515895Syz147064 525895Syz147064 static dladm_status_t 536263Sseb dladm_door_call(void *arg, size_t asize, void *rbuf, size_t rsize) 545895Syz147064 { 555895Syz147064 door_arg_t darg; 565895Syz147064 int fd; 575895Syz147064 dladm_status_t status = DLADM_STATUS_OK; 585895Syz147064 595895Syz147064 if ((fd = open(DLMGMT_DOOR, O_RDONLY)) == -1) 605895Syz147064 return (dladm_errno2status(errno)); 615895Syz147064 625895Syz147064 darg.data_ptr = arg; 635895Syz147064 darg.data_size = asize; 645895Syz147064 darg.desc_ptr = NULL; 655895Syz147064 darg.desc_num = 0; 665895Syz147064 darg.rbuf = rbuf; 676263Sseb darg.rsize = rsize; 685895Syz147064 695895Syz147064 if (door_call(fd, &darg) == -1) 705895Syz147064 status = dladm_errno2status(errno); 715895Syz147064 (void) close(fd); 725895Syz147064 735895Syz147064 if (status != DLADM_STATUS_OK) 745895Syz147064 return (status); 755895Syz147064 765895Syz147064 if (darg.rbuf != rbuf) { 775895Syz147064 /* 785895Syz147064 * The size of the input rbuf is not big enough so that 795895Syz147064 * the door allocate the rbuf itself. In this case, simply 805895Syz147064 * think something wrong with the door call. 815895Syz147064 */ 825895Syz147064 (void) munmap(darg.rbuf, darg.rsize); 835895Syz147064 return (DLADM_STATUS_TOOSMALL); 845895Syz147064 } 856263Sseb if (darg.rsize != rsize) 865895Syz147064 return (DLADM_STATUS_FAILED); 875895Syz147064 886263Sseb return (dladm_errno2status(((dlmgmt_retval_t *)rbuf)->lr_err)); 895895Syz147064 } 905895Syz147064 915895Syz147064 /* 925895Syz147064 * Allocate a new linkid with the given name. Return the new linkid. 935895Syz147064 */ 945895Syz147064 dladm_status_t 955895Syz147064 dladm_create_datalink_id(const char *link, datalink_class_t class, 965895Syz147064 uint32_t media, uint32_t flags, datalink_id_t *linkidp) 975895Syz147064 { 986263Sseb dlmgmt_door_createid_t createid; 995895Syz147064 dlmgmt_createid_retval_t retval; 1006263Sseb uint32_t dlmgmt_flags; 1016263Sseb dladm_status_t status; 1025895Syz147064 1036263Sseb if (link == NULL || class == DATALINK_CLASS_ALL || 1045895Syz147064 !(flags & (DLADM_OPT_ACTIVE | DLADM_OPT_PERSIST)) || 1055895Syz147064 linkidp == NULL) { 1065895Syz147064 return (DLADM_STATUS_BADARG); 1075895Syz147064 } 1085895Syz147064 1095895Syz147064 dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0; 1105895Syz147064 dlmgmt_flags |= (flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0; 1115895Syz147064 1125895Syz147064 (void) strlcpy(createid.ld_link, link, MAXLINKNAMELEN); 1135895Syz147064 createid.ld_class = class; 1145895Syz147064 createid.ld_media = media; 1155895Syz147064 createid.ld_flags = dlmgmt_flags; 1165895Syz147064 createid.ld_cmd = DLMGMT_CMD_CREATE_LINKID; 1175895Syz147064 createid.ld_prefix = (flags & DLADM_OPT_PREFIX); 1185895Syz147064 1196263Sseb if ((status = dladm_door_call(&createid, sizeof (createid), &retval, 1206263Sseb sizeof (retval))) == DLADM_STATUS_OK) { 1216263Sseb *linkidp = retval.lr_linkid; 1226263Sseb } 1236263Sseb return (status); 1245895Syz147064 } 1255895Syz147064 1265895Syz147064 /* 1275895Syz147064 * Destroy the given link ID. 1285895Syz147064 */ 1295895Syz147064 dladm_status_t 1305895Syz147064 dladm_destroy_datalink_id(datalink_id_t linkid, uint32_t flags) 1315895Syz147064 { 1325895Syz147064 dlmgmt_door_destroyid_t destroyid; 1335895Syz147064 dlmgmt_destroyid_retval_t retval; 1345895Syz147064 uint32_t dlmgmt_flags; 1355895Syz147064 1365895Syz147064 dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0; 1375895Syz147064 dlmgmt_flags |= ((flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0); 1385895Syz147064 1395895Syz147064 destroyid.ld_cmd = DLMGMT_CMD_DESTROY_LINKID; 1405895Syz147064 destroyid.ld_linkid = linkid; 1415895Syz147064 destroyid.ld_flags = dlmgmt_flags; 1425895Syz147064 1436263Sseb return (dladm_door_call(&destroyid, sizeof (destroyid), 1446263Sseb &retval, sizeof (retval))); 1455895Syz147064 } 1465895Syz147064 1475895Syz147064 /* 1485895Syz147064 * Remap a given link ID to a new name. 1495895Syz147064 */ 1505895Syz147064 dladm_status_t 1515895Syz147064 dladm_remap_datalink_id(datalink_id_t linkid, const char *link) 1525895Syz147064 { 1535895Syz147064 dlmgmt_door_remapid_t remapid; 1545895Syz147064 dlmgmt_remapid_retval_t retval; 1555895Syz147064 1565895Syz147064 remapid.ld_cmd = DLMGMT_CMD_REMAP_LINKID; 1575895Syz147064 remapid.ld_linkid = linkid; 1585895Syz147064 (void) strlcpy(remapid.ld_link, link, MAXLINKNAMELEN); 1595895Syz147064 1606263Sseb return (dladm_door_call(&remapid, sizeof (remapid), 1616263Sseb &retval, sizeof (retval))); 1625895Syz147064 } 1635895Syz147064 1645895Syz147064 /* 1655895Syz147064 * Make a given link ID active. 1665895Syz147064 */ 1675895Syz147064 dladm_status_t 1685895Syz147064 dladm_up_datalink_id(datalink_id_t linkid) 1695895Syz147064 { 1706263Sseb dlmgmt_door_upid_t upid; 1716263Sseb dlmgmt_upid_retval_t retval; 1725895Syz147064 1735895Syz147064 upid.ld_cmd = DLMGMT_CMD_UP_LINKID; 1745895Syz147064 upid.ld_linkid = linkid; 1755895Syz147064 1766263Sseb return (dladm_door_call(&upid, sizeof (upid), 1776263Sseb &retval, sizeof (retval))); 1785895Syz147064 } 1795895Syz147064 1805895Syz147064 /* 1815895Syz147064 * Create a new link with the given name. Return the new link's handle 1825895Syz147064 */ 1835895Syz147064 dladm_status_t 1845895Syz147064 dladm_create_conf(const char *link, datalink_id_t linkid, 1855895Syz147064 datalink_class_t class, uint32_t media, dladm_conf_t *confp) 1865895Syz147064 { 1876263Sseb dlmgmt_door_createconf_t createconf; 1886263Sseb dlmgmt_createconf_retval_t retval; 1896263Sseb dladm_status_t status; 1905895Syz147064 1916263Sseb if (link == NULL || confp == NULL) 1925895Syz147064 return (DLADM_STATUS_BADARG); 1935895Syz147064 1945895Syz147064 (void) strlcpy(createconf.ld_link, link, MAXLINKNAMELEN); 1955895Syz147064 createconf.ld_class = class; 1965895Syz147064 createconf.ld_media = media; 1975895Syz147064 createconf.ld_linkid = linkid; 1985895Syz147064 createconf.ld_cmd = DLMGMT_CMD_CREATECONF; 1995895Syz147064 2006263Sseb if ((status = dladm_door_call(&createconf, sizeof (createconf), 2016263Sseb &retval, sizeof (retval))) == DLADM_STATUS_OK) { 2026263Sseb *confp = retval.lr_conf; 2036263Sseb } 2046263Sseb return (status); 2055895Syz147064 } 2065895Syz147064 2075895Syz147064 /* 2085895Syz147064 * An active physical link reported by the dlmgmtd daemon might not be active 2095895Syz147064 * anymore as this link might be removed during system shutdown. Check its 2105895Syz147064 * real status by calling dladm_phys_info(). 2115895Syz147064 */ 2125895Syz147064 dladm_status_t 2135895Syz147064 i_dladm_phys_status(datalink_id_t linkid, uint32_t *flagsp) 2145895Syz147064 { 2155895Syz147064 dladm_phys_attr_t dpa; 2165895Syz147064 dladm_status_t status; 2175895Syz147064 2185895Syz147064 assert((*flagsp) & DLMGMT_ACTIVE); 2195895Syz147064 2205895Syz147064 status = dladm_phys_info(linkid, &dpa, DLADM_OPT_ACTIVE); 2215895Syz147064 if (status == DLADM_STATUS_NOTFOUND) { 2225895Syz147064 /* 2235895Syz147064 * No active status, this link was removed. Update its status 2245895Syz147064 * in the daemon and delete all active linkprops. 225*8120SCathy.Zhou@Sun.COM * 226*8120SCathy.Zhou@Sun.COM * Note that the operation could fail. If it does, return 227*8120SCathy.Zhou@Sun.COM * failure now since otherwise dladm_set_linkprop() might 228*8120SCathy.Zhou@Sun.COM * call back to i_dladm_phys_status() recursively. 2295895Syz147064 */ 230*8120SCathy.Zhou@Sun.COM status = dladm_destroy_datalink_id(linkid, DLADM_OPT_ACTIVE); 231*8120SCathy.Zhou@Sun.COM if (status != DLADM_STATUS_OK) 232*8120SCathy.Zhou@Sun.COM return (status); 233*8120SCathy.Zhou@Sun.COM 2345895Syz147064 (void) dladm_set_linkprop(linkid, NULL, NULL, 0, 2355895Syz147064 DLADM_OPT_ACTIVE); 2365895Syz147064 2375895Syz147064 (*flagsp) &= ~DLMGMT_ACTIVE; 2385895Syz147064 status = DLADM_STATUS_OK; 2395895Syz147064 } 2405895Syz147064 return (status); 2415895Syz147064 } 2425895Syz147064 2435895Syz147064 /* 2445895Syz147064 * Walk each entry in the data link configuration repository and 2455895Syz147064 * call fn on the linkid and arg. 2465895Syz147064 */ 2475895Syz147064 dladm_status_t 2485895Syz147064 dladm_walk_datalink_id(int (*fn)(datalink_id_t, void *), void *argp, 2495895Syz147064 datalink_class_t class, datalink_media_t dmedia, uint32_t flags) 2505895Syz147064 { 2515895Syz147064 dlmgmt_door_getnext_t getnext; 2525895Syz147064 dlmgmt_getnext_retval_t retval; 2535895Syz147064 uint32_t dlmgmt_flags; 2545895Syz147064 datalink_id_t linkid = DATALINK_INVALID_LINKID; 2555895Syz147064 dladm_status_t status = DLADM_STATUS_OK; 2565895Syz147064 2575895Syz147064 if (fn == NULL) 2585895Syz147064 return (DLADM_STATUS_BADARG); 2595895Syz147064 2605895Syz147064 dlmgmt_flags = (flags & DLADM_OPT_ACTIVE) ? DLMGMT_ACTIVE : 0; 2615895Syz147064 dlmgmt_flags |= ((flags & DLADM_OPT_PERSIST) ? DLMGMT_PERSIST : 0); 2625895Syz147064 2635895Syz147064 getnext.ld_cmd = DLMGMT_CMD_GETNEXT; 2645895Syz147064 getnext.ld_class = class; 2655895Syz147064 getnext.ld_dmedia = dmedia; 2665895Syz147064 getnext.ld_flags = dlmgmt_flags; 2675895Syz147064 2685895Syz147064 do { 2695895Syz147064 getnext.ld_linkid = linkid; 2706263Sseb if ((status = dladm_door_call(&getnext, sizeof (getnext), 2716263Sseb &retval, sizeof (retval))) != DLADM_STATUS_OK) { 2725895Syz147064 /* 2735895Syz147064 * done with walking 2745895Syz147064 */ 2755895Syz147064 break; 2765895Syz147064 } 2775895Syz147064 2785895Syz147064 linkid = retval.lr_linkid; 2795895Syz147064 if ((retval.lr_class == DATALINK_CLASS_PHYS) && 2805895Syz147064 (retval.lr_flags & DLMGMT_ACTIVE)) { 2815895Syz147064 /* 2825895Syz147064 * An active physical link reported by the dlmgmtd 2835895Syz147064 * daemon might not be active anymore. Check its 2845895Syz147064 * real status. 2855895Syz147064 */ 2865895Syz147064 if (i_dladm_phys_status(linkid, &retval.lr_flags) != 2875895Syz147064 DLADM_STATUS_OK) { 2885895Syz147064 continue; 2895895Syz147064 } 2905895Syz147064 2915895Syz147064 if (!(dlmgmt_flags & retval.lr_flags)) 2925895Syz147064 continue; 2935895Syz147064 } 2945895Syz147064 2955895Syz147064 if (fn(linkid, argp) == DLADM_WALK_TERMINATE) 2965895Syz147064 break; 2975895Syz147064 } while (linkid != DATALINK_INVALID_LINKID); 2985895Syz147064 2995895Syz147064 return (status); 3005895Syz147064 } 3015895Syz147064 3025895Syz147064 /* 3035895Syz147064 * Get the link properties structure for the given link. 3045895Syz147064 */ 3055895Syz147064 dladm_status_t 3065895Syz147064 dladm_read_conf(datalink_id_t linkid, dladm_conf_t *confp) 3075895Syz147064 { 3086263Sseb dlmgmt_door_readconf_t readconf; 3095895Syz147064 dlmgmt_readconf_retval_t retval; 3105895Syz147064 dladm_status_t status; 3115895Syz147064 3125895Syz147064 if (linkid == DATALINK_INVALID_LINKID || confp == NULL) 3135895Syz147064 return (DLADM_STATUS_BADARG); 3145895Syz147064 3155895Syz147064 readconf.ld_linkid = linkid; 3165895Syz147064 readconf.ld_cmd = DLMGMT_CMD_READCONF; 3175895Syz147064 3186263Sseb if ((status = dladm_door_call(&readconf, sizeof (readconf), 3196263Sseb &retval, sizeof (retval))) == DLADM_STATUS_OK) { 3206263Sseb *confp = retval.lr_conf; 3216263Sseb } 3226263Sseb return (status); 3235895Syz147064 } 3245895Syz147064 3255895Syz147064 /* 3265895Syz147064 * Commit the given link to the data link configuration repository so 3275895Syz147064 * that it will persist across reboots. 3285895Syz147064 */ 3295895Syz147064 dladm_status_t 3305895Syz147064 dladm_write_conf(dladm_conf_t conf) 3315895Syz147064 { 3325895Syz147064 dlmgmt_door_writeconf_t writeconf; 3335895Syz147064 dlmgmt_writeconf_retval_t retval; 3345895Syz147064 3355895Syz147064 if (conf == DLADM_INVALID_CONF) 3365895Syz147064 return (DLADM_STATUS_BADARG); 3375895Syz147064 3385895Syz147064 writeconf.ld_cmd = DLMGMT_CMD_WRITECONF; 3395895Syz147064 writeconf.ld_conf = conf; 3405895Syz147064 3416263Sseb return (dladm_door_call(&writeconf, sizeof (writeconf), 3426263Sseb &retval, sizeof (retval))); 3435895Syz147064 } 3445895Syz147064 3455895Syz147064 /* 3465895Syz147064 * Given a link ID and a key, get the matching information from 3475895Syz147064 * data link configuration repository. 3485895Syz147064 */ 3495895Syz147064 dladm_status_t 3505895Syz147064 dladm_get_conf_field(dladm_conf_t conf, const char *attr, void *attrval, 3515895Syz147064 size_t attrsz) 3525895Syz147064 { 3536263Sseb dlmgmt_door_getattr_t getattr; 3546263Sseb dlmgmt_getattr_retval_t retval; 3556263Sseb dladm_status_t status; 3565895Syz147064 3575895Syz147064 if (conf == DLADM_INVALID_CONF || attrval == NULL || 3586263Sseb attrsz == 0 || attr == NULL) { 3595895Syz147064 return (DLADM_STATUS_BADARG); 3605895Syz147064 } 3615895Syz147064 3625895Syz147064 getattr.ld_cmd = DLMGMT_CMD_GETATTR; 3635895Syz147064 getattr.ld_conf = conf; 3645895Syz147064 (void) strlcpy(getattr.ld_attr, attr, MAXLINKATTRLEN); 3655895Syz147064 3666263Sseb if ((status = dladm_door_call(&getattr, sizeof (getattr), &retval, 3676263Sseb sizeof (retval))) != DLADM_STATUS_OK) { 3686263Sseb return (status); 3696263Sseb } 3705895Syz147064 3716263Sseb if (retval.lr_attrsz > attrsz) 3726263Sseb return (DLADM_STATUS_TOOSMALL); 3735895Syz147064 3746263Sseb bcopy(retval.lr_attrval, attrval, retval.lr_attrsz); 3756263Sseb return (DLADM_STATUS_OK); 3765895Syz147064 } 3775895Syz147064 3785895Syz147064 /* 3795895Syz147064 * Get the link ID that is associated with the given name. 3805895Syz147064 */ 3815895Syz147064 dladm_status_t 3825895Syz147064 dladm_name2info(const char *link, datalink_id_t *linkidp, uint32_t *flagp, 3835895Syz147064 datalink_class_t *classp, uint32_t *mediap) 3845895Syz147064 { 3855895Syz147064 dlmgmt_door_getlinkid_t getlinkid; 3865895Syz147064 dlmgmt_getlinkid_retval_t retval; 3875895Syz147064 datalink_id_t linkid; 3885895Syz147064 dladm_status_t status; 3895895Syz147064 3905895Syz147064 getlinkid.ld_cmd = DLMGMT_CMD_GETLINKID; 3915895Syz147064 (void) strlcpy(getlinkid.ld_link, link, MAXLINKNAMELEN); 3925895Syz147064 3936263Sseb if ((status = dladm_door_call(&getlinkid, sizeof (getlinkid), 3946263Sseb &retval, sizeof (retval))) != DLADM_STATUS_OK) { 3955895Syz147064 return (status); 3966263Sseb } 3975895Syz147064 3985895Syz147064 linkid = retval.lr_linkid; 3995895Syz147064 if (retval.lr_class == DATALINK_CLASS_PHYS && 4005895Syz147064 retval.lr_flags & DLMGMT_ACTIVE) { 4015895Syz147064 /* 4025895Syz147064 * An active physical link reported by the dlmgmtd daemon 4035895Syz147064 * might not be active anymore. Check and set its real status. 4045895Syz147064 */ 4055895Syz147064 status = i_dladm_phys_status(linkid, &retval.lr_flags); 4065895Syz147064 if (status != DLADM_STATUS_OK) 4075895Syz147064 return (status); 4085895Syz147064 } 4095895Syz147064 4105895Syz147064 if (linkidp != NULL) 4115895Syz147064 *linkidp = linkid; 4125895Syz147064 if (flagp != NULL) { 4135895Syz147064 *flagp = retval.lr_flags & DLMGMT_ACTIVE ? DLADM_OPT_ACTIVE : 0; 4145895Syz147064 *flagp |= (retval.lr_flags & DLMGMT_PERSIST) ? 4155895Syz147064 DLADM_OPT_PERSIST : 0; 4165895Syz147064 } 4175895Syz147064 if (classp != NULL) 4185895Syz147064 *classp = retval.lr_class; 4195895Syz147064 if (mediap != NULL) 4205895Syz147064 *mediap = retval.lr_media; 4215895Syz147064 4225895Syz147064 return (DLADM_STATUS_OK); 4235895Syz147064 } 4245895Syz147064 4255895Syz147064 /* 4265895Syz147064 * Get the link name that is associated with the given id. 4275895Syz147064 */ 4285895Syz147064 dladm_status_t 4295895Syz147064 dladm_datalink_id2info(datalink_id_t linkid, uint32_t *flagp, 4305895Syz147064 datalink_class_t *classp, uint32_t *mediap, char *link, size_t len) 4315895Syz147064 { 4326263Sseb dlmgmt_door_getname_t getname; 4336263Sseb dlmgmt_getname_retval_t retval; 4346263Sseb dladm_status_t status; 4355895Syz147064 4365895Syz147064 if ((linkid == DATALINK_INVALID_LINKID) || (link != NULL && len == 0) || 4375895Syz147064 (link == NULL && len != 0)) { 4385895Syz147064 return (DLADM_STATUS_BADARG); 4395895Syz147064 } 4405895Syz147064 4415895Syz147064 getname.ld_cmd = DLMGMT_CMD_GETNAME; 4425895Syz147064 getname.ld_linkid = linkid; 4436263Sseb if ((status = dladm_door_call(&getname, sizeof (getname), &retval, 4446263Sseb sizeof (retval))) != DLADM_STATUS_OK) { 4455895Syz147064 return (status); 4466263Sseb } 4475895Syz147064 4486263Sseb if (len != 0 && (strlen(retval.lr_link) + 1 > len)) 4495895Syz147064 return (DLADM_STATUS_TOOSMALL); 4505895Syz147064 4515895Syz147064 if (retval.lr_class == DATALINK_CLASS_PHYS && 4525895Syz147064 retval.lr_flags & DLMGMT_ACTIVE) { 4535895Syz147064 /* 4545895Syz147064 * An active physical link reported by the dlmgmtd daemon 4555895Syz147064 * might not be active anymore. Check and set its real status. 4565895Syz147064 */ 4575895Syz147064 status = i_dladm_phys_status(linkid, &retval.lr_flags); 4585895Syz147064 if (status != DLADM_STATUS_OK) 4595895Syz147064 return (status); 4605895Syz147064 } 4615895Syz147064 4625895Syz147064 if (link != NULL) 4635895Syz147064 (void) strlcpy(link, retval.lr_link, len); 4645895Syz147064 if (classp != NULL) 4655895Syz147064 *classp = retval.lr_class; 4665895Syz147064 if (mediap != NULL) 4675895Syz147064 *mediap = retval.lr_media; 4685895Syz147064 if (flagp != NULL) { 4695895Syz147064 *flagp = retval.lr_flags & DLMGMT_ACTIVE ? 4705895Syz147064 DLADM_OPT_ACTIVE : 0; 4715895Syz147064 *flagp |= (retval.lr_flags & DLMGMT_PERSIST) ? 4725895Syz147064 DLADM_OPT_PERSIST : 0; 4735895Syz147064 } 4745895Syz147064 return (DLADM_STATUS_OK); 4755895Syz147064 } 4765895Syz147064 4775895Syz147064 /* 4785895Syz147064 * Set the given attr with the given attrval for the given link. 4795895Syz147064 */ 4805895Syz147064 dladm_status_t 4815895Syz147064 dladm_set_conf_field(dladm_conf_t conf, const char *attr, 4825895Syz147064 dladm_datatype_t type, const void *attrval) 4835895Syz147064 { 4846263Sseb dlmgmt_door_setattr_t setattr; 4856263Sseb dlmgmt_setattr_retval_t retval; 4866263Sseb size_t attrsz; 4875895Syz147064 4886263Sseb if (attr == NULL || attrval == NULL) 4895895Syz147064 return (DLADM_STATUS_BADARG); 4905895Syz147064 4915895Syz147064 if (type == DLADM_TYPE_STR) 4925895Syz147064 attrsz = strlen(attrval) + 1; 4935895Syz147064 else 4945895Syz147064 attrsz = dladm_datatype_size[type]; 4955895Syz147064 4966263Sseb if (attrsz > MAXLINKATTRVALLEN) 4976263Sseb return (DLADM_STATUS_TOOSMALL); 4985895Syz147064 4996263Sseb setattr.ld_cmd = DLMGMT_CMD_SETATTR; 5006263Sseb setattr.ld_conf = conf; 5016263Sseb (void) strlcpy(setattr.ld_attr, attr, MAXLINKATTRLEN); 5026263Sseb setattr.ld_attrsz = attrsz; 5036263Sseb setattr.ld_type = type; 5046263Sseb bcopy(attrval, &setattr.ld_attrval, attrsz); 5055895Syz147064 5066263Sseb return (dladm_door_call(&setattr, sizeof (setattr), 5076263Sseb &retval, sizeof (retval))); 5085895Syz147064 } 5095895Syz147064 5105895Syz147064 /* 5115895Syz147064 * Unset the given attr the given link. 5125895Syz147064 */ 5135895Syz147064 dladm_status_t 5145895Syz147064 dladm_unset_conf_field(dladm_conf_t conf, const char *attr) 5155895Syz147064 { 5165895Syz147064 dlmgmt_door_unsetattr_t unsetattr; 5175895Syz147064 dlmgmt_unsetattr_retval_t retval; 5185895Syz147064 5196263Sseb if (attr == NULL) 5205895Syz147064 return (DLADM_STATUS_BADARG); 5215895Syz147064 5225895Syz147064 unsetattr.ld_cmd = DLMGMT_CMD_UNSETATTR; 5235895Syz147064 unsetattr.ld_conf = conf; 5245895Syz147064 (void) strlcpy(unsetattr.ld_attr, attr, MAXLINKATTRLEN); 5255895Syz147064 5266263Sseb return (dladm_door_call(&unsetattr, sizeof (unsetattr), 5276263Sseb &retval, sizeof (retval))); 5285895Syz147064 } 5295895Syz147064 5305895Syz147064 /* 5315895Syz147064 * Remove the given link ID and its entry from the data link configuration 5325895Syz147064 * repository. 5335895Syz147064 */ 5345895Syz147064 dladm_status_t 5355895Syz147064 dladm_remove_conf(datalink_id_t linkid) 5365895Syz147064 { 5375895Syz147064 dlmgmt_door_removeconf_t removeconf; 5385895Syz147064 dlmgmt_removeconf_retval_t retval; 5395895Syz147064 5405895Syz147064 removeconf.ld_cmd = DLMGMT_CMD_REMOVECONF; 5415895Syz147064 removeconf.ld_linkid = linkid; 5425895Syz147064 5436263Sseb return (dladm_door_call(&removeconf, sizeof (removeconf), 5446263Sseb &retval, sizeof (retval))); 5455895Syz147064 } 5465895Syz147064 5475895Syz147064 /* 5485895Syz147064 * Free the contents of the link structure. 5495895Syz147064 */ 5505895Syz147064 void 5515895Syz147064 dladm_destroy_conf(dladm_conf_t conf) 5525895Syz147064 { 5535895Syz147064 dlmgmt_door_destroyconf_t destroyconf; 5545895Syz147064 dlmgmt_destroyconf_retval_t retval; 5555895Syz147064 5565895Syz147064 if (conf == DLADM_INVALID_CONF) 5575895Syz147064 return; 5585895Syz147064 5595895Syz147064 destroyconf.ld_cmd = DLMGMT_CMD_DESTROYCONF; 5605895Syz147064 destroyconf.ld_conf = conf; 5615895Syz147064 5626263Sseb (void) dladm_door_call(&destroyconf, sizeof (destroyconf), 5636263Sseb &retval, sizeof (retval)); 5645895Syz147064 } 565