11573Srgrimes/*	$KAME: lexer.l,v 1.7 2000/11/08 02:40:53 itojun Exp $	*/
21573Srgrimes
31573Srgrimes/*
41573Srgrimes * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
51573Srgrimes * All rights reserved.
61573Srgrimes *
71573Srgrimes * Redistribution and use in source and binary forms, with or without
81573Srgrimes * modification, are permitted provided that the following conditions
91573Srgrimes * are met:
101573Srgrimes * 1. Redistributions of source code must retain the above copyright
111573Srgrimes *    notice, this list of conditions and the following disclaimer.
121573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
131573Srgrimes *    notice, this list of conditions and the following disclaimer in the
141573Srgrimes *    documentation and/or other materials provided with the distribution.
151573Srgrimes * 3. Neither the name of the project nor the names of its contributors
161573Srgrimes *    may be used to endorse or promote products derived from this software
171573Srgrimes *    without specific prior written permission.
181573Srgrimes *
191573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
201573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
211573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
221573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
231573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
241573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
251573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
261573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
271573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
281573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
291573Srgrimes * SUCH DAMAGE.
301573Srgrimes *
311573Srgrimes * $FreeBSD: releng/11.0/usr.sbin/rrenumd/lexer.l 281143 2015-04-06 09:42:23Z glebius $
321573Srgrimes */
331573Srgrimes
341573Srgrimes%{
351573Srgrimes#include <sys/param.h>
3690039Sobrien#include <sys/ioctl.h>
3790039Sobrien#include <sys/socket.h>
381573Srgrimes#include <sys/queue.h>
3971579Sdeischen
401573Srgrimes#include <string.h>
411573Srgrimes
421573Srgrimes#include <net/if.h>
438870Srgrimes#include <netinet/in.h>
441573Srgrimes#include <netinet/in_var.h>
451573Srgrimes#include <netinet/icmp6.h>
461573Srgrimes
471573Srgrimes#include <arpa/inet.h>
481573Srgrimes
491573Srgrimes#include "y.tab.h"
5071579Sdeischen
511573Srgrimesint lineno = 1;
5271579Sdeischen
5371579Sdeischen#define LINEBUF_SIZE 1000
541573Srgrimeschar linebuf[LINEBUF_SIZE];
551573Srgrimes
561573Srgrimesint parse(FILE **);
571573Srgrimesvoid yyerror(const char *);
581573Srgrimesint yylex(void);
591573Srgrimes%}
601573Srgrimes
611573Srgrimes%option nounput
621573Srgrimes
631573Srgrimes/* common section */
641573Srgrimesnl		\n
651573Srgrimesws		[ \t]+
661573Srgrimesdigit		[0-9]
671573Srgrimesletter		[0-9A-Za-z]
68108312Salfredhexdigit	[0-9A-Fa-f]
6992941Sobrienspecial		[()+\|\?\*,]
7090039Sobriendot		\.
711573Srgrimeshyphen		\-
721573Srgrimescolon		\:
731573Srgrimesslash		\/
741573Srgrimesbcl		\{
751573Srgrimesecl		\}
761573Srgrimessemi		\;
771573Srgrimesusec		{dot}{digit}{1,6}
7892925Simpcomment		\#.*
791573Srgrimesqstring		\"[^"]*\"
801573Srgrimesdecstring	{digit}+
811573Srgrimeshexpair		{hexdigit}{hexdigit}
821573Srgrimeshexstring	0[xX]{hexdigit}+
831573Srgrimesoctetstring	{octet}({dot}{octet})+
841573Srgrimesipv4addr	{digit}{1,3}({dot}{digit}{1,3}){0,3}
851573Srgrimesipv6addr	{hexdigit}{0,4}({colon}{hexdigit}{0,4}){2,7}
861573Srgrimesipaddrmask	{slash}{digit}{1,3}
871573Srgrimeskeyword		{letter}{letter}+
881573Srgrimesname		{letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
891573Srgrimeshostname	{name}(({dot}{name})+{dot}?)?
901573Srgrimes
911573Srgrimestimeval		{digit}{0,2}
921573Srgrimesdays		d{timeval}
931573Srgrimeshours		h{timeval}
941573Srgrimesminutes		m{timeval}
951573Srgrimesseconds		s{timeval}
961573Srgrimes
971573Srgrimesmprefix		match_prefix|match-prefix
981573Srgrimesuprefix		use_prefix|use-prefix
991573Srgrimes
1001573Srgrimes%%
1011573Srgrimes	/* rrenumd keywords */
1021573Srgrimesdebug		{
1031573Srgrimes			return(DEBUG_CMD);
1041573Srgrimes		}
1051573Srgrimesdest		{
1061573Srgrimes			return(DEST_CMD);
1071573Srgrimes		}
1081573Srgrimesretry		{
1091573Srgrimes			return(RETRY_CMD);
11092925Simp		}
1111573Srgrimesseqnum		{
11292941Sobrien			return(SEQNUM_CMD);
11392941Sobrien		}
1141573Srgrimesadd		{
1151573Srgrimes			yylval.num = RPM_PCO_ADD;
1161573Srgrimes			return(ADD);
1171573Srgrimes		}
1181573Srgrimeschange		{
1191573Srgrimes			yylval.num = RPM_PCO_CHANGE;
1201573Srgrimes			return(CHANGE);
1211573Srgrimes		 }
1221573Srgrimessetglobal	{
1231573Srgrimes			yylval.num = RPM_PCO_SETGLOBAL;
1241573Srgrimes			return(SETGLOBAL);
1251573Srgrimes		}
1261573Srgrimes{mprefix}	{
1271573Srgrimes			return(MATCH_PREFIX_CMD);
1281573Srgrimes		}
1291573Srgrimesmaxlen		{
1301573Srgrimes			return(MAXLEN_CMD);
1311573Srgrimes		}
1321573Srgrimesminlen		{
1331573Srgrimes			return(MINLEN_CMD);
1341573Srgrimes		}
1351573Srgrimes{uprefix}	{
1361573Srgrimes			return(USE_PREFIX_CMD);
1371573Srgrimes		}
1381573Srgrimeskeeplen		{
1391573Srgrimes			return(KEEPLEN_CMD);
1401573Srgrimes		}
1411573Srgrimes
1421573Srgrimesvltime		{
1431573Srgrimes			return(VLTIME_CMD);
1441573Srgrimes		}
1451573Srgrimespltime		{
1461573Srgrimes			return(PLTIME_CMD);
1471573Srgrimes		}
1481573Srgrimesraf_onlink	{
1491573Srgrimes			return(RAF_ONLINK_CMD);
1501573Srgrimes		}
1511573Srgrimesraf_auto	{
1521573Srgrimes			return(RAF_AUTO_CMD);
1531573Srgrimes		}
1541573Srgrimesrrf_decrvalid	{
1551573Srgrimes			return(RAF_DECRVALID_CMD);
1561573Srgrimes		}
1571573Srgrimesrrf_decrprefd	{
1581573Srgrimes			return(RAF_DECRPREFD_CMD);
1591573Srgrimes		}
1601573Srgrimes{days}		{
16192925Simp			yytext++;
1621573Srgrimes			yylval.num = atoi(yytext);
1631573Srgrimes			return(DAYS);
1641573Srgrimes		}
1651573Srgrimes{hours}		{
1661573Srgrimes			yytext++;
1671573Srgrimes			yylval.num = atoi(yytext);
1681573Srgrimes			return(HOURS);
1691573Srgrimes		}
1701573Srgrimes{minutes}	{
1711573Srgrimes			yytext++;
1721573Srgrimes			yylval.num = atoi(yytext);
1731573Srgrimes			return(MINUTES);
1741573Srgrimes		}
1751573Srgrimes{seconds}	{
1761573Srgrimes			yytext++;
1771573Srgrimes			yylval.num = atoi(yytext);
1781573Srgrimes			return(SECONDS);
1791573Srgrimes		}
1801573Srgrimesinfinity	{
1811573Srgrimes			return(INFINITY);
1821573Srgrimes		}
1831573Srgrimes
1841573Srgrimeson		{
1851573Srgrimes			yylval.num = 1;
1861573Srgrimes			return(ON);
18792941Sobrien		}
18892941Sobrienoff		{
1891573Srgrimes			yylval.num = 0;
1901573Srgrimes			return(OFF);
19190039Sobrien		}
192190661Sdelphij
1931573Srgrimes	/* basic rules */
1941573Srgrimes{ws}		;
1951573Srgrimes{nl}		{
1968870Srgrimes			lineno++;
1971573Srgrimes		}
1981573Srgrimes{semi}		{
1991573Srgrimes			return EOS;
2001573Srgrimes		}
2011573Srgrimes{bcl}		{
2021573Srgrimes			return BCL;
2031573Srgrimes		}
2041573Srgrimes{ecl}		{
2051573Srgrimes			return ECL;
2061573Srgrimes		}
2071573Srgrimes{qstring}	{
2081573Srgrimes			yylval.cs.cp = yytext;
2091573Srgrimes			yylval.cs.len = yyleng;
2101573Srgrimes			return QSTRING;
2111573Srgrimes		}
2121573Srgrimes{decstring}	{
2131573Srgrimes			yylval.cs.cp = yytext;
2141573Srgrimes			yylval.cs.len = yyleng;
2151573Srgrimes			return DECSTRING;
2161573Srgrimes		}
2171573Srgrimes{name}		{
2181573Srgrimes			yylval.cs.cp = yytext;
2191573Srgrimes			yylval.cs.len = yyleng;
2201573Srgrimes			return NAME;
2211573Srgrimes		}
2221573Srgrimes{ipv4addr}	{
2231573Srgrimes			memset(&yylval.addr4, 0, sizeof(struct in_addr));
2241573Srgrimes			if (inet_pton(AF_INET, yytext,
2251573Srgrimes				      &yylval.addr4) == 1) {
2261573Srgrimes				return IPV4ADDR;
2271573Srgrimes			} else {
2281573Srgrimes				return ERROR;
2291573Srgrimes			}
2301573Srgrimes		}
2311573Srgrimes{ipv6addr}	{
2321573Srgrimes			memset(&yylval.addr6, 0, sizeof(struct in6_addr));
2331573Srgrimes			if (inet_pton(AF_INET6, yytext,
2341573Srgrimes				      &yylval.addr6) == 1) {
2351573Srgrimes				return IPV6ADDR;
2361573Srgrimes			} else {
2371573Srgrimes				return ERROR;
2381573Srgrimes			}
2391573Srgrimes		}
24030713Sjdp{ipaddrmask}	{
2411573Srgrimes			yytext++;
2421573Srgrimes			yylval.num = atoi(yytext);
2431573Srgrimes			return(PREFIXLEN);
2441573Srgrimes		}
2451573Srgrimes{hostname}	{
2461573Srgrimes			yylval.cs.cp = yytext;
2471573Srgrimes			yylval.cs.len = yyleng;
2481573Srgrimes			return HOSTNAME;
2491573Srgrimes		}
2501573Srgrimes%%
2511573Srgrimes
2521573Srgrimesint parse(FILE **fp)
2531573Srgrimes{
254190661Sdelphij	extern int yyparse(void);
2551573Srgrimes
2561573Srgrimes	yyin = *fp;
2571573Srgrimes
2581573Srgrimes	if (yyparse())
259190661Sdelphij		return(-1);
260190661Sdelphij
261190661Sdelphij	return(0);
262190661Sdelphij
263192129Sdelphij}
2641573Srgrimes
2651573Srgrimesvoid
2661573Srgrimesyyerror(const char *s)
267261813Sjilles{
26844921Simp	printf("%s: at %s in line %d\n", s, yytext, lineno);
26944921Simp}
2701573Srgrimes