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 _LIBDLFLOW_IMPL_H
27 #define	_LIBDLFLOW_IMPL_H
28 
29 #include <sys/types.h>
30 #include <sys/param.h>
31 #include <sys/mac.h>
32 #include <libdladm.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 struct fprop_desc;
39 struct fattr_desc;
40 
41 typedef	dladm_status_t	fpd_getf_t(dladm_handle_t, const char *, char **,
42 			    uint_t *);
43 typedef	dladm_status_t	fpd_setf_t(dladm_handle_t, const char *, val_desc_t *,
44 			    uint_t);
45 typedef	dladm_status_t	fpd_checkf_t(struct fprop_desc *, char **, uint_t,
46 			    val_desc_t **);
47 
48 typedef struct fprop_desc {
49 	char		*pd_name;
50 	val_desc_t	pd_defval;
51 	val_desc_t	*pd_modval;
52 	uint_t		pd_nmodval;
53 	boolean_t	pd_temponly;
54 	fpd_setf_t	*pd_set;
55 	fpd_getf_t	*pd_getmod;
56 	fpd_getf_t	*pd_get;
57 	fpd_checkf_t	*pd_check;
58 } fprop_desc_t;
59 
60 typedef struct prop_table {
61 	fprop_desc_t	*pt_table;
62 	uint_t		pt_size;
63 } prop_table_t;
64 
65 typedef enum {
66 	DLADM_PROP_VAL_CURRENT = 1,
67 	DLADM_PROP_VAL_DEFAULT,
68 	DLADM_PROP_VAL_MODIFIABLE,
69 	DLADM_PROP_VAL_PERSISTENT
70 } prop_type_t;
71 
72 typedef	dladm_status_t	fad_checkf_t(char *, flow_desc_t *);
73 
74 extern dladm_status_t	do_check_ip_addr(char *, boolean_t, flow_desc_t *);
75 extern dladm_status_t	do_check_dsfield(char *, flow_desc_t *);
76 
77 typedef struct fattr_desc {
78 	const char	*ad_name;
79 	fad_checkf_t	*ad_check;
80 } fattr_desc_t;
81 
82 extern dladm_status_t	i_dladm_get_prop_temp(dladm_handle_t, const char *,
83 			    prop_type_t, const char *, char **, uint_t *,
84 			    prop_table_t *);
85 extern dladm_status_t	i_dladm_set_prop_temp(dladm_handle_t, const char *,
86 			    const char *, char **, uint_t, uint_t, char **,
87 			    prop_table_t *);
88 extern boolean_t	i_dladm_is_prop_temponly(const char *prop_name,
89 			    char **, prop_table_t *);
90 /*
91  * Data structures used for implementing persistent properties
92  */
93 typedef struct prop_val {
94 	const char		*lv_name;
95 	struct prop_val		*lv_nextval;
96 } prop_val_t;
97 
98 typedef struct prop_db_info {
99 	const char		*li_name;
100 	struct prop_db_info	*li_nextprop;
101 	struct prop_val		*li_val;
102 } prop_db_info_t;
103 
104 typedef struct prop_db_state	prop_db_state_t;
105 
106 typedef boolean_t (*prop_db_op_t)(dladm_handle_t, prop_db_state_t *,
107     char *, prop_db_info_t *, dladm_status_t *);
108 
109 typedef dladm_status_t (*prop_db_initop_t)(dladm_handle_t, const char *,
110     const char *, char **, uint_t, uint_t, char **);
111 
112 struct prop_db_state {
113 	prop_db_op_t		ls_op;
114 	const char		*ls_name;
115 	const char		*ls_propname;
116 	char			**ls_propval;
117 	uint_t			*ls_valcntp;
118 	prop_db_initop_t	ls_initop;
119 };
120 
121 extern boolean_t	process_prop_set(dladm_handle_t, prop_db_state_t *lsp,
122 			    char *buf, prop_db_info_t *listp,
123 			    dladm_status_t *statusp);
124 extern boolean_t	process_prop_get(dladm_handle_t, prop_db_state_t *lsp,
125 			    char *buf, prop_db_info_t *listp,
126 			    dladm_status_t *statusp);
127 extern boolean_t	process_prop_init(dladm_handle_t, prop_db_state_t *lsp,
128 			    char *buf, prop_db_info_t *listp,
129 			    dladm_status_t *statusp);
130 extern dladm_status_t	process_prop_db(dladm_handle_t, void *arg, FILE *fp,
131 			    FILE *nfp);
132 
133 extern dladm_status_t	i_dladm_init_flowprop_db(dladm_handle_t);
134 extern dladm_status_t	i_dladm_set_flow_proplist_db(dladm_handle_t, char *,
135 			    dladm_arg_list_t *);
136 extern dladm_status_t	i_dladm_flow_check_restriction(datalink_id_t,
137 			    flow_desc_t *, mac_resource_props_t *, boolean_t);
138 
139 extern dladm_status_t	dladm_flow_attrlist_extract(dladm_arg_list_t *,
140 			    flow_desc_t *);
141 
142 #ifdef	__cplusplus
143 }
144 #endif
145 
146 #endif	/* _LIBDLFLOW_IMPL_H */
147