cr_func.c File Reference

Routing and balancing functions.

More...

#include <ctype.h>
#include <assert.h>
#include <stdlib.h>
#include "cr_func.h"
#include "cr_db.h"
#include "../../sr_module.h"
#include "../../action.h"
#include "../../parser/parse_uri.h"
#include "../../parser/parse_from.h"
#include "../../ut.h"
#include "../../parser/digest/digest.h"
#include "../../parser/hf.h"
#include "../../mem/mem.h"
#include "../../qvalue.h"
#include "../../dset.h"
#include "cr_map.h"
#include "cr_rule.h"
#include "cr_domain.h"
#include "cr_carrier.h"
#include "carrierroute.h"

Include dependency graph for cr_func.c:

Go to the source code of this file.

Enumerations

enum  hash_algorithm { alg_crc32 = 1, alg_prime, alg_error }

Functions

static int actually_rewrite (const struct route_rule *rs, str *dest, const struct sip_msg *msg, const str *user, gparam_t *descavp)
int cr_do_route (struct sip_msg *_msg, gparam_t *_carrier, gparam_t *_domain, gparam_t *_prefix_matching, gparam_t *_rewrite_user, enum hash_source _hsrc, enum hash_algorithm _halg, gparam_t *_dstavp)
static int cr_gp2id (struct sip_msg *_msg, gparam_t *gp, struct name_map_t *map, int size)
int cr_load_next_domain (struct sip_msg *_msg, gparam_t *_carrier, gparam_t *_domain, gparam_t *_prefix_matching, gparam_t *_host, gparam_t *_reply_code, gparam_t *_dstavp)
int cr_load_user_carrier (struct sip_msg *_msg, gparam_t *_user, gparam_t *_domain, gparam_t *_dstavp)
int cr_prime_route (struct sip_msg *_msg, gparam_t *_carrier, gparam_t *_domain, gparam_t *_prefix_matching, gparam_t *_rewrite_user, enum hash_source _hsrc, gparam_t *_dstavp)
int cr_route (struct sip_msg *_msg, gparam_t *_carrier, gparam_t *_domain, gparam_t *_prefix_matching, gparam_t *_rewrite_user, enum hash_source _hsrc, gparam_t *_dstavp)
static struct route_ruleget_rule_by_hash (const struct route_flags *rf, const int prob)
static int reply_code_matcher (const str *rcw, const str *rc)
static int rewrite_on_rule (struct route_flags *rf_head, flag_t flags, str *dest, struct sip_msg *msg, const str *user, const enum hash_source hash_source, const enum hash_algorithm alg, gparam_t *dstavp)
static int rewrite_uri_recursor (struct dtrie_node_t *node, const str *pm, flag_t flags, str *dest, struct sip_msg *msg, const str *user, const enum hash_source hash_source, const enum hash_algorithm alg, gparam_t *dstavp)
static int set_next_domain_on_rule (struct failure_route_rule *frr_head, const str *host, const str *reply_code, const flag_t flags, const gparam_t *dstavp)
static int set_next_domain_recursor (struct dtrie_node_t *failure_node, const str *uri, const str *host, const str *reply_code, const flag_t flags, const gparam_t *dstavp)

Variables

static const str AT_SIGN = { .s="@", .len=1 }
static const str SIP_URI = { .s="sip:", .len=4 }
static const str SIPS_URI = { .s="sips:", .len=5 }


Detailed Description

Routing and balancing functions.

Definition in file cr_func.c.


Enumeration Type Documentation

Enumerator:
alg_crc32  hashing algorithm is CRC32
alg_prime  hashing algorithm is (right 18 digits of hash_source % prime_number) % max_targets + 1
alg_error 

Definition at line 52 of file cr_func.c.


Function Documentation

static int actually_rewrite ( const struct route_rule rs,
str dest,
const struct sip_msg msg,
const str user,
gparam_t descavp 
) [static]

does the work for rewrite_on_rule, writes the new URI into dest

