#include #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 #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 YYPREFIX "yy" #line 2 "parser.y" #include #include #include "config.h" #include "netconfig.h" extern struct icmp_item *ICMP_Send; extern struct icmp_item *ICMP_Recv; extern struct udp_item *UDP_Send; extern struct udp_item *UDP_Recv; extern u_short ConfigNum; /* Fields that might be set */ u_long sport=-1, dport=-1, seq=-1, id=-1, type=-1, code=-1, ack=-1, win=-1; u_long nmatch=-1; /* Data in the packet */ char *data; /* Name of current ddos we're working on */ char ddos_name[BUFSIZE]; extern int errno; #line 26 "parser.y" typedef union { char *string; u_short us; u_long ul; } YYSTYPE; #line 49 "y.tab.c" #define START 257 #define END 258 #define SEND 259 #define RECV 260 #define ICMP 261 #define UDP 262 #define TCP 263 #define SPORT 264 #define DPORT 265 #define SEQ 266 #define ID 267 #define TYPE 268 #define CODE 269 #define DATA 270 #define ACK 271 #define WIN 272 #define NMATCH 273 #define QSTRING 274 #define YYERRCODE 256 short yylhs[] = { -1, 0, 0, 1, 1, 3, 3, 5, 5, 5, 5, 5, 5, 6, 9, 9, 10, 10, 10, 10, 10, 10, 8, 11, 11, 12, 12, 12, 12, 7, 2, 4, }; short yylen[] = { 2, 0, 2, 3, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 2, 2, 2, 0, 2, 2, 2, 2, 2, 1, 2, 2, }; short yydefred[] = { 1, 0, 0, 2, 0, 30, 0, 0, 0, 0, 4, 5, 31, 14, 23, 29, 7, 8, 9, 12, 11, 10, 3, 6, 0, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 24, 16, 17, 18, 19, 20, 21, 25, 26, 27, 28, }; short yydgoto[] = { 1, 3, 4, 9, 10, 11, 16, 17, 18, 24, 32, 25, 37, }; short yysindex[] = { 0, -250, -272, 0, -255, 0, -266, -243, -243, -255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -256, -264, -259, -258, -247, -246, -245, -244, 0, -242, -241, -240, -239, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; short yyrindex[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -237, -234, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; short yygindex[] = { 0, 0, 0, 0, 22, 27, 29, 30, 31, 0, 0, 0, 0, }; #define YYTABLESIZE 39 short yytable[] = { 33, 34, 5, 6, 7, 8, 35, 2, 12, 36, 26, 27, 28, 29, 30, 38, 39, 31, 13, 14, 15, 13, 13, 13, 22, 22, 22, 40, 41, 42, 43, 22, 44, 45, 46, 47, 23, 19, 20, 21, }; short yycheck[] = { 264, 265, 274, 258, 259, 260, 270, 257, 274, 273, 266, 267, 268, 269, 270, 274, 274, 273, 261, 262, 263, 258, 259, 260, 258, 259, 260, 274, 274, 274, 274, 9, 274, 274, 274, 274, 9, 8, 8, 8, }; #define YYFINAL 1 #ifndef YYDEBUG #define YYDEBUG 0 #endif #define YYMAXTOKEN 274 #if YYDEBUG char *yyname[] = { "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,"START","END","SEND","RECV", "ICMP","UDP","TCP","SPORT","DPORT","SEQ","ID","TYPE","CODE","DATA","ACK","WIN", "NMATCH","QSTRING", }; char *yyrule[] = { "$accept : ddoses", "ddoses :", "ddoses : ddoses ddos", "ddos : ddos_name ddos_contents ddos_terminator", "ddos : ddos_name ddos_terminator", "ddos_contents : ddos_content", "ddos_contents : ddos_contents ddos_content", "ddos_content : SEND proto_icmp", "ddos_content : SEND proto_tcp", "ddos_content : SEND proto_udp", "ddos_content : RECV proto_udp", "ddos_content : RECV proto_tcp", "ddos_content : RECV proto_icmp", "proto_icmp : ICMP icmp_options", "icmp_options :", "icmp_options : icmp_options icmp_option", "icmp_option : SEQ QSTRING", "icmp_option : ID QSTRING", "icmp_option : TYPE QSTRING", "icmp_option : CODE QSTRING", "icmp_option : DATA QSTRING", "icmp_option : NMATCH QSTRING", "proto_udp : UDP udp_options", "udp_options :", "udp_options : udp_options udp_option", "udp_option : SPORT QSTRING", "udp_option : DPORT QSTRING", "udp_option : DATA QSTRING", "udp_option : NMATCH QSTRING", "proto_tcp : TCP", "ddos_name : START QSTRING", "ddos_terminator : END QSTRING", }; #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 111 "parser.y" add_icmp(struct icmp_item **Head) { struct icmp_item *current = malloc(sizeof(struct icmp_item)); if(current==NULL){ perror("malloc failed. aborting.\n"); exit(FAILURE); } current->string = data; strncpy(current->name, ddos_name, BUFSIZE-1); current->type = type; current->id = id; current->code = code; current->seq = seq; current->nmatch = nmatch; current->Next = NULL; if(*Head == NULL){ *Head = current; } else { current->Next = *Head; *Head = current; } } add_udp(struct udp_item **Head) { struct udp_item *current = malloc(sizeof(struct udp_item)); if(current==NULL){ perror("malloc failed. *aborting*\n"); exit(FAILURE); } current->sport = sport; current->dport = dport; strncpy(current->name, ddos_name, BUFSIZE-1); current->string = data; current->nmatch=nmatch; current->Next = NULL; if(*Head == NULL){ *Head = current; } else { current->Next = *Head; *Head = current; } } static void yyerror(char *msg) { fprintf(stderr, "%s\n", msg); exit(0); } #line 253 "y.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 7: #line 47 "parser.y" { add_icmp(&ICMP_Send); data = NULL; nmatch=sport=dport=seq=id=type=code=ack=win=-1; } break; case 9: #line 52 "parser.y" { add_udp(&UDP_Send); data = NULL; nmatch=sport=dport=seq=id=type=code=ack=win=-1; } break; case 10: #line 56 "parser.y" { add_udp(&UDP_Recv); data = NULL; nmatch=sport=dport=seq=id=type=code=ack=win=-1; } break; case 12: #line 61 "parser.y" { add_icmp(&ICMP_Recv); data=NULL; nmatch=sport=dport=seq=id=type=code=ack=win=-1; } break; case 16: #line 71 "parser.y" { seq = atoi(yyvsp[0].string); } break; case 17: #line 72 "parser.y" { id = atoi(yyvsp[0].string); } break; case 18: #line 73 "parser.y" { type = atoi(yyvsp[0].string); } break; case 19: #line 74 "parser.y" { code = atoi(yyvsp[0].string); } break; case 20: #line 75 "parser.y" { data = malloc(strlen(yyvsp[0].string) * (sizeof(char))); if(data == NULL){ fprintf(stderr, "malloc error. *aborting*\n"); exit(FAILURE); } strcpy(data, yyvsp[0].string); } break; case 21: #line 83 "parser.y" { nmatch = atoi(yyvsp[0].string); } break; case 25: #line 90 "parser.y" { sport = atoi(yyvsp[0].string); } break; case 26: #line 91 "parser.y" { dport = atoi(yyvsp[0].string); } break; case 27: #line 92 "parser.y" { data = malloc(strlen(yyvsp[0].string) * (sizeof(char))); if(data == NULL){ fprintf(stderr, "malloc error. *aborting*\n"); exit(FAILURE); } strcpy(data, yyvsp[0].string); } break; case 28: #line 100 "parser.y" { nmatch = atoi(yyvsp[0].string); } break; case 29: #line 102 "parser.y" { printf("TCP Not implemented\n"); } break; case 30: #line 104 "parser.y" { strncpy(ddos_name, (yyvsp[0].string), sizeof(ddos_name)); } break; case 31: #line 106 "parser.y" { ConfigNum++; bzero(ddos_name, sizeof(ddos_name)); } break; #line 515 "y.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); }