2 * Connection oriented routing user space utils
3 * Copyright (C) 2009-2020
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include <sys/socket.h>
28 #include <arpa/inet.h>
30 #include <sys/epoll.h>
40 #define U32_MAX ((__u32) ((1LL << 32) - 1))
43 #define MAX_ADDRLEN 128 \
62 #define QUERY_STATUS_NOTQUERIED 0
63 #define QUERY_STATUS_QUERIED 1
64 #define QUERY_STATUS_ERROR 2
69 struct route_list routes
;
71 struct service_list services
;
78 __u64 last_query_time
;
80 struct list_head node_list
;
86 #define SEARCHQUERY_NEIGHSNOTQUERIED 1
87 #define SEARCHQUERY_NODEBYADDRESS 2
88 #define SEARCHQUERY_NODEBYSERVICEPORT 3
103 /* __u16 addrlen[numhops] */
108 #define EPOLLDATA_TIMER 1
109 #define EPOLLDATA_DISCOVERNETWORK 2
110 #define EPOLLDATA_RDSCONNECT 3
111 #define EPOLLDATA_RDSOCKCMD 4
112 #define EPOLLDATA_FWD_TO_R 5
113 #define EPOLLDATA_FWD_TO_LSERVICE 6
114 #define EPOLLDATA_FORWARD 7
116 struct nonblock_resumeinfo_connect_to_host_send
{
118 struct e2eroute
*e2er
;
125 struct nonblock_resumeinfo_connect_to_host_recv
{
134 #define FORWARD_BUF_SIZE 4096
136 struct nonblock_resumeinfo
{
147 struct e2eroute
*e2er
;
149 struct nonblock_resumeinfo_connect_to_host_send connect_send
;
150 struct nonblock_resumeinfo_connect_to_host_recv connect_recv
;
152 struct libcor_nonblock_resumeinfo lnr
;
159 struct e2eroute
*e2er
;
162 struct nonblock_resumeinfo_connect_to_host_send connect_send
;
163 struct nonblock_resumeinfo_connect_to_host_recv connect_resp
;
165 struct libcor_nonblock_resumeinfo lnr
;
169 struct libcor_nonblock_resumeinfo lnr
;
181 struct sockaddr
*saddr
;
187 * buf gets filled by reversedir and written into
196 struct nonblock_resumeinfo
*reversedir
;
201 struct fwd_to_r_item
{
202 struct list_head allfwds
;
212 struct fwd_to_lservice_item
{
213 struct list_head allfwds
;
218 struct sockaddr
*saddr
;
223 #define offsetof(type, member) __builtin_offsetof (type, member)
225 #define container_of(ptr, type, member) ({ \
226 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
227 (type *)( (char *)__mptr - offsetof(type,member) );})
230 static inline int check_rc(int rc
, char *errormsg
)
232 if (rc
!= RC_OK
&& rc
!= RC_WOULDBLOCK
)
233 printf("%s\n", errormsg
);
234 return (rc
!= RC_OK
);
239 extern struct list_head node_list
;
243 extern int rdsock_fd
;
247 extern void set_nonblock(int fd
, int value
);
249 extern int addr_eq(char *addr1
, __u32 addrlen1
, char *addr2
, __u32 addrlen2
);
251 extern void print_hex(char *buf
, __u32 len
);
253 extern void neigh_printaddr(__u16 addrlen
, char *addr
);
257 extern char *localaddr
;
258 extern __u16 localaddrlen
;
260 extern __u32 sleep_before_discover
;
261 extern __u8 export_servicelist_enabled
;
263 extern __u32 verbosity
;
266 extern int parse_args(int argc
, char *argv
[], struct list_head
*r_fwds
,
267 struct list_head
*lservice_fwds
);
271 extern struct route_list localneighs
;
272 extern struct service_list localservices
;
274 extern struct list_head node_list
;
276 extern int service_list_contains(struct service_list
*services
, __be16 port
);
278 extern struct node
* try_find_neigh_byaddr(__u16 addrlen
, char *addr
);
280 extern struct node
* try_find_neigh_byservice(__be16 serviceport
);
282 extern struct e2eroute
* get_e2eroute_localhost(void);
284 extern struct e2eroute
* get_e2eroute(struct node
*node
);
286 extern int connect_to_host_recv(int fd
, struct libcor_nonblock_resumeinfo
*lnr
,
287 struct nonblock_resumeinfo_connect_to_host_recv
*rcr
,
288 struct e2eroute
*e2er
);
290 extern int connect_to_host_send(int fd
,
291 struct libcor_nonblock_resumeinfo
*lnr
,
292 struct nonblock_resumeinfo_connect_to_host_send
*cth
,
293 struct e2eroute
*e2er
);
295 extern void _discover_network(int fd
, struct nonblock_resumeinfo
*nr
);
297 extern void discover_network(void);
299 extern int initial_discovery_inprogress(void);
301 extern void init_nodedb(void);
304 extern void fwd_to_r_accept(int listenerfd
, __u8 fwd_to_host
, char *hostaddr
,
305 __u32 hostaddrlen
, __be16 targetport
);
307 extern void fwd_to_lservice_accept(int listenerfd
, int af
,
308 struct sockaddr
*saddr
, socklen_t saddrlen
);
310 extern void forward(struct nonblock_resumeinfo
*nr
, __u32 eventflags
);
312 extern void epoll_add_fwd_to_r(struct list_head
*r_fwds
);
314 extern void epoll_add_fwd_to_lservice(struct list_head
*lservice_fwds
);
317 static inline __u64
get_time_nsec(void)
320 clock_gettime(CLOCK_BOOTTIME
, &ts
);
321 return 1000000000L * ((__u64
) ts
.tv_sec
) + ((__u64
) ts
.tv_nsec
);