2 * Connection oriented routing user space utils
3 * Copyright (C) 2009-2011
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
24 #include <linux/types.h>
25 #include <sys/socket.h>
28 #define CRD_KTU_CONNECT 1
32 * CRD_KTU_CONNECT[4] length[4] flags[8] addrlen[4] addr[addrlen]
37 #define CRD_UTK_CONNECTERROR 2
39 * CRD_KTU_CONNECT[4] length[4] cookie[8] error[4]
47 #define PROTO_COR_RAW 0
48 #define PROTO_COR_RDEAMON 1
52 #define SOCKADDRTYPE_PORT 1
53 #define SOCKADDRTYPE_ADDRPORT 2
55 __SOCKADDR_COMMON (sin_
); /* 2 bytes */
61 #define RESUME_TYPE_NONE 0
62 #define RESUME_TYPE_READ 1
63 #define RESUME_TYPE_WRITE 2
65 #define RESUME_READ_FUNC_NONE 0
66 #define RESUME_READ_FUNC_RESP 1
67 #define RESUME_READ_FUNC_NEIGHLIST 2
68 #define RESUME_READ_FUNC_SERVICELIST 3
69 #define RESUME_READ_FUNC_RDSOCK_CMD 4
71 #define NEIGHLIST_MAX_FIELDS 256
72 #define ADDR_MAX_LEN 1024
73 #define WRITE_BUF_SIZE 1024
75 struct listneigh_field
{
80 struct libcor_nonblock_resumeinfo_resp
{
90 struct libcor_nonblock_resumeinfo_neighlist
{
94 void (*init
)(void *ptr
, __u32 numneighs
);
95 void (*next_neigh
)(void *ptr
, __u32 addrlen
, char *addr
);
105 struct listneigh_field fields
[NEIGHLIST_MAX_FIELDS
];
112 char addr
[ADDR_MAX_LEN
];
117 struct libcor_nonblock_resumeinfo_servicelist
{
121 void (*init
)(void *ptr
, __u32 numservices
);
122 void (*next_service
)(void *ptr
, __be16 port
);
134 struct libcor_nonblock_resumeinfo_rdsockcmd
{
146 struct libcor_nonblock_resumeinfo
{
183 struct libcor_nonblock_resumeinfo_resp resp
;
185 struct libcor_nonblock_resumeinfo_neighlist
188 struct libcor_nonblock_resumeinfo_servicelist
191 struct libcor_nonblock_resumeinfo_rdsockcmd
202 char buf
[WRITE_BUF_SIZE
];
208 #define RC_CONNBROKEN 1
209 #define RC_WOULDBLOCK 2
211 extern int resume_send(int fd
, struct libcor_nonblock_resumeinfo
*nr
);
213 static inline int resume_send_ifneeded(int fd
,
214 struct libcor_nonblock_resumeinfo
*nr
)
216 if (nr
->type
!= RESUME_TYPE_WRITE
)
219 return resume_send(fd
, nr
);
222 extern int read_resp_nonblock(int fd
, struct libcor_nonblock_resumeinfo
*nr
);
224 extern int read_resp(int fd
);
226 extern int send_connect_neigh_nonblock(int fd
,
227 struct libcor_nonblock_resumeinfo
*nr
,
228 __u32 addrlen
, char *addr
);
230 extern int send_connect_neigh(int fd
, __u32 addrlen
, char *addr
);
232 extern int send_connect_port_nonblock(int fd
,
233 struct libcor_nonblock_resumeinfo
*nr
,
236 extern int send_connect_port(int fd
, __be16 port
);
238 extern int send_list_services_nonblock(int fd
,
239 struct libcor_nonblock_resumeinfo
*nr
);
241 extern int send_list_services(int fd
);
243 extern int read_service_list_nonblock(int fd
,
244 struct libcor_nonblock_resumeinfo
*nr
, void *ptr
,
245 void (*init
)(void *ptr
, __u32 numservices
),
246 void (*next_service
)(void *ptr
, __be16 port
));
248 extern int read_service_list(int fd
, void *ptr
,
249 void (*init
)(void *ptr
, __u32 numservices
),
250 void (*next_service
)(void *ptr
, __be16 port
));
252 extern int send_list_neigh_nonblock(int fd
,
253 struct libcor_nonblock_resumeinfo
*nr
);
255 extern int send_list_neigh(int fd
);
257 extern int read_neigh_list_nonblock(int fd
,
258 struct libcor_nonblock_resumeinfo
*nr
,
260 void (*init
)(void *ptr
, __u32 numneighs
),
261 void (*next_neigh
)(void *ptr
, __u32 addrlen
, char *addr
));
263 extern int read_neigh_list(int fd
, void *ptr
,
264 void (*init
)(void *ptr
, __u32 numneighs
),
265 void (*next_neigh
)(void *ptr
, __u32 addrlen
, char *addr
));
270 #define COR_PASS_ON_CLOSE 1
272 #define CONNECTERROR_ACCES 1
273 #define CONNECTERROR_NETUNREACH 2
274 #define CONNECTERROR_TIMEDOUT 3
275 #define CONNECTERROR_REFUSED 4
277 extern int pass_socket(int fd
, __u64 cookie
);
279 extern int send_rdsock_connecterror_nonblock(int fd
,
280 struct libcor_nonblock_resumeinfo
*nr
,
281 __u64 cookie
, __u32 error
);
283 extern int send_rdsock_connecterror(int fd
, __u64 cookie
, __u32 error
);
285 extern int send_rdsock_up_nonblock(int fd
,
286 struct libcor_nonblock_resumeinfo
*nr
,
287 char *addr
, __u32 addrlen
);
289 extern int send_rdsock_up(int fd
, char *addr
, __u32 addrlen
);
297 extern int parse_rdsock_connect(void *ptr
, struct rdsock_cmd
*cmd
,
298 int (*proc_connect
)(void *ptr
, __u64 cookie
,
299 struct cor_sockaddr
*addr
));
301 static inline void free_rdsockcmd_data(struct rdsock_cmd
*cmd
)
307 extern int read_rdsock_cmd_nonblock(int fd
,
308 struct libcor_nonblock_resumeinfo
*nr
,
309 struct rdsock_cmd
*cmd
);
311 extern int read_rdsock_cmd(int fd
, struct rdsock_cmd
*cmd
);