Parameters:
rs the route rule used for rewriting
dest the returned new destination URI
msg the sip message
user the localpart of the uri to be rewritten
descavp the name of the AVP where the description is stored
Returns:
0 on success, -1 on failure
See also:
rewrite_on_rule()

Definition at line 278 of file cr_func.c.

References add_avp(), AVP_VAL_STR, route_rule::comment, route_rule::host, _pv_name::isname, _str::len, len, LM_ERR, route_rule::local_prefix, route_rule::local_suffix, NULL, sip_msg::parsed_uri, pkg_free, pkg_malloc, PKG_MEM_ERROR, _gparam::pve, _pv_param::pvn, _pv_spec::pvp, int_str::s, _str::s, SIPS_URI_T, _pv_elem::spec, route_rule::strip, sip_uri::type, _pv_name::u, and _gparam::v.

Referenced by rewrite_on_rule().

int cr_do_route ( struct sip_msg _msg,
gparam_t _carrier,
gparam_t _domain,
gparam_t _prefix_matching,
gparam_t _rewrite_user,
enum hash_source  _hsrc,
enum hash_algorithm  _halg,
gparam_t _dstavp 
)

rewrites the request URI of msg after determining the new destination URI

Parameters:
_msg the current SIP message
_carrier the requested carrier
_domain the requested routing domain
_prefix_matching the user to be used for prefix matching
_rewrite_user the localpart of the URI to be rewritten
_hsrc the SIP header used for hashing
_halg the hash algorithm used for hashing
_dstavp the name of the destination AVP where the used host name is stored
Returns:
1 on success, -1 on failure

Definition at line 487 of file cr_func.c.

References route_data_t::carrier_map, route_data_t::carrier_num, cr_gp2id(), route_data_t::default_carrier_id, do_action(), route_data_t::domain_map, route_data_t::domain_num, action::elem, fallback_default, fixup_get_svalue(), sip_msg::flags, get_carrier_data(), get_data(), get_domain_data(), _str::len, LM_ERR, LM_INFO, LM_NOTICE, action::next, NULL, pkg_free, release_data(), rewrite_uri_recursor(), _str::s, SET_URI_T, action_elem_::string, STRING_ST, domain_data_t::tree, action_elem_::type, action::type, and action_elem_::u.

Referenced by cr_prime_route(), and cr_route().

static int cr_gp2id ( struct sip_msg _msg,
gparam_t gp,
struct name_map_t map,
int  size 
) [inline, static]

Get the id that belongs to a string name from gparam_t structure.

Get the id that belongs to a string name from gparam_t structure, use the search_id function for the lookup.

Parameters:
_msg SIP message
gp id as integer, pseudo-variable or AVP name of carrier
map lookup function
size size of the list
Returns:
id on success, -1 otherwise

Definition at line 75 of file cr_func.c.

References AVP_VAL_STR, fixup_get_svalue(), usr_avp::flags, GPARAM_TYPE_INT, GPARAM_TYPE_PVE, id, _pv_name::isname, _gparam::ival, _str::len, LM_ERR, map_name2id(), int_str::n, _gparam::pve, _pv_param::pvn, _pv_spec::pvp, PVT_AVP, _str::s, int_str::s, search_first_avp(), _pv_elem::spec, _pv_spec::type, _gparam::type, _pv_name::u, and _gparam::v.

Referenced by cr_do_route(), and cr_load_next_domain().

int cr_load_next_domain ( struct sip_msg _msg,
gparam_t _carrier,
gparam_t _domain,
gparam_t _prefix_matching,
gparam_t _host,
gparam_t _reply_code,
gparam_t _dstavp 
)

Loads next domain from failure routing table and stores it in an AVP.

Parameters:
_msg the current SIP message
_carrier the requested carrier
_domain the requested routing domain
_prefix_matching the user to be used for prefix matching
_host the host name to be used for rule matching
_reply_code the reply code to be used for rule matching
_dstavp the name of the destination AVP
Returns:
1 on success, -1 on failure

Definition at line 686 of file cr_func.c.

