1/*	$KAME: lexer.l,v 1.7 2000/11/08 02:40:53 itojun Exp $	*/
2
3/*-
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 *    notice, this list of conditions and the following disclaimer in the
16 *    documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 *    may be used to endorse or promote products derived from this software
19 *    without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34%{
35#include <sys/param.h>
36#include <sys/ioctl.h>
37#include <sys/socket.h>
38#include <sys/queue.h>
39
40#include <string.h>
41
42#include <net/if.h>
43#include <netinet/in.h>
44#include <netinet/in_var.h>
45#include <netinet/icmp6.h>
46
47#include <arpa/inet.h>
48
49#include "y.tab.h"
50
51int lineno = 1;
52
53#define LINEBUF_SIZE 1000
54char linebuf[LINEBUF_SIZE];
55
56int parse(FILE **);
57void yyerror(const char *);
58int yylex(void);
59%}
60
61%option noyywrap
62%option nounput
63
64/* common section */
65nl		\n
66ws		[ \t]+
67digit		[0-9]
68letter		[0-9A-Za-z]
69hexdigit	[0-9A-Fa-f]
70special		[()+\|\?\*,]
71dot		\.
72hyphen		\-
73colon		\:
74slash		\/
75bcl		\{
76ecl		\}
77semi		\;
78usec		{dot}{digit}{1,6}
79comment		\#.*
80qstring		\"[^"]*\"
81decstring	{digit}+
82hexpair		{hexdigit}{hexdigit}
83hexstring	0[xX]{hexdigit}+
84octetstring	{octet}({dot}{octet})+
85ipv4addr	{digit}{1,3}({dot}{digit}{1,3}){0,3}
86ipv6addr	{hexdigit}{0,4}({colon}{hexdigit}{0,4}){2,7}
87ipaddrmask	{slash}{digit}{1,3}
88keyword		{letter}{letter}+
89name		{letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
90hostname	{name}(({dot}{name})+{dot}?)?
91
92timeval		{digit}{0,2}
93days		d{timeval}
94hours		h{timeval}
95minutes		m{timeval}
96seconds		s{timeval}
97
98mprefix		match_prefix|match-prefix
99uprefix		use_prefix|use-prefix
100
101%%
102	/* rrenumd keywords */
103debug		{
104			return(DEBUG_CMD);
105		}
106dest		{
107			return(DEST_CMD);
108		}
109retry		{
110			return(RETRY_CMD);
111		}
112seqnum		{
113			return(SEQNUM_CMD);
114		}
115add		{
116			yylval.num = RPM_PCO_ADD;
117			return(ADD);
118		}
119change		{
120			yylval.num = RPM_PCO_CHANGE;
121			return(CHANGE);
122		 }
123setglobal	{
124			yylval.num = RPM_PCO_SETGLOBAL;
125			return(SETGLOBAL);
126		}
127{mprefix}	{
128			return(MATCH_PREFIX_CMD);
129		}
130maxlen		{
131			return(MAXLEN_CMD);
132		}
133minlen		{
134			return(MINLEN_CMD);
135		}
136{uprefix}	{
137			return(USE_PREFIX_CMD);
138		}
139keeplen		{
140			return(KEEPLEN_CMD);
141		}
142
143vltime		{
144			return(VLTIME_CMD);
145		}
146pltime		{
147			return(PLTIME_CMD);
148		}
149raf_onlink	{
150			return(RAF_ONLINK_CMD);
151		}
152raf_auto	{
153			return(RAF_AUTO_CMD);
154		}
155rrf_decrvalid	{
156			return(RAF_DECRVALID_CMD);
157		}
158rrf_decrprefd	{
159			return(RAF_DECRPREFD_CMD);
160		}
161{days}		{
162			yytext++;
163			yylval.num = atoi(yytext);
164			return(DAYS);
165		}
166{hours}		{
167			yytext++;
168			yylval.num = atoi(yytext);
169			return(HOURS);
170		}
171{minutes}	{
172			yytext++;
173			yylval.num = atoi(yytext);
174			return(MINUTES);
175		}
176{seconds}	{
177			yytext++;
178			yylval.num = atoi(yytext);
179			return(SECONDS);
180		}
181infinity	{
182			return(INFINITY);
183		}
184
185on		{
186			yylval.num = 1;
187			return(ON);
188		}
189off		{
190			yylval.num = 0;
191			return(OFF);
192		}
193
194	/* basic rules */
195{ws}		;
196{nl}		{
197			lineno++;
198		}
199{semi}		{
200			return EOS;
201		}
202{bcl}		{
203			return BCL;
204		}
205{ecl}		{
206			return ECL;
207		}
208{qstring}	{
209			yylval.cs.cp = yytext;
210			yylval.cs.len = yyleng;
211			return QSTRING;
212		}
213{decstring}	{
214			yylval.cs.cp = yytext;
215			yylval.cs.len = yyleng;
216			return DECSTRING;
217		}
218{name}		{
219			yylval.cs.cp = yytext;
220			yylval.cs.len = yyleng;
221			return NAME;
222		}
223{ipv4addr}	{
224			memset(&yylval.addr4, 0, sizeof(struct in_addr));
225			if (inet_pton(AF_INET, yytext,
226				      &yylval.addr4) == 1) {
227				return IPV4ADDR;
228			} else {
229				return ERROR;
230			}
231		}
232{ipv6addr}	{
233			memset(&yylval.addr6, 0, sizeof(struct in6_addr));
234			if (inet_pton(AF_INET6, yytext,
235				      &yylval.addr6) == 1) {
236				return IPV6ADDR;
237			} else {
238				return ERROR;
239			}
240		}
241{ipaddrmask}	{
242			yytext++;
243			yylval.num = atoi(yytext);
244			return(PREFIXLEN);
245		}
246{hostname}	{
247			yylval.cs.cp = yytext;
248			yylval.cs.len = yyleng;
249			return HOSTNAME;
250		}
251%%
252
253int parse(FILE **fp)
254{
255	extern int yyparse(void);
256
257	yyin = *fp;
258
259	if (yyparse())
260		return(-1);
261
262	return(0);
263
264}
265
266void
267yyerror(const char *s)
268{
269	printf("%s: at %s in line %d\n", s, yytext, lineno);
270}
271