16e91bba0SGirish Moodalbail /*
26e91bba0SGirish Moodalbail  * CDDL HEADER START
36e91bba0SGirish Moodalbail  *
46e91bba0SGirish Moodalbail  * The contents of this file are subject to the terms of the
56e91bba0SGirish Moodalbail  * Common Development and Distribution License (the "License").
66e91bba0SGirish Moodalbail  * You may not use this file except in compliance with the License.
76e91bba0SGirish Moodalbail  *
86e91bba0SGirish Moodalbail  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96e91bba0SGirish Moodalbail  * or http://www.opensolaris.org/os/licensing.
106e91bba0SGirish Moodalbail  * See the License for the specific language governing permissions
116e91bba0SGirish Moodalbail  * and limitations under the License.
126e91bba0SGirish Moodalbail  *
136e91bba0SGirish Moodalbail  * When distributing Covered Code, include this CDDL HEADER in each
146e91bba0SGirish Moodalbail  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156e91bba0SGirish Moodalbail  * If applicable, add the following below this CDDL HEADER, with the
166e91bba0SGirish Moodalbail  * fields enclosed by brackets "[]" replaced with your own identifying
176e91bba0SGirish Moodalbail  * information: Portions Copyright [yyyy] [name of copyright owner]
186e91bba0SGirish Moodalbail  *
196e91bba0SGirish Moodalbail  * CDDL HEADER END
206e91bba0SGirish Moodalbail  */
216e91bba0SGirish Moodalbail 
226e91bba0SGirish Moodalbail /*
23ec3706caSVasumathi Sundaram  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24b31320a7SChris Fraire  * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
25*a73be61aSHans Rosenfeld  * Copyright 2021 Tintri by DDN, Inc. All rights reserved.
266e91bba0SGirish Moodalbail  */
276e91bba0SGirish Moodalbail 
286e91bba0SGirish Moodalbail #ifndef	_IPMGMT_IMPL_H
296e91bba0SGirish Moodalbail #define	_IPMGMT_IMPL_H
306e91bba0SGirish Moodalbail 
316e91bba0SGirish Moodalbail #ifdef  __cplusplus
326e91bba0SGirish Moodalbail extern "C" {
336e91bba0SGirish Moodalbail #endif
346e91bba0SGirish Moodalbail 
356e91bba0SGirish Moodalbail #include <net/if.h>
366e91bba0SGirish Moodalbail #include <libnvpair.h>
376e91bba0SGirish Moodalbail #include <libipadm.h>
386e91bba0SGirish Moodalbail #include <ipadm_ipmgmt.h>
396e91bba0SGirish Moodalbail #include <syslog.h>
406e91bba0SGirish Moodalbail #include <pthread.h>
418887b57dSGirish Moodalbail #include <libscf.h>
426e91bba0SGirish Moodalbail 
436e91bba0SGirish Moodalbail #define	IPMGMT_STRSIZE		256
44550b6e40SSowmini Varadhan #define	IPMGMTD_FMRI		"svc:/network/ip-interface-management:default"
456e91bba0SGirish Moodalbail 
466e91bba0SGirish Moodalbail /* ipmgmt_door.c */
476e91bba0SGirish Moodalbail extern void	ipmgmt_handler(void *, char *, size_t, door_desc_t *, uint_t);
486e91bba0SGirish Moodalbail 
496e91bba0SGirish Moodalbail /* ipmgmt_util.c */
506e91bba0SGirish Moodalbail extern void	ipmgmt_log(int, const char *, ...);
519b5bf10aSMark Haywood extern int	ipmgmt_cpfile(const char *, const char *, boolean_t);
526e91bba0SGirish Moodalbail 
536e91bba0SGirish Moodalbail /* ipmgmt_persist.c */
54*a73be61aSHans Rosenfeld extern boolean_t ipmgmt_persist_if_exists(const char *, sa_family_t);
55*a73be61aSHans Rosenfeld extern void ipmgmt_get_group_interface(const char *, char *, size_t);
566e91bba0SGirish Moodalbail 
576e91bba0SGirish Moodalbail /*
586e91bba0SGirish Moodalbail  * following are the list of DB walker callback functions and the callback
596e91bba0SGirish Moodalbail  * arguments for each of the callback functions used by the daemon
606e91bba0SGirish Moodalbail  */
616e91bba0SGirish Moodalbail /* following functions take 'ipmgmt_prop_arg_t' as the callback argument */
626e91bba0SGirish Moodalbail extern db_wfunc_t	ipmgmt_db_getprop, ipmgmt_db_resetprop;
636e91bba0SGirish Moodalbail 
646e91bba0SGirish Moodalbail /* following functions take ipadm_dbwrite_cbarg_t as callback argument */
65*a73be61aSHans Rosenfeld extern db_wfunc_t	ipmgmt_db_add, ipmgmt_db_update, ipmgmt_db_update_if;
666e91bba0SGirish Moodalbail 
676e91bba0SGirish Moodalbail typedef struct {
68*a73be61aSHans Rosenfeld 	char	*cb_ifname;
69*a73be61aSHans Rosenfeld 	char	*cb_aobjname;
706e91bba0SGirish Moodalbail 	nvlist_t	*cb_onvl;
71*a73be61aSHans Rosenfeld 	int	cb_ocnt;
72*a73be61aSHans Rosenfeld } ipmgmt_get_cbarg_t;
73*a73be61aSHans Rosenfeld extern db_wfunc_t	ipmgmt_db_getif;
746e91bba0SGirish Moodalbail extern db_wfunc_t	ipmgmt_db_getaddr;
756e91bba0SGirish Moodalbail 
766e91bba0SGirish Moodalbail typedef struct {
776e91bba0SGirish Moodalbail 	sa_family_t	cb_family;
786e91bba0SGirish Moodalbail 	char		*cb_ifname;
79*a73be61aSHans Rosenfeld 	boolean_t	cb_ipv4exists;
80*a73be61aSHans Rosenfeld 	boolean_t	cb_ipv6exists;
816e91bba0SGirish Moodalbail } ipmgmt_if_cbarg_t;
826e91bba0SGirish Moodalbail extern db_wfunc_t	ipmgmt_db_setif, ipmgmt_db_resetif;
836e91bba0SGirish Moodalbail 
846e91bba0SGirish Moodalbail typedef struct {
856e91bba0SGirish Moodalbail 	char		*cb_aobjname;
866e91bba0SGirish Moodalbail } ipmgmt_resetaddr_cbarg_t;
876e91bba0SGirish Moodalbail extern db_wfunc_t	ipmgmt_db_resetaddr;
886e91bba0SGirish Moodalbail 
896e91bba0SGirish Moodalbail typedef struct {
906e91bba0SGirish Moodalbail 	sa_family_t	cb_family;
916e91bba0SGirish Moodalbail 	nvlist_t	*cb_invl;
926e91bba0SGirish Moodalbail 	nvlist_t	*cb_onvl;
936e91bba0SGirish Moodalbail 	int		cb_ocnt;
946e91bba0SGirish Moodalbail } ipmgmt_initif_cbarg_t;
956e91bba0SGirish Moodalbail extern db_wfunc_t	ipmgmt_db_initif;
966e91bba0SGirish Moodalbail 
976e91bba0SGirish Moodalbail /*
986e91bba0SGirish Moodalbail  * A linked list of address object nodes. Each node in the list tracks
996e91bba0SGirish Moodalbail  * following information for the address object identified by `am_aobjname'.
1006e91bba0SGirish Moodalbail  *	- interface on which the address is created
101ed1e9379SHans Rosenfeld  *	- logical interface number on which the address is created
1026e91bba0SGirish Moodalbail  *	- address family
1036e91bba0SGirish Moodalbail  *	- `am_nextnum' identifies the next number to use to generate user part
1046e91bba0SGirish Moodalbail  *	  of `aobjname'.
1056e91bba0SGirish Moodalbail  *	- address type (static, dhcp or addrconf)
1066e91bba0SGirish Moodalbail  *	- `am_flags' indicates if this addrobj in active and/or persist config
107b31320a7SChris Fraire  *	- other, ipadm_addr_type_t-specific values are cached in
108b31320a7SChris Fraire  *	  am_addr_cache (see type ipmgmt_addr_cache_u):
109b31320a7SChris Fraire  *	  -	ipv6: ipmgmt_am_linklocal (macro)
110b31320a7SChris Fraire  *	  -	ipv6: ipmgmt_am_ifid (macro)
111b31320a7SChris Fraire  *	  -	dhcp: ipmgmt_am_reqhost (macro)
1126e91bba0SGirish Moodalbail  */
1136e91bba0SGirish Moodalbail typedef struct ipmgmt_aobjmap_s {
1146e91bba0SGirish Moodalbail 	struct ipmgmt_aobjmap_s	*am_next;
1156e91bba0SGirish Moodalbail 	char			am_aobjname[IPADM_AOBJSIZ];
1166e91bba0SGirish Moodalbail 	char			am_ifname[LIFNAMSIZ];
1176e91bba0SGirish Moodalbail 	int32_t			am_lnum;
1186e91bba0SGirish Moodalbail 	sa_family_t		am_family;
1196e91bba0SGirish Moodalbail 	ipadm_addr_type_t	am_atype;
1206e91bba0SGirish Moodalbail 	uint32_t		am_nextnum;
1216e91bba0SGirish Moodalbail 	uint32_t		am_flags;
122b31320a7SChris Fraire 	ipmgmt_addr_type_cache_u	am_atype_cache;
1236e91bba0SGirish Moodalbail } ipmgmt_aobjmap_t;
1246e91bba0SGirish Moodalbail 
125b31320a7SChris Fraire #define	ipmgmt_am_linklocal \
126b31320a7SChris Fraire     am_atype_cache.ipmgmt_ipv6_cache_s.ipmgmt_linklocal
127b31320a7SChris Fraire #define	ipmgmt_am_ifid \
128b31320a7SChris Fraire     am_atype_cache.ipmgmt_ipv6_cache_s.ipmgmt_ifid
129b31320a7SChris Fraire #define	ipmgmt_am_reqhost \
130b31320a7SChris Fraire     am_atype_cache.ipmgmt_dhcp_cache_s.ipmgmt_reqhost
131b31320a7SChris Fraire 
1326e91bba0SGirish Moodalbail /* linked list of `aobjmap' nodes, protected by RW lock */
1336e91bba0SGirish Moodalbail typedef struct ipmgmt_aobjmap_list_s {
1346e91bba0SGirish Moodalbail 	ipmgmt_aobjmap_t	*aobjmap_head;
1356e91bba0SGirish Moodalbail 	pthread_rwlock_t	aobjmap_rwlock;
1366e91bba0SGirish Moodalbail } ipmgmt_aobjmap_list_t;
1376e91bba0SGirish Moodalbail 
1386e91bba0SGirish Moodalbail /* global `aobjmap' defined in ipmgmt_main.c */
1396e91bba0SGirish Moodalbail extern ipmgmt_aobjmap_list_t aobjmap;
1406e91bba0SGirish Moodalbail 
1416e91bba0SGirish Moodalbail /* operations on the `aobjmap' linked list */
1426e91bba0SGirish Moodalbail #define	ADDROBJ_ADD		0x00000001
1436e91bba0SGirish Moodalbail #define	ADDROBJ_DELETE		0x00000002
1446e91bba0SGirish Moodalbail #define	ADDROBJ_LOOKUPADD	0x00000004
145ec3706caSVasumathi Sundaram #define	ADDROBJ_SETLIFNUM	0x00000008
1466e91bba0SGirish Moodalbail 
1478887b57dSGirish Moodalbail /* Permanent data store for ipadm */
1488887b57dSGirish Moodalbail #define	IPADM_DB_FILE		"/etc/ipadm/ipadm.conf"
1498887b57dSGirish Moodalbail #define	IPADM_FILE_MODE		(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
1508887b57dSGirish Moodalbail 
1518887b57dSGirish Moodalbail /*
1528887b57dSGirish Moodalbail  * With the initial integration of the daemon (PSARC 2010/080), the version
1538887b57dSGirish Moodalbail  * of the ipadm data-store (/etc/ipadm/ipadm.conf) was 0. A subsequent fix
1548887b57dSGirish Moodalbail  * needed an upgrade to the data-store and we bumped the version to 1.
1558887b57dSGirish Moodalbail  */
1568887b57dSGirish Moodalbail #define	IPADM_DB_VERSION	1
1578887b57dSGirish Moodalbail 
1586e91bba0SGirish Moodalbail /*
1596e91bba0SGirish Moodalbail  * A temporary file created in SMF volatile filesystem. This file captures the
1606e91bba0SGirish Moodalbail  * in-memory copy of list `aobjmap' on disk. This is done to recover from
1616e91bba0SGirish Moodalbail  * daemon reboot (using svcadm) or crashes.
1626e91bba0SGirish Moodalbail  */
1639b5bf10aSMark Haywood #define	IPADM_TMPFS_DIR		"/etc/svc/volatile/ipadm"
1646e91bba0SGirish Moodalbail #define	ADDROBJ_MAPPING_DB_FILE	IPADM_TMPFS_DIR"/aobjmap.conf"
1656e91bba0SGirish Moodalbail 
1669b5bf10aSMark Haywood /*
1679b5bf10aSMark Haywood  * A temporary copy of the ipadm configuration file might need
1689b5bf10aSMark Haywood  * to be created if write requests are encountered during boottime
1699b5bf10aSMark Haywood  * and the root filesystem is mounted read-only.
1709b5bf10aSMark Haywood  */
1719b5bf10aSMark Haywood #define	IPADM_VOL_DB_FILE	IPADM_TMPFS_DIR"/ipadm.conf"
1729b5bf10aSMark Haywood 
1738887b57dSGirish Moodalbail /* SCF resources required to interact with svc.configd */
1748887b57dSGirish Moodalbail typedef struct scf_resources {
1758887b57dSGirish Moodalbail 	scf_handle_t		*sr_handle;
1768887b57dSGirish Moodalbail 	scf_instance_t		*sr_inst;
1778887b57dSGirish Moodalbail 	scf_propertygroup_t	*sr_pg;
1788887b57dSGirish Moodalbail 	scf_property_t		*sr_prop;
1798887b57dSGirish Moodalbail 	scf_value_t		*sr_val;
1808887b57dSGirish Moodalbail 	scf_transaction_t	*sr_tx;
1818887b57dSGirish Moodalbail 	scf_transaction_entry_t	*sr_ent;
1828887b57dSGirish Moodalbail } scf_resources_t;
1838887b57dSGirish Moodalbail 
184*a73be61aSHans Rosenfeld extern int		ipmgmt_update_family_nvp(nvlist_t *,
185*a73be61aSHans Rosenfeld 			    sa_family_t, uint_t);
1866e91bba0SGirish Moodalbail extern int		ipmgmt_db_walk(db_wfunc_t *, void *, ipadm_db_op_t);
1876e91bba0SGirish Moodalbail extern int		ipmgmt_aobjmap_op(ipmgmt_aobjmap_t *, uint32_t);
1886e91bba0SGirish Moodalbail extern boolean_t	ipmgmt_aobjmap_init(void *, nvlist_t *, char *,
1896e91bba0SGirish Moodalbail 			    size_t, int *);
190ed1e9379SHans Rosenfeld extern int		ipmgmt_persist_aobjmap(ipmgmt_aobjmap_t *,
1916e91bba0SGirish Moodalbail 			    ipadm_db_op_t);
1928887b57dSGirish Moodalbail extern boolean_t	ipmgmt_ngz_firstboot_postinstall();
193550b6e40SSowmini Varadhan extern int		ipmgmt_persist_if(ipmgmt_if_arg_t *);
1948887b57dSGirish Moodalbail extern void		ipmgmt_init_prop();
1958887b57dSGirish Moodalbail extern boolean_t	ipmgmt_db_upgrade(void *, nvlist_t *, char *,
1968887b57dSGirish Moodalbail 			    size_t, int *);
1978887b57dSGirish Moodalbail extern int		ipmgmt_create_scf_resources(const char *,
1988887b57dSGirish Moodalbail 			    scf_resources_t *);
1998887b57dSGirish Moodalbail extern void		ipmgmt_release_scf_resources(scf_resources_t *);
2008887b57dSGirish Moodalbail extern boolean_t	ipmgmt_needs_upgrade(scf_resources_t *);
2018887b57dSGirish Moodalbail extern void		ipmgmt_update_dbver(scf_resources_t *);
2028887b57dSGirish Moodalbail 
2036e91bba0SGirish Moodalbail #ifdef  __cplusplus
2046e91bba0SGirish Moodalbail }
2056e91bba0SGirish Moodalbail #endif
2066e91bba0SGirish Moodalbail 
2076e91bba0SGirish Moodalbail #endif	/* _IPMGMT_IMPL_H */
208