/* * $Id$ * * cfg grammar * * Copyright (C) 2001-2003 FhG Fokus * * This file is part of ser, a free SIP server. * * ser is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version * * For a license to use the ser software under conditions * other than those described here, or to purchase support for this * software, please contact iptel.org by e-mail at the following addresses: * info@iptel.org * * ser is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * History: * --------- * 2003-01-29 src_port added (jiri) * 2003-01-23 mhomed added (jiri) * 2003-03-19 replaced all mallocs/frees with pkg_malloc/pkg_free (andrei) * 2003-03-19 Added support for route type in find_export (janakj) * 2003-03-20 Regex support in modparam (janakj) * 2003-04-01 added dst_port, proto , af (andrei) * 2003-04-05 s/reply_route/failure_route, onreply_route introduced (jiri) * 2003-04-12 added force_rport, chroot and wdir (andrei) * 2003-04-15 added tcp_children, disable_tcp (andrei) * 2003-04-22 strip_tail added (jiri) * 2003-07-03 tls* (disable, certificate, private_key, ca_list, verify, * require_certificate added (andrei) * 2003-07-06 more tls config. vars added: tls_method, tls_port_no (andrei) * 2003-10-02 added {,set_}advertised_{address,port} (andrei) * 2003-10-10 added <,>,<=,>=, != operators support * added msg:len (andrei) * 2003-10-11 if(){} doesn't require a ';' after it anymore (andrei) * 2003-10-13 added FIFO_DIR & proto:host:port listen/alias support (andrei) * 2003-10-24 converted to the new socket_info lists (andrei) * 2003-10-28 added tcp_accept_aliases (andrei) * 2003-11-20 added {tcp_connect, tcp_send, tls_*}_timeout (andrei) * 2004-03-30 added DISABLE_CORE and OPEN_FD_LIMIT (andrei) * 2004-04-29 added SOCK_MODE, SOCK_USER & SOCK_GROUP (andrei) * 2004-05-03 applied multicast support patch (MCAST_LOOPBACK) from janakj * added MCAST_TTL (andrei) * 2004-07-05 src_ip & dst_ip will detect ip addresses between quotes * (andrei) * 2004-10-19 added FROM_URI, TO_URI (andrei) * 2004-11-30 added force_send_socket (andrei) * 2005-07-08 added TCP_CON_LIFETIME, TCP_POLL_METHOD, TCP_MAX_CONNECTIONS * (andrei) * 2005-07-11 added DNS_RETR_TIME, DNS_RETR_NO, DNS_SERVERS_NO, DNS_USE_SEARCH, * DNS_TRY_IPV6 (andrei) * 2005-07-12 default onreply route added (andrei) * 2005-11-16 fixed if (cond) cmd; (andrei) * 2005-12-11 added onsend_route support, fcmd (filtered cmd), * snd_{ip,port,proto,af}, to_{ip,proto} (andrei) * 2005-12-19 select framework (mma) * 2006-01-06 AVP index support (mma) * 2005-01-07 optional semicolon in statement, PARAM_STR&PARAM_STRING * 2006-02-02 named flags support (andrei) * 2006-02-06 named routes support (andrei) * 2006-05-30 avp flags (tma) * 2006-09-11 added dns cache (use, flags, ttls, mem ,gc) & dst blacklist * options (andrei) * 2006-10-13 added STUN_ALLOW_STUN, STUN_ALLOW_FP, STUN_REFRESH_INTERVAL * (vlada) * 2007-02-09 separated command needed for tls-in-core and for tls in general * (andrei) * 2007-06-07 added SHM_FORCE_ALLOC, MLOCK_PAGES, REAL_TIME, RT_PRIO, * RT_POLICY, RT_TIMER1_PRIO, RT_TIMER1_POLICY, RT_TIMER2_PRIO, * RT_TIMER2_POLICY (andrei) * 2007-06-16 added DDNS_SRV_LB, DNS_TRY_NAPTR (andrei) * 2007-09-10 introduced phone2tel option which allows NOT to consider * user=phone URIs as TEL URIs (jiri) * 2007-10-10 added DNS_SEARCH_FMATCH (mma) * 2007-11-28 added TCP_OPT_{FD_CACHE, DEFER_ACCEPT, DELAYED_ACK, SYNCNT, * LINGER2, KEEPALIVE, KEEPIDLE, KEEPINTVL, KEEPCNT} (andrei) * 2008-01-24 added cfg_var definition (Miklos) * 2008-11-18 support for variable parameter module functions (andrei) * 2007-12-03 support for generalised lvalues and rvalues: * lval=rval_expr, where lval=avp|pvar (andrei) * 2007-12-06 expression are now evaluated in terms of rvalues; * NUMBER is now always positive; cleanup (andrei) * 2009-01-26 case/switch() support (andrei) * 2009-03-10 added SET_USERPHONE action (Miklos) * 2009-05-04 switched if to rval_expr (andrei) * 2010-01-10 init shm on first mod_param or route block; * added SHM_MEM_SZ (andrei) * 2010-02-17 added blacklist imask (DST_BLST_*_IMASK) support (andrei) */ %expect 6 %{ #include #include #include #include #include #include #include #include #include #include #include "route_struct.h" #include "globals.h" #ifdef SHM_MEM #include "shm_init.h" #endif /* SHM_MEM */ #include "route.h" #include "switch.h" #include "dprint.h" #include "sr_module.h" #include "modparam.h" #include "ip_addr.h" #include "resolve.h" #include "socket_info.h" #include "name_alias.h" #include "ut.h" #include "dset.h" #include "select.h" #include "flags.h" #include "tcp_init.h" #include "tcp_options.h" #include "sctp_options.h" #include "pvar.h" #include "lvalue.h" #include "rvalue.h" #include "sr_compat.h" #include "msg_translator.h" #include "ppcfg.h" #include "pvapi.h" #include "config.h" #include "cfg_core.h" #include "cfg/cfg.h" #ifdef CORE_TLS #include "tls/tls_config.h" #endif #include "timer_ticks.h" #ifdef DEBUG_DMALLOC #include #endif /* hack to avoid alloca usage in the generated C file (needed for compiler with no built in alloca, like icc*/ #undef _ALLOCA_H #define onsend_check(s) \ do{\ if (rt!=ONSEND_ROUTE) yyerror( s " allowed only in onsend_routes");\ }while(0) #ifdef USE_IPV6 #define IF_AUTO_BIND_IPV6(x) x #else #define IF_AUTO_BIND_IPV6(x) warn("IPV6 support not compiled"); #endif #ifdef USE_DNS_CACHE #define IF_DNS_CACHE(x) x #else #define IF_DNS_CACHE(x) warn("dns cache support not compiled in") #endif #ifdef USE_DNS_FAILOVER #define IF_DNS_FAILOVER(x) x #else #define IF_DNS_FAILOVER(x) warn("dns failover support not compiled in") #endif #ifdef USE_NAPTR #define IF_NAPTR(x) x #else #define IF_NAPTR(x) warn("dns naptr support not compiled in") #endif #ifdef USE_DST_BLACKLIST #define IF_DST_BLACKLIST(x) x #else #define IF_DST_BLACKLIST(x) warn("dst blacklist support not compiled in") #endif #ifdef USE_STUN #define IF_STUN(x) x #else #define IF_STUN(x) warn("stun support not compiled in") #endif #ifdef USE_SCTP #define IF_SCTP(x) x #else #define IF_SCTP(x) warn("sctp support not compiled in") #endif #ifdef USE_RAW_SOCKS #define IF_RAW_SOCKS(x) x #else #define IF_RAW_SOCKS(x) warn("raw socket support not compiled in") #endif extern int yylex(); /* safer then using yytext which can be array or pointer */ extern char* yy_number_str; static void yyerror(char* s, ...); static void yyerror_at(struct cfg_pos* pos, char* s, ...); static char* tmp; static int i_tmp; static unsigned u_tmp; static struct socket_id* lst_tmp; static struct name_lst* nl_tmp; static int rt; /* Type of route block for find_export */ static str* str_tmp; static str s_tmp; static struct ip_addr* ip_tmp; static struct avp_spec* s_attr; static select_t sel; static select_t* sel_ptr; static pv_spec_t* pv_spec; static struct action *mod_func_action; static struct lvalue* lval_tmp; static struct rvalue* rval_tmp; static void warn(char* s, ...); static void warn_at(struct cfg_pos* pos, char* s, ...); static void get_cpos(struct cfg_pos* pos); static struct rval_expr* mk_rve_rval(enum rval_type, void* v); static struct rval_expr* mk_rve1(enum rval_expr_op op, struct rval_expr* rve1); static struct rval_expr* mk_rve2(enum rval_expr_op op, struct rval_expr* rve1, struct rval_expr* rve2); static int rval_expr_int_check(struct rval_expr *rve); static int warn_ct_rve(struct rval_expr *rve, char* name); static struct socket_id* mk_listen_id(char*, int, int); static struct name_lst* mk_name_lst(char* name, int flags); static struct socket_id* mk_listen_id2(struct name_lst*, int, int); static void free_name_lst(struct name_lst* lst); static void free_socket_id_lst(struct socket_id* i); static struct case_stms* mk_case_stm(struct rval_expr* ct, int is_re, struct action* a, int* err); static int case_check_type(struct case_stms* stms); static int case_check_default(struct case_stms* stms); static int mod_f_params_pre_fixup(struct action* a); static void free_mod_func_action(struct action* a); extern int line; extern int column; extern int startcolumn; extern int startline; extern char *finame; #define set_cfg_pos(x) \ do{\ if(x) {\ (x)->cline = line;\ (x)->cfile = (finame!=0)?finame:((cfg_file!=0)?cfg_file:"default");\ }\ }while(0) %} %union { long intval; unsigned long uval; char* strval; struct expr* expr; struct action* action; struct case_stms* case_stms; struct net* ipnet; struct ip_addr* ipaddr; struct socket_id* sockid; struct name_lst* name_l; struct avp_spec* attr; struct _pv_spec* pvar; struct lvalue* lval; struct rvalue* rval; struct rval_expr* rv_expr; select_t* select; } /* terminals */ /* keywords */ %token FORWARD %token FORWARD_TCP %token FORWARD_TLS %token FORWARD_SCTP %token FORWARD_UDP %token EXIT %token DROP %token RETURN %token BREAK %token LOG_TOK %token ERROR %token ROUTE %token ROUTE_REQUEST %token ROUTE_FAILURE %token ROUTE_ONREPLY %token ROUTE_REPLY %token ROUTE_BRANCH %token ROUTE_SEND %token ROUTE_EVENT %token EXEC %token SET_HOST %token SET_HOSTPORT %token SET_HOSTPORTTRANS %token PREFIX %token STRIP %token STRIP_TAIL %token SET_USERPHONE %token APPEND_BRANCH %token REMOVE_BRANCH %token CLEAR_BRANCHES %token SET_USER %token SET_USERPASS %token SET_PORT %token SET_URI %token REVERT_URI %token FORCE_RPORT %token ADD_LOCAL_RPORT %token FORCE_TCP_ALIAS %token UDP_MTU %token UDP_MTU_TRY_PROTO %token UDP4_RAW %token UDP4_RAW_MTU %token UDP4_RAW_TTL %token IF %token ELSE %token SET_ADV_ADDRESS %token SET_ADV_PORT %token FORCE_SEND_SOCKET %token SET_FWD_NO_CONNECT %token SET_RPL_NO_CONNECT %token SET_FWD_CLOSE %token SET_RPL_CLOSE %token SWITCH %token CASE %token DEFAULT %token WHILE %token CFG_SELECT %token CFG_RESET %token URIHOST %token URIPORT %token MAX_LEN %token SETFLAG %token RESETFLAG %token ISFLAGSET %token SETAVPFLAG %token RESETAVPFLAG %token ISAVPFLAGSET %token METHOD %token URI %token FROM_URI %token TO_URI %token SRCIP %token SRCPORT %token DSTIP %token DSTPORT %token TOIP %token TOPORT %token SNDIP %token SNDPORT %token SNDPROTO %token SNDAF %token PROTO %token AF %token MYSELF %token MSGLEN %token UDP %token TCP %token TLS %token SCTP /* config vars. */ %token DEBUG_V %token FORK %token FORK_DELAY %token LOGSTDERROR %token LOGFACILITY %token LOGNAME %token LISTEN %token ADVERTISE %token ALIAS %token SR_AUTO_ALIASES %token DNS %token REV_DNS %token DNS_TRY_IPV6 %token DNS_TRY_NAPTR %token DNS_SRV_LB %token DNS_UDP_PREF %token DNS_TCP_PREF %token DNS_TLS_PREF %token DNS_SCTP_PREF %token DNS_RETR_TIME %token DNS_RETR_NO %token DNS_SERVERS_NO %token DNS_USE_SEARCH %token DNS_SEARCH_FMATCH %token DNS_CACHE_INIT %token DNS_USE_CACHE %token DNS_USE_FAILOVER %token DNS_CACHE_FLAGS %token DNS_CACHE_NEG_TTL %token DNS_CACHE_MIN_TTL %token DNS_CACHE_MAX_TTL %token DNS_CACHE_MEM %token DNS_CACHE_GC_INT %token DNS_CACHE_DEL_NONEXP /* ipv6 auto bind */ %token AUTO_BIND_IPV6 /*blacklist*/ %token DST_BLST_INIT %token USE_DST_BLST %token DST_BLST_MEM %token DST_BLST_TTL %token DST_BLST_GC_INT %token DST_BLST_UDP_IMASK %token DST_BLST_TCP_IMASK %token DST_BLST_TLS_IMASK %token DST_BLST_SCTP_IMASK %token PORT %token STAT %token CHILDREN %token SOCKET_WORKERS %token CHECK_VIA %token PHONE2TEL %token SYN_BRANCH %token MEMLOG %token MEMDBG %token MEMSUM %token MEMSAFETY %token MEMJOIN %token CORELOG %token SIP_WARNING %token SERVER_SIGNATURE %token SERVER_HEADER %token USER_AGENT_HEADER %token REPLY_TO_VIA %token LOADMODULE %token LOADPATH %token MODPARAM %token MAXBUFFER %token SQL_BUFFER_SIZE %token USER %token GROUP %token CHROOT %token WDIR %token MHOMED %token DISABLE_TCP %token TCP_ACCEPT_ALIASES %token TCP_CHILDREN %token TCP_CONNECT_TIMEOUT %token TCP_SEND_TIMEOUT %token TCP_CON_LIFETIME %token TCP_POLL_METHOD %token TCP_MAX_CONNECTIONS %token TLS_MAX_CONNECTIONS %token TCP_NO_CONNECT %token TCP_SOURCE_IPV4 %token TCP_SOURCE_IPV6 %token TCP_OPT_FD_CACHE %token TCP_OPT_BUF_WRITE %token TCP_OPT_CONN_WQ_MAX %token TCP_OPT_WQ_MAX %token TCP_OPT_RD_BUF %token TCP_OPT_WQ_BLK %token TCP_OPT_DEFER_ACCEPT %token TCP_OPT_DELAYED_ACK %token TCP_OPT_SYNCNT %token TCP_OPT_LINGER2 %token TCP_OPT_KEEPALIVE %token TCP_OPT_KEEPIDLE %token TCP_OPT_KEEPINTVL %token TCP_OPT_KEEPCNT %token TCP_OPT_CRLF_PING %token TCP_OPT_ACCEPT_NO_CL %token TCP_CLONE_RCVBUF %token DISABLE_TLS %token ENABLE_TLS %token TLSLOG %token TLS_PORT_NO %token TLS_METHOD %token TLS_HANDSHAKE_TIMEOUT %token TLS_SEND_TIMEOUT %token SSLv23 %token SSLv2 %token SSLv3 %token TLSv1 %token TLS_VERIFY %token TLS_REQUIRE_CERTIFICATE %token TLS_CERTIFICATE %token TLS_PRIVATE_KEY %token TLS_CA_LIST %token DISABLE_SCTP %token ENABLE_SCTP %token SCTP_CHILDREN %token SCTP_SOCKET_RCVBUF %token SCTP_SOCKET_SNDBUF %token SCTP_AUTOCLOSE %token SCTP_SEND_TTL %token SCTP_SEND_RETRIES %token SCTP_ASSOC_TRACKING %token SCTP_ASSOC_REUSE %token SCTP_MAX_ASSOCS %token SCTP_SRTO_INITIAL %token SCTP_SRTO_MAX %token SCTP_SRTO_MIN %token SCTP_ASOCMAXRXT %token SCTP_INIT_MAX_ATTEMPTS %token SCTP_INIT_MAX_TIMEO %token SCTP_HBINTERVAL %token SCTP_PATHMAXRXT %token SCTP_SACK_DELAY %token SCTP_SACK_FREQ %token SCTP_MAX_BURST %token ADVERTISED_ADDRESS %token ADVERTISED_PORT %token DISABLE_CORE %token OPEN_FD_LIMIT %token SHM_MEM_SZ %token SHM_FORCE_ALLOC %token MLOCK_PAGES %token REAL_TIME %token RT_PRIO %token RT_POLICY %token RT_TIMER1_PRIO %token RT_TIMER1_POLICY %token RT_TIMER2_PRIO %token RT_TIMER2_POLICY %token MCAST_LOOPBACK %token MCAST_TTL %token TOS %token PMTU_DISCOVERY %token KILL_TIMEOUT %token MAX_WLOOPS %token PVBUFSIZE %token PVBUFSLOTS %token HTTP_REPLY_HACK %token CFG_DESCRIPTION %token SERVER_ID %token LATENCY_LOG %token LATENCY_LIMIT_DB %token LATENCY_LIMIT_ACTION %token MSG_TIME %token FLAGS_DECL %token AVPFLAGS_DECL %token ATTR_MARK %token SELECT_MARK %token ATTR_FROM %token ATTR_TO %token ATTR_FROMURI %token ATTR_TOURI %token ATTR_FROMUSER %token ATTR_TOUSER %token ATTR_FROMDOMAIN %token ATTR_TODOMAIN %token ATTR_GLOBAL %token ADDEQ %token STUN_REFRESH_INTERVAL %token STUN_ALLOW_STUN %token STUN_ALLOW_FP /*pre-processor*/ %token SUBST %token SUBSTDEF %token SUBSTDEFS /* operators, C like precedence */ %right EQUAL %left LOG_OR %left LOG_AND %left BIN_OR %left BIN_AND %left BIN_XOR %left BIN_LSHIFT %left BIN_RSHIFT %left EQUAL_T DIFF MATCH INTEQ INTDIFF STREQ STRDIFF %left GT LT GTE LTE %left PLUS MINUS %left STAR SLASH MODULO %right NOT UNARY BIN_NOT %right DEFINED %right INTCAST STRCAST %left DOT /* no precedence, they use () */ %token STRLEN %token STREMPTY /* values */ %token NUMBER %token ID %token NUM_ID %token STRING %token IPV6ADDR %token PVAR /* not clear yet if this is an avp or pvar */ %token AVP_OR_PVAR %token EVENT_RT_NAME /* other */ %token COMMA %token SEMICOLON %token RPAREN %token LPAREN %token LBRACE %token RBRACE %token LBRACK %token RBRACK %token CR %token COLON /*non-terminals */ /*%type exp */ %type exp_elem %type intno eint_op eint_op_onsend %type eip_op eip_op_onsend %type action actions cmd fcmd if_cmd stm /*exp_stm*/ assign_action %type switch_cmd while_cmd ret_cmd %type single_case case_stms %type ipv4 ipv6 ipv6addr ip %type ipnet %type host host_or_if host_if_id %type listen_id %type listen_id_lst %type listen_id2 %type id_lst %type phostport %type listen_phostport %type proto port %type equalop strop cmpop rve_cmpop rve_equalop %type uri_type %type attr_id %type attr_id_num_idx %type attr_id_no_idx %type attr_id_ass /*%type attr_id_val*/ %type attr_id_any %type attr_id_any_str %type pvar %type lval %type rval rval_expr ct_rval %type avp_pvar /* %type class_id */ %type assign_op %type