cosmetics
[tomato.git] / release / src / router / openvpn / forward-inline.h
blobbb8f542858ca48ddecf06ec89c84e2b2be6982e8
1 /*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
8 * Copyright (C) 2002-2009 OpenVPN Technologies, Inc. <sales@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef FORWARD_INLINE_H
26 #define FORWARD_INLINE_H
29 * Inline functions
33 * Does TLS session need service?
35 static inline void
36 check_tls (struct context *c)
38 #if defined(USE_CRYPTO) && defined(USE_SSL)
39 void check_tls_dowork (struct context *c);
40 if (c->c2.tls_multi)
41 check_tls_dowork (c);
42 #endif
46 * TLS errors are fatal in TCP mode.
47 * Also check for --tls-exit trigger.
49 static inline void
50 check_tls_errors (struct context *c)
52 #if defined(USE_CRYPTO) && defined(USE_SSL)
53 void check_tls_errors_co (struct context *c);
54 void check_tls_errors_nco (struct context *c);
55 if (c->c2.tls_multi && c->c2.tls_exit_signal)
57 if (link_socket_connection_oriented (c->c2.link_socket))
59 if (c->c2.tls_multi->n_soft_errors)
60 check_tls_errors_co (c);
62 else
64 if (c->c2.tls_multi->n_hard_errors)
65 check_tls_errors_nco (c);
68 #endif
72 * Check for possible incoming configuration
73 * messages on the control channel.
75 static inline void
76 check_incoming_control_channel (struct context *c)
78 #if P2MP
79 void check_incoming_control_channel_dowork (struct context *c);
80 if (tls_test_payload_len (c->c2.tls_multi) > 0)
81 check_incoming_control_channel_dowork (c);
82 #endif
86 * Options like --up-delay need to be triggered by this function which
87 * checks for connection establishment.
89 static inline void
90 check_connection_established (struct context *c)
92 void check_connection_established_dowork (struct context *c);
93 if (event_timeout_defined (&c->c2.wait_for_connect))
94 check_connection_established_dowork (c);
98 * Should we add routes?
100 static inline void
101 check_add_routes (struct context *c)
103 void check_add_routes_dowork (struct context *c);
104 if (event_timeout_trigger (&c->c2.route_wakeup, &c->c2.timeval, ETT_DEFAULT))
105 check_add_routes_dowork (c);
109 * Should we exit due to inactivity timeout?
111 static inline void
112 check_inactivity_timeout (struct context *c)
114 void check_inactivity_timeout_dowork (struct context *c);
116 if (c->options.inactivity_timeout
117 && event_timeout_trigger (&c->c2.inactivity_interval, &c->c2.timeval, ETT_DEFAULT))
118 check_inactivity_timeout_dowork (c);
121 #if P2MP
123 static inline void
124 check_server_poll_timeout (struct context *c)
126 void check_server_poll_timeout_dowork (struct context *c);
128 if (c->options.server_poll_timeout
129 && event_timeout_trigger (&c->c2.server_poll_interval, &c->c2.timeval, ETT_DEFAULT))
130 check_server_poll_timeout_dowork (c);
134 * Scheduled exit?
136 static inline void
137 check_scheduled_exit (struct context *c)
139 void check_scheduled_exit_dowork (struct context *c);
141 if (event_timeout_defined (&c->c2.scheduled_exit))
143 if (event_timeout_trigger (&c->c2.scheduled_exit, &c->c2.timeval, ETT_DEFAULT))
144 check_scheduled_exit_dowork (c);
147 #endif
150 * Should we write timer-triggered status file.
152 static inline void
153 check_status_file (struct context *c)
155 void check_status_file_dowork (struct context *c);
157 if (c->c1.status_output)
159 if (status_trigger_tv (c->c1.status_output, &c->c2.timeval))
160 check_status_file_dowork (c);
164 #ifdef ENABLE_FRAGMENT
166 * Should we deliver a datagram fragment to remote?
168 static inline void
169 check_fragment (struct context *c)
171 void check_fragment_dowork (struct context *c);
172 if (c->c2.fragment)
173 check_fragment_dowork (c);
175 #endif
177 #if P2MP
180 * see if we should send a push_request in response to --pull
182 static inline void
183 check_push_request (struct context *c)
185 void check_push_request_dowork (struct context *c);
186 if (event_timeout_trigger (&c->c2.push_request_interval, &c->c2.timeval, ETT_DEFAULT))
187 check_push_request_dowork (c);
190 #endif
192 #ifdef USE_CRYPTO
194 * Should we persist our anti-replay packet ID state to disk?
196 static inline void
197 check_packet_id_persist_flush (struct context *c)
199 if (packet_id_persist_enabled (&c->c1.pid_persist)
200 && event_timeout_trigger (&c->c2.packet_id_persist_interval, &c->c2.timeval, ETT_DEFAULT))
201 packet_id_persist_save (&c->c1.pid_persist);
203 #endif
206 * Set our wakeup to 0 seconds, so we will be rescheduled
207 * immediately.
209 static inline void
210 context_immediate_reschedule (struct context *c)
212 c->c2.timeval.tv_sec = 0; /* ZERO-TIMEOUT */
213 c->c2.timeval.tv_usec = 0;
216 static inline void
217 context_reschedule_sec (struct context *c, int sec)
219 if (sec < 0)
220 sec = 0;
221 if (sec < c->c2.timeval.tv_sec)
223 c->c2.timeval.tv_sec = sec;
224 c->c2.timeval.tv_usec = 0;
228 static inline struct link_socket_info *
229 get_link_socket_info (struct context *c)
231 if (c->c2.link_socket_info)
232 return c->c2.link_socket_info;
233 else
234 return &c->c2.link_socket->info;
237 static inline void
238 register_activity (struct context *c, const int size)
240 if (c->options.inactivity_timeout)
242 c->c2.inactivity_bytes += size;
243 if (c->c2.inactivity_bytes >= c->options.inactivity_minimum_bytes)
245 c->c2.inactivity_bytes = 0;
246 event_timeout_reset (&c->c2.inactivity_interval);
252 * Return the io_wait() flags appropriate for
253 * a point-to-point tunnel.
255 static inline unsigned int
256 p2p_iow_flags (const struct context *c)
258 unsigned int flags = (IOW_SHAPER|IOW_CHECK_RESIDUAL|IOW_FRAG|IOW_READ|IOW_WAIT_SIGNAL);
259 if (c->c2.to_link.len > 0)
260 flags |= IOW_TO_LINK;
261 if (c->c2.to_tun.len > 0)
262 flags |= IOW_TO_TUN;
263 return flags;
267 * This is the core I/O wait function, used for all I/O waits except
268 * for TCP in server mode.
270 static inline void
271 io_wait (struct context *c, const unsigned int flags)
273 void io_wait_dowork (struct context *c, const unsigned int flags);
275 if (c->c2.fast_io && (flags & (IOW_TO_TUN|IOW_TO_LINK|IOW_MBUF)))
277 /* fast path -- only for TUN/TAP/UDP writes */
278 unsigned int ret = 0;
279 if (flags & IOW_TO_TUN)
280 ret |= TUN_WRITE;
281 if (flags & (IOW_TO_LINK|IOW_MBUF))
282 ret |= SOCKET_WRITE;
283 c->c2.event_set_status = ret;
285 else
287 /* slow path */
288 io_wait_dowork (c, flags);
292 #define CONNECTION_ESTABLISHED(c) (get_link_socket_info(c)->connection_established)
294 #endif /* EVENT_INLINE_H */