00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef prefix_tree_h
00031 #define prefix_tree_h
00032
00033 #include "../../str.h"
00034 #include "../../ip_addr.h"
00035 #include "dr_time.h"
00036
00037 #define PTREE_CHILDREN 10
00038 #define IS_DECIMAL_DIGIT(d) \
00039 (((d)>='0') && ((d)<= '9'))
00040
00041 extern int tree_size;
00042
00043 #define INIT_PTREE_NODE(p, n) \
00044 do {\
00045 (n) = (ptree_t*)shm_malloc(sizeof(ptree_t));\
00046 if(NULL == (n))\
00047 goto err_exit;\
00048 tree_size+=sizeof(ptree_t);\
00049 memset((n), 0, sizeof(ptree_t));\
00050 (n)->bp=(p);\
00051 }while(0);
00052
00053
00054
00055 typedef struct pgw_addr_ {
00056 struct ip_addr ip;
00057 unsigned short port;
00058 int type;
00059 int strip;
00060 struct pgw_addr_ *next;
00061 }pgw_addr_t;
00062
00063
00064 typedef struct pgw_ {
00065
00066 long id;
00067 str pri;
00068 int strip;
00069 str ip;
00070 int type;
00071 str attrs;
00072 struct pgw_ *next;
00073 }pgw_t;
00074
00075
00076 typedef struct pgw_list_ {
00077 pgw_t *pgw;
00078 int grpid;
00079 }pgw_list_t;
00080
00081
00082 typedef struct rt_info_ {
00083 unsigned int priority;
00084 tmrec_t *time_rec;
00085
00086 pgw_list_t *pgwl;
00087
00088 unsigned short pgwa_len;
00089
00090 unsigned short ref_cnt;
00091
00092 int route_idx;
00093 } rt_info_t;
00094
00095 typedef struct rt_info_wrp_ {
00096 rt_info_t *rtl;
00097 struct rt_info_wrp_ *next;
00098 } rt_info_wrp_t;
00099
00100 typedef struct rg_entry_ {
00101 unsigned int rgid;
00102 rt_info_wrp_t *rtlw;
00103 } rg_entry_t;
00104
00105 typedef struct ptree_node_ {
00106 unsigned int rg_len;
00107 unsigned int rg_pos;
00108 rg_entry_t *rg;
00109 struct ptree_ *next;
00110 } ptree_node_t;
00111
00112 typedef struct ptree_ {
00113
00114 struct ptree_ *bp;
00115 ptree_node_t ptnode[PTREE_CHILDREN];
00116 } ptree_t;
00117
00118 void
00119 print_interim(
00120 int,
00121 int,
00122 ptree_t*
00123 );
00124
00125 int
00126 del_tree(
00127 ptree_t *
00128 );
00129
00130 int
00131 add_prefix(
00132 ptree_t*,
00133
00134 str*,
00135 rt_info_t *,
00136 unsigned int
00137 );
00138
00139 rt_info_t*
00140 get_prefix(
00141 ptree_t *ptree,
00142 str* prefix,
00143 unsigned int rgid
00144 );
00145
00146 int
00147 add_rt_info(
00148 ptree_node_t*,
00149 rt_info_t*,
00150 unsigned int
00151 );
00152
00153 pgw_t*
00154 get_pgw(
00155 pgw_t*,
00156 long
00157 );
00158
00159 void
00160 del_rt_list(
00161 rt_info_wrp_t *rl
00162 );
00163
00164 void print_rt(
00165 rt_info_t*
00166 );
00167
00168 void
00169 free_rt_info(
00170 rt_info_t*
00171 );
00172
00173 rt_info_t*
00174 check_rt(
00175 ptree_node_t *ptn,
00176 unsigned int rgid
00177 );
00178
00179 #endif