OpenVPN
reliable.h
Go to the documentation of this file.
1 /*
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
6  * packet compression.
7  *
8  * Copyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net>
9  *
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.
13  *
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.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23 
24 
31 #ifndef RELIABLE_H
32 #define RELIABLE_H
33 
34 #include "basic.h"
35 #include "buffer.h"
36 #include "packet_id.h"
37 #include "session_id.h"
38 #include "mtu.h"
39 
44 #define EXPONENTIAL_BACKOFF
45 
46 #define RELIABLE_ACK_SIZE 8
51 #define RELIABLE_CAPACITY 8
55 #define N_ACK_RETRANSMIT 3
63 struct reliable_ack
64 {
65  int len;
67 };
68 
74 {
75  bool active;
77  time_t next_try;
79  size_t n_acks; /* Number of acks received for packets with higher PID.
80  * Used for fast retransmission when there were at least
81  * N_ACK_RETRANSMIT. */
82  int opcode;
83  struct buffer buf;
84 };
85 
90 struct reliable
91 {
92  int size;
93  interval_t initial_timeout;
95  int offset;
96  bool hold; /* don't xmit until reliable_schedule_now is called */
98 };
99 
101 /**************************************************************************/
123 bool reliable_ack_read(struct reliable_ack *ack,
124  struct buffer *buf, const struct session_id *sid);
125 
133 void reliable_send_purge(struct reliable *rel, const struct reliable_ack *ack);
134 
138 /**************************************************************************/
152 static inline bool
153 reliable_ack_empty(struct reliable_ack *ack)
154 {
155  return !ack->len;
156 }
157 
176 bool reliable_ack_write(struct reliable_ack *ack,
177  struct buffer *buf,
178  const struct session_id *sid, int max, bool prepend);
179 
183 /**************************************************************************/
199 void reliable_init(struct reliable *rel, int buf_size, int offset, int array_size, bool hold);
200 
208 void reliable_free(struct reliable *rel);
209 
210 /* add to extra_frame the maximum number of bytes we will need for reliable_ack_write */
211 void reliable_ack_adjust_frame_parameters(struct frame *frame, int max);
212 
216 /**************************************************************************/
230 bool reliable_can_get(const struct reliable *rel);
231 
243 bool reliable_not_replay(const struct reliable *rel, packet_id_type id);
244 
267 bool reliable_wont_break_sequentiality(const struct reliable *rel, packet_id_type id);
268 
280 
292 struct buffer *reliable_get_buf(struct reliable *rel);
293 
303 void reliable_mark_active_incoming(struct reliable *rel, struct buffer *buf,
304  packet_id_type pid, int opcode);
305 
320 
324 /**************************************************************************/
338 struct buffer *reliable_get_buf_sequenced(struct reliable *rel);
339 
348 void reliable_mark_deleted(struct reliable *rel, struct buffer *buf, bool inc_pid);
349 
353 /**************************************************************************/
370 
382 void reliable_mark_active_outgoing(struct reliable *rel, struct buffer *buf, int opcode);
383 
387 /**************************************************************************/
403 bool reliable_can_send(const struct reliable *rel);
404 
422 struct buffer *reliable_send(struct reliable *rel, int *opcode);
423 
427 /**************************************************************************/
441 bool reliable_empty(const struct reliable *rel);
442 
454 interval_t reliable_send_timeout(const struct reliable *rel);
455 
463 void reliable_schedule_now(struct reliable *rel);
464 
465 void reliable_debug_print(const struct reliable *rel, char *desc);
466 
467 /* set sending timeout (after this time we send again until ACK) */
468 static inline void
470 {
471  rel->initial_timeout = timeout;
472 }
473 
474 /* print a reliable ACK record coming off the wire */
475 const char *reliable_ack_print(struct buffer *buf, bool verbose, struct gc_arena *gc);
477 void reliable_ack_debug_print(const struct reliable_ack *ack, char *desc);
478 
485 #endif /* RELIABLE_H */
void reliable_free(struct reliable *rel)
Free allocated memory associated with a reliable structure and the pointer itself.
Definition: reliable.c:327
interval_t initial_timeout
Definition: reliable.h:100
Packet geometry parameters.
Definition: mtu.h:93
#define RELIABLE_ACK_SIZE
The maximum number of packet IDs waiting to be acknowledged which can be stored in one reliable_ack s...
Definition: reliable.h:46
int opcode
Definition: reliable.h:89
void reliable_debug_print(const struct reliable *rel, char *desc)
bool reliable_empty(const struct reliable *rel)
Check whether a reliable structure is empty.
Definition: reliable.c:344
struct buffer * reliable_get_buf(struct reliable *rel)
Get the buffer of a free reliable entry in which to store a packet.
Definition: reliable.c:485
size_t n_acks
Definition: reliable.h:86
void reliable_mark_active_outgoing(struct reliable *rel, struct buffer *buf, int opcode)
Mark the reliable entry associated with the given buffer as active outgoing.
Definition: reliable.c:715
static void reliable_set_timeout(struct reliable *rel, interval_t timeout)
Definition: reliable.h:476
bool reliable_ack_write(struct reliable_ack *ack, struct buffer *buf, const struct session_id *sid, int max, bool prepend)
Write a packet ID acknowledgment record to a buffer.
Definition: reliable.c:213
void reliable_ack_adjust_frame_parameters(struct frame *frame, int max)
Definition: reliable.c:258
bool reliable_not_replay(const struct reliable *rel, packet_id_type id)
Check that a received packet&#39;s ID is not a replay.
Definition: reliable.c:438
struct buffer * reliable_get_buf_output_sequenced(struct reliable *rel)
Get the buffer of free reliable entry and check whether the outgoing acknowledgment sequence is still...
Definition: reliable.c:502
const char * reliable_ack_print(struct buffer *buf, bool verbose, struct gc_arena *gc)
Definition: reliable.c:265
bool active
Definition: reliable.h:82
interval_t reliable_send_timeout(const struct reliable *rel)
Determined how many seconds until the earliest resend should be attempted.
Definition: reliable.c:645
static bool reliable_ack_empty(struct reliable_ack *ack)
Check whether an acknowledgment structure contains any packet IDs to be acknowledged.
Definition: reliable.h:160
struct buffer buf
Definition: reliable.h:90
packet_id_type packet_id
Definition: reliable.h:85
void reliable_ack_debug_print(const struct reliable_ack *ack, char *desc)
#define RELIABLE_CAPACITY
The maximum number of packets that the reliability layer for one VPN tunnel in one direction can stor...
Definition: reliable.h:54
bool reliable_wont_break_sequentiality(const struct reliable *rel, packet_id_type id)
Check that a received packet&#39;s ID can safely be stored in the reliable structure&#39;s processing window...
Definition: reliable.c:465
struct buffer * reliable_get_buf_sequenced(struct reliable *rel)
Get the buffer of the next sequential and active entry.
Definition: reliable.c:538
time_t next_try
Definition: reliable.h:84
struct buffer * reliable_send(struct reliable *rel, int *opcode)
Get the next packet to send to the remote peer.
Definition: reliable.c:582
void reliable_mark_deleted(struct reliable *rel, struct buffer *buf, bool inc_pid)
Remove an entry from a reliable structure.
Definition: reliable.c:742
The structure in which the reliability layer stores a single incoming or outgoing packet...
Definition: reliable.h:80
The acknowledgment structure in which packet IDs are stored for later acknowledgment.
Definition: reliable.h:70
Wrapper structure for dynamically allocated memory.
Definition: buffer.h:60
bool reliable_ack_read_packet_id(struct buffer *buf, packet_id_type *pid)
Read the packet ID of a received packet.
Definition: reliable.c:123
bool reliable_can_send(const struct reliable *rel)
Check whether a reliable structure has any active entries ready to be (re)sent.
Definition: reliable.c:554
void reliable_init(struct reliable *rel, int buf_size, int offset, int array_size, bool hold)
Initialize a reliable structure.
Definition: reliable.c:309
The reliability layer storage structure for one VPN tunnel&#39;s control channel in one direction...
Definition: reliable.h:97
uint32_t packet_id_type
Definition: packet_id.h:49
bool reliable_can_get(const struct reliable *rel)
Check whether a reliable structure has any free buffers available for use.
Definition: reliable.c:419
Garbage collection arena used to keep track of dynamically allocated memory.
Definition: buffer.h:116
bool reliable_ack_read(struct reliable_ack *ack, struct buffer *buf, const struct session_id *sid)
Read an acknowledgment record from a received packet.
Definition: reliable.c:158
int interval_t
Definition: common.h:36
void reliable_mark_active_incoming(struct reliable *rel, struct buffer *buf, packet_id_type pid, int opcode)
Mark the reliable entry associated with the given buffer as active incoming.
Definition: reliable.c:682
interval_t timeout
Definition: reliable.h:83
void reliable_schedule_now(struct reliable *rel)
Reschedule all entries of a reliable structure to be ready for (re)sending immediately.
Definition: reliable.c:626
void reliable_send_purge(struct reliable *rel, const struct reliable_ack *ack)
Remove acknowledged packets from a reliable structure.
Definition: reliable.c:360
bool reliable_ack_acknowledge_packet_id(struct reliable_ack *ack, packet_id_type pid)
Record a packet ID for later acknowledgment.
Definition: reliable.c:141