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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
22  * Use is subject to license terms.
23  *
24  * Copyright 2021 Tintri by DDN, Inc. All rights reserved.
25  */
26 
27 #ifndef _IPMP_QUERY_H
28 #define	_IPMP_QUERY_H
29 
30 #include <sys/types.h>
31 #include <sys/socket.h>			/* needed by <net/if.h> */
32 #include <net/if.h>			/* for LIF*NAMSIZ */
33 #include <ipmp.h>
34 
35 /*
36  * IPMP query interfaces.
37  *
38  * These interfaces may only be used within ON or after signing a contract
39  * with ON.  For documentation, refer to PSARC/2002/615 and PSARC/2007/272.
40  */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47  * Assorted enumerations used in the data types described below.
48  */
49 typedef enum ipmp_if_probestate {
50 	IPMP_PROBE_OK,		/* probes detect no problems */
51 	IPMP_PROBE_FAILED,	/* probes detect failure */
52 	IPMP_PROBE_UNKNOWN,	/* probe detection unavailable */
53 	IPMP_PROBE_DISABLED	/* probe detection disabled */
54 } ipmp_if_probestate_t;
55 
56 typedef enum ipmp_if_linkstate {
57 	IPMP_LINK_UP,		/* link detects up */
58 	IPMP_LINK_DOWN,		/* link detects down */
59 	IPMP_LINK_UNKNOWN	/* link detection unavailable */
60 } ipmp_if_linkstate_t;
61 
62 typedef enum ipmp_if_flags {
63 	IPMP_IFFLAG_INACTIVE	= 0x1,
64 	IPMP_IFFLAG_HWADDRDUP	= 0x2,
65 	IPMP_IFFLAG_ACTIVE	= 0x4,
66 	IPMP_IFFLAG_DOWN	= 0x8
67 } ipmp_if_flags_t;
68 
69 typedef enum ipmp_addr_state {
70 	IPMP_ADDR_UP,		/* address is up */
71 	IPMP_ADDR_DOWN		/* address is down */
72 } ipmp_addr_state_t;
73 
74 typedef enum ipmp_if_targmode {
75 	IPMP_TARG_DISABLED,	/* use of targets is disabled */
76 	IPMP_TARG_ROUTES,	/* route-learned targets */
77 	IPMP_TARG_MULTICAST	/* multicast-learned targets */
78 } ipmp_if_targmode_t;
79 
80 #define	IPMP_LIST_SIZE(listtype, elsize, nel) \
81 	((sizeof (ipmp_ ## listtype ## _t) - (elsize)) + ((nel) * (elsize)))
82 
83 /*
84  * Data type describing a list of IPMP groups.
85  */
86 typedef struct ipmp_grouplist {
87 	uint64_t	gl_sig;
88 	unsigned int	gl_ngroup;
89 	uint32_t	gl_pad;
90 	char		gl_groups[1][LIFGRNAMSIZ];
91 } ipmp_grouplist_t;
92 
93 #define	IPMP_GROUPLIST_SIZE(ngr)	\
94 	IPMP_LIST_SIZE(grouplist, LIFGRNAMSIZ, ngr)
95 
96 /*
97  * Data type describing a list of interfaces.
98  */
99 typedef struct ipmp_iflist {
100 	unsigned int	il_nif;
101 	char		il_ifs[1][LIFNAMSIZ];
102 } ipmp_iflist_t;
103 
104 #define	IPMP_IFLIST_SIZE(nif)		\
105 	IPMP_LIST_SIZE(iflist, LIFNAMSIZ, nif)
106 
107 /*
108  * Data type describing a list of addresses.
109  */
110 typedef struct ipmp_addrlist {
111 	unsigned int		al_naddr;
112 	uint32_t		al_pad;
113 	struct sockaddr_storage al_addrs[1];
114 } ipmp_addrlist_t;
115 
116 #define	IPMP_ADDRLIST_SIZE(naddr)	\
117 	IPMP_LIST_SIZE(addrlist, sizeof (struct sockaddr_storage), naddr)
118 
119 /*
120  * Data type describing the state of an IPMP group, and a subset data type
121  * used for communication between libipmp and in.mpathd.
122  */
123 typedef struct ipmp_groupinfo {
124 	char			gr_name[LIFGRNAMSIZ];
125 	uint64_t		gr_sig;
126 	ipmp_group_state_t	gr_state;
127 	ipmp_iflist_t		*gr_iflistp;
128 	ipmp_addrlist_t		*gr_adlistp;
129 	char			gr_ifname[LIFNAMSIZ];
130 	char			gr_m4ifname[LIFNAMSIZ];
131 	char			gr_m6ifname[LIFNAMSIZ];
132 	char			gr_bcifname[LIFNAMSIZ];
133 	unsigned int		gr_fdt;
134 } ipmp_groupinfo_t;
135 
136 typedef struct ipmp_groupinfo_xfer {
137 	char			grx_name[LIFGRNAMSIZ];
138 	uint64_t		grx_sig;
139 	ipmp_group_state_t	grx_state;
140 	char			grx_ifname[LIFNAMSIZ];
141 	char			grx_m4ifname[LIFNAMSIZ];
142 	char			grx_m6ifname[LIFNAMSIZ];
143 	char			grx_bcifname[LIFNAMSIZ];
144 	unsigned int		grx_fdt;
145 } ipmp_groupinfo_xfer_t;
146 
147 /*
148  * Data type describing IPMP target information for a particular interface,
149  * and a subset data type used for communication between libipmp and in.mpathd.
150  */
151 typedef struct ipmp_targinfo {
152 	char			it_name[LIFNAMSIZ];
153 	struct sockaddr_storage	it_testaddr;
154 	ipmp_if_targmode_t	it_targmode;
155 	ipmp_addrlist_t		*it_targlistp;
156 } ipmp_targinfo_t;
157 
158 typedef struct ipmp_targinfo_xfer {
159 	char			itx_name[LIFNAMSIZ];
160 	struct sockaddr_storage	itx_testaddr;
161 	ipmp_if_targmode_t	itx_targmode;
162 	uint32_t		itx_pad;
163 } ipmp_targinfo_xfer_t;
164 
165 
166 /*
167  * Data type describing the IPMP-related state of an interface, and a subset
168  * data type used for communication between libipmp and in.mpathd.
169  */
170 typedef struct ipmp_ifinfo {
171 	char			if_name[LIFNAMSIZ];
172 	char			if_group[LIFGRNAMSIZ];
173 	ipmp_if_state_t		if_state;
174 	ipmp_if_type_t		if_type;
175 	ipmp_if_linkstate_t	if_linkstate;
176 	ipmp_if_probestate_t	if_probestate;
177 	ipmp_if_flags_t		if_flags;
178 	ipmp_targinfo_t		if_targinfo4;
179 	ipmp_targinfo_t		if_targinfo6;
180 } ipmp_ifinfo_t;
181 
182 typedef struct ipmp_ifinfo_xfer {
183 	char			ifx_name[LIFNAMSIZ];
184 	char			ifx_group[LIFGRNAMSIZ];
185 	ipmp_if_state_t		ifx_state;
186 	ipmp_if_type_t		ifx_type;
187 	ipmp_if_linkstate_t	ifx_linkstate;
188 	ipmp_if_probestate_t	ifx_probestate;
189 	ipmp_if_flags_t		ifx_flags;
190 	uint32_t		ifx_pad;
191 	ipmp_targinfo_xfer_t	ifx_targinfo4;
192 	ipmp_targinfo_xfer_t	ifx_targinfo6;
193 } ipmp_ifinfo_xfer_t;
194 
195 
196 /*
197  * Data type describing an IPMP data address.
198  */
199 typedef struct ipmp_addrinfo {
200 	struct sockaddr_storage	ad_addr;
201 	ipmp_addr_state_t	ad_state;
202 	char			ad_group[LIFGRNAMSIZ];
203 	char			ad_binding[LIFNAMSIZ];
204 	uint32_t		ad_pad;
205 } ipmp_addrinfo_t;
206 
207 typedef enum {
208 	IPMP_QCONTEXT_LIVE,
209 	IPMP_QCONTEXT_SNAP
210 } ipmp_qcontext_t;
211 
212 extern int  ipmp_setqcontext(ipmp_handle_t, ipmp_qcontext_t);
213 extern int  ipmp_getgrouplist(ipmp_handle_t, ipmp_grouplist_t **);
214 extern void ipmp_freegrouplist(ipmp_grouplist_t *);
215 extern int  ipmp_getgroupinfo(ipmp_handle_t, const char *, ipmp_groupinfo_t **);
216 extern void ipmp_freegroupinfo(ipmp_groupinfo_t *);
217 extern int  ipmp_getifinfo(ipmp_handle_t, const char *, ipmp_ifinfo_t **);
218 extern void ipmp_freeifinfo(ipmp_ifinfo_t *);
219 extern int  ipmp_getaddrinfo(ipmp_handle_t, const char *,
220     struct sockaddr_storage *, ipmp_addrinfo_t **);
221 extern void ipmp_freeaddrinfo(ipmp_addrinfo_t *);
222 
223 #ifdef __cplusplus
224 }
225 #endif
226 
227 #endif /* _IPMP_QUERY_H */
228