route.c File Reference

SIP routing engine. More...

#include <stdlib.h>
#include <sys/types.h>
#include <regex.h>
#include <netdb.h>
#include <string.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "route.h"
#include "forward.h"
#include "dprint.h"
#include "proxy.h"
#include "action.h"
#include "sr_module.h"
#include "ip_addr.h"
#include "resolve.h"
#include "socket_info.h"
#include "blacklists.h"
#include "parser/parse_uri.h"
#include "parser/parse_from.h"
#include "parser/parse_to.h"
#include "mem/mem.h"

Include dependency graph for route.c:

Go to the source code of this file.

Functions

int add_actions (struct action *a, struct action **head)
 Add actions to the list.
static int check_actions (struct action *a, int r_type)
 Check actions on list.
int check_rls (void)
 Check all routing tables for compatiblity between route types and called module functions.
static int check_self_op (int op, str *s, unsigned short p)
 check_self wrapper -- it checks also for the operation
static int comp_ip (struct sip_msg *msg, int op, struct ip_addr *ip, operand_t *opd)
 eval_elem helping function, compare a IP address
static int comp_n2n (int op, int n1, int n2)
 Compare two numbers.
static int comp_no (int port, void *param, int op, int subtype)
 Compare port number to parameter.
static int comp_s2r (int op, str *s1, regex_t *re)
 Compare str to regexp.
static int comp_s2s (int op, str *s1, str *s2)
 Compare str to str.
static int comp_scriptvar (struct sip_msg *msg, int op, operand_t *left, operand_t *right)
 Compare two script variables.
static int comp_str (char *str, void *param, int op, int subtype)
 eval_elem helping function, compare a string value
static int comp_strval (struct sip_msg *msg, int op, str *ival, operand_t *opd)
 eval_elem helping function, compare a str value
static int eval_elem (struct expr *e, struct sip_msg *msg, pv_value_t *val)
 Evaluate expression element.
int eval_expr (struct expr *e, struct sip_msg *msg, pv_value_t *val)
 Evaluate expression.
static int fix_actions (struct action *a)
 Adds the proxies in the proxy list & resolves the hostnames.
static int fix_expr (struct expr *exp)
 Traverses an expression tree and compiles the REs where necessary.
int fix_rls (void)
 Fixes all action tables.
void init_route_lists (void)
 Initialize routing lists.
void print_rl (void)
 Debug function, prints main routing table.
void push (struct action *a, struct action **head)
 Adds an action list to head.

Variables

struct actionbranch_rlist [BRANCH_RT_NO]
struct actionerror_rlist
struct actionfailure_rlist [FAILURE_RT_NO]
struct actiononreply_rlist [ONREPLY_RT_NO]
static int rcheck_stack [RT_NO]
static int rcheck_stack_p = 0
static int rcheck_status = 0
int return_code
struct actionrlist [RT_NO]
int route_type = REQUEST_ROUTE


Detailed Description

SIP routing engine.

Definition in file route.c.


Function Documentation

int add_actions ( struct action a,
struct action **  head 
)

Add actions to the list.

Parameters:
a action
head head of action list
Returns:
0 on success, negative on failure

Definition at line 1533 of file route.c.

References fix_actions(), LM_DBG, and push().

static int check_actions ( struct action a,
int  r_type 
) [static]

Check actions on list.

Parameters:
a action list
r_type routing type
Returns:
0 on success, -1 on failure

Definition at line 1610 of file route.c.

References action_elem_::data, action::elem, cmd_export_::flags, IF_T, LM_CRIT, LM_ERR, MODULE_T, cmd_export_::name, action::next, action_elem_::number, rcheck_stack, rcheck_stack_p, rcheck_status, ROUTE_T, RT_NO, SWITCH_T, action::type, action_elem_::u, and WHILE_T.

Referenced by check_rls().

int check_rls ( void   ) 

Check all routing tables for compatiblity between route types and called module functions.

Returns:
0 if ok , <0 on error

Definition at line 1681 of file route.c.

