Mercurial > dropbear
annotate netio.h @ 1033:ca71904cf3ee fastopen
Fixes for backwards compatibility
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 20 Feb 2015 23:38:05 +0800 |
parents | 0da8ba489c23 |
children | c2a50c9f509e |
rev | line source |
---|---|
1032
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 #ifndef DROPBEAR_NETIO_H |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 #define DROPBEAR_NETIO_H |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 #include "includes.h" |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 #include "buffer.h" |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 #include "queue.h" |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 enum dropbear_prio { |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 DROPBEAR_PRIO_DEFAULT = 10, |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 DROPBEAR_PRIO_LOWDELAY = 11, |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 DROPBEAR_PRIO_BULK = 12, |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 }; |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 void set_sock_nodelay(int sock); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 void set_sock_priority(int sock, enum dropbear_prio prio); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 void get_socket_address(int fd, char **local_host, char **local_port, |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 char **remote_host, char **remote_port, int host_lookup); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 void getaddrstring(struct sockaddr_storage* addr, |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 char **ret_host, char **ret_port, int host_lookup); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 int dropbear_listen(const char* address, const char* port, |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 int *socks, unsigned int sockcount, char **errstring, int *maxfd); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 struct dropbear_progress_connection; |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 /* result is DROPBEAR_SUCCESS or DROPBEAR_FAILURE. |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
27 errstring is only set on DROPBEAR_FAILURE, returns failure message for the last attempted socket */ |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
28 typedef void(*connect_callback)(int result, int sock, void* data, const char* errstring); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
29 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 struct dropbear_progress_connection * connect_remote (const char* remotehost, const char* remoteport, |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 connect_callback cb, void *cb_data); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 void set_connect_fds(fd_set *writefd); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 void handle_connect_fds(fd_set *writefd); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 /* Doesn't actually stop the connect, but adds a dummy callback instead */ |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 void cancel_connect(struct dropbear_progress_connection *c); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 void connect_set_writequeue(struct dropbear_progress_connection *c, struct Queue *writequeue); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 /* TODO: writev #ifdef guard */ |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 struct iovec * packet_queue_to_iovec(struct Queue *queue, int *ret_iov_count); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 void packet_queue_consume(struct Queue *queue, ssize_t written); |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 |
1033
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
45 #ifdef DROPBEAR_TCP_FAST_OPEN |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
46 /* Try for any Linux builds, will fall back if the kernel doesn't support it */ |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
47 void set_listen_fast_open(int sock); |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
48 /* Define values which may be supported by the kernel even if the libc is too old */ |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
49 #ifndef TCP_FASTOPEN |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
50 #define TCP_FASTOPEN 23 |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
51 #endif |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
52 #ifndef MSG_FASTOPEN |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
53 #define MSG_FASTOPEN 0x20000000 |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
54 #endif |
1032
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 #endif |
0da8ba489c23
Move generic network routines to netio.c
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 |
1033
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
57 #endif |
ca71904cf3ee
Fixes for backwards compatibility
Matt Johnston <matt@ucc.asn.au>
parents:
1032
diff
changeset
|
58 |