token.l revision 1.1
11.1Sdegroote/* $NetBSD: token.l,v 1.1 2010/05/07 17:41:58 degroote Exp $ */ 21.1Sdegroote 31.1Sdegroote/*- 41.1Sdegroote * Copyright (c) 2010 The NetBSD Foundation, Inc. 51.1Sdegroote * All rights reserved. 61.1Sdegroote * 71.1Sdegroote * Redistribution and use in source and binary forms, with or without 81.1Sdegroote * modification, are permitted provided that the following conditions 91.1Sdegroote * are met: 101.1Sdegroote * 1. Redistributions of source code must retain the above copyright 111.1Sdegroote * notice, this list of conditions and the following disclaimer. 121.1Sdegroote * 2. Redistributions in binary form must reproduce the above copyright 131.1Sdegroote * notice, this list of conditions and the following disclaimer in the 141.1Sdegroote * documentation and/or other materials provided with the distribution. 151.1Sdegroote * 161.1Sdegroote * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 171.1Sdegroote * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 181.1Sdegroote * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 191.1Sdegroote * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201.1Sdegroote * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 211.1Sdegroote * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 221.1Sdegroote * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231.1Sdegroote * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241.1Sdegroote * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251.1Sdegroote * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261.1Sdegroote * POSSIBILITY OF SUCH DAMAGE. 271.1Sdegroote */ 281.1Sdegroote 291.1Sdegroote 301.1Sdegroote%{ 311.1Sdegroote#include <sys/cdefs.h> 321.1Sdegroote 331.1Sdegroote#ifndef lint 341.1Sdegroote__RCSID("$NetBSD: token.l,v 1.1 2010/05/07 17:41:58 degroote Exp $"); 351.1Sdegroote#endif 361.1Sdegroote 371.1Sdegroote#include <stdlib.h> 381.1Sdegroote#include <limits.h> 391.1Sdegroote#include <inttypes.h> 401.1Sdegroote#include <string.h> 411.1Sdegroote#include <errno.h> 421.1Sdegroote 431.1Sdegroote#include <net/if.h> 441.1Sdegroote#include <netinet/in.h> 451.1Sdegroote#include <net/pfvar.h> 461.1Sdegroote 471.1Sdegroote#include "parse.h" 481.1Sdegroote#include "parser.h" 491.1Sdegroote 501.1Sdegroote%} 511.1Sdegroote 521.1Sdegroote%option nounput 531.1Sdegroote 541.1Sdegroote%% 551.1Sdegroote 561.1Sdegrootestate { return STATE;} 571.1Sdegrooteon { return ON;} 581.1Sdegrooteout { return OUT;} 591.1Sdegrootein { return IN;} 601.1Sdegrooteproto { return PROTO;} 611.1Sdegrootefrom { return FROM;} 621.1Sdegrooteto { return TO;} 631.1Sdegrooteusing { return USING;} 641.1Sdegrooteid { return ID;} 651.1Sdegrootecid { return CID;} 661.1Sdegrooteexpire { return EXPIRE;} 671.1Sdegrootetimeout { return TIMEOUT;} 681.1Sdegrootesrc { return SRC;} 691.1Sdegrootedst { return DST;} 701.1Sdegrooteseq { return SEQ;} 711.1Sdegrootemax_win { return MAX_WIN;} 721.1Sdegrootewscale { return WSCALE;} 731.1Sdegrootemss { return MSS;} 741.1Sdegrooteno-scrub { return NOSCRUB;} 751.1Sdegrootescrub { return SCRUB;} 761.1Sdegrooteflags { return FLAGS;} 771.1Sdegrootettl { return TTL;} 781.1Sdegrootemode { return MODE;} 791.1Sdegroote[0-9]+ { char *ep; 801.1Sdegroote errno = 0; 811.1Sdegroote yylval.num = strtoumax(yytext, &ep, 10); 821.1Sdegroote if (errno == ERANGE && yylval.num == UINTMAX_MAX) 831.1Sdegroote yyfatal("Number out of range"); 841.1Sdegroote return NUMBER; 851.1Sdegroote } 861.1Sdegroote 871.1Sdegroote[A-Za-z0-9:\[][A-Za-z0-9\[\]_:%\.-]* { yylval.str = strdup(yytext); 881.1Sdegroote if (yylval.str == NULL) 891.1Sdegroote yyfatal("Not enough memory"); 901.1Sdegroote return STRING; 911.1Sdegroote } 921.1Sdegroote 931.1Sdegroote 941.1Sdegroote\n { lineno ++; } 951.1Sdegroote 961.1Sdegroote%% 971.1Sdegroote 981.1Sdegroote 991.1Sdegrootevoid 1001.1Sdegrooteyyfatal(const char *s) 1011.1Sdegroote{ 1021.1Sdegroote yyerror(s); 1031.1Sdegroote exit(EXIT_FAILURE); 1041.1Sdegroote} 1051.1Sdegroote 1061.1Sdegrootevoid 1071.1Sdegrooteyyerror(const char *s) 1081.1Sdegroote{ 1091.1Sdegroote printf("line %d: %s at [%s]\n", lineno, s, yytext); 1101.1Sdegroote} 1111.1Sdegroote 1121.1Sdegroote 1131.1Sdegrooteint 1141.1Sdegrooteparse(FILE *fp, struct pfioc_states* s) 1151.1Sdegroote{ 1161.1Sdegroote yyin = fp; 1171.1Sdegroote 1181.1Sdegroote lineno = 1; 1191.1Sdegroote 1201.1Sdegroote states = s; 1211.1Sdegroote allocated = 0; 1221.1Sdegroote memset(s, 0, sizeof(*s)); 1231.1Sdegroote 1241.1Sdegroote if (yyparse()) { 1251.1Sdegroote printf("parse failed, line %d.\n", lineno); 1261.1Sdegroote return(-1); 1271.1Sdegroote } 1281.1Sdegroote 1291.1Sdegroote return(0); 1301.1Sdegroote} 131