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