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) 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
24 */
25 #ifndef _LIBIPADM_H
26 #define _LIBIPADM_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/socket.h>
35 #include <net/if.h>
36 #include <netdb.h>
37 #include <ifaddrs.h>
38 #include <libnvpair.h>
39 #include <netinet/tcp.h>
40 #include <sys/stropts.h>
41
42 #define IPADM_AOBJ_USTRSIZ 32
43 #define IPADM_AOBJSIZ (LIFNAMSIZ + IPADM_AOBJ_USTRSIZ)
44 #define MAXPROPVALLEN 512
45 #define LOOPBACK_IF "lo0"
46
47 /* special timeout values for dhcp operations */
48 #define IPADM_DHCP_WAIT_DEFAULT (-1)
49 #define IPADM_DHCP_WAIT_FOREVER (-2)
50
51 /*
52 * Specifies that the string passed to ipadm_str2nvlist() is a string of comma
53 * separated names and that each name does not have values associated with it.
54 */
55 #define IPADM_NORVAL 0x00000001
56
57 /* error codes */
58 typedef enum {
59 IPADM_SUCCESS, /* No error occurred */
60 IPADM_FAILURE, /* Generic failure */
188 #define IPH_LEGACY 0x00000002 /* Caller is legacy app */
189 #define IPH_IPMGMTD 0x00000004 /* Caller is ipmgmtd itself */
190 /*
191 * Indicates that the operation being invoked is in 'init' context. This is
192 * a library private flag.
193 */
194 #define IPH_INIT 0x10000000
195
196 /* opaque address object structure */
197 typedef struct ipadm_addrobj_s *ipadm_addrobj_t;
198
199 /* ipadm_if_info_t states */
200 typedef enum {
201 IFIS_OK, /* Interface is usable */
202 IFIS_DOWN, /* Interface has no UP addresses */
203 IFIS_FAILED, /* Interface has failed. */
204 IFIS_OFFLINE, /* Interface has been offlined */
205 IFIS_DISABLED /* Interface has been disabled. */
206 } ipadm_if_state_t;
207
208 typedef struct ipadm_if_info_s {
209 struct ipadm_if_info_s *ifi_next;
210 char ifi_name[LIFNAMSIZ]; /* interface name */
211 ipadm_if_state_t ifi_state; /* see above */
212 uint_t ifi_cflags; /* current flags */
213 uint_t ifi_pflags; /* persistent flags */
214 } ipadm_if_info_t;
215
216 /* ipadm_if_info_t flags */
217 #define IFIF_BROADCAST 0x00000001
218 #define IFIF_MULTICAST 0x00000002
219 #define IFIF_POINTOPOINT 0x00000004
220 #define IFIF_VIRTUAL 0x00000008
221 #define IFIF_IPMP 0x00000010
222 #define IFIF_STANDBY 0x00000020
223 #define IFIF_INACTIVE 0x00000040
224 #define IFIF_VRRP 0x00000080
225 #define IFIF_NOACCEPT 0x00000100
226 #define IFIF_IPV4 0x00000200
227 #define IFIF_IPV6 0x00000400
228 #define IFIF_L3PROTECT 0x00000800
229
230 /* ipadm_addr_info_t state */
231 typedef enum {
232 IFA_DISABLED, /* Address not in active configuration. */
233 IFA_DUPLICATE, /* DAD failed. */
267 /* open/close libipadm handle */
268 extern ipadm_status_t ipadm_open(ipadm_handle_t *, uint32_t);
269 extern void ipadm_close(ipadm_handle_t);
270
271 /* Check authorization for network configuration */
272 extern boolean_t ipadm_check_auth(void);
273 /*
274 * Interface management functions
275 */
276 extern ipadm_status_t ipadm_create_if(ipadm_handle_t, char *, sa_family_t,
277 uint32_t);
278 extern ipadm_status_t ipadm_disable_if(ipadm_handle_t, const char *,
279 uint32_t);
280 extern ipadm_status_t ipadm_enable_if(ipadm_handle_t, const char *, uint32_t);
281 extern ipadm_status_t ipadm_if_info(ipadm_handle_t, const char *,
282 ipadm_if_info_t **, uint32_t, int64_t);
283 extern void ipadm_free_if_info(ipadm_if_info_t *);
284 extern ipadm_status_t ipadm_delete_if(ipadm_handle_t, const char *,
285 sa_family_t, uint32_t);
286 extern void ipadm_if_move(ipadm_handle_t, const char *);
287
288 /*
289 * Address management functions
290 */
291 extern ipadm_status_t ipadm_create_addr(ipadm_handle_t, ipadm_addrobj_t,
292 uint32_t);
293 extern ipadm_status_t ipadm_disable_addr(ipadm_handle_t, const char *,
294 uint32_t);
295 extern ipadm_status_t ipadm_enable_addr(ipadm_handle_t, const char *,
296 uint32_t);
297 extern ipadm_status_t ipadm_addr_info(ipadm_handle_t, const char *,
298 ipadm_addr_info_t **, uint32_t, int64_t);
299 extern void ipadm_free_addr_info(ipadm_addr_info_t *);
300 extern ipadm_status_t ipadm_up_addr(ipadm_handle_t, const char *,
301 uint32_t);
302 extern ipadm_status_t ipadm_down_addr(ipadm_handle_t, const char *,
303 uint32_t);
304 extern ipadm_status_t ipadm_refresh_addr(ipadm_handle_t, const char *,
305 uint32_t);
306 extern ipadm_status_t ipadm_delete_addr(ipadm_handle_t, const char *,
|
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) 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
24 * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
25 */
26 #ifndef _LIBIPADM_H
27 #define _LIBIPADM_H
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/socket.h>
36 #include <net/if.h>
37 #include <netdb.h>
38 #include <ifaddrs.h>
39 #include <libnvpair.h>
40 #include <netinet/tcp.h>
41 #include <sys/stropts.h>
42 #include <sys/list.h>
43 #include <stddef.h>
44
45 #define IPADM_AOBJ_USTRSIZ 32
46 #define IPADM_AOBJSIZ (LIFNAMSIZ + IPADM_AOBJ_USTRSIZ)
47 #define MAXPROPVALLEN 512
48 #define LOOPBACK_IF "lo0"
49
50 /* special timeout values for dhcp operations */
51 #define IPADM_DHCP_WAIT_DEFAULT (-1)
52 #define IPADM_DHCP_WAIT_FOREVER (-2)
53
54 /*
55 * Specifies that the string passed to ipadm_str2nvlist() is a string of comma
56 * separated names and that each name does not have values associated with it.
57 */
58 #define IPADM_NORVAL 0x00000001
59
60 /* error codes */
61 typedef enum {
62 IPADM_SUCCESS, /* No error occurred */
63 IPADM_FAILURE, /* Generic failure */
191 #define IPH_LEGACY 0x00000002 /* Caller is legacy app */
192 #define IPH_IPMGMTD 0x00000004 /* Caller is ipmgmtd itself */
193 /*
194 * Indicates that the operation being invoked is in 'init' context. This is
195 * a library private flag.
196 */
197 #define IPH_INIT 0x10000000
198
199 /* opaque address object structure */
200 typedef struct ipadm_addrobj_s *ipadm_addrobj_t;
201
202 /* ipadm_if_info_t states */
203 typedef enum {
204 IFIS_OK, /* Interface is usable */
205 IFIS_DOWN, /* Interface has no UP addresses */
206 IFIS_FAILED, /* Interface has failed. */
207 IFIS_OFFLINE, /* Interface has been offlined */
208 IFIS_DISABLED /* Interface has been disabled. */
209 } ipadm_if_state_t;
210
211 typedef list_t ipadm_ipmp_members_t;
212
213 typedef struct {
214 list_node_t node;
215 char if_name[LIFNAMSIZ];
216 } ipadm_ipmp_member_t;
217
218 typedef enum {
219 IPADM_IF_CLASS_REGULAR,
220 IPADM_IF_CLASS_IPMP,
221 IPADM_IF_CLASS_VIRTUAL,
222 IPADM_IF_CLASS_UNKNOWN
223 } ipadm_if_class_t;
224
225 typedef struct ipadm_if_info_s {
226 struct ipadm_if_info_s *ifi_next;
227 char ifi_name[LIFNAMSIZ]; /* interface name */
228 ipadm_if_class_t ifi_class; /* interface class */
229 ipadm_if_state_t ifi_state; /* see above */
230 uint_t ifi_cflags; /* current flags */
231 uint_t ifi_pflags; /* persistent flags */
232 ipadm_ipmp_members_t ifi_ipmp_cmembers; /* current IPMP members */
233 ipadm_ipmp_members_t ifi_ipmp_pmembers; /* persistent IPMP members */
234 } ipadm_if_info_t;
235
236 /* ipadm_if_info_t flags */
237 #define IFIF_BROADCAST 0x00000001
238 #define IFIF_MULTICAST 0x00000002
239 #define IFIF_POINTOPOINT 0x00000004
240 #define IFIF_VIRTUAL 0x00000008
241 #define IFIF_IPMP 0x00000010
242 #define IFIF_STANDBY 0x00000020
243 #define IFIF_INACTIVE 0x00000040
244 #define IFIF_VRRP 0x00000080
245 #define IFIF_NOACCEPT 0x00000100
246 #define IFIF_IPV4 0x00000200
247 #define IFIF_IPV6 0x00000400
248 #define IFIF_L3PROTECT 0x00000800
249
250 /* ipadm_addr_info_t state */
251 typedef enum {
252 IFA_DISABLED, /* Address not in active configuration. */
253 IFA_DUPLICATE, /* DAD failed. */
287 /* open/close libipadm handle */
288 extern ipadm_status_t ipadm_open(ipadm_handle_t *, uint32_t);
289 extern void ipadm_close(ipadm_handle_t);
290
291 /* Check authorization for network configuration */
292 extern boolean_t ipadm_check_auth(void);
293 /*
294 * Interface management functions
295 */
296 extern ipadm_status_t ipadm_create_if(ipadm_handle_t, char *, sa_family_t,
297 uint32_t);
298 extern ipadm_status_t ipadm_disable_if(ipadm_handle_t, const char *,
299 uint32_t);
300 extern ipadm_status_t ipadm_enable_if(ipadm_handle_t, const char *, uint32_t);
301 extern ipadm_status_t ipadm_if_info(ipadm_handle_t, const char *,
302 ipadm_if_info_t **, uint32_t, int64_t);
303 extern void ipadm_free_if_info(ipadm_if_info_t *);
304 extern ipadm_status_t ipadm_delete_if(ipadm_handle_t, const char *,
305 sa_family_t, uint32_t);
306 extern void ipadm_if_move(ipadm_handle_t, const char *);
307 extern ipadm_status_t ipadm_add_ipmp_member(ipadm_handle_t, const char *,
308 const char *, uint32_t);
309 extern ipadm_status_t ipadm_remove_ipmp_member(ipadm_handle_t, const char *,
310 const char *, uint32_t);
311
312 /*
313 * Address management functions
314 */
315 extern ipadm_status_t ipadm_create_addr(ipadm_handle_t, ipadm_addrobj_t,
316 uint32_t);
317 extern ipadm_status_t ipadm_disable_addr(ipadm_handle_t, const char *,
318 uint32_t);
319 extern ipadm_status_t ipadm_enable_addr(ipadm_handle_t, const char *,
320 uint32_t);
321 extern ipadm_status_t ipadm_addr_info(ipadm_handle_t, const char *,
322 ipadm_addr_info_t **, uint32_t, int64_t);
323 extern void ipadm_free_addr_info(ipadm_addr_info_t *);
324 extern ipadm_status_t ipadm_up_addr(ipadm_handle_t, const char *,
325 uint32_t);
326 extern ipadm_status_t ipadm_down_addr(ipadm_handle_t, const char *,
327 uint32_t);
328 extern ipadm_status_t ipadm_refresh_addr(ipadm_handle_t, const char *,
329 uint32_t);
330 extern ipadm_status_t ipadm_delete_addr(ipadm_handle_t, const char *,
|