cr_data.c File Reference

Contains the functions to manage routing data.

More...

#include <stdlib.h>
#include "../../mem/shm_mem.h"
#include "cr_data.h"
#include "carrierroute.h"
#include "cr_config.h"
#include "cr_db.h"
#include "cr_carrier.h"
#include "cr_domain.h"
#include "cr_rule.h"

Include dependency graph for cr_data.c:

Go to the source code of this file.

Typedefs

typedef int(* cmpfunc_t )(const void *v1, const void *v2)

Functions

int add_carrier_data (struct route_data_t *rd, struct carrier_data_t *carrier_data)
int add_failure_route (struct route_data_t *rd, int carrier_id, int domain_id, const str *scan_prefix, const str *host, const str *reply_code, flag_t flags, flag_t mask, int next_domain_id, const str *comment)
int add_route (struct route_data_t *rd, int carrier_id, int domain_id, const str *scan_prefix, flag_t flags, flag_t mask, int max_targets, double prob, const str *rewrite_hostpart, int strip, const str *rewrite_local_prefix, const str *rewrite_local_suffix, int status, int hash_index, int backup, int *backed_up, const str *comment)
static int binary_search (void *base, unsigned int len, int elemsize, void *key, cmpfunc_t cmpfunc, int *index)
static int carrier_data_fixup (struct route_data_t *rd)
void clear_route_data (struct route_data_t *data)
void destroy_route_data (void)
static int fixup_rule_backup (struct route_flags *rf, struct route_rule *rr)
struct carrier_data_tget_carrier_data (struct route_data_t *rd, int carrier_id)
struct route_data_tget_data (void)
static struct domain_data_tget_domain_data_or_add (struct route_data_t *rd, struct carrier_data_t *carrier_data, int domain_id)
int init_route_data (void)
void release_data (struct route_data_t *data)
int reload_route_data (void)
int rule_fixup (struct route_data_t *rd)
static int rule_fixup_recursor (struct dtrie_node_t *node)

Variables

struct route_data_t ** global_data = NULL


Detailed Description

Contains the functions to manage routing data.

Definition in file cr_data.c.


Typedef Documentation

typedef int(* cmpfunc_t)(const void *v1, const void *v2)

Definition at line 305 of file cr_data.c.


Function Documentation

int add_carrier_data ( struct route_data_t rd,
struct carrier_data_t carrier_data 
)

adds a carrier_data struct for given carrier.

Parameters:
rd route data to be searched
carrier_data the carrier data struct to be inserted
Returns:
0 on success, -1 on failure

Definition at line 143 of file cr_data.c.

References route_data_t::carrier_num, route_data_t::carriers, route_data_t::first_empty_carrier, and LM_ERR.

Referenced by load_config(), and load_route_data_db().

int add_failure_route ( struct route_data_t rd,
int  carrier_id,
int  domain_id,
const str scan_prefix,
const str host,
const str reply_code,
flag_t  flags,
flag_t  mask,
int  next_domain_id,
const str comment 
)

Adds the given failure route information to the failure routing domain identified by domain. scan_prefix, host, reply_code and flags identifies the number for which the information is and the next_domain parameter defines where to continue routing in case of a match.

Parameters:
rd the route data to which the route shall be added
carrier_id the carrier id of the route to be added
domain_id the routing domain id of the new route
scan_prefix the number prefix
host the hostname last tried
reply_code the reply code
flags user defined flags
mask for user defined flags
next_domain_id continue routing with this domain id
comment a comment for the failure route rule
Returns:
0 on success, -1 on error in which case it LOGs a message.

Definition at line 496 of file cr_data.c.

References add_failure_route_to_tree(), domain_data_t::failure_tree, get_carrier_data(), get_domain_data_or_add(), _str::len, LM_ERR, LM_INFO, NULL, and _str::s.

Referenced by load_route_data_db().

int add_route ( struct route_data_t rd,
int  carrier_id,
int  domain_id,
const str scan_prefix,
flag_t  flags,
flag_t  mask,
int  max_targets,
double  prob,
const str rewrite_hostpart,
int  strip,
const str rewrite_local_prefix,
const str rewrite_local_suffix,
int  status,
int  hash_index,
int  backup,
int *  backed_up,
const str comment 
)

