xref: /illumos-gate/usr/src/lib/libdladm/common/libdladm_impl.h (revision faa2068d5f60927511f588cf120b905d985371d0)
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) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
23  * Copyright 2015, Joyent, Inc.
24  */
25 
26 /*
27  * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
28  */
29 
30 #ifndef _LIBDLADM_IMPL_H
31 #define	_LIBDLADM_IMPL_H
32 
33 #include <sys/types.h>
34 #include <sys/mac.h>
35 #include <sys/mac_flow.h>
36 #include <libdladm.h>
37 #include <stdio.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 #define	MAXLINELEN		1024
44 #define	BUFLEN(lim, ptr)	(((lim) > (ptr)) ? ((lim) - (ptr)) : 0)
45 #define	V4_PART_OF_V6(v6)	((v6)._S6_un._S6_u32[3])
46 
47 /*
48  * The handle contains file descriptors to DLD_CONTROL_DEV and
49  * DLMGMT_DOOR.  Rather than opening the file descriptor each time
50  * it is required, the handle is opened by consumers of libdladm
51  * (e.g., dladm) and then passed to libdladm.
52  */
53 struct dladm_handle {
54 	int dld_fd;	/* file descriptor to DLD_CONTROL_DEV */
55 	int door_fd;	/* file descriptor to DLMGMT_DOOR */
56 	kstat_ctl_t *dld_kcp;	/* for kstat consumers */
57 };
58 
59 /* DLMGMT_DOOR can only be accessed by libdladm and dlmgmtd */
60 extern dladm_status_t	dladm_door_fd(dladm_handle_t, int *);
61 
62 extern dladm_status_t	dladm_errno2status(int);
63 extern dladm_status_t   i_dladm_rw_db(dladm_handle_t, const char *, mode_t,
64 			    dladm_status_t (*)(dladm_handle_t, void *, FILE *,
65 			    FILE *), void *, boolean_t);
66 extern dladm_status_t	dladm_get_state(dladm_handle_t, datalink_id_t,
67 			    link_state_t *);
68 extern void		dladm_find_setbits32(uint32_t, uint32_t *, uint32_t *);
69 extern dladm_status_t	dladm_parse_args(char *, dladm_arg_list_t **,
70 			    boolean_t);
71 extern void		dladm_free_args(dladm_arg_list_t *);
72 
73 /*
74  * Link attributes persisted by dlmgmtd.
75  */
76 
77 /*
78  * Set for overlays only
79  */
80 #define	FENCAP		"encap"		/* string */
81 #define	FSEARCH		"search"	/* string */
82 #define	FVNETID		"vnetid"	/* uint64_t */
83 
84 /*
85  * Set for VLANs only
86  */
87 #define	FVLANID		"vid"		/* uint64_t */
88 #define	FLINKOVER	"linkover"	/* uint64_t */
89 
90 /*
91  * Set for AGGRs only
92  */
93 #define	FKEY		"key"		/* uint64_t */
94 #define	FNPORTS		"nports"	/* uint64_t */
95 #define	FPORTS		"portnames"	/* string */
96 #define	FPOLICY		"policy"	/* uint64_t */
97 #define	FFIXMACADDR	"fix_macaddr"	/* boolean_t */
98 #define	FFORCE		"force"		/* boolean_t */
99 #define	FLACPMODE	"lacp_mode"	/* uint64_t */
100 #define	FLACPTIMER	"lacp_timer"	/* uint64_t */
101 
102 /*
103  * Set for VNICs only
104  */
105 #define	FMADDRTYPE	"maddrtype"	/* uint64_t */
106 #define	FMADDRLEN	"maddrlen"	/* uint64_t */
107 #define	FMADDRSLOT	"maddrslot"	/* uint64_t */
108 #define	FMADDRPREFIXLEN	"maddrpreflen"	/* uint64_t */
109 #define	FVRID		"vrid"		/* uint64_t */
110 #define	FVRAF		"vraf"		/* uint64_t */
111 
112 /*
113  * Set for simlinks only
114  */
115 #define	FSIMNETTYPE	"simnettype"	/* uint64_t */
116 #define	FSIMNETPEER	"simnetpeer"	/* uint64_t */
117 
118 /*
119  * Set for IB partitions only
120  */
121 #define	FPORTPKEY	"pkey"		/* uint64_t */
122 
123 /*
124  * Common fields
125  */
126 #define	FMACADDR	"macaddr"	/* string */
127 
128 /*
129  * List of all the above attributes.
130  */
131 #define	DLADM_ATTR_NAMES	FENCAP, FSEARCH, FVNETID, \
132 				FVLANID, FLINKOVER, \
133 				FKEY, FNPORTS, FPORTS, FPOLICY, \
134 				FFIXMACADDR, FFORCE, FLACPMODE, FLACPTIMER, \
135 				FMADDRTYPE, FMADDRLEN, FMADDRSLOT, \
136 				FMADDRPREFIXLEN, FVRID, FVRAF,	\
137 				FMACADDR, FSIMNETTYPE, FSIMNETPEER
138 
139 /*
140  * Data structures used for implementing temporary properties
141  */
142 
143 typedef struct val_desc {
144 	char		*vd_name;
145 	uintptr_t	vd_val;
146 } val_desc_t;
147 
148 #define	VALCNT(vals)	(sizeof ((vals)) / sizeof (val_desc_t))
149 
150 extern dladm_status_t	dladm_link_proplist_extract(dladm_handle_t,
151 			    dladm_arg_list_t *, mac_resource_props_t *,
152 			    uint_t);
153 
154 extern dladm_status_t	dladm_flow_proplist_extract(dladm_arg_list_t *,
155 			    mac_resource_props_t *);
156 
157 /*
158  * The prop extract() callback.
159  *
160  * rp_extract extracts the kernel structure from the val_desc_t created
161  * by the pd_check function.
162  */
163 typedef	dladm_status_t	rp_extractf_t(val_desc_t *, uint_t, void *);
164 extern rp_extractf_t	extract_maxbw, extract_priority,
165 			extract_cpus, extract_protection,
166 			extract_allowedips, extract_allowedcids,
167 			extract_rxrings, extract_txrings, extract_pool;
168 
169 typedef struct resource_prop_s {
170 	/*
171 	 * resource property name
172 	 */
173 	char		*rp_name;
174 
175 	/*
176 	 * callback to extract kernel structure
177 	 */
178 	rp_extractf_t	*rp_extract;
179 } resource_prop_t;
180 
181 /*
182  * Set for bridged links only
183  */
184 #define	FBRIDGE		"bridge"	/* string */
185 
186 /*
187  * For error lists
188  */
189 extern dladm_status_t	dladm_errlist_append(dladm_errlist_t *,
190     const char *, ...);
191 
192 #ifdef	__cplusplus
193 }
194 #endif
195 
196 #endif	/* _LIBDLADM_IMPL_H */
197