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