Mercurial > illumos > illumos-gate
comparison usr/src/lib/libipadm/common/libipadm.h @ 12016:0248e987199b
PSARC 2009/306 Brussels II - ipadm and libipadm
PSARC 2010/080 Brussels II addendum
6827318 Brussels Phase II aka ipadm(1m)
6731945 need BSD getifaddrs() API
6909065 explicitly disallow non-contiguous netmasks in the next minor release
6853922 ifconfig dumps core when ether address is non-hexadecimal.
6815806 ipReasmTimeout value should be variable
6567083 nd_getset has some dead and confusing code.
6884466 remove unused tcp/sctp ndd tunables
6928813 Comments at odds with default value of tcp_time_wait_interval
6236982 ifconfig usesrc lets adapter use itself as source address
6936855 modifying the ip6_strict_src_multihoming to non-zero value will unbind V4 IREs
author | Girish Moodalbail <Girish.Moodalbail@Sun.COM> |
---|---|
date | Fri, 26 Mar 2010 17:53:11 -0400 |
parents | |
children | 162e93ccf12f |
comparison
equal
deleted
inserted
replaced
12015:63716a810520 | 12016:0248e987199b |
---|---|
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 2010 Sun Microsystems, Inc. All rights reserved. | |
23 * Use is subject to license terms. | |
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/socket.h> | |
34 #include <net/if.h> | |
35 #include <netdb.h> | |
36 #include <ifaddrs.h> | |
37 #include <libnvpair.h> | |
38 #include <netinet/tcp.h> | |
39 #include <sys/stropts.h> | |
40 | |
41 #define IPADM_AOBJ_USTRSIZ 32 | |
42 #define IPADM_AOBJSIZ (LIFNAMSIZ + IPADM_AOBJ_USTRSIZ) | |
43 #define MAXPROPVALLEN 512 | |
44 #define LOOPBACK_IF "lo0" | |
45 | |
46 /* special timeout values for dhcp operations */ | |
47 #define IPADM_DHCP_WAIT_DEFAULT (-1) | |
48 #define IPADM_DHCP_WAIT_FOREVER (-2) | |
49 | |
50 /* | |
51 * Specifies that the string passed to ipadm_str2nvlist() is a string of comma | |
52 * separated names and that each name does not have values associated with it. | |
53 */ | |
54 #define IPADM_NORVAL 0x00000001 | |
55 | |
56 /* error codes */ | |
57 typedef enum { | |
58 IPADM_SUCCESS, /* No error occurred */ | |
59 IPADM_FAILURE, /* Generic failure */ | |
60 IPADM_EAUTH, /* Insufficient user authorizations */ | |
61 IPADM_EPERM, /* Permission denied */ | |
62 IPADM_NO_BUFS, /* No Buffer space available */ | |
63 IPADM_NO_MEMORY, /* Insufficient memory */ | |
64 IPADM_BAD_ADDR, /* Invalid address */ | |
65 IPADM_BAD_PROTOCOL, /* Wrong protocol family for operation */ | |
66 IPADM_DAD_FOUND, /* Duplicate address detected */ | |
67 IPADM_EXISTS, /* Already exists */ | |
68 IPADM_IF_EXISTS, /* Interface already exists */ | |
69 IPADM_ADDROBJ_EXISTS, /* Address object already exists */ | |
70 IPADM_ADDRCONF_EXISTS, /* Addrconf already in progress */ | |
71 IPADM_ENXIO, /* Interface does not exist */ | |
72 IPADM_GRP_NOTEMPTY, /* IPMP Group non-empty on unplumb */ | |
73 IPADM_INVALID_ARG, /* Invalid argument */ | |
74 IPADM_INVALID_NAME, /* Invalid name */ | |
75 IPADM_DLPI_FAILURE, /* Could not open DLPI link */ | |
76 IPADM_DLADM_FAILURE, /* DLADM error encountered */ | |
77 IPADM_PROP_UNKNOWN, /* Unknown property */ | |
78 IPADM_ERANGE, /* Value is outside the allowed range */ | |
79 IPADM_ESRCH, /* Value does not exist */ | |
80 IPADM_EOVERFLOW, /* Number of values exceed the allowed limit */ | |
81 IPADM_NOTFOUND, /* Object not found */ | |
82 IPADM_IF_INUSE, /* Interface already in use */ | |
83 IPADM_ADDR_INUSE, /* Address alrelady in use */ | |
84 IPADM_BAD_HOSTNAME, /* hostname maps to multiple IP addresses */ | |
85 IPADM_ADDR_NOTAVAIL, /* Can't assign requested address */ | |
86 IPADM_ALL_ADDRS_NOT_ENABLED, /* All addresses could not be enabled */ | |
87 IPADM_NDPD_NOT_RUNNING, /* in.ndpd not running */ | |
88 IPADM_DHCP_START_ERROR, /* Cannot start dhcpagent */ | |
89 IPADM_DHCP_IPC_ERROR, /* Cannot communicate with dhcpagent */ | |
90 IPADM_DHCP_IPC_TIMEOUT, /* Communication with dhcpagent timed out */ | |
91 IPADM_TEMPORARY_OBJ, /* Permanent operation on temporary object */ | |
92 IPADM_IPC_ERROR, /* Cannot communicate with ipmgmtd */ | |
93 IPADM_OP_DISABLE_OBJ, /* Operation on disable object */ | |
94 IPADM_NOTSUP, /* Operation not supported */ | |
95 IPADM_EBADE /* Invalid data exchange with ipmgmtd */ | |
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 #define IPADM_OPT_PERSIST 0x00000001 | |
144 #define IPADM_OPT_ACTIVE 0x00000002 | |
145 #define IPADM_OPT_DEFAULT 0x00000004 | |
146 #define IPADM_OPT_PERM 0x00000008 | |
147 #define IPADM_OPT_POSSIBLE 0x00000010 | |
148 #define IPADM_OPT_APPEND 0x00000020 | |
149 #define IPADM_OPT_REMOVE 0x00000040 | |
150 #define IPADM_OPT_IPMP 0x00000080 | |
151 #define IPADM_OPT_GENPPA 0x00000100 | |
152 #define IPADM_OPT_ZEROADDR 0x00000200 | |
153 #define IPADM_OPT_RELEASE 0x00000400 | |
154 #define IPADM_OPT_INFORM 0x00000800 | |
155 #define IPADM_OPT_UP 0x00001000 | |
156 | |
157 /* IPADM property class */ | |
158 #define IPADMPROP_CLASS_MODULE 0x00000001 /* on 'protocol' only */ | |
159 #define IPADMPROP_CLASS_IF 0x00000002 /* on 'IP interface' only */ | |
160 #define IPADMPROP_CLASS_ADDR 0x00000004 /* on 'IP address' only */ | |
161 /* protocol property that can be applied on interface too */ | |
162 #define IPADMPROP_CLASS_MODIF (IPADMPROP_CLASS_MODULE | IPADMPROP_CLASS_IF) | |
163 | |
164 /* opaque ipadm handle to libipadm functions */ | |
165 struct ipadm_handle; | |
166 typedef struct ipadm_handle *ipadm_handle_t; | |
167 | |
168 /* ipadm_handle flags */ | |
169 #define IPH_VRRP 0x00000001 /* Caller is VRRP */ | |
170 #define IPH_LEGACY 0x00000002 /* Caller is legacy app */ | |
171 | |
172 /* opaque address object structure */ | |
173 typedef struct ipadm_addrobj_s *ipadm_addrobj_t; | |
174 | |
175 /* ipadm_if_info_t states */ | |
176 typedef enum { | |
177 IFIS_OK, /* Interface is usable */ | |
178 IFIS_DOWN, /* Interface has no UP addresses */ | |
179 IFIS_FAILED, /* Interface has failed. */ | |
180 IFIS_OFFLINE, /* Interface has been offlined */ | |
181 IFIS_DISABLED /* Interface has been disabled. */ | |
182 } ipadm_if_state_t; | |
183 | |
184 typedef struct ipadm_if_info_s { | |
185 struct ipadm_if_info_s *ifi_next; | |
186 char ifi_name[LIFNAMSIZ]; /* interface name */ | |
187 ipadm_if_state_t ifi_state; /* see above */ | |
188 uint_t ifi_cflags; /* current flags */ | |
189 uint_t ifi_pflags; /* persistent flags */ | |
190 } ipadm_if_info_t; | |
191 | |
192 /* ipadm_if_info_t flags */ | |
193 #define IFIF_BROADCAST 0x00000001 | |
194 #define IFIF_MULTICAST 0x00000002 | |
195 #define IFIF_POINTOPOINT 0x00000004 | |
196 #define IFIF_VIRTUAL 0x00000008 | |
197 #define IFIF_IPMP 0x00000010 | |
198 #define IFIF_STANDBY 0x00000020 | |
199 #define IFIF_INACTIVE 0x00000040 | |
200 #define IFIF_VRRP 0x00000080 | |
201 #define IFIF_NOACCEPT 0x00000100 | |
202 #define IFIF_IPV4 0x00000200 | |
203 #define IFIF_IPV6 0x00000400 | |
204 | |
205 /* ipadm_addr_info_t state */ | |
206 typedef enum { | |
207 IFA_DISABLED, /* Address not in active configuration. */ | |
208 IFA_DUPLICATE, /* DAD failed. */ | |
209 IFA_DOWN, /* Address is not IFF_UP */ | |
210 IFA_TENTATIVE, /* DAD verification initiated */ | |
211 IFA_OK, /* Address is usable */ | |
212 IFA_INACCESSIBLE /* Interface has failed */ | |
213 } ipadm_addr_state_t; | |
214 | |
215 /* possible address types */ | |
216 typedef enum { | |
217 IPADM_ADDR_NONE, | |
218 IPADM_ADDR_STATIC, | |
219 IPADM_ADDR_IPV6_ADDRCONF, | |
220 IPADM_ADDR_DHCP | |
221 } ipadm_addr_type_t; | |
222 | |
223 typedef struct ipadm_addr_info_s { | |
224 struct ifaddrs ia_ifa; /* list of addresses */ | |
225 char ia_sname[NI_MAXHOST]; /* local hostname */ | |
226 char ia_dname[NI_MAXHOST]; /* remote hostname */ | |
227 char ia_aobjname[IPADM_AOBJSIZ]; | |
228 uint_t ia_cflags; /* active flags */ | |
229 uint_t ia_pflags; /* persistent flags */ | |
230 ipadm_addr_type_t ia_atype; /* see above */ | |
231 ipadm_addr_state_t ia_state; /* see above */ | |
232 } ipadm_addr_info_t; | |
233 #define IA_NEXT(ia) ((ipadm_addr_info_t *)(ia->ia_ifa.ifa_next)) | |
234 | |
235 /* ipadm_addr_info_t flags */ | |
236 #define IA_UP 0x00000001 | |
237 #define IA_UNNUMBERED 0x00000002 | |
238 #define IA_PRIVATE 0x00000004 | |
239 #define IA_TEMPORARY 0x00000008 | |
240 #define IA_DEPRECATED 0x00000010 | |
241 | |
242 /* open/close libipadm handle */ | |
243 extern ipadm_status_t ipadm_open(ipadm_handle_t *, uint32_t); | |
244 extern void ipadm_close(ipadm_handle_t); | |
245 | |
246 /* Check authorization for network configuration */ | |
247 extern boolean_t ipadm_check_auth(void); | |
248 /* | |
249 * Interface mangement functions | |
250 */ | |
251 extern ipadm_status_t ipadm_create_if(ipadm_handle_t, char *, sa_family_t, | |
252 uint32_t); | |
253 extern ipadm_status_t ipadm_disable_if(ipadm_handle_t, const char *, | |
254 uint32_t); | |
255 extern ipadm_status_t ipadm_enable_if(ipadm_handle_t, const char *, uint32_t); | |
256 extern ipadm_status_t ipadm_if_info(ipadm_handle_t, const char *, | |
257 ipadm_if_info_t **, uint32_t, int64_t); | |
258 extern void ipadm_free_if_info(ipadm_if_info_t *); | |
259 extern ipadm_status_t ipadm_delete_if(ipadm_handle_t, const char *, | |
260 sa_family_t, uint32_t); | |
261 | |
262 /* | |
263 * Address management functions | |
264 */ | |
265 extern ipadm_status_t ipadm_create_addr(ipadm_handle_t, ipadm_addrobj_t, | |
266 uint32_t); | |
267 extern ipadm_status_t ipadm_disable_addr(ipadm_handle_t, const char *, | |
268 uint32_t); | |
269 extern ipadm_status_t ipadm_enable_addr(ipadm_handle_t, const char *, | |
270 uint32_t); | |
271 extern ipadm_status_t ipadm_addr_info(ipadm_handle_t, const char *, | |
272 ipadm_addr_info_t **, uint32_t, int64_t); | |
273 extern void ipadm_free_addr_info(ipadm_addr_info_t *); | |
274 extern ipadm_status_t ipadm_up_addr(ipadm_handle_t, const char *, | |
275 uint32_t); | |
276 extern ipadm_status_t ipadm_down_addr(ipadm_handle_t, const char *, | |
277 uint32_t); | |
278 extern ipadm_status_t ipadm_refresh_addr(ipadm_handle_t, const char *, | |
279 uint32_t); | |
280 extern ipadm_status_t ipadm_delete_addr(ipadm_handle_t, const char *, | |
281 uint32_t); | |
282 | |
283 /* Functions related to creating/deleting/modifying opaque address object */ | |
284 extern ipadm_status_t ipadm_create_addrobj(ipadm_addr_type_t, const char *, | |
285 ipadm_addrobj_t *); | |
286 extern void ipadm_destroy_addrobj(ipadm_addrobj_t); | |
287 | |
288 /* Functions to set fields in addrobj for static addresses */ | |
289 extern ipadm_status_t ipadm_set_addr(ipadm_addrobj_t, const char *, | |
290 sa_family_t); | |
291 extern ipadm_status_t ipadm_set_dst_addr(ipadm_addrobj_t, const char *, | |
292 sa_family_t); | |
293 | |
294 /* Functions to set fields in addrobj for IPv6 addrconf */ | |
295 extern ipadm_status_t ipadm_set_interface_id(ipadm_addrobj_t, const char *); | |
296 extern ipadm_status_t ipadm_set_stateless(ipadm_addrobj_t, boolean_t); | |
297 extern ipadm_status_t ipadm_set_stateful(ipadm_addrobj_t, boolean_t); | |
298 | |
299 /* Functions to set fields in addrobj for DHCP */ | |
300 extern ipadm_status_t ipadm_set_primary(ipadm_addrobj_t, boolean_t); | |
301 extern ipadm_status_t ipadm_set_wait_time(ipadm_addrobj_t, int32_t); | |
302 | |
303 /* | |
304 * Property management functions | |
305 */ | |
306 /* call back function for the property walker */ | |
307 typedef boolean_t ipadm_prop_wfunc_t(void *, const char *, uint_t); | |
308 extern ipadm_status_t ipadm_walk_proptbl(uint_t, uint_t, ipadm_prop_wfunc_t *, | |
309 void *); | |
310 extern ipadm_status_t ipadm_walk_prop(const char *, uint_t, uint_t, | |
311 ipadm_prop_wfunc_t *, void *); | |
312 | |
313 /* Interface property management - set, reset and get */ | |
314 extern ipadm_status_t ipadm_set_ifprop(ipadm_handle_t, const char *, | |
315 const char *, const char *, uint_t, uint_t); | |
316 extern ipadm_status_t ipadm_get_ifprop(ipadm_handle_t, const char *, | |
317 const char *, char *, uint_t *, uint_t, uint_t); | |
318 | |
319 /* Address property management - set, reset and get */ | |
320 extern ipadm_status_t ipadm_set_addrprop(ipadm_handle_t, const char *, | |
321 const char *, const char *, uint_t); | |
322 extern ipadm_status_t ipadm_get_addrprop(ipadm_handle_t, const char *, char *, | |
323 uint_t *, const char *, uint_t); | |
324 | |
325 /* Protoocl property management - set, reset and get */ | |
326 extern ipadm_status_t ipadm_set_prop(ipadm_handle_t, const char *, | |
327 const char *, uint_t, uint_t); | |
328 extern ipadm_status_t ipadm_get_prop(ipadm_handle_t, const char *, char *, | |
329 uint_t *, uint_t, uint_t); | |
330 extern ipadm_status_t ipadm_init_prop(void); | |
331 | |
332 /* | |
333 * miscellaneous helper functions. | |
334 */ | |
335 extern const char *ipadm_status2str(ipadm_status_t); | |
336 extern int ipadm_str2nvlist(const char *, nvlist_t **, uint_t); | |
337 extern size_t ipadm_nvlist2str(nvlist_t *, char *, size_t); | |
338 extern char *ipadm_proto2str(uint_t); | |
339 extern uint_t ipadm_str2proto(const char *); | |
340 extern ipadm_status_t ipadm_open_arp_on_udp(const char *, int *); | |
341 | |
342 #ifdef __cplusplus | |
343 } | |
344 #endif | |
345 | |
346 #endif /* _LIBIPADM_H */ |