File modules/rp/rp_search.c

  $Revision: 1.15 $

Radix payload (rp) - user level functions for storing data in radix trees
rp_search = search the loaded radix trees using an ascii key
Motto: "And all that for inetnums..."
Status: NOT REVIEWED, TESTED
Design and implementation by: Marek Bukowy

Included Files


Global Variable Lock

pthread_mutex_t Lock
Included from include/ca_defs.h
Visible in:  modules/ac/access_control.c
   modules/ca/ca_configFns.c
   modules/ca/ca_initFn.c
   modules/ca/ca_sanityCheck.c
   modules/ca/ca_sourceLoader.c
   modules/ca/ca_values.c
   modules/er/er_macro.c
   modules/pc/pc_commands.c
   modules/pm/pm_serials.c
   modules/pm/protocol_mirror.c
   modules/pw/protocol_whois.c
   modules/qc/query_command.c
   modules/qi/query_instructions.c
   modules/rp/rp_convert.c
   modules/rp/rp_load.c
   modules/rp/rp_search.c
Used in: ca_get_adminIntElement()modules/ca/ca_configFns.c
  ca_get_adminStrElement()modules/ca/ca_configFns.c
  ca_get_boolean()modules/ca/ca_configFns.c
  ca_get_dirlist()modules/ca/ca_configFns.c
  ca_get_int()modules/ca/ca_configFns.c
  ca_get_string()modules/ca/ca_configFns.c
  ca_set_boolean()modules/ca/ca_configFns.c
  ca_set_string()modules/ca/ca_configFns.c
  ca_srchandle2Intelement()modules/ca/ca_configFns.c
  ca_srchandle2Strelement()modules/ca/ca_configFns.c

Global Function RP_asc_search()

  search.

