cfg.y 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558
  1. /*
  2. * $Id$
  3. *
  4. * cfg grammar
  5. *
  6. * Copyright (C) 2001-2003 FhG Fokus
  7. *
  8. * This file is part of ser, a free SIP server.
  9. *
  10. * ser is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version
  14. *
  15. * For a license to use the ser software under conditions
  16. * other than those described here, or to purchase support for this
  17. * software, please contact iptel.org by e-mail at the following addresses:
  18. * [email protected]
  19. *
  20. * ser is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program; if not, write to the Free Software
  27. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  28. */
  29. /*
  30. * History:
  31. * ---------
  32. * 2003-01-29 src_port added (jiri)
  33. * 2003-01-23 mhomed added (jiri)
  34. * 2003-03-19 replaced all mallocs/frees with pkg_malloc/pkg_free (andrei)
  35. * 2003-03-19 Added support for route type in find_export (janakj)
  36. * 2003-03-20 Regex support in modparam (janakj)
  37. * 2003-04-01 added dst_port, proto , af (andrei)
  38. * 2003-04-05 s/reply_route/failure_route, onreply_route introduced (jiri)
  39. * 2003-04-12 added force_rport, chroot and wdir (andrei)
  40. * 2003-04-15 added tcp_children, disable_tcp (andrei)
  41. * 2003-04-22 strip_tail added (jiri)
  42. * 2003-07-03 tls* (disable, certificate, private_key, ca_list, verify,
  43. * require_certificate added (andrei)
  44. * 2003-07-06 more tls config. vars added: tls_method, tls_port_no (andrei)
  45. * 2003-10-02 added {,set_}advertised_{address,port} (andrei)
  46. * 2003-10-10 added <,>,<=,>=, != operators support
  47. * added msg:len (andrei)
  48. * 2003-10-11 if(){} doesn't require a ';' after it anymore (andrei)
  49. * 2003-10-13 added FIFO_DIR & proto:host:port listen/alias support (andrei)
  50. * 2003-10-24 converted to the new socket_info lists (andrei)
  51. * 2003-10-28 added tcp_accept_aliases (andrei)
  52. * 2003-11-20 added {tcp_connect, tcp_send, tls_*}_timeout (andrei)
  53. * 2004-03-30 added DISABLE_CORE and OPEN_FD_LIMIT (andrei)
  54. * 2004-04-29 added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei)
  55. * 2004-05-03 applied multicast support patch (MCAST_LOOPBACK) from janakj
  56. * added MCAST_TTL (andrei)
  57. * 2004-07-05 src_ip & dst_ip will detect ip addresses between quotes
  58. * (andrei)
  59. * 2004-10-19 added FROM_URI, TO_URI (andrei)
  60. * 2004-11-30 added force_send_socket (andrei)
  61. * 2005-07-08 added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS
  62. * (andrei)
  63. * 2005-07-11 added DNS_RETR_TIME, DNS_RETR_NO, DNS_SERVERS_NO, DNS_USE_SEARCH,
  64. * DNS_TRY_IPV6 (andrei)
  65. * 2005-07-12 default onreply route added (andrei)
  66. * 2005-11-16 fixed if (cond) cmd; (andrei)
  67. * 2005-12-11 added onsend_route support, fcmd (filtered cmd),
  68. * snd_{ip,port,proto,af}, to_{ip,proto} (andrei)
  69. * 2005-12-19 select framework (mma)
  70. * 2006-01-06 AVP index support (mma)
  71. * 2005-01-07 optional semicolon in statement, PARAM_STR&PARAM_STRING
  72. * 2006-02-02 named flags support (andrei)
  73. * 2006-02-06 named routes support (andrei)
  74. * 2006-05-30 avp flags (tma)
  75. * 2006-09-11 added dns cache (use, flags, ttls, mem ,gc) & dst blacklist
  76. * options (andrei)
  77. * 2006-10-13 added STUN_ALLOW_STUN, STUN_ALLOW_FP, STUN_REFRESH_INTERVAL
  78. * (vlada)
  79. * 2007-02-09 separated command needed for tls-in-core and for tls in general
  80. * (andrei)
  81. * 2007-06-07 added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO,
  82. * RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO,
  83. * RT_TIMER2_POLICY (andrei)
  84. * 2007-06-16 added DDNS_SRV_LB, DNS_TRY_NAPTR (andrei)
  85. * 2007-09-10 introduced phone2tel option which allows NOT to consider
  86. * user=phone URIs as TEL URIs (jiri)
  87. * 2007-10-10 added DNS_SEARCH_FMATCH (mma)
  88. * 2007-11-28 added TCP_OPT_{FD_CACHE, DEFER_ACCEPT, DELAYED_ACK, SYNCNT,
  89. * LINGER2, KEEPALIVE, KEEPIDLE, KEEPINTVL, KEEPCNT} (andrei)
  90. * 2008-01-24 added cfg_var definition (Miklos)
  91. * 2008-11-18 support for variable parameter module functions (andrei)
  92. * 2007-12-03 support for generalised lvalues and rvalues:
  93. * lval=rval_expr, where lval=avp|pvar (andrei)
  94. * 2007-12-06 expression are now evaluated in terms of rvalues;
  95. * NUMBER is now always positive; cleanup (andrei)
  96. * 2009-01-26 case/switch() support (andrei)
  97. * 2009-03-10 added SET_USERPHONE action (Miklos)
  98. * 2009-05-04 switched if to rval_expr (andrei)
  99. */
  100. %{
  101. #include <stdlib.h>
  102. #include <stdio.h>
  103. #include <stdarg.h>
  104. #include <sys/types.h>
  105. #include <sys/socket.h>
  106. #include <netinet/in.h>
  107. #include <arpa/inet.h>
  108. #include <string.h>
  109. #include <errno.h>
  110. #include "route_struct.h"
  111. #include "globals.h"
  112. #include "route.h"
  113. #include "switch.h"
  114. #include "dprint.h"
  115. #include "sr_module.h"
  116. #include "modparam.h"
  117. #include "ip_addr.h"
  118. #include "resolve.h"
  119. #include "socket_info.h"
  120. #include "name_alias.h"
  121. #include "ut.h"
  122. #include "dset.h"
  123. #include "select.h"
  124. #include "flags.h"
  125. #include "tcp_init.h"
  126. #include "tcp_options.h"
  127. #include "sctp_options.h"
  128. #include "pvar.h"
  129. #include "lvalue.h"
  130. #include "rvalue.h"
  131. #include "sr_compat.h"
  132. #include "msg_translator.h"
  133. #include "config.h"
  134. #include "cfg_core.h"
  135. #include "cfg/cfg.h"
  136. #ifdef CORE_TLS
  137. #include "tls/tls_config.h"
  138. #endif
  139. #include "timer_ticks.h"
  140. #ifdef DEBUG_DMALLOC
  141. #include <dmalloc.h>
  142. #endif
  143. /* hack to avoid alloca usage in the generated C file (needed for compiler
  144. with no built in alloca, like icc*/
  145. #undef _ALLOCA_H
  146. #define onsend_check(s) \
  147. do{\
  148. if (rt!=ONSEND_ROUTE) yyerror( s " allowed only in onsend_routes");\
  149. }while(0)
  150. #ifdef USE_DNS_CACHE
  151. #define IF_DNS_CACHE(x) x
  152. #else
  153. #define IF_DNS_CACHE(x) warn("dns cache support not compiled in")
  154. #endif
  155. #ifdef USE_DNS_FAILOVER
  156. #define IF_DNS_FAILOVER(x) x
  157. #else
  158. #define IF_DNS_FAILOVER(x) warn("dns failover support not compiled in")
  159. #endif
  160. #ifdef USE_NAPTR
  161. #define IF_NAPTR(x) x
  162. #else
  163. #define IF_NAPTR(x) warn("dns naptr support not compiled in")
  164. #endif
  165. #ifdef USE_DST_BLACKLIST
  166. #define IF_DST_BLACKLIST(x) x
  167. #else
  168. #define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in")
  169. #endif
  170. #ifdef USE_STUN
  171. #define IF_STUN(x) x
  172. #else
  173. #define IF_STUN(x) warn("stun support not compiled in")
  174. #endif
  175. #ifdef USE_SCTP
  176. #define IF_SCTP(x) x
  177. #else
  178. #define IF_SCTP(x) warn("sctp support not compiled in")
  179. #endif
  180. extern int yylex();
  181. /* safer then using yytext which can be array or pointer */
  182. extern char* yy_number_str;
  183. static void yyerror(char* s, ...);
  184. static void yyerror_at(struct cfg_pos* pos, char* s, ...);
  185. static char* tmp;
  186. static int i_tmp;
  187. static unsigned u_tmp;
  188. static struct socket_id* lst_tmp;
  189. static struct name_lst* nl_tmp;
  190. static int rt; /* Type of route block for find_export */
  191. static str* str_tmp;
  192. static str s_tmp;
  193. static struct ip_addr* ip_tmp;
  194. static struct avp_spec* s_attr;
  195. static select_t sel;
  196. static select_t* sel_ptr;
  197. static pv_spec_t* pv_spec;
  198. static struct action *mod_func_action;
  199. static struct lvalue* lval_tmp;
  200. static struct rvalue* rval_tmp;
  201. static void warn(char* s, ...);
  202. static void warn_at(struct cfg_pos* pos, char* s, ...);
  203. static void get_cpos(struct cfg_pos* pos);
  204. static struct rval_expr* mk_rve_rval(enum rval_type, void* v);
  205. static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1);
  206. static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
  207. struct rval_expr* rve2);
  208. static int rval_expr_int_check(struct rval_expr *rve);
  209. static int warn_ct_rve(struct rval_expr *rve, char* name);
  210. static struct socket_id* mk_listen_id(char*, int, int);
  211. static struct name_lst* mk_name_lst(char* name, int flags);
  212. static struct socket_id* mk_listen_id2(struct name_lst*, int, int);
  213. static void free_name_lst(struct name_lst* lst);
  214. static void free_socket_id_lst(struct socket_id* i);
  215. static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re,
  216. struct action* a, int* err);
  217. static int case_check_type(struct case_stms* stms);
  218. static int case_check_default(struct case_stms* stms);
  219. extern int line;
  220. extern int column;
  221. extern int startcolumn;
  222. extern int startline;
  223. extern char *finame;
  224. #define set_cfg_pos(x) \
  225. do{\
  226. if(x) {\
  227. (x)->cline = line;\
  228. (x)->cfile = (finame!=0)?finame:((cfg_file!=0)?cfg_file:"default");\
  229. }\
  230. }while(0)
  231. %}
  232. %union {
  233. long intval;
  234. unsigned long uval;
  235. char* strval;
  236. struct expr* expr;
  237. struct action* action;
  238. struct case_stms* case_stms;
  239. struct net* ipnet;
  240. struct ip_addr* ipaddr;
  241. struct socket_id* sockid;
  242. struct name_lst* name_l;
  243. struct avp_spec* attr;
  244. struct _pv_spec* pvar;
  245. struct lvalue* lval;
  246. struct rvalue* rval;
  247. struct rval_expr* rv_expr;
  248. select_t* select;
  249. }
  250. /* terminals */
  251. /* keywords */
  252. %token FORWARD
  253. %token FORWARD_TCP
  254. %token FORWARD_TLS
  255. %token FORWARD_SCTP
  256. %token FORWARD_UDP
  257. %token SEND
  258. %token SEND_TCP
  259. %token EXIT
  260. %token DROP
  261. %token RETURN
  262. %token BREAK
  263. %token LOG_TOK
  264. %token ERROR
  265. %token ROUTE
  266. %token ROUTE_FAILURE
  267. %token ROUTE_ONREPLY
  268. %token ROUTE_BRANCH
  269. %token ROUTE_SEND
  270. %token ROUTE_EVENT
  271. %token EXEC
  272. %token SET_HOST
  273. %token SET_HOSTPORT
  274. %token SET_HOSTPORTTRANS
  275. %token PREFIX
  276. %token STRIP
  277. %token STRIP_TAIL
  278. %token SET_USERPHONE
  279. %token APPEND_BRANCH
  280. %token SET_USER
  281. %token SET_USERPASS
  282. %token SET_PORT
  283. %token SET_URI
  284. %token REVERT_URI
  285. %token FORCE_RPORT
  286. %token ADD_LOCAL_RPORT
  287. %token FORCE_TCP_ALIAS
  288. %token UDP_MTU
  289. %token UDP_MTU_TRY_PROTO
  290. %token IF
  291. %token ELSE
  292. %token SET_ADV_ADDRESS
  293. %token SET_ADV_PORT
  294. %token FORCE_SEND_SOCKET
  295. %token SET_FWD_NO_CONNECT
  296. %token SET_RPL_NO_CONNECT
  297. %token SET_FWD_CLOSE
  298. %token SET_RPL_CLOSE
  299. %token SWITCH
  300. %token CASE
  301. %token DEFAULT
  302. %token WHILE
  303. %token URIHOST
  304. %token URIPORT
  305. %token MAX_LEN
  306. %token SETFLAG
  307. %token RESETFLAG
  308. %token ISFLAGSET
  309. %token SETAVPFLAG
  310. %token RESETAVPFLAG
  311. %token ISAVPFLAGSET
  312. %token METHOD
  313. %token URI
  314. %token FROM_URI
  315. %token TO_URI
  316. %token SRCIP
  317. %token SRCPORT
  318. %token DSTIP
  319. %token DSTPORT
  320. %token TOIP
  321. %token TOPORT
  322. %token SNDIP
  323. %token SNDPORT
  324. %token SNDPROTO
  325. %token SNDAF
  326. %token PROTO
  327. %token AF
  328. %token MYSELF
  329. %token MSGLEN
  330. %token UDP
  331. %token TCP
  332. %token TLS
  333. %token SCTP
  334. /* config vars. */
  335. %token DEBUG_V
  336. %token FORK
  337. %token LOGSTDERROR
  338. %token LOGFACILITY
  339. %token LOGNAME
  340. %token LISTEN
  341. %token ALIAS
  342. %token SR_AUTO_ALIASES
  343. %token DNS
  344. %token REV_DNS
  345. %token DNS_TRY_IPV6
  346. %token DNS_TRY_NAPTR
  347. %token DNS_SRV_LB
  348. %token DNS_UDP_PREF
  349. %token DNS_TCP_PREF
  350. %token DNS_TLS_PREF
  351. %token DNS_SCTP_PREF
  352. %token DNS_RETR_TIME
  353. %token DNS_RETR_NO
  354. %token DNS_SERVERS_NO
  355. %token DNS_USE_SEARCH
  356. %token DNS_SEARCH_FMATCH
  357. %token DNS_CACHE_INIT
  358. %token DNS_USE_CACHE
  359. %token DNS_USE_FAILOVER
  360. %token DNS_CACHE_FLAGS
  361. %token DNS_CACHE_NEG_TTL
  362. %token DNS_CACHE_MIN_TTL
  363. %token DNS_CACHE_MAX_TTL
  364. %token DNS_CACHE_MEM
  365. %token DNS_CACHE_GC_INT
  366. %token DNS_CACHE_DEL_NONEXP
  367. /*blacklist*/
  368. %token DST_BLST_INIT
  369. %token USE_DST_BLST
  370. %token DST_BLST_MEM
  371. %token DST_BLST_TTL
  372. %token DST_BLST_GC_INT
  373. %token PORT
  374. %token STAT
  375. %token CHILDREN
  376. %token CHECK_VIA
  377. %token PHONE2TEL
  378. %token SYN_BRANCH
  379. %token MEMLOG
  380. %token MEMDBG
  381. %token MEMSUM
  382. %token SIP_WARNING
  383. %token SERVER_SIGNATURE
  384. %token SERVER_HEADER
  385. %token USER_AGENT_HEADER
  386. %token REPLY_TO_VIA
  387. %token LOADMODULE
  388. %token LOADPATH
  389. %token MODPARAM
  390. %token MAXBUFFER
  391. %token USER
  392. %token GROUP
  393. %token CHROOT
  394. %token WDIR
  395. %token MHOMED
  396. %token DISABLE_TCP
  397. %token TCP_ACCEPT_ALIASES
  398. %token TCP_CHILDREN
  399. %token TCP_CONNECT_TIMEOUT
  400. %token TCP_SEND_TIMEOUT
  401. %token TCP_CON_LIFETIME
  402. %token TCP_POLL_METHOD
  403. %token TCP_MAX_CONNECTIONS
  404. %token TCP_NO_CONNECT
  405. %token TCP_SOURCE_IPV4
  406. %token TCP_SOURCE_IPV6
  407. %token TCP_OPT_FD_CACHE
  408. %token TCP_OPT_BUF_WRITE
  409. %token TCP_OPT_CONN_WQ_MAX
  410. %token TCP_OPT_WQ_MAX
  411. %token TCP_OPT_RD_BUF
  412. %token TCP_OPT_WQ_BLK
  413. %token TCP_OPT_DEFER_ACCEPT
  414. %token TCP_OPT_DELAYED_ACK
  415. %token TCP_OPT_SYNCNT
  416. %token TCP_OPT_LINGER2
  417. %token TCP_OPT_KEEPALIVE
  418. %token TCP_OPT_KEEPIDLE
  419. %token TCP_OPT_KEEPINTVL
  420. %token TCP_OPT_KEEPCNT
  421. %token TCP_OPT_CRLF_PING
  422. %token DISABLE_TLS
  423. %token ENABLE_TLS
  424. %token TLSLOG
  425. %token TLS_PORT_NO
  426. %token TLS_METHOD
  427. %token TLS_HANDSHAKE_TIMEOUT
  428. %token TLS_SEND_TIMEOUT
  429. %token SSLv23
  430. %token SSLv2
  431. %token SSLv3
  432. %token TLSv1
  433. %token TLS_VERIFY
  434. %token TLS_REQUIRE_CERTIFICATE
  435. %token TLS_CERTIFICATE
  436. %token TLS_PRIVATE_KEY
  437. %token TLS_CA_LIST
  438. %token DISABLE_SCTP
  439. %token ENABLE_SCTP
  440. %token SCTP_CHILDREN
  441. %token SCTP_SOCKET_RCVBUF
  442. %token SCTP_SOCKET_SNDBUF
  443. %token SCTP_AUTOCLOSE
  444. %token SCTP_SEND_TTL
  445. %token SCTP_SEND_RETRIES
  446. %token SCTP_ASSOC_TRACKING
  447. %token SCTP_ASSOC_REUSE
  448. %token SCTP_MAX_ASSOCS
  449. %token SCTP_SRTO_INITIAL
  450. %token SCTP_SRTO_MAX
  451. %token SCTP_SRTO_MIN
  452. %token SCTP_ASOCMAXRXT
  453. %token SCTP_INIT_MAX_ATTEMPTS
  454. %token SCTP_INIT_MAX_TIMEO
  455. %token SCTP_HBINTERVAL
  456. %token SCTP_PATHMAXRXT
  457. %token SCTP_SACK_DELAY
  458. %token SCTP_SACK_FREQ
  459. %token SCTP_MAX_BURST
  460. %token ADVERTISED_ADDRESS
  461. %token ADVERTISED_PORT
  462. %token DISABLE_CORE
  463. %token OPEN_FD_LIMIT
  464. %token SHM_FORCE_ALLOC
  465. %token MLOCK_PAGES
  466. %token REAL_TIME
  467. %token RT_PRIO
  468. %token RT_POLICY
  469. %token RT_TIMER1_PRIO
  470. %token RT_TIMER1_POLICY
  471. %token RT_TIMER2_PRIO
  472. %token RT_TIMER2_POLICY
  473. %token MCAST_LOOPBACK
  474. %token MCAST_TTL
  475. %token TOS
  476. %token PMTU_DISCOVERY
  477. %token KILL_TIMEOUT
  478. %token MAX_WLOOPS
  479. %token CFG_DESCRIPTION
  480. %token SERVER_ID
  481. %token FLAGS_DECL
  482. %token AVPFLAGS_DECL
  483. %token ATTR_MARK
  484. %token SELECT_MARK
  485. %token ATTR_FROM
  486. %token ATTR_TO
  487. %token ATTR_FROMURI
  488. %token ATTR_TOURI
  489. %token ATTR_FROMUSER
  490. %token ATTR_TOUSER
  491. %token ATTR_FROMDOMAIN
  492. %token ATTR_TODOMAIN
  493. %token ATTR_GLOBAL
  494. %token ADDEQ
  495. %token STUN_REFRESH_INTERVAL
  496. %token STUN_ALLOW_STUN
  497. %token STUN_ALLOW_FP
  498. /* operators, C like precedence */
  499. %right EQUAL
  500. %left LOG_OR
  501. %left LOG_AND
  502. %left BIN_OR
  503. %left BIN_AND
  504. %left EQUAL_T DIFF MATCH INTEQ INTDIFF STREQ STRDIFF
  505. %left GT LT GTE LTE
  506. %left PLUS MINUS
  507. %left STAR SLASH MODULO
  508. %right NOT UNARY
  509. %right DEFINED
  510. %right INTCAST STRCAST
  511. %left DOT
  512. /* no precedence, they use () */
  513. %token STRLEN
  514. %token STREMPTY
  515. /* values */
  516. %token <intval> NUMBER
  517. %token <strval> ID
  518. %token <strval> NUM_ID
  519. %token <strval> STRING
  520. %token <strval> IPV6ADDR
  521. %token <strval> PVAR
  522. /* not clear yet if this is an avp or pvar */
  523. %token <strval> AVP_OR_PVAR
  524. %token <strval> EVENT_RT_NAME
  525. /* other */
  526. %token COMMA
  527. %token SEMICOLON
  528. %token RPAREN
  529. %token LPAREN
  530. %token LBRACE
  531. %token RBRACE
  532. %token LBRACK
  533. %token RBRACK
  534. %token CR
  535. %token COLON
  536. /*non-terminals */
  537. /*%type <expr> exp */
  538. %type <expr> exp_elem
  539. %type <intval> intno eint_op eint_op_onsend
  540. %type <intval> eip_op eip_op_onsend
  541. %type <action> action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action
  542. %type <action> switch_cmd while_cmd ret_cmd
  543. %type <case_stms> single_case case_stms
  544. %type <ipaddr> ipv4 ipv6 ipv6addr ip
  545. %type <ipnet> ipnet
  546. %type <strval> host host_or_if host_if_id
  547. %type <strval> listen_id
  548. %type <name_l> listen_id_lst
  549. %type <name_l> listen_id2
  550. %type <sockid> id_lst
  551. %type <sockid> phostport
  552. %type <sockid> listen_phostport
  553. %type <intval> proto port
  554. %type <intval> equalop strop cmpop rve_cmpop rve_equalop
  555. %type <intval> uri_type
  556. %type <attr> attr_id
  557. %type <attr> attr_id_num_idx
  558. %type <attr> attr_id_no_idx
  559. %type <attr> attr_id_ass
  560. /*%type <attr> attr_id_val*/
  561. %type <attr> attr_id_any
  562. %type <attr> attr_id_any_str
  563. %type <pvar> pvar
  564. %type <lval> lval
  565. %type <rv_expr> rval rval_expr ct_rval
  566. %type <lval> avp_pvar
  567. /* %type <intval> class_id */
  568. %type <intval> assign_op
  569. %type <select> select_id
  570. %type <strval> flag_name;
  571. %type <strval> route_name;
  572. %type <intval> avpflag_oper
  573. %type <intval> rve_un_op
  574. %type <strval> cfg_var_id
  575. /* %type <intval> rve_op */
  576. /*%type <route_el> rules;
  577. %type <route_el> rule;
  578. */
  579. %%
  580. cfg:
  581. statements
  582. ;
  583. statements:
  584. statements statement {}
  585. | statement {}
  586. | statements error { yyerror(""); YYABORT;}
  587. ;
  588. statement:
  589. assign_stm
  590. | flags_decl
  591. | avpflags_decl
  592. | module_stm
  593. | {rt=REQUEST_ROUTE;} route_stm
  594. | {rt=FAILURE_ROUTE;} failure_route_stm
  595. | {rt=ONREPLY_ROUTE;} onreply_route_stm
  596. | {rt=BRANCH_ROUTE;} branch_route_stm
  597. | {rt=ONSEND_ROUTE;} send_route_stm
  598. | {rt=EVENT_ROUTE;} event_route_stm
  599. | SEMICOLON /* null statement */
  600. | CR /* null statement*/
  601. ;
  602. listen_id:
  603. ip {
  604. if ($1){
  605. tmp=ip_addr2a($1);
  606. if (tmp==0) {
  607. LOG(L_CRIT, "ERROR: cfg. parser: bad ip "
  608. "address.\n");
  609. $$=0;
  610. } else {
  611. $$=pkg_malloc(strlen(tmp)+1);
  612. if ($$==0) {
  613. LOG(L_CRIT, "ERROR: cfg. parser: out of "
  614. "memory.\n");
  615. } else {
  616. strncpy($$, tmp, strlen(tmp)+1);
  617. }
  618. }
  619. }
  620. }
  621. | STRING {
  622. $$=pkg_malloc(strlen($1)+1);
  623. if ($$==0) {
  624. LOG(L_CRIT, "ERROR: cfg. parser: out of "
  625. "memory.\n");
  626. } else {
  627. strncpy($$, $1, strlen($1)+1);
  628. }
  629. }
  630. | host_or_if {
  631. if ($1){
  632. $$=pkg_malloc(strlen($1)+1);
  633. if ($$==0) {
  634. LOG(L_CRIT, "ERROR: cfg. parser: out of "
  635. "memory.\n");
  636. } else {
  637. strncpy($$, $1, strlen($1)+1);
  638. }
  639. }
  640. }
  641. ;
  642. listen_id_lst:
  643. listen_id { $$=mk_name_lst($1, SI_IS_MHOMED); }
  644. | listen_id COMMA listen_id_lst { $$=mk_name_lst($1, SI_IS_MHOMED);
  645. if ($$) $$->next=$3;
  646. }
  647. ;
  648. listen_id2:
  649. LPAREN listen_id_lst RPAREN { $$=$2; }
  650. | listen_id { $$=mk_name_lst($1, 0); }
  651. ;
  652. proto:
  653. UDP { $$=PROTO_UDP; }
  654. | TCP { $$=PROTO_TCP; }
  655. | TLS { $$=PROTO_TLS; }
  656. | SCTP { $$=PROTO_SCTP; }
  657. | STAR { $$=0; }
  658. ;
  659. port:
  660. NUMBER { $$=$1; }
  661. | STAR { $$=0; }
  662. ;
  663. phostport:
  664. listen_id { $$=mk_listen_id($1, 0, 0); }
  665. | listen_id COLON port { $$=mk_listen_id($1, 0, $3); }
  666. | proto COLON listen_id { $$=mk_listen_id($3, $1, 0); }
  667. | proto COLON listen_id COLON port { $$=mk_listen_id($3, $1, $5);}
  668. | listen_id COLON error { $$=0; yyerror(" port number expected"); }
  669. ;
  670. listen_phostport:
  671. listen_id2 { $$=mk_listen_id2($1, 0, 0); }
  672. | listen_id2 COLON port { $$=mk_listen_id2($1, 0, $3); }
  673. | proto COLON listen_id2 { $$=mk_listen_id2($3, $1, 0); }
  674. | proto COLON listen_id2 COLON port { $$=mk_listen_id2($3, $1, $5);}
  675. | listen_id2 COLON error { $$=0; yyerror(" port number expected"); }
  676. ;
  677. id_lst:
  678. listen_phostport { $$=$1 ; }
  679. | listen_phostport id_lst { $$=$1; if ($$) $$->next=$2; }
  680. ;
  681. intno: NUMBER
  682. | MINUS NUMBER %prec UNARY { $$=-$2; }
  683. ;
  684. flags_decl: FLAGS_DECL flag_list
  685. | FLAGS_DECL error { yyerror("flag list expected\n"); }
  686. ;
  687. flag_list: flag_spec
  688. | flag_spec COMMA flag_list
  689. ;
  690. flag_spec: flag_name { if (register_flag($1,-1)<0)
  691. yyerror("register flag failed");
  692. }
  693. | flag_name COLON NUMBER {
  694. if (register_flag($1, $3)<0)
  695. yyerror("register flag failed");
  696. }
  697. ;
  698. flag_name: STRING { $$=$1; }
  699. | ID { $$=$1; }
  700. ;
  701. avpflags_decl:
  702. AVPFLAGS_DECL avpflag_list
  703. | AVPFLAGS_DECL error { yyerror("avpflag list expected\n"); }
  704. ;
  705. avpflag_list:
  706. avpflag_spec
  707. | avpflag_spec COMMA avpflag_list
  708. ;
  709. avpflag_spec:
  710. flag_name {
  711. if (register_avpflag($1)==0)
  712. yyerror("cannot declare avpflag");
  713. }
  714. ;
  715. assign_stm:
  716. DEBUG_V EQUAL intno { default_core_cfg.debug=$3; }
  717. | DEBUG_V EQUAL error { yyerror("number expected"); }
  718. | FORK EQUAL NUMBER { dont_fork= ! $3; }
  719. | FORK EQUAL error { yyerror("boolean value expected"); }
  720. | LOGSTDERROR EQUAL NUMBER { if (!config_check) log_stderr=$3; }
  721. | LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
  722. | LOGFACILITY EQUAL ID {
  723. if ( (i_tmp=str2facility($3))==-1)
  724. yyerror("bad facility (see syslog(3) man page)");
  725. if (!config_check)
  726. default_core_cfg.log_facility=i_tmp;
  727. }
  728. | LOGFACILITY EQUAL error { yyerror("ID expected"); }
  729. | LOGNAME EQUAL STRING { log_name=$3; }
  730. | LOGNAME EQUAL error { yyerror("string value expected"); }
  731. | DNS EQUAL NUMBER { received_dns|= ($3)?DO_DNS:0; }
  732. | DNS EQUAL error { yyerror("boolean value expected"); }
  733. | REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
  734. | REV_DNS EQUAL error { yyerror("boolean value expected"); }
  735. | DNS_TRY_IPV6 EQUAL NUMBER { default_core_cfg.dns_try_ipv6=$3; }
  736. | DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
  737. | DNS_TRY_NAPTR EQUAL NUMBER { IF_NAPTR(default_core_cfg.dns_try_naptr=$3); }
  738. | DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
  739. | DNS_SRV_LB EQUAL NUMBER { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
  740. | DNS_SRV_LB error { yyerror("boolean value expected"); }
  741. | DNS_UDP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
  742. | DNS_UDP_PREF error { yyerror("number expected"); }
  743. | DNS_TCP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
  744. | DNS_TCP_PREF error { yyerror("number expected"); }
  745. | DNS_TLS_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
  746. | DNS_TLS_PREF error { yyerror("number expected"); }
  747. | DNS_SCTP_PREF EQUAL intno {
  748. IF_NAPTR(default_core_cfg.dns_sctp_pref=$3); }
  749. | DNS_SCTP_PREF error { yyerror("number expected"); }
  750. | DNS_RETR_TIME EQUAL NUMBER { default_core_cfg.dns_retr_time=$3; }
  751. | DNS_RETR_TIME error { yyerror("number expected"); }
  752. | DNS_RETR_NO EQUAL NUMBER { default_core_cfg.dns_retr_no=$3; }
  753. | DNS_RETR_NO error { yyerror("number expected"); }
  754. | DNS_SERVERS_NO EQUAL NUMBER { default_core_cfg.dns_servers_no=$3; }
  755. | DNS_SERVERS_NO error { yyerror("number expected"); }
  756. | DNS_USE_SEARCH EQUAL NUMBER { default_core_cfg.dns_search_list=$3; }
  757. | DNS_USE_SEARCH error { yyerror("boolean value expected"); }
  758. | DNS_SEARCH_FMATCH EQUAL NUMBER { default_core_cfg.dns_search_fmatch=$3; }
  759. | DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
  760. | DNS_CACHE_INIT EQUAL NUMBER { IF_DNS_CACHE(dns_cache_init=$3); }
  761. | DNS_CACHE_INIT error { yyerror("boolean value expected"); }
  762. | DNS_USE_CACHE EQUAL NUMBER { IF_DNS_CACHE(default_core_cfg.use_dns_cache=$3); }
  763. | DNS_USE_CACHE error { yyerror("boolean value expected"); }
  764. | DNS_USE_FAILOVER EQUAL NUMBER { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
  765. | DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
  766. | DNS_CACHE_FLAGS EQUAL NUMBER { IF_DNS_CACHE(default_core_cfg.dns_cache_flags=$3); }
  767. | DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
  768. | DNS_CACHE_NEG_TTL EQUAL NUMBER { IF_DNS_CACHE(default_core_cfg.dns_neg_cache_ttl=$3); }
  769. | DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
  770. | DNS_CACHE_MAX_TTL EQUAL NUMBER { IF_DNS_CACHE(default_core_cfg.dns_cache_max_ttl=$3); }
  771. | DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
  772. | DNS_CACHE_MIN_TTL EQUAL NUMBER { IF_DNS_CACHE(default_core_cfg.dns_cache_min_ttl=$3); }
  773. | DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
  774. | DNS_CACHE_MEM EQUAL NUMBER { IF_DNS_CACHE(default_core_cfg.dns_cache_max_mem=$3); }
  775. | DNS_CACHE_MEM error { yyerror("boolean value expected"); }
  776. | DNS_CACHE_GC_INT EQUAL NUMBER { IF_DNS_CACHE(dns_timer_interval=$3); }
  777. | DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
  778. | DNS_CACHE_DEL_NONEXP EQUAL NUMBER { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
  779. | DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
  780. | DST_BLST_INIT EQUAL NUMBER { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
  781. | DST_BLST_INIT error { yyerror("boolean value expected"); }
  782. | USE_DST_BLST EQUAL NUMBER { IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3); }
  783. | USE_DST_BLST error { yyerror("boolean value expected"); }
  784. | DST_BLST_MEM EQUAL NUMBER { IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3); }
  785. | DST_BLST_MEM error { yyerror("boolean value expected"); }
  786. | DST_BLST_TTL EQUAL NUMBER { IF_DST_BLACKLIST(default_core_cfg.blst_timeout=$3); }
  787. | DST_BLST_TTL error { yyerror("boolean value expected"); }
  788. | DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLACKLIST(blst_timer_interval=$3);}
  789. | DST_BLST_GC_INT error { yyerror("boolean value expected"); }
  790. | PORT EQUAL NUMBER { port_no=$3; }
  791. | STAT EQUAL STRING {
  792. #ifdef STATS
  793. stat_file=$3;
  794. #endif
  795. }
  796. | MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
  797. | MAXBUFFER EQUAL error { yyerror("number expected"); }
  798. | PORT EQUAL error { yyerror("number expected"); }
  799. | CHILDREN EQUAL NUMBER { children_no=$3; }
  800. | CHILDREN EQUAL error { yyerror("number expected"); }
  801. | CHECK_VIA EQUAL NUMBER { check_via=$3; }
  802. | CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
  803. | PHONE2TEL EQUAL NUMBER { phone2tel=$3; }
  804. | PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
  805. | SYN_BRANCH EQUAL NUMBER { syn_branch=$3; }
  806. | SYN_BRANCH EQUAL error { yyerror("boolean value expected"); }
  807. | MEMLOG EQUAL intno { default_core_cfg.memlog=$3; }
  808. | MEMLOG EQUAL error { yyerror("int value expected"); }
  809. | MEMDBG EQUAL intno { default_core_cfg.memdbg=$3; }
  810. | MEMDBG EQUAL error { yyerror("int value expected"); }
  811. | MEMSUM EQUAL intno { default_core_cfg.mem_summary=$3; }
  812. | MEMSUM EQUAL error { yyerror("int value expected"); }
  813. | SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
  814. | SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
  815. | USER EQUAL STRING { user=$3; }
  816. | USER EQUAL ID { user=$3; }
  817. | USER EQUAL error { yyerror("string value expected"); }
  818. | GROUP EQUAL STRING { group=$3; }
  819. | GROUP EQUAL ID { group=$3; }
  820. | GROUP EQUAL error { yyerror("string value expected"); }
  821. | CHROOT EQUAL STRING { chroot_dir=$3; }
  822. | CHROOT EQUAL ID { chroot_dir=$3; }
  823. | CHROOT EQUAL error { yyerror("string value expected"); }
  824. | WDIR EQUAL STRING { working_dir=$3; }
  825. | WDIR EQUAL ID { working_dir=$3; }
  826. | WDIR EQUAL error { yyerror("string value expected"); }
  827. | MHOMED EQUAL NUMBER { mhomed=$3; }
  828. | MHOMED EQUAL error { yyerror("boolean value expected"); }
  829. | DISABLE_TCP EQUAL NUMBER {
  830. #ifdef USE_TCP
  831. tcp_disable=$3;
  832. #else
  833. warn("tcp support not compiled in");
  834. #endif
  835. }
  836. | DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
  837. | TCP_ACCEPT_ALIASES EQUAL NUMBER {
  838. #ifdef USE_TCP
  839. tcp_default_cfg.accept_aliases=$3;
  840. #else
  841. warn("tcp support not compiled in");
  842. #endif
  843. }
  844. | TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
  845. | TCP_CHILDREN EQUAL NUMBER {
  846. #ifdef USE_TCP
  847. tcp_children_no=$3;
  848. #else
  849. warn("tcp support not compiled in");
  850. #endif
  851. }
  852. | TCP_CHILDREN EQUAL error { yyerror("number expected"); }
  853. | TCP_CONNECT_TIMEOUT EQUAL intno {
  854. #ifdef USE_TCP
  855. tcp_default_cfg.connect_timeout_s=$3;
  856. #else
  857. warn("tcp support not compiled in");
  858. #endif
  859. }
  860. | TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
  861. | TCP_SEND_TIMEOUT EQUAL intno {
  862. #ifdef USE_TCP
  863. tcp_default_cfg.send_timeout=S_TO_TICKS($3);
  864. #else
  865. warn("tcp support not compiled in");
  866. #endif
  867. }
  868. | TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
  869. | TCP_CON_LIFETIME EQUAL intno {
  870. #ifdef USE_TCP
  871. if ($3<0)
  872. tcp_default_cfg.con_lifetime=-1;
  873. else
  874. tcp_default_cfg.con_lifetime=S_TO_TICKS($3);
  875. #else
  876. warn("tcp support not compiled in");
  877. #endif
  878. }
  879. | TCP_CON_LIFETIME EQUAL error { yyerror("number expected"); }
  880. | TCP_POLL_METHOD EQUAL ID {
  881. #ifdef USE_TCP
  882. tcp_poll_method=get_poll_type($3);
  883. if (tcp_poll_method==POLL_NONE) {
  884. LOG(L_CRIT, "bad poll method name:"
  885. " %s\n, try one of %s.\n",
  886. $3, poll_support);
  887. yyerror("bad tcp_poll_method "
  888. "value");
  889. }
  890. #else
  891. warn("tcp support not compiled in");
  892. #endif
  893. }
  894. | TCP_POLL_METHOD EQUAL STRING {
  895. #ifdef USE_TCP
  896. tcp_poll_method=get_poll_type($3);
  897. if (tcp_poll_method==POLL_NONE) {
  898. LOG(L_CRIT, "bad poll method name:"
  899. " %s\n, try one of %s.\n",
  900. $3, poll_support);
  901. yyerror("bad tcp_poll_method "
  902. "value");
  903. }
  904. #else
  905. warn("tcp support not compiled in");
  906. #endif
  907. }
  908. | TCP_POLL_METHOD EQUAL error { yyerror("poll method name expected"); }
  909. | TCP_MAX_CONNECTIONS EQUAL NUMBER {
  910. #ifdef USE_TCP
  911. tcp_max_connections=$3;
  912. #else
  913. warn("tcp support not compiled in");
  914. #endif
  915. }
  916. | TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
  917. | TCP_NO_CONNECT EQUAL NUMBER {
  918. #ifdef USE_TCP
  919. tcp_default_cfg.no_connect=$3;
  920. #else
  921. warn("tcp support not compiled in");
  922. #endif
  923. }
  924. | TCP_NO_CONNECT EQUAL error { yyerror("boolean value expected"); }
  925. | TCP_SOURCE_IPV4 EQUAL ipv4 {
  926. #ifdef USE_TCP
  927. if (tcp_set_src_addr($3)<0)
  928. warn("tcp_source_ipv4 failed");
  929. #else
  930. warn("tcp support not compiled in");
  931. #endif
  932. pkg_free($3);
  933. }
  934. | TCP_SOURCE_IPV4 EQUAL error { yyerror("IPv4 address expected"); }
  935. | TCP_SOURCE_IPV6 EQUAL ipv6 {
  936. #ifdef USE_TCP
  937. #ifdef USE_IPV6
  938. if (tcp_set_src_addr($3)<0)
  939. warn("tcp_source_ipv6 failed");
  940. #else
  941. warn("IPv6 support not compiled in");
  942. #endif
  943. #else
  944. warn("tcp support not compiled in");
  945. #endif
  946. pkg_free($3);
  947. }
  948. | TCP_SOURCE_IPV6 EQUAL error { yyerror("IPv6 address expected"); }
  949. | TCP_OPT_FD_CACHE EQUAL NUMBER {
  950. #ifdef USE_TCP
  951. tcp_default_cfg.fd_cache=$3;
  952. #else
  953. warn("tcp support not compiled in");
  954. #endif
  955. }
  956. | TCP_OPT_FD_CACHE EQUAL error { yyerror("boolean value expected"); }
  957. | TCP_OPT_BUF_WRITE EQUAL NUMBER {
  958. #ifdef USE_TCP
  959. tcp_default_cfg.async=$3;
  960. #else
  961. warn("tcp support not compiled in");
  962. #endif
  963. }
  964. | TCP_OPT_BUF_WRITE EQUAL error { yyerror("boolean value expected"); }
  965. | TCP_OPT_CONN_WQ_MAX EQUAL NUMBER {
  966. #ifdef USE_TCP
  967. tcp_default_cfg.tcpconn_wq_max=$3;
  968. #else
  969. warn("tcp support not compiled in");
  970. #endif
  971. }
  972. | TCP_OPT_CONN_WQ_MAX error { yyerror("boolean value expected"); }
  973. | TCP_OPT_WQ_MAX EQUAL NUMBER {
  974. #ifdef USE_TCP
  975. tcp_default_cfg.tcp_wq_max=$3;
  976. #else
  977. warn("tcp support not compiled in");
  978. #endif
  979. }
  980. | TCP_OPT_WQ_MAX error { yyerror("number expected"); }
  981. | TCP_OPT_RD_BUF EQUAL NUMBER {
  982. #ifdef USE_TCP
  983. tcp_default_cfg.rd_buf_size=$3;
  984. #else
  985. warn("tcp support not compiled in");
  986. #endif
  987. }
  988. | TCP_OPT_RD_BUF error { yyerror("number expected"); }
  989. | TCP_OPT_WQ_BLK EQUAL NUMBER {
  990. #ifdef USE_TCP
  991. tcp_default_cfg.wq_blk_size=$3;
  992. #else
  993. warn("tcp support not compiled in");
  994. #endif
  995. }
  996. | TCP_OPT_WQ_BLK error { yyerror("number expected"); }
  997. | TCP_OPT_DEFER_ACCEPT EQUAL NUMBER {
  998. #ifdef USE_TCP
  999. tcp_default_cfg.defer_accept=$3;
  1000. #else
  1001. warn("tcp support not compiled in");
  1002. #endif
  1003. }
  1004. | TCP_OPT_DEFER_ACCEPT EQUAL error { yyerror("boolean value expected"); }
  1005. | TCP_OPT_DELAYED_ACK EQUAL NUMBER {
  1006. #ifdef USE_TCP
  1007. tcp_default_cfg.delayed_ack=$3;
  1008. #else
  1009. warn("tcp support not compiled in");
  1010. #endif
  1011. }
  1012. | TCP_OPT_DELAYED_ACK EQUAL error { yyerror("boolean value expected"); }
  1013. | TCP_OPT_SYNCNT EQUAL NUMBER {
  1014. #ifdef USE_TCP
  1015. tcp_default_cfg.syncnt=$3;
  1016. #else
  1017. warn("tcp support not compiled in");
  1018. #endif
  1019. }
  1020. | TCP_OPT_SYNCNT EQUAL error { yyerror("number expected"); }
  1021. | TCP_OPT_LINGER2 EQUAL NUMBER {
  1022. #ifdef USE_TCP
  1023. tcp_default_cfg.linger2=$3;
  1024. #else
  1025. warn("tcp support not compiled in");
  1026. #endif
  1027. }
  1028. | TCP_OPT_LINGER2 EQUAL error { yyerror("number expected"); }
  1029. | TCP_OPT_KEEPALIVE EQUAL NUMBER {
  1030. #ifdef USE_TCP
  1031. tcp_default_cfg.keepalive=$3;
  1032. #else
  1033. warn("tcp support not compiled in");
  1034. #endif
  1035. }
  1036. | TCP_OPT_KEEPALIVE EQUAL error { yyerror("boolean value expected");}
  1037. | TCP_OPT_KEEPIDLE EQUAL NUMBER {
  1038. #ifdef USE_TCP
  1039. tcp_default_cfg.keepidle=$3;
  1040. #else
  1041. warn("tcp support not compiled in");
  1042. #endif
  1043. }
  1044. | TCP_OPT_KEEPIDLE EQUAL error { yyerror("number expected"); }
  1045. | TCP_OPT_KEEPINTVL EQUAL NUMBER {
  1046. #ifdef USE_TCP
  1047. tcp_default_cfg.keepintvl=$3;
  1048. #else
  1049. warn("tcp support not compiled in");
  1050. #endif
  1051. }
  1052. | TCP_OPT_KEEPINTVL EQUAL error { yyerror("number expected"); }
  1053. | TCP_OPT_KEEPCNT EQUAL NUMBER {
  1054. #ifdef USE_TCP
  1055. tcp_default_cfg.keepcnt=$3;
  1056. #else
  1057. warn("tcp support not compiled in");
  1058. #endif
  1059. }
  1060. | TCP_OPT_KEEPCNT EQUAL error { yyerror("number expected"); }
  1061. | TCP_OPT_CRLF_PING EQUAL NUMBER {
  1062. #ifdef USE_TCP
  1063. tcp_default_cfg.crlf_ping=$3;
  1064. #else
  1065. warn("tcp support not compiled in");
  1066. #endif
  1067. }
  1068. | TCP_OPT_CRLF_PING EQUAL error { yyerror("boolean value expected"); }
  1069. | DISABLE_TLS EQUAL NUMBER {
  1070. #ifdef USE_TLS
  1071. tls_disable=$3;
  1072. #else
  1073. warn("tls support not compiled in");
  1074. #endif
  1075. }
  1076. | DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
  1077. | ENABLE_TLS EQUAL NUMBER {
  1078. #ifdef USE_TLS
  1079. tls_disable=!($3);
  1080. #else
  1081. warn("tls support not compiled in");
  1082. #endif
  1083. }
  1084. | ENABLE_TLS EQUAL error { yyerror("boolean value expected"); }
  1085. | TLSLOG EQUAL NUMBER {
  1086. #ifdef CORE_TLS
  1087. tls_log=$3;
  1088. #else
  1089. warn("tls-in-core support not compiled in");
  1090. #endif
  1091. }
  1092. | TLSLOG EQUAL error { yyerror("int value expected"); }
  1093. | TLS_PORT_NO EQUAL NUMBER {
  1094. #ifdef USE_TLS
  1095. tls_port_no=$3;
  1096. #else
  1097. warn("tls support not compiled in");
  1098. #endif
  1099. }
  1100. | TLS_PORT_NO EQUAL error { yyerror("number expected"); }
  1101. | TLS_METHOD EQUAL SSLv23 {
  1102. #ifdef CORE_TLS
  1103. tls_method=TLS_USE_SSLv23;
  1104. #else
  1105. warn("tls-in-core support not compiled in");
  1106. #endif
  1107. }
  1108. | TLS_METHOD EQUAL SSLv2 {
  1109. #ifdef CORE_TLS
  1110. tls_method=TLS_USE_SSLv2;
  1111. #else
  1112. warn("tls-in-core support not compiled in");
  1113. #endif
  1114. }
  1115. | TLS_METHOD EQUAL SSLv3 {
  1116. #ifdef CORE_TLS
  1117. tls_method=TLS_USE_SSLv3;
  1118. #else
  1119. warn("tls-in-core support not compiled in");
  1120. #endif
  1121. }
  1122. | TLS_METHOD EQUAL TLSv1 {
  1123. #ifdef CORE_TLS
  1124. tls_method=TLS_USE_TLSv1;
  1125. #else
  1126. warn("tls-in-core support not compiled in");
  1127. #endif
  1128. }
  1129. | TLS_METHOD EQUAL error {
  1130. #ifdef CORE_TLS
  1131. yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected");
  1132. #else
  1133. warn("tls-in-core support not compiled in");
  1134. #endif
  1135. }
  1136. | TLS_VERIFY EQUAL NUMBER {
  1137. #ifdef CORE_TLS
  1138. tls_verify_cert=$3;
  1139. #else
  1140. warn("tls-in-core support not compiled in");
  1141. #endif
  1142. }
  1143. | TLS_VERIFY EQUAL error { yyerror("boolean value expected"); }
  1144. | TLS_REQUIRE_CERTIFICATE EQUAL NUMBER {
  1145. #ifdef CORE_TLS
  1146. tls_require_cert=$3;
  1147. #else
  1148. warn( "tls-in-core support not compiled in");
  1149. #endif
  1150. }
  1151. | TLS_REQUIRE_CERTIFICATE EQUAL error { yyerror("boolean value expected"); }
  1152. | TLS_CERTIFICATE EQUAL STRING {
  1153. #ifdef CORE_TLS
  1154. tls_cert_file=$3;
  1155. #else
  1156. warn("tls-in-core support not compiled in");
  1157. #endif
  1158. }
  1159. | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
  1160. | TLS_PRIVATE_KEY EQUAL STRING {
  1161. #ifdef CORE_TLS
  1162. tls_pkey_file=$3;
  1163. #else
  1164. warn("tls-in-core support not compiled in");
  1165. #endif
  1166. }
  1167. | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
  1168. | TLS_CA_LIST EQUAL STRING {
  1169. #ifdef CORE_TLS
  1170. tls_ca_file=$3;
  1171. #else
  1172. warn("tls-in-core support not compiled in");
  1173. #endif
  1174. }
  1175. | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
  1176. | TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
  1177. #ifdef CORE_TLS
  1178. tls_handshake_timeout=$3;
  1179. #else
  1180. warn("tls-in-core support not compiled in");
  1181. #endif
  1182. }
  1183. | TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
  1184. | TLS_SEND_TIMEOUT EQUAL NUMBER {
  1185. #ifdef CORE_TLS
  1186. tls_send_timeout=$3;
  1187. #else
  1188. warn("tls-in-core support not compiled in");
  1189. #endif
  1190. }
  1191. | TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
  1192. | DISABLE_SCTP EQUAL NUMBER {
  1193. #ifdef USE_SCTP
  1194. sctp_disable=$3;
  1195. #else
  1196. warn("sctp support not compiled in");
  1197. #endif
  1198. }
  1199. | DISABLE_SCTP EQUAL error { yyerror("boolean value expected"); }
  1200. | ENABLE_SCTP EQUAL NUMBER {
  1201. #ifdef USE_SCTP
  1202. sctp_disable=($3<=1)?!$3:$3;
  1203. #else
  1204. warn("sctp support not compiled in");
  1205. #endif
  1206. }
  1207. | ENABLE_SCTP EQUAL error { yyerror("boolean or number expected"); }
  1208. | SCTP_CHILDREN EQUAL NUMBER {
  1209. #ifdef USE_SCTP
  1210. sctp_children_no=$3;
  1211. #else
  1212. warn("sctp support not compiled in");
  1213. #endif
  1214. }
  1215. | SCTP_CHILDREN EQUAL error { yyerror("number expected"); }
  1216. | SCTP_SOCKET_RCVBUF EQUAL NUMBER {
  1217. #ifdef USE_SCTP
  1218. sctp_default_cfg.so_rcvbuf=$3;
  1219. #else
  1220. warn("sctp support not compiled in");
  1221. #endif
  1222. }
  1223. | SCTP_SOCKET_RCVBUF EQUAL error { yyerror("number expected"); }
  1224. | SCTP_SOCKET_SNDBUF EQUAL NUMBER {
  1225. #ifdef USE_SCTP
  1226. sctp_default_cfg.so_sndbuf=$3;
  1227. #else
  1228. warn("sctp support not compiled in");
  1229. #endif
  1230. }
  1231. | SCTP_SOCKET_SNDBUF EQUAL error { yyerror("number expected"); }
  1232. | SCTP_AUTOCLOSE EQUAL NUMBER {
  1233. #ifdef USE_SCTP
  1234. sctp_default_cfg.autoclose=$3;
  1235. #else
  1236. warn("sctp support not compiled in");
  1237. #endif
  1238. }
  1239. | SCTP_AUTOCLOSE EQUAL error { yyerror("number expected"); }
  1240. | SCTP_SEND_TTL EQUAL NUMBER {
  1241. #ifdef USE_SCTP
  1242. sctp_default_cfg.send_ttl=$3;
  1243. #else
  1244. warn("sctp support not compiled in");
  1245. #endif
  1246. }
  1247. | SCTP_SEND_TTL EQUAL error { yyerror("number expected"); }
  1248. | SCTP_SEND_RETRIES EQUAL NUMBER {
  1249. #ifdef USE_SCTP
  1250. sctp_default_cfg.send_retries=$3;
  1251. #else
  1252. warn("sctp support not compiled in");
  1253. #endif
  1254. }
  1255. | SCTP_SEND_RETRIES EQUAL error { yyerror("number expected"); }
  1256. | SCTP_ASSOC_TRACKING EQUAL NUMBER {
  1257. #ifdef USE_SCTP
  1258. #ifdef SCTP_CONN_REUSE
  1259. sctp_default_cfg.assoc_tracking=$3;
  1260. #else
  1261. if ($3)
  1262. warn("sctp association tracking/reuse (SCTP_CONN_REUSE) "
  1263. "support not compiled in");
  1264. #endif /* SCTP_CONN_REUSE */
  1265. #else
  1266. warn("sctp support not compiled in");
  1267. #endif /* USE_SCTP */
  1268. }
  1269. | SCTP_ASSOC_TRACKING EQUAL error { yyerror("number expected"); }
  1270. | SCTP_ASSOC_REUSE EQUAL NUMBER {
  1271. #ifdef USE_SCTP
  1272. #ifdef SCTP_CONN_REUSE
  1273. sctp_default_cfg.assoc_reuse=$3;
  1274. #else
  1275. if ($3)
  1276. warn("sctp association reuse (SCTP_CONN_REUSE) support"
  1277. " not compiled in");
  1278. #endif /* SCTP_CONN_REUSE */
  1279. #else
  1280. warn("sctp support not compiled in");
  1281. #endif /* USE_SCTP */
  1282. }
  1283. | SCTP_ASSOC_REUSE EQUAL error { yyerror("number expected"); }
  1284. | SCTP_MAX_ASSOCS EQUAL intno {
  1285. IF_SCTP(sctp_default_cfg.max_assocs=$3);
  1286. }
  1287. | SCTP_MAX_ASSOCS EQUAL error { yyerror("number expected"); }
  1288. | SCTP_SRTO_INITIAL EQUAL NUMBER {
  1289. IF_SCTP(sctp_default_cfg.srto_initial=$3);
  1290. }
  1291. | SCTP_SRTO_INITIAL EQUAL error { yyerror("number expected"); }
  1292. | SCTP_SRTO_MAX EQUAL NUMBER {
  1293. IF_SCTP(sctp_default_cfg.srto_max=$3);
  1294. }
  1295. | SCTP_SRTO_MAX EQUAL error { yyerror("number expected"); }
  1296. | SCTP_SRTO_MIN EQUAL NUMBER {
  1297. IF_SCTP(sctp_default_cfg.srto_min=$3);
  1298. }
  1299. | SCTP_SRTO_MIN EQUAL error { yyerror("number expected"); }
  1300. | SCTP_ASOCMAXRXT EQUAL NUMBER {
  1301. IF_SCTP(sctp_default_cfg.asocmaxrxt=$3);
  1302. }
  1303. | SCTP_ASOCMAXRXT EQUAL error { yyerror("number expected"); }
  1304. | SCTP_INIT_MAX_ATTEMPTS EQUAL NUMBER {
  1305. IF_SCTP(sctp_default_cfg.init_max_attempts=$3);
  1306. }
  1307. | SCTP_INIT_MAX_ATTEMPTS EQUAL error { yyerror("number expected"); }
  1308. | SCTP_INIT_MAX_TIMEO EQUAL NUMBER {
  1309. IF_SCTP(sctp_default_cfg.init_max_timeo=$3);
  1310. }
  1311. | SCTP_INIT_MAX_TIMEO EQUAL error { yyerror("number expected"); }
  1312. | SCTP_HBINTERVAL EQUAL intno {
  1313. IF_SCTP(sctp_default_cfg.hbinterval=$3);
  1314. }
  1315. | SCTP_HBINTERVAL EQUAL error { yyerror("number expected"); }
  1316. | SCTP_PATHMAXRXT EQUAL NUMBER {
  1317. IF_SCTP(sctp_default_cfg.pathmaxrxt=$3);
  1318. }
  1319. | SCTP_PATHMAXRXT EQUAL error { yyerror("number expected"); }
  1320. | SCTP_SACK_DELAY EQUAL NUMBER {
  1321. IF_SCTP(sctp_default_cfg.sack_delay=$3);
  1322. }
  1323. | SCTP_SACK_DELAY EQUAL error { yyerror("number expected"); }
  1324. | SCTP_SACK_FREQ EQUAL NUMBER {
  1325. IF_SCTP(sctp_default_cfg.sack_freq=$3);
  1326. }
  1327. | SCTP_SACK_FREQ EQUAL error { yyerror("number expected"); }
  1328. | SCTP_MAX_BURST EQUAL NUMBER {
  1329. IF_SCTP(sctp_default_cfg.max_burst=$3);
  1330. }
  1331. | SCTP_MAX_BURST EQUAL error { yyerror("number expected"); }
  1332. | SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
  1333. | SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
  1334. | SERVER_HEADER EQUAL STRING { server_hdr.s=$3;
  1335. server_hdr.len=strlen(server_hdr.s);
  1336. }
  1337. | SERVER_HEADER EQUAL error { yyerror("string value expected"); }
  1338. | USER_AGENT_HEADER EQUAL STRING { user_agent_hdr.s=$3;
  1339. user_agent_hdr.len=strlen(user_agent_hdr.s);
  1340. }
  1341. | USER_AGENT_HEADER EQUAL error { yyerror("string value expected"); }
  1342. | REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; }
  1343. | REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
  1344. | LISTEN EQUAL id_lst {
  1345. for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
  1346. if (add_listen_iface( lst_tmp->addr_lst->name,
  1347. lst_tmp->addr_lst->next,
  1348. lst_tmp->port, lst_tmp->proto,
  1349. lst_tmp->flags)!=0) {
  1350. LOG(L_CRIT, "ERROR: cfg. parser: failed to add listen"
  1351. " address\n");
  1352. break;
  1353. }
  1354. }
  1355. free_socket_id_lst($3);
  1356. }
  1357. | LISTEN EQUAL error { yyerror("ip address, interface name or"
  1358. " hostname expected"); }
  1359. | ALIAS EQUAL id_lst {
  1360. for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
  1361. add_alias( lst_tmp->addr_lst->name,
  1362. strlen(lst_tmp->addr_lst->name),
  1363. lst_tmp->port, lst_tmp->proto);
  1364. for (nl_tmp=lst_tmp->addr_lst->next; nl_tmp; nl_tmp=nl_tmp->next)
  1365. add_alias(nl_tmp->name, strlen(nl_tmp->name),
  1366. lst_tmp->port, lst_tmp->proto);
  1367. }
  1368. free_socket_id_lst($3);
  1369. }
  1370. | ALIAS EQUAL error { yyerror(" hostname expected"); }
  1371. | SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; }
  1372. | SR_AUTO_ALIASES EQUAL error { yyerror("boolean value expected"); }
  1373. | ADVERTISED_ADDRESS EQUAL listen_id {
  1374. if ($3){
  1375. default_global_address.s=$3;
  1376. default_global_address.len=strlen($3);
  1377. }
  1378. }
  1379. | ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname expected"); }
  1380. | ADVERTISED_PORT EQUAL NUMBER {
  1381. tmp=int2str($3, &i_tmp);
  1382. if ((default_global_port.s=pkg_malloc(i_tmp))==0) {
  1383. LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
  1384. default_global_port.len=0;
  1385. } else {
  1386. default_global_port.len=i_tmp;
  1387. memcpy(default_global_port.s, tmp, default_global_port.len);
  1388. };
  1389. }
  1390. |ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname expected"); }
  1391. | DISABLE_CORE EQUAL NUMBER { disable_core_dump=$3; }
  1392. | DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
  1393. | OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
  1394. | OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
  1395. | SHM_FORCE_ALLOC EQUAL NUMBER { shm_force_alloc=$3; }
  1396. | SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
  1397. | MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
  1398. | MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
  1399. | REAL_TIME EQUAL NUMBER { real_time=$3; }
  1400. | REAL_TIME EQUAL error { yyerror("boolean value expected"); }
  1401. | RT_PRIO EQUAL NUMBER { rt_prio=$3; }
  1402. | RT_PRIO EQUAL error { yyerror("boolean value expected"); }
  1403. | RT_POLICY EQUAL NUMBER { rt_policy=$3; }
  1404. | RT_POLICY EQUAL error { yyerror("boolean value expected"); }
  1405. | RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
  1406. | RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
  1407. | RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
  1408. | RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
  1409. | RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
  1410. | RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
  1411. | RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
  1412. | RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
  1413. | MCAST_LOOPBACK EQUAL NUMBER {
  1414. #ifdef USE_MCAST
  1415. mcast_loopback=$3;
  1416. #else
  1417. warn("no multicast support compiled in");
  1418. #endif
  1419. }
  1420. | MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
  1421. | MCAST_TTL EQUAL NUMBER {
  1422. #ifdef USE_MCAST
  1423. mcast_ttl=$3;
  1424. #else
  1425. warn("no multicast support compiled in");
  1426. #endif
  1427. }
  1428. | MCAST_TTL EQUAL error { yyerror("number expected"); }
  1429. | TOS EQUAL NUMBER { tos=$3; }
  1430. | TOS EQUAL error { yyerror("number expected"); }
  1431. | PMTU_DISCOVERY EQUAL NUMBER { pmtu_discovery=$3; }
  1432. | PMTU_DISCOVERY error { yyerror("number expected"); }
  1433. | KILL_TIMEOUT EQUAL NUMBER { ser_kill_timeout=$3; }
  1434. | KILL_TIMEOUT EQUAL error { yyerror("number expected"); }
  1435. | MAX_WLOOPS EQUAL NUMBER { default_core_cfg.max_while_loops=$3; }
  1436. | MAX_WLOOPS EQUAL error { yyerror("number expected"); }
  1437. | STUN_REFRESH_INTERVAL EQUAL NUMBER { IF_STUN(stun_refresh_interval=$3); }
  1438. | STUN_REFRESH_INTERVAL EQUAL error{ yyerror("number expected"); }
  1439. | STUN_ALLOW_STUN EQUAL NUMBER { IF_STUN(stun_allow_stun=$3); }
  1440. | STUN_ALLOW_STUN EQUAL error{ yyerror("number expected"); }
  1441. | STUN_ALLOW_FP EQUAL NUMBER { IF_STUN(stun_allow_fp=$3) ; }
  1442. | STUN_ALLOW_FP EQUAL error{ yyerror("number expected"); }
  1443. | SERVER_ID EQUAL NUMBER { server_id=$3; }
  1444. | UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
  1445. | UDP_MTU EQUAL error { yyerror("number expected"); }
  1446. | FORCE_RPORT EQUAL NUMBER
  1447. { default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
  1448. | FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
  1449. | UDP_MTU_TRY_PROTO EQUAL proto
  1450. { default_core_cfg.udp_mtu_try_proto=$3; fix_global_req_flags(0, 0); }
  1451. | UDP_MTU_TRY_PROTO EQUAL error
  1452. { yyerror("TCP, TLS, SCTP or UDP expected"); }
  1453. | cfg_var
  1454. | error EQUAL { yyerror("unknown config variable"); }
  1455. ;
  1456. cfg_var_id: ID
  1457. | DEFAULT { $$="default" ; } /*needed to allow default as cfg var. name*/
  1458. ;
  1459. cfg_var:
  1460. cfg_var_id DOT cfg_var_id EQUAL NUMBER {
  1461. if (cfg_declare_int($1, $3, $5, 0, 0, NULL)) {
  1462. yyerror("variable cannot be declared");
  1463. }
  1464. }
  1465. | cfg_var_id DOT cfg_var_id EQUAL STRING {
  1466. if (cfg_declare_str($1, $3, $5, NULL)) {
  1467. yyerror("variable cannot be declared");
  1468. }
  1469. }
  1470. | cfg_var_id DOT cfg_var_id EQUAL NUMBER CFG_DESCRIPTION STRING {
  1471. if (cfg_declare_int($1, $3, $5, 0, 0, $7)) {
  1472. yyerror("variable cannot be declared");
  1473. }
  1474. }
  1475. | cfg_var_id DOT cfg_var_id EQUAL STRING CFG_DESCRIPTION STRING {
  1476. if (cfg_declare_str($1, $3, $5, $7)) {
  1477. yyerror("variable cannot be declared");
  1478. }
  1479. }
  1480. | cfg_var_id DOT cfg_var_id EQUAL error {
  1481. yyerror("number or string expected");
  1482. }
  1483. ;
  1484. module_stm:
  1485. LOADMODULE STRING {
  1486. DBG("loading module %s\n", $2);
  1487. if (load_module($2)!=0) {
  1488. yyerror("failed to load module");
  1489. }
  1490. }
  1491. | LOADMODULE error { yyerror("string expected"); }
  1492. | LOADPATH STRING {
  1493. DBG("loading modules under %s\n", $2);
  1494. printf("loading modules under %s\n", $2);
  1495. mods_dir = $2;
  1496. }
  1497. | LOADPATH error { yyerror("string expected"); }
  1498. | LOADPATH EQUAL STRING {
  1499. DBG("loading modules under %s\n", $3);
  1500. printf("loading modules under %s\n", $3);
  1501. mods_dir = $3;
  1502. }
  1503. | LOADPATH EQUAL error { yyerror("string expected"); }
  1504. | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
  1505. if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
  1506. yyerror("Can't set module parameter");
  1507. }
  1508. }
  1509. | MODPARAM LPAREN STRING COMMA STRING COMMA NUMBER RPAREN {
  1510. if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
  1511. yyerror("Can't set module parameter");
  1512. }
  1513. }
  1514. | MODPARAM error { yyerror("Invalid arguments"); }
  1515. ;
  1516. ip:
  1517. ipv4 { $$=$1; }
  1518. | ipv6 { $$=$1; }
  1519. ;
  1520. ipv4:
  1521. NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
  1522. $$=pkg_malloc(sizeof(struct ip_addr));
  1523. if ($$==0) {
  1524. LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
  1525. } else {
  1526. memset($$, 0, sizeof(struct ip_addr));
  1527. $$->af=AF_INET;
  1528. $$->len=4;
  1529. if (($1>255) || ($1<0) ||
  1530. ($3>255) || ($3<0) ||
  1531. ($5>255) || ($5<0) ||
  1532. ($7>255) || ($7<0)) {
  1533. yyerror("invalid ipv4 address");
  1534. $$->u.addr32[0]=0;
  1535. /* $$=0; */
  1536. } else {
  1537. $$->u.addr[0]=$1;
  1538. $$->u.addr[1]=$3;
  1539. $$->u.addr[2]=$5;
  1540. $$->u.addr[3]=$7;
  1541. /*
  1542. $$=htonl( ($1<<24)|
  1543. ($3<<16)| ($5<<8)|$7 );
  1544. */
  1545. }
  1546. }
  1547. }
  1548. ;
  1549. ipv6addr:
  1550. IPV6ADDR {
  1551. $$=pkg_malloc(sizeof(struct ip_addr));
  1552. if ($$==0) {
  1553. LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
  1554. } else {
  1555. #ifdef USE_IPV6
  1556. memset($$, 0, sizeof(struct ip_addr));
  1557. $$->af=AF_INET6;
  1558. $$->len=16;
  1559. if (inet_pton(AF_INET6, $1, $$->u.addr)<=0) {
  1560. yyerror("bad ipv6 address");
  1561. }
  1562. #else
  1563. yyerror("ipv6 address & no ipv6 support compiled in");
  1564. YYABORT;
  1565. #endif
  1566. }
  1567. }
  1568. ;
  1569. ipv6:
  1570. ipv6addr { $$=$1; }
  1571. | LBRACK ipv6addr RBRACK {$$=$2; }
  1572. ;
  1573. route_name: NUMBER {
  1574. tmp=int2str($1, &i_tmp);
  1575. if (($$=pkg_malloc(i_tmp+1))==0) {
  1576. yyerror("out of memory");
  1577. YYABORT;
  1578. } else {
  1579. memcpy($$, tmp, i_tmp);
  1580. $$[i_tmp]=0;
  1581. }
  1582. }
  1583. | ID { $$=$1; }
  1584. | STRING { $$=$1; }
  1585. ;
  1586. route_stm:
  1587. ROUTE LBRACE actions RBRACE { push($3, &main_rt.rlist[DEFAULT_RT]); }
  1588. | ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
  1589. i_tmp=route_get(&main_rt, $3);
  1590. if (i_tmp==-1){
  1591. yyerror("internal error");
  1592. YYABORT;
  1593. }
  1594. if (main_rt.rlist[i_tmp]){
  1595. yyerror("duplicate route");
  1596. YYABORT;
  1597. }
  1598. push($6, &main_rt.rlist[i_tmp]);
  1599. }
  1600. | ROUTE error { yyerror("invalid route statement"); }
  1601. ;
  1602. failure_route_stm:
  1603. ROUTE_FAILURE LBRACE actions RBRACE {
  1604. push($3, &failure_rt.rlist[DEFAULT_RT]);
  1605. }
  1606. | ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
  1607. i_tmp=route_get(&failure_rt, $3);
  1608. if (i_tmp==-1){
  1609. yyerror("internal error");
  1610. YYABORT;
  1611. }
  1612. if (failure_rt.rlist[i_tmp]){
  1613. yyerror("duplicate route");
  1614. YYABORT;
  1615. }
  1616. push($6, &failure_rt.rlist[i_tmp]);
  1617. }
  1618. | ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
  1619. ;
  1620. onreply_route_stm:
  1621. ROUTE_ONREPLY LBRACE actions RBRACE {
  1622. push($3, &onreply_rt.rlist[DEFAULT_RT]);
  1623. }
  1624. | ROUTE_ONREPLY LBRACK route_name RBRACK LBRACE actions RBRACE {
  1625. i_tmp=route_get(&onreply_rt, $3);
  1626. if (i_tmp==-1){
  1627. yyerror("internal error");
  1628. YYABORT;
  1629. }
  1630. if (onreply_rt.rlist[i_tmp]){
  1631. yyerror("duplicate route");
  1632. YYABORT;
  1633. }
  1634. push($6, &onreply_rt.rlist[i_tmp]);
  1635. }
  1636. | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
  1637. ;
  1638. branch_route_stm:
  1639. ROUTE_BRANCH LBRACE actions RBRACE {
  1640. push($3, &branch_rt.rlist[DEFAULT_RT]);
  1641. }
  1642. | ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
  1643. i_tmp=route_get(&branch_rt, $3);
  1644. if (i_tmp==-1){
  1645. yyerror("internal error");
  1646. YYABORT;
  1647. }
  1648. if (branch_rt.rlist[i_tmp]){
  1649. yyerror("duplicate route");
  1650. YYABORT;
  1651. }
  1652. push($6, &branch_rt.rlist[i_tmp]);
  1653. }
  1654. | ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
  1655. ;
  1656. send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
  1657. push($3, &onsend_rt.rlist[DEFAULT_RT]);
  1658. }
  1659. | ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
  1660. i_tmp=route_get(&onsend_rt, $3);
  1661. if (i_tmp==-1){
  1662. yyerror("internal error");
  1663. YYABORT;
  1664. }
  1665. if (onsend_rt.rlist[i_tmp]){
  1666. yyerror("duplicate route");
  1667. YYABORT;
  1668. }
  1669. push($6, &onsend_rt.rlist[i_tmp]);
  1670. }
  1671. | ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
  1672. ;
  1673. event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
  1674. i_tmp=route_get(&event_rt, $3);
  1675. if (i_tmp==-1){
  1676. yyerror("internal error");
  1677. YYABORT;
  1678. }
  1679. if (event_rt.rlist[i_tmp]){
  1680. yyerror("duplicate route");
  1681. YYABORT;
  1682. }
  1683. push($6, &event_rt.rlist[i_tmp]);
  1684. }
  1685. | ROUTE_EVENT error { yyerror("invalid event_route statement"); }
  1686. ;
  1687. /*exp: rval_expr
  1688. {
  1689. if ($1==0){
  1690. yyerror("invalid expression");
  1691. $$=0;
  1692. }else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
  1693. yyerror("invalid expression");
  1694. $$=0;
  1695. }else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
  1696. yyerror("invalid expression type, int expected\n");
  1697. $$=0;
  1698. }else
  1699. $$=mk_elem(NO_OP, RVEXP_O, $1, 0, 0);
  1700. }
  1701. ;
  1702. */
  1703. /* exp elem operators */
  1704. equalop:
  1705. EQUAL_T {$$=EQUAL_OP; }
  1706. | DIFF {$$=DIFF_OP; }
  1707. | STREQ {$$=EQUAL_OP; } /* for expr. elems equiv. to EQUAL_T*/
  1708. | STRDIFF {$$=DIFF_OP; } /* for expr. elems. equiv. to DIFF */
  1709. ;
  1710. cmpop:
  1711. GT {$$=GT_OP; }
  1712. | LT {$$=LT_OP; }
  1713. | GTE {$$=GTE_OP; }
  1714. | LTE {$$=LTE_OP; }
  1715. ;
  1716. strop:
  1717. equalop {$$=$1; }
  1718. | MATCH {$$=MATCH_OP; }
  1719. ;
  1720. /* rve expr. operators */
  1721. rve_equalop:
  1722. EQUAL_T {$$=RVE_EQ_OP; }
  1723. | DIFF {$$=RVE_DIFF_OP; }
  1724. | INTEQ {$$=RVE_IEQ_OP; }
  1725. | INTDIFF {$$=RVE_IDIFF_OP; }
  1726. | STREQ {$$=RVE_STREQ_OP; }
  1727. | STRDIFF {$$=RVE_STRDIFF_OP; }
  1728. | MATCH {$$=RVE_MATCH_OP; }
  1729. ;
  1730. rve_cmpop:
  1731. GT {$$=RVE_GT_OP; }
  1732. | LT {$$=RVE_LT_OP; }
  1733. | GTE {$$=RVE_GTE_OP; }
  1734. | LTE {$$=RVE_LTE_OP; }
  1735. ;
  1736. /* boolean expression uri operands */
  1737. uri_type:
  1738. URI {$$=URI_O;}
  1739. | FROM_URI {$$=FROM_URI_O;}
  1740. | TO_URI {$$=TO_URI_O;}
  1741. ;
  1742. /* boolean expression integer operands, available only in the
  1743. onsend route */
  1744. eint_op_onsend:
  1745. SNDPORT { $$=SNDPORT_O; }
  1746. | TOPORT { $$=TOPORT_O; }
  1747. | SNDAF { $$=SNDAF_O; }
  1748. ;
  1749. /* boolean expression integer operands */
  1750. eint_op: SRCPORT { $$=SRCPORT_O; }
  1751. | DSTPORT { $$=DSTPORT_O; }
  1752. | AF { $$=AF_O; }
  1753. | MSGLEN { $$=MSGLEN_O; }
  1754. | eint_op_onsend
  1755. ;
  1756. /* boolean expression ip/ipnet operands */
  1757. eip_op_onsend:
  1758. SNDIP { onsend_check("snd_ip"); $$=SNDIP_O; }
  1759. | TOIP { onsend_check("to_ip"); $$=TOIP_O; }
  1760. ;
  1761. eip_op: SRCIP { $$=SRCIP_O; }
  1762. | DSTIP { $$=DSTIP_O; }
  1763. | eip_op_onsend
  1764. ;
  1765. exp_elem:
  1766. METHOD strop rval_expr %prec EQUAL_T
  1767. {$$= mk_elem($2, METHOD_O, 0, RVE_ST, $3);}
  1768. | METHOD strop ID %prec EQUAL_T
  1769. {$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
  1770. | METHOD strop error { $$=0; yyerror("string expected"); }
  1771. | METHOD error
  1772. { $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
  1773. | uri_type strop rval_expr %prec EQUAL_T
  1774. {$$ = mk_elem($2, $1, 0, RVE_ST, $3); }
  1775. | uri_type strop MYSELF %prec EQUAL_T
  1776. {$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
  1777. | uri_type strop error %prec EQUAL_T
  1778. { $$=0; yyerror("string or MYSELF expected"); }
  1779. | uri_type error
  1780. { $$=0; yyerror("invalid operator, == , != or =~ expected"); }
  1781. | eint_op cmpop rval_expr %prec GT { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
  1782. | eint_op equalop rval_expr %prec EQUAL_T
  1783. { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
  1784. | eint_op cmpop error { $$=0; yyerror("number expected"); }
  1785. | eint_op equalop error { $$=0; yyerror("number expected"); }
  1786. | eint_op error { $$=0; yyerror("==, !=, <,>, >= or <= expected"); }
  1787. | PROTO equalop proto %prec EQUAL_T
  1788. { $$=mk_elem($2, PROTO_O, 0, NUMBER_ST, (void*)$3 ); }
  1789. | PROTO equalop rval_expr %prec EQUAL_T
  1790. { $$=mk_elem($2, PROTO_O, 0, RVE_ST, $3 ); }
  1791. | PROTO equalop error
  1792. { $$=0; yyerror("protocol expected (udp, tcp, tls or sctp)"); }
  1793. | SNDPROTO equalop proto %prec EQUAL_T
  1794. { $$=mk_elem($2, SNDPROTO_O, 0, NUMBER_ST, (void*)$3 ); }
  1795. | SNDPROTO equalop rval_expr %prec EQUAL_T
  1796. { $$=mk_elem($2, SNDPROTO_O, 0, RVE_ST, $3 ); }
  1797. | SNDPROTO equalop error
  1798. { $$=0; yyerror("protocol expected (udp, tcp, tls or sctp)"); }
  1799. | eip_op strop ipnet %prec EQUAL_T { $$=mk_elem($2, $1, 0, NET_ST, $3); }
  1800. | eip_op strop rval_expr %prec EQUAL_T {
  1801. s_tmp.s=0;
  1802. $$=0;
  1803. if (rve_is_constant($3)){
  1804. i_tmp=rve_guess_type($3);
  1805. if (i_tmp==RV_INT)
  1806. yyerror("string expected");
  1807. else if (i_tmp==RV_STR){
  1808. if (((rval_tmp=rval_expr_eval(0, 0, $3))==0) ||
  1809. (rval_get_str(0, 0, &s_tmp, rval_tmp, 0)<0)){
  1810. rval_destroy(rval_tmp);
  1811. yyerror("bad rvalue expression");
  1812. }else{
  1813. rval_destroy(rval_tmp);
  1814. }
  1815. }else{
  1816. yyerror("BUG: unexpected dynamic type");
  1817. }
  1818. }else{
  1819. warn("non constant rvalue in ip comparison");
  1820. }
  1821. if (s_tmp.s){
  1822. ip_tmp=str2ip(&s_tmp);
  1823. #ifdef USE_IPV6
  1824. if (ip_tmp==0)
  1825. ip_tmp=str2ip6(&s_tmp);
  1826. #endif
  1827. pkg_free(s_tmp.s);
  1828. if (ip_tmp) {
  1829. $$=mk_elem($2, $1, 0, NET_ST,
  1830. mk_net_bitlen(ip_tmp, ip_tmp->len*8) );
  1831. } else {
  1832. $$=mk_elem($2, $1, 0, RVE_ST, $3);
  1833. }
  1834. }else{
  1835. $$=mk_elem($2, $1, 0, RVE_ST, $3);
  1836. }
  1837. }
  1838. | eip_op strop host %prec EQUAL_T
  1839. { $$=mk_elem($2, $1, 0, STRING_ST, $3); }
  1840. | eip_op strop MYSELF %prec EQUAL_T
  1841. { $$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
  1842. | eip_op strop error %prec EQUAL_T
  1843. { $$=0; yyerror( "ip address or hostname expected" ); }
  1844. | eip_op error
  1845. { $$=0; yyerror("invalid operator, ==, != or =~ expected");}
  1846. | MYSELF equalop uri_type %prec EQUAL_T
  1847. { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
  1848. | MYSELF equalop eip_op %prec EQUAL_T
  1849. { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
  1850. | MYSELF equalop error %prec EQUAL_T
  1851. { $$=0; yyerror(" URI, SRCIP or DSTIP expected"); }
  1852. | MYSELF error { $$=0; yyerror ("invalid operator, == or != expected"); }
  1853. ;
  1854. /*
  1855. exp_elem2:
  1856. rval_expr cmpop rval_expr %prec GT
  1857. { $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
  1858. |
  1859. rval_expr equalop rval_expr %prec EQUAL_T
  1860. { $$=mk_elem( $2, RVE_ST, $1, RVE_ST, $3);}
  1861. | rval_expr LOG_AND rval_expr
  1862. { $$=mk_exp_rve(LOGAND_OP, $1, $3);}
  1863. | rval_expr LOG_OR rval_expr
  1864. { $$=mk_exp_rve(LOGOR_OP, $1, $3);}
  1865. ;
  1866. */
  1867. ipnet:
  1868. ip SLASH ip { $$=mk_net($1, $3); }
  1869. | ip SLASH NUMBER {
  1870. if (($3<0) || ($3>$1->len*8)) {
  1871. yyerror("invalid bit number in netmask");
  1872. $$=0;
  1873. } else {
  1874. $$=mk_net_bitlen($1, $3);
  1875. /*
  1876. $$=mk_net($1, htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
  1877. */
  1878. }
  1879. }
  1880. | ip { $$=mk_net_bitlen($1, $1->len*8); }
  1881. | ip SLASH error { $$=0; yyerror("netmask (eg:255.0.0.0 or 8) expected"); }
  1882. ;
  1883. host:
  1884. ID { $$=$1; }
  1885. | host DOT ID {
  1886. if ($1){
  1887. $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
  1888. if ($$==0) {
  1889. LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
  1890. " failure while parsing host\n");
  1891. } else {
  1892. memcpy($$, $1, strlen($1));
  1893. $$[strlen($1)]='.';
  1894. memcpy($$+strlen($1)+1, $3, strlen($3));
  1895. $$[strlen($1)+1+strlen($3)]=0;
  1896. }
  1897. pkg_free($1);
  1898. }
  1899. if ($3) pkg_free($3);
  1900. }
  1901. | host MINUS ID {
  1902. if ($1){
  1903. $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
  1904. if ($$==0) {
  1905. LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
  1906. " failure while parsing host\n");
  1907. } else {
  1908. memcpy($$, $1, strlen($1));
  1909. $$[strlen($1)]='-';
  1910. memcpy($$+strlen($1)+1, $3, strlen($3));
  1911. $$[strlen($1)+1+strlen($3)]=0;
  1912. }
  1913. pkg_free($1);
  1914. }
  1915. if ($3) pkg_free($3);
  1916. }
  1917. | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
  1918. | host MINUS error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
  1919. ;
  1920. host_if_id: ID
  1921. | NUM_ID
  1922. | NUMBER {
  1923. /* get string version */
  1924. $$=pkg_malloc(strlen(yy_number_str)+1);
  1925. if ($$)
  1926. strcpy($$, yy_number_str);
  1927. }
  1928. ;
  1929. host_or_if:
  1930. host_if_id { $$=$1; }
  1931. | host_or_if DOT host_if_id {
  1932. if ($1){
  1933. $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
  1934. if ($$==0) {
  1935. LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
  1936. " failure while parsing host/interface name\n");
  1937. } else {
  1938. memcpy($$, $1, strlen($1));
  1939. $$[strlen($1)]='.';
  1940. memcpy($$+strlen($1)+1, $3, strlen($3));
  1941. $$[strlen($1)+1+strlen($3)]=0;
  1942. }
  1943. pkg_free($1);
  1944. }
  1945. if ($3) pkg_free($3);
  1946. }
  1947. | host_or_if MINUS host_if_id {
  1948. if ($1){
  1949. $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
  1950. if ($$==0) {
  1951. LOG(L_CRIT, "ERROR: cfg. parser: memory allocation"
  1952. " failure while parsing host/interface name\n");
  1953. } else {
  1954. memcpy($$, $1, strlen($1));
  1955. $$[strlen($1)]='-';
  1956. memcpy($$+strlen($1)+1, $3, strlen($3));
  1957. $$[strlen($1)+1+strlen($3)]=0;
  1958. }
  1959. pkg_free($1);
  1960. }
  1961. if ($3) pkg_free($3);
  1962. }
  1963. | host_or_if DOT error { $$=0; pkg_free($1);
  1964. yyerror("invalid host or interface name"); }
  1965. | host_or_if MINUS error { $$=0; pkg_free($1);
  1966. yyerror("invalid host or interface name"); }
  1967. ;
  1968. /* filtered cmd */
  1969. fcmd:
  1970. cmd {
  1971. /* check if allowed */
  1972. if ($1 && rt==ONSEND_ROUTE) {
  1973. switch($1->type) {
  1974. case DROP_T:
  1975. case SEND_T:
  1976. case SEND_TCP_T:
  1977. case LOG_T:
  1978. case SETFLAG_T:
  1979. case RESETFLAG_T:
  1980. case ISFLAGSET_T:
  1981. case IF_T:
  1982. case MODULE_T:
  1983. case SET_FWD_NO_CONNECT_T:
  1984. case SET_RPL_NO_CONNECT_T:
  1985. case SET_FWD_CLOSE_T:
  1986. case SET_RPL_CLOSE_T:
  1987. $$=$1;
  1988. break;
  1989. default:
  1990. $$=0;
  1991. yyerror("command not allowed in onsend_route\n");
  1992. }
  1993. } else {
  1994. $$=$1;
  1995. }
  1996. }
  1997. ;
  1998. /*
  1999. exp_stm:
  2000. fcmd { $$=$1; }
  2001. | if_cmd { $$=$1; }
  2002. | assign_action { $$ = $1; }
  2003. | LBRACE actions RBRACE { $$=$2; }
  2004. ;
  2005. */
  2006. stm:
  2007. action { $$=$1; }
  2008. | LBRACE actions RBRACE { $$=$2; }
  2009. ;
  2010. actions:
  2011. actions action {$$=append_action($1, $2); }
  2012. | action {$$=$1;}
  2013. | actions error { $$=0; yyerror("bad command"); }
  2014. ;
  2015. action:
  2016. fcmd SEMICOLON {$$=$1;}
  2017. | if_cmd {$$=$1;}
  2018. | switch_cmd {$$=$1;}
  2019. | while_cmd { $$=$1; }
  2020. | ret_cmd SEMICOLON { $$=$1; }
  2021. | assign_action SEMICOLON {$$=$1;}
  2022. | SEMICOLON /* null action */ {$$=0;}
  2023. | fcmd error { $$=0; yyerror("bad command: missing ';'?"); }
  2024. ;
  2025. if_cmd:
  2026. IF rval_expr stm {
  2027. if ($2 && rval_expr_int_check($2)>=0){
  2028. warn_ct_rve($2, "if");
  2029. $$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0);
  2030. set_cfg_pos($$);
  2031. }else
  2032. YYERROR;
  2033. }
  2034. | IF rval_expr stm ELSE stm {
  2035. if ($2 && rval_expr_int_check($2)>=0){
  2036. warn_ct_rve($2, "if");
  2037. $$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5);
  2038. set_cfg_pos($$);
  2039. }else
  2040. YYERROR;
  2041. }
  2042. ;
  2043. ct_rval: rval_expr {
  2044. $$=0;
  2045. if (!rve_is_constant($1)){
  2046. yyerror("constant expected");
  2047. /*
  2048. } else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
  2049. yyerror("invalid expression (bad type)");
  2050. }else if (i_tmp!=RV_INT){
  2051. yyerror("invalid expression type, int expected\n");
  2052. */
  2053. }else
  2054. $$=$1;
  2055. }
  2056. ;
  2057. single_case:
  2058. CASE ct_rval COLON actions {
  2059. $$=0;
  2060. if ($2==0) yyerror ("bad case label");
  2061. else if ((($$=mk_case_stm($2, 0, $4, &i_tmp))==0) && (i_tmp==-10)){
  2062. YYABORT;
  2063. }
  2064. }
  2065. | CASE SLASH ct_rval COLON actions {
  2066. $$=0;
  2067. if ($3==0) yyerror ("bad case label");
  2068. else if ((($$=mk_case_stm($3, 1, $5, &i_tmp))==0) && (i_tmp==-10)){
  2069. YYABORT;
  2070. }
  2071. }
  2072. | CASE ct_rval COLON {
  2073. $$=0;
  2074. if ($2==0) yyerror ("bad case label");
  2075. else if ((($$=mk_case_stm($2, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
  2076. YYABORT;
  2077. }
  2078. }
  2079. | CASE SLASH ct_rval COLON {
  2080. $$=0;
  2081. if ($3==0) yyerror ("bad case label");
  2082. else if ((($$=mk_case_stm($3, 1, 0, &i_tmp))==0) && (i_tmp==-10)){
  2083. YYABORT;
  2084. }
  2085. }
  2086. | DEFAULT COLON actions {
  2087. if ((($$=mk_case_stm(0, 0, $3, &i_tmp))==0) && (i_tmp=-10)){
  2088. YYABORT;
  2089. }
  2090. }
  2091. | DEFAULT COLON {
  2092. if ((($$=mk_case_stm(0, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
  2093. YYABORT;
  2094. }
  2095. }
  2096. | CASE error { $$=0; yyerror("bad case label"); }
  2097. | CASE ct_rval COLON error { $$=0; yyerror ("bad case body"); }
  2098. ;
  2099. case_stms:
  2100. case_stms single_case {
  2101. $$=$1;
  2102. if ($2==0) yyerror ("bad case");
  2103. if ($$){
  2104. *($$->append)=$2;
  2105. if (*($$->append)!=0)
  2106. $$->append=&((*($$->append))->next);
  2107. }
  2108. }
  2109. | single_case {
  2110. $$=$1;
  2111. if ($1==0) yyerror ("bad case");
  2112. else $$->append=&($$->next);
  2113. }
  2114. ;
  2115. switch_cmd:
  2116. SWITCH rval_expr LBRACE case_stms RBRACE {
  2117. $$=0;
  2118. if ($2==0){
  2119. yyerror("bad expression in switch(...)");
  2120. YYERROR;
  2121. }else if ($4==0){
  2122. yyerror ("bad switch body");
  2123. YYERROR;
  2124. }else if (case_check_default($4)!=0){
  2125. yyerror_at(&$2->fpos, "bad switch(): too many "
  2126. "\"default:\" labels\n");
  2127. YYERROR;
  2128. }else if (case_check_type($4)!=0){
  2129. yyerror_at(&$2->fpos, "bad switch(): mixed integer and"
  2130. " string/RE cases not allowed\n");
  2131. YYERROR;
  2132. }else{
  2133. $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, $4);
  2134. if ($$==0) {
  2135. yyerror("internal error");
  2136. YYABORT;
  2137. }
  2138. set_cfg_pos($$);
  2139. }
  2140. }
  2141. | SWITCH rval_expr LBRACE RBRACE {
  2142. $$=0;
  2143. warn("empty switch()");
  2144. if ($2==0){
  2145. yyerror("bad expression in switch(...)");
  2146. YYERROR;
  2147. }else{
  2148. /* it might have sideffects, so leave it for the optimizer */
  2149. $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, 0);
  2150. if ($$==0) {
  2151. yyerror("internal error");
  2152. YYABORT;
  2153. }
  2154. set_cfg_pos($$);
  2155. }
  2156. }
  2157. | SWITCH error { $$=0; yyerror ("bad expression in switch(...)"); }
  2158. | SWITCH rval_expr LBRACE error RBRACE
  2159. {$$=0; yyerror ("bad switch body"); }
  2160. ;
  2161. while_cmd:
  2162. WHILE rval_expr stm {
  2163. if ($2 && rval_expr_int_check($2)>=0){
  2164. warn_ct_rve($2, "while");
  2165. $$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
  2166. set_cfg_pos($$);
  2167. }else{
  2168. yyerror_at(&$2->fpos, "bad while(...) expression");
  2169. YYERROR;
  2170. }
  2171. }
  2172. ;
  2173. /* class_id:
  2174. LBRACK ATTR_USER RBRACK { $$ = AVP_CLASS_USER; }
  2175. | LBRACK ATTR_DOMAIN RBRACK { $$ = AVP_CLASS_DOMAIN; }
  2176. | LBRACK ATTR_GLOBAL RBRACK { $$ = AVP_CLASS_GLOBAL; }
  2177. ;
  2178. */
  2179. select_param:
  2180. ID {
  2181. if (sel.n >= MAX_SELECT_PARAMS-1) {
  2182. yyerror("Select identifier too long\n");
  2183. }
  2184. sel.params[sel.n].type = SEL_PARAM_STR;
  2185. sel.params[sel.n].v.s.s = $1;
  2186. sel.params[sel.n].v.s.len = strlen($1);
  2187. sel.n++;
  2188. }
  2189. | ID LBRACK intno RBRACK {
  2190. if (sel.n >= MAX_SELECT_PARAMS-2) {
  2191. yyerror("Select identifier too long\n");
  2192. }
  2193. sel.params[sel.n].type = SEL_PARAM_STR;
  2194. sel.params[sel.n].v.s.s = $1;
  2195. sel.params[sel.n].v.s.len = strlen($1);
  2196. sel.n++;
  2197. sel.params[sel.n].type = SEL_PARAM_INT;
  2198. sel.params[sel.n].v.i = $3;
  2199. sel.n++;
  2200. }
  2201. | ID LBRACK STRING RBRACK {
  2202. if (sel.n >= MAX_SELECT_PARAMS-2) {
  2203. yyerror("Select identifier too long\n");
  2204. }
  2205. sel.params[sel.n].type = SEL_PARAM_STR;
  2206. sel.params[sel.n].v.s.s = $1;
  2207. sel.params[sel.n].v.s.len = strlen($1);
  2208. sel.n++;
  2209. sel.params[sel.n].type = SEL_PARAM_STR;
  2210. sel.params[sel.n].v.s.s = $3;
  2211. sel.params[sel.n].v.s.len = strlen($3);
  2212. sel.n++;
  2213. }
  2214. ;
  2215. select_params:
  2216. select_params DOT select_param
  2217. | select_param
  2218. ;
  2219. select_id:
  2220. SELECT_MARK { sel.n = 0; sel.f[0] = 0; } select_params {
  2221. sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
  2222. if (!sel_ptr) {
  2223. yyerror("No memory left to allocate select structure\n");
  2224. }
  2225. memcpy(sel_ptr, &sel, sizeof(select_t));
  2226. $$ = sel_ptr;
  2227. }
  2228. ;
  2229. attr_class_spec:
  2230. ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
  2231. | ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
  2232. | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
  2233. | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
  2234. | ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
  2235. | ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
  2236. | ATTR_FROMDOMAIN { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_DOMAIN; }
  2237. | ATTR_TODOMAIN { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_DOMAIN; }
  2238. | ATTR_GLOBAL { s_attr->type |= AVP_TRACK_ALL | AVP_CLASS_GLOBAL; }
  2239. ;
  2240. attr_name_spec:
  2241. ID { s_attr->type |= AVP_NAME_STR; s_attr->name.s.s = $1; s_attr->name.s.len = strlen ($1); }
  2242. ;
  2243. attr_spec:
  2244. attr_name_spec
  2245. | attr_class_spec DOT attr_name_spec
  2246. ;
  2247. attr_mark:
  2248. ATTR_MARK {
  2249. s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
  2250. if (!s_attr) { yyerror("No memory left"); YYABORT; }
  2251. else s_attr->type = 0;
  2252. }
  2253. ;
  2254. attr_id:
  2255. attr_mark attr_spec { $$ = s_attr; }
  2256. ;
  2257. attr_id_num_idx:
  2258. attr_mark attr_spec LBRACK intno RBRACK {
  2259. s_attr->type|= (AVP_NAME_STR | ($4<0?AVP_INDEX_BACKWARD:AVP_INDEX_FORWARD));
  2260. s_attr->index = ($4<0?-$4:$4);
  2261. $$ = s_attr;
  2262. }
  2263. ;
  2264. attr_id_no_idx:
  2265. attr_mark attr_spec LBRACK RBRACK {
  2266. s_attr->type|= AVP_INDEX_ALL;
  2267. $$ = s_attr;
  2268. }
  2269. ;
  2270. attr_id_ass:
  2271. attr_id
  2272. | attr_id_no_idx
  2273. ;
  2274. /*
  2275. attr_id_val:
  2276. attr_id
  2277. | attr_id_num_idx
  2278. ;
  2279. */
  2280. attr_id_any:
  2281. attr_id
  2282. | attr_id_no_idx
  2283. | attr_id_num_idx
  2284. ;
  2285. attr_id_any_str:
  2286. attr_id
  2287. | avp_pvar {
  2288. if ($1->type==LV_AVP){
  2289. s_attr = pkg_malloc(sizeof(struct avp_spec));
  2290. if (!s_attr) { yyerror("No memory left"); YYABORT; }
  2291. else{
  2292. *s_attr=$1->lv.avps;
  2293. }
  2294. $$=s_attr;
  2295. }else
  2296. $$=0; /* not an avp, a pvar */
  2297. pkg_free($1);
  2298. }
  2299. | STRING {
  2300. avp_spec_t *avp_spec;
  2301. str s;
  2302. int type, idx;
  2303. avp_spec = pkg_malloc(sizeof(*avp_spec));
  2304. if (!avp_spec) {
  2305. yyerror("Not enough memory");
  2306. YYABORT;
  2307. }
  2308. s.s = $1;
  2309. if (s.s[0] == '$')
  2310. s.s++;
  2311. s.len = strlen(s.s);
  2312. if (parse_avp_name(&s, &type, &avp_spec->name, &idx)) {
  2313. yyerror("error when parsing AVP");
  2314. pkg_free(avp_spec);
  2315. YYABORT;
  2316. }
  2317. avp_spec->type = type;
  2318. avp_spec->index = idx;
  2319. $$ = avp_spec;
  2320. }
  2321. ;
  2322. pvar: PVAR {
  2323. pv_spec=pkg_malloc(sizeof(*pv_spec));
  2324. if (!pv_spec) {
  2325. yyerror("Not enough memory");
  2326. YYABORT;
  2327. }
  2328. memset(pv_spec, 0, sizeof(*pv_spec));
  2329. s_tmp.s=$1; s_tmp.len=strlen($1);
  2330. if (pv_parse_spec(&s_tmp, pv_spec)==0){
  2331. yyerror("unknown script pseudo variable %s", $1 );
  2332. pkg_free(pv_spec);
  2333. pv_spec=0;
  2334. YYABORT;
  2335. }
  2336. $$=pv_spec;
  2337. }
  2338. ;
  2339. avp_pvar: AVP_OR_PVAR {
  2340. lval_tmp=pkg_malloc(sizeof(*lval_tmp));
  2341. if (!lval_tmp) {
  2342. yyerror("Not enough memory");
  2343. YYABORT;
  2344. }
  2345. memset(lval_tmp, 0, sizeof(*lval_tmp));
  2346. s_tmp.s=$1; s_tmp.len=strlen(s_tmp.s);
  2347. if (pv_parse_spec2(&s_tmp, &lval_tmp->lv.pvs, 1)==0){
  2348. /* not a pvar, try avps */
  2349. /* lval_tmp might be partially filled by the failed
  2350. pv_parse_spec2() (especially if the avp name is the
  2351. same as a pv class) => clean it again */
  2352. memset(lval_tmp, 0, sizeof(*lval_tmp));
  2353. lval_tmp->lv.avps.type|= AVP_NAME_STR;
  2354. lval_tmp->lv.avps.name.s.s = s_tmp.s+1;
  2355. lval_tmp->lv.avps.name.s.len = s_tmp.len-1;
  2356. lval_tmp->type=LV_AVP;
  2357. }else{
  2358. lval_tmp->type=LV_PVAR;
  2359. }
  2360. $$ = lval_tmp;
  2361. DBG("parsed ambigous avp/pvar \"%.*s\" to %d\n",
  2362. s_tmp.len, s_tmp.s, lval_tmp->type);
  2363. }
  2364. ;
  2365. /*
  2366. assign_op:
  2367. ADDEQ { $$ = ADD_T; }
  2368. | EQUAL { $$ = ASSIGN_T; }
  2369. ;
  2370. */
  2371. assign_op:
  2372. EQUAL { $$ = ASSIGN_T; }
  2373. ;
  2374. lval: attr_id_ass {
  2375. lval_tmp=pkg_malloc(sizeof(*lval_tmp));
  2376. if (!lval_tmp) {
  2377. yyerror("Not enough memory");
  2378. YYABORT;
  2379. }
  2380. lval_tmp->type=LV_AVP; lval_tmp->lv.avps=*$1;
  2381. pkg_free($1); /* free the avp spec we just copied */
  2382. $$=lval_tmp;
  2383. }
  2384. | pvar {
  2385. if (!pv_is_w($1))
  2386. yyerror("read only pvar in assignment left side");
  2387. if ($1->trans!=0)
  2388. yyerror("pvar with transformations in assignment"
  2389. " left side");
  2390. lval_tmp=pkg_malloc(sizeof(*lval_tmp));
  2391. if (!lval_tmp) {
  2392. yyerror("Not enough memory");
  2393. YYABORT;
  2394. }
  2395. lval_tmp->type=LV_PVAR; lval_tmp->lv.pvs=*($1);
  2396. pkg_free($1); /* free the pvar spec we just copied */
  2397. $$=lval_tmp;
  2398. }
  2399. | avp_pvar {
  2400. if (($1)->type==LV_PVAR){
  2401. if (!pv_is_w(&($1)->lv.pvs))
  2402. yyerror("read only pvar in assignment left side");
  2403. if ($1->lv.pvs.trans!=0)
  2404. yyerror("pvar with transformations in assignment"
  2405. " left side");
  2406. }
  2407. $$=$1;
  2408. }
  2409. ;
  2410. rval: intno {$$=mk_rve_rval(RV_INT, (void*)$1); }
  2411. | STRING { s_tmp.s=$1; s_tmp.len=strlen($1);
  2412. $$=mk_rve_rval(RV_STR, &s_tmp); }
  2413. | attr_id_any {$$=mk_rve_rval(RV_AVP, $1); pkg_free($1); }
  2414. | pvar {$$=mk_rve_rval(RV_PVAR, $1); pkg_free($1); }
  2415. | avp_pvar {
  2416. switch($1->type){
  2417. case LV_AVP:
  2418. $$=mk_rve_rval(RV_AVP, &$1->lv.avps);
  2419. break;
  2420. case LV_PVAR:
  2421. $$=mk_rve_rval(RV_PVAR, &$1->lv.pvs);
  2422. break;
  2423. default:
  2424. yyerror("BUG: invalid lvalue type ");
  2425. YYABORT;
  2426. }
  2427. pkg_free($1); /* not needed anymore */
  2428. }
  2429. | select_id {$$=mk_rve_rval(RV_SEL, $1); pkg_free($1); }
  2430. | fcmd {$$=mk_rve_rval(RV_ACTION_ST, $1); }
  2431. | exp_elem { $$=mk_rve_rval(RV_BEXPR, $1); }
  2432. | LBRACE actions RBRACE {$$=mk_rve_rval(RV_ACTION_ST, $2); }
  2433. | LBRACE error RBRACE { $$=0; yyerror("bad command block"); }
  2434. | LPAREN assign_action RPAREN {$$=mk_rve_rval(RV_ACTION_ST, $2); }
  2435. | LPAREN error RPAREN { $$=0; yyerror("bad expression"); }
  2436. ;
  2437. rve_un_op: NOT { $$=RVE_LNOT_OP; }
  2438. | MINUS %prec UNARY { $$=RVE_UMINUS_OP; }
  2439. /* TODO: RVE_BOOL_OP, RVE_NOT_OP? */
  2440. ;
  2441. /*
  2442. rve_op: PLUS { $$=RVE_PLUS_OP; }
  2443. | MINUS { $$=RVE_MINUS_OP; }
  2444. | STAR { $$=RVE_MUL_OP; }
  2445. | SLASH { $$=RVE_DIV_OP; }
  2446. | MODULO { $$=RVE_MOD_OP; }
  2447. ;
  2448. */
  2449. rval_expr: rval { $$=$1;
  2450. if ($$==0){
  2451. /*yyerror("out of memory\n");*/
  2452. YYERROR;
  2453. }
  2454. }
  2455. | rve_un_op rval_expr %prec UNARY {$$=mk_rve1($1, $2); }
  2456. | INTCAST rval_expr {$$=mk_rve1(RVE_INT_OP, $2); }
  2457. | STRCAST rval_expr {$$=mk_rve1(RVE_STR_OP, $2); }
  2458. | rval_expr PLUS rval_expr {$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
  2459. | rval_expr MINUS rval_expr {$$=mk_rve2(RVE_MINUS_OP, $1, $3); }
  2460. | rval_expr STAR rval_expr {$$=mk_rve2(RVE_MUL_OP, $1, $3); }
  2461. | rval_expr SLASH rval_expr {$$=mk_rve2(RVE_DIV_OP, $1, $3); }
  2462. | rval_expr MODULO rval_expr {$$=mk_rve2(RVE_MOD_OP, $1, $3); }
  2463. | rval_expr BIN_OR rval_expr {$$=mk_rve2(RVE_BOR_OP, $1, $3); }
  2464. | rval_expr BIN_AND rval_expr {$$=mk_rve2(RVE_BAND_OP, $1, $3);}
  2465. | rval_expr rve_cmpop rval_expr %prec GT { $$=mk_rve2( $2, $1, $3);}
  2466. | rval_expr rve_equalop rval_expr %prec EQUAL_T
  2467. { $$=mk_rve2( $2, $1, $3);}
  2468. | rval_expr LOG_AND rval_expr { $$=mk_rve2(RVE_LAND_OP, $1, $3);}
  2469. | rval_expr LOG_OR rval_expr { $$=mk_rve2(RVE_LOR_OP, $1, $3);}
  2470. | LPAREN rval_expr RPAREN { $$=$2;}
  2471. | STRLEN LPAREN rval_expr RPAREN { $$=mk_rve1(RVE_STRLEN_OP, $3);}
  2472. | STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
  2473. | DEFINED rval_expr { $$=mk_rve1(RVE_DEFINED_OP, $2);}
  2474. | rve_un_op error %prec UNARY { $$=0; yyerror("bad expression"); }
  2475. | INTCAST error { $$=0; yyerror("bad expression"); }
  2476. | STRCAST error { $$=0; yyerror("bad expression"); }
  2477. | rval_expr PLUS error { $$=0; yyerror("bad expression"); }
  2478. | rval_expr MINUS error { $$=0; yyerror("bad expression"); }
  2479. | rval_expr STAR error { $$=0; yyerror("bad expression"); }
  2480. | rval_expr SLASH error { $$=0; yyerror("bad expression"); }
  2481. | rval_expr MODULO error { $$=0; yyerror("bad expression"); }
  2482. | rval_expr BIN_OR error { $$=0; yyerror("bad expression"); }
  2483. | rval_expr BIN_AND error { $$=0; yyerror("bad expression"); }
  2484. | rval_expr rve_cmpop error %prec GT
  2485. { $$=0; yyerror("bad expression"); }
  2486. | rval_expr rve_equalop error %prec EQUAL_T
  2487. { $$=0; yyerror("bad expression"); }
  2488. | rval_expr LOG_AND error { $$=0; yyerror("bad expression"); }
  2489. | rval_expr LOG_OR error { $$=0; yyerror("bad expression"); }
  2490. | STRLEN LPAREN error RPAREN { $$=0; yyerror("bad expression"); }
  2491. | STREMPTY LPAREN error RPAREN { $$=0; yyerror("bad expression"); }
  2492. | DEFINED error { $$=0; yyerror("bad expression"); }
  2493. ;
  2494. assign_action: lval assign_op rval_expr { $$=mk_action($2, 2, LVAL_ST, $1,
  2495. RVE_ST, $3);
  2496. set_cfg_pos($$);
  2497. }
  2498. ;
  2499. /*
  2500. assign_action:
  2501. attr_id_ass assign_op STRING { $$=mk_action($2, 2, AVP_ST, $1, STRING_ST, $3); }
  2502. | attr_id_ass assign_op NUMBER { $$=mk_action($2, 2, AVP_ST, $1, NUMBER_ST, (void*)$3); }
  2503. | attr_id_ass assign_op fcmd { $$=mk_action($2, 2, AVP_ST, $1, ACTION_ST, $3); }
  2504. | attr_id_ass assign_op attr_id_any { $$=mk_action($2, 2, AVP_ST, $1, AVP_ST, $3); }
  2505. | attr_id_ass assign_op select_id { $$=mk_action($2, 2, AVP_ST, (void*)$1, SELECT_ST, (void*)$3); }
  2506. | attr_id_ass assign_op LPAREN exp RPAREN { $$ = mk_action($2, 2, AVP_ST, $1, EXPR_ST, $4); }
  2507. ;
  2508. */
  2509. avpflag_oper:
  2510. SETAVPFLAG { $$ = 1; }
  2511. | RESETAVPFLAG { $$ = 0; }
  2512. | ISAVPFLAGSET { $$ = -1; }
  2513. ;
  2514. cmd:
  2515. FORWARD LPAREN host RPAREN { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2516. | FORWARD LPAREN STRING RPAREN { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2517. | FORWARD LPAREN ip RPAREN { $$=mk_action( FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
  2518. | FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2519. | FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2520. | FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2521. | FORWARD LPAREN URIHOST COMMA URIPORT RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
  2522. | FORWARD LPAREN URIHOST COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2523. | FORWARD LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
  2524. | FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
  2525. | FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward argument"); }
  2526. | FORWARD_UDP LPAREN host RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2527. | FORWARD_UDP LPAREN STRING RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2528. | FORWARD_UDP LPAREN ip RPAREN { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
  2529. | FORWARD_UDP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2530. | FORWARD_UDP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2531. | FORWARD_UDP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2532. | FORWARD_UDP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
  2533. | FORWARD_UDP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2534. | FORWARD_UDP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
  2535. | FORWARD_UDP error { $$=0; yyerror("missing '(' or ')' ?"); }
  2536. | FORWARD_UDP LPAREN error RPAREN { $$=0; yyerror("bad forward_udp argument"); }
  2537. | FORWARD_TCP LPAREN host RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2538. | FORWARD_TCP LPAREN STRING RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2539. | FORWARD_TCP LPAREN ip RPAREN { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
  2540. | FORWARD_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2541. | FORWARD_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2542. | FORWARD_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2543. | FORWARD_TCP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
  2544. | FORWARD_TCP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2545. | FORWARD_TCP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
  2546. | FORWARD_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
  2547. | FORWARD_TCP LPAREN error RPAREN { $$=0; yyerror("bad forward_tcp argument"); }
  2548. | FORWARD_TLS LPAREN host RPAREN {
  2549. #ifdef USE_TLS
  2550. $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
  2551. #else
  2552. $$=0;
  2553. yyerror("tls support not compiled in");
  2554. #endif
  2555. }
  2556. | FORWARD_TLS LPAREN STRING RPAREN {
  2557. #ifdef USE_TLS
  2558. $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
  2559. #else
  2560. $$=0;
  2561. yyerror("tls support not compiled in");
  2562. #endif
  2563. }
  2564. | FORWARD_TLS LPAREN ip RPAREN {
  2565. #ifdef USE_TLS
  2566. $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$);
  2567. #else
  2568. $$=0;
  2569. yyerror("tls support not compiled in");
  2570. #endif
  2571. }
  2572. | FORWARD_TLS LPAREN host COMMA NUMBER RPAREN {
  2573. #ifdef USE_TLS
  2574. $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
  2575. #else
  2576. $$=0;
  2577. yyerror("tls support not compiled in");
  2578. #endif
  2579. }
  2580. | FORWARD_TLS LPAREN STRING COMMA NUMBER RPAREN {
  2581. #ifdef USE_TLS
  2582. $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
  2583. #else
  2584. $$=0;
  2585. yyerror("tls support not compiled in");
  2586. #endif
  2587. }
  2588. | FORWARD_TLS LPAREN ip COMMA NUMBER RPAREN {
  2589. #ifdef USE_TLS
  2590. $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
  2591. #else
  2592. $$=0;
  2593. yyerror("tls support not compiled in");
  2594. #endif
  2595. }
  2596. | FORWARD_TLS LPAREN URIHOST COMMA URIPORT RPAREN {
  2597. #ifdef USE_TLS
  2598. $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$);
  2599. #else
  2600. $$=0;
  2601. yyerror("tls support not compiled in");
  2602. #endif
  2603. }
  2604. | FORWARD_TLS LPAREN URIHOST COMMA NUMBER RPAREN {
  2605. #ifdef USE_TLS
  2606. $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$);
  2607. #else
  2608. $$=0;
  2609. yyerror("tls support not compiled in");
  2610. #endif
  2611. }
  2612. | FORWARD_TLS LPAREN URIHOST RPAREN {
  2613. #ifdef USE_TLS
  2614. $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$);
  2615. #else
  2616. $$=0;
  2617. yyerror("tls support not compiled in");
  2618. #endif
  2619. }
  2620. | FORWARD_TLS error { $$=0; yyerror("missing '(' or ')' ?"); }
  2621. | FORWARD_TLS LPAREN error RPAREN { $$=0;
  2622. yyerror("bad forward_tls argument"); }
  2623. | FORWARD_SCTP LPAREN host RPAREN {
  2624. #ifdef USE_SCTP
  2625. $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
  2626. #else
  2627. $$=0;
  2628. yyerror("sctp support not compiled in");
  2629. #endif
  2630. }
  2631. | FORWARD_SCTP LPAREN STRING RPAREN {
  2632. #ifdef USE_SCTP
  2633. $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
  2634. #else
  2635. $$=0;
  2636. yyerror("sctp support not compiled in");
  2637. #endif
  2638. }
  2639. | FORWARD_SCTP LPAREN ip RPAREN {
  2640. #ifdef USE_SCTP
  2641. $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$);
  2642. #else
  2643. $$=0;
  2644. yyerror("sctp support not compiled in");
  2645. #endif
  2646. }
  2647. | FORWARD_SCTP LPAREN host COMMA NUMBER RPAREN {
  2648. #ifdef USE_SCTP
  2649. $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
  2650. (void*)$5); set_cfg_pos($$);
  2651. #else
  2652. $$=0;
  2653. yyerror("sctp support not compiled in");
  2654. #endif
  2655. }
  2656. | FORWARD_SCTP LPAREN STRING COMMA NUMBER RPAREN {
  2657. #ifdef USE_SCTP
  2658. $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
  2659. (void*)$5); set_cfg_pos($$);
  2660. #else
  2661. $$=0;
  2662. yyerror("sctp support not compiled in");
  2663. #endif
  2664. }
  2665. | FORWARD_SCTP LPAREN ip COMMA NUMBER RPAREN {
  2666. #ifdef USE_SCTP
  2667. $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST,
  2668. (void*)$5); set_cfg_pos($$);
  2669. #else
  2670. $$=0;
  2671. yyerror("sctp support not compiled in");
  2672. #endif
  2673. }
  2674. | FORWARD_SCTP LPAREN URIHOST COMMA URIPORT RPAREN {
  2675. #ifdef USE_SCTP
  2676. $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$);
  2677. #else
  2678. $$=0;
  2679. yyerror("sctp support not compiled in");
  2680. #endif
  2681. }
  2682. | FORWARD_SCTP LPAREN URIHOST COMMA NUMBER RPAREN {
  2683. #ifdef USE_SCTP
  2684. $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST,
  2685. (void*)$5); set_cfg_pos($$);
  2686. #else
  2687. $$=0;
  2688. yyerror("sctp support not compiled in");
  2689. #endif
  2690. }
  2691. | FORWARD_SCTP LPAREN URIHOST RPAREN {
  2692. #ifdef USE_SCTP
  2693. $$=mk_action(FORWARD_SCTP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$);
  2694. #else
  2695. $$=0;
  2696. yyerror("tls support not compiled in");
  2697. #endif
  2698. }
  2699. | FORWARD_SCTP error { $$=0; yyerror("missing '(' or ')' ?"); }
  2700. | FORWARD_SCTP LPAREN error RPAREN { $$=0;
  2701. yyerror("bad forward_tls argument"); }
  2702. | SEND LPAREN host RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2703. | SEND LPAREN STRING RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2704. | SEND LPAREN ip RPAREN { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
  2705. | SEND LPAREN host COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2706. | SEND LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2707. | SEND LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2708. | SEND error { $$=0; yyerror("missing '(' or ')' ?"); }
  2709. | SEND LPAREN error RPAREN { $$=0; yyerror("bad send argument"); }
  2710. | SEND_TCP LPAREN host RPAREN { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2711. | SEND_TCP LPAREN STRING RPAREN { $$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
  2712. | SEND_TCP LPAREN ip RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
  2713. | SEND_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action( SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);}
  2714. | SEND_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(SEND_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2715. | SEND_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(SEND_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
  2716. | SEND_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
  2717. | SEND_TCP LPAREN error RPAREN { $$=0; yyerror("bad send_tcp argument"); }
  2718. | LOG_TOK LPAREN STRING RPAREN {$$=mk_action(LOG_T, 2, NUMBER_ST,
  2719. (void*)(L_DBG+1), STRING_ST, $3);
  2720. set_cfg_pos($$); }
  2721. | LOG_TOK LPAREN NUMBER COMMA STRING RPAREN {$$=mk_action(LOG_T, 2, NUMBER_ST, (void*)$3, STRING_ST, $5); set_cfg_pos($$); }
  2722. | LOG_TOK error { $$=0; yyerror("missing '(' or ')' ?"); }
  2723. | LOG_TOK LPAREN error RPAREN { $$=0; yyerror("bad log argument"); }
  2724. | SETFLAG LPAREN NUMBER RPAREN {
  2725. if (check_flag($3)==-1)
  2726. yyerror("bad flag value");
  2727. $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
  2728. (void*)$3);
  2729. set_cfg_pos($$);
  2730. }
  2731. | SETFLAG LPAREN flag_name RPAREN {
  2732. i_tmp=get_flag_no($3, strlen($3));
  2733. if (i_tmp<0) yyerror("flag not declared");
  2734. $$=mk_action(SETFLAG_T, 1, NUMBER_ST,
  2735. (void*)(long)i_tmp);
  2736. set_cfg_pos($$);
  2737. }
  2738. | SETFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
  2739. | RESETFLAG LPAREN NUMBER RPAREN {
  2740. if (check_flag($3)==-1)
  2741. yyerror("bad flag value");
  2742. $$=mk_action(RESETFLAG_T, 1, NUMBER_ST, (void*)$3);
  2743. set_cfg_pos($$);
  2744. }
  2745. | RESETFLAG LPAREN flag_name RPAREN {
  2746. i_tmp=get_flag_no($3, strlen($3));
  2747. if (i_tmp<0) yyerror("flag not declared");
  2748. $$=mk_action(RESETFLAG_T, 1, NUMBER_ST,
  2749. (void*)(long)i_tmp);
  2750. set_cfg_pos($$);
  2751. }
  2752. | RESETFLAG error { $$=0; yyerror("missing '(' or ')'?"); }
  2753. | ISFLAGSET LPAREN NUMBER RPAREN {
  2754. if (check_flag($3)==-1)
  2755. yyerror("bad flag value");
  2756. $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST, (void*)$3);
  2757. set_cfg_pos($$);
  2758. }
  2759. | ISFLAGSET LPAREN flag_name RPAREN {
  2760. i_tmp=get_flag_no($3, strlen($3));
  2761. if (i_tmp<0) yyerror("flag not declared");
  2762. $$=mk_action(ISFLAGSET_T, 1, NUMBER_ST,
  2763. (void*)(long)i_tmp);
  2764. set_cfg_pos($$);
  2765. }
  2766. | ISFLAGSET error { $$=0; yyerror("missing '(' or ')'?"); }
  2767. | avpflag_oper LPAREN attr_id_any_str COMMA flag_name RPAREN {
  2768. i_tmp=get_avpflag_no($5);
  2769. if (i_tmp==0) yyerror("avpflag not declared");
  2770. $$=mk_action(AVPFLAG_OPER_T, 3, AVP_ST, $3, NUMBER_ST, (void*)(long)i_tmp, NUMBER_ST, (void*)$1);
  2771. set_cfg_pos($$);
  2772. }
  2773. | avpflag_oper LPAREN attr_id_any_str COMMA error RPAREN {
  2774. $$=0; yyerror("error parsing flag name");
  2775. }
  2776. | avpflag_oper LPAREN error COMMA flag_name RPAREN {
  2777. $$=0; yyerror("error parsing first parameter (avp or string)");
  2778. }
  2779. | avpflag_oper LPAREN error RPAREN { $$=0; yyerror("bad parameters"); }
  2780. | avpflag_oper error { $$=0; yyerror("missing '(' or ')'?"); }
  2781. | ERROR LPAREN STRING COMMA STRING RPAREN {$$=mk_action(ERROR_T, 2, STRING_ST, $3, STRING_ST, $5);
  2782. set_cfg_pos($$);
  2783. }
  2784. | ERROR error { $$=0; yyerror("missing '(' or ')' ?"); }
  2785. | ERROR LPAREN error RPAREN { $$=0; yyerror("bad error argument"); }
  2786. | ROUTE LPAREN route_name RPAREN {
  2787. i_tmp=route_get(&main_rt, $3);
  2788. if (i_tmp==-1){
  2789. yyerror("internal error");
  2790. YYABORT;
  2791. }
  2792. $$=mk_action(ROUTE_T, 1, NUMBER_ST,(void*)(long)i_tmp);
  2793. set_cfg_pos($$);
  2794. }
  2795. | ROUTE error { $$=0; yyerror("missing '(' or ')' ?"); }
  2796. | ROUTE LPAREN error RPAREN { $$=0; yyerror("bad route argument"); }
  2797. | EXEC LPAREN STRING RPAREN { $$=mk_action(EXEC_T, 1, STRING_ST, $3); set_cfg_pos($$); }
  2798. | SET_HOST LPAREN STRING RPAREN { $$=mk_action(SET_HOST_T, 1, STRING_ST, $3); set_cfg_pos($$); }
  2799. | SET_HOST error { $$=0; yyerror("missing '(' or ')' ?"); }
  2800. | SET_HOST LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2801. | PREFIX LPAREN STRING RPAREN { $$=mk_action(PREFIX_T, 1, STRING_ST, $3); set_cfg_pos($$); }
  2802. | PREFIX error { $$=0; yyerror("missing '(' or ')' ?"); }
  2803. | PREFIX LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2804. | STRIP_TAIL LPAREN NUMBER RPAREN { $$=mk_action(STRIP_TAIL_T, 1, NUMBER_ST, (void*)$3); set_cfg_pos($$); }
  2805. | STRIP_TAIL error { $$=0; yyerror("missing '(' or ')' ?"); }
  2806. | STRIP_TAIL LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
  2807. | STRIP LPAREN NUMBER RPAREN { $$=mk_action(STRIP_T, 1, NUMBER_ST, (void*) $3); set_cfg_pos($$); }
  2808. | STRIP error { $$=0; yyerror("missing '(' or ')' ?"); }
  2809. | STRIP LPAREN error RPAREN { $$=0; yyerror("bad argument, number expected"); }
  2810. | SET_USERPHONE LPAREN RPAREN { $$=mk_action(SET_USERPHONE_T, 0); set_cfg_pos($$); }
  2811. | SET_USERPHONE error { $$=0; yyerror("missing '(' or ')' ?"); }
  2812. | APPEND_BRANCH LPAREN STRING COMMA STRING RPAREN {
  2813. qvalue_t q;
  2814. if (str2q(&q, $5, strlen($5)) < 0) {
  2815. yyerror("bad argument, q value expected");
  2816. }
  2817. $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, $3, NUMBER_ST, (void *)(long)q);
  2818. set_cfg_pos($$);
  2819. }
  2820. | APPEND_BRANCH LPAREN STRING RPAREN { $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, $3, NUMBER_ST, (void *)Q_UNSPECIFIED); set_cfg_pos($$); }
  2821. | APPEND_BRANCH LPAREN RPAREN { $$=mk_action(APPEND_BRANCH_T, 2, STRING_ST, 0, NUMBER_ST, (void *)Q_UNSPECIFIED); set_cfg_pos($$); }
  2822. | APPEND_BRANCH { $$=mk_action( APPEND_BRANCH_T, 1, STRING_ST, 0); set_cfg_pos($$); }
  2823. | SET_HOSTPORT LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORT_T, 1, STRING_ST, $3); set_cfg_pos($$); }
  2824. | SET_HOSTPORT error { $$=0; yyerror("missing '(' or ')' ?"); }
  2825. | SET_HOSTPORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2826. | SET_HOSTPORTTRANS LPAREN STRING RPAREN { $$=mk_action(SET_HOSTPORTTRANS_T, 1, STRING_ST, $3); set_cfg_pos($$); }
  2827. | SET_HOSTPORTTRANS error { $$=0; yyerror("missing '(' or ')' ?"); }
  2828. | SET_HOSTPORTTRANS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2829. | SET_PORT LPAREN STRING RPAREN { $$=mk_action(SET_PORT_T, 1, STRING_ST, $3); set_cfg_pos($$); }
  2830. | SET_PORT error { $$=0; yyerror("missing '(' or ')' ?"); }
  2831. | SET_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2832. | SET_USER LPAREN STRING RPAREN { $$=mk_action(SET_USER_T, 1, STRING_ST, $3); set_cfg_pos($$); }
  2833. | SET_USER error { $$=0; yyerror("missing '(' or ')' ?"); }
  2834. | SET_USER LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2835. | SET_USERPASS LPAREN STRING RPAREN { $$=mk_action(SET_USERPASS_T, 1, STRING_ST, $3); set_cfg_pos($$); }
  2836. | SET_USERPASS error { $$=0; yyerror("missing '(' or ')' ?"); }
  2837. | SET_USERPASS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2838. | SET_URI LPAREN STRING RPAREN { $$=mk_action(SET_URI_T, 1, STRING_ST,$3); set_cfg_pos($$); }
  2839. | SET_URI error { $$=0; yyerror("missing '(' or ')' ?"); }
  2840. | SET_URI LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2841. | REVERT_URI LPAREN RPAREN { $$=mk_action(REVERT_URI_T, 0); set_cfg_pos($$); }
  2842. | REVERT_URI { $$=mk_action(REVERT_URI_T, 0); set_cfg_pos($$); }
  2843. | FORCE_RPORT LPAREN RPAREN { $$=mk_action(FORCE_RPORT_T, 0); set_cfg_pos($$); }
  2844. | FORCE_RPORT {$$=mk_action(FORCE_RPORT_T, 0); set_cfg_pos($$); }
  2845. | ADD_LOCAL_RPORT LPAREN RPAREN { $$=mk_action(ADD_LOCAL_RPORT_T, 0); set_cfg_pos($$); }
  2846. | ADD_LOCAL_RPORT {$$=mk_action(ADD_LOCAL_RPORT_T, 0); set_cfg_pos($$); }
  2847. | FORCE_TCP_ALIAS LPAREN NUMBER RPAREN {
  2848. #ifdef USE_TCP
  2849. $$=mk_action(FORCE_TCP_ALIAS_T, 1, NUMBER_ST, (void*)$3);
  2850. set_cfg_pos($$);
  2851. #else
  2852. yyerror("tcp support not compiled in");
  2853. #endif
  2854. }
  2855. | FORCE_TCP_ALIAS LPAREN RPAREN {
  2856. #ifdef USE_TCP
  2857. $$=mk_action(FORCE_TCP_ALIAS_T, 0);
  2858. set_cfg_pos($$);
  2859. #else
  2860. yyerror("tcp support not compiled in");
  2861. #endif
  2862. }
  2863. | FORCE_TCP_ALIAS {
  2864. #ifdef USE_TCP
  2865. $$=mk_action(FORCE_TCP_ALIAS_T, 0);
  2866. set_cfg_pos($$);
  2867. #else
  2868. yyerror("tcp support not compiled in");
  2869. #endif
  2870. }
  2871. | FORCE_TCP_ALIAS LPAREN error RPAREN {$$=0; yyerror("bad argument, number expected"); }
  2872. | UDP_MTU_TRY_PROTO LPAREN proto RPAREN
  2873. { $$=mk_action(UDP_MTU_TRY_PROTO_T, 1, NUMBER_ST, $3); set_cfg_pos($$); }
  2874. | UDP_MTU_TRY_PROTO LPAREN error RPAREN
  2875. { $$=0; yyerror("bad argument, UDP, TCP, TLS or SCTP expected"); }
  2876. | SET_ADV_ADDRESS LPAREN listen_id RPAREN {
  2877. $$=0;
  2878. if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
  2879. LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
  2880. } else {
  2881. str_tmp->s=$3;
  2882. str_tmp->len=$3?strlen($3):0;
  2883. $$=mk_action(SET_ADV_ADDR_T, 1, STR_ST, str_tmp);
  2884. set_cfg_pos($$);
  2885. }
  2886. }
  2887. | SET_ADV_ADDRESS LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2888. | SET_ADV_ADDRESS error {$$=0; yyerror("missing '(' or ')' ?"); }
  2889. | SET_ADV_PORT LPAREN NUMBER RPAREN {
  2890. $$=0;
  2891. tmp=int2str($3, &i_tmp);
  2892. if ((str_tmp=pkg_malloc(sizeof(str)))==0) {
  2893. LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
  2894. } else {
  2895. if ((str_tmp->s=pkg_malloc(i_tmp))==0) {
  2896. LOG(L_CRIT, "ERROR: cfg. parser: out of memory.\n");
  2897. } else {
  2898. memcpy(str_tmp->s, tmp, i_tmp);
  2899. str_tmp->len=i_tmp;
  2900. $$=mk_action(SET_ADV_PORT_T, 1, STR_ST, str_tmp);
  2901. set_cfg_pos($$);
  2902. }
  2903. }
  2904. }
  2905. | SET_ADV_PORT LPAREN error RPAREN { $$=0; yyerror("bad argument, string expected"); }
  2906. | SET_ADV_PORT error {$$=0; yyerror("missing '(' or ')' ?"); }
  2907. | FORCE_SEND_SOCKET LPAREN phostport RPAREN {
  2908. $$=mk_action(FORCE_SEND_SOCKET_T, 1, SOCKID_ST, $3);
  2909. set_cfg_pos($$);
  2910. }
  2911. | FORCE_SEND_SOCKET LPAREN error RPAREN {
  2912. $$=0; yyerror("bad argument, [proto:]host[:port] expected");
  2913. }
  2914. | FORCE_SEND_SOCKET error {$$=0; yyerror("missing '(' or ')' ?"); }
  2915. | SET_FWD_NO_CONNECT LPAREN RPAREN {
  2916. $$=mk_action(SET_FWD_NO_CONNECT_T, 0); set_cfg_pos($$);
  2917. }
  2918. | SET_FWD_NO_CONNECT {
  2919. $$=mk_action(SET_FWD_NO_CONNECT_T, 0); set_cfg_pos($$);
  2920. }
  2921. | SET_RPL_NO_CONNECT LPAREN RPAREN {
  2922. $$=mk_action(SET_RPL_NO_CONNECT_T, 0); set_cfg_pos($$);
  2923. }
  2924. | SET_RPL_NO_CONNECT {
  2925. $$=mk_action(SET_RPL_NO_CONNECT_T, 0); set_cfg_pos($$);
  2926. }
  2927. | SET_FWD_CLOSE LPAREN RPAREN {
  2928. $$=mk_action(SET_FWD_CLOSE_T, 0); set_cfg_pos($$);
  2929. }
  2930. | SET_FWD_CLOSE {
  2931. $$=mk_action(SET_FWD_CLOSE_T, 0); set_cfg_pos($$);
  2932. }
  2933. | SET_RPL_CLOSE LPAREN RPAREN {
  2934. $$=mk_action(SET_RPL_CLOSE_T, 0); set_cfg_pos($$);
  2935. }
  2936. | SET_RPL_CLOSE {
  2937. $$=mk_action(SET_RPL_CLOSE_T, 0); set_cfg_pos($$);
  2938. }
  2939. | ID {mod_func_action = mk_action(MODULE_T, 2, MODEXP_ST, NULL, NUMBER_ST,
  2940. 0); } LPAREN func_params RPAREN {
  2941. mod_func_action->val[0].u.data =
  2942. find_export_record($1, mod_func_action->val[1].u.number, rt,
  2943. &u_tmp);
  2944. if (mod_func_action->val[0].u.data == 0) {
  2945. if (find_export_record($1, mod_func_action->val[1].u.number, 0,
  2946. &u_tmp) ) {
  2947. yyerror("Command cannot be used in the block\n");
  2948. } else {
  2949. yyerror("unknown command, missing loadmodule?\n");
  2950. }
  2951. pkg_free(mod_func_action);
  2952. mod_func_action=0;
  2953. }else{
  2954. switch( ((union cmd_export_u*)
  2955. mod_func_action->val[0].u.data)->c.param_no){
  2956. case 0:
  2957. case 1:
  2958. case 2:
  2959. /* MODULE_T used for 0-2 params */
  2960. break;
  2961. case 3:
  2962. mod_func_action->type=MODULE3_T;
  2963. break;
  2964. case 4:
  2965. mod_func_action->type=MODULE4_T;
  2966. break;
  2967. case 5:
  2968. mod_func_action->type=MODULE5_T;
  2969. break;
  2970. case 6:
  2971. mod_func_action->type=MODULE6_T;
  2972. break;
  2973. case VAR_PARAM_NO:
  2974. mod_func_action->type=MODULEX_T;
  2975. break;
  2976. default:
  2977. yyerror("too many parameters for function\n");
  2978. break;
  2979. }
  2980. }
  2981. $$ = mod_func_action;
  2982. set_cfg_pos($$);
  2983. }
  2984. | ID error { yyerror("'('')' expected (function call)");}
  2985. ;
  2986. func_params:
  2987. /* empty */
  2988. | func_params COMMA func_param { }
  2989. | func_param {}
  2990. | func_params error { yyerror("call params error\n"); }
  2991. ;
  2992. func_param:
  2993. intno {
  2994. if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
  2995. mod_func_action->val[mod_func_action->val[1].u.number+2].type =
  2996. NUMBER_ST;
  2997. mod_func_action->val[mod_func_action->val[1].u.number+2].u.number =
  2998. $1;
  2999. mod_func_action->val[1].u.number++;
  3000. } else {
  3001. yyerror("Too many arguments\n");
  3002. }
  3003. }
  3004. | STRING {
  3005. if (mod_func_action->val[1].u.number < MAX_ACTIONS-2) {
  3006. mod_func_action->val[mod_func_action->val[1].u.number+2].type = STRING_ST;
  3007. mod_func_action->val[mod_func_action->val[1].u.number+2].u.string = $1;
  3008. mod_func_action->val[1].u.number++;
  3009. } else {
  3010. yyerror("Too many arguments\n");
  3011. }
  3012. }
  3013. ;
  3014. ret_cmd:
  3015. DROP LPAREN RPAREN {
  3016. $$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST,
  3017. (void*)(DROP_R_F|EXIT_R_F)); set_cfg_pos($$);
  3018. }
  3019. | DROP rval_expr {
  3020. $$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST,
  3021. (void*)(DROP_R_F|EXIT_R_F)); set_cfg_pos($$);
  3022. }
  3023. | DROP {
  3024. $$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST,
  3025. (void*)(DROP_R_F|EXIT_R_F)); set_cfg_pos($$);
  3026. }
  3027. | EXIT LPAREN RPAREN {
  3028. $$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F);
  3029. set_cfg_pos($$);
  3030. }
  3031. | EXIT rval_expr {
  3032. $$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST, (void*)EXIT_R_F);
  3033. set_cfg_pos($$);
  3034. }
  3035. | EXIT {
  3036. $$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)EXIT_R_F);
  3037. set_cfg_pos($$);
  3038. }
  3039. | RETURN {
  3040. $$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST,
  3041. (void*)RETURN_R_F); set_cfg_pos($$);
  3042. }
  3043. | RETURN LPAREN RPAREN {
  3044. $$=mk_action(DROP_T, 2, NUMBER_ST, (void*)1, NUMBER_ST,
  3045. (void*)RETURN_R_F); set_cfg_pos($$);
  3046. }
  3047. | RETURN rval_expr {
  3048. $$=mk_action(DROP_T, 2, RVE_ST, $2, NUMBER_ST, (void*)RETURN_R_F);
  3049. set_cfg_pos($$);
  3050. }
  3051. | BREAK {
  3052. $$=mk_action(DROP_T, 2, NUMBER_ST, 0, NUMBER_ST, (void*)BREAK_R_F);
  3053. set_cfg_pos($$);
  3054. }
  3055. ;
  3056. %%
  3057. static void get_cpos(struct cfg_pos* pos)
  3058. {
  3059. pos->s_line=startline;
  3060. pos->e_line=line;
  3061. pos->s_col=startcolumn;
  3062. pos->e_col=column-1;
  3063. if(finame==0)
  3064. finame = (cfg_file!=0)?cfg_file:"default";
  3065. pos->fname=finame;
  3066. }
  3067. static void warn_at(struct cfg_pos* p, char* format, ...)
  3068. {
  3069. va_list ap;
  3070. char s[256];
  3071. va_start(ap, format);
  3072. vsnprintf(s, sizeof(s), format, ap);
  3073. va_end(ap);
  3074. if (p->e_line!=p->s_line)
  3075. LOG(L_WARN, "warning in config file %s, from line %d, column %d to"
  3076. " line %d, column %d: %s\n",
  3077. p->fname, p->s_line, p->s_col, p->e_line, p->e_col, s);
  3078. else if (p->s_col!=p->e_col)
  3079. LOG(L_WARN, "warning in config file %s, line %d, column %d-%d: %s\n",
  3080. p->fname, p->s_line, p->s_col, p->e_col, s);
  3081. else
  3082. LOG(L_WARN, "warning in config file %s, line %d, column %d: %s\n",
  3083. p->fname, p->s_line, p->s_col, s);
  3084. cfg_warnings++;
  3085. }
  3086. static void yyerror_at(struct cfg_pos* p, char* format, ...)
  3087. {
  3088. va_list ap;
  3089. char s[256];
  3090. va_start(ap, format);
  3091. vsnprintf(s, sizeof(s), format, ap);
  3092. va_end(ap);
  3093. if (p->e_line!=p->s_line)
  3094. LOG(L_CRIT, "parse error in config file %s, from line %d, column %d"
  3095. " to line %d, column %d: %s\n",
  3096. p->fname, p->s_line, p->s_col, p->e_line, p->e_col, s);
  3097. else if (p->s_col!=p->e_col)
  3098. LOG(L_CRIT,"parse error in config file %s, line %d, column %d-%d: %s\n",
  3099. p->fname, p->s_line, p->s_col, p->e_col, s);
  3100. else
  3101. LOG(L_CRIT, "parse error in config file %s, line %d, column %d: %s\n",
  3102. p->fname, p->s_line, p->s_col, s);
  3103. cfg_errors++;
  3104. }
  3105. static void warn(char* format, ...)
  3106. {
  3107. va_list ap;
  3108. char s[256];
  3109. struct cfg_pos pos;
  3110. get_cpos(&pos);
  3111. va_start(ap, format);
  3112. vsnprintf(s, sizeof(s), format, ap);
  3113. va_end(ap);
  3114. warn_at(&pos, s);
  3115. }
  3116. static void yyerror(char* format, ...)
  3117. {
  3118. va_list ap;
  3119. char s[256];
  3120. struct cfg_pos pos;
  3121. get_cpos(&pos);
  3122. va_start(ap, format);
  3123. vsnprintf(s, sizeof(s), format, ap);
  3124. va_end(ap);
  3125. yyerror_at(&pos, s);
  3126. }
  3127. /** mk_rval_expr_v wrapper.
  3128. * checks mk_rval_expr_v return value and sets the cfg. pos
  3129. * (line and column numbers)
  3130. * @return rval_expr* on success, 0 on error (@see mk_rval_expr_v)
  3131. */
  3132. static struct rval_expr* mk_rve_rval(enum rval_type type, void* v)
  3133. {
  3134. struct rval_expr* ret;
  3135. struct cfg_pos pos;
  3136. get_cpos(&pos);
  3137. ret=mk_rval_expr_v(type, v, &pos);
  3138. if (ret==0){
  3139. yyerror("internal error: failed to create rval expr");
  3140. /* YYABORT; */
  3141. }
  3142. return ret;
  3143. }
  3144. /** mk_rval_expr1 wrapper.
  3145. * checks mk_rval_expr1 return value (!=0 and type checking)
  3146. * @return rval_expr* on success, 0 on error (@see mk_rval_expr1)
  3147. */
  3148. static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1)
  3149. {
  3150. struct rval_expr* ret;
  3151. struct rval_expr* bad_rve;
  3152. enum rval_type type, bad_t, exp_t;
  3153. if (rve1==0)
  3154. return 0;
  3155. ret=mk_rval_expr1(op, rve1, &rve1->fpos);
  3156. if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
  3157. yyerror_at(&rve1->fpos, "bad expression: type mismatch"
  3158. " (%s instead of %s)", rval_type_name(bad_t),
  3159. rval_type_name(exp_t));
  3160. rve_destroy(ret);
  3161. ret=0;
  3162. }
  3163. return ret;
  3164. }
  3165. /** mk_rval_expr2 wrapper.
  3166. * checks mk_rval_expr2 return value (!=0 and type checking)
  3167. * @return rval_expr* on success, 0 on error (@see mk_rval_expr2)
  3168. */
  3169. static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1,
  3170. struct rval_expr* rve2)
  3171. {
  3172. struct rval_expr* ret;
  3173. struct rval_expr* bad_rve;
  3174. enum rval_type type, bad_t, exp_t;
  3175. struct cfg_pos pos;
  3176. if ((rve1==0) || (rve2==0))
  3177. return 0;
  3178. bad_rve=0;
  3179. bad_t=0;
  3180. exp_t=0;
  3181. cfg_pos_join(&pos, &rve1->fpos, &rve2->fpos);
  3182. ret=mk_rval_expr2(op, rve1, rve2, &pos);
  3183. if (ret && (rve_check_type(&type, ret, &bad_rve, &bad_t, &exp_t)!=1)){
  3184. if (bad_rve)
  3185. yyerror_at(&pos, "bad expression: type mismatch:"
  3186. " %s instead of %s at (%d,%d)",
  3187. rval_type_name(bad_t), rval_type_name(exp_t),
  3188. bad_rve->fpos.s_line, bad_rve->fpos.s_col);
  3189. else
  3190. yyerror("BUG: unexpected null \"bad\" expression\n");
  3191. rve_destroy(ret);
  3192. ret=0;
  3193. }
  3194. return ret;
  3195. }
  3196. /** check if the expression is an int.
  3197. * if the expression does not evaluate to an int return -1 and
  3198. * log an error.
  3199. * @return 0 success, no warnings; 1 success but warnings; -1 on error */
  3200. static int rval_expr_int_check(struct rval_expr *rve)
  3201. {
  3202. struct rval_expr* bad_rve;
  3203. enum rval_type type, bad_t, exp_t;
  3204. if (rve==0){
  3205. yyerror("invalid expression");
  3206. return -1;
  3207. }else if (!rve_check_type(&type, rve, &bad_rve, &bad_t ,&exp_t)){
  3208. if (bad_rve)
  3209. yyerror_at(&rve->fpos, "bad expression: type mismatch:"
  3210. " %s instead of %s at (%d,%d)",
  3211. rval_type_name(bad_t), rval_type_name(exp_t),
  3212. bad_rve->fpos.s_line, bad_rve->fpos.s_col);
  3213. else
  3214. yyerror("BUG: unexpected null \"bad\" expression\n");
  3215. return -1;
  3216. }else if (type!=RV_INT && type!=RV_NONE){
  3217. warn_at(&rve->fpos, "non-int expression (you might want to use"
  3218. " casts)\n");
  3219. return 1;
  3220. }
  3221. return 0;
  3222. }
  3223. /** warn if the expression is constant.
  3224. * @return 0 on success (no warning), 1 when warning */
  3225. static int warn_ct_rve(struct rval_expr *rve, char* name)
  3226. {
  3227. if (rve && rve_is_constant(rve)){
  3228. warn_at(&rve->fpos, "constant value in %s%s",
  3229. name?name:"expression", name?"(...)":"");
  3230. return 1;
  3231. }
  3232. return 0;
  3233. }
  3234. static struct name_lst* mk_name_lst(char* host, int flags)
  3235. {
  3236. struct name_lst* l;
  3237. if (host==0) return 0;
  3238. l=pkg_malloc(sizeof(struct name_lst));
  3239. if (l==0) {
  3240. LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
  3241. } else {
  3242. l->name=host;
  3243. l->flags=flags;
  3244. l->next=0;
  3245. }
  3246. return l;
  3247. }
  3248. static struct socket_id* mk_listen_id(char* host, int proto, int port)
  3249. {
  3250. struct socket_id* l;
  3251. if (host==0) return 0;
  3252. l=pkg_malloc(sizeof(struct socket_id));
  3253. if (l==0) {
  3254. LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
  3255. } else {
  3256. l->addr_lst=mk_name_lst(host, 0);
  3257. if (l->addr_lst==0){
  3258. pkg_free(l);
  3259. return 0;
  3260. }
  3261. l->flags=0;
  3262. l->port=port;
  3263. l->proto=proto;
  3264. l->next=0;
  3265. }
  3266. return l;
  3267. }
  3268. static void free_name_lst(struct name_lst* lst)
  3269. {
  3270. struct name_lst* tmp;
  3271. while(lst){
  3272. tmp=lst;
  3273. lst=lst->next;
  3274. pkg_free(tmp);
  3275. }
  3276. }
  3277. static struct socket_id* mk_listen_id2(struct name_lst* addr_l, int proto,
  3278. int port)
  3279. {
  3280. struct socket_id* l;
  3281. if (addr_l==0) return 0;
  3282. l=pkg_malloc(sizeof(struct socket_id));
  3283. if (l==0) {
  3284. LOG(L_CRIT,"ERROR: cfg. parser: out of memory.\n");
  3285. } else {
  3286. l->flags=addr_l->flags;
  3287. l->port=port;
  3288. l->proto=proto;
  3289. l->addr_lst=addr_l;
  3290. l->next=0;
  3291. }
  3292. return l;
  3293. }
  3294. static void free_socket_id(struct socket_id* i)
  3295. {
  3296. free_name_lst(i->addr_lst);
  3297. pkg_free(i);
  3298. }
  3299. static void free_socket_id_lst(struct socket_id* lst)
  3300. {
  3301. struct socket_id* tmp;
  3302. while(lst){
  3303. tmp=lst;
  3304. lst=lst->next;
  3305. free_socket_id(tmp);
  3306. }
  3307. }
  3308. /** create a temporary case statmenet structure.
  3309. * *err will be filled in case of error (return == 0):
  3310. * -1 - non constant expression
  3311. * -2 - expression error (bad type)
  3312. * -10 - memory allocation error
  3313. */
  3314. static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re,
  3315. struct action* a, int* err)
  3316. {
  3317. struct case_stms* s;
  3318. struct rval_expr* bad_rve;
  3319. enum rval_type type, bad_t, exp_t;
  3320. enum match_str_type t;
  3321. t=MATCH_UNKNOWN;
  3322. if (ct){
  3323. /* if ct!=0 => case, else if ct==0 is a default */
  3324. if (!rve_is_constant(ct)){
  3325. yyerror_at(&ct->fpos, "non constant expression in case");
  3326. *err=-1;
  3327. return 0;
  3328. }
  3329. if (rve_check_type(&type, ct, &bad_rve, &bad_t, &exp_t)!=1){
  3330. yyerror_at(&ct->fpos, "bad expression: type mismatch:"
  3331. " %s instead of %s at (%d,%d)",
  3332. rval_type_name(bad_t), rval_type_name(exp_t),
  3333. bad_rve->fpos.s_line, bad_rve->fpos.s_col);
  3334. *err=-2;
  3335. return 0;
  3336. }
  3337. if (is_re)
  3338. t=MATCH_RE;
  3339. else if (type==RV_STR)
  3340. t=MATCH_STR;
  3341. else
  3342. t=MATCH_INT;
  3343. }
  3344. s=pkg_malloc(sizeof(*s));
  3345. if (s==0) {
  3346. yyerror("internal error: memory allocation failure");
  3347. *err=-10;
  3348. } else {
  3349. memset(s, 0, sizeof(*s));
  3350. s->ct_rve=ct;
  3351. s->type=t;
  3352. s->actions=a;
  3353. s->next=0;
  3354. s->append=0;
  3355. }
  3356. return s;
  3357. }
  3358. /*
  3359. * @return 0 on success, -1 on error.
  3360. */
  3361. static int case_check_type(struct case_stms* stms)
  3362. {
  3363. struct case_stms* c;
  3364. struct case_stms* s;
  3365. for(c=stms; c ; c=c->next){
  3366. if (!c->ct_rve) continue;
  3367. for (s=c->next; s; s=s->next){
  3368. if (!s->ct_rve) continue;
  3369. if ((s->type!=c->type) &&
  3370. !( (c->type==MATCH_STR || c->type==MATCH_RE) &&
  3371. (s->type==MATCH_STR || s->type==MATCH_RE) ) ){
  3372. yyerror_at(&s->ct_rve->fpos, "type mismatch in case");
  3373. return -1;
  3374. }
  3375. }
  3376. }
  3377. return 0;
  3378. }
  3379. /*
  3380. * @return 0 on success, -1 on error.
  3381. */
  3382. static int case_check_default(struct case_stms* stms)
  3383. {
  3384. struct case_stms* c;
  3385. int default_no;
  3386. default_no=0;
  3387. for(c=stms; c ; c=c->next)
  3388. if (c->ct_rve==0) default_no++;
  3389. return (default_no<=1)?0:-1;
  3390. }
  3391. /*
  3392. int main(int argc, char ** argv)
  3393. {
  3394. if (yyparse()!=0)
  3395. fprintf(stderr, "parsing error\n");
  3396. }
  3397. */