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