RTRlib
Loading...
Searching...
No Matches
rtr_mgr.h
1/*
2 * This file is part of RTRlib.
3 *
4 * This file is subject to the terms and conditions of the MIT license.
5 * See the file LICENSE in the top level directory for more details.
6 *
7 * Website: http://rtrlib.realmv6.org/
8 */
9
33#ifndef RTR_MGR
34#define RTR_MGR
35
36#include "config.h"
37
38#include "rtrlib/pfx/pfx.h"
39#include "rtrlib/spki/spkitable.h"
40#ifdef RTRLIB_BGPSEC_ENABLED
41#include "rtrlib/bgpsec/bgpsec.h"
42#endif
43
44#include <pthread.h>
45#include <stdint.h>
46
59};
60
72 struct rtr_socket **sockets;
73 unsigned int sockets_len;
74 uint8_t preference;
75 enum rtr_mgr_status status;
76};
77
78typedef void (*rtr_mgr_status_fp)(const struct rtr_mgr_group *, enum rtr_mgr_status, const struct rtr_socket *, void *);
79
80struct tommy_list_wrapper;
81
82// TODO Add refresh, expire, and retry intervals to config for easier access.
83struct rtr_mgr_config {
84 struct tommy_list_wrapper *groups;
85 unsigned int len;
86 pthread_rwlock_t mutex;
87 rtr_mgr_status_fp status_fp;
88 void *status_fp_data;
89 struct pfx_table *pfx_table;
90 struct spki_table *spki_table;
91};
92
131int rtr_mgr_init(struct rtr_mgr_config **config_out, struct rtr_mgr_group groups[], const unsigned int groups_len,
132 const unsigned int refresh_interval, const unsigned int expire_interval,
133 const unsigned int retry_interval, const pfx_update_fp update_fp, const spki_update_fp spki_update_fp,
134 const rtr_mgr_status_fp status_fp, void *status_fp_data);
135
154int rtr_mgr_add_group(struct rtr_mgr_config *config, const struct rtr_mgr_group *group);
167int rtr_mgr_remove_group(struct rtr_mgr_config *config, unsigned int preference);
173void rtr_mgr_free(struct rtr_mgr_config *config);
174
184int rtr_mgr_start(struct rtr_mgr_config *config);
185
192void rtr_mgr_stop(struct rtr_mgr_config *config);
193
200bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config);
201
212int rtr_mgr_validate(struct rtr_mgr_config *config, const uint32_t asn, const struct lrtr_ip_addr *prefix,
213 const uint8_t mask_len, enum pfxv_state *result);
214
225int rtr_mgr_get_spki(struct rtr_mgr_config *config, const uint32_t asn, uint8_t *ski, struct spki_record **result,
226 unsigned int *result_count);
227
234const char *rtr_mgr_status_to_str(enum rtr_mgr_status status);
235
244void rtr_mgr_for_each_ipv4_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data);
245
254void rtr_mgr_for_each_ipv6_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data);
255
261struct rtr_mgr_group *rtr_mgr_get_first_group(struct rtr_mgr_config *config);
262
263int rtr_mgr_for_each_group(struct rtr_mgr_config *config, void (*fp)(const struct rtr_mgr_group *group, void *data),
264 void *data);
265/* @} */
266
273#ifdef RTRLIB_BGPSEC_ENABLED
283int rtr_mgr_bgpsec_validate_as_path(const struct rtr_bgpsec *data, struct rtr_mgr_config *config);
284
295int rtr_mgr_bgpsec_generate_signature(const struct rtr_bgpsec *data, uint8_t *private_key,
296 struct rtr_signature_seg **new_signature);
297
303
311
317int rtr_mgr_bgpsec_get_algorithm_suites(const uint8_t **algs_arr);
318
325
333struct rtr_secure_path_seg *rtr_mgr_bgpsec_new_secure_path_seg(uint8_t pcount, uint8_t flags, uint32_t asn);
334
341
351struct rtr_signature_seg *rtr_mgr_bgpsec_new_signature_seg(uint8_t *ski, uint16_t sig_len, uint8_t *signature);
352
363
374struct rtr_bgpsec *rtr_mgr_bgpsec_new(uint8_t alg, uint8_t safi, uint16_t afi, uint32_t my_as, uint32_t target_as,
375 struct rtr_bgpsec_nlri *nlri);
376
382void rtr_mgr_bgpsec_free(struct rtr_bgpsec *bgpsec);
383
390
399
408
409void rtr_mgr_bgpsec_append_sec_path_seg(struct rtr_bgpsec *bgpsec, struct rtr_secure_path_seg *new_seg);
410
411int rtr_mgr_bgpsec_append_sig_seg(struct rtr_bgpsec *bgpsec, struct rtr_signature_seg *new_seg);
412
413struct rtr_bgpsec_nlri *rtr_mgr_bgpsec_nlri_new(int nlri_len);
414
415void rtr_mgr_bgpsec_nlri_free(struct rtr_bgpsec_nlri *nlri);
416
417void rtr_mgr_bgpsec_add_spki_record(struct rtr_mgr_config *config, struct spki_record *record);
418#endif
419
420#endif
int rtr_mgr_bgpsec_generate_signature(const struct rtr_bgpsec *data, uint8_t *private_key, struct rtr_signature_seg **new_signature)
Signing function for a BGPsec_PATH.
struct rtr_bgpsec * rtr_mgr_bgpsec_new(uint8_t alg, uint8_t safi, uint16_t afi, uint32_t my_as, uint32_t target_as, struct rtr_bgpsec_nlri *nlri)
Initializes and returns a pointer to a rtr_bgpsec struct.
int rtr_mgr_bgpsec_prepend_sig_seg(struct rtr_bgpsec *bgpsec, struct rtr_signature_seg *new_seg)
Prepend a given Signature Segment to rtr_bgpsec::sigs. All fields of the new_seg must be filled.
int rtr_mgr_bgpsec_has_algorithm_suite(uint8_t alg_suite)
Check, if an algorithm suite is supported by RTRlib.
void rtr_mgr_bgpsec_free(struct rtr_bgpsec *bgpsec)
Free a rtr_bgpsec struct and any Secure Path and Signature Segments it holds.
int rtr_mgr_bgpsec_get_algorithm_suites(const uint8_t **algs_arr)
Returns pointer to a list that holds all supported algorithm suites.
int rtr_mgr_bgpsec_get_version(void)
Returns the highest supported BGPsec version.
void rtr_mgr_free_secure_path(struct rtr_secure_path_seg *seg)
Free a Secure Path Segment and any segments that are pointed to by rtr_secure_path_seg::next.
struct rtr_signature_seg * rtr_mgr_bgpsec_pop_signature_seg(struct rtr_bgpsec *bgpsec)
Retrieve a pointer to the last appended Signature Segment from a bgpsec struct.
struct rtr_secure_path_seg * rtr_mgr_bgpsec_pop_secure_path_seg(struct rtr_bgpsec *bgpsec)
Retrieve a pointer to the last appended Secure Path Segment from a bgpsec struct.
void rtr_mgr_bgpsec_prepend_sec_path_seg(struct rtr_bgpsec *bgpsec, struct rtr_secure_path_seg *new_seg)
Prepend a given Secure Path Segment to rtr_bgpsec::path.
struct rtr_signature_seg * rtr_mgr_bgpsec_new_signature_seg(uint8_t *ski, uint16_t sig_len, uint8_t *signature)
Return an allocated and initialized Signature.
struct rtr_secure_path_seg * rtr_mgr_bgpsec_new_secure_path_seg(uint8_t pcount, uint8_t flags, uint32_t asn)
Return an allocated and initialized Secure Path Segment.
uint8_t * signature
Definition bgpsec.h:93
int rtr_mgr_bgpsec_validate_as_path(const struct rtr_bgpsec *data, struct rtr_mgr_config *config)
Validation function for AS path validation.
void rtr_mgr_bgpsec_free_signatures(struct rtr_signature_seg *seg)
Free a signature and any signatures that are pointed to.
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
Validation states returned from pfx_validate_origin.
Definition pfx.h:46
void rtr_mgr_free(struct rtr_mgr_config *config)
Frees all resources that were allocated from the rtr_mgr.
bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config)
Check if rtr_mgr_group is fully synchronized with at least one 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.
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.
struct rtr_mgr_group * rtr_mgr_get_first_group(struct rtr_mgr_config *config)
Returns the first, thus active group.
rtr_mgr_status
Status of a rtr_mgr_group.
Definition rtr_mgr.h:50
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.
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.
void rtr_mgr_stop(struct rtr_mgr_config *config)
Terminates rtr_socket connections.
int rtr_mgr_start(struct rtr_mgr_config *config)
Establishes rtr_socket connections.
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.
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.
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.
const char * rtr_mgr_status_to_str(enum rtr_mgr_status status)
Converts a rtr_mgr_status to a String.
@ RTR_MGR_ERROR
Definition rtr_mgr.h:58
@ RTR_MGR_ESTABLISHED
Definition rtr_mgr.h:56
@ RTR_MGR_CONNECTING
Definition rtr_mgr.h:54
@ RTR_MGR_CLOSED
Definition rtr_mgr.h:52
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
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
The lrtr_ip_addr struct stores a IPv4 or IPv6 address in host byte order.
Definition ip.h:38
pfx_table.
Definition trie-pfx.h:65
This struct contains the Network Layer Reachability Information (NLRI). The NLRI consists of a prefix...
Definition bgpsec.h:105
The data that is passed to the rtr_mgr_bgpsec_validate_as_path function.
Definition bgpsec.h:125
A set of RTR sockets.
Definition rtr_mgr.h:71
A single Secure Path Segment.
Definition bgpsec.h:73
A single Signature Segment.
Definition bgpsec.h:88
A RTR socket.
Definition rtr.h:116
spki_record.
Definition spkitable.h:38