xref: /illumos-gate/usr/src/cmd/dlmgmtd/dlmgmt_impl.h (revision 6a634c9d)
1d62bc4baSyz /*
2d62bc4baSyz  * CDDL HEADER START
3d62bc4baSyz  *
4d62bc4baSyz  * The contents of this file are subject to the terms of the
5d62bc4baSyz  * Common Development and Distribution License (the "License").
6d62bc4baSyz  * You may not use this file except in compliance with the License.
7d62bc4baSyz  *
8d62bc4baSyz  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9d62bc4baSyz  * or http://www.opensolaris.org/os/licensing.
10d62bc4baSyz  * See the License for the specific language governing permissions
11d62bc4baSyz  * and limitations under the License.
12d62bc4baSyz  *
13d62bc4baSyz  * When distributing Covered Code, include this CDDL HEADER in each
14d62bc4baSyz  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15d62bc4baSyz  * If applicable, add the following below this CDDL HEADER, with the
16d62bc4baSyz  * fields enclosed by brackets "[]" replaced with your own identifying
17d62bc4baSyz  * information: Portions Copyright [yyyy] [name of copyright owner]
18d62bc4baSyz  *
19d62bc4baSyz  * CDDL HEADER END
20d62bc4baSyz  */
21d62bc4baSyz 
22d62bc4baSyz /*
23*32715170SCathy Zhou  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24d62bc4baSyz  */
25d62bc4baSyz 
26d62bc4baSyz /*
27d62bc4baSyz  * Functions to maintain a table of datalink configuration information.
28d62bc4baSyz  */
29d62bc4baSyz 
30d62bc4baSyz #ifndef	_DLMGMT_IMPL_H
31d62bc4baSyz #define	_DLMGMT_IMPL_H
32d62bc4baSyz 
33d62bc4baSyz #ifdef  __cplusplus
34d62bc4baSyz extern "C" {
35d62bc4baSyz #endif
36d62bc4baSyz 
37d62bc4baSyz #include <door.h>
38d62bc4baSyz #include <libdllink.h>
3982a2fc47SJames Carlson #include <sys/avl.h>
40d62bc4baSyz 
41d62bc4baSyz /*
42d62bc4baSyz  * datalink attribute structure
43d62bc4baSyz  */
44d62bc4baSyz typedef struct dlmgmt_linkattr_s {
45d62bc4baSyz 	struct dlmgmt_linkattr_s	*lp_next;
46d62bc4baSyz 	struct dlmgmt_linkattr_s	*lp_prev;
47d62bc4baSyz 	char				lp_name[MAXLINKATTRLEN];
48d62bc4baSyz 	void				*lp_val;
49d62bc4baSyz 	dladm_datatype_t		lp_type;
50d62bc4baSyz 	uint_t				lp_sz;
5162ee1d25SArtem Kachitchkine 	boolean_t			lp_linkprop;
52d62bc4baSyz } dlmgmt_linkattr_t;
53d62bc4baSyz 
54d62bc4baSyz /*
55d62bc4baSyz  * datalink structure
56d62bc4baSyz  */
57d62bc4baSyz typedef struct dlmgmt_link_s {
58d62bc4baSyz 	dlmgmt_linkattr_t	*ll_head;
59d62bc4baSyz 	char			ll_link[MAXLINKNAMELEN];
60d62bc4baSyz 	datalink_class_t	ll_class;
61d62bc4baSyz 	uint32_t		ll_media;
62d62bc4baSyz 	datalink_id_t		ll_linkid;
632b24ab6bSSebastien Roy 	zoneid_t		ll_zoneid;
642b24ab6bSSebastien Roy 	boolean_t		ll_onloan;
652b24ab6bSSebastien Roy 	avl_node_t		ll_name_node;
662b24ab6bSSebastien Roy 	avl_node_t		ll_id_node;
672b24ab6bSSebastien Roy 	avl_node_t		ll_loan_node;
68d62bc4baSyz 	uint32_t		ll_flags;
69d62bc4baSyz 	uint32_t		ll_gen;		/* generation number */
70d62bc4baSyz } dlmgmt_link_t;
71d62bc4baSyz 
72d62bc4baSyz /*
73d62bc4baSyz  * datalink configuration request structure
74d62bc4baSyz  */
75d62bc4baSyz typedef struct dlmgmt_dlconf_s {
76d62bc4baSyz 	dlmgmt_linkattr_t	*ld_head;
77d62bc4baSyz 	char			ld_link[MAXLINKNAMELEN];
78d62bc4baSyz 	datalink_id_t		ld_linkid;
79d62bc4baSyz 	datalink_class_t	ld_class;
80d62bc4baSyz 	uint32_t		ld_media;
81d62bc4baSyz 	int			ld_id;
822b24ab6bSSebastien Roy 	zoneid_t		ld_zoneid;
83d62bc4baSyz 	uint32_t		ld_gen;
84d62bc4baSyz 	avl_node_t		ld_node;
85d62bc4baSyz } dlmgmt_dlconf_t;
86d62bc4baSyz 
87d62bc4baSyz extern boolean_t	debug;
88d62bc4baSyz extern const char	*progname;
892b24ab6bSSebastien Roy extern char		cachefile[];
904ac67f02SAnurag S. Maskey extern dladm_handle_t	dld_handle;
912b24ab6bSSebastien Roy extern datalink_id_t	dlmgmt_nextlinkid;
92d62bc4baSyz extern avl_tree_t	dlmgmt_name_avl;
93d62bc4baSyz extern avl_tree_t	dlmgmt_id_avl;
942b24ab6bSSebastien Roy extern avl_tree_t	dlmgmt_loan_avl;
95d62bc4baSyz extern avl_tree_t	dlmgmt_dlconf_avl;
96d62bc4baSyz 
97d62bc4baSyz boolean_t	linkattr_equal(dlmgmt_linkattr_t **, const char *, void *,
98d62bc4baSyz 		    size_t);
992b24ab6bSSebastien Roy dlmgmt_linkattr_t *linkattr_find(dlmgmt_linkattr_t *, const char *);
1002b24ab6bSSebastien Roy void		linkattr_unset(dlmgmt_linkattr_t **, const char *);
101d62bc4baSyz int		linkattr_set(dlmgmt_linkattr_t **, const char *, void *,
102d62bc4baSyz 		    size_t, dladm_datatype_t);
103d62bc4baSyz int		linkattr_get(dlmgmt_linkattr_t **, const char *, void **,
104d62bc4baSyz 		    size_t *, dladm_datatype_t *);
105*32715170SCathy Zhou void		linkattr_destroy(dlmgmt_link_t *);
106d62bc4baSyz 
107d62bc4baSyz void		link_destroy(dlmgmt_link_t *);
1082b24ab6bSSebastien Roy int		link_activate(dlmgmt_link_t *);
1092b24ab6bSSebastien Roy boolean_t	link_is_visible(dlmgmt_link_t *, zoneid_t);
1102b24ab6bSSebastien Roy dlmgmt_link_t	*link_by_id(datalink_id_t, zoneid_t);
1112b24ab6bSSebastien Roy dlmgmt_link_t	*link_by_name(const char *, zoneid_t);
112d62bc4baSyz int		dlmgmt_create_common(const char *, datalink_class_t,
1132b24ab6bSSebastien Roy 		    uint32_t, zoneid_t, uint32_t, dlmgmt_link_t **);
114d62bc4baSyz int		dlmgmt_destroy_common(dlmgmt_link_t *, uint32_t);
1152b24ab6bSSebastien Roy int		dlmgmt_getattr_common(dlmgmt_linkattr_t **, const char *,
116024b0a25Sseb 		    dlmgmt_getattr_retval_t *);
117d62bc4baSyz 
118d62bc4baSyz void		dlmgmt_advance(dlmgmt_link_t *);
119d62bc4baSyz void		dlmgmt_table_lock(boolean_t);
120d62bc4baSyz void		dlmgmt_table_unlock();
121d62bc4baSyz 
122d62bc4baSyz int		dlconf_create(const char *, datalink_id_t, datalink_class_t,
1232b24ab6bSSebastien Roy 		    uint32_t, zoneid_t, dlmgmt_dlconf_t **);
124d62bc4baSyz void		dlconf_destroy(dlmgmt_dlconf_t *);
125d62bc4baSyz void		dlmgmt_advance_dlconfid(dlmgmt_dlconf_t *);
126d62bc4baSyz void		dlmgmt_dlconf_table_lock(boolean_t);
127d62bc4baSyz void		dlmgmt_dlconf_table_unlock(void);
128d62bc4baSyz 
1292b24ab6bSSebastien Roy int		dlmgmt_generate_name(const char *, char *, size_t, zoneid_t);
130d62bc4baSyz 
1312b24ab6bSSebastien Roy void		dlmgmt_linktable_init(void);
132d62bc4baSyz void		dlmgmt_linktable_fini(void);
133d62bc4baSyz 
1342b24ab6bSSebastien Roy int		dlmgmt_zone_init(zoneid_t);
1352b24ab6bSSebastien Roy int		dlmgmt_elevate_privileges(void);
1362b24ab6bSSebastien Roy int		dlmgmt_drop_privileges();
137d62bc4baSyz void		dlmgmt_handler(void *, char *, size_t, door_desc_t *, uint_t);
138d62bc4baSyz void		dlmgmt_log(int, const char *, ...);
1392b24ab6bSSebastien Roy int		dlmgmt_write_db_entry(const char *, dlmgmt_link_t *, uint32_t);
1402b24ab6bSSebastien Roy int		dlmgmt_delete_db_entry(dlmgmt_link_t *, uint32_t);
1412b24ab6bSSebastien Roy int 		dlmgmt_db_init(zoneid_t);
1422b24ab6bSSebastien Roy void		dlmgmt_db_fini(zoneid_t);
143b9e076dcSyz 
144d62bc4baSyz #ifdef  __cplusplus
145d62bc4baSyz }
146d62bc4baSyz #endif
147d62bc4baSyz 
148d62bc4baSyz #endif	/* _DLMGMT_IMPL_H */
149