RTRlib
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
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 
71 struct rtr_mgr_group {
72  struct rtr_socket **sockets;
73  unsigned int sockets_len;
74  uint8_t preference;
75  enum rtr_mgr_status status;
76 };
77 
78 typedef void (*rtr_mgr_status_fp)(const struct rtr_mgr_group *, enum rtr_mgr_status, const struct rtr_socket *, void *);
79 
80 struct tommy_list_wrapper;
81 
82 // TODO Add refresh, expire, and retry intervals to config for easier access.
83 struct 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 
131 int 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 
154 int rtr_mgr_add_group(struct rtr_mgr_config *config, const struct rtr_mgr_group *group);
167 int rtr_mgr_remove_group(struct rtr_mgr_config *config, unsigned int preference);
173 void rtr_mgr_free(struct rtr_mgr_config *config);
174 
184 int rtr_mgr_start(struct rtr_mgr_config *config);
185 
192 void rtr_mgr_stop(struct rtr_mgr_config *config);
193 
200 bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config);
201 
212 int 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 
225 int 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 
234 const char *rtr_mgr_status_to_str(enum rtr_mgr_status status);
235 
244 void rtr_mgr_for_each_ipv4_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data);
245 
254 void rtr_mgr_for_each_ipv6_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data);
255 
261 struct rtr_mgr_group *rtr_mgr_get_first_group(struct rtr_mgr_config *config);
262 
263 int 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
274 
283 int rtr_mgr_bgpsec_validate_as_path(const struct rtr_bgpsec *data, struct rtr_mgr_config *config);
284 
295 int rtr_mgr_bgpsec_generate_signature(const struct rtr_bgpsec *data, uint8_t *private_key,
296  struct rtr_signature_seg **new_signature);
297 
303 
310 int rtr_mgr_bgpsec_has_algorithm_suite(uint8_t alg_suite);
311 
317 int rtr_mgr_bgpsec_get_algorithm_suites(const uint8_t **algs_arr);
318 
325 
333 struct rtr_secure_path_seg *rtr_mgr_bgpsec_new_secure_path_seg(uint8_t pcount, uint8_t flags, uint32_t asn);
334 
340 void rtr_mgr_bgpsec_prepend_sec_path_seg(struct rtr_bgpsec *bgpsec, struct rtr_secure_path_seg *new_seg);
341 
351 struct rtr_signature_seg *rtr_mgr_bgpsec_new_signature_seg(uint8_t *ski, uint16_t sig_len, uint8_t *signature);
352 
362 int rtr_mgr_bgpsec_prepend_sig_seg(struct rtr_bgpsec *bgpsec, struct rtr_signature_seg *new_seg);
363 
374 struct 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 
382 void rtr_mgr_bgpsec_free(struct rtr_bgpsec *bgpsec);
383 
390 
399 
408 
409 void rtr_mgr_bgpsec_append_sec_path_seg(struct rtr_bgpsec *bgpsec, struct rtr_secure_path_seg *new_seg);
410 
411 int rtr_mgr_bgpsec_append_sig_seg(struct rtr_bgpsec *bgpsec, struct rtr_signature_seg *new_seg);
412 
413 struct rtr_bgpsec_nlri *rtr_mgr_bgpsec_nlri_new(int nlri_len);
414 
415 void rtr_mgr_bgpsec_nlri_free(struct rtr_bgpsec_nlri *nlri);
416 
417 void rtr_mgr_bgpsec_add_spki_record(struct rtr_mgr_config *config, struct spki_record *record);
418 #endif
419 
420 #endif
421 
The data that is passed to the rtr_mgr_bgpsec_validate_as_path function.
Definition: bgpsec.h:125
A single Secure Path Segment.
Definition: bgpsec.h:73
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. ...
This struct contains the Network Layer Reachability Information (NLRI). The NLRI consists of a prefix...
Definition: bgpsec.h:105
Definition: rtr_mgr.h:52
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_free(struct rtr_mgr_config *config)
Frees all resources that were allocated from the rtr_mgr.
uint8_t * signature
Definition: bgpsec.h:93
Definition: rtr_mgr.h:56
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.
Definition: rtr_mgr.h:54
void rtr_mgr_bgpsec_free(struct rtr_bgpsec *bgpsec)
Free a rtr_bgpsec struct and any Secure Path and Signature Segments it holds.
A single Signature Segment.
Definition: bgpsec.h:88
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.
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.
int rtr_mgr_bgpsec_get_version(void)
Returns the highest supported BGPsec version.
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...
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_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(* 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
rtr_mgr_status
Status of a rtr_mgr_group.
Definition: rtr_mgr.h:50
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.
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
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.
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.
spki_record.
Definition: spkitable.h:38
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.
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_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.
pfx_table.
Definition: trie-pfx.h:65
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.
pfxv_state
Validation states returned from pfx_validate_origin.
Definition: pfx.h:46
Definition: rtr_mgr.h:58
void rtr_mgr_bgpsec_free_signatures(struct rtr_signature_seg *seg)
Free a signature and any signatures that are pointed to.
int rtr_mgr_bgpsec_has_algorithm_suite(uint8_t alg_suite)
Check, if an algorithm suite is supported by RTRlib.
The lrtr_ip_addr struct stores a IPv4 or IPv6 address in host byte order.
Definition: ip.h:38
A RTR socket.
Definition: rtr.h:116
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.
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.
int rtr_mgr_start(struct rtr_mgr_config *config)
Establishes rtr_socket connections.
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
A set of RTR sockets.
Definition: rtr_mgr.h:71
void rtr_mgr_stop(struct rtr_mgr_config *config)
Terminates rtr_socket connections.
const char * rtr_mgr_status_to_str(enum rtr_mgr_status status)
Converts a rtr_mgr_status to a String.
int rtr_mgr_bgpsec_get_algorithm_suites(const uint8_t **algs_arr)
Returns pointer to a list that holds all supported algorithm suites.
bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config)
Check if rtr_mgr_group is fully synchronized with at least one group.
struct rtr_mgr_group * rtr_mgr_get_first_group(struct rtr_mgr_config *config)
Returns the first, thus active group.