Adds the given route information to the routing domain identified by domain. scan_prefix identifies the number for which the information is and the rewrite_* parameters define what to do in case of a match. prob gives the probability with which this rule applies if there are more than one for a given prefix.

Parameters:
rd the route data to which the route shall be added
carrier_id the carrier id of the route to be added
domain_id the routing domain id of the new route
scan_prefix the number prefix
flags user defined flags
mask mask for user defined flags
max_targets the number of targets
prob the weight of the rule
rewrite_hostpart the rewrite_host of the rule
strip the number of digits to be stripped off userpart before prepending prefix
rewrite_local_prefix the rewrite prefix
rewrite_local_suffix the rewrite suffix
status the status of the rule
hash_index the hash index of the rule
backup indicates if the route is backed up by another. only useful if status==0, if set, it is the hash value of another rule
backed_up an -1-termintated array of hash indices of the route for which this route is backup
comment a comment for the route rule
Returns:
0 on success, -1 on error in which case it LOGs a message.

Definition at line 451 of file cr_data.c.

References add_route_to_tree(), get_carrier_data(), get_domain_data_or_add(), _str::len, LM_ERR, LM_INFO, NULL, _str::s, and domain_data_t::tree.

Referenced by load_config(), load_route_data_db(), and update_route_data().

static int binary_search ( void *  base,
unsigned int  len,
int  elemsize,
void *  key,
cmpfunc_t  cmpfunc,
int *  index 
) [static]

Implements a binary search algorithm using the function cmpfunc for comparison.

Parameters:
base pointer to the beginning of the array
len length of array
elemsize size of array elements
key pointer to the key we are looking for
cmpfunc function to be used for comparison
index If index is not NULL it is set to: -1 if an error occured, the index of the first entry equal to v or the index of the first entry greater than v in the case v was not found. Be careful: The index returned can be greater than the length of the array!
Returns:
-1 on error, 0 if the value was not found, 1 if it was found.

Definition at line 325 of file cr_data.c.

References LM_DBG, and LM_ERR.

Referenced by get_domain_data_or_add().

static int carrier_data_fixup ( struct route_data_t rd  )  [static]

void clear_route_data ( struct route_data_t data  ) 

Clears the complete routing data.

Parameters:
data route data to be cleared

Definition at line 104 of file cr_data.c.

References route_data_t::carrier_map, route_data_t::carrier_num, route_data_t::carriers, destroy_carrier_data(), route_data_t::domain_map, route_data_t::domain_num, name_map_t::name, NULL, _str::s, and shm_free.

Referenced by destroy_route_data(), reload_route_data(), and update_route_data().

void destroy_route_data ( void   ) 

Frees the routing data

Definition at line 88 of file cr_data.c.

References clear_route_data(), get_data(), NULL, and shm_free.

Referenced by mod_destroy().

static int fixup_rule_backup ( struct route_flags rf,
struct route_rule rr 
) [static]

struct carrier_data_t* get_carrier_data ( struct route_data_t rd,
int  carrier_id 
) [read]

Returns the carrier data for the given id by doing a binary search.

Note:
The carrier array must be sorted!
Parameters:
rd route data to be searched
carrier_id the id of the desired carrier
Returns:
a pointer to the desired carrier data, NULL if not found.

Definition at line 289 of file cr_data.c.

References route_data_t::carrier_num, route_data_t::carriers, compare_carrier_data(), carrier_data_t::id, LM_ERR, and NULL.

Referenced by add_failure_route(), add_route(), cr_do_route(), and cr_load_next_domain().

struct route_data_t* get_data ( void   )  [read]

Increases lock counter and returns a pointer to the current routing data

Returns:
pointer to the global routing data on success, NULL on failure

Definition at line 248 of file cr_data.c.

References route_data_t::lock, NULL, and route_data_t::proc_cnt.

