xref: /titanic_50/usr/src/lib/libdladm/common/libdladm.h (revision a307732568c3d861c38b0342ae32434226d10e94)
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 #ifndef _LIBDLADM_H
26 #define	_LIBDLADM_H
27 
28 #include <sys/dls_mgmt.h>
29 #include <sys/dld.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_NOREFRESH:
68  *    Do not refresh the daemon after setting parameter (used by STP mcheck).
69  *
70  *  - DLADM_OPT_BOOT:
71  *    Bypass check functions during boot (used by pool property since pools
72  *    can come up after link properties are set)
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_NOREFRESH	0x00000080
82 #define	DLADM_OPT_BOOT		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	64
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_BADCPUID,
135 	DLADM_STATUS_CPUERR,
136 	DLADM_STATUS_CPUNOTONLINE,
137 	DLADM_STATUS_BADRANGE,
138 	DLADM_STATUS_TOOMANYELEMENTS,
139 	DLADM_STATUS_DB_NOTFOUND,
140 	DLADM_STATUS_DB_PARSE_ERR,
141 	DLADM_STATUS_PROP_PARSE_ERR,
142 	DLADM_STATUS_ATTR_PARSE_ERR,
143 	DLADM_STATUS_FLOW_DB_ERR,
144 	DLADM_STATUS_FLOW_DB_OPEN_ERR,
145 	DLADM_STATUS_FLOW_DB_PARSE_ERR,
146 	DLADM_STATUS_FLOWPROP_DB_PARSE_ERR,
147 	DLADM_STATUS_FLOW_ADD_ERR,
148 	DLADM_STATUS_FLOW_WALK_ERR,
149 	DLADM_STATUS_FLOW_IDENTICAL,
150 	DLADM_STATUS_FLOW_INCOMPATIBLE,
151 	DLADM_STATUS_FLOW_EXISTS,
152 	DLADM_STATUS_PERSIST_FLOW_EXISTS,
153 	DLADM_STATUS_INVALID_IP,
154 	DLADM_STATUS_INVALID_PREFIXLEN,
155 	DLADM_STATUS_INVALID_PROTOCOL,
156 	DLADM_STATUS_INVALID_PORT,
157 	DLADM_STATUS_INVALID_DSF,
158 	DLADM_STATUS_INVALID_DSFMASK,
159 	DLADM_STATUS_INVALID_MACMARGIN,
160 	DLADM_STATUS_NOTDEFINED,
161 	DLADM_STATUS_BADPROP,
162 	DLADM_STATUS_MINMAXBW,
163 	DLADM_STATUS_NO_HWRINGS,
164 	DLADM_STATUS_PERMONLY,
165 	DLADM_STATUS_OPTMISSING,
166 	DLADM_STATUS_POOLCPU,
167 	DLADM_STATUS_INVALID_PORT_INSTANCE,
168 	DLADM_STATUS_PORT_IS_DOWN,
169 	DLADM_STATUS_PKEY_NOT_PRESENT,
170 	DLADM_STATUS_PARTITION_EXISTS,
171 	DLADM_STATUS_INVALID_PKEY,
172 	DLADM_STATUS_NO_IB_HW_RESOURCE,
173 	DLADM_STATUS_INVALID_PKEY_TBL_SIZE,
174 	DLADM_STATUS_PORT_NOPROTO
175 } dladm_status_t;
176 
177 typedef enum {
178 	DLADM_TYPE_STR,
179 	DLADM_TYPE_BOOLEAN,
180 	DLADM_TYPE_UINT64
181 } dladm_datatype_t;
182 
183 typedef int dladm_conf_t;
184 #define	DLADM_INVALID_CONF	0
185 
186 /* opaque dladm handle to libdladm functions */
187 struct dladm_handle;
188 typedef struct dladm_handle *dladm_handle_t;
189 
190 /* open/close handle */
191 extern dladm_status_t	dladm_open(dladm_handle_t *);
192 extern void		dladm_close(dladm_handle_t);
193 
194 /*
195  * retrieve the dld file descriptor from handle, only libdladm and
196  * dlmgmtd are given access to the door file descriptor.
197  */
198 extern int	dladm_dld_fd(dladm_handle_t);
199 
200 typedef struct dladm_arg_info {
201 	const char	*ai_name;
202 	char		*ai_val[DLADM_MAX_ARG_VALS];
203 	uint_t		ai_count;
204 } dladm_arg_info_t;
205 
206 typedef struct dladm_arg_list {
207 	dladm_arg_info_t	al_info[DLADM_MAX_ARG_CNT];
208 	uint_t			al_count;
209 	char			*al_buf;
210 } dladm_arg_list_t;
211 
212 typedef enum {
213 	DLADM_LOGTYPE_LINK = 1,
214 	DLADM_LOGTYPE_FLOW
215 } dladm_logtype_t;
216 
217 typedef struct dladm_usage {
218 	char		du_name[MAXLINKNAMELEN];
219 	uint64_t	du_duration;
220 	uint64_t	du_stime;
221 	uint64_t	du_etime;
222 	uint64_t	du_ipackets;
223 	uint64_t	du_rbytes;
224 	uint64_t	du_opackets;
225 	uint64_t	du_obytes;
226 	uint64_t	du_bandwidth;
227 	boolean_t	du_last;
228 } dladm_usage_t;
229 
230 extern const char	*dladm_status2str(dladm_status_t, char *);
231 extern dladm_status_t	dladm_set_rootdir(const char *);
232 extern const char	*dladm_class2str(datalink_class_t, char *);
233 extern const char	*dladm_media2str(uint32_t, char *);
234 extern uint32_t		dladm_str2media(const char *);
235 extern boolean_t	dladm_valid_linkname(const char *);
236 extern boolean_t	dladm_str2interval(char *, uint32_t *);
237 extern dladm_status_t	dladm_str2bw(char *, uint64_t *);
238 extern const char	*dladm_bw2str(int64_t, char *);
239 extern dladm_status_t	dladm_str2pri(char *, mac_priority_level_t *);
240 extern const char	*dladm_pri2str(mac_priority_level_t, char *);
241 extern dladm_status_t	dladm_str2protect(char *, uint32_t *);
242 extern const char	*dladm_protect2str(uint32_t, char *);
243 extern dladm_status_t	dladm_str2ipv4addr(char *, void *);
244 extern const char	*dladm_ipv4addr2str(void *, char *);
245 extern dladm_status_t	dladm_str2ipv6addr(char *, void *);
246 extern const char	*dladm_ipv6addr2str(void *, char *);
247 
248 extern dladm_status_t	dladm_parse_flow_props(char *, dladm_arg_list_t **,
249 			    boolean_t);
250 extern dladm_status_t	dladm_parse_link_props(char *, dladm_arg_list_t **,
251 			    boolean_t);
252 extern void		dladm_free_props(dladm_arg_list_t *);
253 extern dladm_status_t	dladm_parse_flow_attrs(char *, dladm_arg_list_t **,
254 			    boolean_t);
255 extern void		dladm_free_attrs(dladm_arg_list_t *);
256 
257 extern dladm_status_t	dladm_start_usagelog(dladm_handle_t, dladm_logtype_t,
258 			    uint_t);
259 extern dladm_status_t	dladm_stop_usagelog(dladm_handle_t, dladm_logtype_t);
260 extern dladm_status_t	dladm_walk_usage_res(int (*)(dladm_usage_t *, void *),
261 			    int, char *, char *, char *, char *, void *);
262 extern dladm_status_t	dladm_walk_usage_time(int (*)(dladm_usage_t *, void *),
263 			    int, char *, char *, char *, void *);
264 extern dladm_status_t	dladm_usage_summary(int (*)(dladm_usage_t *, void *),
265 			    int, char *, void *);
266 extern dladm_status_t	dladm_usage_dates(int (*)(dladm_usage_t *, void *),
267 			    int, char *, char *, void *);
268 extern dladm_status_t	dladm_zone_boot(dladm_handle_t, zoneid_t);
269 extern dladm_status_t	dladm_zone_halt(dladm_handle_t, zoneid_t);
270 
271 extern dladm_status_t	dladm_strs2range(char **, uint_t, mac_propval_type_t,
272 			    mac_propval_range_t **);
273 extern dladm_status_t	dladm_range2list(mac_propval_range_t *, void*,
274 			    uint_t *);
275 extern int		dladm_range2strs(mac_propval_range_t *, char **);
276 extern dladm_status_t	dladm_list2range(void *, uint_t, mac_propval_type_t,
277 			    mac_propval_range_t **);
278 
279 #ifdef	__cplusplus
280 }
281 #endif
282 
283 #endif	/* _LIBDLADM_H */
284