RTRlib
 All Data Structures Functions Typedefs Enumerations Enumerator Groups Pages
rtr_mgr.h
1 /*
2  * This file is part of RTRlib.
3  *
4  * RTRlib is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or (at your
7  * option) any later version.
8  *
9  * RTRlib is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
12  * License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public License
15  * along with RTRlib; see the file COPYING.LESSER.
16  *
17  * INET group, Hamburg University of Applied Sciences,
18  * CST group, Freie Universitaet Berlin
19  * Website: http://rpki.realmv6.org/
20  */
21 
22 
40 #ifndef RTR_MGR
41 #define RTR_MGR
42 #include "rtrlib/pfx/pfx.h"
43 #include "rtrlib/rtr/rtr.h"
44 #include "rtrlib/spki/spkitable.h"
45 
52 
55 
58 
61 };
62 
70 struct rtr_mgr_group {
71  struct rtr_socket **sockets;
72  unsigned int sockets_len;
73  uint8_t preference;
74  enum rtr_mgr_status status;
75 };
76 
77 typedef void (*rtr_mgr_status_fp)(const struct rtr_mgr_group *, enum rtr_mgr_status, const struct rtr_socket *, void *);
78 
79 
83 typedef void (*pfx_for_each_fp)(const struct pfx_record *pfx_record, void *data);
84 
85 struct rtr_mgr_config {
86  struct rtr_mgr_group *groups;
87  unsigned int len;
88  pthread_mutex_t mutex;
89  rtr_mgr_status_fp status_fp;
90  void *status_fp_data;
91 };
92 
118 struct rtr_mgr_config *rtr_mgr_init(struct rtr_mgr_group groups[], const unsigned int groups_len,
119  const unsigned int refresh_interval, const unsigned int expire_interval,
120  const pfx_update_fp update_fp,
122  const rtr_mgr_status_fp status_fp,
123  void *status_fp_data);
124 
130 void rtr_mgr_free(struct rtr_mgr_config *config);
131 
138 int rtr_mgr_start(struct rtr_mgr_config *config);
139 
144 void rtr_mgr_stop(struct rtr_mgr_config *config);
145 
152 bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config);
153 
164 int rtr_mgr_validate(struct rtr_mgr_config *config, const uint32_t asn, const struct ip_addr *prefix, const uint8_t mask_len, enum pfxv_state *result);
165 
166 
177 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);
178 
185 const char *rtr_mgr_status_to_str(enum rtr_mgr_status status);
186 
195 void rtr_mgr_for_each_ipv4_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data);
196 
205 void rtr_mgr_for_each_ipv6_record(struct rtr_mgr_config *config, pfx_for_each_fp fp, void *data);
206 
207 #endif
208 /* @} */
Definition: rtr_mgr.h:51
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...
Definition: rtr_mgr.c:295
Definition: rtr_mgr.h:57
Definition: rtr_mgr.h:54
void(* pfx_for_each_fp)(const struct pfx_record *pfx_record, void *data)
Definition: rtr_mgr.h:83
The ip_addr struct stores a IPv4 or IPv6 address in host byte order.
Definition: ip.h:44
rtr_mgr_status
Status of a rtr_mgr_group.
Definition: rtr_mgr.h:49
int rtr_mgr_validate(struct rtr_mgr_config *config, const uint32_t asn, const struct ip_addr *prefix, const uint8_t mask_len, enum pfxv_state *result)
Validates the origin of a BGP-Route.
Definition: rtr_mgr.c:307
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.
Definition: rtr_mgr.c:312
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:92
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:67
pfxv_state
Validation states returned from pfx_validate_origin.
Definition: pfx.h:58
Definition: rtr_mgr.h:60
A RTR socket.
Definition: rtr.h:113
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 the connection with the rtr_sockets of the group with the lowest preference value and han...
Definition: rtr_mgr.c:276
pfx_record.
Definition: pfx.h:78
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:81
A set of RTR sockets.
Definition: rtr_mgr.h:70
void rtr_mgr_stop(struct rtr_mgr_config *config)
Terminates all rtr_socket connections that are defined in the config. All pfx_records received from t...
Definition: rtr_mgr.c:317
const char * rtr_mgr_status_to_str(enum rtr_mgr_status status)
Converts a rtr_mgr_status to a String.
Definition: rtr_mgr.c:326
struct rtr_mgr_config * rtr_mgr_init(struct rtr_mgr_group groups[], const unsigned int groups_len, const unsigned int refresh_interval, const unsigned int expire_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.
Definition: rtr_mgr.c:212
bool rtr_mgr_conf_in_sync(struct rtr_mgr_config *config)
Detects if the rtr_mgr_group is fully synchronized with at least one group.
Definition: rtr_mgr.c:281