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