References route_data_t::carrier_map, route_data_t::carrier_num, cr_gp2id(), route_data_t::default_carrier_id, route_data_t::domain_map, route_data_t::domain_num, domain_data_t::failure_tree, fallback_default, fixup_get_svalue(), sip_msg::flags, get_carrier_data(), get_data(), get_domain_data(), _str::len, LM_ERR, LM_INFO, LM_NOTICE, NULL, release_data(), _str::s, and set_next_domain_recursor().

int cr_load_user_carrier ( struct sip_msg _msg,
gparam_t _user,
gparam_t _domain,
gparam_t _dstavp 
)

Loads user carrier from subscriber table and stores it in an AVP.

Parameters:
_msg the current SIP message
_user the user to determine the carrier data
_domain the domain to determine the domain data
_dstavp the name of the AVP where to store the carrier id
Returns:
1 on success, -1 on failure

Definition at line 595 of file cr_func.c.

References add_avp(), domain, fixup_get_svalue(), _pv_name::isname, LM_ERR, load_user_carrier(), int_str::n, _gparam::pve, _pv_param::pvn, _pv_spec::pvp, _pv_elem::spec, _pv_name::u, user, and _gparam::v.

int cr_prime_route ( struct sip_msg _msg,
gparam_t _carrier,
gparam_t _domain,
gparam_t _prefix_matching,
gparam_t _rewrite_user,
enum hash_source  _hsrc,
gparam_t _dstavp 
)

rewrites the request URI of msg after determining the new destination URI with the prime hash algorithm.

Parameters:
_msg the current SIP message
_carrier the requested carrier
_domain the requested routing domain
_prefix_matching the user to be used for prefix matching
_rewrite_user the localpart of the URI to be rewritten
_hsrc the SIP header used for hashing
_dstavp the name of the destination AVP where the used host name is stored
Returns:
1 on success, -1 on failure

Definition at line 663 of file cr_func.c.

References alg_prime, and cr_do_route().

int cr_route ( struct sip_msg _msg,
gparam_t _carrier,
gparam_t _domain,
gparam_t _prefix_matching,
gparam_t _rewrite_user,
enum hash_source  _hsrc,
gparam_t _dstavp 
)

rewrites the request URI of msg after determining the new destination URI with the crc32 hash algorithm.

Parameters:
_msg the current SIP message
_carrier the requested carrier
_domain the requested routing domain
_prefix_matching the user to be used for prefix matching
_rewrite_user the localpart of the URI to be rewritten
_hsrc the SIP header used for hashing
_dstavp the name of the destination AVP where the used host name is stored
Returns:
1 on success, -1 on failure

Definition at line 639 of file cr_func.c.

References alg_crc32, and cr_do_route().

static struct route_rule* get_rule_by_hash ( const struct route_flags rf,
const int  prob 
) [static, read]

searches for a rule int rt with hash_index prob - 1 If the rule with the desired hash index is deactivated, the next working rule is used.

Parameters:
rf the route_flags node to search for rule
prob the hash index
Returns:
pointer to route rule on success, NULL on failure

Definition at line 243 of file cr_func.c.

References route_rule::backup, route_rule::hash_index, LM_INFO, LM_WARN, NULL, route_rule_p_list::rr, route_flags::rule_num, route_flags::rules, and route_rule::status.

Referenced by rewrite_on_rule().

static int reply_code_matcher ( const str rcw,
const str rc 
) [inline, static]

Try to match the reply code rc to the reply code with wildcards.

Parameters:
rcw reply code specifier with wildcards
rc the current reply code
Returns:
0 on match, -1 otherwise

Definition at line 135 of file cr_func.c.

References _str::len, and _str::s.

Referenced by set_next_domain_on_rule().

static int rewrite_on_rule ( struct route_flags rf_head,
flag_t  flags,
str dest,
struct sip_msg msg,
const str user,
const enum hash_source  hash_source,
const enum hash_algorithm  alg,
gparam_t dstavp 
) [static]

writes the uri dest using the flags and rule list of rf_head

