xref: /illumos-gate/usr/src/cmd/cmd-inet/lib/ipmgmtd/ipmgmt_impl.h (revision 50e803017668ce124e5b7c37cae78c397813805a)
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 /*
23  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
25  * Copyright 2021, Tintri by DDN. All rights reserved.
26  */
27 
28 #ifndef	_IPMGMT_IMPL_H
29 #define	_IPMGMT_IMPL_H
30 
31 #ifdef  __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <net/if.h>
36 #include <libnvpair.h>
37 #include <libipadm.h>
38 #include <ipadm_ipmgmt.h>
39 #include <syslog.h>
40 #include <pthread.h>
41 #include <libscf.h>
42 
43 #define	IPMGMT_STRSIZE		256
44 #define	IPMGMTD_FMRI		"svc:/network/ip-interface-management:default"
45 
46 /* ipmgmt_door.c */
47 extern void	ipmgmt_handler(void *, char *, size_t, door_desc_t *, uint_t);
48 
49 /* ipmgmt_util.c */
50 extern void	ipmgmt_log(int, const char *, ...);
51 extern int	ipmgmt_cpfile(const char *, const char *, boolean_t);
52 
53 /* ipmgmt_persist.c */
54 
55 /*
56  * following are the list of DB walker callback functions and the callback
57  * arguments for each of the callback functions used by the daemon
58  */
59 /* following functions take 'ipmgmt_prop_arg_t' as the callback argument */
60 extern db_wfunc_t	ipmgmt_db_getprop, ipmgmt_db_resetprop;
61 
62 /* following functions take ipadm_dbwrite_cbarg_t as callback argument */
63 extern db_wfunc_t	ipmgmt_db_add, ipmgmt_db_update;
64 
65 typedef struct {
66 	char			*cb_ifname;
67 	ipadm_if_info_list_t	*cb_ifinfo;
68 } ipmgmt_getif_cbarg_t;
69 extern db_wfunc_t	ipmgmt_db_getif;
70 
71 typedef struct {
72 	char		*cb_aobjname;
73 	char		*cb_ifname;
74 	nvlist_t	*cb_onvl;
75 	int		cb_ocnt;
76 } ipmgmt_getaddr_cbarg_t;
77 extern db_wfunc_t	ipmgmt_db_getaddr;
78 
79 typedef struct {
80 	sa_family_t	cb_family;
81 	char		*cb_ifname;
82 } ipmgmt_if_cbarg_t;
83 extern db_wfunc_t	ipmgmt_db_setif, ipmgmt_db_resetif;
84 
85 typedef struct {
86 	char		*cb_aobjname;
87 } ipmgmt_resetaddr_cbarg_t;
88 extern db_wfunc_t	ipmgmt_db_resetaddr;
89 
90 typedef struct {
91 	sa_family_t	cb_family;
92 	nvlist_t	*cb_invl;
93 	nvlist_t	*cb_onvl;
94 	int		cb_ocnt;
95 } ipmgmt_initif_cbarg_t;
96 extern db_wfunc_t	ipmgmt_db_initif;
97 
98 /*
99  * A linked list of address object nodes. Each node in the list tracks
100  * following information for the address object identified by `am_aobjname'.
101  *	- interface on which the address is created
102  *	- logical interface number on which the address is created
103  *	- address family
104  *	- `am_nextnum' identifies the next number to use to generate user part
105  *	  of `aobjname'.
106  *	- address type (static, dhcp or addrconf)
107  *	- `am_flags' indicates if this addrobj in active and/or persist config
108  *	- other, ipadm_addr_type_t-specific values are cached in
109  *	  am_addr_cache (see type ipmgmt_addr_cache_u):
110  *	  -	ipv6: ipmgmt_am_linklocal (macro)
111  *	  -	ipv6: ipmgmt_am_ifid (macro)
112  *	  -	dhcp: ipmgmt_am_reqhost (macro)
113  */
114 typedef struct ipmgmt_aobjmap_s {
115 	struct ipmgmt_aobjmap_s	*am_next;
116 	char			am_aobjname[IPADM_AOBJSIZ];
117 	char			am_ifname[LIFNAMSIZ];
118 	int32_t			am_lnum;
119 	sa_family_t		am_family;
120 	ipadm_addr_type_t	am_atype;
121 	uint32_t		am_nextnum;
122 	uint32_t		am_flags;
123 	ipmgmt_addr_type_cache_u	am_atype_cache;
124 } ipmgmt_aobjmap_t;
125 
126 #define	ipmgmt_am_linklocal \
127     am_atype_cache.ipmgmt_ipv6_cache_s.ipmgmt_linklocal
128 #define	ipmgmt_am_ifid \
129     am_atype_cache.ipmgmt_ipv6_cache_s.ipmgmt_ifid
130 #define	ipmgmt_am_reqhost \
131     am_atype_cache.ipmgmt_dhcp_cache_s.ipmgmt_reqhost
132 
133 /* linked list of `aobjmap' nodes, protected by RW lock */
134 typedef struct ipmgmt_aobjmap_list_s {
135 	ipmgmt_aobjmap_t	*aobjmap_head;
136 	pthread_rwlock_t	aobjmap_rwlock;
137 } ipmgmt_aobjmap_list_t;
138 
139 /* global `aobjmap' defined in ipmgmt_main.c */
140 extern ipmgmt_aobjmap_list_t aobjmap;
141 
142 /* operations on the `aobjmap' linked list */
143 #define	ADDROBJ_ADD		0x00000001
144 #define	ADDROBJ_DELETE		0x00000002
145 #define	ADDROBJ_LOOKUPADD	0x00000004
146 #define	ADDROBJ_SETLIFNUM	0x00000008
147 
148 /* Permanent data store for ipadm */
149 #define	IPADM_DB_FILE		"/etc/ipadm/ipadm.conf"
150 #define	IPADM_FILE_MODE		(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
151 
152 /*
153  * With the initial integration of the daemon (PSARC 2010/080), the version
154  * of the ipadm data-store (/etc/ipadm/ipadm.conf) was 0. A subsequent fix
155  * needed an upgrade to the data-store and we bumped the version to 1.
156  */
157 #define	IPADM_DB_VERSION	1
158 
159 /*
160  * A temporary file created in SMF volatile filesystem. This file captures the
161  * in-memory copy of list `aobjmap' on disk. This is done to recover from
162  * daemon reboot (using svcadm) or crashes.
163  */
164 #define	IPADM_TMPFS_DIR		"/etc/svc/volatile/ipadm"
165 #define	ADDROBJ_MAPPING_DB_FILE	IPADM_TMPFS_DIR"/aobjmap.conf"
166 
167 /*
168  * A temporary copy of the ipadm configuration file might need
169  * to be created if write requests are encountered during boottime
170  * and the root filesystem is mounted read-only.
171  */
172 #define	IPADM_VOL_DB_FILE	IPADM_TMPFS_DIR"/ipadm.conf"
173 
174 /* SCF resources required to interact with svc.configd */
175 typedef struct scf_resources {
176 	scf_handle_t		*sr_handle;
177 	scf_instance_t		*sr_inst;
178 	scf_propertygroup_t	*sr_pg;
179 	scf_property_t		*sr_prop;
180 	scf_value_t		*sr_val;
181 	scf_transaction_t	*sr_tx;
182 	scf_transaction_entry_t	*sr_ent;
183 } scf_resources_t;
184 
185 extern int		ipmgmt_db_walk(db_wfunc_t *, void *, ipadm_db_op_t);
186 extern int		ipmgmt_aobjmap_op(ipmgmt_aobjmap_t *, uint32_t);
187 extern boolean_t	ipmgmt_aobjmap_init(void *, nvlist_t *, char *,
188 			    size_t, int *);
189 extern int		ipmgmt_persist_aobjmap(ipmgmt_aobjmap_t *,
190 			    ipadm_db_op_t);
191 extern boolean_t	ipmgmt_ngz_firstboot_postinstall();
192 extern int		ipmgmt_persist_if(ipmgmt_if_arg_t *);
193 extern void		ipmgmt_init_prop();
194 extern boolean_t	ipmgmt_db_upgrade(void *, nvlist_t *, char *,
195 			    size_t, int *);
196 extern int		ipmgmt_create_scf_resources(const char *,
197 			    scf_resources_t *);
198 extern void		ipmgmt_release_scf_resources(scf_resources_t *);
199 extern boolean_t	ipmgmt_needs_upgrade(scf_resources_t *);
200 extern void		ipmgmt_update_dbver(scf_resources_t *);
201 
202 #ifdef  __cplusplus
203 }
204 #endif
205 
206 #endif	/* _IPMGMT_IMPL_H */
207