Forwarding Information Base (FIB)

FIB implementation. More...

Detailed Description

FIB implementation.

Files

file  table.h
 Types and functions for operating fib tables.
 
file  fib.h
 Types and functions for FIB.
 

Data Structures

struct  rp_address_msg_t
 Routing Protocol (RP) message content to request/reply notification. More...
 
struct  fib_destination_set_entry_t
 entry used to collect available destinations More...
 

Macros

#define FIB_MSG_RP_SIGNAL_UNREACHABLE_DESTINATION   (0x99)
 message type for RP notification: no route to destination available, start route discovery if appropriate
 
#define FIB_MSG_RP_SIGNAL_DESTINATION_USED   (0x98)
 message type for RP notification: entry used
 
#define FIB_MSG_RP_SIGNAL_SOURCE_ROUTE_CREATED   (0x97)
 message type for RP notification: source route created
 
#define FIB_LIFETIME_NO_EXPIRE   (0xFFFFFFFFffffffff)
 indicator of a lifetime that does not expire (2^64 - 1)
 
#define FIB_FLAG_RPL_ROUTE   (1UL << 0)
 flag to identify if a route was set by RPL
 
#define FIB_FLAG_NET_PREFIX_SHIFT   (24)
 flag used as shift for the net prefix length in bits
 
#define FIB_FLAG_NET_PREFIX_MASK   (0xffUL << FIB_FLAG_NET_PREFIX_SHIFT)
 flag used as mask for the net prefix length in bits
 

Functions

void fib_init (fib_table_t *table)
 initializes all FIB entries with 0 More...
 
void fib_deinit (fib_table_t *table)
 de-initializes the FIB entries and source route entries More...
 
int fib_register_rp (fib_table_t *table, uint8_t *prefix, size_t prefix_addr_type_size)
 Registration of a routing protocol handler function. More...
 
int fib_add_entry (fib_table_t *table, kernel_pid_t iface_id, uint8_t *dst, size_t dst_size, uint32_t dst_flags, uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags, uint32_t lifetime)
 Adds a new entry in the corresponding FIB table for global destination and next hop. More...
 
int fib_update_entry (fib_table_t *table, uint8_t *dst, size_t dst_size, uint8_t *next_hop, size_t next_hop_size, uint32_t next_hop_flags, uint32_t lifetime)
 Updates an entry in the FIB table with next hop and lifetime. More...
 
void fib_remove_entry (fib_table_t *table, uint8_t *dst, size_t dst_size)
 removes an entry from the corresponding FIB table More...
 
void fib_flush (fib_table_t *table, kernel_pid_t interface)
 removes all entries from the corresponding FIB table and interface combination More...
 
int fib_get_next_hop (fib_table_t *table, kernel_pid_t *iface_id, uint8_t *next_hop, size_t *next_hop_size, uint32_t *next_hop_flags, uint8_t *dst, size_t dst_size, uint32_t dst_flags)
 provides a next hop for a given destination More...
 
int fib_get_destination_set (fib_table_t *table, uint8_t *prefix, size_t prefix_size, fib_destination_set_entry_t *dst_set, size_t *dst_set_size)
 provides a set of destination addresses matching the given prefix If the out buffer is insufficient low or passed as NULL, the function will continue to count the number of matching entries and provide the number to the caller. More...
 
int fib_sr_create (fib_table_t *table, fib_sr_t **fib_sr, kernel_pid_t sr_iface_id, uint32_t sr_flags, uint32_t sr_lifetime)
 creates a new source route More...
 
int fib_sr_read_head (fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *sr_iface_id, uint32_t *sr_flags, uint32_t *sr_lifetime)
 reads the information from the sr head to the given locations More...
 
int fib_sr_read_destination (fib_table_t *table, fib_sr_t *fib_sr, uint8_t *dst, size_t *dst_size)
 reads the destination address from the sr head to the given location More...
 
int fib_sr_set (fib_table_t *table, fib_sr_t *fib_sr, kernel_pid_t *sr_iface_id, uint32_t *sr_flags, uint32_t *sr_lifetime)
 sets the provided parameters in the given sr header if a given parameter is NULL its considered not to be changed More...
 
int fib_sr_delete (fib_table_t *table, fib_sr_t *fib_sr)
 deletes the sr More...
 
int fib_sr_next (fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t **sr_path_entry)
 iterates to the next entry in the sr_path More...
 
