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