summaryrefslogtreecommitdiff
path: root/usr/src/lib/libdladm/common/libdladm.h
blob: 685356fa64d089633383c1654bc465cb5121a8fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
 * Copyright 2017, Joyent, Inc.
 */

/*
 * Copyright 2020 OmniOS Community Edition (OmniOSce) Association
 */

#ifndef _LIBDLADM_H
#define	_LIBDLADM_H

#include <sys/dls_mgmt.h>
#include <sys/dld.h>
#include <sys/dlpi.h>
#include <libnvpair.h>
#include <kstat.h>

/*
 * This file includes structures, macros and common routines shared by all
 * data-link administration, and routines which do not directly administrate
 * links. For example, dladm_status2str().
 */

#ifdef	__cplusplus
extern "C" {
#endif

#define	LINKID_STR_WIDTH	10
#define	DLADM_STRSIZE		2048

/*
 * option flags taken by the libdladm functions
 *
 *  - DLADM_OPT_ACTIVE:
 *    The function requests to bringup some configuration that only take
 *    effect on active system (not persistent).
 *
 *  - DLADM_OPT_PERSIST:
 *    The function requests to persist some configuration.
 *
 *  - DLADM_OPT_CREATE:
 *    Today, only used by dladm_set_secobj() - requests to create a secobj.
 *
 *  - DLADM_OPT_FORCE:
 *    The function requests to execute a specific operation forcefully.
 *
 *  - DLADM_OPT_PREFIX:
 *    The function requests to generate a link name using the specified prefix.
 *
 *  - DLADM_OPT_VLAN:
 *    Signifies VLAN creation code path
 *
 *  - DLADM_OPT_NOREFRESH:
 *    Do not refresh the daemon after setting parameter (used by STP mcheck).
 *
 *  - DLADM_OPT_BOOT:
 *    Bypass check functions during boot (used by pool property since pools
 *    can come up after link properties are set)
 *
 *  - DLADM_OPT_TRANSIENT:
 *    Indicates that the link assigned to a zone is transient and will be
 *    removed when the zone shuts down.
 */
#define	DLADM_OPT_ACTIVE	0x00000001
#define	DLADM_OPT_PERSIST	0x00000002
#define	DLADM_OPT_CREATE	0x00000004
#define	DLADM_OPT_FORCE		0x00000008
#define	DLADM_OPT_PREFIX	0x00000010
#define	DLADM_OPT_ANCHOR	0x00000020
#define	DLADM_OPT_VLAN		0x00000040
#define	DLADM_OPT_NOREFRESH	0x00000080
#define	DLADM_OPT_BOOT		0x00000100
#define	DLADM_OPT_TRANSIENT	0x00000200

#define	DLADM_WALK_TERMINATE	0
#define	DLADM_WALK_CONTINUE	-1

#define	DLADM_MAX_ARG_CNT	32
#define	DLADM_MAX_ARG_VALS	64

typedef enum {
	DLADM_STATUS_OK = 0,
	DLADM_STATUS_BADARG,
	DLADM_STATUS_FAILED,
	DLADM_STATUS_TOOSMALL,
	DLADM_STATUS_NOTSUP,
	DLADM_STATUS_NOTFOUND,
	DLADM_STATUS_BADVAL,
	DLADM_STATUS_NOMEM,
	DLADM_STATUS_EXIST,
	DLADM_STATUS_LINKINVAL,
	DLADM_STATUS_PROPRDONLY,
	DLADM_STATUS_BADVALCNT,
	DLADM_STATUS_DBNOTFOUND,
	DLADM_STATUS_DENIED,
	DLADM_STATUS_IOERR,
	DLADM_STATUS_TEMPONLY,
	DLADM_STATUS_TIMEDOUT,
	DLADM_STATUS_ISCONN,
	DLADM_STATUS_NOTCONN,
	DLADM_STATUS_REPOSITORYINVAL,
	DLADM_STATUS_MACADDRINVAL,
	DLADM_STATUS_KEYINVAL,
	DLADM_STATUS_INVALIDMACADDRLEN,
	DLADM_STATUS_INVALIDMACADDRTYPE,
	DLADM_STATUS_LINKBUSY,
	DLADM_STATUS_VIDINVAL,
	DLADM_STATUS_NONOTIF,
	DLADM_STATUS_TRYAGAIN,
	DLADM_STATUS_IPTUNTYPE,
	DLADM_STATUS_IPTUNTYPEREQD,
	DLADM_STATUS_BADIPTUNLADDR,
	DLADM_STATUS_BADIPTUNRADDR,
	DLADM_STATUS_ADDRINUSE,
	DLADM_STATUS_BADTIMEVAL,
	DLADM_STATUS_INVALIDMACADDR,
	DLADM_STATUS_INVALIDMACADDRNIC,
	DLADM_STATUS_INVALIDMACADDRINUSE,
	DLADM_STATUS_MACFACTORYSLOTINVALID,
	DLADM_STATUS_MACFACTORYSLOTUSED,
	DLADM_STATUS_MACFACTORYSLOTALLUSED,
	DLADM_STATUS_MACFACTORYNOTSUP,
	DLADM_STATUS_INVALIDMACPREFIX,
	DLADM_STATUS_INVALIDMACPREFIXLEN,
	DLADM_STATUS_BADCPUID,
	DLADM_STATUS_CPUERR,
	DLADM_STATUS_CPUNOTONLINE,
	DLADM_STATUS_BADRANGE,
	DLADM_STATUS_TOOMANYELEMENTS,
	DLADM_STATUS_DB_NOTFOUND,
	DLADM_STATUS_DB_PARSE_ERR,
	DLADM_STATUS_PROP_PARSE_ERR,
	DLADM_STATUS_ATTR_PARSE_ERR,
	DLADM_STATUS_FLOW_DB_ERR,
	DLADM_STATUS_FLOW_DB_OPEN_ERR,
	DLADM_STATUS_FLOW_DB_PARSE_ERR,
	DLADM_STATUS_FLOWPROP_DB_PARSE_ERR,
	DLADM_STATUS_FLOW_ADD_ERR,
	DLADM_STATUS_FLOW_WALK_ERR,
	DLADM_STATUS_FLOW_IDENTICAL,
	DLADM_STATUS_FLOW_INCOMPATIBLE,
	DLADM_STATUS_FLOW_EXISTS,
	DLADM_STATUS_PERSIST_FLOW_EXISTS,
	DLADM_STATUS_INVALID_IP,
	DLADM_STATUS_INVALID_PREFIXLEN,
	DLADM_STATUS_INVALID_PROTOCOL,
	DLADM_STATUS_INVALID_PORT,
	DLADM_STATUS_INVALID_DSF,
	DLADM_STATUS_INVALID_DSFMASK,
	DLADM_STATUS_INVALID_MACMARGIN,
	DLADM_STATUS_NOTDEFINED,
	DLADM_STATUS_BADPROP,
	DLADM_STATUS_MINMAXBW,
	DLADM_STATUS_NO_HWRINGS,
	DLADM_STATUS_PERMONLY,
	DLADM_STATUS_OPTMISSING,
	DLADM_STATUS_POOLCPU,
	DLADM_STATUS_INVALID_PORT_INSTANCE,
	DLADM_STATUS_PORT_IS_DOWN,
	DLADM_STATUS_PKEY_NOT_PRESENT,
	DLADM_STATUS_PARTITION_EXISTS,
	DLADM_STATUS_INVALID_PKEY,
	DLADM_STATUS_NO_IB_HW_RESOURCE,
	DLADM_STATUS_INVALID_PKEY_TBL_SIZE,
	DLADM_STATUS_PORT_NOPROTO,
	DLADM_STATUS_INVALID_MTU,
	DLADM_STATUS_BAD_ENCAP,
	DLADM_STATUS_PERSIST_ON_TEMP
} dladm_status_t;

typedef enum {
	DLADM_TYPE_STR,
	DLADM_TYPE_BOOLEAN,
	DLADM_TYPE_UINT64
} dladm_datatype_t;

typedef struct {
	boolean_t	ds_readonly;
	union {
		int	dsu_confid;
		nvlist_t *dsu_nvl;
	} ds_u;
} dladm_conf_t;

#define	ds_confid	ds_u.dsu_confid
#define	ds_nvl		ds_u.dsu_nvl

#define	DLADM_INVALID_CONF	0

/* opaque dladm handle to libdladm functions */
struct dladm_handle;
typedef struct dladm_handle *dladm_handle_t;

/* open/close handle */
extern dladm_status_t	dladm_open(dladm_handle_t *);
extern void		dladm_close(dladm_handle_t);

/*
 * retrieve the dld file descriptor from handle, only libdladm and
 * dlmgmtd are given access to the door file descriptor.
 */
extern int	dladm_dld_fd(dladm_handle_t);
/*
 * Retrieve kstat_ctl_t* from handle.The libkstat handle is opened
 * when the first caller needs it.This allows the library to share
 * the kstat handle.
 */
extern kstat_ctl_t	*dladm_dld_kcp(dladm_handle_t);

typedef struct dladm_arg_info {
	const char	*ai_name;
	char		*ai_val[DLADM_MAX_ARG_VALS];
	uint_t		ai_count;
} dladm_arg_info_t;

typedef struct dladm_arg_list {
	dladm_arg_info_t	al_info[DLADM_MAX_ARG_CNT];
	uint_t			al_count;
	char			*al_buf;
} dladm_arg_list_t;

typedef struct dladm_errlist {
	uint_t		el_count;
	uint_t		el_alloc;
	char		**el_errs;
} dladm_errlist_t;

typedef enum {
	DLADM_LOGTYPE_LINK = 1,
	DLADM_LOGTYPE_FLOW
} dladm_logtype_t;

typedef struct dladm_usage {
	char		du_name[MAXLINKNAMELEN];
	uint64_t	du_duration;
	uint64_t	du_stime;
	uint64_t	du_etime;
	uint64_t	du_ipackets;
	uint64_t	du_rbytes;
	uint64_t	du_opackets;
	uint64_t	du_obytes;
	uint64_t	du_bandwidth;
	boolean_t	du_last;
} dladm_usage_t;

extern const char	*dladm_status2str(dladm_status_t, char *);
extern dladm_status_t	dladm_set_rootdir(const char *);
extern const char	*dladm_class2str(datalink_class_t, char *);
extern const char	*dladm_media2str(uint32_t, char *);
extern uint32_t		dladm_str2media(const char *);
extern boolean_t	dladm_valid_linkname(const char *);
extern boolean_t	dladm_str2interval(char *, uint32_t *);
extern dladm_status_t	dladm_str2bw(char *, uint64_t *);
extern const char	*dladm_bw2str(int64_t, char *);
extern dladm_status_t	dladm_str2pri(char *, mac_priority_level_t *);
extern const char	*dladm_pri2str(mac_priority_level_t, char *);
extern dladm_status_t	dladm_str2protect(char *, uint32_t *);
extern const char	*dladm_protect2str(uint32_t, char *);
extern const char	*dladm_dynamic2str(uint32_t, char *, size_t);
extern dladm_status_t	dladm_str2ipv4addr(char *, void *);
extern const char	*dladm_ipv4addr2str(void *, char *);
extern dladm_status_t	dladm_str2ipv6addr(char *, void *);
extern const char	*dladm_ipv6addr2str(void *, char *);

extern dladm_status_t	dladm_parse_flow_props(char *, dladm_arg_list_t **,
			    boolean_t);
extern dladm_status_t	dladm_parse_link_props(char *, dladm_arg_list_t **,
			    boolean_t);
extern void		dladm_free_props(dladm_arg_list_t *);
extern dladm_status_t	dladm_parse_flow_attrs(char *, dladm_arg_list_t **,
			    boolean_t);
extern void		dladm_free_attrs(dladm_arg_list_t *);

extern dladm_status_t	dladm_start_usagelog(dladm_handle_t, dladm_logtype_t,
			    uint_t);
extern dladm_status_t	dladm_stop_usagelog(dladm_handle_t, dladm_logtype_t);
extern dladm_status_t	dladm_walk_usage_res(int (*)(dladm_usage_t *, void *),
			    int, char *, char *, char *, char *, void *);
extern dladm_status_t	dladm_walk_usage_time(int (*)(dladm_usage_t *, void *),
			    int, char *, char *, char *, void *);
extern dladm_status_t	dladm_usage_summary(int (*)(dladm_usage_t *, void *),
			    int, char *, void *);
extern dladm_status_t	dladm_usage_dates(int (*)(dladm_usage_t *, void *),
			    int, char *, char *, void *);
extern dladm_status_t	dladm_zone_boot(dladm_handle_t, zoneid_t);
extern dladm_status_t	dladm_zone_halt(dladm_handle_t, zoneid_t);

extern dladm_status_t	dladm_strs2range(char **, uint_t, mac_propval_type_t,
			    mac_propval_range_t **);
extern dladm_status_t	dladm_range2list(const mac_propval_range_t *, void *,
			    uint_t *);
extern int		dladm_range2strs(const mac_propval_range_t *, char **);
extern dladm_status_t	dladm_list2range(void *, uint_t, mac_propval_type_t,
			    mac_propval_range_t **);

extern void		dladm_errlist_init(dladm_errlist_t *);
extern void		dladm_errlist_reset(dladm_errlist_t *);

#ifdef	__cplusplus
}
#endif

#endif	/* _LIBDLADM_H */