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