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