11.2Sjoerg/* $NetBSD: token.l,v 1.2 2011/05/24 13:41:53 joerg 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.2Sjoerg__RCSID("$NetBSD: token.l,v 1.2 2011/05/24 13:41:53 joerg 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.2Sjoerg%option noinput 541.1Sdegroote 551.1Sdegroote%% 561.1Sdegroote 571.1Sdegrootestate { return STATE;} 581.1Sdegrooteon { return ON;} 591.1Sdegrooteout { return OUT;} 601.1Sdegrootein { return IN;} 611.1Sdegrooteproto { return PROTO;} 621.1Sdegrootefrom { return FROM;} 631.1Sdegrooteto { return TO;} 641.1Sdegrooteusing { return USING;} 651.1Sdegrooteid { return ID;} 661.1Sdegrootecid { return CID;} 671.1Sdegrooteexpire { return EXPIRE;} 681.1Sdegrootetimeout { return TIMEOUT;} 691.1Sdegrootesrc { return SRC;} 701.1Sdegrootedst { return DST;} 711.1Sdegrooteseq { return SEQ;} 721.1Sdegrootemax_win { return MAX_WIN;} 731.1Sdegrootewscale { return WSCALE;} 741.1Sdegrootemss { return MSS;} 751.1Sdegrooteno-scrub { return NOSCRUB;} 761.1Sdegrootescrub { return SCRUB;} 771.1Sdegrooteflags { return FLAGS;} 781.1Sdegrootettl { return TTL;} 791.1Sdegrootemode { return MODE;} 801.1Sdegroote[0-9]+ { char *ep; 811.1Sdegroote errno = 0; 821.1Sdegroote yylval.num = strtoumax(yytext, &ep, 10); 831.1Sdegroote if (errno == ERANGE && yylval.num == UINTMAX_MAX) 841.1Sdegroote yyfatal("Number out of range"); 851.1Sdegroote return NUMBER; 861.1Sdegroote } 871.1Sdegroote 881.1Sdegroote[A-Za-z0-9:\[][A-Za-z0-9\[\]_:%\.-]* { yylval.str = strdup(yytext); 891.1Sdegroote if (yylval.str == NULL) 901.1Sdegroote yyfatal("Not enough memory"); 911.1Sdegroote return STRING; 921.1Sdegroote } 931.1Sdegroote 941.1Sdegroote 951.1Sdegroote\n { lineno ++; } 961.1Sdegroote 971.1Sdegroote%% 981.1Sdegroote 991.1Sdegroote 1001.1Sdegrootevoid 1011.1Sdegrooteyyfatal(const char *s) 1021.1Sdegroote{ 1031.1Sdegroote yyerror(s); 1041.1Sdegroote exit(EXIT_FAILURE); 1051.1Sdegroote} 1061.1Sdegroote 1071.1Sdegrootevoid 1081.1Sdegrooteyyerror(const char *s) 1091.1Sdegroote{ 1101.1Sdegroote printf("line %d: %s at [%s]\n", lineno, s, yytext); 1111.1Sdegroote} 1121.1Sdegroote 1131.1Sdegroote 1141.1Sdegrooteint 1151.1Sdegrooteparse(FILE *fp, struct pfioc_states* s) 1161.1Sdegroote{ 1171.1Sdegroote yyin = fp; 1181.1Sdegroote 1191.1Sdegroote lineno = 1; 1201.1Sdegroote 1211.1Sdegroote states = s; 1221.1Sdegroote allocated = 0; 1231.1Sdegroote memset(s, 0, sizeof(*s)); 1241.1Sdegroote 1251.1Sdegroote if (yyparse()) { 1261.1Sdegroote printf("parse failed, line %d.\n", lineno); 1271.1Sdegroote return(-1); 1281.1Sdegroote } 1291.1Sdegroote 1301.1Sdegroote return(0); 1311.1Sdegroote} 132