Parameters:
rf_head the head of the route flags list
flags user defined flags
dest the returned new destination URI
msg the sip message
user the localpart of the uri to be rewritten
hash_source the SIP header used for hashing
alg the algorithm used for hashing
dstavp the name of the destination AVP where the used host name is stored
Returns:
0 on success, -1 on failure, 1 on empty rule list

Definition at line 358 of file cr_func.c.

References actually_rewrite(), alg_crc32, alg_prime, route_rule::backup, route_flags::dice_max, route_rule::dice_to, route_flags::flags, get_rule_by_hash(), hash_func(), LM_CRIT, LM_DBG, LM_ERR, LM_INFO, route_flags::mask, route_flags::max_targets, route_rule::next, route_flags::next, NULL, prime_hash_func(), route_rule::prob, route_rule_p_list::rr, route_flags::rule_list, and route_rule::status.

Referenced by rewrite_uri_recursor().

static int rewrite_uri_recursor ( struct dtrie_node_t *  node,
const str pm,
flag_t  flags,
str dest,
struct sip_msg msg,
const str user,
const enum hash_source  hash_source,
const enum hash_algorithm  alg,
gparam_t dstavp 
) [static]

traverses the routing tree until a matching rule is found The longest match is taken, so it is possible to define route rules for a single number

Parameters:
node the current routing tree node
pm the user to be used for prefix matching
flags user defined flags
dest the returned new destination URI
msg the sip message
user the localpart of the uri to be rewritten
hash_source the SIP header used for hashing
alg the algorithm used for hashing
dstavp the name of the destination AVP where the used host name is stored
Returns:
0 on success, -1 on failure, 1 on no more matching child node and no rule list

Definition at line 450 of file cr_func.c.

References cr_match_mode, _str::len, LM_INFO, NULL, rewrite_on_rule(), and _str::s.

Referenced by cr_do_route().

static int set_next_domain_on_rule ( struct failure_route_rule frr_head,
const str host,
const str reply_code,
const flag_t  flags,
const gparam_t dstavp 
) [static]

writes the next_domain avp using the rule list of failure_tree

Parameters:
frr_head the head of the failure route rule list
host last tried host
reply_code the last reply code
flags flags for the failure route rule
dstavp the name of the AVP where to store the next domain
Returns:
0 on success, -1 on failure

Definition at line 161 of file cr_func.c.

References add_avp(), failure_route_rule::flags, failure_route_rule::host, _pv_name::isname, _str::len, LM_DBG, LM_ERR, LM_INFO, failure_route_rule::mask, int_str::n, failure_route_rule::next, failure_route_rule::next_domain, NULL, _gparam::pve, _pv_param::pvn, _pv_spec::pvp, failure_route_rule::reply_code, reply_code_matcher(), _str::s, _pv_elem::spec, str_strcmp(), _pv_name::u, and _gparam::v.

Referenced by set_next_domain_recursor().

static int set_next_domain_recursor ( struct dtrie_node_t *  failure_node,
const str uri,
const str host,
const str reply_code,
const flag_t  flags,
const gparam_t dstavp 
) [static]

traverses the failure routing tree until a matching rule is found. The longest match is taken, so it is possible to define failure route rules for a single number

Parameters:
failure_node the current routing tree node
uri the uri to be rewritten at the current position
host last tried host
reply_code the last reply code
flags flags for the failure route rule
dstavp the name of the AVP where to store the next domain
Returns:
0 on success, -1 on failure, 1 on no more matching child node and no rule list

Definition at line 212 of file cr_func.c.

References cr_match_mode, _str::len, LM_INFO, NULL, _str::s, and set_next_domain_on_rule().

Referenced by cr_load_next_domain().


Variable Documentation

const str AT_SIGN = { .s="@", .len=1 } [static]

Definition at line 61 of file cr_func.c.

const str SIP_URI = { .s="sip:", .len=4 } [static]

Definition at line 59 of file cr_func.c.

const str SIPS_URI = { .s="sips:", .len=5 } [static]

Definition at line 60 of file cr_func.c.


Generated on Mon May 21 18:00:38 2012 for Kamailio - The Open Source SIP Server by  doxygen 1.5.6