int fib_sr_search (fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t addr_size, fib_sr_entry_t **sr_path_entry)
 searches the entry containing the given address More...
 
int fib_sr_entry_append (fib_table_t *table, fib_sr_t *fib_sr, uint8_t *dst, size_t dst_size)
 append a new entry at the end of the source route, i.e. More...
 
int fib_sr_entry_add (fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t *sr_path_entry, uint8_t *addr, size_t addr_size, bool keep_remaining_route)
 adds a new entry behind a given sr entry More...
 
int fib_sr_entry_delete (fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr, size_t addr_size, bool keep_remaining_route)
 removes an entry from a source route More...
 
int fib_sr_entry_overwrite (fib_table_t *table, fib_sr_t *fib_sr, uint8_t *addr_old, size_t addr_old_size, uint8_t *addr_new, size_t addr_new_size)
 overwrites the address of an entry with a new address More...
 
int fib_sr_entry_get_address (fib_table_t *table, fib_sr_t *fib_sr, fib_sr_entry_t *sr_path_entry, uint8_t *addr, size_t *addr_size)
 writes the address of an entry to the given out pointers More...
 
int fib_sr_get_route (fib_table_t *table, uint8_t *dst, size_t dst_size, kernel_pid_t *sr_iface_id, uint32_t *sr_flags, uint8_t *addr_list, size_t *addr_list_size, size_t *element_size, bool reverse, fib_sr_t **fib_sr)
 copies a source route to the given destination More...
 
int fib_get_num_used_entries (fib_table_t *table)
 returns the actual number of used FIB entries More...
 
void fib_print_notify_rrp (void)
 Prints the kernel_pid_t for all registered RRPs.
 
void fib_print_fib_table (fib_table_t *table)
 Prints the FIB content (does not print the entries) More...
 
void fib_print_routes (fib_table_t *table)
 Prints the FIB content. More...
 
void fib_print_sr (fib_table_t *table, fib_sr_t *sr)
 Prints the given FIB sourceroute. More...
 

Function Documentation

◆ fib_add_entry()

int fib_add_entry ( fib_table_t table,
kernel_pid_t  iface_id,
uint8_t *  dst,
size_t  dst_size,
uint32_t  dst_flags,
uint8_t *  next_hop,
size_t  next_hop_size,
uint32_t  next_hop_flags,
uint32_t  lifetime 
)

Adds a new entry in the corresponding FIB table for global destination and next hop.

Parameters
[in]tablethe fib table the entry should be added to
[in]iface_idthe interface ID
[in]dstthe destination address
[in]dst_sizethe destination address size
[in]dst_flagsthe destination address flags
[in]next_hopthe next hop address to be updated
[in]next_hop_sizethe next hop address size
[in]next_hop_flagsthe next-hop address flags
[in]lifetimethe lifetime in ms to be updates
Returns
0 on success -ENOMEM if the entry cannot be created due to insufficient RAM -EFAULT if dst and/or next_hop is not a valid pointer

◆ fib_deinit()

void fib_deinit ( fib_table_t table)

de-initializes the FIB entries and source route entries

Parameters
[in]tablethe fib instance to de-initialize

◆ fib_flush()

void fib_flush ( fib_table_t table,
kernel_pid_t  interface 
)

removes all entries from the corresponding FIB table and interface combination

Note
if interface is KERNEL_PID_UNDEF, then all entries regardless of the interface will be removed.
Parameters
[in]tablethe fib table to flush
[in]interfaceentries associated with this interface will be removed

◆ fib_get_destination_set()

int fib_get_destination_set ( fib_table_t table,
uint8_t *  prefix,
size_t  prefix_size,
fib_destination_set_entry_t dst_set,
size_t *  dst_set_size 
)

provides a set of destination addresses matching the given prefix If the out buffer is insufficient low or passed as NULL, the function will continue to count the number of matching entries and provide the number to the caller.

Parameters
[in]tablethe fib table that should be searched
[in]prefixthe destination address
[in]prefix_sizethe destination address size
[out]dst_setthe destination addresses matching the prefix
[in,out]dst_set_sizethe number of entries available on in and used on out
Returns
0 on success -EHOSTUNREACH if no entry matches the type in the FIB -ENOBUFS if the size for the found entries is insufficient low The actual needed size is stored then in dst_set_size, however the required size may change in between calls.

◆ fib_get_next_hop()

