xref: /illumos-gate/usr/src/lib/libipadm/common/libipadm_impl.h (revision a73be61a80f7331c35adfa540bcf8f1546ff1e33)
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 /*
23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright (c) 2013 by Delphix. All rights reserved.
25  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
26  * Copyright 2021 Tintri by DDN, Inc. All rights reserved.
27  */
28 
29 #ifndef _LIBIPADM_IMPL_H
30 #define	_LIBIPADM_IMPL_H
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/socket.h>
37 #include <sys/list.h>
38 #include <net/if.h>
39 #include <libipadm.h>
40 #include <libdladm.h>
41 #include <ipadm_ipmgmt.h>
42 #include <inet/tunables.h>
43 #include <netinet/in.h>
44 #include <pthread.h>
45 #include <libinetutil.h>
46 #include <libsocket_priv.h>
47 
48 #define	IPADM_STRSIZE		256
49 #define	IPADM_ONSTR		"on"
50 #define	IPADM_OFFSTR		"off"
51 #define	ARP_MOD_NAME		"arp"
52 #define	IPADM_LOGICAL_SEP	':'
53 #define	IPV6_MIN_MTU		1280	/* rfc2460 */
54 
55 /* mask for flags accepted by libipadm functions */
56 #define	IPADM_COMMON_OPT_MASK	(IPADM_OPT_ACTIVE | IPADM_OPT_PERSIST)
57 
58 typedef enum {
59     IPADM_ADD_IPMP,
60     IPADM_REMOVE_IPMP
61 } ipadm_ipmp_op_t;
62 
63 /* Opaque library handle */
64 struct ipadm_handle {
65 	int		iph_sock;	/* socket to interface */
66 	int		iph_sock6;	/* socket to interface */
67 	int		iph_door_fd;	/* door descriptor to ipmgmtd */
68 	int		iph_rtsock;	/* routing socket */
69 	dladm_handle_t	iph_dlh;	/* handle to libdladm library */
70 	uint32_t	iph_flags;	/* internal flags */
71 	pthread_mutex_t	iph_lock;	/* lock to set door_fd */
72 	zoneid_t	iph_zoneid;	/* zoneid where handle was opened */
73 };
74 
75 struct ipadm_addrobj_s {
76 	char			ipadm_ifname[LIFNAMSIZ];
77 	int32_t			ipadm_lifnum;
78 	char			ipadm_aobjname[IPADM_AOBJSIZ];
79 	ipadm_addr_type_t	ipadm_atype;
80 	uint32_t		ipadm_flags;
81 	sa_family_t		ipadm_af;
82 	union {
83 		struct {
84 			char			ipadm_ahname[MAXNAMELEN];
85 			struct sockaddr_storage	ipadm_addr;
86 			uint32_t		ipadm_prefixlen;
87 			char			ipadm_dhname[MAXNAMELEN];
88 			struct sockaddr_storage ipadm_dstaddr;
89 		} ipadm_static_addr_s;
90 		struct {
91 			struct sockaddr_in6	ipadm_intfid;
92 			uint32_t		ipadm_intfidlen;
93 			boolean_t		ipadm_stateless;
94 			boolean_t		ipadm_stateful;
95 		} ipadm_ipv6_intfid_s;
96 		struct {
97 			boolean_t		ipadm_primary;
98 			int32_t			ipadm_wait;
99 			char			ipadm_reqhost[MAXNAMELEN];
100 		} ipadm_dhcp_s;
101 	} ipadm_addr_u;
102 };
103 
104 #define	ipadm_static_addr	ipadm_addr_u.ipadm_static_addr_s.ipadm_addr
105 #define	ipadm_static_aname	ipadm_addr_u.ipadm_static_addr_s.ipadm_ahname
106 #define	ipadm_static_prefixlen	ipadm_addr_u.ipadm_static_addr_s.ipadm_prefixlen
107 #define	ipadm_static_dst_addr	ipadm_addr_u.ipadm_static_addr_s.ipadm_dstaddr
108 #define	ipadm_static_dname	ipadm_addr_u.ipadm_static_addr_s.ipadm_dhname
109 #define	ipadm_intfid		ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_intfid
110 #define	ipadm_intfidlen		ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_intfidlen
111 #define	ipadm_stateless		ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_stateless
112 #define	ipadm_stateful		ipadm_addr_u.ipadm_ipv6_intfid_s.ipadm_stateful
113 #define	ipadm_primary		ipadm_addr_u.ipadm_dhcp_s.ipadm_primary
114 #define	ipadm_wait		ipadm_addr_u.ipadm_dhcp_s.ipadm_wait
115 #define	ipadm_reqhost	ipadm_addr_u.ipadm_dhcp_s.ipadm_reqhost
116 
117 /*
118  * Data structures and callback functions related to property management
119  */
120 struct ipadm_prop_desc;
121 typedef struct ipadm_prop_desc ipadm_prop_desc_t;
122 
123 /* property set() callback */
124 typedef ipadm_status_t	ipadm_pd_setf_t(ipadm_handle_t, const void *,
125     ipadm_prop_desc_t *, const void *, uint_t, uint_t);
126 
127 /* property get() callback */
128 typedef ipadm_status_t	ipadm_pd_getf_t(ipadm_handle_t, const void *,
129     ipadm_prop_desc_t *, char *, uint_t *, uint_t, uint_t);
130 
131 struct ipadm_prop_desc {
132 	char		*ipd_name;	/* property name */
133 	char		*ipd_old_name;	/* for backward compatibility */
134 	uint_t		ipd_class;	/* prop. class - global/perif/both */
135 	uint_t		ipd_proto;	/* protocol to which property belongs */
136 	uint_t		ipd_flags;	/* see below */
137 	ipadm_pd_setf_t	*ipd_set;	/* set callback function */
138 	ipadm_pd_getf_t	*ipd_get_range;	/* get range callback function */
139 	ipadm_pd_getf_t	*ipd_get;	/* get value callback function */
140 };
141 
142 /* ipd_flags values */
143 #define	IPADMPROP_MULVAL	0x00000001	/* property multi-valued */
144 
145 extern ipadm_prop_desc_t	ipadm_addrprop_table[];
146 extern ipadm_pd_getf_t		i_ipadm_get_onoff;
147 
148 /* libipadm.c */
149 extern ipadm_status_t	i_ipadm_get_flags(ipadm_handle_t, const char *,
150 			    sa_family_t, uint64_t *);
151 extern ipadm_status_t	i_ipadm_set_flags(ipadm_handle_t, const char *,
152 			    sa_family_t, uint64_t, uint64_t);
153 extern ipadm_status_t	i_ipadm_init_ifs(ipadm_handle_t, const char *,
154 			    nvlist_t **);
155 extern ipadm_status_t	i_ipadm_init_ifobj(ipadm_handle_t, const char *,
156 			    nvlist_t *);
157 extern ipadm_status_t	i_ipadm_init_addrobj(ipadm_handle_t, nvlist_t *);
158 extern ipadm_status_t	i_ipadm_addr_persist(ipadm_handle_t,
159 			    const ipadm_addrobj_t, boolean_t, uint32_t,
160 			    const char *);
161 extern ipadm_status_t	i_ipadm_delete_addr(ipadm_handle_t, ipadm_addrobj_t);
162 extern int		i_ipadm_strioctl(int, int, char *, int);
163 extern boolean_t	i_ipadm_is_loopback(const char *);
164 extern boolean_t	i_ipadm_is_vni(const char *);
165 extern boolean_t	i_ipadm_is_6to4(ipadm_handle_t, char *);
166 extern boolean_t	i_ipadm_validate_ifname(ipadm_handle_t, const char *);
167 extern ipadm_status_t	ipadm_errno2status(int);
168 extern int		ipadm_door_call(ipadm_handle_t, void *, size_t, void **,
169 			    size_t, boolean_t);
170 extern boolean_t	ipadm_if_enabled(ipadm_handle_t, const char *,
171 			    sa_family_t);
172 extern ipadm_status_t i_ipadm_call_ipmgmtd(ipadm_handle_t, void *,
173 	    size_t, nvlist_t **);
174 
175 /* ipadm_ndpd.c */
176 extern	ipadm_status_t	i_ipadm_create_ipv6addrs(ipadm_handle_t,
177 			    ipadm_addrobj_t, uint32_t);
178 extern ipadm_status_t	i_ipadm_delete_ipv6addrs(ipadm_handle_t,
179 			    ipadm_addrobj_t);
180 extern ipadm_status_t	i_ipadm_disable_autoconf(const char *);
181 extern ipadm_status_t	i_ipadm_enable_autoconf(const char *);
182 
183 /* ipadm_persist.c */
184 extern ipadm_status_t	i_ipadm_add_ipaddr2nvl(nvlist_t *, ipadm_addrobj_t);
185 extern ipadm_status_t	i_ipadm_add_ip6addr2nvl(nvlist_t *, ipadm_addrobj_t);
186 extern ipadm_status_t	i_ipadm_add_intfid2nvl(nvlist_t *, ipadm_addrobj_t);
187 extern ipadm_status_t	i_ipadm_add_dhcp2nvl(nvlist_t *, boolean_t, int32_t);
188 
189 /* ipadm_prop.c */
190 extern ipadm_status_t	i_ipadm_persist_propval(ipadm_handle_t,
191 			    ipadm_prop_desc_t *, const char *, const void *,
192 			    uint_t);
193 extern ipadm_status_t	i_ipadm_get_persist_propval(ipadm_handle_t,
194 			    ipadm_prop_desc_t *, char *, uint_t *,
195 			    const void *);
196 
197 /* ipadm_addr.c */
198 extern ipadm_status_t	i_ipadm_active_addr_info(ipadm_handle_t, const char *,
199 			    ipadm_addr_info_t **, uint32_t, int64_t);
200 extern void		i_ipadm_init_addr(ipadm_addrobj_t, const char *,
201 			    const char *, ipadm_addr_type_t);
202 extern ipadm_status_t	i_ipadm_merge_addrprops_from_nvl(nvlist_t *, nvlist_t *,
203 			    const char *);
204 extern ipadm_status_t	i_ipadm_get_addrobj(ipadm_handle_t, ipadm_addrobj_t);
205 extern ipadm_status_t	i_ipadm_enable_static(ipadm_handle_t, const char *,
206 			    nvlist_t *, sa_family_t);
207 extern ipadm_status_t	i_ipadm_enable_dhcp(ipadm_handle_t, const char *,
208 			    nvlist_t *);
209 extern ipadm_status_t	i_ipadm_enable_addrconf(ipadm_handle_t, const char *,
210 			    nvlist_t *);
211 extern void		i_ipadm_addrobj2lifname(ipadm_addrobj_t, char *, int);
212 extern ipadm_status_t	i_ipadm_nvl2in6_addr(nvlist_t *, char *,
213 			    in6_addr_t *);
214 extern ipadm_status_t	i_ipadm_get_lif2addrobj(ipadm_handle_t,
215 			    ipadm_addrobj_t);
216 extern ipadm_status_t	i_ipadm_lookupadd_addrobj(ipadm_handle_t,
217 			    ipadm_addrobj_t);
218 extern ipadm_status_t	i_ipadm_setlifnum_addrobj(ipadm_handle_t,
219 			    ipadm_addrobj_t);
220 extern ipadm_status_t	i_ipadm_do_addif(ipadm_handle_t, ipadm_addrobj_t);
221 extern ipadm_status_t	i_ipadm_delete_addrobj(ipadm_handle_t,
222 			    const ipadm_addrobj_t, uint32_t);
223 extern boolean_t	i_ipadm_name2atype(const char *, sa_family_t *,
224 			    ipadm_addr_type_t *);
225 extern ipadm_status_t	i_ipadm_resolve_addr(const char *, sa_family_t,
226 			    struct sockaddr_storage *);
227 
228 /* ipadm_if.c */
229 extern ipadm_status_t	i_ipadm_create_if(ipadm_handle_t, char *,  sa_family_t,
230 			    uint32_t);
231 extern ipadm_status_t	i_ipadm_delete_if(ipadm_handle_t, const char *,
232 			    sa_family_t, uint32_t);
233 extern ipadm_status_t	i_ipadm_plumb_if(ipadm_handle_t, char *, sa_family_t,
234 			    uint32_t);
235 extern ipadm_status_t	i_ipadm_unplumb_if(ipadm_handle_t, const char *,
236 			    sa_family_t);
237 extern ipadm_status_t	i_ipadm_if_pexists(ipadm_handle_t, const char *,
238 			    sa_family_t, boolean_t *);
239 extern ipadm_status_t	i_ipadm_delete_ifobj(ipadm_handle_t, const char *,
240 			    sa_family_t, boolean_t);
241 extern int		i_ipadm_get_lnum(const char *);
242 
243 extern ipadm_status_t i_ipadm_set_groupname_active(ipadm_handle_t,
244 	    const char *, const char *);
245 extern ipadm_status_t i_ipadm_get_groupname_active(ipadm_handle_t,
246 	    const char *, char *, size_t);
247 extern boolean_t i_ipadm_is_under_ipmp(ipadm_handle_t, const char *);
248 extern boolean_t i_ipadm_is_ipmp(ipadm_handle_t, const char *);
249 #ifdef	__cplusplus
250 }
251 #endif
252 
253 #endif	/* _LIBIPADM_IMPL_H */
254