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