Functions | Variables

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.

Functions

Variables


Detailed Description

Definition in 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, and route_data_t::first_empty_carrier.

Referenced by load_config(), and load_route_data_db().

Here is the caller graph for this function:

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 
)

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, and _str::s.

Referenced by load_route_data_db().

Here is the call graph for this function:

Here is the caller graph for this function:

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 
)

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, _str::s, and domain_data_t::tree.

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

Here is the call graph for this function:

Here is the caller graph for this function:

static int binary_search ( void *  base,
unsigned int  len,
int  elemsize,
void *  key,
cmpfunc_t  cmpfunc,
int *  index 
) [static]
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.

Referenced by get_domain_data_or_add().

Here is the caller graph for this function:

void clear_route_data ( struct route_data_t 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, and _str::s.

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

Here is the call graph for this function:

Here is the caller graph for this function:

struct carrier_data_t* get_carrier_data ( struct route_data_t rd,
int  carrier_id 
) [read]
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(), and carrier_data_t::id.

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

Here is the call graph for this function:

Here is the caller graph for this function:

struct route_data_t* get_data ( void   )  [read]
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, 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().

Here is the caller graph for this function:

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]

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, map_id2name(), carrier_data_t::name, and _str::s.

Referenced by add_failure_route(), and add_route().

Here is the call graph for this function:

Here is the caller graph for this function:

int init_route_data ( void   ) 
Returns:
0 on success, -1 on failure

Definition at line 71 of file cr_data.c.

Referenced by mod_init().

Here is the caller graph for this function:

void release_data ( struct route_data_t 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().

Here is the caller graph for this function:

int reload_route_data ( void   ) 

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 route_data_t::carrier_num, route_data_t::carriers, clear_route_data(), compare_carrier_data(), compare_domain_data(), carrier_data_t::domain_num, carrier_data_t::domains, load_config(), load_route_data_db(), route_data_t::proc_cnt, and rule_fixup().

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

Here is the call graph for this function:

Here is the caller graph for this function:

int rule_fixup ( struct route_data_t rd  ) 
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, domain_data_t::name, rule_fixup_recursor(), _str::s, and domain_data_t::tree.

Referenced by reload_route_data(), and update_route_data().

Here is the call graph for this function:

Here is the caller graph for this function:

static int rule_fixup_recursor ( struct dtrie_node_t node  )  [static]

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 dtrie_node_t::child, dtrie_node_t::data, route_flags::dice_max, route_rule::dice_to, route_rule::hash_index, route_rule::host, _str::len, route_flags::max_targets, route_rule::next, route_flags::next, route_rule::prob, route_flags::rule_list, route_flags::rule_num, route_flags::rules, and _str::s.

Referenced by rule_fixup().

Here is the caller graph for this function: