00001 /* 00002 * $Id: cr_data.h 5189 2008-11-12 15:53:01Z henningw $ 00003 * 00004 * Copyright (C) 2007-2008 1&1 Internet AG 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 */ 00022 00023 /** 00024 * \file cr_data.h 00025 * \brief Contains the functions to manage routing data. 00026 * \ingroup carrierroute 00027 * - Module; \ref carrierroute 00028 */ 00029 00030 #ifndef CR_DATA_H 00031 #define CR_DATA_H 00032 00033 #include <sys/types.h> 00034 #include "../../locking.h" 00035 #include "../../flags.h" 00036 #include "cr_map.h" 00037 00038 00039 /** 00040 * contains all routing data. 00041 */ 00042 struct route_data_t { 00043 struct name_map_t * carrier_map; /*!< holds the map between carrier names and numbers */ 00044 struct name_map_t * domain_map; /*!< holds the map between domain names and numbers */ 00045 struct carrier_data_t ** carriers; /*!< array of carriers */ 00046 size_t carrier_num; /*!< number of carriers */ 00047 size_t first_empty_carrier; /*!< the index of the first empty entry in carriers */ 00048 size_t domain_num; /*!< total number of different domains */ 00049 int default_carrier_id; 00050 int proc_cnt; /*!< a ref counter for the shm data */ 00051 gen_lock_t lock; /*!< lock for ref counter updates */ 00052 }; 00053 00054 /** 00055 * initialises the routing data, initialises the global data pointer 00056 * 00057 * @return 0 on success, -1 on failure 00058 */ 00059 int init_route_data(void); 00060 00061 00062 /** 00063 * Frees the routing data 00064 */ 00065 void destroy_route_data(void); 00066 00067 00068 /** 00069 * Clears the complete routing data. 00070 * 00071 * @param data route data to be cleared 00072 */ 00073 void clear_route_data(struct route_data_t *data); 00074 00075 00076 /** 00077 * adds a carrier_data struct for given carrier 00078 * 00079 * @param rd route data to be searched 00080 * @param carrier_data the carrier data struct to be inserted 00081 * 00082 * @return 0 on success, -1 on failure 00083 */ 00084 int add_carrier_data(struct route_data_t * rd, struct carrier_data_t * carrier_data); 00085 00086 00087 /** 00088 * Loads the routing data into the routing trees and sets the 00089 * global_data pointer to the new data. The old_data is removed 00090 * when it is not locked anymore. 00091 * 00092 * @return 0 on success, -1 on failure 00093 */ 00094 int reload_route_data(void); 00095 00096 00097 /** 00098 * Increases lock counter and returns a pointer to the 00099 * current routing data 00100 * 00101 * @return pointer to the global routing data on success, 00102 * NULL on failure 00103 */ 00104 struct route_data_t * get_data(void); 00105 00106 00107 /** 00108 * decrements the lock counter of the routing data 00109 * 00110 * @param data data to be released 00111 */ 00112 void release_data(struct route_data_t *data); 00113 00114 00115 /** 00116 * Returns the carrier data for the given id by doing a binary search. 00117 * @note The carrier array must be sorted! 00118 * 00119 * @param rd route data to be searched 00120 * @param carrier_id the id of the desired carrier 00121 * 00122 * @return a pointer to the desired carrier data, NULL if not found. 00123 */ 00124 struct carrier_data_t *get_carrier_data(struct route_data_t * rd, int carrier_id); 00125 00126 00127 /** 00128 * Adds the given route information to the routing domain identified by 00129 * domain. scan_prefix identifies the number for which the information 00130 * is and the rewrite_* parameters define what to do in case of a match. 00131 * prob gives the probability with which this rule applies if there are 00132 * more than one for a given prefix. 00133 * 00134 * @param rd the route data to which the route shall be added 00135 * @param carrier_id the carrier id of the route to be added 00136 * @param domain_id the routing domain id of the new route 00137 * @param scan_prefix the number prefix 00138 * @param flags user defined flags 00139 * @param mask mask for user defined flags 00140 * @param max_targets the number of targets 00141 * @param prob the weight of the rule 00142 * @param strip the number of digits to be stripped off userpart before prepending prefix 00143 * @param rewrite_hostpart the rewrite_host of the rule 00144 * @param rewrite_local_prefix the rewrite prefix 00145 * @param rewrite_local_suffix the rewrite suffix 00146 * @param status the status of the rule 00147 * @param hash_index the hash index of the rule 00148 * @param backup indicates if the route is backed up by another. only 00149 useful if status==0, if set, it is the hash value 00150 of another rule 00151 * @param backed_up an -1-termintated array of hash indices of the route 00152 for which this route is backup 00153 * @param comment a comment for the route rule 00154 * 00155 * @return 0 on success, -1 on error in which case it LOGs a message. 00156 */ 00157 int add_route(struct route_data_t * rd, int carrier_id, 00158 int domain_id, const str * scan_prefix, flag_t flags, flag_t mask, int max_targets, 00159 double prob, const str * rewrite_hostpart, int strip, const str * rewrite_local_prefix, 00160 const str * rewrite_local_suffix, int status, int hash_index, int backup, int * backed_up, 00161 const str * comment); 00162 00163 00164 /** 00165 * Adds the given failure route information to the failure routing domain identified by 00166 * domain. scan_prefix, host, reply_code and flags identifies the number for which 00167 * the information is and the next_domain parameter defines where to continue routing 00168 * in case of a match. 00169 * 00170 * @param rd the route data to which the route shall be added 00171 * @param carrier_id the carrier id of the route to be added 00172 * @param domain_id the routing domain id of the new route 00173 * @param scan_prefix the number prefix 00174 * @param host the hostname last tried 00175 * @param reply_code the reply code 00176 * @param flags user defined flags 00177 * @param mask for user defined flags 00178 * @param next_domain_id continue routing with this domain id 00179 * @param comment a comment for the failure route rule 00180 * 00181 * @return 0 on success, -1 on error in which case it LOGs a message. 00182 */ 00183 int add_failure_route(struct route_data_t * rd, int carrier_id, int domain_id, 00184 const str * scan_prefix, const str * host, const str * reply_code, 00185 flag_t flags, flag_t mask, int next_domain_id, const str * comment); 00186 00187 00188 /** 00189 * Fixes the route rules by creating an array for accessing 00190 * route rules by hash index directly 00191 * 00192 * @param rd route data to be fixed 00193 * 00194 * @return 0 on success, -1 on failure 00195 */ 00196 int rule_fixup(struct route_data_t * rd); 00197 00198 00199 #endif
1.5.6