cfg.y 110 KB

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