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