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