xref: /titanic_44/usr/src/lib/libdhcputil/common/dhcp_symbol.h (revision 786d1eec1cd1cac7e26243d118cd209e84bc6bb9)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5d04ccbb3Scarlsonj  * Common Development and Distribution License (the "License").
6d04ccbb3Scarlsonj  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*786d1eecSBart Coddens  * Copyright 2014 Garrett D'Amore <garrett@damore.org>
23*786d1eecSBart Coddens  *
24d04ccbb3Scarlsonj  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #ifndef	_DHCP_SYMBOL_H
297c478bd9Sstevel@tonic-gate #define	_DHCP_SYMBOL_H
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * This file, along with <dhcp_symbol_common.h>, contains the DHCP symbol
337c478bd9Sstevel@tonic-gate  * constants and the definitions for the external interfaces to the parsing
347c478bd9Sstevel@tonic-gate  * logic (contained in dhcp_symbol.c) for symbol definitions. These
357c478bd9Sstevel@tonic-gate  * definitions can and should be used by all consumers of DHCP symbols.
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <sys/types.h>
397c478bd9Sstevel@tonic-gate #include <dhcp_symbol_common.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Vendor class length (and implicitly, the number of classes)
477c478bd9Sstevel@tonic-gate  */
48*786d1eecSBart Coddens #define	DSYM_CLASS_SIZE		128			/* Single class max */
497c478bd9Sstevel@tonic-gate #define	DSYM_MAX_CLASS_SIZE	(DSYM_CLASS_SIZE * 10)	/* At least 10 */
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
52*786d1eecSBart Coddens  * Maximum symbol length
537c478bd9Sstevel@tonic-gate  */
54*786d1eecSBart Coddens #define	DSYM_MAX_SYM_LEN	128
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * symbol parsing error codes
587c478bd9Sstevel@tonic-gate  */
597c478bd9Sstevel@tonic-gate typedef enum {
607c478bd9Sstevel@tonic-gate 	DSYM_SUCCESS,
617c478bd9Sstevel@tonic-gate 	DSYM_SYNTAX_ERROR,
627c478bd9Sstevel@tonic-gate 	DSYM_NULL_FIELD,
637c478bd9Sstevel@tonic-gate 	DSYM_TOO_MANY_FIELDS,
647c478bd9Sstevel@tonic-gate 	DSYM_CODE_OUT_OF_RANGE,
657c478bd9Sstevel@tonic-gate 	DSYM_VALUE_OUT_OF_RANGE,
667c478bd9Sstevel@tonic-gate 	DSYM_INVALID_CAT,
677c478bd9Sstevel@tonic-gate 	DSYM_INVALID_TYPE,
687c478bd9Sstevel@tonic-gate 	DSYM_EXCEEDS_CLASS_SIZE,
697c478bd9Sstevel@tonic-gate 	DSYM_EXCEEDS_MAX_CLASS_SIZE,
707c478bd9Sstevel@tonic-gate 	DSYM_NO_MEMORY,
717c478bd9Sstevel@tonic-gate 	DSYM_INVALID_FIELD_NUM
727c478bd9Sstevel@tonic-gate } dsym_errcode_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * symbol fields
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate #define	DSYM_CAT_FIELD		0
787c478bd9Sstevel@tonic-gate #define	DSYM_CODE_FIELD		1
797c478bd9Sstevel@tonic-gate #define	DSYM_TYPE_FIELD		2
807c478bd9Sstevel@tonic-gate #define	DSYM_GRAN_FIELD		3
817c478bd9Sstevel@tonic-gate #define	DSYM_MAX_FIELD		4
827c478bd9Sstevel@tonic-gate #define	DSYM_NUM_FIELDS		5
837c478bd9Sstevel@tonic-gate #define	DSYM_FIRST_FIELD	DSYM_CAT_FIELD
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate /*
867c478bd9Sstevel@tonic-gate  * This structure is used by the dhcp_symbol_t structure below
877c478bd9Sstevel@tonic-gate  * when the option being defined is a vendor option. In which case,
887c478bd9Sstevel@tonic-gate  * this structure contains the client classes for which the option
897c478bd9Sstevel@tonic-gate  * applies.
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate typedef struct dhcp_classes {
927c478bd9Sstevel@tonic-gate 	char		**dc_names;
937c478bd9Sstevel@tonic-gate 	uint8_t		dc_cnt;
947c478bd9Sstevel@tonic-gate } dhcp_classes_t;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * This structure is used to define a DHCP symbol. The structure is
987c478bd9Sstevel@tonic-gate  * used by both the inittab parsing routines and by the dhcptab parsing
997c478bd9Sstevel@tonic-gate  * routines to define a symbol definition in either of those tables.
100d04ccbb3Scarlsonj  * Note that ds_dhcpv6 is defined last so that it needn't be initialized
101d04ccbb3Scarlsonj  * as part of the inittab_table[] definition.
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate typedef struct dhcp_symbol {
1047c478bd9Sstevel@tonic-gate 	dsym_category_t	ds_category;			/* category */
1057c478bd9Sstevel@tonic-gate 	ushort_t	ds_code;			/* option code */
1067c478bd9Sstevel@tonic-gate 	char		ds_name[DSYM_MAX_SYM_LEN + 1];	/* option name */
1077c478bd9Sstevel@tonic-gate 	dsym_cdtype_t	ds_type;			/* type of parm */
1087c478bd9Sstevel@tonic-gate 	uchar_t		ds_gran;			/* granularity */
1097c478bd9Sstevel@tonic-gate 	uchar_t		ds_max;				/* maximum number */
1107c478bd9Sstevel@tonic-gate 	dhcp_classes_t	ds_classes;			/* client classes */
111d04ccbb3Scarlsonj 	uchar_t		ds_dhcpv6;			/* dhcpv6 flag */
1127c478bd9Sstevel@tonic-gate } dhcp_symbol_t;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate extern void dsym_free_fields(char **);
1157c478bd9Sstevel@tonic-gate extern void dsym_free_classes(dhcp_classes_t *);
1167c478bd9Sstevel@tonic-gate extern void dsym_close_parser(char **, dhcp_symbol_t *);
1177c478bd9Sstevel@tonic-gate extern dsym_errcode_t dsym_init_parser(const char *, const char *, char ***,
1187c478bd9Sstevel@tonic-gate     dhcp_symbol_t *);
1197c478bd9Sstevel@tonic-gate extern dsym_errcode_t dsym_parse_field(int, char **, dhcp_symbol_t *);
1207c478bd9Sstevel@tonic-gate extern dsym_errcode_t dsym_parser(char **, dhcp_symbol_t *, int *, boolean_t);
1217c478bd9Sstevel@tonic-gate extern dsym_errcode_t dsym_get_cat_id(const char *, dsym_category_t *,
1227c478bd9Sstevel@tonic-gate     boolean_t);
1237c478bd9Sstevel@tonic-gate extern dsym_errcode_t dsym_get_code_ranges(const char *cat, ushort_t *,
1247c478bd9Sstevel@tonic-gate     ushort_t *, boolean_t);
1257c478bd9Sstevel@tonic-gate extern dsym_errcode_t dsym_get_type_id(const char *, dsym_cdtype_t *,
1267c478bd9Sstevel@tonic-gate     boolean_t);
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1297c478bd9Sstevel@tonic-gate }
1307c478bd9Sstevel@tonic-gate #endif
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate #endif	/* _DHCP_SYMBOL_H */
133