xref: /titanic_51/usr/src/lib/libdladm/common/libdladm_impl.h (revision 65908c77dfc02644236ba18bffe67b5ed6f23135)
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  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _LIBDLADM_IMPL_H
27 #define	_LIBDLADM_IMPL_H
28 
29 #include <libdladm.h>
30 #include <stdio.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #define	MAXLINELEN		1024
37 #define	BUFLEN(lim, ptr)	(((lim) > (ptr)) ? ((lim) - (ptr)) : 0)
38 
39 /*
40  * The handle contains file descriptors to DLD_CONTROL_DEV and
41  * DLMGMT_DOOR.  Rather than opening the file descriptor each time
42  * it is required, the handle is opened by consumers of libdladm
43  * (e.g., dladm) and then passed to libdladm.
44  */
45 struct dladm_handle {
46 	int dld_fd;	/* file descriptor to DLD_CONTROL_DEV */
47 	int door_fd;	/* file descriptor to DLMGMT_DOOR */
48 };
49 
50 /* DLMGMT_DOOR can only be accessed by libdladm and dlmgmtd */
51 extern dladm_status_t	dladm_door_fd(dladm_handle_t, int *);
52 
53 extern dladm_status_t	dladm_errno2status(int);
54 extern dladm_status_t   i_dladm_rw_db(dladm_handle_t, const char *, mode_t,
55 			    dladm_status_t (*)(dladm_handle_t, void *, FILE *,
56 			    FILE *), void *, boolean_t);
57 extern dladm_status_t	i_dladm_get_state(dladm_handle_t, datalink_id_t,
58 			    link_state_t *);
59 
60 extern const char	*dladm_pri2str(mac_priority_level_t, char *);
61 extern dladm_status_t	dladm_str2pri(char *, mac_priority_level_t *);
62 extern dladm_status_t	dladm_parse_args(char *, dladm_arg_list_t **,
63 			    boolean_t);
64 extern void		dladm_free_args(dladm_arg_list_t *);
65 
66 /*
67  * Link attributes persisted by dlmgmtd.
68  */
69 /*
70  * Set for VLANs only
71  */
72 #define	FVLANID		"vid"		/* uint64_t */
73 #define	FLINKOVER	"linkover"	/* uint64_t */
74 
75 /*
76  * Set for AGGRs only
77  */
78 #define	FKEY		"key"		/* uint64_t */
79 #define	FNPORTS		"nports"	/* uint64_t */
80 #define	FPORTS		"portnames"	/* string */
81 #define	FPOLICY		"policy"	/* uint64_t */
82 #define	FFIXMACADDR	"fix_macaddr"	/* boolean_t */
83 #define	FFORCE		"force"		/* boolean_t */
84 #define	FLACPMODE	"lacp_mode"	/* uint64_t */
85 #define	FLACPTIMER	"lacp_timer"	/* uint64_t */
86 
87 /*
88  * Set for VNICs only
89  */
90 #define	FMADDRTYPE	"maddrtype"	/* uint64_t */
91 #define	FMADDRLEN	"maddrlen"	/* uint64_t */
92 #define	FMADDRSLOT	"maddrslot"	/* uint64_t */
93 #define	FMADDRPREFIXLEN	"maddrpreflen"	/* uint64_t */
94 #define	FHWRINGS	"hwrings"	/* boolean_t */
95 
96 /*
97  * Set for simlinks only
98  */
99 #define	FSIMNETTYPE	"simnettype"	/* uint64_t */
100 #define	FSIMNETPEER	"simnetpeer"	/* uint64_t */
101 
102 /*
103  * Common fields
104  */
105 #define	FMACADDR	"macaddr"	/* string */
106 
107 /*
108  * List of all the above attributes.
109  */
110 #define	DLADM_ATTR_NAMES	FVLANID, FLINKOVER, \
111 				FKEY, FNPORTS, FPORTS, FPOLICY, \
112 				FFIXMACADDR, FFORCE, FLACPMODE, FLACPTIMER, \
113 				FMADDRTYPE, FMADDRLEN, FMADDRSLOT, \
114 				FMADDRPREFIXLEN, FHWRINGS, \
115 				FMACADDR, FSIMNETTYPE, FSIMNETPEER
116 
117 /*
118  * Data structures used for implementing temporary properties
119  */
120 
121 typedef struct val_desc {
122 	char		*vd_name;
123 	uintptr_t	vd_val;
124 } val_desc_t;
125 
126 #define	VALCNT(vals)	(sizeof ((vals)) / sizeof (val_desc_t))
127 
128 extern dladm_status_t	dladm_link_proplist_extract(dladm_handle_t,
129 			    dladm_arg_list_t *, mac_resource_props_t *);
130 
131 extern dladm_status_t	dladm_flow_proplist_extract(dladm_arg_list_t *,
132 			    mac_resource_props_t *);
133 
134 /*
135  * The prop extract() callback.
136  *
137  * rp_extract extracts the kernel structure from the val_desc_t created
138  * by the pd_check function.
139  */
140 typedef	dladm_status_t	rp_extractf_t(val_desc_t *propval, void *arg,
141 				uint_t cnt);
142 extern rp_extractf_t	do_extract_maxbw, do_extract_priority,
143 			do_extract_cpus;
144 
145 typedef struct resource_prop_s {
146 	/*
147 	 * resource property name
148 	 */
149 	char		*rp_name;
150 
151 	/*
152 	 * callback to extract kernel structure
153 	 */
154 	rp_extractf_t	*rp_extract;
155 } resource_prop_t;
156 
157 #ifdef	__cplusplus
158 }
159 #endif
160 
161 #endif	/* _LIBDLADM_IMPL_H */
162