xref: /titanic_51/usr/src/cmd/dlmgmtd/dlmgmt_impl.h (revision 6bbe05905a1c10a2703f95fb4912eb14b87f6670)
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 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Functions to maintain a table of datalink configuration information.
29  */
30 
31 #ifndef	_DLMGMT_IMPL_H
32 #define	_DLMGMT_IMPL_H
33 
34 #ifdef  __cplusplus
35 extern "C" {
36 #endif
37 
38 #include <door.h>
39 #include <libdllink.h>
40 #include <sys/avl.h>
41 
42 /*
43  * datalink attribute structure
44  */
45 typedef struct dlmgmt_linkattr_s {
46 	struct dlmgmt_linkattr_s	*lp_next;
47 	struct dlmgmt_linkattr_s	*lp_prev;
48 	char				lp_name[MAXLINKATTRLEN];
49 	void				*lp_val;
50 	dladm_datatype_t		lp_type;
51 	uint_t				lp_sz;
52 	boolean_t			lp_linkprop;
53 } dlmgmt_linkattr_t;
54 
55 /*
56  * datalink structure
57  */
58 typedef struct dlmgmt_link_s {
59 	dlmgmt_linkattr_t	*ll_head;
60 	char			ll_link[MAXLINKNAMELEN];
61 	datalink_class_t	ll_class;
62 	uint32_t		ll_media;
63 	datalink_id_t		ll_linkid;
64 	zoneid_t		ll_zoneid;
65 	boolean_t		ll_onloan;
66 	avl_node_t		ll_name_node;
67 	avl_node_t		ll_id_node;
68 	avl_node_t		ll_loan_node;
69 	uint32_t		ll_flags;
70 	uint32_t		ll_gen;		/* generation number */
71 } dlmgmt_link_t;
72 
73 /*
74  * datalink configuration request structure
75  */
76 typedef struct dlmgmt_dlconf_s {
77 	dlmgmt_linkattr_t	*ld_head;
78 	char			ld_link[MAXLINKNAMELEN];
79 	datalink_id_t		ld_linkid;
80 	datalink_class_t	ld_class;
81 	uint32_t		ld_media;
82 	int			ld_id;
83 	zoneid_t		ld_zoneid;
84 	uint32_t		ld_gen;
85 	avl_node_t		ld_node;
86 } dlmgmt_dlconf_t;
87 
88 extern boolean_t	debug;
89 extern const char	*progname;
90 extern char		cachefile[];
91 extern dladm_handle_t	dld_handle;
92 extern datalink_id_t	dlmgmt_nextlinkid;
93 extern avl_tree_t	dlmgmt_name_avl;
94 extern avl_tree_t	dlmgmt_id_avl;
95 extern avl_tree_t	dlmgmt_loan_avl;
96 extern avl_tree_t	dlmgmt_dlconf_avl;
97 
98 boolean_t	linkattr_equal(dlmgmt_linkattr_t **, const char *, void *,
99 		    size_t);
100 dlmgmt_linkattr_t *linkattr_find(dlmgmt_linkattr_t *, const char *);
101 void		linkattr_unset(dlmgmt_linkattr_t **, const char *);
102 int		linkattr_set(dlmgmt_linkattr_t **, const char *, void *,
103 		    size_t, dladm_datatype_t);
104 int		linkattr_get(dlmgmt_linkattr_t **, const char *, void **,
105 		    size_t *, dladm_datatype_t *);
106 int		linkprop_getnext(dlmgmt_linkattr_t **, const char *,
107 		    char **, void **, size_t *, dladm_datatype_t *);
108 
109 void		link_destroy(dlmgmt_link_t *);
110 int		link_activate(dlmgmt_link_t *);
111 boolean_t	link_is_visible(dlmgmt_link_t *, zoneid_t);
112 dlmgmt_link_t	*link_by_id(datalink_id_t, zoneid_t);
113 dlmgmt_link_t	*link_by_name(const char *, zoneid_t);
114 int		dlmgmt_create_common(const char *, datalink_class_t,
115 		    uint32_t, zoneid_t, uint32_t, dlmgmt_link_t **);
116 int		dlmgmt_destroy_common(dlmgmt_link_t *, uint32_t);
117 int		dlmgmt_getattr_common(dlmgmt_linkattr_t **, const char *,
118 		    dlmgmt_getattr_retval_t *);
119 
120 void		dlmgmt_advance(dlmgmt_link_t *);
121 void		dlmgmt_table_lock(boolean_t);
122 void		dlmgmt_table_unlock();
123 
124 int		dlconf_create(const char *, datalink_id_t, datalink_class_t,
125 		    uint32_t, zoneid_t, dlmgmt_dlconf_t **);
126 void		dlconf_destroy(dlmgmt_dlconf_t *);
127 void		dlmgmt_advance_dlconfid(dlmgmt_dlconf_t *);
128 void		dlmgmt_dlconf_table_lock(boolean_t);
129 void		dlmgmt_dlconf_table_unlock(void);
130 
131 int		dlmgmt_generate_name(const char *, char *, size_t, zoneid_t);
132 
133 void		dlmgmt_linktable_init(void);
134 void		dlmgmt_linktable_fini(void);
135 
136 int		dlmgmt_zone_init(zoneid_t);
137 int		dlmgmt_elevate_privileges(void);
138 int		dlmgmt_drop_privileges();
139 void		dlmgmt_handler(void *, char *, size_t, door_desc_t *, uint_t);
140 void		dlmgmt_log(int, const char *, ...);
141 int		dlmgmt_write_db_entry(const char *, dlmgmt_link_t *, uint32_t);
142 int		dlmgmt_delete_db_entry(dlmgmt_link_t *, uint32_t);
143 int 		dlmgmt_db_init(zoneid_t);
144 void		dlmgmt_db_fini(zoneid_t);
145 
146 #ifdef  __cplusplus
147 }
148 #endif
149 
150 #endif	/* _DLMGMT_IMPL_H */
151