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