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 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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 26 #ifndef _LIBDLADM_H 27 #define _LIBDLADM_H 28 29 #include <sys/dls_mgmt.h> 30 #include <sys/dlpi.h> 31 32 /* 33 * This file includes structures, macros and common routines shared by all 34 * data-link administration, and routines which do not directly administrate 35 * links. For example, dladm_status2str(). 36 */ 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 #define LINKID_STR_WIDTH 10 43 #define DLADM_STRSIZE 256 44 45 /* 46 * option flags taken by the libdladm functions 47 * 48 * - DLADM_OPT_ACTIVE: 49 * The function requests to bringup some configuration that only take 50 * effect on active system (not persistent). 51 * 52 * - DLADM_OPT_PERSIST: 53 * The function requests to persist some configuration. 54 * 55 * - DLADM_OPT_CREATE: 56 * Today, only used by dladm_set_secobj() - requests to create a secobj. 57 * 58 * - DLADM_OPT_FORCE: 59 * The function requests to execute a specific operation forcefully. 60 * 61 * - DLADM_OPT_PREFIX: 62 * The function requests to generate a link name using the specified prefix. 63 * 64 * - DLADM_OPT_VLAN: 65 * Signifies VLAN creation code path 66 * 67 * - DLADM_OPT_HWRINGS: 68 * Requires a hardware group of rings when creating a vnic. 69 * 70 * - DLADM_OPT_NOREFRESH: 71 * Do not refresh the daemon after setting parameter (used by STP mcheck). 72 */ 73 #define DLADM_OPT_ACTIVE 0x00000001 74 #define DLADM_OPT_PERSIST 0x00000002 75 #define DLADM_OPT_CREATE 0x00000004 76 #define DLADM_OPT_FORCE 0x00000008 77 #define DLADM_OPT_PREFIX 0x00000010 78 #define DLADM_OPT_ANCHOR 0x00000020 79 #define DLADM_OPT_VLAN 0x00000040 80 #define DLADM_OPT_HWRINGS 0x00000080 81 #define DLADM_OPT_NOREFRESH 0x00000100 82 83 #define DLADM_WALK_TERMINATE 0 84 #define DLADM_WALK_CONTINUE -1 85 86 #define DLADM_MAX_ARG_CNT 32 87 #define DLADM_MAX_ARG_VALS 32 88 89 typedef enum { 90 DLADM_STATUS_OK = 0, 91 DLADM_STATUS_BADARG, 92 DLADM_STATUS_FAILED, 93 DLADM_STATUS_TOOSMALL, 94 DLADM_STATUS_NOTSUP, 95 DLADM_STATUS_NOTFOUND, 96 DLADM_STATUS_BADVAL, 97 DLADM_STATUS_NOMEM, 98 DLADM_STATUS_EXIST, 99 DLADM_STATUS_LINKINVAL, 100 DLADM_STATUS_PROPRDONLY, 101 DLADM_STATUS_BADVALCNT, 102 DLADM_STATUS_DBNOTFOUND, 103 DLADM_STATUS_DENIED, 104 DLADM_STATUS_IOERR, 105 DLADM_STATUS_TEMPONLY, 106 DLADM_STATUS_TIMEDOUT, 107 DLADM_STATUS_ISCONN, 108 DLADM_STATUS_NOTCONN, 109 DLADM_STATUS_REPOSITORYINVAL, 110 DLADM_STATUS_MACADDRINVAL, 111 DLADM_STATUS_KEYINVAL, 112 DLADM_STATUS_INVALIDMACADDRLEN, 113 DLADM_STATUS_INVALIDMACADDRTYPE, 114 DLADM_STATUS_LINKBUSY, 115 DLADM_STATUS_VIDINVAL, 116 DLADM_STATUS_NONOTIF, 117 DLADM_STATUS_TRYAGAIN, 118 DLADM_STATUS_BADTIMEVAL, 119 DLADM_STATUS_INVALIDMACADDR, 120 DLADM_STATUS_INVALIDMACADDRNIC, 121 DLADM_STATUS_INVALIDMACADDRINUSE, 122 DLADM_STATUS_MACFACTORYSLOTINVALID, 123 DLADM_STATUS_MACFACTORYSLOTUSED, 124 DLADM_STATUS_MACFACTORYSLOTALLUSED, 125 DLADM_STATUS_MACFACTORYNOTSUP, 126 DLADM_STATUS_INVALIDMACPREFIX, 127 DLADM_STATUS_INVALIDMACPREFIXLEN, 128 DLADM_STATUS_CPUMAX, 129 DLADM_STATUS_CPUERR, 130 DLADM_STATUS_CPUNOTONLINE, 131 DLADM_STATUS_DB_NOTFOUND, 132 DLADM_STATUS_DB_PARSE_ERR, 133 DLADM_STATUS_PROP_PARSE_ERR, 134 DLADM_STATUS_ATTR_PARSE_ERR, 135 DLADM_STATUS_FLOW_DB_ERR, 136 DLADM_STATUS_FLOW_DB_OPEN_ERR, 137 DLADM_STATUS_FLOW_DB_PARSE_ERR, 138 DLADM_STATUS_FLOWPROP_DB_PARSE_ERR, 139 DLADM_STATUS_FLOW_ADD_ERR, 140 DLADM_STATUS_FLOW_WALK_ERR, 141 DLADM_STATUS_FLOW_IDENTICAL, 142 DLADM_STATUS_FLOW_INCOMPATIBLE, 143 DLADM_STATUS_FLOW_EXISTS, 144 DLADM_STATUS_PERSIST_FLOW_EXISTS, 145 DLADM_STATUS_INVALID_IP, 146 DLADM_STATUS_INVALID_PREFIXLEN, 147 DLADM_STATUS_INVALID_PROTOCOL, 148 DLADM_STATUS_INVALID_PORT, 149 DLADM_STATUS_INVALID_DSF, 150 DLADM_STATUS_INVALID_DSFMASK, 151 DLADM_STATUS_INVALID_MACMARGIN, 152 DLADM_STATUS_NOTDEFINED, 153 DLADM_STATUS_BADPROP, 154 DLADM_STATUS_MINMAXBW, 155 DLADM_STATUS_NO_HWRINGS, 156 DLADM_STATUS_PERMONLY, 157 DLADM_STATUS_OPTMISSING 158 } dladm_status_t; 159 160 typedef enum { 161 DLADM_TYPE_STR, 162 DLADM_TYPE_BOOLEAN, 163 DLADM_TYPE_UINT64 164 } dladm_datatype_t; 165 166 typedef int dladm_conf_t; 167 #define DLADM_INVALID_CONF 0 168 169 /* opaque dladm handle to libdladm functions */ 170 struct dladm_handle; 171 typedef struct dladm_handle *dladm_handle_t; 172 173 /* open/close handle */ 174 extern dladm_status_t dladm_open(dladm_handle_t *); 175 extern void dladm_close(dladm_handle_t); 176 177 /* 178 * retrieve the dld file descriptor from handle, only libdladm and 179 * dlmgmtd are given access to the door file descriptor. 180 */ 181 extern int dladm_dld_fd(dladm_handle_t); 182 183 typedef struct dladm_arg_info { 184 const char *ai_name; 185 char *ai_val[DLADM_MAX_ARG_VALS]; 186 uint_t ai_count; 187 } dladm_arg_info_t; 188 189 typedef struct dladm_arg_list { 190 dladm_arg_info_t al_info[DLADM_MAX_ARG_CNT]; 191 uint_t al_count; 192 char *al_buf; 193 } dladm_arg_list_t; 194 195 typedef enum { 196 DLADM_LOGTYPE_LINK = 1, 197 DLADM_LOGTYPE_FLOW 198 } dladm_logtype_t; 199 200 typedef struct dladm_usage { 201 char du_name[MAXLINKNAMELEN]; 202 uint64_t du_duration; 203 uint64_t du_stime; 204 uint64_t du_etime; 205 uint64_t du_ipackets; 206 uint64_t du_rbytes; 207 uint64_t du_opackets; 208 uint64_t du_obytes; 209 uint64_t du_bandwidth; 210 boolean_t du_last; 211 } dladm_usage_t; 212 213 extern const char *dladm_status2str(dladm_status_t, char *); 214 extern dladm_status_t dladm_set_rootdir(const char *); 215 extern const char *dladm_class2str(datalink_class_t, char *); 216 extern const char *dladm_media2str(uint32_t, char *); 217 extern uint32_t dladm_str2media(const char *); 218 extern boolean_t dladm_valid_linkname(const char *); 219 extern boolean_t dladm_str2interval(char *, uint32_t *); 220 extern dladm_status_t dladm_str2bw(char *, uint64_t *); 221 extern const char *dladm_bw2str(int64_t, char *); 222 223 extern dladm_status_t dladm_parse_flow_props(char *, dladm_arg_list_t **, 224 boolean_t); 225 extern dladm_status_t dladm_parse_link_props(char *, dladm_arg_list_t **, 226 boolean_t); 227 extern void dladm_free_props(dladm_arg_list_t *); 228 extern dladm_status_t dladm_parse_flow_attrs(char *, dladm_arg_list_t **, 229 boolean_t); 230 extern void dladm_free_attrs(dladm_arg_list_t *); 231 232 extern dladm_status_t dladm_start_usagelog(dladm_handle_t, dladm_logtype_t, 233 uint_t); 234 extern dladm_status_t dladm_stop_usagelog(dladm_handle_t, dladm_logtype_t); 235 extern dladm_status_t dladm_walk_usage_res(int (*)(dladm_usage_t *, void *), 236 int, char *, char *, char *, char *, void *); 237 extern dladm_status_t dladm_walk_usage_time(int (*)(dladm_usage_t *, void *), 238 int, char *, char *, char *, void *); 239 extern dladm_status_t dladm_usage_summary(int (*)(dladm_usage_t *, void *), 240 int, char *, void *); 241 extern dladm_status_t dladm_usage_dates(int (*)(dladm_usage_t *, void *), 242 int, char *, char *, void *); 243 244 #ifdef __cplusplus 245 } 246 #endif 247 248 #endif /* _LIBDLADM_H */ 249