Usage example of the RTR connection manager.
#include "rtrlib/rtrlib.h"
#include <arpa/inet.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
char ssh_host[] = "123.231.123.221";
char ssh_user[] = "rpki_user";
char ssh_hostkey[] = "/etc/rpki-rtr/hostkey";
char ssh_privkey[] = "/etc/rpki-rtr/client.priv";
ssh_host,
22,
NULL,
ssh_user,
ssh_hostkey,
ssh_privkey,
NULL,
NULL,
0,
NULL,
};
char tcp_host[] = "rpki-validator.realmv6.org";
char tcp_port[] = "8282";
tcp_host,
tcp_port,
NULL,
NULL,
NULL,
0,
};
rtr_ssh.
tr_socket = &tr_ssh;
rtr_tcp.tr_socket = &tr_tcp;
groups[0].
sockets = malloc(
sizeof(
struct rtr_socket *));
groups[0].
sockets_len = 1;
groups[0].sockets[0] = &rtr_tcp;
groups[0].
preference = 1;
groups[1].sockets = malloc(1 *
sizeof(
struct rtr_socket *));
groups[1].sockets_len = 1;
groups[1].sockets[0] = &rtr_ssh;
groups[1].preference = 2;
struct rtr_mgr_config *conf;
rtr_mgr_init(&conf, groups, 2, 30, 600, 600, NULL, NULL, NULL, NULL);
sleep(1);
}
const uint8_t mask = 24;
char buffer[INET_ADDRSTRLEN];
printf("RESULT: The prefix %s/%i ", buffer, mask);
switch (result) {
printf("is valid.\n");
break;
printf("is invalid.\n");
break;
printf("was not found.\n");
break;
default:
break;
}
free(groups[0].sockets);
free(groups[1].sockets);
}
pfxv_state
Validation states returned from pfx_validate_origin.
Definition pfx.h:46
@ BGP_PFXV_STATE_VALID
Definition pfx.h:48
@ BGP_PFXV_STATE_INVALID
One or more records that match the input prefix exists in the pfx_table but the prefix max_len or ASN...
Definition pfx.h:56
@ BGP_PFXV_STATE_NOT_FOUND
No certificate for the route exists.
Definition pfx.h:51
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.
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.
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.
int tr_ssh_init(const struct tr_ssh_config *config, struct tr_socket *socket)
Initializes the tr_socket struct for a SSH connection.
int tr_tcp_init(const struct tr_tcp_config *config, struct tr_socket *socket)
Initializes the tr_socket struct for a TCP connection.
int lrtr_ip_addr_to_str(const struct lrtr_ip_addr *ip, char *str, const unsigned int len)
int lrtr_ip_str_to_addr(const char *str, struct lrtr_ip_addr *ip)
The lrtr_ip_addr struct stores a IPv4 or IPv6 address in host byte order.
Definition ip.h:38
A set of RTR sockets.
Definition rtr_mgr.h:66
A RTR socket.
Definition rtr.h:116
A transport socket datastructure.
Definition transport.h:102
A tr_ssh_config struct holds configuration data for an tr_ssh socket.
Definition ssh_transport.h:51
A tr_tcp_config struct holds configuration for a TCP connection.
Definition tcp_transport.h:41