int fib_get_next_hop ( fib_table_t table,
kernel_pid_t iface_id,
uint8_t *  next_hop,
size_t *  next_hop_size,
uint32_t *  next_hop_flags,
uint8_t *  dst,
size_t  dst_size,
uint32_t  dst_flags 
)

provides a next hop for a given destination

Parameters
[in]tablethe fib table that should be searched
[in,out]iface_idpointer to store the interface ID for the next hop
[out]next_hoppointer where the next hop address should be stored
[in,out]next_hop_sizethe next hop address size. The value is overwritten with the actual next hop size
[out]next_hop_flagsthe next-hop address flags, e.g. compression type
[in]dstthe destination address
[in]dst_sizethe destination address size
[in]dst_flagsthe destination address flags
Returns
0 on success -EHOSTUNREACH if no next hop is available in any FIB table all RRPs are notified before the return -ENOBUFS if the size for the next hop address is insufficient low -EFAULT if dst and/or next_hop is not a valid pointer -EINVAL if one of the other passed out pointers is NULL

◆ fib_get_num_used_entries()

int fib_get_num_used_entries ( fib_table_t table)

returns the actual number of used FIB entries

Parameters
[in]tablethe fib instance to check

◆ fib_init()

void fib_init ( fib_table_t table)

initializes all FIB entries with 0

Parameters
[in]tablethe fib instance to initialize

◆ fib_print_fib_table()

void fib_print_fib_table ( fib_table_t table)

Prints the FIB content (does not print the entries)

Parameters
[in]tablethe fib instance to print

◆ fib_print_routes()

void fib_print_routes ( fib_table_t table)

Prints the FIB content.

Parameters
[in]tablethe fib instance to print

◆ fib_print_sr()

void fib_print_sr ( fib_table_t table,
fib_sr_t sr 
)

Prints the given FIB sourceroute.

Parameters
[in]tablethe fib instance to print
[in]srthe source route to print

◆ fib_register_rp()

int fib_register_rp ( fib_table_t table,
uint8_t *  prefix,
size_t  prefix_addr_type_size 
)

Registration of a routing protocol handler function.

Parameters
[in]tablethe fib table the RP should be registered to
[in]prefixthe prefix handled by the according RP
[in]prefix_addr_type_sizethe size of the address type used for the prefix
Returns
0 on success -ENOMEM if the entry cannot be registered (mximum registrations reached) -EINVAL if the prefix is NULL or the provided size is 0

◆ fib_remove_entry()

void fib_remove_entry ( fib_table_t table,
uint8_t *  dst,
size_t  dst_size 
)

removes an entry from the corresponding FIB table

Parameters
[in]tablethe fib table containing the entry to remove
[in]dstthe destination address
[in]dst_sizethe destination address size

◆ fib_sr_create()

int fib_sr_create ( fib_table_t table,
fib_sr_t **  fib_sr,
kernel_pid_t  sr_iface_id,
uint32_t  sr_flags,
uint32_t  sr_lifetime 
)

creates a new source route

Parameters
[in,out]tablethe table the new source route belongs to
[in,out]fib_srpointer to store the new created source route pointer
[in]sr_iface_idthe interface ID used for the created source route
[in]sr_flagsthe flags for the source route
[in]sr_lifetimethe lifetime in ms of the source route
Returns
0 on success -EFAULT on wrong parameters, i.e. fib_sr is NULL and/or sr_lifetime is 0 -ENOBUFS on insufficient memory, i.e. all source route fields are in use

◆ fib_sr_delete()

int fib_sr_delete ( fib_table_t table,
fib_sr_t fib_sr 
)

deletes the sr

Parameters
[in]tablethe fib instance to access
[in,out]fib_srpointer to the source route to be deleted
Returns
0 on success -EFAULT on fib_sr pointer is NULL

◆ fib_sr_entry_add()

int fib_sr_entry_add ( fib_table_t table,
fib_sr_t fib_sr,
fib_sr_entry_t sr_path_entry,
uint8_t *  addr,
size_t  addr_size,
bool  keep_remaining_route 
)

adds a new entry behind a given sr entry

