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 #include <stdint.h>
36 #include <pthread.h>
37 
38 #include "rtrlib/pfx/pfx.h"
39 #include "rtrlib/spki/spkitable.h"
40 #include "rtrlib/spki/hashtable/hashtable_forward.h"
41 
54 };
55 
66 struct rtr_mgr_group {
67  struct rtr_socket **sockets;
68  unsigned int sockets_len;
69  uint8_t preference;
70  enum rtr_mgr_status status;
71 };
72 
73 typedef void (*rtr_mgr_status_fp)(const struct rtr_mgr_group *,
74  enum rtr_mgr_status,
75  const struct rtr_socket *,
76  void *);
77 
78 //TODO Add refresh, expire, and retry intervals to config for easier access.
79 struct rtr_mgr_config {
80  tommy_list groups;
81  unsigned int len;
82  pthread_mutex_t mutex;
83  rtr_mgr_status_fp status_fp;
84  void *status_fp_data;
85  struct pfx_table *pfx_table;
86  struct spki_table *spki_table;
87 };
88 
127 int rtr_mgr_init(struct rtr_mgr_config **config_out,
128  struct rtr_mgr_group groups[],
129  const unsigned int groups_len,
130  const unsigned int refresh_interval,
131  const unsigned int expire_interval,
132  const unsigned int retry_interval,
133  const pfx_update_fp update_fp,
135  const rtr_mgr_status_fp status_fp,
136  void *status_fp_data);
137 
156 int rtr_mgr_add_group(struct rtr_mgr_config *config,
157  const struct rtr_mgr_group *group);
170 int rtr_mgr_remove_group(struct rtr_mgr_config *config,
171  unsigned int preference);
177 void rtr_mgr_free(struct rtr_mgr_config *config);
178 
188 int rtr_mgr_start(struct rtr_mgr_config *config);
189 
196 void rtr_mgr_stop(struct rtr_mgr_config *config);
197 
204 bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config);
205 
216 int rtr_mgr_validate(struct rtr_mgr_config *config,
217  const uint32_t asn,
218  const struct lrtr_ip_addr *prefix,
219  const uint8_t mask_len,
220  enum pfxv_state *result);
221 
232 int rtr_mgr_get_spki(struct rtr_mgr_config *config,
233  const uint32_t asn,
234  uint8_t *ski,
235  struct spki_record **result,
236  unsigned int *result_count);
237 
244 const char *rtr_mgr_status_to_str(enum rtr_mgr_status status);
245 
254 void rtr_mgr_for_each_ipv4_record(struct rtr_mgr_config *config,
255  pfx_for_each_fp fp,
256  void *data);
257 
266 void rtr_mgr_for_each_ipv6_record(struct rtr_mgr_config *config,
267  pfx_for_each_fp fp,
268  void *data);
269 
275 struct rtr_mgr_group *rtr_mgr_get_first_group(struct rtr_mgr_config *config);
276 
277 int rtr_mgr_for_each_group(struct rtr_mgr_config *config,
278  void (*fp)(const struct rtr_mgr_group *group,
279  void *data),
280  void *data);
281 #endif
282 /* @} */
Definition: rtr_mgr.h:47
void rtr_mgr_free(struct rtr_mgr_config *config)
Frees all resources that were allocated from the rtr_mgr.
Definition: rtr_mgr.h:51
Definition: rtr_mgr.h:49
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_status
Status of a rtr_mgr_group.
Definition: rtr_mgr.h:45
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:91
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(* 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: pfx.h:83
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:37
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.
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:49
Definition: rtr_mgr.h:53
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:109
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.
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:51
A set of RTR sockets.
Definition: rtr_mgr.h:66
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.
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.