UniRec  2.9.3
Data Structures | Macros | Functions
ip_prefix_search.h File Reference

Init context and prefix search. More...

#include "ipaddr.h"

Go to the source code of this file.

Data Structures

struct  ipps_network_t
 
struct  ipps_network_list_t
 
struct  ipps_interval_t
 
struct  ipps_context_t
 

Macros

#define DATASLOTS   8
 
#define COLLECTORSLOTS   16
 
#define NETWORKSLOTS   16
 

Functions

ipps_context_tipps_init (ipps_network_list_t *networks)
 
int ipps_destroy (ipps_context_t *prefix_context)
 
int ipps_search (ip_addr_t *ip, ipps_context_t *prefix_context, void ***data)
 

Detailed Description

Init context and prefix search.

Author
Erik Sabik xsabi.nosp@m.k02@.nosp@m.stud..nosp@m.fit..nosp@m.vutbr.nosp@m..cz
Ondrej Ploteny xplot.nosp@m.e01@.nosp@m.stud..nosp@m.fit..nosp@m.vutbr.nosp@m..cz
Date
2013
2014
2016

Definition in file ip_prefix_search.h.


Data Structure Documentation

◆ ipps_network_t

struct ipps_network_t

Structure of network and assoc data. Represent input information

Definition at line 64 of file ip_prefix_search.h.

Data Fields
ip_addr_t addr Network IP address.
void * data Pointer to same data.
size_t data_len Number of bytes in 'data'.
uint32_t mask Network mask, CIDR notation, use for indexing.

◆ ipps_network_list_t

struct ipps_network_list_t

Structure of all networks

Definition at line 74 of file ip_prefix_search.h.

Data Fields
uint32_t net_count Number of networks in 'networks' array.
ipps_network_t * networks Pointer to networks array.

◆ ipps_interval_t

struct ipps_interval_t

Structure of IP interval. IP interval is range of all IP addresses between low_ip and high_ip

Definition at line 83 of file ip_prefix_search.h.

Data Fields
size_t array_len Allocated size of 'data_array' => total available slots.
void ** data_array Array of pointers to data.
uint32_t data_cnt Number of currently used data pointers in 'data_array'.
ip_addr_t high_ip High IP of interval.
ip_addr_t low_ip Low IP of interval.

◆ ipps_context_t

struct ipps_context_t

Structure of sorted interval arrays. Used for searching

Definition at line 96 of file ip_prefix_search.h.

Data Fields
uint32_t v4_count Number of intervals in IPv4 array.
ipps_interval_t * v4_prefix_intervals Pointer to IPv4 intervals array.
uint32_t v6_count Number of intervals in IPv6 array.
ipps_interval_t * v6_prefix_intervals Pointer to IPv6 intervals array.

Macro Definition Documentation

◆ COLLECTORSLOTS

#define COLLECTORSLOTS   16

Definition at line 56 of file ip_prefix_search.h.

◆ DATASLOTS

#define DATASLOTS   8

Definition at line 53 of file ip_prefix_search.h.

◆ NETWORKSLOTS

#define NETWORKSLOTS   16

Definition at line 59 of file ip_prefix_search.h.

Function Documentation

◆ ipps_destroy()

int ipps_destroy ( ipps_context_t prefix_context)

Deinitialize interval_search_context structure Dealloc all memory, garbage collector

Parameters
[in]prefix_contextPointer to interval_search_context struct return 0 if deallocis OK, 1 if free fails

Deinitialize interval_search_context structure Dealloc all memory, garbage collector

Parameters
[in]prefix_contextPointer to interval_search_context struct return 0 if dealloc is OK, 1 if free fails

Definition at line 342 of file ip_prefix_search.c.

◆ ipps_init()

ipps_context_t* ipps_init ( ipps_network_list_t network_list)

Initialize interval_search_context structure, fill IPv4 and IPv6 interval_search_context arrays Function compute for all networks in 'network_list' appropriate intervals and copied network data Overlapping intervals are split. Array is sorted by low IP addr of interval. Networks in network list is not necessary sorted, 'ipps_init' mask and sort each network itself

Parameters
[in]network_listPointer to network list structure
Returns
NULL if memory alloc fails, Pointer to interval_search_context structure

Initialize ipps_context_t structure, fill IPv4 and IPv6 ipps_interval arrays Function compute for all networks in 'network_list' appropriate intervals and copied network data Overlapping intervals are split. Array is sorted by low IP addr of interval. Networks in network list is not necessary sorted, 'ipps_init' mask and sort each network itself

Parameters
[in]network_listPointer to network list structure
Returns
NULL if memory alloc fails, Pointer to ipps_context structure

Definition at line 409 of file ip_prefix_search.c.

◆ ipps_search()

int ipps_search ( ip_addr_t ip,
ipps_context_t prefix_context,
void ***  data 
)

Binary search in interval_search_context Binary search 'ip' in intervals interval_search_context, 'ip' is compare with 'low_ip' and 'high_ip' of interval if match, fill 'data' pointer by data_array of the interval and return number of used data slots if no match return 0 and 'data' pointer not fill Optimized for IPv4 or IPv6 search

Parameters
[in]ipPointer to ip address structure
[in]prefix_contextPointer to interval_search_context structure
[out]dataPointer to array of void pointers - pointers to data
Returns
int 0 if no match, >0 Number of data members in matched interval

Binary search in interval_search_context Binary search 'ip' in intervals interval_search_context, 'ip' is compare with 'low_ip' and 'high_ip' of interval. if match, fill 'data' pointer by pointer to data_array of interval and return number of data members if no match return 0 and 'data' pointer not fill Optimized for IPv4 or IPv6 search

Parameters
[in]ipPointer to ip address structure
[in]prefix_contextPointer to interval_search_context structure
[out]dataPointer to array of void pointers - pointers to data
Returns
int 0 if no match, >0 Number of data members in matched interval

Definition at line 924 of file ip_prefix_search.c.