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
8 * Copyright (C) 2002-2008 Telethra, 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
33 * Does TLS session need service?
36 check_tls (struct context
*c
)
38 #if defined(USE_CRYPTO) && defined(USE_SSL)
39 void check_tls_dowork (struct context
*c
);
46 * TLS errors are fatal in TCP mode.
47 * Also check for --tls-exit trigger.
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
);
64 if (c
->c2
.tls_multi
->n_hard_errors
)
65 check_tls_errors_nco (c
);
72 * Check for possible incoming configuration
73 * messages on the control channel.
76 check_incoming_control_channel (struct context
*c
)
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
);
86 * Options like --up-delay need to be triggered by this function which
87 * checks for connection establishment.
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?
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?
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
);
126 check_scheduled_exit (struct context
*c
)
128 void check_scheduled_exit_dowork (struct context
*c
);
130 if (event_timeout_defined (&c
->c2
.scheduled_exit
))
132 if (event_timeout_trigger (&c
->c2
.scheduled_exit
, &c
->c2
.timeval
, ETT_DEFAULT
))
133 check_scheduled_exit_dowork (c
);
139 * Should we write timer-triggered status file.
142 check_status_file (struct context
*c
)
144 void check_status_file_dowork (struct context
*c
);
146 if (c
->c1
.status_output
)
148 if (status_trigger_tv (c
->c1
.status_output
, &c
->c2
.timeval
))
149 check_status_file_dowork (c
);
153 #ifdef ENABLE_FRAGMENT
155 * Should we deliver a datagram fragment to remote?
158 check_fragment (struct context
*c
)
160 void check_fragment_dowork (struct context
*c
);
162 check_fragment_dowork (c
);
169 * see if we should send a push_request in response to --pull
172 check_push_request (struct context
*c
)
174 void check_push_request_dowork (struct context
*c
);
175 if (event_timeout_trigger (&c
->c2
.push_request_interval
, &c
->c2
.timeval
, ETT_DEFAULT
))
176 check_push_request_dowork (c
);
183 * Should we persist our anti-replay packet ID state to disk?
186 check_packet_id_persist_flush (struct context
*c
)
188 if (packet_id_persist_enabled (&c
->c1
.pid_persist
)
189 && event_timeout_trigger (&c
->c2
.packet_id_persist_interval
, &c
->c2
.timeval
, ETT_DEFAULT
))
190 packet_id_persist_save (&c
->c1
.pid_persist
);
195 * Set our wakeup to 0 seconds, so we will be rescheduled
199 context_immediate_reschedule (struct context
*c
)
201 c
->c2
.timeval
.tv_sec
= 0; /* ZERO-TIMEOUT */
202 c
->c2
.timeval
.tv_usec
= 0;
206 context_reschedule_sec (struct context
*c
, int sec
)
210 if (sec
< c
->c2
.timeval
.tv_sec
)
212 c
->c2
.timeval
.tv_sec
= sec
;
213 c
->c2
.timeval
.tv_usec
= 0;
217 static inline struct link_socket_info
*
218 get_link_socket_info (struct context
*c
)
220 if (c
->c2
.link_socket_info
)
221 return c
->c2
.link_socket_info
;
223 return &c
->c2
.link_socket
->info
;
227 register_activity (struct context
*c
, const int size
)
229 if (c
->options
.inactivity_timeout
)
231 c
->c2
.inactivity_bytes
+= size
;
232 if (c
->c2
.inactivity_bytes
>= c
->options
.inactivity_minimum_bytes
)
234 c
->c2
.inactivity_bytes
= 0;
235 event_timeout_reset (&c
->c2
.inactivity_interval
);
241 * Return the io_wait() flags appropriate for
242 * a point-to-point tunnel.
244 static inline unsigned int
245 p2p_iow_flags (const struct context
*c
)
247 unsigned int flags
= (IOW_SHAPER
|IOW_CHECK_RESIDUAL
|IOW_FRAG
|IOW_READ
|IOW_WAIT_SIGNAL
);
248 if (c
->c2
.to_link
.len
> 0)
249 flags
|= IOW_TO_LINK
;
250 if (c
->c2
.to_tun
.len
> 0)
256 * This is the core I/O wait function, used for all I/O waits except
257 * for TCP in server mode.
260 io_wait (struct context
*c
, const unsigned int flags
)
262 void io_wait_dowork (struct context
*c
, const unsigned int flags
);
264 if (c
->c2
.fast_io
&& (flags
& (IOW_TO_TUN
|IOW_TO_LINK
|IOW_MBUF
)))
266 /* fast path -- only for TUN/TAP/UDP writes */
267 unsigned int ret
= 0;
268 if (flags
& IOW_TO_TUN
)
270 if (flags
& (IOW_TO_LINK
|IOW_MBUF
))
272 c
->c2
.event_set_status
= ret
;
277 io_wait_dowork (c
, flags
);
281 #define CONNECTION_ESTABLISHED(c) (get_link_socket_info(c)->connection_established)
283 #endif /* EVENT_INLINE_H */