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