References BRANCH_ROUTE, BRANCH_RT_NO, check_actions(), ERROR_ROUTE, FAILURE_ROUTE, FAILURE_RT_NO, LM_ERR, LOCAL_ROUTE, ONREPLY_ROUTE, ONREPLY_RT_NO, rcheck_status, and REQUEST_ROUTE.

Referenced by main().

static int check_self_op ( int  op,
str s,
unsigned short  p 
) [inline, static]

check_self wrapper -- it checks also for the operation

Parameters:
op compare operation
s host
p port
Returns:
result from check_self on success, -1 on failure

Definition at line 651 of file route.c.

References check_self(), DIFF_OP, EQUAL_OP, and LM_CRIT.

Referenced by comp_ip(), and eval_elem().

static int comp_ip ( struct sip_msg msg,
int  op,
struct ip_addr ip,
operand_t opd 
) [inline, static]

eval_elem helping function, compare a IP address

Parameters:
msg SIP message
op compare operation
ip IP address
opd operand type and data
Returns:
1 if address and operand match, 0 if they not match, -1 on failure

Definition at line 677 of file route.c.

References ip_addr::addr, ip_addr::af, check_self_op(), comp_str(), operand::operand_val::data, DIFF_OP, DO_REV_DNS, EQUAL_OP, ip_addr2a(), _str::len, ip_addr::len, LM_CRIT, LM_DBG, MATCH_OP, matchnet(), MYSELF_ST, NET_ST, print_ip(), RE_ST, received_dns, resolvehost(), rev_resolvehost, _str::s, STRING_ST, operand::type, ip_addr::u, and operand::v.

Referenced by eval_elem().

static int comp_n2n ( int  op,
int  n1,
int  n2 
) [inline, static]

Compare two numbers.

Parameters:
op compare operation
n1 first number
n2 second number
Returns:
1 if both numbers match, 0 if they not match, -1 on failure

Definition at line 900 of file route.c.

References DIFF_OP, EQUAL_OP, GT_OP, GTE_OP, LM_CRIT, LT_OP, LTE_OP, MATCH_OP, MATCHD_OP, NOTMATCH_OP, and NOTMATCHD_OP.

Referenced by comp_scriptvar().

static int comp_no ( int  port,
void *  param,
int  op,
int  subtype 
) [inline, static]

Compare port number to parameter.

Parameters:
port port number
param parameter
op compare operation
subtype type of the parameter, should be NUMBER_ST
Returns:
1 if port number and param match, 0 if they not match, negative on failure

Definition at line 467 of file route.c.

References DIFF_OP, E_BUG, EQUAL_OP, GT_OP, GTE_OP, LM_CRIT, LT_OP, LTE_OP, and NUMBER_ST.

Referenced by eval_elem().

static int comp_s2r ( int  op,
str s1,
regex_t *  re 
) [inline, static]

Compare str to regexp.

Parameters:
op compare operation
s1 string
re reqular expression
Returns:
1 if str and regexp match, 0 if they not match, -1 on error

Definition at line 772 of file route.c.

References _str::len, LM_CRIT, MATCH_OP, NOTMATCH_OP, NULL, and _str::s.

Referenced by comp_scriptvar().

static int comp_s2s ( int  op,
str s1,
str s2 
) [inline, static]

Compare str to str.

Parameters:
op compare operation
s1 first string
s2 second string
Returns:
1 if both strings match, 0 if they not match, -1 on failure

Definition at line 805 of file route.c.

References DIFF_OP, EQUAL_OP, GT_OP, GTE_OP, _str::len, LM_CRIT, LT_OP, LTE_OP, MATCHD_OP, NOTMATCHD_OP, NULL, pkg_free, pkg_malloc, and _str::s.

Referenced by comp_scriptvar().

static int comp_scriptvar ( struct sip_msg msg,
int  op,
operand_t left,
operand_t right 
) [inline, static]

Compare two script variables.

Parameters:
msg SIP message
op compare operation
left left type and data
right right type and data
Returns:
1 if both variables match, 0 if they not match, -1 on failure

Definition at line 946 of file route.c.

