2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
8 * Copyright (C) 2002-2005 OpenVPN Solutions LLC <info@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
26 * This routines implement a reliability layer on top of UDP,
27 * so that TLS can be run over UDP.
30 #if defined(USE_CRYPTO) && defined(USE_SSL)
37 #include "packet_id.h"
38 #include "session_id.h"
41 /* #define EXPONENTIAL_BACKOFF */
43 #define RELIABLE_ACK_SIZE 8
48 packet_id_type packet_id
[RELIABLE_ACK_SIZE
];
51 /* no active buffers? */
53 reliable_ack_empty (struct reliable_ack
*ack
)
58 /* get a packet_id from buf */
59 bool reliable_ack_read_packet_id (struct buffer
*buf
, packet_id_type
*pid
);
61 /* acknowledge a packet_id by adding it to a struct reliable_ack */
62 bool reliable_ack_acknowledge_packet_id (struct reliable_ack
*ack
, packet_id_type pid
);
64 /* read a packet ID acknowledgement record from buf */
65 bool reliable_ack_read (struct reliable_ack
*ack
,
66 struct buffer
*buf
, const struct session_id
*sid
);
68 /* write a packet ID acknowledgement record to buf */
69 bool reliable_ack_write (struct reliable_ack
*ack
,
71 const struct session_id
*sid
, int max
, bool prepend
);
73 /* print a reliable ACK record coming off the wire */
74 const char *reliable_ack_print (struct buffer
*buf
, bool verbose
, struct gc_arena
*gc
);
76 /* add to extra_frame the maximum number of bytes we will need for reliable_ack_write */
77 void reliable_ack_adjust_frame_parameters (struct frame
* frame
, int max
);
79 void reliable_ack_debug_print (const struct reliable_ack
*ack
, char *desc
);
81 #define RELIABLE_CAPACITY 8
88 packet_id_type packet_id
;
96 interval_t initial_timeout
;
97 packet_id_type packet_id
;
99 struct reliable_entry array
[RELIABLE_CAPACITY
];
102 void reliable_debug_print (const struct reliable
*rel
, char *desc
);
104 /* set sending timeout (after this time we send again until ACK) */
106 reliable_set_timeout (struct reliable
*rel
, interval_t timeout
)
108 rel
->initial_timeout
= timeout
;
111 void reliable_init (struct reliable
*rel
, int buf_size
, int offset
, int array_size
);
113 void reliable_free (struct reliable
*rel
);
115 /* no active buffers? */
116 bool reliable_empty (const struct reliable
*rel
);
118 /* in how many seconds should we wake up to check for timeout */
119 interval_t
reliable_send_timeout (const struct reliable
*rel
);
121 /* del acknowledged items from send buf */
122 void reliable_send_purge (struct reliable
*rel
, struct reliable_ack
*ack
);
124 /* true if at least one free buffer available */
125 bool reliable_can_get (const struct reliable
*rel
);
127 /* make sure that incoming packet ID isn't a replay */
128 bool reliable_not_replay (const struct reliable
*rel
, packet_id_type id
);
130 /* make sure that incoming packet ID won't deadlock the receive buffer */
131 bool reliable_wont_break_sequentiality (const struct reliable
*rel
, packet_id_type id
);
133 /* grab a free buffer */
134 struct buffer
*reliable_get_buf (struct reliable
*rel
);
136 /* grab a free buffer, fail if buffer clogged by unacknowledged low packet IDs */
137 struct buffer
*reliable_get_buf_output_sequenced (struct reliable
*rel
);
139 /* get active buffer for next sequentially increasing key ID */
140 struct buffer
*reliable_get_buf_sequenced (struct reliable
*rel
);
142 /* return true if reliable_send would return a non-NULL result */
143 bool reliable_can_send (const struct reliable
*rel
);
145 /* return next buffer to send to remote */
146 struct buffer
*reliable_send (struct reliable
*rel
, int *opcode
);
148 /* schedule all pending packets for immediate retransmit */
149 void reliable_schedule_now (struct reliable
*rel
);
151 /* enable an incoming buffer previously returned by a get function as active */
152 void reliable_mark_active_incoming (struct reliable
*rel
, struct buffer
*buf
,
153 packet_id_type pid
, int opcode
);
155 /* enable an outgoing buffer previously returned by a get function as active. */
156 void reliable_mark_active_outgoing (struct reliable
*rel
, struct buffer
*buf
, int opcode
);
158 /* delete a buffer previously activated by reliable_mark_active() */
159 void reliable_mark_deleted (struct reliable
*rel
, struct buffer
*buf
, bool inc_pid
);
161 #endif /* RELIABLE_H */
162 #endif /* USE_CRYPTO && USE_SSL */