Loading...
Searching...
No Matches
rtr_mgr.h
/*
* This file is part of RTRlib.
*
* This file is subject to the terms and conditions of the MIT license.
* See the file LICENSE in the top level directory for more details.
*
* Website: http://rtrlib.realmv6.org/
*/
#ifndef RTR_MGR
#define RTR_MGR
#include "rtrlib/pfx/pfx.h"
#include "rtrlib/spki/spkitable.h"
#include <pthread.h>
#include <stdint.h>
enum rtr_mgr_status {
RTR_MGR_CLOSED,
RTR_MGR_CONNECTING,
RTR_MGR_ESTABLISHED,
RTR_MGR_ERROR,
};
struct rtr_mgr_group {
struct rtr_socket **sockets;
unsigned int sockets_len;
uint8_t preference;
enum rtr_mgr_status status;
};
typedef void (*rtr_mgr_status_fp)(const struct rtr_mgr_group *, enum rtr_mgr_status, const struct rtr_socket *, void *);
struct tommy_list_wrapper;
// TODO Add refresh, expire, and retry intervals to config for easier access.
struct rtr_mgr_config {
struct tommy_list_wrapper *groups;
unsigned int len;
pthread_mutex_t mutex;
rtr_mgr_status_fp status_fp;
void *status_fp_data;
struct pfx_table *pfx_table;
struct spki_table *spki_table;
};
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);
int rtr_mgr_add_group(struct rtr_mgr_config *config, const struct rtr_mgr_group *group);
int rtr_mgr_remove_group(struct rtr_mgr_config *config, unsigned int preference);
void rtr_mgr_free(struct rtr_mgr_config *config);
int rtr_mgr_start(struct rtr_mgr_config *config);
void rtr_mgr_stop(struct rtr_mgr_config *config);
bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *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);
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);
const char *rtr_mgr_status_to_str(enum rtr_mgr_status status);
void rtr_mgr_for_each_ipv4_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data);
void rtr_mgr_for_each_ipv6_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data);
struct rtr_mgr_group *rtr_mgr_get_first_group(struct rtr_mgr_config *config);
int rtr_mgr_for_each_group(struct rtr_mgr_config *config, void (*fp)(const struct rtr_mgr_group *group, void *data),
void *data);
#endif
pfx_for_each_fp
void(* pfx_for_each_fp)(const struct pfx_record *pfx_record, void *data)
A function pointer that is called for each record in the pfx_table.
Definition pfx.h:65
pfxv_state
pfxv_state
Validation states returned from pfx_validate_origin.
Definition pfx.h:46
rtr_mgr_free
void rtr_mgr_free(struct rtr_mgr_config *config)
Frees all resources that were allocated from the rtr_mgr.
rtr_mgr_conf_in_sync
bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config)
Check if rtr_mgr_group is fully synchronized with at least one group.
rtr_mgr_add_group
int rtr_mgr_add_group(struct rtr_mgr_config *config, const struct rtr_mgr_group *group)
Adds a new rtr_mgr_group to the linked list of a initialized config.
rtr_mgr_remove_group
int rtr_mgr_remove_group(struct rtr_mgr_config *config, unsigned int preference)
Removes an existing rtr_mgr_group from the linked list of config.
rtr_mgr_get_first_group
struct rtr_mgr_group * rtr_mgr_get_first_group(struct rtr_mgr_config *config)
Returns the first, thus active group.
rtr_mgr_status
rtr_mgr_status
Status of a rtr_mgr_group.
Definition rtr_mgr.h:45
rtr_mgr_get_spki
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.
rtr_mgr_for_each_ipv6_record
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.
rtr_mgr_stop
void rtr_mgr_stop(struct rtr_mgr_config *config)
Terminates rtr_socket connections.
rtr_mgr_start
int rtr_mgr_start(struct rtr_mgr_config *config)
Establishes rtr_socket connections.
rtr_mgr_validate
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.
rtr_mgr_for_each_ipv4_record
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.
rtr_mgr_init
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.
rtr_mgr_status_to_str
const char * rtr_mgr_status_to_str(enum rtr_mgr_status status)
Converts a rtr_mgr_status to a String.
RTR_MGR_ERROR
@ RTR_MGR_ERROR
Definition rtr_mgr.h:53
RTR_MGR_ESTABLISHED
@ RTR_MGR_ESTABLISHED
Definition rtr_mgr.h:51
RTR_MGR_CONNECTING
@ RTR_MGR_CONNECTING
Definition rtr_mgr.h:49
RTR_MGR_CLOSED
@ RTR_MGR_CLOSED
Definition rtr_mgr.h:47
spki_update_fp
void(* spki_update_fp)(struct spki_table *spki_table, const struct spki_record record, const bool added)
A function pointer that is called if an record was added to the spki_table or was removed from the sp...
Definition spkitable.h:52
pfx_update_fp
void(* pfx_update_fp)(struct pfx_table *pfx_table, const struct pfx_record record, const bool added)
A function pointer that is called if an record was added to the pfx_table or was removed from the pfx...
Definition trie-pfx.h:56
lrtr_ip_addr
The lrtr_ip_addr struct stores a IPv4 or IPv6 address in host byte order.
Definition ip.h:38
pfx_table
pfx_table.
Definition trie-pfx.h:65
rtr_mgr_group
A set of RTR sockets.
Definition rtr_mgr.h:66
rtr_socket
A RTR socket.
Definition rtr.h:116
spki_record
spki_record.
Definition spkitable.h:38