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