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