%{ /* * Copyright (C) 1999 WIDE Project. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * $FreeBSD$ */ #include #include #include #include #ifdef HAVE_STDARG_H #include #else #include #endif #include "var.h" #include "vmbuf.h" #include "debug.h" #include "cfparse.h" #include "y.tab.h" static int yyerrorcount = 0; int lineno = 1; int yy_first_time = 1; extern char configfilename[]; #if 0 static void cfdebug_print __P((char *, char *, int)); #endif extern int yylex __P((void)); %} /* common seciton */ nl \n ws [ \t]+ comment \#.* semi \; string [a-zA-Z0-9:\._][a-zA-Z0-9:\._]* digit [0-9] integer {digit}+ number {integer}|({digit}*\.{integer}) hexdigit [0-9A-Fa-f] hexpair {hexdigit}{hexdigit} hexstring 0[xX]{hexpair}+ ifname [a-zA-Z]+[0-9]+ slash \/ %s S_CNF %s S_LOG %s S_PHYINT S_IFCONF S_CANDRP S_CANDBSR S_PREFIX %s S_THRES %% %{ if (yy_first_time) { BEGIN S_CNF; yy_first_time = 0; } %} /* logging */ log { DP("begin logging"); BEGIN S_LOG; return(LOGGING); } (no)?mld_proto { YYD_ECHO; yylval.num = DEBUG_MLD_PROTO; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?mld_timer { YYD_ECHO; yylval.num = DEBUG_MLD_TIMER; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?mld_member { YYD_ECHO; yylval.num = DEBUG_MLD_MEMBER; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?mld { YYD_ECHO; yylval.num = DEBUG_MLD; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?switch { YYD_ECHO; yylval.num = DEBUG_SWITCH; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?m?trace { YYD_ECHO; yylval.num = DEBUG_TRACE; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?traceroute { YYD_ECHO; yylval.num = DEBUG_TRACE; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?timeout { YYD_ECHO; yylval.num = DEBUG_TIMEOUT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?callout { YYD_ECHO; yylval.num = DEBUG_TIMEOUT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pkt { YYD_ECHO; yylval.num = DEBUG_PKT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?packets { YYD_ECHO; yylval.num = DEBUG_PKT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?interfaces { YYD_ECHO; yylval.num = DEBUG_IF; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?vif { YYD_ECHO; yylval.num = DEBUG_IF; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?kernel { YYD_ECHO; yylval.num = DEBUG_KERN; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?cache { YYD_ECHO; yylval.num = DEBUG_MFC; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?mfc { YYD_ECHO; yylval.num = DEBUG_MFC; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?k_cache { YYD_ECHO; yylval.num = DEBUG_MFC; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?k_mfc { YYD_ECHO; yylval.num = DEBUG_MFC; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?rsrr { YYD_ECHO; yylval.num = DEBUG_RSRR; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_detail { YYD_ECHO; yylval.num = DEBUG_PIM_DETAIL; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_hello { YYD_ECHO; yylval.num = DEBUG_PIM_HELLO; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_neighbors { YYD_ECHO; yylval.num = DEBUG_PIM_HELLO; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_register { YYD_ECHO; yylval.num = DEBUG_PIM_REGISTER; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?registers { YYD_ECHO; yylval.num = DEBUG_PIM_REGISTER; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_join_prune { YYD_ECHO; yylval.num = DEBUG_PIM_JOIN_PRUNE; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_j_p { YYD_ECHO; yylval.num = DEBUG_PIM_JOIN_PRUNE; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_jp { YYD_ECHO; yylval.num = DEBUG_PIM_JOIN_PRUNE; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_bootstrap { YYD_ECHO; yylval.num = DEBUG_PIM_BOOTSTRAP; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_bsr { YYD_ECHO; yylval.num = DEBUG_PIM_BOOTSTRAP; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?bsr { YYD_ECHO; yylval.num = DEBUG_PIM_BOOTSTRAP; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?bootstrap { YYD_ECHO; yylval.num = DEBUG_PIM_BOOTSTRAP; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_asserts { YYD_ECHO; yylval.num = DEBUG_PIM_ASSERT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_cand_rp { YYD_ECHO; yylval.num = DEBUG_PIM_CAND_RP; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_c_rp { YYD_ECHO; yylval.num = DEBUG_PIM_CAND_RP; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_rp { YYD_ECHO; yylval.num = DEBUG_PIM_CAND_RP; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?rp { YYD_ECHO; yylval.num = DEBUG_PIM_CAND_RP; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_routes { YYD_ECHO; yylval.num = DEBUG_PIM_MRT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_routing { YYD_ECHO; yylval.num = DEBUG_PIM_MRT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_mrt { YYD_ECHO; yylval.num = DEBUG_PIM_MRT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_timers { YYD_ECHO; yylval.num = DEBUG_PIM_TIMER; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim_rpf { YYD_ECHO; yylval.num = DEBUG_PIM_RPF; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?rpf { YYD_ECHO; yylval.num = DEBUG_RPF; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?pim { YYD_ECHO; yylval.num = DEBUG_PIM; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?routes { YYD_ECHO; yylval.num = DEBUG_MRT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?routing { YYD_ECHO; yylval.num = DEBUG_MRT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?mrt { YYD_ECHO; yylval.num = DEBUG_MRT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?routers { YYD_ECHO; yylval.num = DEBUG_NEIGHBORS; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?mrouters { YYD_ECHO; yylval.num = DEBUG_NEIGHBORS; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?neighbors { YYD_ECHO; yylval.num = DEBUG_NEIGHBORS; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?timers { YYD_ECHO; yylval.num = DEBUG_TIMER; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } (no)?asserts { YYD_ECHO; yylval.num = DEBUG_ASSERT; if (strncmp("no", yytext, 2)) return(LOGLEV); else return(NOLOGLEV); } all { YYD_ECHO; yylval.num = DEBUG_ALL; return(LOGLEV); } 3 { YYD_ECHO; yylval.num = DEBUG_ALL; return(LOGLEV); } {semi} { DP("end logging"); BEGIN S_CNF; return(EOS); } {string} { yywarn("unknown log type: %s (ignored)", yytext); } /* yes-or-no */ [yY][eE][sS] { YYD_ECHO; return(YES); } [nN][oO] { YYD_ECHO; return(NO); } /* reverselookup */ reverselookup { YYD_ECHO; return(REVERSELOOKUP); } /* phyint */ phyint { DP("begin phyint"); BEGIN S_PHYINT; return(PHYINT); } {string} { YYD_ECHO; BEGIN S_IFCONF; yylval.val.l = strlen(yytext); yylval.val.v = strdup(yytext); return(IFNAME); } {semi} { yyerror("phyint was specified without interface."); return(EOS); } disable { YYD_ECHO; return(DISABLE); } preference { YYD_ECHO; return(PREFERENCE); } metric { YYD_ECHO; return(METRIC); } nolistener { YYD_ECHO; return(NOLISTENER); } {semi} { DP("end phyint"); BEGIN S_CNF; return(EOS); } /* cand_rp */ cand_rp { DP("begin cand_rp"); BEGIN S_CANDRP; return(CANDRP); } priority { YYD_ECHO; return(PRIORITY); } time { YYD_ECHO; return(TIME); } {ifname} { YYD_ECHO; yylval.val.l = strlen(yytext); yylval.val.v = strdup(yytext); return(IFNAME); } {semi} { DP("end cand_rp"); BEGIN S_CNF; return(EOS); } /* cand_bootstrap_router */ cand_bootstrap_router { DP("begin cand_bsr"); BEGIN S_CANDBSR; return(CANDBSR); } priority { YYD_ECHO; return(PRIORITY); } masklen { YYD_ECHO; return(MASKLEN); } time { YYD_ECHO; return(TIME); } {ifname} { YYD_ECHO; yylval.val.l = strlen(yytext); yylval.val.v = strdup(yytext); return(IFNAME); } {semi} { DP("end cand_bsr"); BEGIN S_CNF; return(EOS); } /* group_prefix */ group_prefix { YYD_ECHO; return(GRPPFX); } /* switch_register_threshold */ switch_register_threshold { YYD_ECHO; BEGIN S_THRES; return(REGTHRES); } /* switch_data_threshold */ switch_data_threshold { YYD_ECHO; BEGIN S_THRES; return(DATATHRES); } rate { YYD_ECHO; return(RATE); } interval { YYD_ECHO; return(INTERVAL); } {semi} { DP("end thres"); BEGIN S_CNF; return(EOS); } /* various parameters */ default_source_metric { YYD_ECHO; return(SRCMETRIC); } default_source_preference { YYD_ECHO; return(SRCPREF); } hello_period { YYD_ECHO; return(HELLOPERIOD); } granularity { YYD_ECHO; return(GRANULARITY); } join_prune_period { YYD_ECHO; return(JPPERIOD); } data_timeout { YYD_ECHO; return(DATATIME); } register_suppression_timeout { YYD_ECHO; return(REGSUPTIME); } probe_time { YYD_ECHO; return(PROBETIME); } assert_timeout { YYD_ECHO; return(ASSERTTIME); } /* misc */ {ws} { ; } {nl} { lineno++; } {comment} { DP("comment"); } {number} { YYD_ECHO; yylval.fl = atof(yytext); return(NUMBER); } {slash} { YYD_ECHO; return(SLASH); } {semi} { DP("end cnf"); return(EOS); } /* last resort */ {string} { YYD_ECHO; yylval.val.l = strlen(yytext); yylval.val.v = strdup(yytext); return(STRING); } %% #if 0 static void cfdebug_print(w, t, l) char *w, *t; int l; { printf("<%d>%s [%s] (%d)\n", yy_start, w, t, l); } #endif static void yyerror0(char *s, va_list ap) { fprintf(stderr, "%s %d: ", configfilename, lineno); vfprintf(stderr, s, ap); fprintf(stderr, "\n"); } void yyerror(char *s, ...) { va_list ap; #ifdef HAVE_STDARG_H va_start(ap, s); #else va_start(ap); #endif yyerror0(s, ap); va_end(ap); yyerrorcount++; } void yywarn(char *s, ...) { va_list ap; #ifdef HAVE_STDARG_H va_start(ap, s); #else va_start(ap); #endif yyerror0(s, ap); va_end(ap); } int cfparse(strict, debugonly) int strict, debugonly; { if ((yyin = fopen(configfilename, "r")) == NULL) { fprintf(stderr, "cfparse: fopen(%s)\n", configfilename); return(-1); } cf_init(strict, debugonly); if ((yyparse() || yyerrorcount) && strict) { if (yyerrorcount) { yyerror("fatal parse failure: exiting (%d errors)", yyerrorcount); } else yyerror("fatal parse failure: exiting"); return(-1); } YIPSDP(PLOG("parse successed.\n")); return cf_post_config(); }