References comp_n2n(), comp_s2r(), comp_s2s(), DIFF_OP, EQUAL_OP, operand::operand_val::expr, _pv_value::flags, _str::len, LM_CRIT, LM_DBG, MATCH_OP, MATCHD_OP, operand::operand_val::n, NOTMATCH_OP, NOTMATCHD_OP, NULLV_ST, NUMBER_ST, pv_get_spec_value(), PV_VAL_INT, PV_VAL_NULL, PV_VAL_STR, RE_ST, _pv_value::ri, _pv_value::rs, operand::operand_val::s, _str::s, SCRIPTVAR_ST, operand::operand_val::spec, STRING_ST, operand::type, operand::v, and ZSW.

Referenced by eval_elem().

static int comp_str ( char *  str,
void *  param,
int  op,
int  subtype 
) [inline, static]

eval_elem helping function, compare a string value

Parameters:
str string
param compared parameter
op compare operation
subtype type of the value
Returns:
1 if string and parameter match, 0 if they not match, -1 on failure

Definition at line 600 of file route.c.

References DIFF_OP, EQUAL_OP, LM_CRIT, MATCH_OP, NOTMATCH_OP, RE_ST, and STRING_ST.

Referenced by comp_ip().

static int comp_strval ( struct sip_msg msg,
int  op,
str ival,
operand_t opd 
) [inline, static]

eval_elem helping function, compare a str value

Parameters:
msg SIP message
op compare operation
ival str value
opd operand type and data
Returns:
1 if str and operand match, 0 if they not match, -1 on failure

Definition at line 502 of file route.c.

References operand::operand_val::data, DIFF_OP, EQUAL_OP, _pv_value::flags, _str::len, LM_CRIT, MATCH_OP, operand::operand_val::n, NOTMATCH_OP, NULL, NUMBER_ST, pkg_free, pkg_malloc, pv_get_spec_value(), PV_VAL_STR, RE_ST, _pv_value::ri, _pv_value::rs, operand::operand_val::s, _str::s, SCRIPTVAR_ST, sint2str(), operand::operand_val::spec, STRING_ST, operand::type, and operand::v.

Referenced by eval_elem().

static int eval_elem ( struct expr e,
struct sip_msg msg,
pv_value_t val 
) [static]

Evaluate expression element.

Parameters:
e expression
msg SIP message
val pseudo-variable value
Returns:
0/1 (false/true) or -1 on error, -127 on EXPR_DROP

Definition at line 1079 of file route.c.

References ACTION_O, ip_addr::af, AF_O, BAND_OP, BLSHIFT_OP, BNOT_OP, BOR_OP, BRSHIFT_OP, BXOR_OP, check_self_op(), comp_ip(), comp_no(), comp_scriptvar(), comp_strval(), operand::operand_val::data, DIV_OP, receive_info::dst_ip, receive_info::dst_port, DSTIP_O, DSTPORT_O, E_BUG, ELEM_T, eval_expr(), EXPR_DROP, EXPR_O, sip_msg::first_line, _pv_value::flags, FROM_URI_O, get_from, get_to, HDR_TO_F, sip_uri::host, expr::left, sip_msg::len, _str::len, LM_CRIT, LM_ERR, METHOD_O, MINUS_OP, MODULO_OP, MSGLEN_O, MULT_OP, MYSELF_ST, operand::operand_val::n, sip_msg::new_uri, NO_OP, NULL, NUMBER_O, NUMBERV_O, expr::op, parse_from_header(), parse_headers(), parse_sip_msg_uri(), parse_uri(), sip_msg::parsed_uri, pkg_malloc, PLUS_OP, sip_uri::port_no, receive_info::proto, PROTO_O, pv_get_spec_value(), PV_TYPE_INT, PV_VAL_EMPTY, PV_VAL_INT, PV_VAL_NONE, PV_VAL_NULL, PV_VAL_PKG, PV_VAL_SHM, PV_VAL_STR, pv_value_destroy(), sip_msg::rcv, msg_start::request, RETCODE_O, return_code, _pv_value::ri, expr::right, _pv_value::rs, run_action_list(), operand::operand_val::s, _str::s, SCRIPTVAR_O, SIP_PORT, operand::operand_val::spec, receive_info::src_ip, receive_info::src_port, SRCIP_O, SRCPORT_O, STRINGV_O, sip_msg::to, TO_URI_O, operand::type, expr::type, msg_start::u, URI_O, operand::v, and VALUE_OP.

