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