-
Notifications
You must be signed in to change notification settings - Fork 0
/
RTRlib.xs
128 lines (105 loc) · 3.37 KB
/
RTRlib.xs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <unistd.h>
#include "rtrlib/rtrlib.h"
#include "ppport.h"
MODULE = RPKI::RTRlib PACKAGE = RPKI::RTRlib
struct rtr_mgr_config *
start(host, port)
char* host;
char* port;
CODE:
//create a TCP transport socket
struct tr_socket *tr_tcp = malloc(sizeof(struct tr_socket));
struct tr_tcp_config tcp_config1 = {
host, //IP
port, //Port
NULL //Source address
};
tr_tcp_init(&tcp_config1, tr_tcp);
struct rtr_socket *rtr_tcp = malloc(sizeof(struct rtr_socket));
rtr_tcp->tr_socket = tr_tcp;
struct rtr_mgr_group *groups = malloc(1 * sizeof(struct rtr_mgr_group));
groups[0].sockets = malloc(1 * sizeof(struct rtr_socket*));
groups[0].sockets_len = 1;
groups[0].sockets[0] = rtr_tcp;
groups[0].preference = 1; //Preference value of this group
//create a rtr_mgr_config struct that stores the group
//initialize all rtr_sockets in the server pool with the same settings
struct rtr_mgr_config *conf = malloc(sizeof(struct rtr_mgr_config));
int ret = rtr_mgr_init(&conf, groups, 1, 30, 600, 600, NULL, NULL, NULL, NULL);
//start the connection manager
rtr_mgr_start(conf);
//wait till at least one rtr_mgr_group is fully synchronized with the server
while(!rtr_mgr_conf_in_sync(conf))
sleep(1);
RETVAL = conf;
OUTPUT:
RETVAL
int
validate(conf, asn,ipAddr, cidr)
struct rtr_mgr_config *conf;
int asn;
char* ipAddr;
int cidr;
CODE:
struct lrtr_ip_addr pref;
lrtr_ip_str_to_addr(ipAddr, &pref);
enum pfxv_state result;
rtr_mgr_validate(conf, asn, &pref, cidr, &result);
RETVAL = result;
OUTPUT:
RETVAL
SV *
validate_r(conf, asn,ipAddr,cidr)
struct rtr_mgr_config *conf;
int asn;
char *ipAddr;
int cidr;
INIT:
HV * results;
results = (HV *) sv_2mortal ((SV *) newHV());
AV * alist;
alist = (AV *) sv_2mortal ((SV *) newAV());
CODE:
struct lrtr_ip_addr pref;
lrtr_ip_str_to_addr(ipAddr, &pref);
struct pfx_record *reason = malloc(sizeof(struct pfx_record));
unsigned int *reason_len = malloc(sizeof(unsigned int));
enum pfxv_state result;
pfx_table_validate_r(conf->groups[0].sockets[0]->pfx_table,&reason,reason_len, asn, &pref, cidr, &result);
hv_store(results,"state",5,newSViv(result),0);
int i;
for(i=0;i<(*reason_len);i++){
char stripAddr[INET6_ADDRSTRLEN];
lrtr_ip_addr_to_str(&reason[i].prefix,stripAddr,INET6_ADDRSTRLEN);
HV * roa = (HV *) sv_2mortal((SV *)newHV());
hv_store(roa,"asn",3,newSViv(reason[i].asn),0);
hv_store(roa,"max",3,newSViv(reason[i].max_len),0);
hv_store(roa,"min",3,newSViv(reason[i].min_len),0);
hv_store(roa,"prefix",6,newSVpv(stripAddr,strlen(stripAddr)),0);
av_push(alist,newRV((SV *)roa));
}
hv_store(results,"roas",4,newRV((SV *)alist),0);
RETVAL = newRV((SV *)results);
OUTPUT:
RETVAL
void
DESTROY(conf)
struct rtr_mgr_config *conf ;
CODE:
rtr_mgr_stop(conf);
rtr_mgr_free(conf);
void
stop(conf)
struct rtr_mgr_config *conf ;
CODE:
rtr_mgr_stop(conf);
rtr_mgr_free(conf);