dhclient - Silence dhclient by immediately exiting if the interface doesn't exist.
[dragonfly.git] / usr.sbin / rrenumd / lexer.l
blob307b1f60806204bcc0cd1ca90c4ff07edad1af2a
1 /*      $KAME: lexer.l,v 1.7 2000/11/08 02:40:53 itojun Exp $   */
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: src/usr.sbin/rrenumd/lexer.l,v 1.1.2.2 2001/07/03 11:02:10 ume Exp $
32  * $DragonFly: src/usr.sbin/rrenumd/lexer.l,v 1.4 2004/02/10 02:59:43 rob Exp $
33  */
36 #define YY_NO_INPUT
37 #define YY_NO_UNPUT
39 #include <sys/param.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
42 #include <sys/queue.h>
44 #include <string.h>
46 #include <net/if.h>
47 #if defined(__DragonFly__) 
48 #include <net/if_var.h>
49 #endif /* __DragonFly__  */
51 #include <netinet/in.h>
52 #include <netinet/in_var.h>
53 #include <netinet/icmp6.h>
55 #include <arpa/inet.h>
57 #include "y.tab.h"
59 int lineno = 1;
61 #define LINEBUF_SIZE 1000
62 char linebuf[LINEBUF_SIZE];
64 int parse(FILE **);
65 void yyerror(const char *);
66 int yylex(void);
69 /* common section */
70 nl              \n
71 ws              [ \t]+
72 digit           [0-9]
73 letter          [0-9A-Za-z]
74 hexdigit        [0-9A-Fa-f]
75 special         [()+\|\?\*,]
76 dot             \.
77 hyphen          \-
78 colon           \:
79 slash           \/
80 bcl             \{
81 ecl             \}
82 semi            \;
83 usec            {dot}{digit}{1,6}
84 comment         \#.*
85 qstring         \"[^"]*\"
86 decstring       {digit}+
87 hexpair         {hexdigit}{hexdigit}
88 hexstring       0[xX]{hexdigit}+
89 octetstring     {octet}({dot}{octet})+
90 ipv4addr        {digit}{1,3}({dot}{digit}{1,3}){0,3}
91 ipv6addr        {hexdigit}{0,4}({colon}{hexdigit}{0,4}){2,7}
92 ipaddrmask      {slash}{digit}{1,3}
93 keyword         {letter}{letter}+
94 name            {letter}(({letter}|{digit}|{hyphen})*({letter}|{digit}))*
95 hostname        {name}(({dot}{name})+{dot}?)?
97 timeval         {digit}{0,2}
98 days            d{timeval}
99 hours           h{timeval}
100 minutes         m{timeval}
101 seconds         s{timeval}
103 mprefix         match_prefix|match-prefix
104 uprefix         use_prefix|use-prefix
107         /* rrenumd keywords */
108 debug           {
109                         return(DEBUG_CMD);
110                 }
111 dest            {
112                         return(DEST_CMD);
113                 }
114 retry           {
115                         return(RETRY_CMD);
116                 }
117 seqnum          {
118                         return(SEQNUM_CMD);
119                 }
120 add             {
121                         yylval.num = RPM_PCO_ADD;
122                         return(ADD);
123                 }
124 change          {
125                         yylval.num = RPM_PCO_CHANGE;
126                         return(CHANGE);
127                  }
128 setglobal       {
129                         yylval.num = RPM_PCO_SETGLOBAL;
130                         return(SETGLOBAL);
131                 }
132 {mprefix}       {
133                         return(MATCH_PREFIX_CMD);
134                 }
135 maxlen          {
136                         return(MAXLEN_CMD);
137                 }
138 minlen          {
139                         return(MINLEN_CMD);
140                 }
141 {uprefix}       {
142                         return(USE_PREFIX_CMD);
143                 }
144 keeplen         {
145                         return(KEEPLEN_CMD);
146                 }
148 vltime          {
149                         return(VLTIME_CMD);
150                 }
151 pltime          {
152                         return(PLTIME_CMD);
153                 }
154 raf_onlink      {
155                         return(RAF_ONLINK_CMD);
156                 }
157 raf_auto        {
158                         return(RAF_AUTO_CMD);
159                 }
160 rrf_decrvalid   {
161                         return(RAF_DECRVALID_CMD);
162                 }
163 rrf_decrprefd   {
164                         return(RAF_DECRPREFD_CMD);
165                 }
166 {days}          {
167                         yytext++;
168                         yylval.num = atoi(yytext);
169                         return(DAYS);
170                 }
171 {hours}         {
172                         yytext++;
173                         yylval.num = atoi(yytext);
174                         return(HOURS);
175                 }
176 {minutes}       {
177                         yytext++;
178                         yylval.num = atoi(yytext);
179                         return(MINUTES);
180                 }
181 {seconds}       {
182                         yytext++;
183                         yylval.num = atoi(yytext);
184                         return(SECONDS);
185                 }
186 infinity        {
187                         return(INFINITY);
188                 }
190 on              {
191                         yylval.num = 1;
192                         return(ON);
193                 }
194 off             {
195                         yylval.num = 0;
196                         return(OFF);
197                 }
199         /* basic rules */
200 {ws}            ;
201 {nl}            {
202                         lineno++;
203                 }
204 {semi}          {
205                         return EOS;
206                 }
207 {bcl}           {
208                         return BCL;
209                 }
210 {ecl}           {
211                         return ECL;
212                 }
213 {qstring}       {
214                         yylval.cs.cp = yytext;
215                         yylval.cs.len = yyleng;
216                         return QSTRING;
217                 }
218 {decstring}     {
219                         yylval.cs.cp = yytext;
220                         yylval.cs.len = yyleng;
221                         return DECSTRING;
222                 }
223 {name}          {
224                         yylval.cs.cp = yytext;
225                         yylval.cs.len = yyleng;
226                         return NAME;
227                 }
228 {ipv4addr}      {
229                         memset(&yylval.addr4, 0, sizeof(struct in_addr));
230                         if (inet_pton(AF_INET, yytext,
231                                       &yylval.addr4) == 1) {
232                                 return IPV4ADDR;
233                         } else {
234                                 return ERROR;
235                         }
236                 }
237 {ipv6addr}      {
238                         memset(&yylval.addr6, 0, sizeof(struct in6_addr));
239                         if (inet_pton(AF_INET6, yytext,
240                                       &yylval.addr6) == 1) {
241                                 return IPV6ADDR;
242                         } else {
243                                 return ERROR;
244                         }
245                 }
246 {ipaddrmask}    {
247                         yytext++;
248                         yylval.num = atoi(yytext);
249                         return(PREFIXLEN);
250                 }
251 {hostname}      {
252                         yylval.cs.cp = yytext;
253                         yylval.cs.len = yyleng;
254                         return HOSTNAME;
255                 }
258 int parse(FILE **fp)
260         extern int yyparse(void);
262         yyin = *fp;
264         if (yyparse())
265                 return(-1);
267         return(0);
271 void
272 yyerror(const char *s)
274         printf("%s: at %s in line %d\n", s, yytext, lineno);