Go to the documentation of this file.
56 const unsigned int extent)
67 const unsigned int extent)
69 if (base + extent >= base)
71 if (test < base + extent)
78 if ((test+0x80000000u) < (base+0x80000000u) + extent)
102 for (i = 0; i < ack->
len; ++i)
118 if (
buf_read(buf, &net_pid,
sizeof(net_pid)))
164 "ACK read BAD SESSION-ID FROM REMOTE, local=%s, remote=%s",
179 if (!
buf_read(buf, &count,
sizeof(count)))
183 for (
int i = 0; i < count; ++i)
186 if (!
buf_read(buf, &net_pid,
sizeof(net_pid)))
215 for (
int i = n-1; i >= 0; i--)
220 if (ack_mru->
len == 0)
226 bool idfound =
false;
231 for (
int j = 0; j < ack_mru->
len; j++)
258 const struct session_id *sid,
int max,
bool prepend)
273 uint8_t total_acks =
min_int(max, ack_mru->
len);
285 for (i = 0; i < total_acks; ++i)
299 for (i = 0, j = n; j < ack->
len; )
323 if (!
buf_read(buf, &n_ack,
sizeof(n_ack)))
327 for (i = 0; i < n_ack; ++i)
329 if (!
buf_read(buf, &pid,
sizeof(pid)))
365 rel->
size = array_size;
367 for (i = 0; i < rel->
size; ++i)
383 for (i = 0; i < rel->
size; ++i)
396 for (i = 0; i < rel->
size; ++i)
412 for (i = 0; i < ack->
len; ++i)
415 for (j = 0; j < rel->
size; ++j)
456 for (i = 0; i < rel->
size; ++i)
474 for (i = 0; i < rel->
size; ++i)
482 dmsg(
D_REL_LOW,
"ACK no free receive buffer available: %s", reliable_print_ids(rel, &gc));
497 for (i = 0; i < rel->
size; ++i)
539 for (i = 0; i < rel->
size; ++i)
556 bool min_id_defined =
false;
559 for (
int i = 0; i < rel->
size; ++i)
566 min_id_defined =
true;
588 bool min_id_defined =
false;
589 struct buffer *ret = NULL;
592 for (i = 0; i < rel->
size; ++i)
599 min_id_defined =
true;
611 dmsg(
D_REL_LOW,
"ACK output sequence broken: %s", reliable_print_ids(rel, &gc));
622 for (i = 0; i < rel->
size; ++i)
639 int n_active = 0, n_current = 0;
640 for (i = 0; i < rel->
size; ++i)
655 reliable_print_ids(rel, &gc));
658 return n_current > 0 && !rel->
hold;
667 const time_t local_now =
now;
669 for (i = 0; i < rel->
size; ++i)
707 for (i = 0; i < rel->
size; ++i)
726 const time_t local_now =
now;
728 for (i = 0; i < rel->
size; ++i)
747 reliable_print_ids(rel, &gc));
762 for (i = 0; i < rel->
size; ++i)
794 for (i = 0; i < rel->
size; ++i)
821 for (i = 0; i < rel->
size; ++i)
841 printf(
"********* struct reliable_ack %s\n", desc);
842 for (i = 0; i < ack->
len; ++i)
854 printf(
"********* struct reliable %s\n", desc);
857 printf(
" now=%" PRIi64
"\n", (int64_t)
now);
858 for (i = 0; i < rel->
size; ++i)
864 printf(
" next_try=%" PRIi64, (int64_t)e->
next_try);
void reliable_schedule_now(struct reliable *rel)
Reschedule all entries of a reliable structure to be ready for (re)sending immediately.
bool reliable_ack_acknowledge_packet_id(struct reliable_ack *ack, packet_id_type pid)
Record a packet ID for later acknowledgment.
static bool buf_read(struct buffer *src, void *dest, int size)
static struct gc_arena gc_new(void)
#define RELIABLE_ACK_SIZE
The maximum number of packet IDs waiting to be acknowledged which can be stored in one reliable_ack s...
int len
Length in bytes of the actual content within the allocated memory.
#define buf_init(buf, offset)
bool reliable_empty(const struct reliable *rel)
Check whether a reliable structure is empty.
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
static bool session_id_equal(const struct session_id *sid1, const struct session_id *sid2)
static bool session_id_write(const struct session_id *sid, struct buffer *buf)
struct buffer buf_sub(struct buffer *buf, int size, bool prepend)
const char * session_id_print(const struct session_id *sid, struct gc_arena *gc)
struct buffer * reliable_get_buf(struct reliable *rel)
Get the buffer of a free reliable entry in which to store a packet.
struct reliable_entry array[RELIABLE_CAPACITY]
bool reliable_ack_parse(struct buffer *buf, struct reliable_ack *ack, struct session_id *session_id_remote)
Parse an acknowledgment record from a received packet.
void reliable_debug_print(const struct reliable *rel, char *desc)
int reliable_get_num_output_sequenced_available(struct reliable *rel)
Counts the number of free buffers in output that can be potentially used for sending.
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.
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...
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
bool reliable_not_replay(const struct reliable *rel, packet_id_type id)
Check that a received packet's ID is not a replay.
static bool buf_write_u8(struct buffer *dest, uint8_t data)
static void update_time(void)
static bool session_id_read(struct session_id *sid, struct buffer *buf)
interval_t reliable_send_timeout(const struct reliable *rel)
Determined how many seconds until the earliest resend should be attempted.
void reliable_mark_deleted(struct reliable *rel, struct buffer *buf)
Remove an entry from a reliable structure.
#define N_ACK_RETRANSMIT
We retry sending a packet early if this many later packets have been ACKed.
const char * reliable_ack_print(struct buffer *buf, bool verbose, struct gc_arena *gc)
packet_id_type packet_id[RELIABLE_ACK_SIZE]
static bool reliable_pid_in_range2(const packet_id_type test, const packet_id_type base, const unsigned int extent)
void reliable_ack_debug_print(const struct reliable_ack *ack, char *desc)
Wrapper structure for dynamically allocated memory.
#define RELIABLE_CAPACITY
The maximum number of packets that the reliability layer for one VPN tunnel in one direction can stor...
static packet_id_type subtract_pid(const packet_id_type test, const packet_id_type base)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
unsigned int packet_id_print_type
static bool session_id_defined(const struct session_id *sid1)
struct buffer * reliable_send(struct reliable *rel, int *opcode)
Get the next packet to send to the remote peer.
Garbage collection arena used to keep track of dynamically allocated memory.
int offset
Offset in bytes of the actual content within the allocated memory.
int offset
Offset of the bufs in the reliable_entry array.
The reliability layer storage structure for one VPN tunnel's control channel in one direction.
void free_buf(struct buffer *buf)
bool reliable_ack_read_packet_id(struct buffer *buf, packet_id_type *pid)
Read the packet ID of a received packet.
static bool reliable_ack_packet_id_present(struct reliable_ack *ack, packet_id_type pid)
bool reliable_wont_break_sequentiality(const struct reliable *rel, packet_id_type id)
Check that a received packet's ID can safely be stored in the reliable structure's processing window.
static int min_int(int x, int y)
static void gc_free(struct gc_arena *a)
bool reliable_can_get(const struct reliable *rel)
Check whether a reliable structure has any free buffers available for use.
bool reliable_ack_read(struct reliable_ack *ack, struct buffer *buf, const struct session_id *sid)
Read an acknowledgment record from a received packet.
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.
static bool reliable_pid_in_range1(const packet_id_type test, const packet_id_type base, const unsigned int extent)
struct reliable_entry * reliable_get_entry_sequenced(struct reliable *rel)
Get the buffer of the next sequential and active entry.
bool reliable_can_send(const struct reliable *rel)
Check whether a reliable structure has any active entries ready to be (re)sent.
void reliable_init(struct reliable *rel, int buf_size, int offset, int array_size, bool hold)
Initialize a reliable structure.
interval_t initial_timeout
bool reliable_ack_write(struct reliable_ack *ack, struct reliable_ack *ack_mru, struct buffer *buf, const struct session_id *sid, int max, bool prepend)
Write a packet ID acknowledgment record to a buffer.
void reliable_send_purge(struct reliable *rel, const struct reliable_ack *ack)
Remove acknowledged packets from a reliable structure.
struct buffer alloc_buf(size_t size)
void copy_acks_to_mru(struct reliable_ack *ack, struct reliable_ack *ack_mru, int n)
Copies the first n acks from ack to ack_mru.
static bool reliable_pid_min(const packet_id_type p1, const packet_id_type p2)
The acknowledgment structure in which packet IDs are stored for later acknowledgment.
void reliable_free(struct reliable *rel)
Free allocated memory associated with a reliable structure and the pointer itself.
bool buf_printf(struct buffer *buf, const char *format,...)
The structure in which the reliability layer stores a single incoming or outgoing packet.