RTRlib¶
Contents:
-
struct
rtr_mgr_config¶ Public Members
-
struct rtr_mgr_group *
groups¶
-
unsigned int
len¶
-
pthread_mutex_t
mutex¶
-
rtr_mgr_status_fp
status_fp¶
-
void *
status_fp_data¶
-
struct rtr_mgr_group *
-
struct
rtr_mgr_group¶ - #include <rtr_mgr.h>
A set of RTR sockets.
- Parameters
sockets: Array of rtr_socket pointer. The tr_socket element of the rtr_socket must be associated with an initialized # transport socket.sockets_len: Number of elements in the sockets array.preference: The preference value of this group. Groups with lower preference values are preferred.status: Status of the group.
Public Members
-
struct rtr_socket **
sockets¶
-
unsigned int
sockets_len¶
-
uint8_t
preference¶
-
rtr_mgr_status
status¶
-
file
rtr_mgr.c - #include “rtrlib/rtr_mgr.h”#include “rtrlib/pfx/trie/trie-pfx.h”#include “rtrlib/spki/hashtable/ht-spkitable.h”#include <stdlib.h>#include <pthread.h>#include <stdio.h>#include <string.h>#include “rtrlib/lib/log.h”
Defines
-
MGR_DBG(fmt, ...) lrtr_dbg("RTR_MGR: " fmt, ## __VA_ARGS__)¶
-
MGR_DBG1(a) lrtr_dbg("RTR_MGR: " a)¶
Functions
-
int
rtr_mgr_find_group(const struct rtr_mgr_config *config, const struct rtr_socket *sock, unsigned int *ind)¶
-
int
rtr_mgr_config_cmp(const void *a, const void *b)¶
-
bool
rtr_mgr_config_status_is_synced(const struct rtr_mgr_group *config)¶
-
static void
set_status(const struct rtr_mgr_config *conf, struct rtr_mgr_group *group, enum rtr_mgr_status mgr_status, const struct rtr_socket *rtr_sock)¶
-
static int
rtr_mgr_start_sockets(struct rtr_mgr_group *group)¶
-
static void
rtr_mgr_close_less_preferable_groups(const struct rtr_socket *sock, struct rtr_mgr_config *config, unsigned int my_group_idx)¶
-
static struct rtr_mgr_group *
get_best_inactive_rtr_mgr_group(struct rtr_mgr_config *config, unsigned int my_group_idx)¶
-
static bool
is_some_rtr_mgr_group_established(struct rtr_mgr_config *config)¶
-
static void
_rtr_mgr_cb_state_shutdown(const struct rtr_socket *sock, struct rtr_mgr_config *config, unsigned int ind)¶
-
static void
_rtr_mgr_cb_state_established(const struct rtr_socket *sock, struct rtr_mgr_config *config, unsigned int ind)¶
-
static void
_rtr_mgr_cb_state_connecting(const struct rtr_socket *sock, struct rtr_mgr_config *config, unsigned int ind)¶
-
static void
_rtr_mgr_cb_state_error(const struct rtr_socket *sock, struct rtr_mgr_config *config, unsigned int ind)¶
-
static void
rtr_mgr_cb(const struct rtr_socket *sock, const enum rtr_socket_state state, void *data)¶
-
int
rtr_mgr_init(struct rtr_mgr_config **config_out, struct rtr_mgr_group groups[], const unsigned int groups_len, const unsigned int refresh_interval, const unsigned int expire_interval, const unsigned int retry_interval, const pfx_update_fp update_fp, const spki_update_fp spki_update_fp, const rtr_mgr_status_fp status_fp, void *status_fp_data)¶ Initializes a rtr_mgr_config.
- Return
- RTR_ERROR If an error occurred
- Return
- RTR_INVALID_PARAM If refresh_interval or expire_interval is invalid.
- Return
- RTR_SUCCESS On success.
- Parameters
config_out: The rtr_mgr_config that will be initialized by this function. On error, *config_out will be NULL!groups: Array of rtr_mgr_group. Every RTR socket in an rtr_mgr_group must be assoziated with an initialized transport socket. A Transport socket is only allowed to be associated with one rtr socket. The preference values must be unique in the group array. More than one rtr_mgr_group with the same preference value isn’t allowed.groups_len: Number of elements in the groups array.refresh_interval: Interval in seconds between serial queries that are sent to the server. Must be >= 1 and <= 86400s (1d), recommended default is 3600s (1h).expire_interval: Stored validation records will be deleted if cache was unable to refresh data for this period. The value should be twice the refresh_interval and must be >= 600s (10min) and <= 172800s (2d). The recommended default is 7200s (2h).retry_interval: This parameter tells the router how long to wait (in seconds) before retrying a failed Serial Query or Reset Query. The value must be >= 1s and <= 7200s (2h). The recommended default is 600s (10min).update_fp: Pointer to pfx_update_fp callback, that is executed for every added and removed pfx_record.spki_update_fp: Pointer to spki_update_fp callback, that is executed for every added and removed spki_record.status_fp: Pointer to a function that is called if the connection status from one of the socket groups is changed.status_fp_data: Pointer to a memory area that is passed to the status_fp function. Memory area can be freely used to pass user-defined data to the status_fp callback.
-
int
rtr_mgr_start(struct rtr_mgr_config *config)¶ Establishes rtr_socket connections.
Establishes the connection with the rtr_sockets of the group with the lowest preference value and handles errors as defined in the RPKI-RTR protocol.
- Return
- RTR_SUCCESS On success
- Return
- RTR_ERROR On error
- Parameters
config: Pointer to an initialized rtr_mgr_config.
-
bool
rtr_mgr_conf_in_sync(struct rtr_mgr_config *config)¶ Check if rtr_mgr_group is fully synchronized with at least one group.
- Return
- true If pfx_table stores non-outdated pfx_records
- Return
- false If pfx_table isn’t fully synchronized with at least one group.
- Parameters
config: The rtr_mgr_config.
-
void
rtr_mgr_free(struct rtr_mgr_config *config)¶ Frees all resources that were allocated from the rtr_mgr.
rtr_mgr_stop must be called before, to shutdown all rtr_sockets.
- Parameters
config: rtr_mgr_config.
-
int
rtr_mgr_validate(struct rtr_mgr_config *config, const uint32_t asn, const struct lrtr_ip_addr *prefix, const uint8_t mask_len, enum pfxv_state *result)¶ Validates the origin of a BGP-Route.
- Return
- PFX_SUCCESS On success.
- Return
- PFX_ERROR If an error occurred.
- Parameters
config: The rtr_mgr_configasn: Autonomous system number of the Origin-AS of the prefixprefix: Announced network prefixmask_len: Length of the network mask of the announced prefixresult: Outcome of the validation
-
int
rtr_mgr_get_spki(struct rtr_mgr_config *config, const uint32_t asn, uint8_t *ski, struct spki_record *result, unsigned int *result_count)¶ Returns all SPKI records which match the given ASN and SKI.
- Return
- SPKI_SUCCESS On success
- Return
- SPKI_ERROR If an error occurred
- Parameters
config:asn: Autonomous system number of the Origin-ASski: the SKI to search forresult: a array of all matching spki_recordsresult_count: number of returned spki_records
-
void
rtr_mgr_stop(struct rtr_mgr_config *config)¶ Terminates rtr_socket connections.
Terminates all rtr_socket connections defined in the config. All pfx_records received from these sockets will be purged.
- Parameters
config: The rtr_mgr_config struct
-
const char *
rtr_mgr_status_to_str(enum rtr_mgr_status status)¶ Converts a rtr_mgr_status to a String.
- Return
- NULL If status isn’t a valid rtr_mgr_status.
- Return
- !=NULL The rtr_rtr_mgr_status as String.
- Parameters
status: state to convert to a string.
-
void rtr_mgr_for_each_ipv4_record(struct rtr_mgr_config * config, void(fp)(const struct pfx_record *, void *data), void * data)
-
void rtr_mgr_for_each_ipv6_record(struct rtr_mgr_config * config, void(fp)(const struct pfx_record *, void *data), void * data)
Variables
-
const char *const
mgr_str_status[] = { [RTR_MGR_CLOSED] = "RTR_MGR_CLOSED", [RTR_MGR_CONNECTING] = "RTR_MGR_CONNECTING", [RTR_MGR_ESTABLISHED] = "RTR_MGR_ESTABLISHED", [RTR_MGR_ERROR] = "RTR_MGR_ERROR", }¶
-
-
file
rtr_mgr.h - #include “rtrlib/pfx/pfx.h”#include “rtrlib/rtr/rtr.h”#include “rtrlib/spki/spkitable.h”
Typedefs
-
typedef void (*
rtr_mgr_status_fp)(const struct rtr_mgr_group *, enum rtr_mgr_status, const struct rtr_socket *, void *)¶
Enums
-
enum
rtr_mgr_status¶ Status of a rtr_mgr_group.
Values:
-
RTR_MGR_CLOSED¶ RTR sockets are disconnected
-
RTR_MGR_CONNECTING¶ RTR sockets trying to establish a connection.
-
RTR_MGR_ESTABLISHED¶ All RTR sockets of the group are synchronized with rtr servers.
-
RTR_MGR_ERROR¶ Error occurred on at least one RTR socket.
-
Functions
-
int
rtr_mgr_init(struct rtr_mgr_config **config_out, struct rtr_mgr_group groups[], const unsigned int groups_len, const unsigned int refresh_interval, const unsigned int expire_interval, const unsigned int retry_interval, const pfx_update_fp update_fp, const spki_update_fp spki_update_fp, const rtr_mgr_status_fp status_fp, void *status_fp_data)¶ Initializes a rtr_mgr_config.
- Return
- RTR_ERROR If an error occurred
- Return
- RTR_INVALID_PARAM If refresh_interval or expire_interval is invalid.
- Return
- RTR_SUCCESS On success.
- Parameters
config_out: The rtr_mgr_config that will be initialized by this function. On error, *config_out will be NULL!groups: Array of rtr_mgr_group. Every RTR socket in an rtr_mgr_group must be assoziated with an initialized transport socket. A Transport socket is only allowed to be associated with one rtr socket. The preference values must be unique in the group array. More than one rtr_mgr_group with the same preference value isn’t allowed.groups_len: Number of elements in the groups array.refresh_interval: Interval in seconds between serial queries that are sent to the server. Must be >= 1 and <= 86400s (1d), recommended default is 3600s (1h).expire_interval: Stored validation records will be deleted if cache was unable to refresh data for this period. The value should be twice the refresh_interval and must be >= 600s (10min) and <= 172800s (2d). The recommended default is 7200s (2h).retry_interval: This parameter tells the router how long to wait (in seconds) before retrying a failed Serial Query or Reset Query. The value must be >= 1s and <= 7200s (2h). The recommended default is 600s (10min).update_fp: Pointer to pfx_update_fp callback, that is executed for every added and removed pfx_record.spki_update_fp: Pointer to spki_update_fp callback, that is executed for every added and removed spki_record.status_fp: Pointer to a function that is called if the connection status from one of the socket groups is changed.status_fp_data: Pointer to a memory area that is passed to the status_fp function. Memory area can be freely used to pass user-defined data to the status_fp callback.
-
void
rtr_mgr_free(struct rtr_mgr_config *config)¶ Frees all resources that were allocated from the rtr_mgr.
rtr_mgr_stop must be called before, to shutdown all rtr_sockets.
- Parameters
config: rtr_mgr_config.
-
int
rtr_mgr_start(struct rtr_mgr_config *config)¶ Establishes rtr_socket connections.
Establishes the connection with the rtr_sockets of the group with the lowest preference value and handles errors as defined in the RPKI-RTR protocol.
- Return
- RTR_SUCCESS On success
- Return
- RTR_ERROR On error
- Parameters
config: Pointer to an initialized rtr_mgr_config.
-
void
rtr_mgr_stop(struct rtr_mgr_config *config)¶ Terminates rtr_socket connections.
Terminates all rtr_socket connections defined in the config. All pfx_records received from these sockets will be purged.
- Parameters
config: The rtr_mgr_config struct
-
bool
rtr_mgr_conf_in_sync(struct rtr_mgr_config *config)¶ Check if rtr_mgr_group is fully synchronized with at least one group.
- Return
- true If pfx_table stores non-outdated pfx_records
- Return
- false If pfx_table isn’t fully synchronized with at least one group.
- Parameters
config: The rtr_mgr_config.
-
int
rtr_mgr_validate(struct rtr_mgr_config *config, const uint32_t asn, const struct lrtr_ip_addr *prefix, const uint8_t mask_len, enum pfxv_state *result)¶ Validates the origin of a BGP-Route.
- Return
- PFX_SUCCESS On success.
- Return
- PFX_ERROR If an error occurred.
- Parameters
config: The rtr_mgr_configasn: Autonomous system number of the Origin-AS of the prefixprefix: Announced network prefixmask_len: Length of the network mask of the announced prefixresult: Outcome of the validation
-
int
rtr_mgr_get_spki(struct rtr_mgr_config *config, const uint32_t asn, uint8_t *ski, struct spki_record *result, unsigned int *result_count)¶ Returns all SPKI records which match the given ASN and SKI.
- Return
- SPKI_SUCCESS On success
- Return
- SPKI_ERROR If an error occurred
- Parameters
config:asn: Autonomous system number of the Origin-ASski: the SKI to search forresult: a array of all matching spki_recordsresult_count: number of returned spki_records
-
const char *
rtr_mgr_status_to_str(enum rtr_mgr_status status)¶ Converts a rtr_mgr_status to a String.
- Return
- NULL If status isn’t a valid rtr_mgr_status.
- Return
- !=NULL The rtr_rtr_mgr_status as String.
- Parameters
status: state to convert to a string.
-
void
rtr_mgr_for_each_ipv4_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data)¶ Iterates over all IPv4 records in the pfx_table.
For every pfx_record the function fp is called. The pfx_record and the data pointer is passed to the fp.
- Parameters
config: rtr_mgr_configfp: Pointer to callback function with signaturepfx_for_each_fp.data: This parameter is forwarded to the callback function.
-
void
rtr_mgr_for_each_ipv6_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data)¶ Iterates over all IPv6 records in the pfx_table.
For every pfx_record the function fp is called. The pfx_record and the data pointer is passed to the fp.
- Parameters
config: rtr_mgr_configfp: Pointer to callback function with signaturepfx_for_each_fp.data: This parameter is forwarded to the callback function.
-
typedef void (*
-
file
rtrlib.h - #include “rtrlib/transport/transport.h”#include “rtrlib/transport/tcp/tcp_transport.h”#include “rtrlib/rtr_mgr.h”#include “rtrlib/pfx/trie/trie-pfx.h”#include “rtrlib/rtr/rtr.h”#include “rtrlib/lib/utils.h”#include “rtrlib/transport/ssh/ssh_transport.h”
-
group
mod_rtr_mgr_h The RTR connection manager maintains multiple groups of RTR sockets.
The RTR connection manager is initialized with one or multiple groups of rtr_sockets. Each group is configured with a preference value and contains a set of rtr_socket RTR sockets. It connects to all sockets of the group with the lowest preference value. In case of failures, the connection manager establishes connections to RTR servers of another group with the next lowest preference value (see IETF RFC 6810 for details about error handling). RTRlib also supports a Retry Interval (see draft-ietf-sidr-rpki-rtr-rfc6810-bis). If a more preferred group is online again, the RTR connection manager will switch back and close connections to the caches of the less preferred group.
Typedefs
-
typedef void (*
rtr_mgr_status_fp)(const struct rtr_mgr_group *, enum rtr_mgr_status, const struct rtr_socket *, void *)¶
Enums
-
enum
rtr_mgr_status¶ Status of a rtr_mgr_group.
Values:
-
RTR_MGR_CLOSED¶ RTR sockets are disconnected
-
RTR_MGR_CONNECTING¶ RTR sockets trying to establish a connection.
-
RTR_MGR_ESTABLISHED¶ All RTR sockets of the group are synchronized with rtr servers.
-
RTR_MGR_ERROR¶ Error occurred on at least one RTR socket.
-
-
typedef void (*
-
dir
/Volumes/workspace/github/smlng/rtrlib/rtrlib
-
example
rtr_mgr.c Usage example of the RTR connection manager.
#include <stdio.h> #include <stdlib.h> #include "rtrlib/rtrlib.h" int main(){ //create a SSH transport socket char ssh_host[] = "123.231.123.221"; char ssh_user[] = "rpki_user"; char ssh_hostkey[] = "/etc/rpki-rtr/hostkey"; char ssh_privkey[] = "/etc/rpki-rtr/client.priv"; struct tr_socket tr_ssh; struct tr_ssh_config config = { ssh_host, //IP 22, //Port NULL, //Source address ssh_user, ssh_hostkey, //Server hostkey ssh_privkey, //Private key }; tr_ssh_init(&config, &tr_ssh); //create a TCP transport socket struct tr_socket tr_tcp; char tcp_host[] = "rpki-validator.realmv6.org"; char tcp_port[] = "8282"; struct tr_tcp_config tcp_config = { tcp_host, //IP tcp_port, //Port NULL //Source address }; tr_tcp_init(&tcp_config, &tr_tcp); //create 3 rtr_sockets and associate them with the transprort sockets struct rtr_socket rtr_ssh, rtr_tcp; rtr_ssh.tr_socket = &tr_ssh; rtr_tcp.tr_socket = &tr_tcp; //create a rtr_mgr_group array with 2 elements struct rtr_mgr_group groups[2]; //The first group contains both TCP RTR sockets groups[0].sockets = malloc(sizeof(struct rtr_socket*)); groups[0].sockets_len = 1; groups[0].sockets[0] = &rtr_tcp; groups[0].preference = 1; //Preference value of this group //The seconds group contains only the SSH RTR socket groups[1].sockets = malloc(1 * sizeof(struct rtr_socket*)); groups[1].sockets_len = 1; groups[1].sockets[0] = &rtr_ssh; groups[1].preference = 2; //create a rtr_mgr_config struct that stores the group //initialize all rtr_sockets in the server pool with the same settings struct rtr_mgr_config *conf; int ret = rtr_mgr_init(&conf, groups, 2, 30, 600, 600, NULL, NULL, NULL, NULL); //start the connection manager rtr_mgr_start(conf); //wait till at least one rtr_mgr_group is fully synchronized with the server while(!rtr_mgr_conf_in_sync(conf)) { sleep(1); } //validate the BGP-Route 10.10.0.0/24, origin ASN: 12345 struct lrtr_ip_addr pref; lrtr_ip_str_to_addr("10.10.0.0", &pref); enum pfxv_state result; const uint8_t mask = 24; rtr_mgr_validate(conf, 12345, &pref, mask, &result); //output the result of the prefix validation above //to showcase the returned states. char buffer[INET_ADDRSTRLEN]; lrtr_ip_addr_to_str(&pref, buffer, sizeof(buffer)); printf("RESULT: The prefix %s/%i ", buffer, mask); switch(result) { case BGP_PFXV_STATE_VALID: printf("is valid.\n"); break; case BGP_PFXV_STATE_INVALID: printf("is invalid.\n"); break; case BGP_PFXV_STATE_NOT_FOUND: printf("was not found.\n"); break; default: break; } rtr_mgr_stop(conf); rtr_mgr_free(conf); free(groups[0].sockets); free(groups[1].sockets); }