xref: /titanic_44/usr/src/cmd/cmd-inet/lib/ipmgmtd/ipmgmt_impl.h (revision cb04b8739c50e3e6d12e89b790fa7b8d0d899865)
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  */
25 
26 #ifndef	_IPMGMT_IMPL_H
27 #define	_IPMGMT_IMPL_H
28 
29 #ifdef  __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <net/if.h>
34 #include <libnvpair.h>
35 #include <libipadm.h>
36 #include <ipadm_ipmgmt.h>
37 #include <syslog.h>
38 #include <pthread.h>
39 
40 #define	IPMGMT_STRSIZE		256
41 #define	IPMGMTD_FMRI		"svc:/network/ip-interface-management:default"
42 
43 /* ipmgmt_door.c */
44 extern void	ipmgmt_handler(void *, char *, size_t, door_desc_t *, uint_t);
45 
46 /* ipmgmt_util.c */
47 extern void	ipmgmt_log(int, const char *, ...);
48 extern int	ipmgmt_cpfile(const char *, const char *, boolean_t);
49 
50 /* ipmgmt_persist.c */
51 
52 /*
53  * following are the list of DB walker callback functions and the callback
54  * arguments for each of the callback functions used by the daemon
55  */
56 /* following functions take 'ipmgmt_prop_arg_t' as the callback argument */
57 extern db_wfunc_t	ipmgmt_db_getprop, ipmgmt_db_resetprop;
58 
59 /* following functions take ipadm_dbwrite_cbarg_t as callback argument */
60 extern db_wfunc_t	ipmgmt_db_add, ipmgmt_db_update;
61 
62 typedef struct {
63 	char		*cb_ifname;
64 	ipadm_if_info_t	*cb_ifinfo;
65 } ipmgmt_getif_cbarg_t;
66 extern db_wfunc_t	ipmgmt_db_getif;
67 
68 typedef struct {
69 	char		*cb_aobjname;
70 	char		*cb_ifname;
71 	nvlist_t	*cb_onvl;
72 	int		cb_ocnt;
73 } ipmgmt_getaddr_cbarg_t;
74 extern db_wfunc_t	ipmgmt_db_getaddr;
75 
76 typedef struct {
77 	sa_family_t	cb_family;
78 	char		*cb_ifname;
79 } ipmgmt_if_cbarg_t;
80 extern db_wfunc_t	ipmgmt_db_setif, ipmgmt_db_resetif;
81 
82 typedef struct {
83 	char		*cb_aobjname;
84 } ipmgmt_resetaddr_cbarg_t;
85 extern db_wfunc_t	ipmgmt_db_resetaddr;
86 
87 typedef struct {
88 	sa_family_t	cb_family;
89 	nvlist_t	*cb_invl;
90 	nvlist_t	*cb_onvl;
91 	int		cb_ocnt;
92 } ipmgmt_initif_cbarg_t;
93 extern db_wfunc_t	ipmgmt_db_initif;
94 
95 /*
96  * A linked list of address object nodes. Each node in the list tracks
97  * following information for the address object identified by `am_aobjname'.
98  *	- interface on which the address is created
99  * 	- logical interface number on which the address is created
100  *	- address family
101  *	- `am_nextnum' identifies the next number to use to generate user part
102  *	  of `aobjname'.
103  *	- address type (static, dhcp or addrconf)
104  *	- `am_flags' indicates if this addrobj in active and/or persist config
105  *	- if `am_atype' is IPADM_ADDR_IPV6_ADDRCONF then `am_ifid' holds the
106  *	  interface-id used to configure auto-configured addresses
107  */
108 typedef struct ipmgmt_aobjmap_s {
109 	struct ipmgmt_aobjmap_s	*am_next;
110 	char			am_aobjname[IPADM_AOBJSIZ];
111 	char			am_ifname[LIFNAMSIZ];
112 	int32_t			am_lnum;
113 	sa_family_t		am_family;
114 	ipadm_addr_type_t	am_atype;
115 	uint32_t		am_nextnum;
116 	uint32_t		am_flags;
117 	boolean_t		am_linklocal;
118 	struct sockaddr_storage	am_ifid;
119 } ipmgmt_aobjmap_t;
120 
121 /* linked list of `aobjmap' nodes, protected by RW lock */
122 typedef struct ipmgmt_aobjmap_list_s {
123 	ipmgmt_aobjmap_t	*aobjmap_head;
124 	pthread_rwlock_t	aobjmap_rwlock;
125 } ipmgmt_aobjmap_list_t;
126 
127 /* global `aobjmap' defined in ipmgmt_main.c */
128 extern ipmgmt_aobjmap_list_t aobjmap;
129 
130 /* operations on the `aobjmap' linked list */
131 #define	ADDROBJ_ADD		0x00000001
132 #define	ADDROBJ_DELETE		0x00000002
133 #define	ADDROBJ_LOOKUPADD	0x00000004
134 #define	ADDROBJ_SETLIFNUM	0x00000008
135 
136 /*
137  * A temporary file created in SMF volatile filesystem. This file captures the
138  * in-memory copy of list `aobjmap' on disk. This is done to recover from
139  * daemon reboot (using svcadm) or crashes.
140  */
141 #define	IPADM_TMPFS_DIR		"/etc/svc/volatile/ipadm"
142 #define	ADDROBJ_MAPPING_DB_FILE	IPADM_TMPFS_DIR"/aobjmap.conf"
143 
144 /*
145  * A temporary copy of the ipadm configuration file might need
146  * to be created if write requests are encountered during boottime
147  * and the root filesystem is mounted read-only.
148  */
149 #define	IPADM_VOL_DB_FILE	IPADM_TMPFS_DIR"/ipadm.conf"
150 
151 extern int		ipmgmt_db_walk(db_wfunc_t *, void *, ipadm_db_op_t);
152 extern int		ipmgmt_aobjmap_op(ipmgmt_aobjmap_t *, uint32_t);
153 extern boolean_t	ipmgmt_aobjmap_init(void *, nvlist_t *, char *,
154 			    size_t, int *);
155 extern int 		ipmgmt_persist_aobjmap(ipmgmt_aobjmap_t *,
156 			    ipadm_db_op_t);
157 
158 extern boolean_t	ipmgmt_first_boot();
159 extern int		ipmgmt_persist_if(ipmgmt_if_arg_t *);
160 #ifdef  __cplusplus
161 }
162 #endif
163 
164 #endif	/* _IPMGMT_IMPL_H */
165