xref: /titanic_51/usr/src/lib/libdladm/common/libdladm_impl.h (revision db3659e514c8bf3f03bcca6dd082e363bd7b466a)
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 2008 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  * Common fields
98  */
99 #define	FMACADDR	"macaddr"	/* string */
100 
101 /*
102  * List of all the above attributes.
103  */
104 #define	DLADM_ATTR_NAMES	FVLANID, FLINKOVER, \
105 				FKEY, FNPORTS, FPORTS, FPOLICY, \
106 				FFIXMACADDR, FFORCE, FLACPMODE, FLACPTIMER, \
107 				FMADDRTYPE, FMADDRLEN, FMADDRSLOT, \
108 				FMADDRPREFIXLEN, FHWRINGS, \
109 				FMACADDR
110 
111 /*
112  * Data structures used for implementing temporary properties
113  */
114 
115 typedef struct val_desc {
116 	char		*vd_name;
117 	uintptr_t	vd_val;
118 } val_desc_t;
119 
120 #define	VALCNT(vals)	(sizeof ((vals)) / sizeof (val_desc_t))
121 
122 extern dladm_status_t	dladm_link_proplist_extract(dladm_handle_t,
123 			    dladm_arg_list_t *, mac_resource_props_t *);
124 
125 extern dladm_status_t	dladm_flow_proplist_extract(dladm_arg_list_t *,
126 			    mac_resource_props_t *);
127 
128 /*
129  * The prop extract() callback.
130  *
131  * rp_extract extracts the kernel structure from the val_desc_t created
132  * by the pd_check function.
133  */
134 typedef	dladm_status_t	rp_extractf_t(val_desc_t *propval, void *arg,
135 				uint_t cnt);
136 extern rp_extractf_t	do_extract_maxbw, do_extract_priority,
137 			do_extract_cpus;
138 
139 typedef struct resource_prop_s {
140 	/*
141 	 * resource property name
142 	 */
143 	char		*rp_name;
144 
145 	/*
146 	 * callback to extract kernel structure
147 	 */
148 	rp_extractf_t	*rp_extract;
149 } resource_prop_t;
150 
151 #ifdef	__cplusplus
152 }
153 #endif
154 
155 #endif	/* _LIBDLADM_IMPL_H */
156