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