BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file |
||
3 | * Application layered TCP connection API (to be used from TCPIP thread)\n |
||
4 | * This interface mimics the tcp callback API to the application while preventing |
||
5 | * direct linking (much like virtual functions). |
||
6 | * This way, an application can make use of other application layer protocols |
||
7 | * on top of TCP without knowing the details (e.g. TLS, proxy connection). |
||
8 | * |
||
9 | * This file contains the generic API. |
||
10 | */ |
||
11 | |||
12 | /* |
||
13 | * Copyright (c) 2017 Simon Goldschmidt |
||
14 | * All rights reserved. |
||
15 | * |
||
16 | * Redistribution and use in source and binary forms, with or without modification, |
||
17 | * are permitted provided that the following conditions are met: |
||
18 | * |
||
19 | * 1. Redistributions of source code must retain the above copyright notice, |
||
20 | * this list of conditions and the following disclaimer. |
||
21 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
||
22 | * this list of conditions and the following disclaimer in the documentation |
||
23 | * and/or other materials provided with the distribution. |
||
24 | * 3. The name of the author may not be used to endorse or promote products |
||
25 | * derived from this software without specific prior written permission. |
||
26 | * |
||
27 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
||
28 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
||
29 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
||
30 | * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
||
31 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
||
32 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
33 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
34 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
||
35 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY |
||
36 | * OF SUCH DAMAGE. |
||
37 | * |
||
38 | * This file is part of the lwIP TCP/IP stack. |
||
39 | * |
||
40 | * Author: Simon Goldschmidt <goldsimon@gmx.de> |
||
41 | * |
||
42 | */ |
||
43 | #ifndef LWIP_HDR_ALTCP_H |
||
44 | #define LWIP_HDR_ALTCP_H |
||
45 | |||
46 | #include "lwip/opt.h" |
||
47 | |||
48 | #if LWIP_ALTCP /* don't build if not configured for use in lwipopts.h */ |
||
49 | |||
50 | #include "lwip/tcpbase.h" |
||
51 | #include "lwip/err.h" |
||
52 | #include "lwip/pbuf.h" |
||
53 | #include "lwip/ip_addr.h" |
||
54 | |||
55 | #ifdef __cplusplus |
||
56 | extern "C" { |
||
57 | #endif |
||
58 | |||
59 | struct altcp_pcb; |
||
60 | struct altcp_functions; |
||
61 | |||
62 | typedef err_t (*altcp_accept_fn)(void *arg, struct altcp_pcb *new_conn, err_t err); |
||
63 | typedef err_t (*altcp_connected_fn)(void *arg, struct altcp_pcb *conn, err_t err); |
||
64 | typedef err_t (*altcp_recv_fn)(void *arg, struct altcp_pcb *conn, struct pbuf *p, err_t err); |
||
65 | typedef err_t (*altcp_sent_fn)(void *arg, struct altcp_pcb *conn, u16_t len); |
||
66 | typedef err_t (*altcp_poll_fn)(void *arg, struct altcp_pcb *conn); |
||
67 | typedef void (*altcp_err_fn)(void *arg, err_t err); |
||
68 | |||
69 | |||
70 | struct altcp_pcb { |
||
71 | const struct altcp_functions *fns; |
||
72 | struct altcp_pcb *inner_conn; |
||
73 | void *arg; |
||
74 | void *state; |
||
75 | /* application callbacks */ |
||
76 | altcp_accept_fn accept; |
||
77 | altcp_connected_fn connected; |
||
78 | altcp_recv_fn recv; |
||
79 | altcp_sent_fn sent; |
||
80 | altcp_poll_fn poll; |
||
81 | altcp_err_fn err; |
||
82 | u8_t pollinterval; |
||
83 | }; |
||
84 | |||
85 | void altcp_arg(struct altcp_pcb *conn, void *arg); |
||
86 | void altcp_accept(struct altcp_pcb *conn, altcp_accept_fn accept); |
||
87 | void altcp_recv(struct altcp_pcb *conn, altcp_recv_fn recv); |
||
88 | void altcp_sent(struct altcp_pcb *conn, altcp_sent_fn sent); |
||
89 | void altcp_poll(struct altcp_pcb *conn, altcp_poll_fn poll, u8_t interval); |
||
90 | void altcp_err(struct altcp_pcb *conn, altcp_err_fn err); |
||
91 | |||
92 | void altcp_recved(struct altcp_pcb *conn, u16_t len); |
||
93 | err_t altcp_bind(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port); |
||
94 | err_t altcp_connect(struct altcp_pcb *conn, const ip_addr_t *ipaddr, u16_t port, altcp_connected_fn connected); |
||
95 | |||
96 | /* return conn for source code compatibility to tcp callback API only */ |
||
97 | struct altcp_pcb *altcp_listen_with_backlog_and_err(struct altcp_pcb *conn, u8_t backlog, err_t *err); |
||
98 | #define altcp_listen_with_backlog(conn, backlog) altcp_listen_with_backlog_and_err(conn, backlog, NULL) |
||
99 | /** @ingroup altcp */ |
||
100 | #define altcp_listen(conn) altcp_listen_with_backlog_and_err(conn, TCP_DEFAULT_LISTEN_BACKLOG, NULL) |
||
101 | |||
102 | void altcp_abort(struct altcp_pcb *conn); |
||
103 | err_t altcp_close(struct altcp_pcb *conn); |
||
104 | err_t altcp_shutdown(struct altcp_pcb *conn, int shut_rx, int shut_tx); |
||
105 | |||
106 | err_t altcp_write(struct altcp_pcb *conn, const void *dataptr, u16_t len, u8_t apiflags); |
||
107 | err_t altcp_output(struct altcp_pcb *conn); |
||
108 | |||
109 | u16_t altcp_mss(struct altcp_pcb *conn); |
||
110 | u16_t altcp_sndbuf(struct altcp_pcb *conn); |
||
111 | u16_t altcp_sndqueuelen(struct altcp_pcb *conn); |
||
112 | void altcp_nagle_disable(struct altcp_pcb *conn); |
||
113 | void altcp_nagle_enable(struct altcp_pcb *conn); |
||
114 | int altcp_nagle_disabled(struct altcp_pcb *conn); |
||
115 | |||
116 | void altcp_setprio(struct altcp_pcb *conn, u8_t prio); |
||
117 | |||
118 | err_t altcp_get_tcp_addrinfo(struct altcp_pcb *conn, int local, ip_addr_t *addr, u16_t *port); |
||
119 | ip_addr_t *altcp_get_ip(struct altcp_pcb *conn, int local); |
||
120 | u16_t altcp_get_port(struct altcp_pcb *conn, int local); |
||
121 | |||
122 | #ifdef LWIP_DEBUG |
||
123 | enum tcp_state altcp_dbg_get_tcp_state(struct altcp_pcb *conn); |
||
124 | #endif |
||
125 | |||
126 | #ifdef __cplusplus |
||
127 | } |
||
128 | #endif |
||
129 | |||
130 | #else /* LWIP_ALTCP */ |
||
131 | |||
132 | /* ALTCP disabled, define everything to link against tcp callback API (e.g. to get a small non-ssl httpd) */ |
||
133 | |||
134 | #include "lwip/tcp.h" |
||
135 | |||
136 | #define altcp_accept_fn tcp_accept_fn |
||
137 | #define altcp_connected_fn tcp_connected_fn |
||
138 | #define altcp_recv_fn tcp_recv_fn |
||
139 | #define altcp_sent_fn tcp_sent_fn |
||
140 | #define altcp_poll_fn tcp_poll_fn |
||
141 | #define altcp_err_fn tcp_err_fn |
||
142 | |||
143 | #define altcp_pcb tcp_pcb |
||
144 | #define altcp_tcp_new_ip_type tcp_new_ip_type |
||
145 | #define altcp_tcp_new tcp_new |
||
146 | #define altcp_tcp_new_ip6 tcp_new_ip6 |
||
147 | |||
148 | #define altcp_arg tcp_arg |
||
149 | #define altcp_accept tcp_accept |
||
150 | #define altcp_recv tcp_recv |
||
151 | #define altcp_sent tcp_sent |
||
152 | #define altcp_poll tcp_poll |
||
153 | #define altcp_err tcp_err |
||
154 | |||
155 | #define altcp_recved tcp_recved |
||
156 | #define altcp_bind tcp_bind |
||
157 | #define altcp_connect tcp_connect |
||
158 | |||
159 | #define altcp_listen_with_backlog_and_err tcp_listen_with_backlog_and_err |
||
160 | #define altcp_listen_with_backlog tcp_listen_with_backlog |
||
161 | #define altcp_listen tcp_listen |
||
162 | |||
163 | #define altcp_abort tcp_abort |
||
164 | #define altcp_close tcp_close |
||
165 | #define altcp_shutdown tcp_shutdown |
||
166 | |||
167 | #define altcp_write tcp_write |
||
168 | #define altcp_output tcp_output |
||
169 | |||
170 | #define altcp_mss tcp_mss |
||
171 | #define altcp_sndbuf tcp_sndbuf |
||
172 | #define altcp_sndqueuelen tcp_sndqueuelen |
||
173 | #define altcp_nagle_disable tcp_nagle_disable |
||
174 | #define altcp_nagle_enable tcp_nagle_enable |
||
175 | #define altcp_nagle_disabled tcp_nagle_disabled |
||
176 | #define altcp_setprio tcp_setprio |
||
177 | |||
178 | #define altcp_get_tcp_addrinfo tcp_get_tcp_addrinfo |
||
179 | #define altcp_get_ip(pcb, local) ((local) ? (&(pcb)->local_ip) : (&(pcb)->remote_ip)) |
||
180 | |||
181 | #ifdef LWIP_DEBUG |
||
182 | #define altcp_dbg_get_tcp_state tcp_dbg_get_tcp_state |
||
183 | #endif |
||
184 | |||
185 | #endif /* LWIP_ALTCP */ |
||
186 | |||
187 | #endif /* LWIP_HDR_ALTCP_H */ |