xref: /titanic_50/usr/src/lib/libdhcputil/common/dhcp_symbol.h (revision c77a61a72b5ecdc507d6cf104142edd371a16c84)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2001-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_DHCP_SYMBOL_H
28 #define	_DHCP_SYMBOL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * This file, along with <dhcp_symbol_common.h>, contains the DHCP symbol
34  * constants and the definitions for the external interfaces to the parsing
35  * logic (contained in dhcp_symbol.c) for symbol definitions. These
36  * definitions can and should be used by all consumers of DHCP symbols.
37  */
38 
39 #include <sys/types.h>
40 #include <dhcp_svc_private.h>
41 #include <dhcp_symbol_common.h>
42 
43 #ifdef	__cplusplus
44 extern "C" {
45 #endif
46 
47 /*
48  * Vendor class length (and implicitly, the number of classes)
49  */
50 #define	DSYM_CLASS_SIZE		DSVC_MAX_MACSYM_LEN	/* Single class max */
51 #define	DSYM_MAX_CLASS_SIZE	(DSYM_CLASS_SIZE * 10)	/* At least 10 */
52 
53 /*
54  * Maximum symbol length is defined by the libdhcpsvc.
55  */
56 #define	DSYM_MAX_SYM_LEN	DSVC_MAX_MACSYM_LEN
57 
58 /*
59  * symbol parsing error codes
60  */
61 typedef enum {
62 	DSYM_SUCCESS,
63 	DSYM_SYNTAX_ERROR,
64 	DSYM_NULL_FIELD,
65 	DSYM_TOO_MANY_FIELDS,
66 	DSYM_CODE_OUT_OF_RANGE,
67 	DSYM_VALUE_OUT_OF_RANGE,
68 	DSYM_INVALID_CAT,
69 	DSYM_INVALID_TYPE,
70 	DSYM_EXCEEDS_CLASS_SIZE,
71 	DSYM_EXCEEDS_MAX_CLASS_SIZE,
72 	DSYM_NO_MEMORY,
73 	DSYM_INVALID_FIELD_NUM
74 } dsym_errcode_t;
75 
76 /*
77  * symbol fields
78  */
79 #define	DSYM_CAT_FIELD		0
80 #define	DSYM_CODE_FIELD		1
81 #define	DSYM_TYPE_FIELD		2
82 #define	DSYM_GRAN_FIELD		3
83 #define	DSYM_MAX_FIELD		4
84 #define	DSYM_NUM_FIELDS		5
85 #define	DSYM_FIRST_FIELD	DSYM_CAT_FIELD
86 
87 /*
88  * This structure is used by the dhcp_symbol_t structure below
89  * when the option being defined is a vendor option. In which case,
90  * this structure contains the client classes for which the option
91  * applies.
92  */
93 typedef struct dhcp_classes {
94 	char		**dc_names;
95 	uint8_t		dc_cnt;
96 } dhcp_classes_t;
97 
98 /*
99  * This structure is used to define a DHCP symbol. The structure is
100  * used by both the inittab parsing routines and by the dhcptab parsing
101  * routines to define a symbol definition in either of those tables.
102  */
103 typedef struct dhcp_symbol {
104 	dsym_category_t	ds_category;			/* category */
105 	ushort_t	ds_code;			/* option code */
106 	char		ds_name[DSYM_MAX_SYM_LEN + 1];	/* option name */
107 	dsym_cdtype_t	ds_type;			/* type of parm */
108 	uchar_t		ds_gran;			/* granularity */
109 	uchar_t		ds_max;				/* maximum number */
110 	dhcp_classes_t	ds_classes;			/* client classes */
111 } dhcp_symbol_t;
112 
113 extern void dsym_free_fields(char **);
114 extern void dsym_free_classes(dhcp_classes_t *);
115 extern void dsym_close_parser(char **, dhcp_symbol_t *);
116 extern dsym_errcode_t dsym_init_parser(const char *, const char *, char ***,
117     dhcp_symbol_t *);
118 extern dsym_errcode_t dsym_parse_field(int, char **, dhcp_symbol_t *);
119 extern dsym_errcode_t dsym_parser(char **, dhcp_symbol_t *, int *, boolean_t);
120 extern dsym_errcode_t dsym_get_cat_id(const char *, dsym_category_t *,
121     boolean_t);
122 extern dsym_errcode_t dsym_get_code_ranges(const char *cat, ushort_t *,
123     ushort_t *, boolean_t);
124 extern dsym_errcode_t dsym_get_type_id(const char *, dsym_cdtype_t *,
125     boolean_t);
126 
127 #ifdef	__cplusplus
128 }
129 #endif
130 
131 #endif	/* _DHCP_SYMBOL_H */
132