2 approaches:
1. (most modes): look up all less specifics of beginning and end of range, compare/select/etc.
2. More spec mode: break up the query range into prefixes, [erform a search for each of them. Add all results together.
translates a query into a binary prefix (or prefixes, if range). for registry+space (or if they are zero, for all registries/spaces) finds tree calls RX_bin_search (returning node copies). will not put duplicate entries (composed inetnums). returns some sort of error code :-)
Cuts the number of answers from RX_bin_search down to max_count, but since some of the answers may have been "normalized" in the underlying functions (multiple occurences removed), the result is _at_most_ max_count.
appends to a given list of data blocks (not nodes!)
The EXLESS search on inetnum tree should return the shortest range that was found, by means of comparing span (size) of the range. If there are more of size equal to the smallest one, they are also returned.
returns RX_OK or a code from an underlying function
er_ret_t RP_asc_search ( rx_srch_mt search_mode, int par_a, int par_b, char* key, rp_regid_t reg_id, rp_attr_t attr, GList** finallist, int max_count )
rx_srch_mt search_mode
&nbs;
int par_a
&nbs;
int par_b
&nbs;
char* key
search term: (string) prefix/range/IP
rp_regid_t reg_id
&nbs;
rp_attr_t attr
extra tree id (within the same reg/spc/fam
GList** finallist
answers go here, please
int max_count
max # of answers. RX_ALLANS == unlimited
Prototyped in: include/rp.h
Calls: DF_get_attribute_name()modules/df/defs.c
  ER_dbg_va()modules/er/er.c
  IP_pref_b2_space()modules/ip/ip.c
  IP_sizebits()modules/ip/ip.c
  IP_smart_conv()modules/ip/ip.c
  IP_smart_range()modules/ip/ip.c
  NOERR()modules/er/er.c
  RP_attr2fam()modules/rp/rp_convert.c
  rp_asc_process_datlist()modules/rp/rp_search.c
  rp_begend_preselection()modules/rp/rp_search.c
  rp_preflist_search()modules/rp/rp_search.c
  rp_srch_copyresults()modules/rp/rp_search.c
  RP_tree_get(), RX_bin_search(), RX_text_srch_mode(), TH_acquire_read_lockw(), TH_release_read_lockw(), g_list_first(), g_list_length(), wr_real_clear_list()
Called by: qi_collect_ids()modules/qi/query_instructions.c

Local Function rp_asc_append_datref()

 appends the element pointed to by datref to finallist 
static er_ret_t rp_asc_append_datref ( rx_datref_t* refptr, GList** finallist )
Calls: ER_dbg_va()modules/er/er.c
  g_list_prepend(), memcpy(), wr_real_calloc()
Called by: rp_srch_copyresults()modules/rp/rp_search.c

Local Function rp_asc_process_datlist()

 rp_asc_process_datlist() - helper for RP_asc_search()

fetches the copies of objects from the radix tree into datlist
ASSUMES LOCKED TREE
the behaviour for a default inetnum (range) query is: do an exact match; if it fails, do an exless match on the encompassing prefix for routes(prefixes): do an exless match
So if it's the default search mode on an inetnum tree, and the key is a range, then an exact search is performed on one of the composing prefixes.
Then the resulting data leaves are checked for exact matching with the range queried for. Any dataleaves that do not match are discarded, and if none are left, the procedure falls back to searching for the encompassing prefix. (calculated in the smart_conv routine). Add the dataleaf copies to the list of answers, taking span into account
static er_ret_t rp_asc_process_datlist ( rx_srch_mt search_mode, int par_a, rx_fam_t fam_id, int prefnumber, GList** datlist, ip_range_t* testrang, int* hits )
Calls: ER_dbg_va()modules/er/er.c
  IP_addr_in_rang()modules/ip/ip.c
  IP_rang_span()modules/ip/ip.c
  rp_exclude_datlink()modules/rp/rp_search.c
  rp_exclude_exact_match()modules/rp/rp_search.c
  rp_find_longest_prefix()modules/rp/rp_search.c
  rp_find_smallest_span()modules/rp/rp_search.c
  rp_leaf_occ_inc()modules/rp/rp_search.c
  g_hash_table_destroy(), g_hash_table_new(), g_list_first(), memcmp()
Called by: RP_asc_search()modules/rp/rp_search.c

Local Function rp_begend_preselection()

static void rp_begend_preselection ( GList** datlist, rx_fam_t fam_id, ip_range_t* testrang )
Calls: ER_dbg_va()modules/er/er.c
  IP_addr_in_rang()modules/ip/ip.c
  rp_exclude_datlink()modules/rp/rp_search.c
  g_list_first()
Called by: RP_asc_search()modules/rp/rp_search.c

Local Function rp_exclude_datlink()

static void rp_exclude_datlink ( GList** datlist, GList* element )
Calls: g_list_remove_link(), wr_real_clear_list()
Called by: rp_asc_process_datlist()modules/rp/rp_search.c
  rp_begend_preselection()modules/rp/rp_search.c
  rp_exclude_exact_match()modules/rp/rp_search.c

Local Function rp_exclude_exact_match()

static void rp_exclude_exact_match ( GList** datlist, ip_range_t* testrang )
Calls: ER_dbg_va()modules/er/er.c
  rp_exclude_datlink()modules/rp/rp_search.c
  g_list_first(), memcmp()
Called by: rp_asc_process_datlist()modules/rp/rp_search.c

Local Function rp_find_longest_prefix()

static int rp_find_longest_prefix ( GList** datlist )
Calls: g_list_first()
Called by: rp_asc_process_datlist()modules/rp/rp_search.c

Local Function rp_find_smallest_span()

  this is a helper: goes through a datlist and returns the smallest
  size of a range

works for IPv4 only
static ip_rangesize_t rp_find_smallest_span ( GList* datlist )
Calls: ER_dbg_va()modules/er/er.c
  IP_rang_span()modules/ip/ip.c
  g_list_first()
Called by: rp_asc_process_datlist()modules/rp/rp_search.c

Local Function rp_leaf_occ_inc()

static int rp_leaf_occ_inc ( GHashTable* hash, rx_dataleaf_t* leafptr )
Calls: g_hash_table_insert(), g_hash_table_lookup()
Called by: rp_asc_process_datlist()modules/rp/rp_search.c

Local Function rp_preflist_search()

   helper: 
   this routine goes through the list of prefixes and performs a bin_search
   on each of them; attaches the results to datlist.
static er_ret_t rp_preflist_search ( rx_srch_mt search_mode, int par_a, int par_b, rx_tree_t* mytree, GList** preflist, GList** datlist )
Calls: ER_dbg_va()modules/er/er.c
  IP_pref_b2a()modules/ip/ip.c
  RX_bin_search(), RX_text_srch_mode(), fprintf(), g_list_first()
Called by: RP_asc_search()modules/rp/rp_search.c

Local Function rp_srch_copyresults()

 goes through datlist (list of references "datref") and add copies of 
leaves referenced to the finallist 

maintains its own uniqhash which holds pointers to copied dataleaves.
modifies: finallist
returns: error from wr_malloc
static er_ret_t rp_srch_copyresults ( GList* datlist, GList** finallist, int maxcount )
Calls: ER_dbg_va()modules/er/er.c
  NOERR()modules/er/er.c
  rp_asc_append_datref()modules/rp/rp_search.c
  g_hash_table_destroy(), g_hash_table_insert(), g_hash_table_lookup(), g_hash_table_new(), g_list_first()
Called by: RP_asc_search()modules/rp/rp_search.c