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