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 (c) 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _IPADM_IPMGMT_H
26 #define	_IPADM_IPMGMT_H
27 
28 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <sys/mman.h>
35 #include <door.h>
36 #include <libipadm.h>
37 #include <inet/tunables.h>
38 
39 /*
40  * Function declarations and data structures shared by libipadm.so and
41  * the IP management daemon.
42  */
43 
44 /* Authorization required to configure network interfaces */
45 #define	NETWORK_INTERFACE_CONFIG_AUTH	"solaris.network.interface.config"
46 
47 /*
48  * Data store read/write utilities related declarations.
49  */
50 /* Permanent data store for ipadm */
51 #define	IPADM_DB_FILE		"/etc/ipadm/ipadm.conf"
52 #define	IPADM_FILE_MODE		(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
53 
54 /*
55  * For more information on these definitions please refer to the top of
56  * ipadm_persist.c. These are the name of the nvpairs which hold the
57  * respective values. All nvpairs private to ipadm have names that begin
58  * with "_". Note below that 'prefixlen' is an address property and therefore
59  * not a private nvpair name.
60  */
61 #define	IPADM_NVP_PROTONAME	"_protocol"	/* protocol name */
62 #define	IPADM_NVP_IFNAME	"_ifname"	/* interface name */
63 #define	IPADM_NVP_AOBJNAME	"_aobjname"	/* addrobj name */
64 #define	IPADM_NVP_FAMILY	"_family"	/* address family */
65 #define	IPADM_NVP_IPV4ADDR	"_ipv4addr"	/* name of IPv4 addr nvlist */
66 #define	IPADM_NVP_IPNUMADDR	"_addr"		/* local address */
67 #define	IPADM_NVP_IPADDRHNAME	"_aname"	/* local hostname */
68 #define	IPADM_NVP_IPDADDRHNAME	"_dname"	/* remote hostname */
69 #define	IPADM_NVP_PREFIXLEN	"prefixlen"	/* prefixlen */
70 #define	IPADM_NVP_IPV6ADDR	"_ipv6addr"	/* name of IPv6 addr nvlist */
71 #define	IPADM_NVP_DHCP		"_dhcp"		/* name of DHCP nvlist */
72 #define	IPADM_NVP_WAIT		"_wait"		/* DHCP timeout value */
73 #define	IPADM_NVP_PRIMARY	"_primary"	/* DHCP primary interface */
74 #define	IPADM_NVP_LIFNUM	"_lifnum"	/* logical interface number */
75 #define	IPADM_NVP_INTFID	"_intfid"	/* name of IPv6 intfid nvlist */
76 #define	IPADM_NVP_STATELESS	"_stateless"	/* IPv6 autoconf stateless */
77 #define	IPADM_NVP_STATEFUL	"_stateful"	/* IPv6 autoconf dhcpv6 */
78 
79 #define	IPADM_PRIV_NVP(s) ((s)[0] == '_')
80 
81 /* data-store operations */
82 typedef enum {
83 	IPADM_DB_WRITE = 0,	/* Writes to DB */
84 	IPADM_DB_DELETE,	/* Deletes an entry from DB */
85 	IPADM_DB_READ		/* Read from DB */
86 } ipadm_db_op_t;
87 
88 /*
89  * callback arg used by db_wfunc_t that writes to DB. The contents to be
90  * written to DB are captured in `dbw_nvl'.
91  */
92 typedef	struct	ipadm_dbwrite_cbarg_s {
93 	nvlist_t	*dbw_nvl;
94 	uint_t		dbw_flags;
95 } ipadm_dbwrite_cbarg_t;
96 
97 /*
98  * door related function declarations and data structures.
99  */
100 
101 /* The door file for the ipmgmt (ip-interface management) daemon */
102 #define	IPMGMT_DOOR		"/etc/svc/volatile/ipadm/ipmgmt_door"
103 #define	MAXPROTONAMELEN		32
104 
105 /* door call command type */
106 typedef enum {
107 	IPMGMT_CMD_SETPROP = 1,		/* persist property */
108 	IPMGMT_CMD_SETIF,		/* persist interface */
109 	IPMGMT_CMD_SETADDR,		/* persist address */
110 	IPMGMT_CMD_GETPROP,		/* retrieve persisted property value */
111 	IPMGMT_CMD_GETIF,		/* retrieve persisted interface conf. */
112 	IPMGMT_CMD_GETADDR,		/* retrieve persisted addresses */
113 	IPMGMT_CMD_RESETIF,		/* purge interface configuration */
114 	IPMGMT_CMD_RESETADDR,		/* purge address configuration */
115 	IPMGMT_CMD_RESETPROP,		/* purge property configuration */
116 	IPMGMT_CMD_INITIF,		/* retrieve interfaces to initialize */
117 	IPMGMT_CMD_ADDROBJ_LOOKUPADD,	/* addr. object lookup & add */
118 	IPMGMT_CMD_ADDROBJ_SETLIFNUM,	/* set lifnum on the addrobj */
119 	IPMGMT_CMD_ADDROBJ_ADD,		/* add addr. object to addrobj map */
120 	IPMGMT_CMD_LIF2ADDROBJ,		/* lifname to addrobj mapping */
121 	IPMGMT_CMD_AOBJNAME2ADDROBJ	/* aobjname to addrobj mapping */
122 } ipmgmt_door_cmd_type_t;
123 
124 /*
125  * Note: We need to keep the size of the structure the same on amd64 and i386
126  * for all door_call arguments and door_return structures.
127  */
128 /* door_call argument */
129 typedef struct ipmgmt_arg {
130 	ipmgmt_door_cmd_type_t	ia_cmd;
131 } ipmgmt_arg_t;
132 
133 /* IPMGMT_CMD_{SETPROP|GETPROP|RESETPROP} door_call argument */
134 typedef struct ipmgmt_prop_arg_s {
135 	ipmgmt_door_cmd_type_t	ia_cmd;
136 	uint32_t		ia_flags;
137 	char			ia_ifname[LIFNAMSIZ];
138 	char			ia_aobjname[IPADM_AOBJSIZ];
139 	char			ia_module[MAXPROTONAMELEN];
140 	char			ia_pname[MAXPROPNAMELEN];
141 	char			ia_pval[MAXPROPVALLEN];
142 } ipmgmt_prop_arg_t;
143 /*
144  * ia_flags used in ipmgmt_prop_arg_t.
145  *	- APPEND updates the multi-valued property entry with a new value
146  *	- REDUCE updates the multi-valued property entry by removing a value
147  */
148 #define	IPMGMT_APPEND	0x00000001
149 #define	IPMGMT_REMOVE	0x00000002
150 
151 /* IPMGMT_CMD_GETIF door_call argument structure */
152 typedef struct ipmgmt_getif_arg_s {
153 	ipmgmt_door_cmd_type_t	ia_cmd;
154 	uint32_t	ia_flags;
155 	char		ia_ifname[LIFNAMSIZ];
156 } ipmgmt_getif_arg_t;
157 
158 /* IPMGMT_CMD_RESETIF, IPMGMT_CMD_SETIF door_call argument structure */
159 typedef struct ipmgmt_if_arg_s {
160 	ipmgmt_door_cmd_type_t	ia_cmd;
161 	uint32_t		ia_flags;
162 	char			ia_ifname[LIFNAMSIZ];
163 	sa_family_t		ia_family;
164 } ipmgmt_if_arg_t;
165 
166 /* IPMGMT_CMD_INITIF door_call argument structure */
167 typedef struct ipmgmt_initif_arg_s {
168 	ipmgmt_door_cmd_type_t	ia_cmd;
169 	uint32_t	ia_flags;
170 	sa_family_t	ia_family;
171 	size_t		ia_nvlsize;
172 	/* packed nvl follows */
173 } ipmgmt_initif_arg_t;
174 
175 /* IPMGMT_CMD_SETADDR door_call argument */
176 typedef struct ipmgmt_setaddr_arg_s {
177 	ipmgmt_door_cmd_type_t	ia_cmd;
178 	uint32_t		ia_flags;
179 	size_t			ia_nvlsize;
180 	/* packed nvl follows */
181 } ipmgmt_setaddr_arg_t;
182 
183 /* IPMGMT_CMD_GETADDR door_call argument */
184 typedef struct ipmgmt_getaddr_arg_s {
185 	ipmgmt_door_cmd_type_t	ia_cmd;
186 	uint32_t	ia_flags;
187 	char		ia_ifname[LIFNAMSIZ];
188 	sa_family_t	ia_family;
189 	char		ia_aobjname[IPADM_AOBJSIZ];
190 } ipmgmt_getaddr_arg_t;
191 
192 /* IPMGMT_CMD_RESETADDR door_call argument */
193 typedef struct ipmgmt_addr_arg_s {
194 	ipmgmt_door_cmd_type_t	ia_cmd;
195 	uint32_t	ia_flags;
196 	char		ia_aobjname[IPADM_AOBJSIZ];
197 	int32_t		ia_lnum;
198 } ipmgmt_addr_arg_t;
199 
200 /*
201  * IPMGMT_CMD_{ADDROBJ_ADD|ADDROBJ_LOOKUPADD|LIFNUM2ADDROBJ|
202  * ADDROBJ2LIFNUM} door_call argument.
203  */
204 typedef struct ipmgmt_aobjop_arg_s {
205 	ipmgmt_door_cmd_type_t	ia_cmd;
206 	uint32_t		ia_flags;
207 	char			ia_aobjname[IPADM_AOBJSIZ];
208 	char			ia_ifname[LIFNAMSIZ];
209 	int32_t			ia_lnum;
210 	sa_family_t		ia_family;
211 	ipadm_addr_type_t	ia_atype;
212 } ipmgmt_aobjop_arg_t;
213 
214 /*
215  * ia_flags used inside the arguments for interface/address commands
216  *	- ACTIVE updates the running configuration
217  *	- PERSIST updates the permanent data store
218  *	- INIT	indicates that operation being performed is under init
219  *		    context
220  */
221 #define	IPMGMT_ACTIVE		0x00000001
222 #define	IPMGMT_PERSIST		0x00000002
223 #define	IPMGMT_INIT		0x00000004
224 
225 /* door call return value */
226 typedef struct ipmgmt_retval_s {
227 	int32_t	ir_err;
228 } ipmgmt_retval_t;
229 
230 /* IPMGMT_CMD_GETADDR door_return value */
231 typedef struct ipmgmt_get_rval_s {
232 	int32_t		ir_err;
233 	size_t		ir_nvlsize;
234 	/* packed nvl follows */
235 } ipmgmt_get_rval_t;
236 
237 /* IPMGMT_CMD_GETPROP door_return value */
238 typedef struct ipmgmt_getprop_rval_s {
239 	int32_t		ir_err;
240 	char		ir_pval[MAXPROPVALLEN];
241 } ipmgmt_getprop_rval_t;
242 
243 /* IPMGMT_CMD_GETIF door_return value */
244 typedef struct ipmgmt_getif_rval_s {
245 	int32_t		ir_err;
246 	uint32_t	ir_ifcnt;
247 	ipadm_if_info_t	ir_ifinfo[1];
248 } ipmgmt_getif_rval_t;
249 
250 /* IPMGMT_CMD_{LOOKUPADD|LIFNUM2ADDROBJ|ADDROBJ2LIFNUM} door_return value */
251 typedef struct ipmgmt_aobjop_rval_s {
252 	int32_t			ir_err;
253 	char			ir_aobjname[IPADM_AOBJSIZ];
254 	char			ir_ifname[LIFNAMSIZ];
255 	int32_t			ir_lnum;
256 	sa_family_t		ir_family;
257 	uint32_t		ir_flags;
258 	ipadm_addr_type_t	ir_atype;
259 	struct sockaddr_storage	ir_ifid;
260 } ipmgmt_aobjop_rval_t;
261 
262 /* DB walk callback functions */
263 typedef boolean_t	db_wfunc_t(void *, nvlist_t *, char *, size_t, int *);
264 extern int		ipadm_rw_db(db_wfunc_t *, void *, const char *, mode_t,
265 			    ipadm_db_op_t);
266 
267 /* zone related functions */
268 /*
269  *  callback function to persist an interface in ipmgmtd data store
270  */
271 typedef void (*persist_cb_t)(char *, boolean_t, boolean_t);
272 /*
273  * ipmgmtd/libipadm network initialization interface.
274  */
275 extern ipadm_status_t	ipadm_init_net_from_gz(ipadm_handle_t, char *,
276 			    persist_cb_t);
277 
278 #ifdef	__cplusplus
279 }
280 #endif
281 
282 #endif	/* _IPADM_IPMGMT_H */
283