xref: /illumos-gate/usr/src/cmd/dlmgmtd/dlmgmt_impl.h (revision 024b0a25)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Functions to maintain a table of datalink configuration information.
31  */
32 
33 #ifndef	_DLMGMT_IMPL_H
34 #define	_DLMGMT_IMPL_H
35 
36 #ifdef  __cplusplus
37 extern "C" {
38 #endif
39 
40 #include <door.h>
41 #include <libdllink.h>
42 
43 /*
44  * datalink attribute structure
45  */
46 typedef struct dlmgmt_linkattr_s {
47 	struct dlmgmt_linkattr_s	*lp_next;
48 	struct dlmgmt_linkattr_s	*lp_prev;
49 	char				lp_name[MAXLINKATTRLEN];
50 	void				*lp_val;
51 	dladm_datatype_t		lp_type;
52 	uint_t				lp_sz;
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 	avl_node_t		ll_node_by_name;
65 	avl_node_t		ll_node_by_id;
66 	uint32_t		ll_flags;
67 	uint32_t		ll_gen;		/* generation number */
68 } dlmgmt_link_t;
69 
70 /*
71  * datalink configuration request structure
72  */
73 typedef struct dlmgmt_dlconf_s {
74 	dlmgmt_linkattr_t	*ld_head;
75 	char			ld_link[MAXLINKNAMELEN];
76 	datalink_id_t		ld_linkid;
77 	datalink_class_t	ld_class;
78 	uint32_t		ld_media;
79 	int			ld_id;
80 	uint32_t		ld_gen;
81 	avl_node_t		ld_node;
82 } dlmgmt_dlconf_t;
83 
84 extern boolean_t	debug;
85 extern const char	*progname;
86 
87 extern avl_tree_t	dlmgmt_name_avl;
88 extern avl_tree_t	dlmgmt_id_avl;
89 extern avl_tree_t	dlmgmt_dlconf_avl;
90 
91 boolean_t	linkattr_equal(dlmgmt_linkattr_t **, const char *, void *,
92 		    size_t);
93 int		linkattr_unset(dlmgmt_linkattr_t **, const char *);
94 int		linkattr_set(dlmgmt_linkattr_t **, const char *, void *,
95 		    size_t, dladm_datatype_t);
96 int		linkattr_get(dlmgmt_linkattr_t **, const char *, void **,
97 		    size_t *, dladm_datatype_t *);
98 
99 void		link_destroy(dlmgmt_link_t *);
100 dlmgmt_link_t	*link_by_id(datalink_id_t);
101 dlmgmt_link_t	*link_by_name(const char *);
102 int		dlmgmt_create_common(const char *, datalink_class_t,
103 		    uint32_t, uint32_t, dlmgmt_link_t **);
104 int		dlmgmt_destroy_common(dlmgmt_link_t *, uint32_t);
105 void		dlmgmt_getattr_common(dlmgmt_linkattr_t **, const char *,
106 		    dlmgmt_getattr_retval_t *);
107 
108 void		dlmgmt_advance(dlmgmt_link_t *);
109 void		dlmgmt_table_lock(boolean_t);
110 void		dlmgmt_table_unlock();
111 
112 int		dlconf_create(const char *, datalink_id_t, datalink_class_t,
113 		    uint32_t, dlmgmt_dlconf_t **);
114 void		dlconf_destroy(dlmgmt_dlconf_t *);
115 void		dlmgmt_advance_dlconfid(dlmgmt_dlconf_t *);
116 void		dlmgmt_dlconf_table_lock(boolean_t);
117 void		dlmgmt_dlconf_table_unlock(void);
118 
119 int		dlmgmt_generate_name(const char *, char *, size_t);
120 
121 int		dlmgmt_linktable_init(void);
122 void		dlmgmt_linktable_fini(void);
123 
124 void		dlmgmt_handler(void *, char *, size_t, door_desc_t *, uint_t);
125 void		dlmgmt_log(int, const char *, ...);
126 int		dlmgmt_write_db_entry(datalink_id_t, uint32_t);
127 int		dlmgmt_delete_db_entry(datalink_id_t, uint32_t);
128 int 		dlmgmt_db_init(void);
129 
130 #define	DLMGMT_TMPFS_DIR	"/etc/svc/volatile/dladm"
131 
132 #ifdef  __cplusplus
133 }
134 #endif
135 
136 #endif	/* _DLMGMT_IMPL_H */
137