Referenced by carrier_name_2_id(), cr_do_route(), cr_load_next_domain(), destroy_route_data(), domain_name_2_id(), and dump_fifo().

static struct domain_data_t* get_domain_data_or_add ( struct route_data_t rd,
struct carrier_data_t carrier_data,
int  domain_id 
) [static, read]

Returns the domain data for the given id by doing a binary search. If not found, a new domain data structure is added.

Parameters:
rd route data to used for name - id mapping
carrier_data carrier data to be searched
domain_id the id of desired domain
Returns:
a pointer to the desired domain data, NULL on error.

Definition at line 374 of file cr_data.c.

References add_domain_data(), binary_search(), compare_domain_data(), create_domain_data(), destroy_domain_data(), route_data_t::domain_map, route_data_t::domain_num, carrier_data_t::domains, carrier_data_t::first_empty_domain, carrier_data_t::id, domain_data_t::id, _str::len, LM_ERR, LM_INFO, map_id2name(), carrier_data_t::name, NULL, and _str::s.

Referenced by add_failure_route(), and add_route().

int init_route_data ( void   ) 

initialises the routing data, initialises the global data pointer

Returns:
0 on success, -1 on failure

Definition at line 71 of file cr_data.c.

References NULL, shm_malloc(), and SHM_MEM_ERROR.

Referenced by mod_init().

void release_data ( struct route_data_t data  ) 

decrements the lock counter of the routing data

Parameters:
data data to be released

Definition at line 273 of file cr_data.c.

References route_data_t::lock, and route_data_t::proc_cnt.

Referenced by carrier_name_2_id(), cr_do_route(), cr_load_next_domain(), domain_name_2_id(), and dump_fifo().

int reload_route_data ( void   ) 

Loads the routing data into the routing trees and sets the global_data pointer to the new data. The old_data is removed when it is not locked anymore.

Returns:
0 on success, -1 on failure

Definition at line 167 of file cr_data.c.

References carrier_data_fixup(), route_data_t::carrier_num, CARRIERROUTE_MODE_DB, CARRIERROUTE_MODE_FILE, route_data_t::carriers, clear_route_data(), compare_carrier_data(), compare_domain_data(), carrier_data_t::domain_num, carrier_data_t::domains, LM_ERR, load_config(), load_route_data_db(), mode, NULL, route_data_t::proc_cnt, rule_fixup(), shm_malloc(), SHM_MEM_ERROR, and sleep_us().

Referenced by mod_init(), reload_fifo(), and update_route_data().

int rule_fixup ( struct route_data_t rd  ) 

Fixes the route rules by creating an array for accessing route rules by hash index directly

Parameters:
rd route data to be fixed
Returns:
0 on success, -1 on failure

Definition at line 650 of file cr_data.c.

References route_data_t::carrier_num, route_data_t::carriers, carrier_data_t::domain_num, carrier_data_t::domains, _str::len, LM_INFO, LM_NOTICE, domain_data_t::name, rule_fixup_recursor(), _str::s, and domain_data_t::tree.

Referenced by reload_route_data(), and update_route_data().

static int rule_fixup_recursor ( struct dtrie_node_t *  node  )  [static]

Does the work for rule_fixup recursively. First, it tries to set a pointer the rules with an existing hash index at the marching array index. Afterward, remaining rules are populated with incrementing hash indices.

Parameters:
node the prefix tree node to be fixed up
Returns:
0 on success, -1 on failure

Definition at line 554 of file cr_data.c.

References cr_match_mode, DICE_MAX, route_flags::dice_max, route_rule::dice_to, fixup_rule_backup(), route_rule::hash_index, route_rule::host, _str::len, LM_ERR, LM_INFO, route_flags::max_targets, route_rule::next, route_flags::next, NULL, route_rule::prob, route_flags::rule_list, route_flags::rule_num, route_flags::rules, _str::s, shm_free, shm_malloc(), and SHM_MEM_ERROR.

Referenced by rule_fixup().


Variable Documentation

struct route_data_t** global_data = NULL

Pointer to the routing data.

Definition at line 44 of file cr_data.c.


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