Parameters
[in]tablethe table with the source route to add the new entry
[in]fib_srpointer to the sr to add a hop address
[in]sr_path_entrypointer to the entry after which we add the new one
[in]addrpointer to the new address bytes
[in]addr_sizethe size in bytes of the address type
[in]keep_remaining_routeindicate if the remaining route after sr_path_entry should be kept and appended after the new entry
Returns
0 on success -EFAULT on fib_sr and/or sr_path_entry and/or addr is NULL -ENOENT on expired lifetime of the source route -EINVAL on the given address is already present in the path

◆ fib_sr_entry_append()

int fib_sr_entry_append ( fib_table_t table,
fib_sr_t fib_sr,
uint8_t *  dst,
size_t  dst_size 
)

append a new entry at the end of the source route, i.e.

a new destination

Parameters
[in]tablethe table with the source route to append the new entry
[in]fib_srpointer to the sr to append a hop address
[in]dstpointer to the new destination address bytes
[in]dst_sizethe size in bytes of the destination address type
Returns
0 on success -EINVAL on the given destination is already on the path in the source route -ENOENT on expired lifetime of the source route -EFAULT on fib_sr and/or dst is NULL

◆ fib_sr_entry_delete()

int fib_sr_entry_delete ( fib_table_t table,
fib_sr_t fib_sr,
uint8_t *  addr,
size_t  addr_size,
bool  keep_remaining_route 
)

removes an entry from a source route

Parameters
[in]tablethe fib instance to access
[in]fib_srpointer to the sr to delete a hop address
[in]addrpointer to the address bytes to delete
[in]addr_sizethe size in bytes of the address type
[in]keep_remaining_routeindicate if the remaining route should be kept and appended after the predecessor of the removed entry
Returns
0 on success -EFAULT on one of the passed pointers is NULL -ENOENT on expired lifetime of the source route

◆ fib_sr_entry_get_address()

int fib_sr_entry_get_address ( fib_table_t table,
fib_sr_t fib_sr,
fib_sr_entry_t sr_path_entry,
uint8_t *  addr,
size_t *  addr_size 
)

writes the address of an entry to the given out pointers

Parameters
[in]tablethe fib instance to access
[in]fib_srpointer to the sr to get a hop address
[in]sr_path_entrypointer to the entry with the address
[out]addrpointer to store the address bytes
[in,out]addr_sizethe size in bytes of the address type
Returns
0 on success -ENOMEM on insufficient memory provided to store the address -EFAULT on one of the passed pointers is NULL -ENOENT on expired lifetime of the source route

◆ fib_sr_entry_overwrite()

int fib_sr_entry_overwrite ( fib_table_t table,
fib_sr_t fib_sr,
uint8_t *  addr_old,
size_t  addr_old_size,
uint8_t *  addr_new,
size_t  addr_new_size 
)

overwrites the address of an entry with a new address

Parameters
[in]tablethe fib instance to access
[in]fib_srpointer to the sr to overwrite a hop address
[in]addr_oldpointer to the address bytes to overwrite
[in]addr_old_sizethe size in bytes of the address type
[in]addr_newpointer to the new address bytes
[in]addr_new_sizethe size in bytes of the address type
Returns
0 on success -EINVAL on the given address is already present in the path -ENOMEM on no memory left to create a new address entry to overwrite the old one -EFAULT on one of the passed pointers is NULL -ENOENT on expired lifetime of the source route

◆ fib_sr_get_route()

int fib_sr_get_route ( fib_table_t table,
uint8_t *  dst,
size_t  dst_size,
kernel_pid_t sr_iface_id,
uint32_t *  sr_flags,
uint8_t *  addr_list,
size_t *  addr_list_size,
size_t *  element_size,
bool  reverse,
fib_sr_t **  fib_sr 
)

copies a source route to the given destination

Parameters
[in]tabletable to search for a source route
[in]dstpointer to the destination address bytes
[in]dst_sizethe size in bytes of the destination address type
[out]sr_iface_idpointer to the store the iface_id for this route
[in,out]sr_flagspointer to store the flags of this route
[out]addr_listpointer to the location for storing the source route addresses
[in,out]addr_list_sizethe number of elements available in addr_list
[in,out]element_sizethe provided size for one element in addr_list
[in]reverseindicator if the hops should be stored in reverse order
[in,out]fib_srpointer for cosecutive receiving matching source routes. If NULL only the first matching source route is returned. If !NULL the pointer will be overwritten with the current returned fib_sr. The FIB skips all entries until the provided fib_sr+1. The fib_sr pointer is only overwritten when a further matching sr has been found.
Note
The actual needed size for an element and the number of elements is stored in addr_list_elements and element_size respectively when the return value is NOT -EFAULT or NOT -EHOSTUNREACH. However,the required size for may change in between calls.
Returns
0 on success, path to destination with equal flags 1 on success, path to destination with distinct flags -EFAULT on one of the provided parameter pointers is NULL -EHOSTUNREACH if no sr for the destination exists in the FIB -ENOBUFS if the size to store all hops is insufficient low

