BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /**
2 * @file
3 * netconn API lwIP internal implementations (do not use in application code)
4 */
5  
6 /*
7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
30 * OF SUCH DAMAGE.
31 *
32 * This file is part of the lwIP TCP/IP stack.
33 *
34 * Author: Adam Dunkels <adam@sics.se>
35 *
36 */
37 #ifndef LWIP_HDR_API_MSG_H
38 #define LWIP_HDR_API_MSG_H
39  
40 #include "lwip/opt.h"
41  
42 #if LWIP_NETCONN || LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */
43 /* Note: Netconn API is always available when sockets are enabled -
44 * sockets are implemented on top of them */
45  
46 #include "lwip/arch.h"
47 #include "lwip/ip_addr.h"
48 #include "lwip/err.h"
49 #include "lwip/sys.h"
50 #include "lwip/igmp.h"
51 #include "lwip/api.h"
52 #include "lwip/priv/tcpip_priv.h"
53  
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57  
58 #if LWIP_MPU_COMPATIBLE
59 #if LWIP_NETCONN_SEM_PER_THREAD
60 #define API_MSG_M_DEF_SEM(m) *m
61 #else
62 #define API_MSG_M_DEF_SEM(m) API_MSG_M_DEF(m)
63 #endif
64 #else /* LWIP_MPU_COMPATIBLE */
65 #define API_MSG_M_DEF_SEM(m) API_MSG_M_DEF(m)
66 #endif /* LWIP_MPU_COMPATIBLE */
67  
68 /* For the netconn API, these values are use as a bitmask! */
69 #define NETCONN_SHUT_RD 1
70 #define NETCONN_SHUT_WR 2
71 #define NETCONN_SHUT_RDWR (NETCONN_SHUT_RD | NETCONN_SHUT_WR)
72  
73 /* IP addresses and port numbers are expected to be in
74 * the same byte order as in the corresponding pcb.
75 */
76 /** This struct includes everything that is necessary to execute a function
77 for a netconn in another thread context (mainly used to process netconns
78 in the tcpip_thread context to be thread safe). */
79 struct api_msg {
80 /** The netconn which to process - always needed: it includes the semaphore
81 which is used to block the application thread until the function finished. */
82 struct netconn *conn;
83 /** The return value of the function executed in tcpip_thread. */
84 err_t err;
85 /** Depending on the executed function, one of these union members is used */
86 union {
87 /** used for lwip_netconn_do_send */
88 struct netbuf *b;
89 /** used for lwip_netconn_do_newconn */
90 struct {
91 u8_t proto;
92 } n;
93 /** used for lwip_netconn_do_bind and lwip_netconn_do_connect */
94 struct {
95 API_MSG_M_DEF_C(ip_addr_t, ipaddr);
96 u16_t port;
97 u8_t if_idx;
98 } bc;
99 /** used for lwip_netconn_do_getaddr */
100 struct {
101 ip_addr_t API_MSG_M_DEF(ipaddr);
102 u16_t API_MSG_M_DEF(port);
103 u8_t local;
104 } ad;
105 /** used for lwip_netconn_do_write */
106 struct {
107 /** current vector to write */
108 const struct netvector *vector;
109 /** number of unwritten vectors */
110 u16_t vector_cnt;
111 /** offset into current vector */
112 size_t vector_off;
113 /** total length across vectors */
114 size_t len;
115 /** offset into total length/output of bytes written when err == ERR_OK */
116 size_t offset;
117 u8_t apiflags;
118 #if LWIP_SO_SNDTIMEO
119 u32_t time_started;
120 #endif /* LWIP_SO_SNDTIMEO */
121 } w;
122 /** used for lwip_netconn_do_recv */
123 struct {
124 size_t len;
125 } r;
126 #if LWIP_TCP
127 /** used for lwip_netconn_do_close (/shutdown) */
128 struct {
129 u8_t shut;
130 #if LWIP_SO_SNDTIMEO || LWIP_SO_LINGER
131 u32_t time_started;
132 #else /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
133 u8_t polls_left;
134 #endif /* LWIP_SO_SNDTIMEO || LWIP_SO_LINGER */
135 } sd;
136 #endif /* LWIP_TCP */
137 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
138 /** used for lwip_netconn_do_join_leave_group */
139 struct {
140 API_MSG_M_DEF_C(ip_addr_t, multiaddr);
141 API_MSG_M_DEF_C(ip_addr_t, netif_addr);
142 u8_t if_idx;
143 enum netconn_igmp join_or_leave;
144 } jl;
145 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
146 #if TCP_LISTEN_BACKLOG
147 struct {
148 u8_t backlog;
149 } lb;
150 #endif /* TCP_LISTEN_BACKLOG */
151 } msg;
152 #if LWIP_NETCONN_SEM_PER_THREAD
153 sys_sem_t* op_completed_sem;
154 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
155 };
156  
157 #if LWIP_NETCONN_SEM_PER_THREAD
158 #define LWIP_API_MSG_SEM(msg) ((msg)->op_completed_sem)
159 #else /* LWIP_NETCONN_SEM_PER_THREAD */
160 #define LWIP_API_MSG_SEM(msg) (&(msg)->conn->op_completed)
161 #endif /* LWIP_NETCONN_SEM_PER_THREAD */
162  
163  
164 #if LWIP_DNS
165 /** As lwip_netconn_do_gethostbyname requires more arguments but doesn't require a netconn,
166 it has its own struct (to avoid struct api_msg getting bigger than necessary).
167 lwip_netconn_do_gethostbyname must be called using tcpip_callback instead of tcpip_apimsg
168 (see netconn_gethostbyname). */
169 struct dns_api_msg {
170 /** Hostname to query or dotted IP address string */
171 #if LWIP_MPU_COMPATIBLE
172 char name[DNS_MAX_NAME_LENGTH];
173 #else /* LWIP_MPU_COMPATIBLE */
174 const char *name;
175 #endif /* LWIP_MPU_COMPATIBLE */
176 /** The resolved address is stored here */
177 ip_addr_t API_MSG_M_DEF(addr);
178 #if LWIP_IPV4 && LWIP_IPV6
179 /** Type of resolve call */
180 u8_t dns_addrtype;
181 #endif /* LWIP_IPV4 && LWIP_IPV6 */
182 /** This semaphore is posted when the name is resolved, the application thread
183 should wait on it. */
184 sys_sem_t API_MSG_M_DEF_SEM(sem);
185 /** Errors are given back here */
186 err_t API_MSG_M_DEF(err);
187 };
188 #endif /* LWIP_DNS */
189  
190 int lwip_netconn_is_err_msg(void *msg, err_t *err);
191 void lwip_netconn_do_newconn (void *m);
192 void lwip_netconn_do_delconn (void *m);
193 void lwip_netconn_do_bind (void *m);
194 void lwip_netconn_do_bind_if (void *m);
195 void lwip_netconn_do_connect (void *m);
196 void lwip_netconn_do_disconnect (void *m);
197 void lwip_netconn_do_listen (void *m);
198 void lwip_netconn_do_send (void *m);
199 void lwip_netconn_do_recv (void *m);
200 #if TCP_LISTEN_BACKLOG
201 void lwip_netconn_do_accepted (void *m);
202 #endif /* TCP_LISTEN_BACKLOG */
203 void lwip_netconn_do_write (void *m);
204 void lwip_netconn_do_getaddr (void *m);
205 void lwip_netconn_do_close (void *m);
206 void lwip_netconn_do_shutdown (void *m);
207 #if LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD)
208 void lwip_netconn_do_join_leave_group(void *m);
209 void lwip_netconn_do_join_leave_group_netif(void *m);
210 #endif /* LWIP_IGMP || (LWIP_IPV6 && LWIP_IPV6_MLD) */
211  
212 #if LWIP_DNS
213 void lwip_netconn_do_gethostbyname(void *arg);
214 #endif /* LWIP_DNS */
215  
216 struct netconn* netconn_alloc(enum netconn_type t, netconn_callback callback);
217 void netconn_free(struct netconn *conn);
218  
219 /* netifapi related lwIP internal definitions */
220  
221 #if LWIP_MPU_COMPATIBLE
222 #define NETIFAPI_IPADDR_DEF(type, m) type m
223 #else /* LWIP_MPU_COMPATIBLE */
224 #define NETIFAPI_IPADDR_DEF(type, m) const type * m
225 #endif /* LWIP_MPU_COMPATIBLE */
226  
227 typedef void (*netifapi_void_fn)(struct netif *netif);
228 typedef err_t (*netifapi_errt_fn)(struct netif *netif);
229  
230 struct netifapi_msg {
231 struct tcpip_api_call_data call;
232 struct netif *netif;
233 union {
234 struct {
235 #if LWIP_IPV4
236 NETIFAPI_IPADDR_DEF(ip4_addr_t, ipaddr);
237 NETIFAPI_IPADDR_DEF(ip4_addr_t, netmask);
238 NETIFAPI_IPADDR_DEF(ip4_addr_t, gw);
239 #endif /* LWIP_IPV4 */
240 void *state;
241 netif_init_fn init;
242 netif_input_fn input;
243 } add;
244 struct {
245 netifapi_void_fn voidfunc;
246 netifapi_errt_fn errtfunc;
247 } common;
248 struct {
249 #if LWIP_MPU_COMPATIBLE
250 char name[NETIF_NAMESIZE];
251 #else /* LWIP_MPU_COMPATIBLE */
252 char *name;
253 #endif /* LWIP_MPU_COMPATIBLE */
254 u8_t index;
255 } ifs;
256 } msg;
257 };
258  
259 #ifdef __cplusplus
260 }
261 #endif
262  
263 #endif /* LWIP_NETCONN || LWIP_SOCKET */
264  
265 #endif /* LWIP_HDR_API_MSG_H */