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 */
24 #ifndef _LIBIPADM_H
25 #define _LIBIPADM_H
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #include <net/if.h>
34 #include <netdb.h>
35 #include <ifaddrs.h>
36 #include <libnvpair.h>
37 #include <netinet/tcp.h>
38 #include <sys/stropts.h>
39
40 #define IPADM_AOBJ_USTRSIZ 32
41 #define IPADM_AOBJSIZ (LIFNAMSIZ + IPADM_AOBJ_USTRSIZ)
42 #define MAXPROPVALLEN 512
43 #define LOOPBACK_IF "lo0"
44
45 /* special timeout values for dhcp operations */
46 #define IPADM_DHCP_WAIT_DEFAULT (-1)
47 #define IPADM_DHCP_WAIT_FOREVER (-2)
48
49 /*
50 * Specifies that the string passed to ipadm_str2nvlist() is a string of comma
51 * separated names and that each name does not have values associated with it.
84 IPADM_ADDR_NOTAVAIL, /* Can't assign requested address */
85 IPADM_ALL_ADDRS_NOT_ENABLED, /* All addresses could not be enabled */
86 IPADM_NDPD_NOT_RUNNING, /* in.ndpd not running */
87 IPADM_DHCP_START_ERROR, /* Cannot start dhcpagent */
88 IPADM_DHCP_IPC_ERROR, /* Cannot communicate with dhcpagent */
89 IPADM_DHCP_IPC_TIMEOUT, /* Communication with dhcpagent timed out */
90 IPADM_TEMPORARY_OBJ, /* Permanent operation on temporary object */
91 IPADM_IPC_ERROR, /* Cannot communicate with ipmgmtd */
92 IPADM_OP_DISABLE_OBJ, /* Operation on disable object */
93 IPADM_NOTSUP, /* Operation not supported */
94 IPADM_EBADE, /* Invalid data exchange with ipmgmtd */
95 IPADM_GZ_PERM /* Operation not permitted on from-gz intf */
96 } ipadm_status_t;
97
98 /*
99 * option flags taken by the libipadm functions
100 *
101 * - IPADM_OPT_PERSIST:
102 * For all the create/delete/up/down/set/get functions,
103 * requests to persist the configuration so that it can be
104 * re-enabled or reapplied on boot.
105 *
106 * - IPADM_OPT_ACTIVE:
107 * Requests to apply configuration without persisting it and
108 * used by show-* subcommands to retrieve current values.
109 *
110 * - IPADM_OPT_DEFAULT:
111 * retrieves the default value for a given property
112 *
113 * - IPADM_OPT_PERM
114 * retrieves the permission for a given property
115 *
116 * - IPADM_OPT_POSSIBLE
117 * retrieves the range of values for a given property
118 *
119 * - IPADM_OPT_APPEND
120 * for multi-valued properties, appends a new value.
121 *
122 * - IPADM_OPT_REMOVE
123 * for multi-valued properties, removes the specified value
124 *
125 * - IPADM_OPT_IPMP
126 * Used in ipadm_create_if() to plumb ipmp interfaces.
127 *
128 * - IPADM_OPT_GENPPA
129 * Used in ipadm_create_if() to generate a ppa for the given interface.
130 *
131 * - IPADM_OPT_ZEROADDR
132 * return :: or INADDR_ANY
133 *
134 * - IPADM_OPT_RELEASE
135 * Used to release the lease on a dhcp address object
136 *
137 * - IPADM_OPT_INFORM
138 * Used to perform DHCP_INFORM on a specified static address object
139 *
140 * - IPADM_OPT_UP
141 * Used to bring up a static address on creation
142 *
143 * - IPADM_OPT_V46
144 * Used to plumb both IPv4 and IPv6 interfaces by ipadm_create_addr()
145 */
146 #define IPADM_OPT_PERSIST 0x00000001
147 #define IPADM_OPT_ACTIVE 0x00000002
148 #define IPADM_OPT_DEFAULT 0x00000004
149 #define IPADM_OPT_PERM 0x00000008
150 #define IPADM_OPT_POSSIBLE 0x00000010
151 #define IPADM_OPT_APPEND 0x00000020
152 #define IPADM_OPT_REMOVE 0x00000040
153 #define IPADM_OPT_IPMP 0x00000080
154 #define IPADM_OPT_GENPPA 0x00000100
155 #define IPADM_OPT_ZEROADDR 0x00000200
156 #define IPADM_OPT_RELEASE 0x00000400
157 #define IPADM_OPT_INFORM 0x00000800
158 #define IPADM_OPT_UP 0x00001000
159 #define IPADM_OPT_V46 0x00002000
160
161 /* IPADM property class */
162 #define IPADMPROP_CLASS_MODULE 0x00000001 /* on 'protocol' only */
163 #define IPADMPROP_CLASS_IF 0x00000002 /* on 'IP interface' only */
164 #define IPADMPROP_CLASS_ADDR 0x00000004 /* on 'IP address' only */
165 /* protocol property that can be applied on interface too */
166 #define IPADMPROP_CLASS_MODIF (IPADMPROP_CLASS_MODULE | IPADMPROP_CLASS_IF)
167
168 /* opaque ipadm handle to libipadm functions */
169 struct ipadm_handle;
170 typedef struct ipadm_handle *ipadm_handle_t;
171
172 /* ipadm_handle flags */
173 #define IPH_VRRP 0x00000001 /* Caller is VRRP */
174 #define IPH_LEGACY 0x00000002 /* Caller is legacy app */
175 #define IPH_IPMGMTD 0x00000004 /* Caller is ipmgmtd itself */
176 /*
177 * Indicates that the operation being invoked is in 'init' context. This is
178 * a library private flag.
179 */
240 uint_t ia_pflags; /* persistent flags */
241 ipadm_addr_type_t ia_atype; /* see above */
242 ipadm_addr_state_t ia_state; /* see above */
243 } ipadm_addr_info_t;
244 #define IA_NEXT(ia) ((ipadm_addr_info_t *)(ia->ia_ifa.ifa_next))
245
246 /* ipadm_addr_info_t flags */
247 #define IA_UP 0x00000001
248 #define IA_UNNUMBERED 0x00000002
249 #define IA_PRIVATE 0x00000004
250 #define IA_TEMPORARY 0x00000008
251 #define IA_DEPRECATED 0x00000010
252
253 /* open/close libipadm handle */
254 extern ipadm_status_t ipadm_open(ipadm_handle_t *, uint32_t);
255 extern void ipadm_close(ipadm_handle_t);
256
257 /* Check authorization for network configuration */
258 extern boolean_t ipadm_check_auth(void);
259 /*
260 * Interface mangement functions
261 */
262 extern ipadm_status_t ipadm_create_if(ipadm_handle_t, char *, sa_family_t,
263 uint32_t);
264 extern ipadm_status_t ipadm_disable_if(ipadm_handle_t, const char *,
265 uint32_t);
266 extern ipadm_status_t ipadm_enable_if(ipadm_handle_t, const char *, uint32_t);
267 extern ipadm_status_t ipadm_if_info(ipadm_handle_t, const char *,
268 ipadm_if_info_t **, uint32_t, int64_t);
269 extern void ipadm_free_if_info(ipadm_if_info_t *);
270 extern ipadm_status_t ipadm_delete_if(ipadm_handle_t, const char *,
271 sa_family_t, uint32_t);
272 extern void ipadm_if_move(ipadm_handle_t, const char *);
273
274 /*
275 * Address management functions
276 */
277 extern ipadm_status_t ipadm_create_addr(ipadm_handle_t, ipadm_addrobj_t,
278 uint32_t);
279 extern ipadm_status_t ipadm_disable_addr(ipadm_handle_t, const char *,
280 uint32_t);
298 extern void ipadm_destroy_addrobj(ipadm_addrobj_t);
299 extern ipadm_status_t ipadm_get_aobjname(const ipadm_addrobj_t, char *,
300 size_t);
301
302 /* Functions to set fields in addrobj for static addresses */
303 extern ipadm_status_t ipadm_set_addr(ipadm_addrobj_t, const char *,
304 sa_family_t);
305 extern ipadm_status_t ipadm_set_dst_addr(ipadm_addrobj_t, const char *,
306 sa_family_t);
307 extern ipadm_status_t ipadm_get_addr(const ipadm_addrobj_t,
308 struct sockaddr_storage *);
309
310 /* Functions to set fields in addrobj for IPv6 addrconf */
311 extern ipadm_status_t ipadm_set_interface_id(ipadm_addrobj_t, const char *);
312 extern ipadm_status_t ipadm_set_stateless(ipadm_addrobj_t, boolean_t);
313 extern ipadm_status_t ipadm_set_stateful(ipadm_addrobj_t, boolean_t);
314
315 /* Functions to set fields in addrobj for DHCP */
316 extern ipadm_status_t ipadm_set_primary(ipadm_addrobj_t, boolean_t);
317 extern ipadm_status_t ipadm_set_wait_time(ipadm_addrobj_t, int32_t);
318
319 /*
320 * Property management functions
321 */
322 /* call back function for the property walker */
323 typedef boolean_t ipadm_prop_wfunc_t(void *, const char *, uint_t);
324 extern ipadm_status_t ipadm_walk_proptbl(uint_t, uint_t, ipadm_prop_wfunc_t *,
325 void *);
326 extern ipadm_status_t ipadm_walk_prop(const char *, uint_t, uint_t,
327 ipadm_prop_wfunc_t *, void *);
328
329 /* Interface property management - set, reset and get */
330 extern ipadm_status_t ipadm_set_ifprop(ipadm_handle_t, const char *,
331 const char *, const char *, uint_t, uint_t);
332 extern ipadm_status_t ipadm_get_ifprop(ipadm_handle_t, const char *,
333 const char *, char *, uint_t *, uint_t, uint_t);
334
335 /* Address property management - set, reset and get */
336 extern ipadm_status_t ipadm_set_addrprop(ipadm_handle_t, const char *,
337 const char *, const char *, uint_t);
340
341 /* Protoocl property management - set, reset and get */
342 extern ipadm_status_t ipadm_set_prop(ipadm_handle_t, const char *,
343 const char *, uint_t, uint_t);
344 extern ipadm_status_t ipadm_get_prop(ipadm_handle_t, const char *, char *,
345 uint_t *, uint_t, uint_t);
346
347 /*
348 * miscellaneous helper functions.
349 */
350 extern const char *ipadm_status2str(ipadm_status_t);
351 extern int ipadm_str2nvlist(const char *, nvlist_t **, uint_t);
352 extern size_t ipadm_nvlist2str(nvlist_t *, char *, size_t);
353 extern char *ipadm_proto2str(uint_t);
354 extern uint_t ipadm_str2proto(const char *);
355 extern ipadm_status_t ipadm_open_arp_on_udp(const char *, int *);
356 extern int ipadm_legacy2new_propname(const char *, char *,
357 uint_t, uint_t *);
358 extern int ipadm_new2legacy_propname(const char *, char *,
359 uint_t, uint_t);
360
361 #ifdef __cplusplus
362 }
363 #endif
364
365 #endif /* _LIBIPADM_H */
|
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.
86 IPADM_ADDR_NOTAVAIL, /* Can't assign requested address */
87 IPADM_ALL_ADDRS_NOT_ENABLED, /* All addresses could not be enabled */
88 IPADM_NDPD_NOT_RUNNING, /* in.ndpd not running */
89 IPADM_DHCP_START_ERROR, /* Cannot start dhcpagent */
90 IPADM_DHCP_IPC_ERROR, /* Cannot communicate with dhcpagent */
91 IPADM_DHCP_IPC_TIMEOUT, /* Communication with dhcpagent timed out */
92 IPADM_TEMPORARY_OBJ, /* Permanent operation on temporary object */
93 IPADM_IPC_ERROR, /* Cannot communicate with ipmgmtd */
94 IPADM_OP_DISABLE_OBJ, /* Operation on disable object */
95 IPADM_NOTSUP, /* Operation not supported */
96 IPADM_EBADE, /* Invalid data exchange with ipmgmtd */
97 IPADM_GZ_PERM /* Operation not permitted on from-gz intf */
98 } ipadm_status_t;
99
100 /*
101 * option flags taken by the libipadm functions
102 *
103 * - IPADM_OPT_PERSIST:
104 * For all the create/delete/up/down/set/get functions,
105 * requests to persist the configuration so that it can be
106 * re-enabled or re-applied on boot.
107 *
108 * - IPADM_OPT_ACTIVE:
109 * Requests to apply configuration without persisting it and
110 * used by show-* subcommands to retrieve current values.
111 *
112 * - IPADM_OPT_DEFAULT:
113 * retrieves the default value for a given property
114 *
115 * - IPADM_OPT_PERM
116 * retrieves the permission for a given property
117 *
118 * - IPADM_OPT_POSSIBLE
119 * retrieves the range of values for a given property
120 *
121 * - IPADM_OPT_APPEND
122 * for multi-valued properties, appends a new value.
123 *
124 * - IPADM_OPT_REMOVE
125 * for multi-valued properties, removes the specified value
126 *
127 * - IPADM_OPT_IPMP
128 * Used in ipadm_create_if() to plumb ipmp interfaces.
129 *
130 * - IPADM_OPT_GENPPA
131 * Used in ipadm_create_if() to generate a ppa for the given interface.
132 *
133 * - IPADM_OPT_ZEROADDR
134 * return :: or INADDR_ANY
135 *
136 * - IPADM_OPT_RELEASE
137 * Used to release the lease on a dhcp address object
138 *
139 * - IPADM_OPT_INFORM
140 * Used to perform DHCP_INFORM on a specified static address object
141 *
142 * - IPADM_OPT_UP
143 * Used to bring up a static address on creation
144 *
145 * - IPADM_OPT_V46
146 * Used to plumb both IPv4 and IPv6 interfaces by ipadm_create_addr()
147 *
148 * - IPADM_OPT_SET_PROPS
149 * Used to indicate the update changes the running configuration of
150 * "props" data on the object. The props are cached there on the parent,
151 * but the PROPS_ONLY change does not affect the ACTIVE/PERSIST state of
152 * the parent.
153 *
154 * - IPADM_OPT_PERSIST_PROPS
155 * Used when IPADM_OPT_SET_PROPS is active to indicate the update changes
156 * the persistent configuration of the "props" data on the object.
157 */
158 #define IPADM_OPT_PERSIST 0x00000001
159 #define IPADM_OPT_ACTIVE 0x00000002
160 #define IPADM_OPT_DEFAULT 0x00000004
161 #define IPADM_OPT_PERM 0x00000008
162 #define IPADM_OPT_POSSIBLE 0x00000010
163 #define IPADM_OPT_APPEND 0x00000020
164 #define IPADM_OPT_REMOVE 0x00000040
165 #define IPADM_OPT_IPMP 0x00000080
166 #define IPADM_OPT_GENPPA 0x00000100
167 #define IPADM_OPT_ZEROADDR 0x00000200
168 #define IPADM_OPT_RELEASE 0x00000400
169 #define IPADM_OPT_INFORM 0x00000800
170 #define IPADM_OPT_UP 0x00001000
171 #define IPADM_OPT_V46 0x00002000
172 #define IPADM_OPT_SET_PROPS 0x00004000
173 #define IPADM_OPT_PERSIST_PROPS 0x00008000
174
175 /* IPADM property class */
176 #define IPADMPROP_CLASS_MODULE 0x00000001 /* on 'protocol' only */
177 #define IPADMPROP_CLASS_IF 0x00000002 /* on 'IP interface' only */
178 #define IPADMPROP_CLASS_ADDR 0x00000004 /* on 'IP address' only */
179 /* protocol property that can be applied on interface too */
180 #define IPADMPROP_CLASS_MODIF (IPADMPROP_CLASS_MODULE | IPADMPROP_CLASS_IF)
181
182 /* opaque ipadm handle to libipadm functions */
183 struct ipadm_handle;
184 typedef struct ipadm_handle *ipadm_handle_t;
185
186 /* ipadm_handle flags */
187 #define IPH_VRRP 0x00000001 /* Caller is VRRP */
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 */
254 uint_t ia_pflags; /* persistent flags */
255 ipadm_addr_type_t ia_atype; /* see above */
256 ipadm_addr_state_t ia_state; /* see above */
257 } ipadm_addr_info_t;
258 #define IA_NEXT(ia) ((ipadm_addr_info_t *)(ia->ia_ifa.ifa_next))
259
260 /* ipadm_addr_info_t flags */
261 #define IA_UP 0x00000001
262 #define IA_UNNUMBERED 0x00000002
263 #define IA_PRIVATE 0x00000004
264 #define IA_TEMPORARY 0x00000008
265 #define IA_DEPRECATED 0x00000010
266
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);
312 extern void ipadm_destroy_addrobj(ipadm_addrobj_t);
313 extern ipadm_status_t ipadm_get_aobjname(const ipadm_addrobj_t, char *,
314 size_t);
315
316 /* Functions to set fields in addrobj for static addresses */
317 extern ipadm_status_t ipadm_set_addr(ipadm_addrobj_t, const char *,
318 sa_family_t);
319 extern ipadm_status_t ipadm_set_dst_addr(ipadm_addrobj_t, const char *,
320 sa_family_t);
321 extern ipadm_status_t ipadm_get_addr(const ipadm_addrobj_t,
322 struct sockaddr_storage *);
323
324 /* Functions to set fields in addrobj for IPv6 addrconf */
325 extern ipadm_status_t ipadm_set_interface_id(ipadm_addrobj_t, const char *);
326 extern ipadm_status_t ipadm_set_stateless(ipadm_addrobj_t, boolean_t);
327 extern ipadm_status_t ipadm_set_stateful(ipadm_addrobj_t, boolean_t);
328
329 /* Functions to set fields in addrobj for DHCP */
330 extern ipadm_status_t ipadm_set_primary(ipadm_addrobj_t, boolean_t);
331 extern ipadm_status_t ipadm_set_wait_time(ipadm_addrobj_t, int32_t);
332 extern ipadm_status_t ipadm_set_reqhost(ipadm_addrobj_t, const char *);
333
334 /*
335 * Property management functions
336 */
337 /* call back function for the property walker */
338 typedef boolean_t ipadm_prop_wfunc_t(void *, const char *, uint_t);
339 extern ipadm_status_t ipadm_walk_proptbl(uint_t, uint_t, ipadm_prop_wfunc_t *,
340 void *);
341 extern ipadm_status_t ipadm_walk_prop(const char *, uint_t, uint_t,
342 ipadm_prop_wfunc_t *, void *);
343
344 /* Interface property management - set, reset and get */
345 extern ipadm_status_t ipadm_set_ifprop(ipadm_handle_t, const char *,
346 const char *, const char *, uint_t, uint_t);
347 extern ipadm_status_t ipadm_get_ifprop(ipadm_handle_t, const char *,
348 const char *, char *, uint_t *, uint_t, uint_t);
349
350 /* Address property management - set, reset and get */
351 extern ipadm_status_t ipadm_set_addrprop(ipadm_handle_t, const char *,
352 const char *, const char *, uint_t);
355
356 /* Protoocl property management - set, reset and get */
357 extern ipadm_status_t ipadm_set_prop(ipadm_handle_t, const char *,
358 const char *, uint_t, uint_t);
359 extern ipadm_status_t ipadm_get_prop(ipadm_handle_t, const char *, char *,
360 uint_t *, uint_t, uint_t);
361
362 /*
363 * miscellaneous helper functions.
364 */
365 extern const char *ipadm_status2str(ipadm_status_t);
366 extern int ipadm_str2nvlist(const char *, nvlist_t **, uint_t);
367 extern size_t ipadm_nvlist2str(nvlist_t *, char *, size_t);
368 extern char *ipadm_proto2str(uint_t);
369 extern uint_t ipadm_str2proto(const char *);
370 extern ipadm_status_t ipadm_open_arp_on_udp(const char *, int *);
371 extern int ipadm_legacy2new_propname(const char *, char *,
372 uint_t, uint_t *);
373 extern int ipadm_new2legacy_propname(const char *, char *,
374 uint_t, uint_t);
375 extern boolean_t ipadm_is_valid_hostname(const char *hostname);
376 extern boolean_t ipadm_is_nil_hostname(const char *hostname);
377
378 #ifdef __cplusplus
379 }
380 #endif
381
382 #endif /* _LIBIPADM_H */
|