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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 23 */ 24 25 /* 26 * Copyright 2015, Joyent, Inc. 27 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association 28 */ 29 30 #ifndef _LIBDLADM_H 31 #define _LIBDLADM_H 32 33 #include <sys/dls_mgmt.h> 34 #include <sys/dld.h> 35 #include <sys/dlpi.h> 36 #include <libnvpair.h> 37 #include <kstat.h> 38 39 /* 40 * This file includes structures, macros and common routines shared by all 41 * data-link administration, and routines which do not directly administrate 42 * links. For example, dladm_status2str(). 43 */ 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 #define LINKID_STR_WIDTH 10 50 #define DLADM_STRSIZE 256 51 52 /* 53 * option flags taken by the libdladm functions 54 * 55 * - DLADM_OPT_ACTIVE: 56 * The function requests to bringup some configuration that only take 57 * effect on active system (not persistent). 58 * 59 * - DLADM_OPT_PERSIST: 60 * The function requests to persist some configuration. 61 * 62 * - DLADM_OPT_CREATE: 63 * Today, only used by dladm_set_secobj() - requests to create a secobj. 64 * 65 * - DLADM_OPT_FORCE: 66 * The function requests to execute a specific operation forcefully. 67 * 68 * - DLADM_OPT_PREFIX: 69 * The function requests to generate a link name using the specified prefix. 70 * 71 * - DLADM_OPT_VLAN: 72 * Signifies VLAN creation code path 73 * 74 * - DLADM_OPT_NOREFRESH: 75 * Do not refresh the daemon after setting parameter (used by STP mcheck). 76 * 77 * - DLADM_OPT_BOOT: 78 * Bypass check functions during boot (used by pool property since pools 79 * can come up after link properties are set) 80 */ 81 #define DLADM_OPT_ACTIVE 0x00000001 82 #define DLADM_OPT_PERSIST 0x00000002 83 #define DLADM_OPT_CREATE 0x00000004 84 #define DLADM_OPT_FORCE 0x00000008 85 #define DLADM_OPT_PREFIX 0x00000010 86 #define DLADM_OPT_ANCHOR 0x00000020 87 #define DLADM_OPT_VLAN 0x00000040 88 #define DLADM_OPT_NOREFRESH 0x00000080 89 #define DLADM_OPT_BOOT 0x00000100 90 91 #define DLADM_WALK_TERMINATE 0 92 #define DLADM_WALK_CONTINUE -1 93 94 #define DLADM_MAX_ARG_CNT 32 95 #define DLADM_MAX_ARG_VALS 64 96 97 typedef enum { 98 DLADM_STATUS_OK = 0, 99 DLADM_STATUS_BADARG, 100 DLADM_STATUS_FAILED, 101 DLADM_STATUS_TOOSMALL, 102 DLADM_STATUS_NOTSUP, 103 DLADM_STATUS_NOTFOUND, 104 DLADM_STATUS_BADVAL, 105 DLADM_STATUS_NOMEM, 106 DLADM_STATUS_EXIST, 107 DLADM_STATUS_LINKINVAL, 108 DLADM_STATUS_PROPRDONLY, 109 DLADM_STATUS_BADVALCNT, 110 DLADM_STATUS_DBNOTFOUND, 111 DLADM_STATUS_DENIED, 112 DLADM_STATUS_IOERR, 113 DLADM_STATUS_TEMPONLY, 114 DLADM_STATUS_TIMEDOUT, 115 DLADM_STATUS_ISCONN, 116 DLADM_STATUS_NOTCONN, 117 DLADM_STATUS_REPOSITORYINVAL, 118 DLADM_STATUS_MACADDRINVAL, 119 DLADM_STATUS_KEYINVAL, 120 DLADM_STATUS_INVALIDMACADDRLEN, 121 DLADM_STATUS_INVALIDMACADDRTYPE, 122 DLADM_STATUS_LINKBUSY, 123 DLADM_STATUS_VIDINVAL, 124 DLADM_STATUS_NONOTIF, 125 DLADM_STATUS_TRYAGAIN, 126 DLADM_STATUS_IPTUNTYPE, 127 DLADM_STATUS_IPTUNTYPEREQD, 128 DLADM_STATUS_BADIPTUNLADDR, 129 DLADM_STATUS_BADIPTUNRADDR, 130 DLADM_STATUS_ADDRINUSE, 131 DLADM_STATUS_BADTIMEVAL, 132 DLADM_STATUS_INVALIDMACADDR, 133 DLADM_STATUS_INVALIDMACADDRNIC, 134 DLADM_STATUS_INVALIDMACADDRINUSE, 135 DLADM_STATUS_MACFACTORYSLOTINVALID, 136 DLADM_STATUS_MACFACTORYSLOTUSED, 137 DLADM_STATUS_MACFACTORYSLOTALLUSED, 138 DLADM_STATUS_MACFACTORYNOTSUP, 139 DLADM_STATUS_INVALIDMACPREFIX, 140 DLADM_STATUS_INVALIDMACPREFIXLEN, 141 DLADM_STATUS_BADCPUID, 142 DLADM_STATUS_CPUERR, 143 DLADM_STATUS_CPUNOTONLINE, 144 DLADM_STATUS_BADRANGE, 145 DLADM_STATUS_TOOMANYELEMENTS, 146 DLADM_STATUS_DB_NOTFOUND, 147 DLADM_STATUS_DB_PARSE_ERR, 148 DLADM_STATUS_PROP_PARSE_ERR, 149 DLADM_STATUS_ATTR_PARSE_ERR, 150 DLADM_STATUS_FLOW_DB_ERR, 151 DLADM_STATUS_FLOW_DB_OPEN_ERR, 152 DLADM_STATUS_FLOW_DB_PARSE_ERR, 153 DLADM_STATUS_FLOWPROP_DB_PARSE_ERR, 154 DLADM_STATUS_FLOW_ADD_ERR, 155 DLADM_STATUS_FLOW_WALK_ERR, 156 DLADM_STATUS_FLOW_IDENTICAL, 157 DLADM_STATUS_FLOW_INCOMPATIBLE, 158 DLADM_STATUS_FLOW_EXISTS, 159 DLADM_STATUS_PERSIST_FLOW_EXISTS, 160 DLADM_STATUS_INVALID_IP, 161 DLADM_STATUS_INVALID_PREFIXLEN, 162 DLADM_STATUS_INVALID_PROTOCOL, 163 DLADM_STATUS_INVALID_PORT, 164 DLADM_STATUS_INVALID_DSF, 165 DLADM_STATUS_INVALID_DSFMASK, 166 DLADM_STATUS_INVALID_MACMARGIN, 167 DLADM_STATUS_NOTDEFINED, 168 DLADM_STATUS_BADPROP, 169 DLADM_STATUS_MINMAXBW, 170 DLADM_STATUS_NO_HWRINGS, 171 DLADM_STATUS_PERMONLY, 172 DLADM_STATUS_OPTMISSING, 173 DLADM_STATUS_POOLCPU, 174 DLADM_STATUS_INVALID_PORT_INSTANCE, 175 DLADM_STATUS_PORT_IS_DOWN, 176 DLADM_STATUS_PKEY_NOT_PRESENT, 177 DLADM_STATUS_PARTITION_EXISTS, 178 DLADM_STATUS_INVALID_PKEY, 179 DLADM_STATUS_NO_IB_HW_RESOURCE, 180 DLADM_STATUS_INVALID_PKEY_TBL_SIZE, 181 DLADM_STATUS_PORT_NOPROTO, 182 DLADM_STATUS_INVALID_MTU, 183 DLADM_STATUS_PERSIST_ON_TEMP, 184 DLADM_STATUS_BAD_ENCAP 185 } dladm_status_t; 186 187 typedef enum { 188 DLADM_TYPE_STR, 189 DLADM_TYPE_BOOLEAN, 190 DLADM_TYPE_UINT64 191 } dladm_datatype_t; 192 193 typedef struct { 194 boolean_t ds_readonly; 195 union { 196 int dsu_confid; 197 nvlist_t *dsu_nvl; 198 } ds_u; 199 } dladm_conf_t; 200 201 #define ds_confid ds_u.dsu_confid 202 #define ds_nvl ds_u.dsu_nvl 203 204 #define DLADM_INVALID_CONF 0 205 206 /* opaque dladm handle to libdladm functions */ 207 struct dladm_handle; 208 typedef struct dladm_handle *dladm_handle_t; 209 210 /* open/close handle */ 211 extern dladm_status_t dladm_open(dladm_handle_t *); 212 extern void dladm_close(dladm_handle_t); 213 214 /* 215 * retrieve the dld file descriptor from handle, only libdladm and 216 * dlmgmtd are given access to the door file descriptor. 217 */ 218 extern int dladm_dld_fd(dladm_handle_t); 219 /* 220 * Retrieve kstat_ctl_t* from handle.The libkstat handle is opened 221 * when the first caller needs it.This allows the library to share 222 * the kstat handle. 223 */ 224 extern kstat_ctl_t *dladm_dld_kcp(dladm_handle_t); 225 226 typedef struct dladm_arg_info { 227 const char *ai_name; 228 char *ai_val[DLADM_MAX_ARG_VALS]; 229 uint_t ai_count; 230 } dladm_arg_info_t; 231 232 typedef struct dladm_arg_list { 233 dladm_arg_info_t al_info[DLADM_MAX_ARG_CNT]; 234 uint_t al_count; 235 char *al_buf; 236 } dladm_arg_list_t; 237 238 typedef struct dladm_errlist { 239 uint_t el_count; 240 uint_t el_alloc; 241 char **el_errs; 242 } dladm_errlist_t; 243 244 typedef enum { 245 DLADM_LOGTYPE_LINK = 1, 246 DLADM_LOGTYPE_FLOW 247 } dladm_logtype_t; 248 249 typedef struct dladm_usage { 250 char du_name[MAXLINKNAMELEN]; 251 uint64_t du_duration; 252 uint64_t du_stime; 253 uint64_t du_etime; 254 uint64_t du_ipackets; 255 uint64_t du_rbytes; 256 uint64_t du_opackets; 257 uint64_t du_obytes; 258 uint64_t du_bandwidth; 259 boolean_t du_last; 260 } dladm_usage_t; 261 262 extern const char *dladm_status2str(dladm_status_t, char *); 263 extern dladm_status_t dladm_set_rootdir(const char *); 264 extern const char *dladm_class2str(datalink_class_t, char *); 265 extern const char *dladm_media2str(uint32_t, char *); 266 extern uint32_t dladm_str2media(const char *); 267 extern boolean_t dladm_valid_linkname(const char *); 268 extern boolean_t dladm_str2interval(char *, uint32_t *); 269 extern dladm_status_t dladm_str2bw(char *, uint64_t *); 270 extern const char *dladm_bw2str(int64_t, char *); 271 extern dladm_status_t dladm_str2pri(char *, mac_priority_level_t *); 272 extern const char *dladm_pri2str(mac_priority_level_t, char *); 273 extern dladm_status_t dladm_str2protect(char *, uint32_t *); 274 extern const char *dladm_protect2str(uint32_t, char *); 275 extern dladm_status_t dladm_str2ipv4addr(char *, void *); 276 extern const char *dladm_ipv4addr2str(void *, char *); 277 extern dladm_status_t dladm_str2ipv6addr(char *, void *); 278 extern const char *dladm_ipv6addr2str(void *, char *); 279 280 extern dladm_status_t dladm_parse_flow_props(char *, dladm_arg_list_t **, 281 boolean_t); 282 extern dladm_status_t dladm_parse_link_props(char *, dladm_arg_list_t **, 283 boolean_t); 284 extern void dladm_free_props(dladm_arg_list_t *); 285 extern dladm_status_t dladm_parse_flow_attrs(char *, dladm_arg_list_t **, 286 boolean_t); 287 extern void dladm_free_attrs(dladm_arg_list_t *); 288 289 extern dladm_status_t dladm_start_usagelog(dladm_handle_t, dladm_logtype_t, 290 uint_t); 291 extern dladm_status_t dladm_stop_usagelog(dladm_handle_t, dladm_logtype_t); 292 extern dladm_status_t dladm_walk_usage_res(int (*)(dladm_usage_t *, void *), 293 int, char *, char *, char *, char *, void *); 294 extern dladm_status_t dladm_walk_usage_time(int (*)(dladm_usage_t *, void *), 295 int, char *, char *, char *, void *); 296 extern dladm_status_t dladm_usage_summary(int (*)(dladm_usage_t *, void *), 297 int, char *, void *); 298 extern dladm_status_t dladm_usage_dates(int (*)(dladm_usage_t *, void *), 299 int, char *, char *, void *); 300 extern dladm_status_t dladm_zone_boot(dladm_handle_t, zoneid_t); 301 extern dladm_status_t dladm_zone_halt(dladm_handle_t, zoneid_t); 302 303 extern dladm_status_t dladm_strs2range(char **, uint_t, mac_propval_type_t, 304 mac_propval_range_t **); 305 extern dladm_status_t dladm_range2list(const mac_propval_range_t *, void *, 306 uint_t *); 307 extern int dladm_range2strs(const mac_propval_range_t *, char **); 308 extern dladm_status_t dladm_list2range(void *, uint_t, mac_propval_type_t, 309 mac_propval_range_t **); 310 311 extern void dladm_errlist_init(dladm_errlist_t *); 312 extern void dladm_errlist_reset(dladm_errlist_t *); 313 314 #ifdef __cplusplus 315 } 316 #endif 317 318 #endif /* _LIBDLADM_H */ 319