xref: /freebsd/usr.sbin/rrenumd/lexer.l (revision 9a4365d0e0833374e893c519639bde71756aa104)
19a4365d0SYoshinobu Inoue /*
29a4365d0SYoshinobu Inoue  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
39a4365d0SYoshinobu Inoue  * All rights reserved.
49a4365d0SYoshinobu Inoue  *
59a4365d0SYoshinobu Inoue  * Redistribution and use in source and binary forms, with or without
69a4365d0SYoshinobu Inoue  * modification, are permitted provided that the following conditions
79a4365d0SYoshinobu Inoue  * are met:
89a4365d0SYoshinobu Inoue  * 1. Redistributions of source code must retain the above copyright
99a4365d0SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer.
109a4365d0SYoshinobu Inoue  * 2. Redistributions in binary form must reproduce the above copyright
119a4365d0SYoshinobu Inoue  *    notice, this list of conditions and the following disclaimer in the
129a4365d0SYoshinobu Inoue  *    documentation and/or other materials provided with the distribution.
139a4365d0SYoshinobu Inoue  * 3. Neither the name of the project nor the names of its contributors
149a4365d0SYoshinobu Inoue  *    may be used to endorse or promote products derived from this software
159a4365d0SYoshinobu Inoue  *    without specific prior written permission.
169a4365d0SYoshinobu Inoue  *
179a4365d0SYoshinobu Inoue  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
189a4365d0SYoshinobu Inoue  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199a4365d0SYoshinobu Inoue  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209a4365d0SYoshinobu Inoue  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
219a4365d0SYoshinobu Inoue  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
229a4365d0SYoshinobu Inoue  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
239a4365d0SYoshinobu Inoue  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
249a4365d0SYoshinobu Inoue  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
259a4365d0SYoshinobu Inoue  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
269a4365d0SYoshinobu Inoue  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
279a4365d0SYoshinobu Inoue  * SUCH DAMAGE.
289a4365d0SYoshinobu Inoue  *
299a4365d0SYoshinobu Inoue  * $FreeBSD$
309a4365d0SYoshinobu Inoue  */
319a4365d0SYoshinobu Inoue 
329a4365d0SYoshinobu Inoue %{
339a4365d0SYoshinobu Inoue #include <sys/param.h>
349a4365d0SYoshinobu Inoue #include <sys/ioctl.h>
359a4365d0SYoshinobu Inoue #include <sys/socket.h>
369a4365d0SYoshinobu Inoue 
379a4365d0SYoshinobu Inoue #include <string.h>
389a4365d0SYoshinobu Inoue 
399a4365d0SYoshinobu Inoue #include <net/if.h>
409a4365d0SYoshinobu Inoue #include <net/if_var.h>
419a4365d0SYoshinobu Inoue 
429a4365d0SYoshinobu Inoue #include <netinet/in.h>
439a4365d0SYoshinobu Inoue #include <netinet/in_var.h>
449a4365d0SYoshinobu Inoue #include <netinet/icmp6.h>
459a4365d0SYoshinobu Inoue #include "y.tab.h"
469a4365d0SYoshinobu Inoue 
479a4365d0SYoshinobu Inoue int lineno = 1;
489a4365d0SYoshinobu Inoue 
499a4365d0SYoshinobu Inoue #define	LINEBUF_SIZE 1000
509a4365d0SYoshinobu Inoue char linebuf[LINEBUF_SIZE];
519a4365d0SYoshinobu Inoue %}
529a4365d0SYoshinobu Inoue 
539a4365d0SYoshinobu Inoue /* common section */
549a4365d0SYoshinobu Inoue nl		\n
559a4365d0SYoshinobu Inoue ws		[ \t]+
569a4365d0SYoshinobu Inoue digit		[0-9]
579a4365d0SYoshinobu Inoue letter		[0-9A-Za-z]
589a4365d0SYoshinobu Inoue hexdigit	[0-9A-Fa-f]
599a4365d0SYoshinobu Inoue special		[()+\|\?\*,]
609a4365d0SYoshinobu Inoue dot		\.
619a4365d0SYoshinobu Inoue hyphen		\-
629a4365d0SYoshinobu Inoue colon		\:
639a4365d0SYoshinobu Inoue slash		\/
649a4365d0SYoshinobu Inoue bcl		\{
659a4365d0SYoshinobu Inoue ecl		\}
669a4365d0SYoshinobu Inoue semi		\;
679a4365d0SYoshinobu Inoue usec		{dot}{digit}{1,6}
689a4365d0SYoshinobu Inoue comment		\#.*
699a4365d0SYoshinobu Inoue qstring		\"[^"]*\"
709a4365d0SYoshinobu Inoue decstring	{digit}+
719a4365d0SYoshinobu Inoue hexpair		{hexdigit}{hexdigit}
729a4365d0SYoshinobu Inoue hexstring	0[xX]{hexdigit}+
739a4365d0SYoshinobu Inoue octetstring	{octet}({dot}{octet})+
749a4365d0SYoshinobu Inoue ipv4addr	{digit}{1,3}({dot}{digit}{1,3}){0,3}
759a4365d0SYoshinobu Inoue ipv6addr	{hexdigit}{0,4}({colon}{hexdigit}{0,4}){2,7}
769a4365d0SYoshinobu Inoue ipaddrmask	{slash}{digit}{1,3}
779a4365d0SYoshinobu Inoue keyword		{letter}{letter}+
789a4365d0SYoshinobu Inoue name		{letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
799a4365d0SYoshinobu Inoue hostname	{name}(({dot}{name})+{dot}?)?
809a4365d0SYoshinobu Inoue 
819a4365d0SYoshinobu Inoue timeval		{digit}{0,2}
829a4365d0SYoshinobu Inoue days		d{timeval}
839a4365d0SYoshinobu Inoue hours		h{timeval}
849a4365d0SYoshinobu Inoue minutes		m{timeval}
859a4365d0SYoshinobu Inoue seconds		s{timeval}
869a4365d0SYoshinobu Inoue 
879a4365d0SYoshinobu Inoue mprefix		match_prefix|match-prefix
889a4365d0SYoshinobu Inoue uprefix		use_prefix|use-prefix
899a4365d0SYoshinobu Inoue 
909a4365d0SYoshinobu Inoue %%
919a4365d0SYoshinobu Inoue 	/* rrenumd keywords */
929a4365d0SYoshinobu Inoue debug		{
939a4365d0SYoshinobu Inoue 			return(DEBUG_CMD);
949a4365d0SYoshinobu Inoue 		}
959a4365d0SYoshinobu Inoue dest		{
969a4365d0SYoshinobu Inoue 			return(DEST_CMD);
979a4365d0SYoshinobu Inoue 		}
989a4365d0SYoshinobu Inoue retry		{
999a4365d0SYoshinobu Inoue 			return(RETRY_CMD);
1009a4365d0SYoshinobu Inoue 		}
1019a4365d0SYoshinobu Inoue seqnum		{
1029a4365d0SYoshinobu Inoue 			return(SEQNUM_CMD);
1039a4365d0SYoshinobu Inoue 		}
1049a4365d0SYoshinobu Inoue add		{
1059a4365d0SYoshinobu Inoue 			yylval.num = RPM_PCO_ADD;
1069a4365d0SYoshinobu Inoue 			return(ADD);
1079a4365d0SYoshinobu Inoue 		}
1089a4365d0SYoshinobu Inoue change		{
1099a4365d0SYoshinobu Inoue 			yylval.num = RPM_PCO_CHANGE;
1109a4365d0SYoshinobu Inoue 			return(CHANGE);
1119a4365d0SYoshinobu Inoue 		 }
1129a4365d0SYoshinobu Inoue setglobal	{
1139a4365d0SYoshinobu Inoue 			yylval.num = RPM_PCO_SETGLOBAL;
1149a4365d0SYoshinobu Inoue 			return(SETGLOBAL);
1159a4365d0SYoshinobu Inoue 		}
1169a4365d0SYoshinobu Inoue {mprefix}	{
1179a4365d0SYoshinobu Inoue 			return(MATCH_PREFIX_CMD);
1189a4365d0SYoshinobu Inoue 		}
1199a4365d0SYoshinobu Inoue maxlen		{
1209a4365d0SYoshinobu Inoue 			return(MAXLEN_CMD);
1219a4365d0SYoshinobu Inoue 		}
1229a4365d0SYoshinobu Inoue minlen		{
1239a4365d0SYoshinobu Inoue 			return(MINLEN_CMD);
1249a4365d0SYoshinobu Inoue 		}
1259a4365d0SYoshinobu Inoue {uprefix}	{
1269a4365d0SYoshinobu Inoue 			return(USE_PREFIX_CMD);
1279a4365d0SYoshinobu Inoue 		}
1289a4365d0SYoshinobu Inoue keeplen		{
1299a4365d0SYoshinobu Inoue 			return(KEEPLEN_CMD);
1309a4365d0SYoshinobu Inoue 		}
1319a4365d0SYoshinobu Inoue 
1329a4365d0SYoshinobu Inoue vltime		{
1339a4365d0SYoshinobu Inoue 			return(VLTIME_CMD);
1349a4365d0SYoshinobu Inoue 		}
1359a4365d0SYoshinobu Inoue pltime		{
1369a4365d0SYoshinobu Inoue 			return(PLTIME_CMD);
1379a4365d0SYoshinobu Inoue 		}
1389a4365d0SYoshinobu Inoue raf_onlink	{
1399a4365d0SYoshinobu Inoue 			return(RAF_ONLINK_CMD);
1409a4365d0SYoshinobu Inoue 		}
1419a4365d0SYoshinobu Inoue raf_auto	{
1429a4365d0SYoshinobu Inoue 			return(RAF_AUTO_CMD);
1439a4365d0SYoshinobu Inoue 		}
1449a4365d0SYoshinobu Inoue rrf_decrvalid	{
1459a4365d0SYoshinobu Inoue 			return(RAF_DECRVALID_CMD);
1469a4365d0SYoshinobu Inoue 		}
1479a4365d0SYoshinobu Inoue rrf_decrprefd	{
1489a4365d0SYoshinobu Inoue 			return(RAF_DECRPREFD_CMD);
1499a4365d0SYoshinobu Inoue 		}
1509a4365d0SYoshinobu Inoue {days}		{
1519a4365d0SYoshinobu Inoue 			yytext++;
1529a4365d0SYoshinobu Inoue 			yylval.num = atoi(yytext);
1539a4365d0SYoshinobu Inoue 			return(DAYS);
1549a4365d0SYoshinobu Inoue 		}
1559a4365d0SYoshinobu Inoue {hours}		{
1569a4365d0SYoshinobu Inoue 			yytext++;
1579a4365d0SYoshinobu Inoue 			yylval.num = atoi(yytext);
1589a4365d0SYoshinobu Inoue 			return(HOURS);
1599a4365d0SYoshinobu Inoue 		}
1609a4365d0SYoshinobu Inoue {minutes}	{
1619a4365d0SYoshinobu Inoue 			yytext++;
1629a4365d0SYoshinobu Inoue 			yylval.num = atoi(yytext);
1639a4365d0SYoshinobu Inoue 			return(MINUTES);
1649a4365d0SYoshinobu Inoue 		}
1659a4365d0SYoshinobu Inoue {seconds}	{
1669a4365d0SYoshinobu Inoue 			yytext++;
1679a4365d0SYoshinobu Inoue 			yylval.num = atoi(yytext);
1689a4365d0SYoshinobu Inoue 			return(SECONDS);
1699a4365d0SYoshinobu Inoue 		}
1709a4365d0SYoshinobu Inoue infinity	{
1719a4365d0SYoshinobu Inoue 			return(INFINITY);
1729a4365d0SYoshinobu Inoue 		}
1739a4365d0SYoshinobu Inoue 
1749a4365d0SYoshinobu Inoue on		{
1759a4365d0SYoshinobu Inoue 			yylval.num = 1;
1769a4365d0SYoshinobu Inoue 			return(ON);
1779a4365d0SYoshinobu Inoue 		}
1789a4365d0SYoshinobu Inoue off		{
1799a4365d0SYoshinobu Inoue 			yylval.num = 0;
1809a4365d0SYoshinobu Inoue 			return(OFF);
1819a4365d0SYoshinobu Inoue 		}
1829a4365d0SYoshinobu Inoue 
1839a4365d0SYoshinobu Inoue 	/* basic rules */
1849a4365d0SYoshinobu Inoue {ws}		;
1859a4365d0SYoshinobu Inoue {nl}		{
1869a4365d0SYoshinobu Inoue 			lineno++;
1879a4365d0SYoshinobu Inoue 		}
1889a4365d0SYoshinobu Inoue {semi}		{
1899a4365d0SYoshinobu Inoue 			return EOS;
1909a4365d0SYoshinobu Inoue 		}
1919a4365d0SYoshinobu Inoue {bcl}		{
1929a4365d0SYoshinobu Inoue 			return BCL;
1939a4365d0SYoshinobu Inoue 		}
1949a4365d0SYoshinobu Inoue {ecl}		{
1959a4365d0SYoshinobu Inoue 			return ECL;
1969a4365d0SYoshinobu Inoue 		}
1979a4365d0SYoshinobu Inoue {qstring}	{
1989a4365d0SYoshinobu Inoue 			yylval.cs.cp = yytext;
1999a4365d0SYoshinobu Inoue 			yylval.cs.len = yyleng;
2009a4365d0SYoshinobu Inoue 			return QSTRING;
2019a4365d0SYoshinobu Inoue 		}
2029a4365d0SYoshinobu Inoue {decstring}	{
2039a4365d0SYoshinobu Inoue 			yylval.cs.cp = yytext;
2049a4365d0SYoshinobu Inoue 			yylval.cs.len = yyleng;
2059a4365d0SYoshinobu Inoue 			return DECSTRING;
2069a4365d0SYoshinobu Inoue 		}
2079a4365d0SYoshinobu Inoue {name}		{
2089a4365d0SYoshinobu Inoue 			yylval.cs.cp = yytext;
2099a4365d0SYoshinobu Inoue 			yylval.cs.len = yyleng;
2109a4365d0SYoshinobu Inoue 			return NAME;
2119a4365d0SYoshinobu Inoue 		}
2129a4365d0SYoshinobu Inoue {ipv6addr}	{
2139a4365d0SYoshinobu Inoue 			memset(&yylval.addr6, 0, sizeof(struct in6_addr));
2149a4365d0SYoshinobu Inoue 			if (inet_pton(AF_INET6, yytext,
2159a4365d0SYoshinobu Inoue 				      &yylval.addr6) == 1) {
2169a4365d0SYoshinobu Inoue 				return IPV6ADDR;
2179a4365d0SYoshinobu Inoue 			} else {
2189a4365d0SYoshinobu Inoue 				return ERROR;
2199a4365d0SYoshinobu Inoue 			}
2209a4365d0SYoshinobu Inoue 		}
2219a4365d0SYoshinobu Inoue {ipaddrmask}	{
2229a4365d0SYoshinobu Inoue 			yytext++;
2239a4365d0SYoshinobu Inoue 			yylval.num = atoi(yytext);
2249a4365d0SYoshinobu Inoue 			return(PREFIXLEN);
2259a4365d0SYoshinobu Inoue 		}
2269a4365d0SYoshinobu Inoue {hostname}	{
2279a4365d0SYoshinobu Inoue 			yylval.cs.cp = yytext;
2289a4365d0SYoshinobu Inoue 			yylval.cs.len = yyleng;
2299a4365d0SYoshinobu Inoue 			return HOSTNAME;
2309a4365d0SYoshinobu Inoue 		}
2319a4365d0SYoshinobu Inoue %%
2329a4365d0SYoshinobu Inoue 
2339a4365d0SYoshinobu Inoue int parse(FILE **fp)
2349a4365d0SYoshinobu Inoue {
2359a4365d0SYoshinobu Inoue 	yyin = *fp;
2369a4365d0SYoshinobu Inoue 
2379a4365d0SYoshinobu Inoue 	if(yyparse())
2389a4365d0SYoshinobu Inoue 		return(-1);
2399a4365d0SYoshinobu Inoue 
2409a4365d0SYoshinobu Inoue 	return(0);
2419a4365d0SYoshinobu Inoue 
2429a4365d0SYoshinobu Inoue }
2439a4365d0SYoshinobu Inoue 
2449a4365d0SYoshinobu Inoue void
2459a4365d0SYoshinobu Inoue yyerror(const char *s)
2469a4365d0SYoshinobu Inoue {
2479a4365d0SYoshinobu Inoue 	printf("%s: at %s in line %d\n", s, yytext, lineno);
2489a4365d0SYoshinobu Inoue }
249