$Revision: 1.26 $
Radix tree (rx). rxroutines.h - header file for radix tree handling module.
Status: NOT REVUED, TESTED
Design and implementation by: marek
Included Files
- #include </home/shane/release/RIP/include/stubs.h>
- #include </home/shane/release/RIP/include/memwrap.h>
- #include </home/shane/release/RIP/include/iproutines.h>
Preprocessor definitions
#define _RX_H
#define RX_ANS_ALL -1
#define RX_ALL_DEPTHS 255
typedef enum {...} rx_fam_t
enum |
|
{ |
|
RX_FAM_RT; |
|
RX_FAM_IN; |
|
RX_FAM_IP; |
|
} |
|
the node operation modes
typedef enum {...} rx_oper_mt
enum |
|
{ |
|
RX_OPER_CRE; |
|
RX_OPER_DEL; |
|
} |
|
stack building modes
typedef enum {...} rx_stk_mt
enum |
|
{ |
|
RX_STK_CREAT; | - creation = all glue nodes, stop at first non-glue
|
RX_STK_QUERY_ALLNOD; | - query = all glue nodes, stop when deep enough
|
RX_STK_QUERY_NOGLUE; | - query = no glue nodes, stop when deep enough
|
} |
|
the search modes
typedef enum {...} rx_srch_mt
enum |
|
{ |
|
RX_SRCH_CREAT; | special search - does not skip glue nodes
|
RX_SRCH_EXLESS; | the default search
|
RX_SRCH_EXACT; |
|
RX_SRCH_LESS; |
|
RX_SRCH_MORE; | more specific search
|
RX_SRCH_DBLS; | special more spec: return only nodes with
more than one data leaves
|
RX_SRCH_RANG; | more specific range search, RPSL style : ^n-m
|
} |
|
radix tree's memory modes -- not yet implemented
typedef enum {...} rx_mem_mt
enum |
|
{ |
|
RX_MEM_RAMONLY; |
|
RX_MEM_RAMSQL; |
|
RX_MEM_SQLONLY; |
|
} |
|
subtree modes -- not yet implemented
typedef enum {...} rx_subtree_mt
enum |
|
{ |
|
RX_SUB_NONE; |
|
RX_SUB_AUTO; |
|
RX_SUB_HAND; |
|
} |
|
typedef enum {...} rx_walk_mt
enum |
|
{ |
|
RX_WALK_CNTGLU; | default: count also glue nodes and make the level
checking aware of them
|
RX_WALK_SKPGLU; | only real nodes counted & watched in level checks
|
RX_WALK_PRFLEN; | make level check a check for prefix length;
still only non-glue nodes are counted
|
RX_WALK_REVERS; | reverse the order of traversing the tree
(first link 1 then 0)
|
} |
|
A struct for data hooked via a double linked list at a radix node.
Must uniquely define the object for lookups in the SQL tables and/or memory.
Must also contain enough info to let the delete_node choose (and remove)
the proper object from the (linked) list
typedef struct {...} rx_dataleaf_t
struct |
|
{ |
|
ip_range_t iprange; | filled for all trees. Used in rp_search
for determining exact matches (all trees)
and to see if an address is in range
(only IPv4 inetnum trees)
|
unsigned char preflen; |
|
char composed; | non-zero for composed inetnums
equal to: the number of prefixes composing
the range - minus 1
|
void* data_ptr; | to in-memory immediate data
|
unsigned data_len; | and its length
|
sql_key_t data_key; | key to the SQL full-text data record
|
sql_key_t leaf_key; | pointer to the SQL data leaf record
|
} |
|
The struct for radix nodes.
Must contain prefix, parent, left/right child links in memory and sql,
link to the sql version of the node.
And of course data: pointer to a double linked list of rx_data_t's.
typedef struct _rx_node_str rx_node_t
struct _rx_node_str |
|
{ |
|
ip_prefix_t prefix; | who am i.
|
char glue; |
|
GList* leaves_ptr; | a double-linked list of rx_data_t structs
the data leaves can be multiple at each node
(due to a user error the inetnum ranges can
overlap, due to multihoming or error routes
can be duplicated ).
So we link a dynamic thing here
|
struct _rx_node_str* parent_ptr; | radix links in memory
|
struct _rx_node_str* child_ptr[2]; | NULL means empty
|
sql_key_t parent_key; | radix links in SQL
|
sql_key_t child_key[2]; | zero means empty
|
sql_key_t node_key; | key of the corresponding SQL radix node
|
} |
|
rx_tree_t - defines a radix tree.
includes a pointer(key) to the top node,
names of the corresponding SQL tables
(they can be generated automatically,
but this is the place to store the result)
Data_table is for data_key.
Radix_table is for parent_id, right_id, left_id, node_id.
Leaves_table is for leaves_key (double linked list in SQL).
typedef struct _rx_tree_str rx_tree_t
struct _rx_tree_str |
|
{ |
|
ip_space_t space; | one of IPv4, IPv6
|
rx_fam_t family; | one of RT, IN
|
rx_subtree_mt subtrees; | one of NONE, AUTO, HAND
|
rx_mem_mt mem_mode; | where the tree will sit - SQL or RAM
|
struct rx_tree_str* parent_tree; | pointer to the parent tree
|
ip_prefix_t prefix; | of the IP space this tree covers
|
int maxbits; | max depth of this tree
(depends on the space, so it is redundant)
|
sql_tblnam_t data_table; |
|
sql_tblnam_t radix_table; |
|
sql_tblnam_t leaves_table; |
|
int num_nodes; | number of nodes in tree - for assertions
|
rx_node_t* top_ptr; | pointer to the top node
|
long top_key; | the same in SQL
|
rw_lock_t rwlock; | per-tree reader/writer lock
|
} |
|
this is a definition of a node copy used for:
* stack elements returned from rx_stack_build,
* answer elements from an rx_nod_search.
It *must* hold pointers to the original locations of it (in terms of
memory and SQL) so that one could actually modify the node...
In SQL tree mode it holds also a copy of a node.
This seems to be unnecessary for in-memory radix trees but is a must
for sql ones.
WARNING!!!!! The fact that pointers to tree and memory / SQL nodes are
here is a subject to race condition. The location of the tree in the
forest list and the node in memory must not change.
typedef struct {...} rx_nodcpy_t
struct |
|
{ |
|
rx_tree_t* tree; | contains registry_id, space_id, sql table names
|
rx_node_t* srcptr; |
|
sql_key_t srckey; |
|
rx_node_t cpy; | filled in if the tree is kept in SQL only mode
|
} |
|
This represents one data leaf (by reference). It's used for returning data
from rx_bin_search() to rx_asc_search().
typedef struct {...} rx_datref_t
struct |
|
{ |
|
sql_key_t srckey; |
|
rx_dataleaf_t* leafptr; |
|
} |
|
this is a structure used for returning the data from the search.
It contains a copy of the dataleaf and a pointer to the source
typedef struct {...} rx_datcpy_t
struct |
|
{ |
|
sql_key_t srckey; |
|
rx_dataleaf_t leafcpy; |
|
} |
|
typedef struct {...} rx_treecheck_t
struct |
|
{ |
|
rx_node_t* node; |
|
int code; |
|
int datatoo; |
|
rx_tree_t* tree; |
|
} |
|
typedef struct {...} rx_sqlobj_t
struct |
|
{ |
|
sql_tblnam_t name; |
|
sql_key_t key; |
|
} |
|
typedef struct {...} hook_addnode_userdat_t
struct |
|
{ |
|
GList** nodlist; |
|
rx_tree_t* tree; |
|
ip_prefix_t* prefix; |
|
} |
|
static char* asctime_r ( const struct tm* __tm, char* __buf )
static char* ctime_r ( const time_t* __time, char* __buf )
static int getlogin_r ( char* __name, int __len )
static int sigwait ( const sigset_t* __setp, int* __signo )
static int ttyname_r ( int __fildes, char* __buf, size_t __size )