5 * The contents of this file are subject to the terms of the
6 * Common Development and Distribution License (the "License").
7 * You may not use this file except in compliance with the License.
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.
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]
24 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
25 * Use is subject to license terms.
26 * Copyright (c) 2016, Chris Fraire <cfraire@me.com>.
31 #include <sys/types.h>
33 #include "nwamcfg_grammar.tab.h"
35 int lex_lineno = 1; /* line number for error reporting */
36 static int state = INITIAL;
37 extern boolean_t cmd_file_mode;
39 extern void yyerror(char *s);
40 char *safe_strdup(char *s);
51 * The state below are for tokens.
57 <INITIAL>"#"[^\n]* { }
156 <TSTATE>[Ll][Oo][Cc] { return LOC; }
157 <TSTATE>[Nn][Cc][Pp] { return NCP; }
158 <TSTATE>[Ee][Nn][Mm] { return ENM; }
159 <TSTATE>[Ww][Ll][Aa][Nn] { return WLAN; }
161 <TSTATE>[Nn][Cc][Uu] { return NCU; }
163 <TSTATE>[Pp][Hh][Yy][Ss] { return PHYS; }
164 <TSTATE>[Ii][Pp] { return IP; }
166 <TSTATE>unknown { return UNKNOWN; }
167 <TSTATE>activation-mode { return ACTIVATION_MODE; }
168 <TSTATE>conditions { return CONDITIONS; }
169 <TSTATE>enabled { return ENABLED; }
171 <TSTATE>type { return TYPE; }
172 <TSTATE>class { return CLASS; }
173 <TSTATE>parent { return PARENT; }
174 <TSTATE>priority-group { return PRIORITY_GROUP; }
175 <TSTATE>priority-mode { return PRIORITY_MODE; }
176 <TSTATE>link-mac-addr { return LINK_MACADDR; }
177 <TSTATE>link-autopush { return LINK_AUTOPUSH; }
178 <TSTATE>link-mtu { return LINK_MTU; }
179 <TSTATE>ip-version { return IP_VERSION; }
180 <TSTATE>ipv4-addrsrc { return IPV4_ADDRSRC; }
181 <TSTATE>ipv4-addr { return IPV4_ADDR; }
182 <TSTATE>ipv4-default-route { return IPV4_DEFAULT_ROUTE; }
183 <TSTATE>ipv6-addrsrc { return IPV6_ADDRSRC; }
184 <TSTATE>ipv6-addr { return IPV6_ADDR; }
185 <TSTATE>ipv6-default-route { return IPV6_DEFAULT_ROUTE; }
186 <TSTATE>ip-primary { return IP_PRIMARY; }
187 <TSTATE>ip-reqhost { return IP_REQHOST; }
189 <TSTATE>state { return ENM_STATE; }
190 <TSTATE>fmri { return ENM_FMRI; }
191 <TSTATE>start { return ENM_START; }
192 <TSTATE>stop { return ENM_STOP; }
194 <TSTATE>nameservices { return LOC_NAMESERVICES; }
195 <TSTATE>nameservices-config-file { return LOC_NAMESERVICES_CONFIG; }
196 <TSTATE>dns-nameservice-configsrc { return LOC_DNS_CONFIGSRC; }
197 <TSTATE>dns-nameservice-domain { return LOC_DNS_DOMAIN; }
198 <TSTATE>dns-nameservice-servers { return LOC_DNS_SERVERS; }
199 <TSTATE>dns-nameservice-search { return LOC_DNS_SEARCH; }
200 <TSTATE>nis-nameservice-configsrc { return LOC_NIS_CONFIGSRC; }
201 <TSTATE>nis-nameservice-servers { return LOC_NIS_SERVERS; }
202 <TSTATE>ldap-nameservice-configsrc { return LOC_LDAP_CONFIGSRC; }
203 <TSTATE>ldap-nameservice-servers { return LOC_LDAP_SERVERS; }
204 <TSTATE>default-domain { return LOC_DEFAULT_DOMAIN; }
205 <TSTATE>nfsv4-domain { return LOC_NFSV4_DOMAIN; }
206 <TSTATE>ipfilter-config-file { return LOC_IPF_CONFIG; }
207 <TSTATE>ipfilter-v6-config-file { return LOC_IPF_V6_CONFIG; }
208 <TSTATE>ipnat-config-file { return LOC_IPNAT_CONFIG; }
209 <TSTATE>ippool-config-file { return LOC_IPPOOL_CONFIG; }
210 <TSTATE>ike-config-file { return LOC_IKE_CONFIG; }
211 <TSTATE>ipsecpolicy-config-file { return LOC_IPSECPOL_CONFIG; }
213 <TSTATE>bssids { return WLAN_BSSIDS; }
214 <TSTATE>priority { return WLAN_PRIORITY; }
215 <TSTATE>keyname { return WLAN_KEYNAME; }
216 <TSTATE>keyslot { return WLAN_KEYSLOT; }
217 <TSTATE>security-mode { return WLAN_SECURITY_MODE; }
219 <TSTATE>= { return EQUAL; }
221 <TSTATE>\-[adftV] { /* matches options */
222 yylval.strval = safe_strdup(yytext);
226 <TSTATE>[^ \t\n\";=\[\]\(\)]+ { /* matches non-quoted values */
227 yylval.strval = safe_strdup(yytext);
231 <TSTATE>\"[^\"\n]*[\"\n] { /* matches string with quotes */
232 yylval.strval = safe_strdup(yytext);
236 <TSTATE>\".*\"\,\".*\" { /* matches string list of the form "a","b",.. */
237 yylval.strval = safe_strdup(yytext);
252 [ \t] ; /* ignore white space */
254 . { /* matches all single otherwise unmatched characters */
265 if ((result = strdup(s)) == NULL) {
266 yyerror("Out of memory");
275 /* feof(yyin) is not an error; anything else is, so we set saw_error */
276 if (yytext[0] == '\0') {
279 (void) fprintf(stderr, gettext("%s, token expected\n"),
287 (void) fprintf(stderr, gettext("%s on line %d at '%s'\n"), s,
288 lex_lineno, (yytext[0] == '\n') ? "\\n" : yytext);
290 (void) fprintf(stderr, gettext("%s at '%s'\n\n"), s,
291 (yytext[0] == '\n') ? "\\n" : yytext);