-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathlib.h
249 lines (224 loc) · 7.76 KB
/
lib.h
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#ifndef __HAVE_LIB_H
#define __HAVE_LIB_H
#define LISP
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <ifaddrs.h>
#include <strings.h>
#include <signal.h>
#include <pthread.h>
#include <poll.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
#include <sys/errno.h>
#include <netinet/in.h>
#include <netinet/udp.h>
#include <netinet/ip.h>
#include <netinet/ip6.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <net/route.h>
#include <ifaddrs.h>
#include "radix/db.h"
#include "radix/db_table.h"
#include "radix/db_prefix.h"
#include "list/list.h"
#include "hmac/hmac_sha.h"
#include "db.h"
#include "thr_pool/thr_pool.h"
#define TRUE 1
#define FALSE 0
#define BSIZE 40
#define OUTPUT_STREAM stdout
#define OUTPUT_ERROR stderr
/* for Linux */
#ifndef OPEN_MAX
#define OPEN_MAX 256
#endif
#ifndef INFTIM
#define INFTIM -1
#endif
/* referral action types */
#define LISP_REFERRAL_NODE_REFERRAL 0x0
#define LISP_REFERRAL_MS_REFERRAL 0x1
#define LISP_REFERRAL_MS_ACK 0x2
#define LISP_REFERRAL_MS_NOT_REGISTERED 0x3
#define LISP_REFERRAL_DELEGATION_HOLE 0x4
#define LISP_REFERRAL_NOT_AUTHORITATIVE 0x5
#define COUNT 3
#define MIN_COUNT 1
#define MAX_COUNT 3
#define MR_MAX_LOOKUP 10
#define MAX_LOOKUPS 100
#define MAP_REPLY_TIMEOUT 2
#define MIN_EPHEMERAL_PORT 32768
#define MAX_EPHEMERAL_PORT 65535
#define OUTPUT_ERROR stderr
#define LISP_CP_PORT 4342
#define LISP_DP_PORT 4341
#define _FNC_XTR 1
#define _FNC_MS 2
#define _FNC_MR 4
#define _FNC_NODE 8
#define _FNC_RTR 16
#define PKMSIZE 4096
#define MTTL 10 //max recuse map-referral
#define MIF 10 //max inteface support
#define LNONE 0
#define LLOG 1
#define LDEBUG 2
#define LOOPBACK "127.0.0.1"
#define LOOPBACK6 "::1"
#define LINK_LOCAL "fe80"
#define LINK_LOCAL_LEN 4
#define CO(addr,len) (((char *) addr + len))
#define SA_LEN(a) ((a == AF_INET) ? sizeof(struct sockaddr_in) : sizeof(struct sockaddr_in6))
#define SIN_LEN(a) ((a == AF_INET) ? sizeof(struct in_addr) : sizeof(struct in6_addr))
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
#define htonll(x) (((uint64_t)htonl((x) & 0xFFFFFFFF) << 32) | htonl((x) >> 32))
#define ntohll(x) (((uint64_t)ntohl((x) & 0xFFFFFFFF) << 32) | ntohl((x) >> 32))
#else
#define htonll(x) (x)
#define ntohll(x) (x)
#endif
extern struct db_table *table;
extern u_char _fncs;
extern u_char lisp_te;
extern u_char srcport_rand;
extern char *config_file[];
int PK_POOL_MAX;
int min_thread;
int max_thread;
int linger_thread;
int _debug;
thr_pool_t *cpp;
int skfd, skfd6;
struct pollfd _sk[OPEN_MAX];
char ip[INET6_ADDRSTRLEN];
pthread_mutex_t ipq_mutex;
pthread_cond_t ipq_cv;
unsigned int ipq_no;
/* communication abstraction */
struct communication_fct {
/* communication management */
void *(*start_communication)(void *context);
void *(*stop_communication)(void *context);
/* Map-Reply */
/* create a new reply
@param nonce nonce of the reply
@return a identifier for the reply
*/
void *(*reply_add)(void *data);
/* start a new record for the reply
@param id reply identifier
@return TRUE on success, otherwise a FALSE is returned
*/
int (*reply_add_record)(void *data, struct prefix *p, uint32_t ttl, uint8_t lcount, uint32_t version, uint8_t A, uint8_t act);
/* add a locator to the current record
@param id reply identifier
@param e map-entry information (locator, priority...)
@return TRUE on success, otherwise a FALSE is returned
*/
int (*reply_add_locator)(void *data, struct map_entry *e);
/* something wrong happened */
int (*reply_error)(void *data);
/* Indicates that the reply construction is finished, post-processing
can be started */
int (*reply_terminate)(void *data);
/* Map-Referral */
/* create a new referral
@param nonce nonce of the referral
@return a identifier for the referral
*/
void *(*referral_add)(void *data);
/* start a new record for the referral
@param id referral identifier
@return TRUE on success, otherwise a FALSE is returned
*/
int (*referral_add_record)(void *data, uint32_t iid, struct prefix *p, uint32_t ttl, uint8_t lcount, uint32_t version, uint8_t A, uint8_t act, uint8_t i, uint8_t sigcnt);
/* add a locator to the current record
@param id referral identifier
@param e map-entry information (locator, priority...)
@return TRUE on success, otherwise a FALSE is returned
*/
int (*referral_add_locator)(void *data, struct map_entry *e);
/* something wrong happened */
int (*referral_error)(void *data);
/* Indicates that the referral construction is finished, post-processing
can be started */
int (*referral_terminate)(void *data);
/* Map-Request */
/* Obtain the EID associated to the request. p is set to the EID found
in the request
@param id request identifier
@param p eid prefix in the request
@return TRUE on success, otherwise a FALSE is returned
*/
int (*request_get_eid)(void *data, struct prefix *p);
/* Obtain the nonce associated to the request. nonce is set to the
nonce found in the request
@param id request identifier
@param nonce nonce in the request
@return TRUE on success, otherwise a FALSE is returned
XXX nonce is given in network byte order
*/
uint64_t (*request_get_nonce)(void *data);
int (*request_is_ddt)(void *data);
/* Obtain a source ITR address of the request
@param id request identifier
@param itr ITR address in the request
@return TRUE on success, otherwise a FALSE is returned
*/
int (*request_get_itr)(void *data, union sockunion *itr, int afi);
/* Obtain the UDP source port from the Map-Request
@param id request identifier
@param port port of the request
@return TRUE on success, otherwise a FALSE is returned
*/
int (*request_get_port)(void *data, uint16_t *port);
void *(*request_add)(void *data, uint8_t security, uint8_t ddt,\
uint8_t A, uint8_t M, uint8_t P, uint8_t S,\
uint8_t p, uint8_t s, uint64_t nonce,\
const union sockunion *src, \
const union sockunion *dst, \
const struct prefix *eid );
/* Indicates that the request has been processed completely */
int (*request_terminate)(void *data);
/* Indicates that the DDT request construction is finished,
post-processing can be started
@param id request identifier
@param server server where to send the DDT request
return TRUE on success, otherwise a FALSE is returned
*/
int (*request_ddt_terminate)(void *data, const union sockunion *server, char terminal);
};
/* ! communication abstraction */
int generic_process_request(void *data, struct communication_fct *fct);
void *generic_mapping_new(struct prefix *eid);
int generic_mapping_set_flags(void *mapping, const struct mapping_flags *mflags);
int generic_mapping_add_rloc(void *mapping, struct map_entry *entry);
int xtr_generic_process_request(void *data, struct communication_fct *fct);
int pending_request(void *data, struct communication_fct *fct, struct db_node *rn);
int udp_init_socket();
int udp_preparse_pk(void *data);
char *sk_get_ip(union sockunion *sk, char *ip);
int sk_get_port(union sockunion *sk);
void sk_set_port(union sockunion *sk, int port);
void reconfigure();
uint64_t _make_nonce();
int _parser_config(const char *filename);
int timespec_subtract(struct timespec *res, struct timespec *x, struct timespec *y);
int entrycmp(void *esrc, void *edst);
int _map_entry_cmp(void *data, void *entry);
ushort ip_checksum (unsigned short *buf, int nwords);
int is_my_addr(union sockunion *sk);
void cp_log(int level, char *format, ...);
#endif