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