Referenced by eval_expr().

int eval_expr ( struct expr e,
struct sip_msg msg,
pv_value_t val 
)

Evaluate expression.

Parameters:
e expression
msg SIP message
val pseudo-variable
Returns:
ret= 0/1 (true/false) , -1 on error or EXPR_DROP (-127)

Definition at line 1459 of file route.c.

References AND_OP, ELEM_T, eval_elem(), eval_expr(), EVAL_OP, EXP_T, operand::operand_val::expr, expr::left, LM_CRIT, MAX_REC_LEV, NOT_OP, expr::op, OR_OP, rec_lev, expr::right, expr::type, and operand::v.

Referenced by do_action(), do_assign(), eval_elem(), and eval_expr().

static int fix_actions ( struct action a  )  [static]

static int fix_expr ( struct expr exp  )  [static]

Traverses an expression tree and compiles the REs where necessary.

Parameters:
exp expression tree
Returns:
0 for ok, <0 on errors

Definition at line 115 of file route.c.

References ACTION_O, AND_OP, operand::operand_val::data, E_BAD_RE, E_BUG, E_OUT_OF_MEM, ELEM_T, EVAL_OP, EXP_T, operand::operand_val::expr, EXPR_O, EXPR_ST, fix_actions(), expr::left, LM_CRIT, MATCH_OP, NOT_OP, NOTMATCH_OP, expr::op, OR_OP, pkg_free, pkg_malloc, RE_ST, expr::right, SCRIPTVAR_ST, STRING_ST, operand::type, expr::type, and operand::v.

Referenced by fix_actions().

int fix_rls ( void   ) 

Fixes all action tables.

Returns:
0 if ok , <0 on error

Definition at line 1552 of file route.c.

References BRANCH_RT_NO, FAILURE_RT_NO, fix_actions(), ONREPLY_RT_NO, and RT_NO.

Referenced by main().

void init_route_lists ( void   ) 

Initialize routing lists.

Definition at line 98 of file route.c.

Referenced by main().

void print_rl ( void   ) 

Debug function, prints main routing table.

Definition at line 1738 of file route.c.

References BRANCH_RT_NO, FAILURE_RT_NO, LM_DBG, ONREPLY_RT_NO, print_actions(), and RT_NO.

Referenced by main().

void push ( struct action a,
struct action **  head 
)

Adds an action list to head.

Parameters:
a action, must be null terminated (last a->next=0)
head head of action list

Definition at line 1515 of file route.c.

References action::next.

Referenced by add_actions().


Variable Documentation

struct action* branch_rlist[BRANCH_RT_NO]

Branch routes table

Definition at line 82 of file route.c.

Referenced by pre_print_uac_request().

Error route table

Definition at line 86 of file route.c.

Referenced by run_action_list().

struct action* failure_rlist[FAILURE_RT_NO]

Failure route table

Definition at line 81 of file route.c.

Referenced by run_failure_handlers().

struct action* onreply_rlist[ONREPLY_RT_NO]

main reply route table

Definition at line 80 of file route.c.

Referenced by receive_msg(), and reply_received().

int rcheck_stack[RT_NO] [static]

Definition at line 1599 of file route.c.

Referenced by check_actions().

int rcheck_stack_p = 0 [static]

Definition at line 1600 of file route.c.

Referenced by check_actions().

int rcheck_status = 0 [static]

Definition at line 1601 of file route.c.

Referenced by check_actions(), and check_rls().

Definition at line 86 of file action.c.

Referenced by do_action(), and eval_elem().

struct action* rlist[RT_NO]

main "script table"

Definition at line 78 of file route.c.

Referenced by cpl_proxy_to_loc_set(), dlg_ontimeout(), do_action(), and receive_msg().

int route_type = REQUEST_ROUTE


Generated on Thu May 24 12:00:42 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6