◆ fib_sr_next()

int fib_sr_next ( fib_table_t table,
fib_sr_t fib_sr,
fib_sr_entry_t **  sr_path_entry 
)

iterates to the next entry in the sr_path

Parameters
[in]tablethe fib instance to access
[in]fib_srpointer to the sr to iterate
[in,out]sr_path_entrypointer to the entry for iterating to the next entry
Returns
0 on success 1 on success, end reached -ENOENT on expired lifetime of the source route -EFAULT on fib_sr and/or sr_path_entry is NULL

◆ fib_sr_read_destination()

int fib_sr_read_destination ( fib_table_t table,
fib_sr_t fib_sr,
uint8_t *  dst,
size_t *  dst_size 
)

reads the destination address from the sr head to the given location

Parameters
[in]tablethe fib instance to access
[in]fib_srpointer to the sr to read from
[in,out]dstpointer to the store destination address bytes
[in,out]dst_sizepointer to store the destination address size
Returns
0 on success -ENOENT on expired lifetime of the source route -EFAULT on one of the parameter pointers is NULL -ENOBUFS if the size to store the destination is insufficient low -EHOSTUNREACH on the destination address is not set

◆ fib_sr_read_head()

int fib_sr_read_head ( fib_table_t table,
fib_sr_t fib_sr,
kernel_pid_t sr_iface_id,
uint32_t *  sr_flags,
uint32_t *  sr_lifetime 
)

reads the information from the sr head to the given locations

Parameters
[in]tablethe fib instance to access
[in]fib_srpointer to the sr to read from
[in,out]sr_iface_idpointer to store the iface_id
[in,out]sr_flagspointer to store the flags
[in,out]sr_lifetimepointer to store the current left lifetime
Returns
0 on success -ENOENT on expired lifetime of the source route -EFAULT on fib_sr is NULL

◆ fib_sr_search()

int fib_sr_search ( fib_table_t table,
fib_sr_t fib_sr,
uint8_t *  addr,
size_t  addr_size,
fib_sr_entry_t **  sr_path_entry 
)

searches the entry containing the given address

Parameters
[in]tablethe fib instance to access
[in]fib_srpointer to the sr to search for a hop address
[in]addrpointer to the searched address bytes
[in]addr_sizethe size in bytes of the searched address type
[out]sr_path_entrypointer to the found address entry
Returns
0 on success -EHOSTUNREACH when no address matches on the path -ENOENT on expired lifetime of the source route -EFAULT on one of the given parameter pointer is NULL

◆ fib_sr_set()

int fib_sr_set ( fib_table_t table,
fib_sr_t fib_sr,
kernel_pid_t sr_iface_id,
uint32_t *  sr_flags,
uint32_t *  sr_lifetime 
)

sets the provided parameters in the given sr header if a given parameter is NULL its considered not to be changed

Parameters
[in]tablethe fib instance to access
[in]fib_srpointer to the sr to write to
[in]sr_iface_idpointer to the new iface_id
[in]sr_flagspointer to the new flags
[in]sr_lifetimepointer to store the new lifetime
Returns
0 on success -ENOENT on expired lifetime of the source route -EFAULT on passed fib_sr is NULL

◆ fib_update_entry()

int fib_update_entry ( fib_table_t table,
uint8_t *  dst,
size_t  dst_size,
uint8_t *  next_hop,
size_t  next_hop_size,
uint32_t  next_hop_flags,
uint32_t  lifetime 
)

Updates an entry in the FIB table with next hop and lifetime.

Parameters
[in]tablethe fib table containing the entry to update
[in]dstthe destination address
[in]dst_sizethe destination address size
[in]next_hopthe next hop address to be updated
[in]next_hop_sizethe next hop address size
[in]next_hop_flagsthe next-hop address flags
[in]lifetimethe lifetime in ms to be updates
Returns
0 on success -ENOMEM if the entry cannot be updated due to insufficient RAM -EFAULT if dst and/or next_hop is not a valid pointer