core: new core parameter xavp_via_params
[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 XAVPVIAPARAMS
328 %token LISTEN
329 %token ADVERTISE
330 %token ALIAS
331 %token SR_AUTO_ALIASES
332 %token DNS
333 %token REV_DNS
334 %token DNS_TRY_IPV6
335 %token DNS_TRY_NAPTR
336 %token DNS_SRV_LB
337 %token DNS_UDP_PREF
338 %token DNS_TCP_PREF
339 %token DNS_TLS_PREF
340 %token DNS_SCTP_PREF
341 %token DNS_RETR_TIME
342 %token DNS_RETR_NO
343 %token DNS_SERVERS_NO
344 %token DNS_USE_SEARCH
345 %token DNS_SEARCH_FMATCH
346 %token DNS_NAPTR_IGNORE_RFC
347 %token DNS_CACHE_INIT
348 %token DNS_USE_CACHE
349 %token DNS_USE_FAILOVER
350 %token DNS_CACHE_FLAGS
351 %token DNS_CACHE_NEG_TTL
352 %token DNS_CACHE_MIN_TTL
353 %token DNS_CACHE_MAX_TTL
354 %token DNS_CACHE_MEM
355 %token DNS_CACHE_GC_INT
356 %token DNS_CACHE_DEL_NONEXP
357 %token DNS_CACHE_REC_PREF
358
359 /* ipv6 auto bind */
360 %token AUTO_BIND_IPV6
361
362 /*blacklist*/
363 %token DST_BLST_INIT
364 %token USE_DST_BLST
365 %token DST_BLST_MEM
366 %token DST_BLST_TTL
367 %token DST_BLST_GC_INT
368 %token DST_BLST_UDP_IMASK
369 %token DST_BLST_TCP_IMASK
370 %token DST_BLST_TLS_IMASK
371 %token DST_BLST_SCTP_IMASK
372 %token IP_FREE_BIND
373
374 %token PORT
375 %token STAT
376 %token CHILDREN
377 %token SOCKET_WORKERS
378 %token ASYNC_WORKERS
379 %token ASYNC_USLEEP
380 %token CHECK_VIA
381 %token PHONE2TEL
382 %token MEMLOG
383 %token MEMDBG
384 %token MEMSUM
385 %token MEMSAFETY
386 %token MEMJOIN
387 %token MEMSTATUSMODE
388 %token CORELOG
389 %token SIP_WARNING
390 %token SERVER_SIGNATURE
391 %token SERVER_HEADER
392 %token USER_AGENT_HEADER
393 %token REPLY_TO_VIA
394 %token LOADMODULE
395 %token LOADPATH
396 %token MODPARAM
397 %token CFGENGINE
398 %token MAXBUFFER
399 %token SQL_BUFFER_SIZE
400 %token USER
401 %token GROUP
402 %token CHROOT
403 %token WDIR
404 %token RUNDIR
405 %token MHOMED
406 %token DISABLE_TCP
407 %token TCP_ACCEPT_ALIASES
408 %token TCP_CHILDREN
409 %token TCP_CONNECT_TIMEOUT
410 %token TCP_SEND_TIMEOUT
411 %token TCP_CON_LIFETIME
412 %token TCP_POLL_METHOD
413 %token TCP_MAX_CONNECTIONS
414 %token TLS_MAX_CONNECTIONS
415 %token TCP_NO_CONNECT
416 %token TCP_SOURCE_IPV4
417 %token TCP_SOURCE_IPV6
418 %token TCP_OPT_FD_CACHE
419 %token TCP_OPT_BUF_WRITE
420 %token TCP_OPT_CONN_WQ_MAX
421 %token TCP_OPT_WQ_MAX
422 %token TCP_OPT_RD_BUF
423 %token TCP_OPT_WQ_BLK
424 %token TCP_OPT_DEFER_ACCEPT
425 %token TCP_OPT_DELAYED_ACK
426 %token TCP_OPT_SYNCNT
427 %token TCP_OPT_LINGER2
428 %token TCP_OPT_KEEPALIVE
429 %token TCP_OPT_KEEPIDLE
430 %token TCP_OPT_KEEPINTVL
431 %token TCP_OPT_KEEPCNT
432 %token TCP_OPT_CRLF_PING
433 %token TCP_OPT_ACCEPT_NO_CL
434 %token TCP_OPT_ACCEPT_HEP3
435 %token TCP_CLONE_RCVBUF
436 %token TCP_REUSE_PORT
437 %token DISABLE_TLS
438 %token ENABLE_TLS
439 %token TLSLOG
440 %token TLS_PORT_NO
441 %token TLS_METHOD
442 %token TLS_HANDSHAKE_TIMEOUT
443 %token TLS_SEND_TIMEOUT
444 %token SSLv23
445 %token SSLv2
446 %token SSLv3
447 %token TLSv1
448 %token TLS_VERIFY
449 %token TLS_REQUIRE_CERTIFICATE
450 %token TLS_CERTIFICATE
451 %token TLS_PRIVATE_KEY
452 %token TLS_CA_LIST
453 %token DISABLE_SCTP
454 %token ENABLE_SCTP
455 %token SCTP_CHILDREN
456 %token ADVERTISED_ADDRESS
457 %token ADVERTISED_PORT
458 %token DISABLE_CORE
459 %token OPEN_FD_LIMIT
460 %token SHM_MEM_SZ
461 %token SHM_FORCE_ALLOC
462 %token MLOCK_PAGES
463 %token REAL_TIME
464 %token RT_PRIO
465 %token RT_POLICY
466 %token RT_TIMER1_PRIO
467 %token RT_TIMER1_POLICY
468 %token RT_TIMER2_PRIO
469 %token RT_TIMER2_POLICY
470 %token MCAST_LOOPBACK
471 %token MCAST_TTL
472 %token MCAST
473 %token TOS
474 %token PMTU_DISCOVERY
475 %token KILL_TIMEOUT
476 %token MAX_WLOOPS
477 %token PVBUFSIZE
478 %token PVBUFSLOTS
479 %token PVCACHELIMIT
480 %token PVCACHEACTION
481 %token HTTP_REPLY_PARSE
482 %token VERSION_TABLE_CFG
483 %token VERBOSE_STARTUP
484 %token ROUTE_LOCKS_SIZE
485 %token CFG_DESCRIPTION
486 %token SERVER_ID
487 %token KEMI
488 %token ONSEND_ROUTE_CALLBACK
489 %token REPLY_ROUTE_CALLBACK
490 %token EVENT_ROUTE_CALLBACK
491 %token MAX_RECURSIVE_LEVEL
492 %token MAX_BRANCHES_PARAM
493 %token LATENCY_CFG_LOG
494 %token LATENCY_LOG
495 %token LATENCY_LIMIT_DB
496 %token LATENCY_LIMIT_ACTION
497 %token MSG_TIME
498 %token ONSEND_RT_REPLY
499
500 %token FLAGS_DECL
501 %token AVPFLAGS_DECL
502
503 %token ATTR_MARK
504 %token SELECT_MARK
505 %token ATTR_FROM
506 %token ATTR_TO
507 %token ATTR_FROMURI
508 %token ATTR_TOURI
509 %token ATTR_FROMUSER
510 %token ATTR_TOUSER
511 %token ATTR_FROMDOMAIN
512 %token ATTR_TODOMAIN
513 %token ATTR_GLOBAL
514 %token ADDEQ
515
516
517 /*pre-processor*/
518 %token SUBST
519 %token SUBSTDEF
520 %token SUBSTDEFS
521
522 /* operators, C like precedence */
523 %right EQUAL
524 %left LOG_OR
525 %left LOG_AND
526 %left BIN_OR
527 %left BIN_AND
528 %left BIN_XOR
529 %left BIN_LSHIFT
530 %left BIN_RSHIFT
531 %left EQUAL_T DIFF MATCH INTEQ INTDIFF STREQ STRDIFF
532 %left GT LT GTE LTE
533 %left PLUS MINUS
534 %left STAR SLASH MODULO
535 %right NOT UNARY BIN_NOT
536 %right DEFINED
537 %right INTCAST STRCAST
538 %left DOT
539
540 /* no precedence, they use () */
541 %token STRLEN
542 %token STREMPTY
543
544 /* values */
545 %token <intval> NUMBER
546 %token <strval> ID
547 %token <strval> NUM_ID
548 %token <strval> STRING
549 %token <strval> IPV6ADDR
550 %token <strval> PVAR
551 /* not clear yet if this is an avp or pvar */
552 %token <strval> AVP_OR_PVAR
553 %token <strval> EVENT_RT_NAME
554
555 /* other */
556 %token COMMA
557 %token SEMICOLON
558 %token RPAREN
559 %token LPAREN
560 %token LBRACE
561 %token RBRACE
562 %token LBRACK
563 %token RBRACK
564 %token CR
565 %token COLON
566
567
568 /*non-terminals */
569 /*%type <expr> exp */
570 %type <expr> exp_elem
571 %type <intval> intno eint_op eint_op_onsend
572 %type <intval> eip_op eip_op_onsend
573 %type <action> action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action
574 %type <action> switch_cmd while_cmd ret_cmd
575 %type <case_stms> single_case case_stms
576 %type <ipaddr> ipv4 ipv6 ipv6addr ip
577 %type <ipnet> ipnet
578 %type <strval> host host_or_if host_if_id
579 %type <strval> listen_id
580 %type <name_l> listen_id_lst
581 %type <name_l> listen_id2
582 %type <sockid>  id_lst
583 %type <sockid>  phostport
584 %type <sockid>  listen_phostport
585 %type <intval> proto eqproto port
586 %type <intval> equalop strop cmpop rve_cmpop rve_equalop
587 %type <intval> uri_type
588 %type <attr> attr_id
589 %type <attr> attr_id_num_idx
590 %type <attr> attr_id_no_idx
591 %type <attr> attr_id_ass
592 /*%type <attr> attr_id_val*/
593 %type <attr> attr_id_any
594 %type <attr> attr_id_any_str
595 %type <pvar> pvar
596 %type <lval> lval
597 %type <rv_expr> rval rval_expr ct_rval
598 %type <lval> avp_pvar
599 /* %type <intval> class_id */
600 %type <intval> assign_op
601 %type <select> select_id
602 %type <strval>  flag_name;
603 %type <strval>  route_name;
604 %type <intval> avpflag_oper
605 %type <intval> rve_un_op
606 %type <strval> cfg_var_id
607 %type <strval> cfg_var_idn
608 /* %type <intval> rve_op */
609
610 /*%type <route_el> rules;
611   %type <route_el> rule;
612 */
613
614 %%
615
616
617 cfg:
618         statements
619         ;
620 statements:
621         statements statement {}
622         | statement {}
623         | statements error { yyerror(""); YYABORT;}
624         ;
625 statement:
626         assign_stm
627         | preprocess_stm
628         | flags_decl
629         | avpflags_decl
630         | module_stm
631         | {rt=REQUEST_ROUTE;} route_stm
632         | {rt=FAILURE_ROUTE;} failure_route_stm
633         | onreply_route_stm
634         | {rt=BRANCH_ROUTE;} branch_route_stm
635         | {rt=ONSEND_ROUTE;}   send_route_stm
636         | {rt=EVENT_ROUTE;}   event_route_stm
637         | SEMICOLON     /* null statement */
638         | CR    /* null statement*/
639         ;
640 listen_id:
641         ip {
642                 if ($1){
643                         tmp=ip_addr2a($1);
644                         if (tmp==0) {
645                                 LM_CRIT("cfg. parser: bad ip address.\n");
646                                 $$=0;
647                         } else {
648                                 $$=pkg_malloc(strlen(tmp)+1);
649                                 if ($$==0) {
650                                         LM_CRIT("cfg. parser: out of memory.\n");
651                                 } else {
652                                         strncpy($$, tmp, strlen(tmp)+1);
653                                 }
654                         }
655                 }
656         }
657         | STRING {
658                 $$=pkg_malloc(strlen($1)+1);
659                 if ($$==0) {
660                                 LM_CRIT("cfg. parser: out of memory.\n");
661                 } else {
662                                 strncpy($$, $1, strlen($1)+1);
663                 }
664         }
665         | host_or_if {
666                 if ($1){
667                         $$=pkg_malloc(strlen($1)+1);
668                         if ($$==0) {
669                                         LM_CRIT("cfg. parser: out of memory.\n");
670                         } else {
671                                         strncpy($$, $1, strlen($1)+1);
672                         }
673                 }
674         }
675         ;
676
677
678 listen_id_lst:
679         listen_id       { $$=mk_name_lst($1, SI_IS_MHOMED); }
680         | listen_id COMMA listen_id_lst { $$=mk_name_lst($1, SI_IS_MHOMED);
681                                                                                 if ($$) $$->next=$3;
682                                                                         }
683         ;
684
685 listen_id2:
686         LPAREN listen_id_lst RPAREN { $$=$2; }
687         | listen_id     { $$=mk_name_lst($1, 0); }
688         ;
689
690 proto:
691         UDP     { $$=PROTO_UDP; }
692         | TCP   { $$=PROTO_TCP; }
693         | TLS   { $$=PROTO_TLS; }
694         | SCTP  { $$=PROTO_SCTP; }
695         | STAR  { $$=0; }
696         ;
697 eqproto:
698         UDP     { $$=PROTO_UDP; }
699         | TCP   { $$=PROTO_TCP; }
700         | TLS   { $$=PROTO_TLS; }
701         | SCTP  { $$=PROTO_SCTP; }
702         | WS    { $$=PROTO_WS; }
703         | WSS   { $$=PROTO_WSS; }
704         | STAR  { $$=0; }
705         ;
706 port:
707         NUMBER  { $$=$1; }
708         | STAR  { $$=0; }
709 ;
710 phostport:
711         listen_id               { $$=mk_listen_id($1, 0, 0); }
712         | listen_id COLON port  { $$=mk_listen_id($1, 0, $3); }
713         | proto COLON listen_id { $$=mk_listen_id($3, $1, 0); }
714         | proto COLON listen_id COLON port      { $$=mk_listen_id($3, $1, $5);}
715         | listen_id COLON error { $$=0; yyerror("port number expected"); }
716         ;
717
718 listen_phostport:
719         listen_id2              { $$=mk_listen_id2($1, 0, 0); }
720         | listen_id2 COLON port { $$=mk_listen_id2($1, 0, $3); }
721         | proto COLON listen_id2        { $$=mk_listen_id2($3, $1, 0); }
722         | proto COLON listen_id2 COLON port     { $$=mk_listen_id2($3, $1, $5);}
723         | listen_id2 COLON error { $$=0; yyerror("port number expected"); }
724         ;
725
726 id_lst:
727         listen_phostport                {  $$=$1 ; }
728         | listen_phostport id_lst       { $$=$1;  if ($$) $$->next=$2; }
729         ;
730
731 intno: NUMBER
732         |  MINUS NUMBER %prec UNARY { $$=-$2; }
733         ;
734
735 flags_decl:             FLAGS_DECL      flag_list
736                         |       FLAGS_DECL error { yyerror("flag list expected\n"); }
737 ;
738 flag_list:              flag_spec
739                         |       flag_spec COMMA flag_list
740 ;
741
742 flag_spec:              flag_name       { if (register_flag($1,-1)<0)
743                                                                 yyerror("register flag failed");
744                                                 }
745                         |       flag_name COLON NUMBER {
746                                                 if (register_flag($1, $3)<0)
747                                                                 yyerror("register flag failed");
748                                                                                 }
749 ;
750
751 flag_name:              STRING  { $$=$1; }
752                         |       ID              { $$=$1; }
753 ;
754
755 avpflags_decl:
756         AVPFLAGS_DECL avpflag_list
757         | AVPFLAGS_DECL error { yyerror("avpflag list expected\n"); }
758         ;
759 avpflag_list:
760         avpflag_spec
761         | avpflag_spec COMMA avpflag_list
762         ;
763 avpflag_spec:
764         flag_name {
765                 if (register_avpflag($1)==0)
766                         yyerror("cannot declare avpflag");
767         }
768         ;
769 assign_stm:
770         DEBUG_V EQUAL intno { default_core_cfg.debug=$3; }
771         | DEBUG_V EQUAL error  { yyerror("number  expected"); }
772         | FORK  EQUAL NUMBER { dont_fork= ! $3; }
773         | FORK  EQUAL error  { yyerror("boolean value expected"); }
774         | FORK_DELAY  EQUAL NUMBER { set_fork_delay($3); }
775         | FORK_DELAY  EQUAL error  { yyerror("number expected"); }
776         | MODINIT_DELAY  EQUAL NUMBER { set_modinit_delay($3); }
777         | MODINIT_DELAY  EQUAL error  { yyerror("number expected"); }
778         | LOGSTDERROR EQUAL NUMBER { if (!config_check)  /* if set from cmd line, don't overwrite from yyparse()*/
779                                         if(log_stderr == 0) log_stderr=$3;
780                                    }
781         | LOGSTDERROR EQUAL error { yyerror("boolean value expected"); }
782         | LOGFACILITY EQUAL ID {
783                 if ( (i_tmp=str2facility($3))==-1)
784                         yyerror("bad facility (see syslog(3) man page)");
785                 if (!config_check)
786                         default_core_cfg.log_facility=i_tmp;
787         }
788         | LOGFACILITY EQUAL error { yyerror("ID expected"); }
789         | LOGNAME EQUAL STRING { log_name=$3; }
790         | LOGNAME EQUAL error { yyerror("string value expected"); }
791         | LOGCOLOR EQUAL NUMBER { log_color=$3; }
792         | LOGCOLOR EQUAL error { yyerror("boolean value expected"); }
793         | LOGPREFIX EQUAL STRING { log_prefix_fmt=$3; }
794         | LOGPREFIX EQUAL error { yyerror("string value expected"); }
795         | LOGPREFIXMODE EQUAL NUMBER { log_prefix_mode=$3; }
796         | LOGPREFIXMODE EQUAL error { yyerror("number expected"); }
797         | LOGENGINETYPE EQUAL STRING { _km_log_engine_type=$3; }
798         | LOGENGINETYPE EQUAL error { yyerror("string value expected"); }
799         | LOGENGINEDATA EQUAL STRING { _km_log_engine_data=$3; }
800         | LOGENGINEDATA EQUAL error { yyerror("string value expected"); }
801         | XAVPVIAPARAMS EQUAL STRING { _ksr_xavp_via_params.s=$3;
802                         _ksr_xavp_via_params.len=strlen($3);
803                 }
804         | XAVPVIAPARAMS EQUAL error { yyerror("string value expected"); }
805         | DNS EQUAL NUMBER   { received_dns|= ($3)?DO_DNS:0; }
806         | DNS EQUAL error { yyerror("boolean value expected"); }
807         | REV_DNS EQUAL NUMBER { received_dns|= ($3)?DO_REV_DNS:0; }
808         | REV_DNS EQUAL error { yyerror("boolean value expected"); }
809         | DNS_TRY_IPV6 EQUAL NUMBER   { default_core_cfg.dns_try_ipv6=$3; }
810         | DNS_TRY_IPV6 error { yyerror("boolean value expected"); }
811         | DNS_TRY_NAPTR EQUAL NUMBER   { IF_NAPTR(default_core_cfg.dns_try_naptr=$3); }
812         | DNS_TRY_NAPTR error { yyerror("boolean value expected"); }
813         | DNS_SRV_LB EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.dns_srv_lb=$3); }
814         | DNS_SRV_LB error { yyerror("boolean value expected"); }
815         | DNS_UDP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_udp_pref=$3);}
816         | DNS_UDP_PREF error { yyerror("number expected"); }
817         | DNS_TCP_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tcp_pref=$3);}
818         | DNS_TCP_PREF error { yyerror("number expected"); }
819         | DNS_TLS_PREF EQUAL intno { IF_NAPTR(default_core_cfg.dns_tls_pref=$3);}
820         | DNS_TLS_PREF error { yyerror("number expected"); }
821         | DNS_SCTP_PREF EQUAL intno {
822                                                                 IF_NAPTR(default_core_cfg.dns_sctp_pref=$3); }
823         | DNS_SCTP_PREF error { yyerror("number expected"); }
824         | DNS_RETR_TIME EQUAL NUMBER   { default_core_cfg.dns_retr_time=$3; }
825         | DNS_RETR_TIME error { yyerror("number expected"); }
826         | DNS_RETR_NO EQUAL NUMBER   { default_core_cfg.dns_retr_no=$3; }
827         | DNS_RETR_NO error { yyerror("number expected"); }
828         | DNS_SERVERS_NO EQUAL NUMBER   { default_core_cfg.dns_servers_no=$3; }
829         | DNS_SERVERS_NO error { yyerror("number expected"); }
830         | DNS_USE_SEARCH EQUAL NUMBER   { default_core_cfg.dns_search_list=$3; }
831         | DNS_USE_SEARCH error { yyerror("boolean value expected"); }
832         | DNS_SEARCH_FMATCH EQUAL NUMBER   { default_core_cfg.dns_search_fmatch=$3; }
833         | DNS_SEARCH_FMATCH error { yyerror("boolean value expected"); }
834         | DNS_NAPTR_IGNORE_RFC EQUAL NUMBER   { default_core_cfg.dns_naptr_ignore_rfc=$3; }
835         | DNS_NAPTR_IGNORE_RFC error { yyerror("boolean value expected"); }
836         | DNS_CACHE_INIT EQUAL NUMBER   { IF_DNS_CACHE(dns_cache_init=$3); }
837         | DNS_CACHE_INIT error { yyerror("boolean value expected"); }
838         | DNS_USE_CACHE EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.use_dns_cache=$3); }
839         | DNS_USE_CACHE error { yyerror("boolean value expected"); }
840         | DNS_USE_FAILOVER EQUAL NUMBER   { IF_DNS_FAILOVER(default_core_cfg.use_dns_failover=$3);}
841         | DNS_USE_FAILOVER error { yyerror("boolean value expected"); }
842         | DNS_CACHE_FLAGS EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_flags=$3); }
843         | DNS_CACHE_FLAGS error { yyerror("boolean value expected"); }
844         | DNS_CACHE_NEG_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_neg_cache_ttl=$3); }
845         | DNS_CACHE_NEG_TTL error { yyerror("boolean value expected"); }
846         | DNS_CACHE_MAX_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_ttl=$3); }
847         | DNS_CACHE_MAX_TTL error { yyerror("boolean value expected"); }
848         | DNS_CACHE_MIN_TTL EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_min_ttl=$3); }
849         | DNS_CACHE_MIN_TTL error { yyerror("boolean value expected"); }
850         | DNS_CACHE_MEM EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_max_mem=$3); }
851         | DNS_CACHE_MEM error { yyerror("boolean value expected"); }
852         | DNS_CACHE_GC_INT EQUAL NUMBER   { IF_DNS_CACHE(dns_timer_interval=$3); }
853         | DNS_CACHE_GC_INT error { yyerror("boolean value expected"); }
854         | DNS_CACHE_DEL_NONEXP EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_del_nonexp=$3); }
855         | DNS_CACHE_DEL_NONEXP error { yyerror("boolean value expected"); }
856         | DNS_CACHE_REC_PREF EQUAL NUMBER   { IF_DNS_CACHE(default_core_cfg.dns_cache_rec_pref=$3); }
857         | DNS_CACHE_REC_PREF error { yyerror("boolean value expected"); }
858         | AUTO_BIND_IPV6 EQUAL NUMBER {IF_AUTO_BIND_IPV6(auto_bind_ipv6 = $3);}
859         | AUTO_BIND_IPV6 error { yyerror("boolean value expected"); }
860         | DST_BLST_INIT EQUAL NUMBER   { IF_DST_BLACKLIST(dst_blacklist_init=$3); }
861         | DST_BLST_INIT error { yyerror("boolean value expected"); }
862         | USE_DST_BLST EQUAL NUMBER {
863                 IF_DST_BLACKLIST(default_core_cfg.use_dst_blacklist=$3);
864         }
865         | USE_DST_BLST error { yyerror("boolean value expected"); }
866         | DST_BLST_MEM EQUAL NUMBER {
867                 IF_DST_BLACKLIST(default_core_cfg.blst_max_mem=$3);
868         }
869         | DST_BLST_MEM error { yyerror("boolean value expected"); }
870         | DST_BLST_TTL EQUAL NUMBER {
871                 IF_DST_BLACKLIST(default_core_cfg.blst_timeout=$3);
872         }
873         | DST_BLST_TTL error { yyerror("boolean value expected"); }
874         | DST_BLST_GC_INT EQUAL NUMBER { IF_DST_BLACKLIST(blst_timer_interval=$3);}
875         | DST_BLST_GC_INT error { yyerror("boolean value expected"); }
876         | DST_BLST_UDP_IMASK EQUAL NUMBER {
877                 IF_DST_BLACKLIST(default_core_cfg.blst_udp_imask=$3);
878         }
879         | DST_BLST_UDP_IMASK error { yyerror("number(flags) expected"); }
880         | DST_BLST_TCP_IMASK EQUAL NUMBER {
881                 IF_DST_BLACKLIST(default_core_cfg.blst_tcp_imask=$3);
882         }
883         | DST_BLST_TCP_IMASK error { yyerror("number(flags) expected"); }
884         | DST_BLST_TLS_IMASK EQUAL NUMBER {
885                 IF_DST_BLACKLIST(default_core_cfg.blst_tls_imask=$3);
886         }
887         | DST_BLST_TLS_IMASK error { yyerror("number(flags) expected"); }
888         | DST_BLST_SCTP_IMASK EQUAL NUMBER {
889                 IF_DST_BLACKLIST(default_core_cfg.blst_sctp_imask=$3);
890         }
891         | DST_BLST_SCTP_IMASK error { yyerror("number(flags) expected"); }
892         | IP_FREE_BIND EQUAL intno { _sr_ip_free_bind=$3; }
893         | IP_FREE_BIND EQUAL error { yyerror("int value expected"); }
894         | PORT EQUAL NUMBER   { port_no=$3; }
895         | STAT EQUAL STRING {
896                 #ifdef STATS
897                                 stat_file=$3;
898                 #endif
899         }
900         | MAXBUFFER EQUAL NUMBER { maxbuffer=$3; }
901         | MAXBUFFER EQUAL error { yyerror("number expected"); }
902     | SQL_BUFFER_SIZE EQUAL NUMBER { sql_buffer_size=$3; }
903         | SQL_BUFFER_SIZE EQUAL error { yyerror("number expected"); }
904         | PORT EQUAL error    { yyerror("number expected"); }
905         | CHILDREN EQUAL NUMBER { children_no=$3; }
906         | CHILDREN EQUAL error { yyerror("number expected"); }
907         | SOCKET_WORKERS EQUAL NUMBER { socket_workers=$3; }
908         | SOCKET_WORKERS EQUAL error { yyerror("number expected"); }
909         | ASYNC_WORKERS EQUAL NUMBER { async_task_set_workers($3); }
910         | ASYNC_WORKERS EQUAL error { yyerror("number expected"); }
911         | ASYNC_USLEEP EQUAL NUMBER { async_task_set_usleep($3); }
912         | ASYNC_USLEEP EQUAL error { yyerror("number expected"); }
913         | CHECK_VIA EQUAL NUMBER { check_via=$3; }
914         | CHECK_VIA EQUAL error { yyerror("boolean value expected"); }
915         | PHONE2TEL EQUAL NUMBER { phone2tel=$3; }
916         | PHONE2TEL EQUAL error { yyerror("boolean value expected"); }
917         | MEMLOG EQUAL intno { default_core_cfg.memlog=$3; }
918         | MEMLOG EQUAL error { yyerror("int value expected"); }
919         | MEMDBG EQUAL intno { default_core_cfg.memdbg=$3; }
920         | MEMDBG EQUAL error { yyerror("int value expected"); }
921         | MEMSUM EQUAL intno { default_core_cfg.mem_summary=$3; }
922         | MEMSUM EQUAL error { yyerror("int value expected"); }
923         | MEMSAFETY EQUAL intno { default_core_cfg.mem_safety=$3; }
924         | MEMSAFETY EQUAL error { yyerror("int value expected"); }
925         | MEMJOIN EQUAL intno { default_core_cfg.mem_join=$3; }
926         | MEMJOIN EQUAL error { yyerror("int value expected"); }
927         | MEMSTATUSMODE EQUAL intno { default_core_cfg.mem_status_mode=$3; }
928         | MEMSTATUSMODE EQUAL error { yyerror("int value expected"); }
929         | CORELOG EQUAL intno { default_core_cfg.corelog=$3; }
930         | CORELOG EQUAL error { yyerror("int value expected"); }
931         | SIP_WARNING EQUAL NUMBER { sip_warning=$3; }
932         | SIP_WARNING EQUAL error { yyerror("boolean value expected"); }
933         | VERSION_TABLE_CFG EQUAL STRING { version_table.s=$3;
934                         version_table.len=strlen(version_table.s);
935         }
936         | VERSION_TABLE_CFG EQUAL error { yyerror("string value expected"); }
937         | USER EQUAL STRING     {
938                 if (shm_initialized())
939                         yyerror("user must be before any modparam or the"
940                                         " route blocks");
941                 else if (user==0)
942                         user=$3;
943         }
944         | USER EQUAL ID         {
945                 if (shm_initialized())
946                         yyerror("user must be before any modparam or the"
947                                         " route blocks");
948                 else if (user==0)
949                         user=$3;
950         }
951         | USER EQUAL error      { yyerror("string value expected"); }
952         | GROUP EQUAL STRING     { group=$3; }
953         | GROUP EQUAL ID         { group=$3; }
954         | GROUP EQUAL error      { yyerror("string value expected"); }
955         | CHROOT EQUAL STRING     { chroot_dir=$3; }
956         | CHROOT EQUAL ID         { chroot_dir=$3; }
957         | CHROOT EQUAL error      { yyerror("string value expected"); }
958         | WDIR EQUAL STRING     { working_dir=$3; }
959         | WDIR EQUAL ID         { working_dir=$3; }
960         | WDIR EQUAL error      { yyerror("string value expected"); }
961         | RUNDIR EQUAL STRING     { runtime_dir=$3; }
962         | RUNDIR EQUAL ID         { runtime_dir=$3; }
963         | RUNDIR EQUAL error      { yyerror("string value expected"); }
964         | MHOMED EQUAL NUMBER { mhomed=$3; }
965         | MHOMED EQUAL error { yyerror("boolean value expected"); }
966         | DISABLE_TCP EQUAL NUMBER {
967                 #ifdef USE_TCP
968                         tcp_disable=$3;
969                 #else
970                         warn("tcp support not compiled in");
971                 #endif
972         }
973         | DISABLE_TCP EQUAL error { yyerror("boolean value expected"); }
974         | TCP_ACCEPT_ALIASES EQUAL NUMBER {
975                 #ifdef USE_TCP
976                         tcp_default_cfg.accept_aliases=$3;
977                 #else
978                         warn("tcp support not compiled in");
979                 #endif
980         }
981         | TCP_ACCEPT_ALIASES EQUAL error { yyerror("boolean value expected"); }
982         | TCP_CHILDREN EQUAL NUMBER {
983                 #ifdef USE_TCP
984                         tcp_cfg_children_no=$3;
985                 #else
986                         warn("tcp support not compiled in");
987                 #endif
988         }
989         | TCP_CHILDREN EQUAL error { yyerror("number expected"); }
990         | TCP_CONNECT_TIMEOUT EQUAL intno {
991                 #ifdef USE_TCP
992                         tcp_default_cfg.connect_timeout_s=$3;
993                 #else
994                         warn("tcp support not compiled in");
995                 #endif
996         }
997         | TCP_CONNECT_TIMEOUT EQUAL error { yyerror("number expected"); }
998         | TCP_SEND_TIMEOUT EQUAL intno {
999                 #ifdef USE_TCP
1000                         tcp_default_cfg.send_timeout=S_TO_TICKS($3);
1001                 #else
1002                         warn("tcp support not compiled in");
1003                 #endif
1004         }
1005         | TCP_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
1006         | TCP_CON_LIFETIME EQUAL intno {
1007                 #ifdef USE_TCP
1008                         if ($3<0)
1009                                 tcp_default_cfg.con_lifetime=-1;
1010                         else
1011                                 tcp_default_cfg.con_lifetime=S_TO_TICKS($3);
1012                 #else
1013                         warn("tcp support not compiled in");
1014                 #endif
1015         }
1016         | TCP_CON_LIFETIME EQUAL error { yyerror("number expected"); }
1017         | TCP_POLL_METHOD EQUAL ID {
1018                 #ifdef USE_TCP
1019                         tcp_poll_method=get_poll_type($3);
1020                         if (tcp_poll_method==POLL_NONE) {
1021                                 LOG(L_CRIT, "bad poll method name:"
1022                                                 " %s\n, try one of %s.\n",
1023                                                 $3, poll_support);
1024                                 yyerror("bad tcp_poll_method "
1025                                                 "value");
1026                         }
1027                 #else
1028                         warn("tcp support not compiled in");
1029                 #endif
1030         }
1031         | TCP_POLL_METHOD EQUAL STRING {
1032                 #ifdef USE_TCP
1033                         tcp_poll_method=get_poll_type($3);
1034                         if (tcp_poll_method==POLL_NONE) {
1035                                 LOG(L_CRIT, "bad poll method name:"
1036                                                 " %s\n, try one of %s.\n",
1037                                                 $3, poll_support);
1038                                 yyerror("bad tcp_poll_method "
1039                                                 "value");
1040                         }
1041                 #else
1042                         warn("tcp support not compiled in");
1043                 #endif
1044         }
1045         | TCP_POLL_METHOD EQUAL error { yyerror("poll method name expected"); }
1046         | TCP_MAX_CONNECTIONS EQUAL NUMBER {
1047                 #ifdef USE_TCP
1048                         tcp_max_connections=$3;
1049                 #else
1050                         warn("tcp support not compiled in");
1051                 #endif
1052         }
1053         | TCP_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
1054         | TLS_MAX_CONNECTIONS EQUAL NUMBER {
1055                 #ifdef USE_TLS
1056                         tls_max_connections=$3;
1057                 #else
1058                         warn("tls support not compiled in");
1059                 #endif
1060         }
1061         | TLS_MAX_CONNECTIONS EQUAL error { yyerror("number expected"); }
1062         | TCP_NO_CONNECT EQUAL NUMBER {
1063                 #ifdef USE_TCP
1064                         tcp_default_cfg.no_connect=$3;
1065                 #else
1066                         warn("tcp support not compiled in");
1067                 #endif
1068         }
1069         | TCP_NO_CONNECT EQUAL error { yyerror("boolean value expected"); }
1070         | TCP_SOURCE_IPV4 EQUAL ipv4 {
1071                 #ifdef USE_TCP
1072                         if (tcp_set_src_addr($3)<0)
1073                                 warn("tcp_source_ipv4 failed");
1074                 #else
1075                         warn("tcp support not compiled in");
1076                 #endif
1077                 pkg_free($3);
1078         }
1079         | TCP_SOURCE_IPV4 EQUAL error { yyerror("IPv4 address expected"); }
1080         | TCP_SOURCE_IPV6 EQUAL ipv6 {
1081                 #ifdef USE_TCP
1082                                 if (tcp_set_src_addr($3)<0)
1083                                         warn("tcp_source_ipv6 failed");
1084                 #else
1085                         warn("tcp support not compiled in");
1086                 #endif
1087                 pkg_free($3);
1088         }
1089         | TCP_SOURCE_IPV6 EQUAL error { yyerror("IPv6 address expected"); }
1090         | TCP_OPT_FD_CACHE EQUAL NUMBER {
1091                 #ifdef USE_TCP
1092                         tcp_default_cfg.fd_cache=$3;
1093                 #else
1094                         warn("tcp support not compiled in");
1095                 #endif
1096         }
1097         | TCP_OPT_FD_CACHE EQUAL error { yyerror("boolean value expected"); }
1098         | TCP_OPT_BUF_WRITE EQUAL NUMBER {
1099                 #ifdef USE_TCP
1100                         tcp_default_cfg.async=$3;
1101                 #else
1102                         warn("tcp support not compiled in");
1103                 #endif
1104         }
1105         | TCP_OPT_BUF_WRITE EQUAL error { yyerror("boolean value expected"); }
1106         | TCP_OPT_CONN_WQ_MAX EQUAL NUMBER {
1107                 #ifdef USE_TCP
1108                         tcp_default_cfg.tcpconn_wq_max=$3;
1109                 #else
1110                         warn("tcp support not compiled in");
1111                 #endif
1112         }
1113         | TCP_OPT_CONN_WQ_MAX error { yyerror("boolean value expected"); }
1114         | TCP_OPT_WQ_MAX EQUAL NUMBER {
1115                 #ifdef USE_TCP
1116                         tcp_default_cfg.tcp_wq_max=$3;
1117                 #else
1118                         warn("tcp support not compiled in");
1119                 #endif
1120         }
1121         | TCP_OPT_WQ_MAX error { yyerror("number expected"); }
1122         | TCP_OPT_RD_BUF EQUAL NUMBER {
1123                 #ifdef USE_TCP
1124                         tcp_default_cfg.rd_buf_size=$3;
1125                 #else
1126                         warn("tcp support not compiled in");
1127                 #endif
1128         }
1129         | TCP_OPT_RD_BUF error { yyerror("number expected"); }
1130         | TCP_OPT_WQ_BLK EQUAL NUMBER {
1131                 #ifdef USE_TCP
1132                         tcp_default_cfg.wq_blk_size=$3;
1133                 #else
1134                         warn("tcp support not compiled in");
1135                 #endif
1136         }
1137         | TCP_OPT_WQ_BLK error { yyerror("number expected"); }
1138         | TCP_OPT_DEFER_ACCEPT EQUAL NUMBER {
1139                 #ifdef USE_TCP
1140                         tcp_default_cfg.defer_accept=$3;
1141                 #else
1142                         warn("tcp support not compiled in");
1143                 #endif
1144         }
1145         | TCP_OPT_DEFER_ACCEPT EQUAL error { yyerror("boolean value expected"); }
1146         | TCP_OPT_DELAYED_ACK EQUAL NUMBER {
1147                 #ifdef USE_TCP
1148                         tcp_default_cfg.delayed_ack=$3;
1149                 #else
1150                         warn("tcp support not compiled in");
1151                 #endif
1152         }
1153         | TCP_OPT_DELAYED_ACK EQUAL error { yyerror("boolean value expected"); }
1154         | TCP_OPT_SYNCNT EQUAL NUMBER {
1155                 #ifdef USE_TCP
1156                         tcp_default_cfg.syncnt=$3;
1157                 #else
1158                         warn("tcp support not compiled in");
1159                 #endif
1160         }
1161         | TCP_OPT_SYNCNT EQUAL error { yyerror("number expected"); }
1162         | TCP_OPT_LINGER2 EQUAL NUMBER {
1163                 #ifdef USE_TCP
1164                         tcp_default_cfg.linger2=$3;
1165                 #else
1166                         warn("tcp support not compiled in");
1167                 #endif
1168         }
1169         | TCP_OPT_LINGER2 EQUAL error { yyerror("number expected"); }
1170         | TCP_OPT_KEEPALIVE EQUAL NUMBER {
1171                 #ifdef USE_TCP
1172                         tcp_default_cfg.keepalive=$3;
1173                 #else
1174                         warn("tcp support not compiled in");
1175                 #endif
1176         }
1177         | TCP_OPT_KEEPALIVE EQUAL error { yyerror("boolean value expected");}
1178         | TCP_OPT_KEEPIDLE EQUAL NUMBER {
1179                 #ifdef USE_TCP
1180                         tcp_default_cfg.keepidle=$3;
1181                 #else
1182                         warn("tcp support not compiled in");
1183                 #endif
1184         }
1185         | TCP_OPT_KEEPIDLE EQUAL error { yyerror("number expected"); }
1186         | TCP_OPT_KEEPINTVL EQUAL NUMBER {
1187                 #ifdef USE_TCP
1188                         tcp_default_cfg.keepintvl=$3;
1189                 #else
1190                         warn("tcp support not compiled in");
1191                 #endif
1192         }
1193         | TCP_OPT_KEEPINTVL EQUAL error { yyerror("number expected"); }
1194         | TCP_OPT_KEEPCNT EQUAL NUMBER {
1195                 #ifdef USE_TCP
1196                         tcp_default_cfg.keepcnt=$3;
1197                 #else
1198                         warn("tcp support not compiled in");
1199                 #endif
1200         }
1201         | TCP_OPT_KEEPCNT EQUAL error { yyerror("number expected"); }
1202         | TCP_OPT_CRLF_PING EQUAL NUMBER {
1203                 #ifdef USE_TCP
1204                         tcp_default_cfg.crlf_ping=$3;
1205                 #else
1206                         warn("tcp support not compiled in");
1207                 #endif
1208         }
1209         | TCP_OPT_CRLF_PING EQUAL error { yyerror("boolean value expected"); }
1210         | TCP_OPT_ACCEPT_NO_CL EQUAL NUMBER {
1211                 #ifdef USE_TCP
1212                         tcp_default_cfg.accept_no_cl=$3;
1213                 #else
1214                         warn("tcp support not compiled in");
1215                 #endif
1216         }
1217         | TCP_OPT_ACCEPT_NO_CL EQUAL error { yyerror("boolean value expected"); }
1218         | TCP_OPT_ACCEPT_HEP3 EQUAL NUMBER {
1219                 #ifdef USE_TCP
1220                         ksr_tcp_accept_hep3=$3;
1221                 #else
1222                         warn("tcp support not compiled in");
1223                 #endif
1224         }
1225         | TCP_OPT_ACCEPT_HEP3 EQUAL error { yyerror("boolean value expected"); }
1226
1227         | TCP_CLONE_RCVBUF EQUAL NUMBER {
1228                 #ifdef USE_TCP
1229                         tcp_set_clone_rcvbuf($3);
1230                 #else
1231                         warn("tcp support not compiled in");
1232                 #endif
1233         }
1234         | TCP_CLONE_RCVBUF EQUAL error { yyerror("number expected"); }
1235         | TCP_REUSE_PORT EQUAL NUMBER {
1236                 #ifdef USE_TCP
1237                 #ifdef SO_REUSEPORT
1238                         tcp_default_cfg.reuse_port=$3;
1239                 #else
1240                         warn("support for SO_REUSEPORT not compiled in");
1241                 #endif
1242                 #else
1243                         warn("tcp support not compiled in");
1244                 #endif
1245         }
1246         | TCP_REUSE_PORT EQUAL error { yyerror("boolean value expected"); }
1247         | DISABLE_TLS EQUAL NUMBER {
1248                 #ifdef USE_TLS
1249                         tls_disable=$3;
1250                 #else
1251                         warn("tls support not compiled in");
1252                 #endif
1253         }
1254         | DISABLE_TLS EQUAL error { yyerror("boolean value expected"); }
1255         | ENABLE_TLS EQUAL NUMBER {
1256                 #ifdef USE_TLS
1257                         tls_disable=!($3);
1258                 #else
1259                         warn("tls support not compiled in");
1260                 #endif
1261         }
1262         | ENABLE_TLS EQUAL error { yyerror("boolean value expected"); }
1263         | TLSLOG EQUAL NUMBER {
1264                 #ifdef CORE_TLS
1265                         tls_log=$3;
1266                 #else
1267                         warn("tls-in-core support not compiled in");
1268                 #endif
1269         }
1270         | TLSLOG EQUAL error { yyerror("int value expected"); }
1271         | TLS_PORT_NO EQUAL NUMBER {
1272                 #ifdef USE_TLS
1273                         tls_port_no=$3;
1274                 #else
1275                         warn("tls support not compiled in");
1276                 #endif
1277         }
1278         | TLS_PORT_NO EQUAL error { yyerror("number expected"); }
1279         | TLS_METHOD EQUAL SSLv23 {
1280                 #ifdef CORE_TLS
1281                         tls_method=TLS_USE_SSLv23;
1282                 #else
1283                         warn("tls-in-core support not compiled in");
1284                 #endif
1285         }
1286         | TLS_METHOD EQUAL SSLv2 {
1287                 #ifdef CORE_TLS
1288                         tls_method=TLS_USE_SSLv2;
1289                 #else
1290                         warn("tls-in-core support not compiled in");
1291                 #endif
1292         }
1293         | TLS_METHOD EQUAL SSLv3 {
1294                 #ifdef CORE_TLS
1295                         tls_method=TLS_USE_SSLv3;
1296                 #else
1297                         warn("tls-in-core support not compiled in");
1298                 #endif
1299         }
1300         | TLS_METHOD EQUAL TLSv1 {
1301                 #ifdef CORE_TLS
1302                         tls_method=TLS_USE_TLSv1;
1303                 #else
1304                         warn("tls-in-core support not compiled in");
1305                 #endif
1306         }
1307         | TLS_METHOD EQUAL error {
1308                 #ifdef CORE_TLS
1309                         yyerror("SSLv23, SSLv2, SSLv3 or TLSv1 expected");
1310                 #else
1311                         warn("tls-in-core support not compiled in");
1312                 #endif
1313         }
1314         | TLS_VERIFY EQUAL NUMBER {
1315                 #ifdef CORE_TLS
1316                         tls_verify_cert=$3;
1317                 #else
1318                         warn("tls-in-core support not compiled in");
1319                 #endif
1320         }
1321         | TLS_VERIFY EQUAL error { yyerror("boolean value expected"); }
1322         | TLS_REQUIRE_CERTIFICATE EQUAL NUMBER {
1323                 #ifdef CORE_TLS
1324                         tls_require_cert=$3;
1325                 #else
1326                         warn( "tls-in-core support not compiled in");
1327                 #endif
1328         }
1329         | TLS_REQUIRE_CERTIFICATE EQUAL error { yyerror("boolean value expected"); }
1330         | TLS_CERTIFICATE EQUAL STRING {
1331                 #ifdef CORE_TLS
1332                         tls_cert_file=$3;
1333                 #else
1334                         warn("tls-in-core support not compiled in");
1335                 #endif
1336         }
1337         | TLS_CERTIFICATE EQUAL error { yyerror("string value expected"); }
1338         | TLS_PRIVATE_KEY EQUAL STRING {
1339                 #ifdef CORE_TLS
1340                         tls_pkey_file=$3;
1341                 #else
1342                         warn("tls-in-core support not compiled in");
1343                 #endif
1344         }
1345         | TLS_PRIVATE_KEY EQUAL error { yyerror("string value expected"); }
1346         | TLS_CA_LIST EQUAL STRING {
1347                 #ifdef CORE_TLS
1348                         tls_ca_file=$3;
1349                 #else
1350                         warn("tls-in-core support not compiled in");
1351                 #endif
1352         }
1353         | TLS_CA_LIST EQUAL error { yyerror("string value expected"); }
1354         | TLS_HANDSHAKE_TIMEOUT EQUAL NUMBER {
1355                 #ifdef CORE_TLS
1356                         tls_handshake_timeout=$3;
1357                 #else
1358                         warn("tls-in-core support not compiled in");
1359                 #endif
1360         }
1361         | TLS_HANDSHAKE_TIMEOUT EQUAL error { yyerror("number expected"); }
1362         | TLS_SEND_TIMEOUT EQUAL NUMBER {
1363                 #ifdef CORE_TLS
1364                         tls_send_timeout=$3;
1365                 #else
1366                         warn("tls-in-core support not compiled in");
1367                 #endif
1368         }
1369         | TLS_SEND_TIMEOUT EQUAL error { yyerror("number expected"); }
1370         | DISABLE_SCTP EQUAL NUMBER {
1371                 #ifdef USE_SCTP
1372                         sctp_disable=$3;
1373                 #else
1374                         warn("sctp support not compiled in");
1375                 #endif
1376         }
1377         | DISABLE_SCTP EQUAL error { yyerror("boolean value expected"); }
1378         | ENABLE_SCTP EQUAL NUMBER {
1379                 #ifdef USE_SCTP
1380                         sctp_disable=($3<=1)?!$3:$3;
1381                 #else
1382                         warn("sctp support not compiled in");
1383                 #endif
1384         }
1385         | ENABLE_SCTP EQUAL error { yyerror("boolean or number expected"); }
1386         | SCTP_CHILDREN EQUAL NUMBER {
1387                 #ifdef USE_SCTP
1388                         sctp_children_no=$3;
1389                 #else
1390                         warn("sctp support not compiled in");
1391                 #endif
1392         }
1393         | SCTP_CHILDREN EQUAL error { yyerror("number expected"); }
1394         | SERVER_SIGNATURE EQUAL NUMBER { server_signature=$3; }
1395         | SERVER_SIGNATURE EQUAL error { yyerror("boolean value expected"); }
1396         | SERVER_HEADER EQUAL STRING { server_hdr.s=$3;
1397                         server_hdr.len=strlen(server_hdr.s);
1398         }
1399         | SERVER_HEADER EQUAL error { yyerror("string value expected"); }
1400         | USER_AGENT_HEADER EQUAL STRING { user_agent_hdr.s=$3;
1401                         user_agent_hdr.len=strlen(user_agent_hdr.s);
1402         }
1403         | USER_AGENT_HEADER EQUAL error { yyerror("string value expected"); }
1404         | REPLY_TO_VIA EQUAL NUMBER { reply_to_via=$3; }
1405         | REPLY_TO_VIA EQUAL error { yyerror("boolean value expected"); }
1406         | LISTEN EQUAL id_lst {
1407                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1408                         if (add_listen_iface(   lst_tmp->addr_lst->name,
1409                                                                         lst_tmp->addr_lst->next,
1410                                                                         lst_tmp->port, lst_tmp->proto,
1411                                                                         lst_tmp->flags)!=0) {
1412                                 LM_CRIT("cfg. parser: failed to add listen address\n");
1413                                 break;
1414                         }
1415                 }
1416                 free_socket_id_lst($3);
1417         }
1418         | LISTEN EQUAL id_lst ADVERTISE listen_id COLON NUMBER {
1419                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next) {
1420                         if (add_listen_advertise_iface( lst_tmp->addr_lst->name,
1421                                                                         lst_tmp->addr_lst->next,
1422                                                                         lst_tmp->port, lst_tmp->proto,
1423                                                                         $5, $7,
1424                                                                         lst_tmp->flags)!=0) {
1425                                 LM_CRIT("cfg. parser: failed to add listen address\n");
1426                                 break;
1427                         }
1428                 }
1429                 free_socket_id_lst($3);
1430         }
1431         | LISTEN EQUAL  error { yyerror("ip address, interface name or"
1432                                                                         " hostname expected"); }
1433         | ALIAS EQUAL  id_lst {
1434                 for(lst_tmp=$3; lst_tmp; lst_tmp=lst_tmp->next){
1435                         add_alias(      lst_tmp->addr_lst->name,
1436                                                 strlen(lst_tmp->addr_lst->name),
1437                                                 lst_tmp->port, lst_tmp->proto);
1438                         for (nl_tmp=lst_tmp->addr_lst->next; nl_tmp; nl_tmp=nl_tmp->next)
1439                                 add_alias(nl_tmp->name, strlen(nl_tmp->name),
1440                                                         lst_tmp->port, lst_tmp->proto);
1441                 }
1442                 free_socket_id_lst($3);
1443         }
1444         | ALIAS  EQUAL error  { yyerror("hostname expected"); }
1445         | SR_AUTO_ALIASES EQUAL NUMBER { sr_auto_aliases=$3; }
1446         | SR_AUTO_ALIASES EQUAL error  { yyerror("boolean value expected"); }
1447         | ADVERTISED_ADDRESS EQUAL listen_id {
1448                 if ($3){
1449                         default_global_address.s=$3;
1450                         default_global_address.len=strlen($3);
1451                 }
1452         }
1453         | ADVERTISED_ADDRESS EQUAL error {yyerror("ip address or hostname expected"); }
1454         | ADVERTISED_PORT EQUAL NUMBER {
1455                 tmp=int2str($3, &i_tmp);
1456                 if ((default_global_port.s=pkg_malloc(i_tmp))==0) {
1457                         LM_CRIT("cfg. parser: out of memory.\n");
1458                         default_global_port.len=0;
1459                 } else {
1460                         default_global_port.len=i_tmp;
1461                         memcpy(default_global_port.s, tmp, default_global_port.len);
1462                 };
1463         }
1464         |ADVERTISED_PORT EQUAL error {yyerror("ip address or hostname expected"); }
1465         | DISABLE_CORE EQUAL NUMBER { disable_core_dump=$3; }
1466         | DISABLE_CORE EQUAL error { yyerror("boolean value expected"); }
1467         | OPEN_FD_LIMIT EQUAL NUMBER { open_files_limit=$3; }
1468         | OPEN_FD_LIMIT EQUAL error { yyerror("number expected"); }
1469         | SHM_MEM_SZ EQUAL NUMBER {
1470                 if (shm_initialized())
1471                         yyerror("shm/shm_mem_size must be before any modparam or the"
1472                                         " route blocks");
1473                 else if (shm_mem_size == 0 || shm_mem_size == SHM_MEM_POOL_SIZE)
1474                         shm_mem_size=$3 * 1024 * 1024;
1475         }
1476         | SHM_MEM_SZ EQUAL error { yyerror("number expected"); }
1477         | SHM_FORCE_ALLOC EQUAL NUMBER {
1478                 if (shm_initialized())
1479                         yyerror("shm_force_alloc must be before any modparam or the"
1480                                         " route blocks");
1481                 else
1482                         shm_force_alloc=$3;
1483         }
1484         | SHM_FORCE_ALLOC EQUAL error { yyerror("boolean value expected"); }
1485         | MLOCK_PAGES EQUAL NUMBER { mlock_pages=$3; }
1486         | MLOCK_PAGES EQUAL error { yyerror("boolean value expected"); }
1487         | REAL_TIME EQUAL NUMBER { real_time=$3; }
1488         | REAL_TIME EQUAL error { yyerror("boolean value expected"); }
1489         | RT_PRIO EQUAL NUMBER { rt_prio=$3; }
1490         | RT_PRIO EQUAL error { yyerror("boolean value expected"); }
1491         | RT_POLICY EQUAL NUMBER { rt_policy=$3; }
1492         | RT_POLICY EQUAL error { yyerror("boolean value expected"); }
1493         | RT_TIMER1_PRIO EQUAL NUMBER { rt_timer1_prio=$3; }
1494         | RT_TIMER1_PRIO EQUAL error { yyerror("boolean value expected"); }
1495         | RT_TIMER1_POLICY EQUAL NUMBER { rt_timer1_policy=$3; }
1496         | RT_TIMER1_POLICY EQUAL error { yyerror("boolean value expected"); }
1497         | RT_TIMER2_PRIO EQUAL NUMBER { rt_timer2_prio=$3; }
1498         | RT_TIMER2_PRIO EQUAL error { yyerror("boolean value expected"); }
1499         | RT_TIMER2_POLICY EQUAL NUMBER { rt_timer2_policy=$3; }
1500         | RT_TIMER2_POLICY EQUAL error { yyerror("boolean value expected"); }
1501         | MCAST_LOOPBACK EQUAL NUMBER {
1502                 #ifdef USE_MCAST
1503                         mcast_loopback=$3;
1504                 #else
1505                         warn("no multicast support compiled in");
1506                 #endif
1507         }
1508         | MCAST_LOOPBACK EQUAL error { yyerror("boolean value expected"); }
1509         | MCAST_TTL EQUAL NUMBER {
1510                 #ifdef USE_MCAST
1511                         mcast_ttl=$3;
1512                 #else
1513                         warn("no multicast support compiled in");
1514                 #endif
1515         }
1516         | MCAST_TTL EQUAL error { yyerror("number expected"); }
1517         | MCAST EQUAL ID {
1518                 #ifdef USE_MCAST
1519                         mcast=$3;
1520                 #else
1521                         warn("no multicast support compiled in");
1522                 #endif
1523         }
1524         | MCAST EQUAL STRING {
1525                 #ifdef USE_MCAST
1526                         mcast=$3;
1527                 #else
1528                         warn("no multicast support compiled in");
1529                 #endif
1530         }
1531         | MCAST EQUAL error { yyerror("string expected"); }
1532         | TOS EQUAL NUMBER { tos=$3; }
1533         | TOS EQUAL ID { if (strcasecmp($3,"IPTOS_LOWDELAY")) {
1534                         tos=IPTOS_LOWDELAY;
1535                 } else if (strcasecmp($3,"IPTOS_THROUGHPUT")) {
1536                         tos=IPTOS_THROUGHPUT;
1537                 } else if (strcasecmp($3,"IPTOS_RELIABILITY")) {
1538                         tos=IPTOS_RELIABILITY;
1539 #if defined(IPTOS_MINCOST)
1540                 } else if (strcasecmp($3,"IPTOS_MINCOST")) {
1541                         tos=IPTOS_MINCOST;
1542 #endif
1543 #if defined(IPTOS_LOWCOST)
1544                 } else if (strcasecmp($3,"IPTOS_LOWCOST")) {
1545                         tos=IPTOS_LOWCOST;
1546 #endif
1547                 } else {
1548                         yyerror("invalid tos value - allowed: "
1549                                 "IPTOS_LOWDELAY,IPTOS_THROUGHPUT,"
1550                                 "IPTOS_RELIABILITY"
1551 #if defined(IPTOS_LOWCOST)
1552                                 ",IPTOS_LOWCOST"
1553 #endif
1554 #if !defined(IPTOS_MINCOST)
1555                                 ",IPTOS_MINCOST"
1556 #endif
1557                                 "\n");
1558                 }
1559         }
1560         | TOS EQUAL error { yyerror("number expected"); }
1561         | PMTU_DISCOVERY EQUAL NUMBER { pmtu_discovery=$3; }
1562         | PMTU_DISCOVERY error { yyerror("number expected"); }
1563         | KILL_TIMEOUT EQUAL NUMBER { ser_kill_timeout=$3; }
1564         | KILL_TIMEOUT EQUAL error { yyerror("number expected"); }
1565         | MAX_WLOOPS EQUAL NUMBER { default_core_cfg.max_while_loops=$3; }
1566         | MAX_WLOOPS EQUAL error { yyerror("number expected"); }
1567         | PVBUFSIZE EQUAL NUMBER { pv_set_buffer_size($3); }
1568         | PVBUFSIZE EQUAL error { yyerror("number expected"); }
1569         | PVBUFSLOTS EQUAL NUMBER { pv_set_buffer_slots($3); }
1570         | PVBUFSLOTS EQUAL error { yyerror("number expected"); }
1571         | PVCACHELIMIT EQUAL NUMBER { default_core_cfg.pv_cache_limit=$3; }
1572         | PVCACHELIMIT EQUAL error { yyerror("number expected"); }
1573         | PVCACHEACTION EQUAL NUMBER { default_core_cfg.pv_cache_action=$3; }
1574         | PVCACHEACTION EQUAL error { yyerror("number expected"); }
1575         | HTTP_REPLY_PARSE EQUAL NUMBER { http_reply_parse=$3; }
1576         | HTTP_REPLY_PARSE EQUAL error { yyerror("boolean value expected"); }
1577         | VERBOSE_STARTUP EQUAL NUMBER { ksr_verbose_startup=$3; }
1578         | VERBOSE_STARTUP EQUAL error { yyerror("boolean value expected"); }
1579         | ROUTE_LOCKS_SIZE EQUAL NUMBER { ksr_route_locks_size=$3; }
1580         | ROUTE_LOCKS_SIZE EQUAL error { yyerror("number expected"); }
1581     | SERVER_ID EQUAL NUMBER { server_id=$3; }
1582         | SERVER_ID EQUAL error  { yyerror("number expected"); }
1583         | KEMI DOT ONSEND_ROUTE_CALLBACK EQUAL STRING {
1584                         kemi_onsend_route_callback.s = $5;
1585                         kemi_onsend_route_callback.len = strlen($5);
1586                         if(kemi_onsend_route_callback.len==4
1587                                         && strcasecmp(kemi_onsend_route_callback.s, "none")==0) {
1588                                 kemi_onsend_route_callback.s = "";
1589                                 kemi_onsend_route_callback.len = 0;
1590                         }
1591                 }
1592         | KEMI DOT ONSEND_ROUTE_CALLBACK EQUAL error { yyerror("string expected"); }
1593         | KEMI DOT REPLY_ROUTE_CALLBACK EQUAL STRING {
1594                         kemi_reply_route_callback.s = $5;
1595                         kemi_reply_route_callback.len = strlen($5);
1596                         if(kemi_reply_route_callback.len==4
1597                                         && strcasecmp(kemi_reply_route_callback.s, "none")==0) {
1598                                 kemi_reply_route_callback.s = "";
1599                                 kemi_reply_route_callback.len = 0;
1600                         }
1601                 }
1602         | KEMI DOT REPLY_ROUTE_CALLBACK EQUAL error { yyerror("string expected"); }
1603         | KEMI DOT EVENT_ROUTE_CALLBACK EQUAL STRING {
1604                         kemi_event_route_callback.s = $5;
1605                         kemi_event_route_callback.len = strlen($5);
1606                         if(kemi_event_route_callback.len==4
1607                                         && strcasecmp(kemi_event_route_callback.s, "none")==0) {
1608                                 kemi_event_route_callback.s = "";
1609                                 kemi_event_route_callback.len = 0;
1610                         }
1611                 }
1612         | KEMI DOT EVENT_ROUTE_CALLBACK EQUAL error { yyerror("string expected"); }
1613     | MAX_RECURSIVE_LEVEL EQUAL NUMBER { set_max_recursive_level($3); }
1614     | MAX_BRANCHES_PARAM EQUAL NUMBER { sr_dst_max_branches = $3; }
1615     | LATENCY_LOG EQUAL intno { default_core_cfg.latency_log=$3; }
1616         | LATENCY_LOG EQUAL error  { yyerror("number  expected"); }
1617     | LATENCY_CFG_LOG EQUAL intno { default_core_cfg.latency_cfg_log=$3; }
1618         | LATENCY_CFG_LOG EQUAL error  { yyerror("number  expected"); }
1619     | LATENCY_LIMIT_DB EQUAL NUMBER { default_core_cfg.latency_limit_db=$3; }
1620         | LATENCY_LIMIT_DB EQUAL error  { yyerror("number  expected"); }
1621     | LATENCY_LIMIT_ACTION EQUAL NUMBER { default_core_cfg.latency_limit_action=$3; }
1622         | LATENCY_LIMIT_ACTION EQUAL error  { yyerror("number  expected"); }
1623     | MSG_TIME EQUAL NUMBER { sr_msg_time=$3; }
1624         | MSG_TIME EQUAL error  { yyerror("number  expected"); }
1625         | ONSEND_RT_REPLY EQUAL NUMBER { onsend_route_reply=$3; }
1626         | ONSEND_RT_REPLY EQUAL error { yyerror("int value expected"); }
1627         | UDP_MTU EQUAL NUMBER { default_core_cfg.udp_mtu=$3; }
1628         | UDP_MTU EQUAL error { yyerror("number expected"); }
1629         | FORCE_RPORT EQUAL NUMBER
1630                 { default_core_cfg.force_rport=$3; fix_global_req_flags(0, 0); }
1631         | FORCE_RPORT EQUAL error { yyerror("boolean value expected"); }
1632         | UDP_MTU_TRY_PROTO EQUAL proto
1633                 { default_core_cfg.udp_mtu_try_proto=$3; fix_global_req_flags(0, 0); }
1634         | UDP_MTU_TRY_PROTO EQUAL error
1635                 { yyerror("TCP, TLS, SCTP or UDP expected"); }
1636         | UDP4_RAW EQUAL intno { IF_RAW_SOCKS(default_core_cfg.udp4_raw=$3); }
1637         | UDP4_RAW EQUAL error { yyerror("number expected"); }
1638         | UDP4_RAW_MTU EQUAL NUMBER {
1639                 IF_RAW_SOCKS(default_core_cfg.udp4_raw_mtu=$3);
1640         }
1641         | UDP4_RAW_MTU EQUAL error { yyerror("number expected"); }
1642         | UDP4_RAW_TTL EQUAL NUMBER {
1643                 IF_RAW_SOCKS(default_core_cfg.udp4_raw_ttl=$3);
1644         }
1645         | UDP4_RAW_TTL EQUAL error { yyerror("number expected"); }
1646         | cfg_var
1647         | error EQUAL { yyerror("unknown config variable"); }
1648         ;
1649
1650 cfg_var_id: ID
1651         | DEFAULT { $$="default" ; } /*needed to allow default as cfg var. name*/
1652         ;
1653
1654 cfg_var_idn: ID
1655         | DEFAULT { $$="default" ; } /*needed to allow default as cfg var. name*/
1656         | NUMBER {
1657                 yyerror("cfg var field name - use of number or reserved token not allowed: %s",
1658                                 yy_number_str);
1659                 YYERROR;
1660         }
1661         ;
1662
1663 cfg_var:
1664         cfg_var_id DOT cfg_var_idn EQUAL NUMBER {
1665                 if (cfg_declare_int($1, $3, $5, 0, 0, NULL)) {
1666                         yyerror("variable cannot be declared");
1667                 }
1668         }
1669         | cfg_var_id DOT cfg_var_idn EQUAL STRING {
1670                 if (cfg_declare_str($1, $3, $5, NULL)) {
1671                         yyerror("variable cannot be declared");
1672                 }
1673         }
1674         | cfg_var_id DOT cfg_var_idn EQUAL NUMBER CFG_DESCRIPTION STRING {
1675                 if (cfg_declare_int($1, $3, $5, 0, 0, $7)) {
1676                         yyerror("variable cannot be declared");
1677                 }
1678         }
1679         | cfg_var_id DOT cfg_var_idn EQUAL STRING CFG_DESCRIPTION STRING {
1680                 if (cfg_declare_str($1, $3, $5, $7)) {
1681                         yyerror("variable cannot be declared");
1682                 }
1683         }
1684         | cfg_var_id DOT cfg_var_idn EQUAL error {
1685                 yyerror("number or string expected");
1686         }
1687         | cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_idn EQUAL NUMBER {
1688                 if (cfg_ginst_var_int($1, $3, $6, $8)) {
1689                         yyerror("variable cannot be added to the group instance");
1690                 }
1691         }
1692         | cfg_var_id LBRACK NUMBER RBRACK DOT cfg_var_idn EQUAL STRING {
1693                 if (cfg_ginst_var_string($1, $3, $6, $8)) {
1694                         yyerror("variable cannot be added to the group instance");
1695                 }
1696         }
1697         ;
1698
1699 module_stm:
1700         LOADMODULE STRING {
1701                 LM_DBG("loading module %s\n", $2);
1702                         if (load_module($2)!=0) {
1703                                 yyerror("failed to load module");
1704                         }
1705         }
1706         | LOADMODULE error      { yyerror("string expected"); }
1707         | LOADPATH STRING {
1708                 if(mods_dir_cmd==0) {
1709                         LM_DBG("loading modules under %s\n", $2);
1710                         printf("loading modules under config path: %s\n", $2);
1711                         mods_dir = $2;
1712                 } else {
1713                         LM_DBG("ignoring mod path given in config: %s\n", $2);
1714                         printf("loading modules under command line path: %s\n", mods_dir);
1715                 }
1716         }
1717         | LOADPATH error        { yyerror("string expected"); }
1718         | LOADPATH EQUAL STRING {
1719                 if(mods_dir_cmd==0) {
1720                         LM_DBG("loading modules under %s\n", $3);
1721                         printf("loading modules under config path: %s\n", $3);
1722                         mods_dir = $3;
1723                 } else {
1724                         LM_DBG("ignoring mod path given in config: %s\n", $3);
1725                         printf("loading modules under command line path: %s\n", mods_dir);
1726                 }
1727         }
1728         | LOADPATH EQUAL error  { yyerror("string expected"); }
1729         | MODPARAM LPAREN STRING COMMA STRING COMMA STRING RPAREN {
1730         #ifdef SHM_MEM
1731                 if (!shm_initialized() && init_shm()<0) {
1732                         yyerror("Can't initialize shared memory");
1733                         YYABORT;
1734                 }
1735         #endif /* SHM_MEM */
1736                 if (set_mod_param_regex($3, $5, PARAM_STRING, $7) != 0) {
1737                          yyerror("Can't set module parameter");
1738                 }
1739         }
1740         | MODPARAM LPAREN STRING COMMA STRING COMMA intno RPAREN {
1741         #ifdef SHM_MEM
1742                 if (!shm_initialized() && init_shm()<0) {
1743                         yyerror("Can't initialize shared memory");
1744                         YYABORT;
1745                 }
1746         #endif /* SHM_MEM */
1747                 if (set_mod_param_regex($3, $5, PARAM_INT, (void*)$7) != 0) {
1748                          yyerror("Can't set module parameter");
1749                 }
1750         }
1751         | MODPARAM error { yyerror("Invalid arguments"); }
1752         | CFGENGINE STRING {
1753                 if(sr_kemi_eng_setz($2, NULL)) {
1754                         yyerror("Can't set config routing engine");
1755                         YYABORT;
1756                 }
1757         }
1758         | CFGENGINE error       { yyerror("string expected"); }
1759         | CFGENGINE EQUAL STRING {
1760                 if(sr_kemi_eng_setz($3, NULL)) {
1761                         yyerror("Can't set config routing engine");
1762                         YYABORT;
1763                 }
1764         }
1765         | CFGENGINE EQUAL error { yyerror("string expected"); }
1766
1767         ;
1768 ip:
1769         ipv4  { $$=$1; }
1770         | ipv6  { $$=$1; }
1771         ;
1772 ipv4:
1773         NUMBER DOT NUMBER DOT NUMBER DOT NUMBER {
1774                 $$=pkg_malloc(sizeof(struct ip_addr));
1775                 if ($$==0) {
1776                         LM_CRIT("cfg. parser: out of memory.\n");
1777                 } else {
1778                         memset($$, 0, sizeof(struct ip_addr));
1779                         $$->af=AF_INET;
1780                         $$->len=4;
1781                         if (($1>255) || ($1<0) ||
1782                                 ($3>255) || ($3<0) ||
1783                                 ($5>255) || ($5<0) ||
1784                                 ($7>255) || ($7<0)) {
1785                                 yyerror("invalid ipv4 address");
1786                                 $$->u.addr32[0]=0;
1787                                 /* $$=0; */
1788                         } else {
1789                                 $$->u.addr[0]=$1;
1790                                 $$->u.addr[1]=$3;
1791                                 $$->u.addr[2]=$5;
1792                                 $$->u.addr[3]=$7;
1793                                 /*
1794                                 $$=htonl( ($1<<24)|
1795                                 ($3<<16)| ($5<<8)|$7 );
1796                                 */
1797                         }
1798                 }
1799         }
1800         ;
1801 ipv6addr:
1802         IPV6ADDR {
1803                 $$=pkg_malloc(sizeof(struct ip_addr));
1804                 if ($$==0) {
1805                         LM_CRIT("cfg. parser: out of memory.\n");
1806                 } else {
1807                         memset($$, 0, sizeof(struct ip_addr));
1808                         $$->af=AF_INET6;
1809                         $$->len=16;
1810                         if (inet_pton(AF_INET6, $1, $$->u.addr)<=0) {
1811                                 yyerror("bad ipv6 address");
1812                         }
1813                 }
1814         }
1815         ;
1816 ipv6:
1817         ipv6addr { $$=$1; }
1818         | LBRACK ipv6addr RBRACK {$$=$2; }
1819 ;
1820
1821
1822 route_name:             NUMBER  {
1823                                         tmp=int2str($1, &i_tmp);
1824                                         if (($$=pkg_malloc(i_tmp+1))==0) {
1825                                                 yyerror("out of  memory");
1826                                                 YYABORT;
1827                                         } else {
1828                                                 memcpy($$, tmp, i_tmp);
1829                                                 $$[i_tmp]=0;
1830                                         }
1831                                         routename = tmp;
1832                                                 }
1833                         |       ID              { routename = $1; $$=$1; }
1834                         |       STRING  { routename = $1; $$=$1; }
1835 ;
1836
1837
1838 route_main:     ROUTE { routename=NULL; }
1839                   | ROUTE_REQUEST { routename=NULL; }
1840 ;
1841
1842 route_stm:
1843         route_main LBRACE actions RBRACE {
1844         #ifdef SHM_MEM
1845                 if (!shm_initialized() && init_shm()<0) {
1846                         yyerror("Can't initialize shared memory");
1847                         YYABORT;
1848                 }
1849         #endif /* SHM_MEM */
1850                 push($3, &main_rt.rlist[DEFAULT_RT]);
1851         }
1852         | ROUTE LBRACK route_name RBRACK LBRACE actions RBRACE {
1853         #ifdef SHM_MEM
1854                 if (!shm_initialized() && init_shm()<0) {
1855                         yyerror("Can't initialize shared memory");
1856                         YYABORT;
1857                 }
1858         #endif /* SHM_MEM */
1859                 i_tmp=route_get(&main_rt, $3);
1860                 if (i_tmp==-1){
1861                         yyerror("internal error");
1862                         YYABORT;
1863                 }
1864                 if (main_rt.rlist[i_tmp]){
1865                         yyerror("duplicate route");
1866                         YYABORT;
1867                 }
1868                 push($6, &main_rt.rlist[i_tmp]);
1869         }
1870         | ROUTE error { yyerror("invalid  route  statement"); }
1871         | ROUTE_REQUEST error { yyerror("invalid  request_route  statement"); }
1872         ;
1873 failure_route_stm:
1874         ROUTE_FAILURE LBRACE actions RBRACE {
1875         #ifdef SHM_MEM
1876                 if (!shm_initialized() && init_shm()<0) {
1877                         yyerror("Can't initialize shared memory");
1878                         YYABORT;
1879                 }
1880         #endif /* SHM_MEM */
1881                 push($3, &failure_rt.rlist[DEFAULT_RT]);
1882         }
1883         | ROUTE_FAILURE LBRACK route_name RBRACK LBRACE actions RBRACE {
1884         #ifdef SHM_MEM
1885                 if (!shm_initialized() && init_shm()<0) {
1886                         yyerror("Can't initialize shared memory");
1887                         YYABORT;
1888                 }
1889         #endif /* SHM_MEM */
1890                 i_tmp=route_get(&failure_rt, $3);
1891                 if (i_tmp==-1){
1892                         yyerror("internal error");
1893                         YYABORT;
1894                 }
1895                 if (failure_rt.rlist[i_tmp]){
1896                         yyerror("duplicate route");
1897                         YYABORT;
1898                 }
1899                 push($6, &failure_rt.rlist[i_tmp]);
1900         }
1901         | ROUTE_FAILURE error { yyerror("invalid failure_route statement"); }
1902         ;
1903
1904
1905 route_reply_main:       ROUTE_ONREPLY { routename=NULL; }
1906                   | ROUTE_REPLY { routename=NULL; }
1907 ;
1908
1909
1910 onreply_route_stm:
1911         route_reply_main LBRACE {rt=CORE_ONREPLY_ROUTE;} actions RBRACE {
1912         #ifdef SHM_MEM
1913                 if (!shm_initialized() && init_shm()<0) {
1914                         yyerror("Can't initialize shared memory");
1915                         YYABORT;
1916                 }
1917         #endif /* SHM_MEM */
1918                 push($4, &onreply_rt.rlist[DEFAULT_RT]);
1919         }
1920         | ROUTE_ONREPLY error { yyerror("invalid onreply_route statement"); }
1921         | ROUTE_REPLY error { yyerror("invalid onreply_route statement"); }
1922         | ROUTE_ONREPLY LBRACK route_name RBRACK
1923                 {rt=(*$3=='0' && $3[1]==0)?CORE_ONREPLY_ROUTE:TM_ONREPLY_ROUTE;}
1924                 LBRACE actions RBRACE {
1925         #ifdef SHM_MEM
1926                 if (!shm_initialized() && init_shm()<0) {
1927                         yyerror("Can't initialize shared memory");
1928                         YYABORT;
1929                 }
1930         #endif /* SHM_MEM */
1931                 if (*$3=='0' && $3[1]==0){
1932                         /* onreply_route[0] {} is equivalent with onreply_route {}*/
1933                         push($7, &onreply_rt.rlist[DEFAULT_RT]);
1934                 }else{
1935                         i_tmp=route_get(&onreply_rt, $3);
1936                         if (i_tmp==-1){
1937                                 yyerror("internal error");
1938                                 YYABORT;
1939                         }
1940                         if (onreply_rt.rlist[i_tmp]){
1941                                 yyerror("duplicate route");
1942                                 YYABORT;
1943                         }
1944                         push($7, &onreply_rt.rlist[i_tmp]);
1945                 }
1946         }
1947         | ROUTE_ONREPLY LBRACK route_name RBRACK error {
1948                 yyerror("invalid onreply_route statement");
1949         }
1950         ;
1951 branch_route_stm:
1952         ROUTE_BRANCH LBRACE actions RBRACE {
1953         #ifdef SHM_MEM
1954                 if (!shm_initialized() && init_shm()<0) {
1955                         yyerror("Can't initialize shared memory");
1956                         YYABORT;
1957                 }
1958         #endif /* SHM_MEM */
1959                 push($3, &branch_rt.rlist[DEFAULT_RT]);
1960         }
1961         | ROUTE_BRANCH LBRACK route_name RBRACK LBRACE actions RBRACE {
1962         #ifdef SHM_MEM
1963                 if (!shm_initialized() && init_shm()<0) {
1964                         yyerror("Can't initialize shared memory");
1965                         YYABORT;
1966                 }
1967         #endif /* SHM_MEM */
1968                 i_tmp=route_get(&branch_rt, $3);
1969                 if (i_tmp==-1){
1970                         yyerror("internal error");
1971                         YYABORT;
1972                 }
1973                 if (branch_rt.rlist[i_tmp]){
1974                         yyerror("duplicate route");
1975                         YYABORT;
1976                 }
1977                 push($6, &branch_rt.rlist[i_tmp]);
1978         }
1979         | ROUTE_BRANCH error { yyerror("invalid branch_route statement"); }
1980         ;
1981 send_route_stm: ROUTE_SEND LBRACE actions RBRACE {
1982         #ifdef SHM_MEM
1983                 if (!shm_initialized() && init_shm()<0) {
1984                         yyerror("Can't initialize shared memory");
1985                         YYABORT;
1986                 }
1987         #endif /* SHM_MEM */
1988                 push($3, &onsend_rt.rlist[DEFAULT_RT]);
1989         }
1990         | ROUTE_SEND LBRACK route_name RBRACK LBRACE actions RBRACE {
1991         #ifdef SHM_MEM
1992                 if (!shm_initialized() && init_shm()<0) {
1993                         yyerror("Can't initialize shared memory");
1994                         YYABORT;
1995                 }
1996         #endif /* SHM_MEM */
1997                 i_tmp=route_get(&onsend_rt, $3);
1998                 if (i_tmp==-1){
1999                         yyerror("internal error");
2000                         YYABORT;
2001                 }
2002                 if (onsend_rt.rlist[i_tmp]){
2003                         yyerror("duplicate route");
2004                         YYABORT;
2005                 }
2006                 push($6, &onsend_rt.rlist[i_tmp]);
2007         }
2008         | ROUTE_SEND error { yyerror("invalid onsend_route statement"); }
2009         ;
2010 event_route_stm: ROUTE_EVENT LBRACK EVENT_RT_NAME RBRACK LBRACE actions RBRACE {
2011         #ifdef SHM_MEM
2012                 if (!shm_initialized() && init_shm()<0) {
2013                         yyerror("Can't initialize shared memory");
2014                         YYABORT;
2015                 }
2016         #endif /* SHM_MEM */
2017                 i_tmp=route_get(&event_rt, $3);
2018                 if (i_tmp==-1){
2019                         yyerror("internal error");
2020                         YYABORT;
2021                 }
2022                 if (event_rt.rlist[i_tmp]){
2023                         yyerror("duplicate route");
2024                         YYABORT;
2025                 }
2026                 push($6, &event_rt.rlist[i_tmp]);
2027         }
2028
2029         | ROUTE_EVENT error { yyerror("invalid event_route statement"); }
2030         ;
2031 preprocess_stm:
2032         SUBST STRING { if(pp_subst_add($2)<0) YYERROR; }
2033         | SUBST error { yyerror("invalid subst preprocess statement"); }
2034         | SUBSTDEF STRING { if(pp_substdef_add($2, 0)<0) YYERROR; }
2035         | SUBSTDEF error { yyerror("invalid substdef preprocess statement"); }
2036         | SUBSTDEFS STRING { if(pp_substdef_add($2, 1)<0) YYERROR; }
2037         | SUBSTDEFS error { yyerror("invalid substdefs preprocess statement"); }
2038         ;
2039
2040 /*exp:  rval_expr
2041                 {
2042                         if ($1==0){
2043                                 yyerror("invalid expression");
2044                                 $$=0;
2045                         }else if (!rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
2046                                 yyerror("invalid expression");
2047                                 $$=0;
2048                         }else if (i_tmp!=RV_INT && i_tmp!=RV_NONE){
2049                                 yyerror("invalid expression type, int expected\n");
2050                                 $$=0;
2051                         }else
2052                                 $$=mk_elem(NO_OP, RVEXP_O, $1, 0, 0);
2053                 }
2054         ;
2055 */
2056
2057 /* exp elem operators */
2058 equalop:
2059         EQUAL_T {$$=EQUAL_OP; }
2060         | DIFF  {$$=DIFF_OP; }
2061         | STREQ {$$=EQUAL_OP; }  /* for expr. elems equiv. to EQUAL_T*/
2062         | STRDIFF {$$=DIFF_OP; } /* for expr. elems. equiv. to DIFF */
2063         ;
2064 cmpop:
2065           GT    {$$=GT_OP; }
2066         | LT    {$$=LT_OP; }
2067         | GTE   {$$=GTE_OP; }
2068         | LTE   {$$=LTE_OP; }
2069         ;
2070 strop:
2071         equalop {$$=$1; }
2072         | MATCH {$$=MATCH_OP; }
2073         ;
2074
2075
2076 /* rve expr. operators */
2077 rve_equalop:
2078         EQUAL_T {$$=RVE_EQ_OP; }
2079         | DIFF  {$$=RVE_DIFF_OP; }
2080         | INTEQ {$$=RVE_IEQ_OP; }
2081         | INTDIFF {$$=RVE_IDIFF_OP; }
2082         | STREQ {$$=RVE_STREQ_OP; }
2083         | STRDIFF {$$=RVE_STRDIFF_OP; }
2084         | MATCH {$$=RVE_MATCH_OP; }
2085         ;
2086 rve_cmpop:
2087           GT    {$$=RVE_GT_OP; }
2088         | LT    {$$=RVE_LT_OP; }
2089         | GTE   {$$=RVE_GTE_OP; }
2090         | LTE   {$$=RVE_LTE_OP; }
2091         ;
2092
2093
2094
2095 /* boolean expression uri operands */
2096 uri_type:
2097         URI             {$$=URI_O;}
2098         | FROM_URI      {$$=FROM_URI_O;}
2099         | TO_URI        {$$=TO_URI_O;}
2100         ;
2101
2102
2103 /* boolean expression integer operands, available only in the
2104   onsend route */
2105 eint_op_onsend:
2106                         SNDPORT         { $$=SNDPORT_O; }
2107                 |       TOPORT          { $$=TOPORT_O; }
2108                 |       SNDAF           { $$=SNDAF_O; }
2109                 ;
2110
2111 /* boolean expression integer operands */
2112 eint_op:        SRCPORT         { $$=SRCPORT_O; }
2113                 |       DSTPORT         { $$=DSTPORT_O; }
2114                 |       AF                      { $$=AF_O; }
2115                 |       MSGLEN          { $$=MSGLEN_O; }
2116                 | eint_op_onsend
2117         ;
2118
2119 /* boolean expression ip/ipnet operands */
2120 eip_op_onsend:
2121                         SNDIP           { onsend_check("snd_ip"); $$=SNDIP_O; }
2122                 |       TOIP            { onsend_check("to_ip");  $$=TOIP_O; }
2123                 ;
2124
2125 eip_op:         SRCIP           { $$=SRCIP_O; }
2126                 |       DSTIP           { $$=DSTIP_O; }
2127                 | eip_op_onsend
2128                 ;
2129
2130
2131
2132 exp_elem:
2133         METHOD strop rval_expr %prec EQUAL_T
2134                 {$$= mk_elem($2, METHOD_O, 0, RVE_ST, $3);}
2135         | METHOD strop ID %prec EQUAL_T
2136                 {$$ = mk_elem($2, METHOD_O, 0, STRING_ST,$3); }
2137         | METHOD strop error { $$=0; yyerror("string expected"); }
2138         | METHOD error
2139                 { $$=0; yyerror("invalid operator,== , !=, or =~ expected"); }
2140         | uri_type strop rval_expr %prec EQUAL_T
2141                 {$$ = mk_elem($2, $1, 0, RVE_ST, $3); }
2142         | uri_type strop MYSELF %prec EQUAL_T
2143                 {$$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
2144         | uri_type strop error %prec EQUAL_T
2145                 { $$=0; yyerror("string or MYSELF expected"); }
2146         | uri_type error
2147                 { $$=0; yyerror("invalid operator, == , != or =~ expected"); }
2148         | eint_op cmpop rval_expr %prec GT { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
2149         | eint_op equalop rval_expr %prec EQUAL_T
2150                 { $$=mk_elem($2, $1, 0, RVE_ST, $3 ); }
2151         | eint_op cmpop error   { $$=0; yyerror("number expected"); }
2152         | eint_op equalop error { $$=0; yyerror("number expected"); }
2153         | eint_op error { $$=0; yyerror("==, !=, <,>, >= or <=  expected"); }
2154         | PROTO equalop eqproto %prec EQUAL_T
2155                 { $$=mk_elem($2, PROTO_O, 0, NUMBER_ST, (void*)$3 ); }
2156         | PROTO equalop rval_expr %prec EQUAL_T
2157                 { $$=mk_elem($2, PROTO_O, 0, RVE_ST, $3 ); }
2158         | PROTO equalop error
2159                 { $$=0; yyerror("protocol expected (udp, tcp, tls, sctp, ws, or wss)"); }
2160         | SNDPROTO equalop eqproto %prec EQUAL_T
2161                 { $$=mk_elem($2, SNDPROTO_O, 0, NUMBER_ST, (void*)$3 ); }
2162         | SNDPROTO equalop rval_expr %prec EQUAL_T
2163                 { $$=mk_elem($2, SNDPROTO_O, 0, RVE_ST, $3 ); }
2164         | SNDPROTO equalop error
2165                 { $$=0; yyerror("protocol expected (udp, tcp, tls, sctp, ws, or wss)"); }
2166         | eip_op strop ipnet %prec EQUAL_T { $$=mk_elem($2, $1, 0, NET_ST, $3); }
2167         | eip_op strop rval_expr %prec EQUAL_T {
2168                         s_tmp.s=0;
2169                         $$=0;
2170                         if (rve_is_constant($3)){
2171                                 i_tmp=rve_guess_type($3);
2172                                 if (i_tmp==RV_INT)
2173                                         yyerror("string expected");
2174                                 else if (i_tmp==RV_STR){
2175                                         if (((rval_tmp=rval_expr_eval(0, 0, $3))==0) ||
2176                                                                 (rval_get_str(0, 0, &s_tmp, rval_tmp, 0)<0)){
2177                                                 rval_destroy(rval_tmp);
2178                                                 yyerror("bad rvalue expression");
2179                                         }else{
2180                                                 rval_destroy(rval_tmp);
2181                                         }
2182                                 }else{
2183                                         yyerror("BUG: unexpected dynamic type");
2184                                 }
2185                         }else{
2186                                         /* warn("non constant rvalue in ip comparison") */;
2187                         }
2188                         if (s_tmp.s){
2189                                 ip_tmp=str2ip(&s_tmp);
2190                                 if (ip_tmp==0)
2191                                         ip_tmp=str2ip6(&s_tmp);
2192                                 pkg_free(s_tmp.s);
2193                                 if (ip_tmp) {
2194                                         $$=mk_elem($2, $1, 0, NET_ST,
2195                                                                 mk_new_net_bitlen(ip_tmp, ip_tmp->len*8) );
2196                                 } else {
2197                                         $$=mk_elem($2, $1, 0, RVE_ST, $3);
2198                                 }
2199                         }else{
2200                                 $$=mk_elem($2, $1, 0, RVE_ST, $3);
2201                         }
2202                 }
2203         | eip_op strop host %prec EQUAL_T
2204                 { $$=mk_elem($2, $1, 0, STRING_ST, $3); }
2205         | eip_op strop MYSELF %prec EQUAL_T
2206                 { $$=mk_elem($2, $1, 0, MYSELF_ST, 0); }
2207         | eip_op strop error %prec EQUAL_T
2208                 { $$=0; yyerror( "ip address or hostname expected" ); }
2209         | eip_op error
2210                 { $$=0; yyerror("invalid operator, ==, != or =~ expected");}
2211
2212         | MYSELF equalop uri_type %prec EQUAL_T
2213                 { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
2214         | MYSELF equalop eip_op %prec EQUAL_T
2215                 { $$=mk_elem($2, $3, 0, MYSELF_ST, 0); }
2216         | MYSELF equalop error %prec EQUAL_T
2217                 { $$=0; yyerror("URI, SRCIP or DSTIP expected"); }
2218         | MYSELF error  { $$=0; yyerror ("invalid operator, == or != expected"); }
2219         ;
2220
2221 ipnet:
2222         ip SLASH ip     { $$=mk_new_net($1, $3); }
2223         | ip SLASH NUMBER {
2224                 if (($3<0) || ($3>$1->len*8)) {
2225                         yyerror("invalid bit number in netmask");
2226                         $$=0;
2227                 } else {
2228                         $$=mk_new_net_bitlen($1, $3);
2229                 /*
2230                         $$=mk_new_net($1, htonl( ($3)?~( (1<<(32-$3))-1 ):0 ) );
2231                 */
2232                 }
2233         }
2234         | ip    { $$=mk_new_net_bitlen($1, $1->len*8); }
2235         | ip SLASH error { $$=0; yyerror("netmask (eg:255.0.0.0 or 8) expected"); }
2236         ;
2237
2238 host:
2239         ID { $$=$1; }
2240         | host DOT ID {
2241                 if ($1){
2242                         $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
2243                         if ($$==0) {
2244                                 LM_CRIT("cfg. parser: memory allocation"
2245                                                         " failure while parsing host\n");
2246                         } else {
2247                                 memcpy($$, $1, strlen($1));
2248                                 $$[strlen($1)]='.';
2249                                 memcpy($$+strlen($1)+1, $3, strlen($3));
2250                                 $$[strlen($1)+1+strlen($3)]=0;
2251                         }
2252                         pkg_free($1);
2253                 }
2254                 if ($3) pkg_free($3);
2255         }
2256         | host MINUS ID {
2257                 if ($1){
2258                         $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
2259                         if ($$==0) {
2260                                 LM_CRIT("cfg. parser: memory allocation"
2261                                                         " failure while parsing host\n");
2262                         } else {
2263                                 memcpy($$, $1, strlen($1));
2264                                 $$[strlen($1)]='-';
2265                                 memcpy($$+strlen($1)+1, $3, strlen($3));
2266                                 $$[strlen($1)+1+strlen($3)]=0;
2267                         }
2268                         pkg_free($1);
2269                 }
2270                 if ($3) pkg_free($3);
2271         }
2272         | host DOT error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
2273         | host MINUS error { $$=0; pkg_free($1); yyerror("invalid hostname"); }
2274         ;
2275
2276 host_if_id: ID
2277                 | NUM_ID
2278                 | NUMBER {
2279                         /* get string version */
2280                         $$=pkg_malloc(strlen(yy_number_str)+1);
2281                         if ($$)
2282                                 strcpy($$, yy_number_str);
2283                 }
2284                 ;
2285
2286 host_or_if:
2287         host_if_id { $$=$1; }
2288         | host_or_if DOT host_if_id {
2289                 if ($1){
2290                         $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
2291                         if ($$==0) {
2292                                 LM_CRIT("cfg. parser: memory allocation"
2293                                                         " failure while parsing host/interface name\n");
2294                         } else {
2295                                 memcpy($$, $1, strlen($1));
2296                                 $$[strlen($1)]='.';
2297                                 memcpy($$+strlen($1)+1, $3, strlen($3));
2298                                 $$[strlen($1)+1+strlen($3)]=0;
2299                         }
2300                         pkg_free($1);
2301                 }
2302                 if ($3) pkg_free($3);
2303         }
2304         | host_or_if MINUS host_if_id {
2305                 if ($1){
2306                         $$=(char*)pkg_malloc(strlen($1)+1+strlen($3)+1);
2307                         if ($$==0) {
2308                                 LM_CRIT("cfg. parser: memory allocation"
2309                                                         " failure while parsing host/interface name\n");
2310                         } else {
2311                                 memcpy($$, $1, strlen($1));
2312                                 $$[strlen($1)]='-';
2313                                 memcpy($$+strlen($1)+1, $3, strlen($3));
2314                                 $$[strlen($1)+1+strlen($3)]=0;
2315                         }
2316                         pkg_free($1);
2317                 }
2318                 if ($3) pkg_free($3);
2319         }
2320         | host_or_if DOT error { $$=0; pkg_free($1);
2321                                                                 yyerror("invalid host or interface name"); }
2322         | host_or_if MINUS error { $$=0; pkg_free($1);
2323                                                                 yyerror("invalid host or interface name"); }
2324         ;
2325
2326
2327 /* filtered cmd */
2328 fcmd:
2329         cmd {
2330                 /* check if allowed */
2331                 if ($1 && rt==ONSEND_ROUTE) {
2332                         switch($1->type) {
2333                                 case DROP_T:
2334                                 case LOG_T:
2335                                 case SETFLAG_T:
2336                                 case RESETFLAG_T:
2337                                 case ISFLAGSET_T:
2338                                 case IF_T:
2339                                 case MODULE0_T:
2340                                 case MODULE1_T:
2341                                 case MODULE2_T:
2342                                 case MODULE3_T:
2343                                 case MODULE4_T:
2344                                 case MODULE5_T:
2345                                 case MODULE6_T:
2346                                 case MODULEX_T:
2347                                 case SET_FWD_NO_CONNECT_T:
2348                                 case SET_RPL_NO_CONNECT_T:
2349                                 case SET_FWD_CLOSE_T:
2350                                 case SET_RPL_CLOSE_T:
2351                                         $$=$1;
2352                                         break;
2353                                 default:
2354                                         $$=0;
2355                                         yyerror("command not allowed in onsend_route\n");
2356                         }
2357                 } else {
2358                         $$=$1;
2359                 }
2360         }
2361         ;
2362 /*
2363 exp_stm:
2364         fcmd    { $$=$1; }
2365         | if_cmd        { $$=$1; }
2366         | assign_action { $$ = $1; }
2367         | LBRACE actions RBRACE { $$=$2; }
2368         ;
2369 */
2370 stm:
2371         action  { $$=$1; }
2372         | LBRACE actions RBRACE { $$=$2; }
2373         ;
2374 actions:
2375         actions action  {$$=append_action($1, $2); }
2376         | action        {$$=$1;}
2377         | actions error { $$=0; yyerror("bad command"); }
2378         ;
2379 action:
2380         fcmd SEMICOLON {$$=$1;}
2381         | if_cmd {$$=$1;}
2382         | switch_cmd {$$=$1;}
2383         | while_cmd { $$=$1; }
2384         | ret_cmd SEMICOLON { $$=$1; }
2385         | assign_action SEMICOLON {$$=$1;}
2386         | SEMICOLON /* null action */ {$$=0;}
2387         | fcmd error { $$=0; yyerror("bad command: missing ';'?"); }
2388         ;
2389 if_cmd:
2390         IF rval_expr stm        {
2391                 if ($2 && rval_expr_int_check($2)>=0){
2392                         warn_ct_rve($2, "if");
2393                         $$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, NOSUBTYPE, 0);
2394                         set_cfg_pos($$);
2395                 }else
2396                         YYERROR;
2397         }
2398         | IF rval_expr stm ELSE stm     {
2399                 if ($2 && rval_expr_int_check($2)>=0){
2400                         warn_ct_rve($2, "if");
2401                         $$=mk_action( IF_T, 3, RVE_ST, $2, ACTIONS_ST, $3, ACTIONS_ST, $5);
2402                         set_cfg_pos($$);
2403                 }else
2404                         YYERROR;
2405         }
2406         ;
2407
2408 ct_rval: rval_expr {
2409                         $$=0;
2410                         if ($1 && !rve_is_constant($1)){
2411                                 yyerror("constant expected");
2412                                 YYERROR;
2413                         /*
2414                         } else if ($1 &&
2415                                                 !rve_check_type((enum rval_type*)&i_tmp, $1, 0, 0 ,0)){
2416                                 yyerror("invalid expression (bad type)");
2417                         }else if ($1 && i_tmp!=RV_INT){
2418                                 yyerror("invalid expression type, int expected\n");
2419                         */
2420                         }else
2421                                 $$=$1;
2422                 }
2423 ;
2424 single_case:
2425         CASE ct_rval COLON actions {
2426                 $$=0;
2427                 if ($2==0) { yyerror ("bad case label"); YYERROR; }
2428                 else if ((($$=mk_case_stm($2, 0, $4, &i_tmp))==0) && (i_tmp==-10)){
2429                                 YYABORT;
2430                 }
2431         }
2432 | CASE SLASH ct_rval COLON actions {
2433                 $$=0;
2434                 if ($3==0) { yyerror ("bad case label"); YYERROR; }
2435                 else if ((($$=mk_case_stm($3, 1, $5, &i_tmp))==0) && (i_tmp==-10)){
2436                                 YYABORT;
2437                 }
2438         }
2439         | CASE ct_rval COLON {
2440                 $$=0;
2441                 if ($2==0) { yyerror ("bad case label"); YYERROR; }
2442                 else if ((($$=mk_case_stm($2, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
2443                                 YYABORT;
2444                 }
2445         }
2446         | CASE SLASH ct_rval COLON {
2447                 $$=0;
2448                 if ($3==0) { yyerror ("bad regex case label"); YYERROR; }
2449                 else if ((($$=mk_case_stm($3, 1, 0, &i_tmp))==0) && (i_tmp==-10)){
2450                                 YYABORT;
2451                 }
2452         }
2453         | DEFAULT COLON actions {
2454                 if ((($$=mk_case_stm(0, 0, $3, &i_tmp))==0) && (i_tmp==-10)){
2455                                 YYABORT;
2456                 }
2457         }
2458         | DEFAULT COLON {
2459                 if ((($$=mk_case_stm(0, 0, 0, &i_tmp))==0) && (i_tmp==-10)){
2460                                 YYABORT;
2461                 }
2462         }
2463         | CASE error COLON actions { $$=0; yyerror("bad case label"); }
2464         | CASE SLASH error COLON actions { $$=0; yyerror("bad case regex label"); }
2465         | CASE error COLON { $$=0; yyerror("bad case label"); }
2466         | CASE SLASH error COLON { $$=0; yyerror("bad case regex label"); }
2467         | CASE ct_rval COLON error { $$=0; yyerror ("bad case body"); }
2468 ;
2469 case_stms:
2470         case_stms single_case {
2471                 $$=$1;
2472                 if ($2==0) yyerror ("bad case");
2473                 if ($$){
2474                         *($$->append)=$2;
2475                         if (*($$->append)!=0)
2476                                 $$->append=&((*($$->append))->next);
2477                 }
2478         }
2479         | single_case {
2480                 $$=$1;
2481                 if ($1==0) yyerror ("bad case");
2482                 else $$->append=&($$->next);
2483         }
2484 ;
2485 switch_cmd:
2486           SWITCH rval_expr LBRACE case_stms RBRACE {
2487                 $$=0;
2488                 if ($2==0){
2489                         yyerror("bad expression in switch(...)");
2490                         YYERROR;
2491                 }else if ($4==0){
2492                         yyerror ("bad switch body");
2493                         YYERROR;
2494                 }else if (case_check_default($4)!=0){
2495                         yyerror_at(&$2->fpos, "bad switch(): too many "
2496                                                         "\"default:\" labels\n");
2497                         YYERROR;
2498                 }else if (case_check_type($4)!=0){
2499                         yyerror_at(&$2->fpos, "bad switch(): mixed integer and"
2500                                                         " string/RE cases not allowed\n");
2501                         YYERROR;
2502                 }else{
2503                         $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, $4);
2504                         if ($$==0) {
2505                                 yyerror("internal error");
2506                                 YYABORT;
2507                         }
2508                         set_cfg_pos($$);
2509                 }
2510         }
2511         | SWITCH rval_expr LBRACE RBRACE {
2512                 $$=0;
2513                 warn("empty switch()");
2514                 if ($2==0){
2515                         yyerror("bad expression in switch(...)");
2516                         YYERROR;
2517                 }else{
2518                         /* it might have sideffects, so leave it for the optimizer */
2519                         $$=mk_action(SWITCH_T, 2, RVE_ST, $2, CASE_ST, 0);
2520                         if ($$==0) {
2521                                 yyerror("internal error");
2522                                 YYABORT;
2523                         }
2524                         set_cfg_pos($$);
2525                 }
2526         }
2527         | SWITCH error { $$=0; yyerror ("bad expression in switch(...)"); }
2528         | SWITCH rval_expr LBRACE error RBRACE
2529                 {$$=0; yyerror ("bad switch body"); }
2530 ;
2531
2532 while_cmd:
2533         WHILE rval_expr stm {
2534                 if ($2 && rval_expr_int_check($2)>=0){
2535                         warn_ct_rve($2, "while");
2536                         $$=mk_action( WHILE_T, 2, RVE_ST, $2, ACTIONS_ST, $3);
2537                         set_cfg_pos($$);
2538                 }else{
2539                         yyerror_at(&$2->fpos, "bad while(...) expression");
2540                         YYERROR;
2541                 }
2542         }
2543 ;
2544
2545 /* class_id:
2546         LBRACK ATTR_USER RBRACK { $$ = AVP_CLASS_USER; }
2547         | LBRACK ATTR_DOMAIN RBRACK { $$ = AVP_CLASS_DOMAIN; }
2548         | LBRACK ATTR_GLOBAL RBRACK { $$ = AVP_CLASS_GLOBAL; }
2549         ;
2550 */
2551 select_param:
2552         ID {
2553                 if (sel.n >= MAX_SELECT_PARAMS-1) {
2554                         yyerror("Select identifier too long\n");
2555                 }
2556                 sel.params[sel.n].type = SEL_PARAM_STR;
2557                 sel.params[sel.n].v.s.s = $1;
2558                 sel.params[sel.n].v.s.len = strlen($1);
2559                 sel.n++;
2560         }
2561         | ID LBRACK intno RBRACK {
2562                 if (sel.n >= MAX_SELECT_PARAMS-2) {
2563                         yyerror("Select identifier too long\n");
2564                 }
2565                 sel.params[sel.n].type = SEL_PARAM_STR;
2566                 sel.params[sel.n].v.s.s = $1;
2567                 sel.params[sel.n].v.s.len = strlen($1);
2568                 sel.n++;
2569                 sel.params[sel.n].type = SEL_PARAM_INT;
2570                 sel.params[sel.n].v.i = $3;
2571                 sel.n++;
2572         }
2573         | ID LBRACK STRING RBRACK {
2574                 if (sel.n >= MAX_SELECT_PARAMS-2) {
2575                         yyerror("Select identifier too long\n");
2576                 }
2577                 sel.params[sel.n].type = SEL_PARAM_STR;
2578                 sel.params[sel.n].v.s.s = $1;
2579                 sel.params[sel.n].v.s.len = strlen($1);
2580                 sel.n++;
2581                 sel.params[sel.n].type = SEL_PARAM_STR;
2582                 sel.params[sel.n].v.s.s = $3;
2583                 sel.params[sel.n].v.s.len = strlen($3);
2584                 sel.n++;
2585         }
2586         ;
2587 select_params:
2588         select_params DOT select_param
2589         | select_param
2590         ;
2591 select_id:
2592         SELECT_MARK { sel.n = 0; sel.f[0] = 0; } select_params {
2593                 sel_ptr = (select_t*)pkg_malloc(sizeof(select_t));
2594                 if (!sel_ptr) {
2595                         yyerror("No memory left to allocate select structure\n");
2596                 }
2597                 memcpy(sel_ptr, &sel, sizeof(select_t));
2598                 $$ = sel_ptr;
2599         }
2600         ;
2601 attr_class_spec:
2602         ATTR_FROM { s_attr->type |= AVP_TRACK_FROM; }
2603         | ATTR_TO { s_attr->type |= AVP_TRACK_TO; }
2604         | ATTR_FROMURI { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_URI; }
2605         | ATTR_TOURI { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_URI; }
2606         | ATTR_FROMUSER { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_USER; }
2607         | ATTR_TOUSER { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_USER; }
2608         | ATTR_FROMDOMAIN { s_attr->type |= AVP_TRACK_FROM | AVP_CLASS_DOMAIN; }
2609         | ATTR_TODOMAIN { s_attr->type |= AVP_TRACK_TO | AVP_CLASS_DOMAIN; }
2610         | ATTR_GLOBAL { s_attr->type |= AVP_TRACK_ALL | AVP_CLASS_GLOBAL; }
2611         ;
2612 attr_name_spec:
2613         ID { s_attr->type |= AVP_NAME_STR; s_attr->name.s.s = $1; s_attr->name.s.len = strlen ($1); }
2614         ;
2615 attr_spec:
2616         attr_name_spec
2617         | attr_class_spec DOT attr_name_spec
2618         ;
2619 attr_mark:
2620         ATTR_MARK {
2621                 s_attr = (struct avp_spec*)pkg_malloc(sizeof(struct avp_spec));
2622                 if (!s_attr) { yyerror("No memory left"); YYABORT; }
2623                 else s_attr->type = 0;
2624         }
2625         ;
2626 attr_id:
2627         attr_mark attr_spec { $$ = s_attr; }
2628         ;
2629 attr_id_num_idx:
2630         attr_mark attr_spec LBRACK intno RBRACK {
2631                 s_attr->type|= (AVP_NAME_STR | ($4<0?AVP_INDEX_BACKWARD:AVP_INDEX_FORWARD));
2632                 s_attr->index = ($4<0?-$4:$4);
2633                 $$ = s_attr;
2634         }
2635         ;
2636 attr_id_no_idx:
2637         attr_mark attr_spec LBRACK RBRACK {
2638                 s_attr->type|= AVP_INDEX_ALL;
2639                 $$ = s_attr;
2640         }
2641         ;
2642 attr_id_ass:
2643         attr_id
2644         | attr_id_no_idx
2645         ;
2646 /*
2647 attr_id_val:
2648         attr_id
2649         | attr_id_num_idx
2650         ;
2651 */
2652 attr_id_any:
2653         attr_id
2654         | attr_id_no_idx
2655         | attr_id_num_idx
2656 ;
2657 attr_id_any_str:
2658         attr_id
2659         | avp_pvar {
2660                 if ($1->type==LV_AVP){
2661                         s_attr = pkg_malloc(sizeof(struct avp_spec));
2662                         if (!s_attr) { yyerror("No memory left"); YYABORT; }
2663                         else{
2664                                 *s_attr=$1->lv.avps;
2665                         }
2666                         $$=s_attr;
2667                 }else
2668                         $$=0; /* not an avp, a pvar */
2669                 pkg_free($1);
2670         }
2671         | STRING {
2672                 avp_spec_t *avp_spec;
2673                 str s;
2674                 int type, idx;
2675                 avp_spec = pkg_malloc(sizeof(*avp_spec));
2676                 if (!avp_spec) {
2677                         yyerror("Not enough memory");
2678                         YYABORT;
2679                 }
2680                 s.s = $1;
2681                 if (s.s[0] == '$')
2682                         s.s++;
2683                 s.len = strlen(s.s);
2684                 if (parse_avp_name(&s, &type, &avp_spec->name, &idx)) {
2685                         yyerror("error when parsing AVP");
2686                         pkg_free(avp_spec);
2687                         YYABORT;
2688                 }
2689                 avp_spec->type = type;
2690                 avp_spec->index = idx;
2691                 $$ = avp_spec;
2692         }
2693         ;
2694
2695 pvar:   PVAR {
2696                         s_tmp.s=$1; s_tmp.len=strlen($1);
2697                         pv_spec=pv_cache_get(&s_tmp);
2698                         if (!pv_spec) {
2699                                 yyerror("Can't get from cache: %s", $1);
2700                                 YYABORT;
2701                         }
2702                         $$=pv_spec;
2703                 }
2704         ;
2705
2706 avp_pvar:       AVP_OR_PVAR {
2707                                 lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2708                                 if (!lval_tmp) {
2709                                         yyerror("Not enough memory");
2710                                         YYABORT;
2711                                 }
2712                                 memset(lval_tmp, 0, sizeof(*lval_tmp));
2713                                 s_tmp.s=$1; s_tmp.len=strlen(s_tmp.s);
2714                                 lval_tmp->lv.pvs = pv_cache_get(&s_tmp);
2715                                 if (lval_tmp->lv.pvs==NULL){
2716                                         lval_tmp->lv.avps.type|= AVP_NAME_STR;
2717                                         lval_tmp->lv.avps.name.s.s = s_tmp.s+1;
2718                                         lval_tmp->lv.avps.name.s.len = s_tmp.len-1;
2719                                         lval_tmp->type=LV_AVP;
2720                                 }else{
2721                                         lval_tmp->type=LV_PVAR;
2722                                 }
2723                                 $$ = lval_tmp;
2724                                 DBG("parsed ambiguous avp/pvar \"%.*s\" to %d\n",
2725                                                         s_tmp.len, s_tmp.s, lval_tmp->type);
2726                         }
2727         ;
2728
2729
2730 /*
2731 assign_op:
2732         ADDEQ { $$ = ADD_T; }
2733         | EQUAL { $$ = ASSIGN_T; }
2734         ;
2735 */
2736 assign_op:
2737         EQUAL { $$ = ASSIGN_T; }
2738         ;
2739
2740
2741 lval: attr_id_ass {
2742                                         lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2743                                         if (!lval_tmp) {
2744                                                 yyerror("Not enough memory");
2745                                                 YYABORT;
2746                                         }
2747                                         lval_tmp->type=LV_AVP; lval_tmp->lv.avps=*$1;
2748                                         pkg_free($1); /* free the avp spec we just copied */
2749                                         $$=lval_tmp;
2750                                 }
2751         | pvar        {
2752                                         if (!pv_is_w($1))
2753                                                 yyerror("read only pvar in assignment left side");
2754                                         if ($1->trans!=0)
2755                                                 yyerror("pvar with transformations in assignment"
2756                                                                 " left side");
2757                                         lval_tmp=pkg_malloc(sizeof(*lval_tmp));
2758                                         if (!lval_tmp) {
2759                                                 yyerror("Not enough memory");
2760                                                 YYABORT;
2761                                         }
2762                                         lval_tmp->type=LV_PVAR; lval_tmp->lv.pvs=$1;
2763                                         $$=lval_tmp;
2764                                 }
2765         | avp_pvar    {
2766                                         if (($1)->type==LV_PVAR){
2767                                                 if (!pv_is_w($1->lv.pvs))
2768                                                         yyerror("read only pvar in assignment left side");
2769                                                 if ($1->lv.pvs->trans!=0)
2770                                                         yyerror("pvar with transformations in assignment"
2771                                                                         " left side");
2772                                         }
2773                                         $$=$1;
2774                                 }
2775         ;
2776
2777 rval: intno                     {$$=mk_rve_rval(RV_INT, (void*)$1); }
2778         | STRING                        {       s_tmp.s=$1; s_tmp.len=strlen($1);
2779                                                         $$=mk_rve_rval(RV_STR, &s_tmp); }
2780         | attr_id_any           {$$=mk_rve_rval(RV_AVP, $1); pkg_free($1); }
2781         | pvar                          {$$=mk_rve_rval(RV_PVAR, $1); }
2782         | avp_pvar                      {
2783                                                         switch($1->type){
2784                                                                 case LV_AVP:
2785                                                                         $$=mk_rve_rval(RV_AVP, &$1->lv.avps);
2786                                                                         break;
2787                                                                 case LV_PVAR:
2788                                                                         $$=mk_rve_rval(RV_PVAR, $1->lv.pvs);
2789                                                                         break;
2790                                                                 default:
2791                                                                         yyerror("BUG: invalid lvalue type ");
2792                                                                         YYABORT;
2793                                                         }
2794                                                         pkg_free($1); /* not needed anymore */
2795                                                 }
2796         | select_id                     {$$=mk_rve_rval(RV_SEL, $1); pkg_free($1); }
2797         | fcmd                          {$$=mk_rve_rval(RV_ACTION_ST, $1); }
2798         | exp_elem { $$=mk_rve_rval(RV_BEXPR, $1); }
2799         | LBRACE actions RBRACE {$$=mk_rve_rval(RV_ACTION_ST, $2); }
2800         | LBRACE error RBRACE   { $$=0; yyerror("bad command block"); }
2801         | LPAREN assign_action RPAREN   {$$=mk_rve_rval(RV_ACTION_ST, $2); }
2802         | LPAREN error RPAREN   { $$=0; yyerror("bad expression"); }
2803         ;
2804
2805
2806 rve_un_op: NOT  { $$=RVE_LNOT_OP; }
2807                 |  BIN_NOT      { $$=RVE_BNOT_OP; }
2808                 |  MINUS %prec UNARY    { $$=RVE_UMINUS_OP; }
2809                 /* TODO: RVE_BOOL_OP, RVE_NOT_OP? */
2810         ;
2811
2812 /*
2813 rve_op:         PLUS            { $$=RVE_PLUS_OP; }
2814                 |       MINUS           { $$=RVE_MINUS_OP; }
2815                 |       STAR            { $$=RVE_MUL_OP; }
2816                 |       SLASH           { $$=RVE_DIV_OP; }
2817                 |       MODULO          { $$=RVE_MOD_OP; }
2818         ;
2819 */
2820
2821 rval_expr: rval                                         { $$=$1;
2822                                                                                 if ($$==0){
2823                                                                                         /*yyerror("out of memory\n");*/
2824                                                                                         YYERROR;
2825                                                                                 }
2826                                                                         }
2827                 | rve_un_op rval_expr %prec UNARY       {$$=mk_rve1($1, $2); }
2828                 | INTCAST rval_expr                             {$$=mk_rve1(RVE_INT_OP, $2); }
2829                 | STRCAST rval_expr                             {$$=mk_rve1(RVE_STR_OP, $2); }
2830                 | rval_expr PLUS rval_expr              {$$=mk_rve2(RVE_PLUS_OP, $1, $3); }
2831                 | rval_expr MINUS rval_expr             {$$=mk_rve2(RVE_MINUS_OP, $1, $3); }
2832                 | rval_expr STAR rval_expr              {$$=mk_rve2(RVE_MUL_OP, $1, $3); }
2833                 | rval_expr SLASH rval_expr             {$$=mk_rve2(RVE_DIV_OP, $1, $3); }
2834                 | rval_expr MODULO rval_expr    {$$=mk_rve2(RVE_MOD_OP, $1, $3); }
2835                 | rval_expr BIN_OR rval_expr    {$$=mk_rve2(RVE_BOR_OP, $1,  $3); }
2836                 | rval_expr BIN_AND rval_expr   {$$=mk_rve2(RVE_BAND_OP, $1,  $3);}
2837                 | rval_expr BIN_XOR rval_expr   {$$=mk_rve2(RVE_BXOR_OP, $1,  $3);}
2838                 | rval_expr BIN_LSHIFT rval_expr {$$=mk_rve2(RVE_BLSHIFT_OP, $1,  $3);}
2839                 | rval_expr BIN_RSHIFT rval_expr {$$=mk_rve2(RVE_BRSHIFT_OP, $1,  $3);}
2840                 | rval_expr rve_cmpop rval_expr %prec GT { $$=mk_rve2( $2, $1, $3);}
2841                 | rval_expr rve_equalop rval_expr %prec EQUAL_T {
2842                         /* comparing with $null => treat as defined or !defined */
2843                         if($3->op==RVE_RVAL_OP && $3->left.rval.type==RV_PVAR
2844                                         && $3->left.rval.v.pvs.type==PVT_NULL) {
2845                                 if($2==RVE_DIFF_OP || $2==RVE_IDIFF_OP
2846                                                 || $2==RVE_STRDIFF_OP) {
2847                                         DBG("comparison with $null switched to notdefined operator\n");
2848                                         $$=mk_rve1(RVE_DEFINED_OP, $1);
2849                                 } else {
2850                                         DBG("comparison with $null switched to defined operator\n");
2851                                         $$=mk_rve1(RVE_NOTDEFINED_OP, $1);
2852                                 }
2853                                 /* free rve struct for $null */
2854                                 rve_destroy($3);
2855                         } else {
2856                                 $$=mk_rve2($2, $1, $3);
2857                         }
2858                 }
2859                 | rval_expr LOG_AND rval_expr   { $$=mk_rve2(RVE_LAND_OP, $1, $3);}
2860                 | rval_expr LOG_OR rval_expr    { $$=mk_rve2(RVE_LOR_OP, $1, $3);}
2861                 | LPAREN rval_expr RPAREN               { $$=$2;}
2862                 | STRLEN LPAREN rval_expr RPAREN { $$=mk_rve1(RVE_STRLEN_OP, $3);}
2863                 | STREMPTY LPAREN rval_expr RPAREN {$$=mk_rve1(RVE_STREMPTY_OP, $3);}
2864                 | DEFINED rval_expr                             { $$=mk_rve1(RVE_DEFINED_OP, $2);}
2865                 | rve_un_op error %prec UNARY           { $$=0; yyerror("bad expression"); }
2866                 | INTCAST error                                 { $$=0; yyerror("bad expression"); }
2867                 | STRCAST error                                 { $$=0; yyerror("bad expression"); }
2868                 | rval_expr PLUS error                  { $$=0; yyerror("bad expression"); }
2869                 | rval_expr MINUS error                 { $$=0; yyerror("bad expression"); }
2870                 | rval_expr STAR error                  { $$=0; yyerror("bad expression"); }
2871                 | rval_expr SLASH error                 { $$=0; yyerror("bad expression"); }
2872                 | rval_expr MODULO error                        { $$=0; yyerror("bad expression"); }
2873                 | rval_expr BIN_OR error                { $$=0; yyerror("bad expression"); }
2874                 | rval_expr BIN_AND error               { $$=0; yyerror("bad expression"); }
2875                 | rval_expr rve_cmpop error %prec GT
2876                         { $$=0; yyerror("bad expression"); }
2877                 | rval_expr rve_equalop error %prec EQUAL_T
2878                         { $$=0; yyerror("bad expression"); }
2879                 | rval_expr LOG_AND error               { $$=0; yyerror("bad expression"); }
2880                 | rval_expr LOG_OR error                { $$=0; yyerror("bad expression"); }
2881                 | STRLEN LPAREN error RPAREN    { $$=0; yyerror("bad expression"); }
2882                 | STREMPTY LPAREN error RPAREN  { $$=0; yyerror("bad expression"); }
2883                 | DEFINED error                                 { $$=0; yyerror("bad expression"); }
2884                 ;
2885
2886 assign_action: lval assign_op  rval_expr        { $$=mk_action($2, 2, LVAL_ST, $1,
2887                                                                                                                           RVE_ST, $3);
2888                                                                                         set_cfg_pos($$);
2889                                                                                 }
2890         ;
2891
2892 /*
2893 assign_action:
2894         attr_id_ass assign_op STRING  { $$=mk_action($2, 2, AVP_ST, $1, STRING_ST, $3); }
2895         | attr_id_ass assign_op NUMBER  { $$=mk_action($2, 2, AVP_ST, $1, NUMBER_ST, (void*)$3); }
2896         | attr_id_ass assign_op fcmd    { $$=mk_action($2, 2, AVP_ST, $1, ACTION_ST, $3); }
2897         | attr_id_ass assign_op attr_id_any { $$=mk_action($2, 2, AVP_ST, $1, AVP_ST, $3); }
2898         | attr_id_ass assign_op select_id { $$=mk_action($2, 2, AVP_ST, (void*)$1, SELECT_ST, (void*)$3); }
2899         | attr_id_ass assign_op LPAREN exp RPAREN { $$ = mk_action($2, 2, AVP_ST, $1, EXPR_ST, $4); }
2900         ;
2901 */
2902
2903 avpflag_oper:
2904         SETAVPFLAG { $$ = 1; }
2905         | RESETAVPFLAG { $$ = 0; }
2906         | ISAVPFLAGSET { $$ = -1; }
2907         ;
2908 cmd:
2909         FORWARD LPAREN RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
2910         | FORWARD LPAREN host RPAREN    { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2911         | FORWARD LPAREN STRING RPAREN  { $$=mk_action( FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2912         | FORWARD LPAREN ip RPAREN      { $$=mk_action( FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
2913         | FORWARD LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2914         | FORWARD LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2915         | FORWARD LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2916         | FORWARD LPAREN URIHOST COMMA URIPORT RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
2917         | FORWARD LPAREN URIHOST COMMA NUMBER RPAREN {$$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2918         | FORWARD LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
2919         | FORWARD error { $$=0; yyerror("missing '(' or ')' ?"); }
2920         | FORWARD LPAREN error RPAREN { $$=0; yyerror("bad forward argument"); }
2921         | FORWARD_UDP LPAREN host RPAREN        { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2922         | FORWARD_UDP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2923         | FORWARD_UDP LPAREN ip RPAREN  { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
2924         | FORWARD_UDP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2925         | FORWARD_UDP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_UDP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2926         | FORWARD_UDP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2927         | FORWARD_UDP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
2928         | FORWARD_UDP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2929         | FORWARD_UDP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_UDP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
2930         | FORWARD_UDP error { $$=0; yyerror("missing '(' or ')' ?"); }
2931         | FORWARD_UDP LPAREN error RPAREN { $$=0; yyerror("bad forward_udp argument"); }
2932         | FORWARD_TCP LPAREN host RPAREN        { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2933         | FORWARD_TCP LPAREN STRING RPAREN      { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$); }
2934         | FORWARD_TCP LPAREN ip RPAREN  { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$); }
2935         | FORWARD_TCP LPAREN host COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2936         | FORWARD_TCP LPAREN STRING COMMA NUMBER RPAREN {$$=mk_action(FORWARD_TCP_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2937         | FORWARD_TCP LPAREN ip COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2938         | FORWARD_TCP LPAREN URIHOST COMMA URIPORT RPAREN {$$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$); }
2939         | FORWARD_TCP LPAREN URIHOST COMMA NUMBER RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$); }
2940         | FORWARD_TCP LPAREN URIHOST RPAREN { $$=mk_action(FORWARD_TCP_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$); }
2941         | FORWARD_TCP error { $$=0; yyerror("missing '(' or ')' ?"); }
2942         | FORWARD_TCP LPAREN error RPAREN { $$=0; yyerror("bad forward_tcp argument"); }
2943         | FORWARD_TLS LPAREN host RPAREN {
2944                 #ifdef USE_TLS
2945                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
2946                 #else
2947                         $$=0;
2948                         yyerror("tls support not compiled in");
2949                 #endif
2950         }
2951         | FORWARD_TLS LPAREN STRING RPAREN {
2952                 #ifdef USE_TLS
2953                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
2954                 #else
2955                         $$=0;
2956                         yyerror("tls support not compiled in");
2957                 #endif
2958         }
2959         | FORWARD_TLS LPAREN ip RPAREN  {
2960                 #ifdef USE_TLS
2961                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$);
2962                 #else
2963                         $$=0;
2964                         yyerror("tls support not compiled in");
2965                 #endif
2966         }
2967         | FORWARD_TLS LPAREN host COMMA NUMBER RPAREN {
2968                 #ifdef USE_TLS
2969                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
2970                 #else
2971                         $$=0;
2972                         yyerror("tls support not compiled in");
2973                 #endif
2974         }
2975         | FORWARD_TLS LPAREN STRING COMMA NUMBER RPAREN {
2976                 #ifdef USE_TLS
2977                         $$=mk_action(FORWARD_TLS_T, 2, STRING_ST, $3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
2978                 #else
2979                         $$=0;
2980                         yyerror("tls support not compiled in");
2981                 #endif
2982         }
2983         | FORWARD_TLS LPAREN ip COMMA NUMBER RPAREN {
2984                 #ifdef USE_TLS
2985                         $$=mk_action(FORWARD_TLS_T, 2, IP_ST, (void*)$3, NUMBER_ST, (void*)$5); set_cfg_pos($$);
2986                 #else
2987                         $$=0;
2988                         yyerror("tls support not compiled in");
2989                 #endif
2990                                         }
2991         | FORWARD_TLS LPAREN URIHOST COMMA URIPORT RPAREN {
2992                 #ifdef USE_TLS
2993                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, URIPORT_ST, 0); set_cfg_pos($$);
2994                 #else
2995                         $$=0;
2996                         yyerror("tls support not compiled in");
2997                 #endif
2998         }
2999         | FORWARD_TLS LPAREN URIHOST COMMA NUMBER RPAREN {
3000                 #ifdef USE_TLS
3001                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, (void*)$5); set_cfg_pos($$);
3002                 #else
3003                         $$=0;
3004                         yyerror("tls support not compiled in");
3005                 #endif
3006         }
3007         | FORWARD_TLS LPAREN URIHOST RPAREN {
3008                 #ifdef USE_TLS
3009                         $$=mk_action(FORWARD_TLS_T, 2, URIHOST_ST, 0, NUMBER_ST, 0); set_cfg_pos($$);
3010                 #else
3011                         $$=0;
3012                         yyerror("tls support not compiled in");
3013                 #endif
3014         }
3015         | FORWARD_TLS error { $$=0; yyerror("missing '(' or ')' ?"); }
3016         | FORWARD_TLS LPAREN error RPAREN { $$=0;
3017                                                                         yyerror("bad forward_tls argument"); }
3018         | FORWARD_SCTP LPAREN host RPAREN {
3019                 #ifdef USE_SCTP
3020                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
3021                 #else
3022                         $$=0;
3023                         yyerror("sctp support not compiled in");
3024                 #endif
3025         }
3026         | FORWARD_SCTP LPAREN STRING RPAREN {
3027                 #ifdef USE_SCTP
3028                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST, 0); set_cfg_pos($$);
3029                 #else
3030                         $$=0;
3031                         yyerror("sctp support not compiled in");
3032                 #endif
3033         }
3034         | FORWARD_SCTP LPAREN ip RPAREN {
3035                 #ifdef USE_SCTP
3036                         $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST, 0); set_cfg_pos($$);
3037                 #else
3038                         $$=0;
3039                         yyerror("sctp support not compiled in");
3040                 #endif
3041         }
3042         | FORWARD_SCTP LPAREN host COMMA NUMBER RPAREN {
3043                 #ifdef USE_SCTP
3044                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
3045                                                         (void*)$5); set_cfg_pos($$);
3046                 #else
3047                         $$=0;
3048                         yyerror("sctp support not compiled in");
3049                 #endif
3050         }
3051         | FORWARD_SCTP LPAREN STRING COMMA NUMBER RPAREN {
3052                 #ifdef USE_SCTP
3053                         $$=mk_action(FORWARD_SCTP_T, 2, STRING_ST, $3, NUMBER_ST,
3054                                                         (void*)$5); set_cfg_pos($$);
3055                 #else
3056                         $$=0;
3057                         yyerror("sctp support not compiled in");
3058                 #endif
3059         }
3060         | FORWARD_SCTP LPAREN ip COMMA NUMBER RPAREN {
3061                 #ifdef USE_SCTP
3062                         $$=mk_action(FORWARD_SCTP_T, 2, IP_ST, (void*)$3, NUMBER_ST,
3063                                                         (void*)$5); set_cfg_pos($$);
3064                 #else
3065             &n