#include <sys/cdefs.h>
#ifndef lint
#if 0
static char yysccsid[] = "@(#)yaccpar 1.9 (Berkeley) 02/21/93";
#else
__IDSTRING(yyrcsid, "$NetBSD: skeleton.c,v 1.14 1997/10/20 03:41:16 lukem Exp $");
#endif
#endif
#include <stdlib.h>
#define YYBYACC 1
#define YYMAJOR 1
#define YYMINOR 9
#define YYLEX yylex()
#define YYEMPTY -1
#define yyclearin (yychar=(YYEMPTY))
#define yyerrok (yyerrflag=0)
#define YYRECOVERING (yyerrflag!=0)
#define yyparse table_parse
#define yylex table_lex
#define yyerror table_error
#define yychar table_char
#define yyval table_val
#define yylval table_lval
#define yydebug table_debug
#define yynerrs table_nerrs
#define yyerrflag table_errflag
#define yyss table_ss
#define yysslim table_sslim
#define yyssp table_ssp
#define yyvs table_vs
#define yyvsp table_vsp
#define yystacksize table_stacksize
#define yylhs table_lhs
#define yylen table_len
#define yydefred table_defred
#define yydgoto table_dgoto
#define yysindex table_sindex
#define yyrindex table_rindex
#define yygindex table_gindex
#define yytable table_table
#define yycheck table_check
#define yyname table_name
#define yyrule table_rule
#define YYPREFIX "table_"
#line 19 "table_parse.y"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include "types.h"
#include "ip4_range.h"
#include "table_parse.h"
#define YYSTYPE char *
#define YY_EXIT_FAILURE -1
extern int table_lineno;
int table_lex(void);
int table_parse(void);
void table_restart(FILE *input_file);
void table_error(const char *str);
ip4_range_list_t *table_parse_target_list;
#line 72 "yacc.table_parse.tab.c"
#define CIDR 257
#define RANGE 258
#define SINGLEIP 259
#define HOSTNAME 260
#define NEWLINE 261
#define YYERRCODE 256
short table_lhs[] = { -1,
0, 0, 0, 1, 1, 1, 1,
};
short table_len[] = { 2,
3, 2, 0, 1, 1, 1, 1,
};
short table_defred[] = { 3,
0, 4, 5, 6, 7, 2, 0, 1,
};
short table_dgoto[] = { 1,
7,
};
short table_sindex[] = { 0,
-257, 0, 0, 0, 0, 0, -256, 0,
};
short table_rindex[] = { 0,
0, 0, 0, 0, 0, 0, 0, 0,
};
short table_gindex[] = { 0,
0,
};
#define YYTABLESIZE 5
short table_table[] = { 2,
3, 4, 5, 6, 8,
};
short table_check[] = { 257,
258, 259, 260, 261, 261,
};
#define YYFINAL 1
#ifndef YYDEBUG
#define YYDEBUG 0
#endif
#define YYMAXTOKEN 261
#if YYDEBUG
char *table_name[] = {
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"CIDR","RANGE","SINGLEIP",
"HOSTNAME","NEWLINE",
};
char *table_rule[] = {
"$accept : lines",
"lines : lines line NEWLINE",
"lines : lines NEWLINE",
"lines :",
"line : CIDR",
"line : RANGE",
"line : SINGLEIP",
"line : HOSTNAME",
};
#endif
#ifndef YYSTYPE
typedef int YYSTYPE;
#endif
#ifdef YYSTACKSIZE
#undef YYMAXDEPTH
#define YYMAXDEPTH YYSTACKSIZE
#else
#ifdef YYMAXDEPTH
#define YYSTACKSIZE YYMAXDEPTH
#else
#define YYSTACKSIZE 10000
#define YYMAXDEPTH 10000
#endif
#endif
#define YYINITSTACKSIZE 200
int yydebug;
int yynerrs;
int yyerrflag;
int yychar;
short *yyssp;
YYSTYPE *yyvsp;
YYSTYPE yyval;
YYSTYPE yylval;
short *yyss;
short *yysslim;
YYSTYPE *yyvs;
int yystacksize;
#line 133 "table_parse.y"
void
table_parse_file(const char *file, ip4_range_list_t *list) {
FILE *f;
if (file == NULL) {
f = stdin;
}
else {
f = fopen(file, "r");
}
if (f == NULL) {
fprintf(stderr, "Error opening file %s.\n", file);
return;
}
table_parse_target_list = list;
table_restart(f);
table_parse();
fclose(f);
}
void
table_error(const char *str) {
fprintf(stderr,"error: %s on line: %d\n",str, table_lineno);
}
#line 187 "yacc.table_parse.tab.c"
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
int yyparse __P((void));
static int yygrowstack __P((void));
static int yygrowstack()
{
int newsize, i;
short *newss;
YYSTYPE *newvs;
if ((newsize = yystacksize) == 0)
newsize = YYINITSTACKSIZE;
else if (newsize >= YYMAXDEPTH)
return -1;
else if ((newsize *= 2) > YYMAXDEPTH)
newsize = YYMAXDEPTH;
i = yyssp - yyss;
if ((newss = (short *)realloc(yyss, newsize * sizeof *newss)) == NULL)
return -1;
yyss = newss;
yyssp = newss + i;
if ((newvs = (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs)) == NULL)
return -1;
yyvs = newvs;
yyvsp = newvs + i;
yystacksize = newsize;
yysslim = yyss + newsize - 1;
return 0;
}
#define YYABORT goto yyabort
#define YYREJECT goto yyabort
#define YYACCEPT goto yyaccept
#define YYERROR goto yyerrlab
int
yyparse()
{
int yym, yyn, yystate;
#if YYDEBUG
char *yys;
if ((yys = getenv("YYDEBUG")) != NULL)
{
yyn = *yys;
if (yyn >= '0' && yyn <= '9')
yydebug = yyn - '0';
}
#endif
yynerrs = 0;
yyerrflag = 0;
yychar = (-1);
if (yyss == NULL && yygrowstack()) goto yyoverflow;
yyssp = yyss;
yyvsp = yyvs;
*yyssp = yystate = 0;
yyloop:
if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
}
if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, shifting to state %d\n",
YYPREFIX, yystate, yytable[yyn]);
#endif
if (yyssp >= yysslim && yygrowstack())
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
yychar = (-1);
if (yyerrflag > 0) --yyerrflag;
goto yyloop;
}
if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
{
yyn = yytable[yyn];
goto yyreduce;
}
if (yyerrflag) goto yyinrecovery;
goto yynewerror;
yynewerror:
yyerror("syntax error");
goto yyerrlab;
yyerrlab:
++yynerrs;
yyinrecovery:
if (yyerrflag < 3)
{
yyerrflag = 3;
for (;;)
{
if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, error recovery shifting\
to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
#endif
if (yyssp >= yysslim && yygrowstack())
{
goto yyoverflow;
}
*++yyssp = yystate = yytable[yyn];
*++yyvsp = yylval;
goto yyloop;
}
else
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: error recovery discarding state %d\n",
YYPREFIX, *yyssp);
#endif
if (yyssp <= yyss) goto yyabort;
--yyssp;
--yyvsp;
}
}
}
else
{
if (yychar == 0) goto yyabort;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
YYPREFIX, yystate, yychar, yys);
}
#endif
yychar = (-1);
goto yyloop;
}
yyreduce:
#if YYDEBUG
if (yydebug)
printf("%sdebug: state %d, reducing by rule %d (%s)\n",
YYPREFIX, yystate, yyn, yyrule[yyn]);
#endif
yym = yylen[yyn];
yyval = yyvsp[1-yym];
switch (yyn)
{
case 4:
#line 60 "table_parse.y"
{
int a, b, c, d;
int p;
if (sscanf(yyvsp[0], "%d.%d.%d.%d/%d", &a, &b, &c, &d, &p) == 5 &&
a >= 0 && a < 256 &&
b >= 0 && b < 256 &&
c >= 0 && c < 256 &&
d >= 0 && d < 256 &&
p >= 0 && p < 33) {
ip4_range_list_insert_cidr(table_parse_target_list, IP(a,b,c,d), p, NULL);
}
free(yyvsp[0]);
}
break;
case 5:
#line 73 "table_parse.y"
{
int a, b, c, d;
int a1, b1, c1, d1;
if (sscanf(yyvsp[0], "%d.%d.%d.%d-%d.%d.%d.%d", &a, &b, &c, &d, &a1, &b1, &c1, &d1 ) == 8 &&
a >= 0 && a < 256 &&
b >= 0 && b < 256 &&
c >= 0 && c < 256 &&
d >= 0 && d < 256 &&
a1 >= 0 && a1 < 256 &&
b1 >= 0 && b1 < 256 &&
c1 >= 0 && c1 < 256 &&
d1 >= 0 && d1 < 256) {
ip4_range_list_insert_range_raw( table_parse_target_list, IP(a,b,c,d), IP(a1, b1, c1, d1), NULL);
}
free(yyvsp[0]);
}
break;
case 6:
#line 90 "table_parse.y"
{
int a, b, c, d;
if (sscanf(yyvsp[0], "%d.%d.%d.%d", &a, &b, &c, &d) == 4 &&
a >= 0 && a < 256 &&
b >= 0 && b < 256 &&
c >= 0 && c < 256 &&
d >= 0 && d < 256) {
ip4_range_list_insert_cidr(table_parse_target_list, IP(a,b,c,d), 32, NULL);
}
free(yyvsp[0]);
}
break;
case 7:
#line 102 "table_parse.y"
{
struct addrinfo *ai_result;
struct addrinfo *ai;
struct sockaddr_in *sa;
int result;
struct addrinfo hint;
memset(&hint, 0, sizeof(struct addrinfo));
hint.ai_family = AF_INET;
hint.ai_socktype = SOCK_STREAM;
result = getaddrinfo(yyvsp[0], NULL, &hint, &ai_result);
if (result) {
fprintf(stderr, "Host lookup for host '%s' failed: %s\n", yyvsp[0], gai_strerror(result));
}
else {
for (ai = ai_result; ai; ai = ai->ai_next) {
sa = (struct sockaddr_in *) ai->ai_addr;
ip4_range_list_insert_cidr(table_parse_target_list, ntohl(sa->sin_addr.s_addr), 32, NULL);
}
freeaddrinfo(ai_result);
}
free(yyvsp[0]);
}
break;
#line 434 "yacc.table_parse.tab.c"
}
yyssp -= yym;
yystate = *yyssp;
yyvsp -= yym;
yym = yylhs[yyn];
if (yystate == 0 && yym == 0)
{
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state 0 to\
state %d\n", YYPREFIX, YYFINAL);
#endif
yystate = YYFINAL;
*++yyssp = YYFINAL;
*++yyvsp = yyval;
if (yychar < 0)
{
if ((yychar = yylex()) < 0) yychar = 0;
#if YYDEBUG
if (yydebug)
{
yys = 0;
if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
if (!yys) yys = "illegal-symbol";
printf("%sdebug: state %d, reading %d (%s)\n",
YYPREFIX, YYFINAL, yychar, yys);
}
#endif
}
if (yychar == 0) goto yyaccept;
goto yyloop;
}
if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
yystate = yytable[yyn];
else
yystate = yydgoto[yym];
#if YYDEBUG
if (yydebug)
printf("%sdebug: after reduction, shifting from state %d \
to state %d\n", YYPREFIX, *yyssp, yystate);
#endif
if (yyssp >= yysslim && yygrowstack())
{
goto yyoverflow;
}
*++yyssp = yystate;
*++yyvsp = yyval;
goto yyloop;
yyoverflow:
yyerror("yacc stack overflow");
yyabort:
return (1);
yyaccept:
return (0);
}
syntax highlighted by Code2HTML, v. 0.9.1