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)
298 for (
i = 0,
j = n;
j <
ack->len; )
300 ack->packet_id[
i++] =
ack->packet_id[
j++];
366 for (
i = 0;
i <
rel->size; ++
i)
382 for (i = 0; i < rel->
size; ++i)
395 for (i = 0; i < rel->
size; ++i)
411 for (i = 0; i < ack->
len; ++i)
414 for (j = 0; j < rel->
size; ++j)
455 for (
i = 0;
i <
rel->size; ++
i)
473 for (i = 0; i < rel->
size; ++i)
481 dmsg(
D_REL_LOW,
"ACK no free receive buffer available: %s", reliable_print_ids(rel, &
gc));
496 for (i = 0; i < rel->
size; ++i)
538 for (
i = 0;
i <
rel->size; ++
i)
555 bool min_id_defined =
false;
558 for (
int i = 0; i < rel->
size; ++i)
565 min_id_defined =
true;
587 bool min_id_defined =
false;
591 for (
i = 0;
i <
rel->size; ++
i)
598 min_id_defined =
true;
610 dmsg(
D_REL_LOW,
"ACK output sequence broken: %s", reliable_print_ids(rel, &
gc));
621 for (i = 0; i < rel->
size; ++i)
638 int n_active = 0, n_current = 0;
639 for (i = 0; i < rel->
size; ++i)
654 reliable_print_ids(rel, &
gc));
657 return n_current > 0 && !rel->
hold;
666 const time_t local_now =
now;
668 for (i = 0; i < rel->
size; ++i)
706 for (i = 0; i < rel->
size; ++i)
725 const time_t local_now =
now;
727 for (i = 0; i < rel->
size; ++i)
746 reliable_print_ids(rel, &
gc));
761 for (i = 0; i < rel->
size; ++i)
793 for (i = 0; i < rel->
size; ++i)
820 for (i = 0; i < rel->
size; ++i)
840 printf(
"********* struct reliable_ack %s\n", desc);
841 for (i = 0; i < ack->
len; ++i)
853 printf(
"********* struct reliable %s\n", desc);
856 printf(
" now=%" PRIi64
"\n", (int64_t)
now);
857 for (i = 0; i < rel->
size; ++i)
863 printf(
" next_try=%" PRIi64, (int64_t)e->
next_try);
void free_buf(struct buffer *buf)
bool buf_printf(struct buffer *buf, const char *format,...)
struct buffer buf_sub(struct buffer *buf, int size, bool prepend)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
struct buffer alloc_buf(size_t size)
static bool buf_write_prepend(struct buffer *dest, const void *src, int size)
static bool buf_read(struct buffer *src, void *dest, int size)
static bool buf_write(struct buffer *dest, const void *src, size_t size)
static bool buf_write_u8(struct buffer *dest, uint8_t data)
static void gc_free(struct gc_arena *a)
#define buf_init(buf, offset)
static struct gc_arena gc_new(void)
void reliable_free(struct reliable *rel)
Free allocated memory associated with a reliable structure and the pointer itself.
bool reliable_ack_read(struct reliable_ack *ack, struct buffer *buf, const struct session_id *sid)
Read an acknowledgment record from a received packet.
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...
void reliable_schedule_now(struct reliable *rel)
Reschedule all entries of a reliable structure to be ready for (re)sending immediately.
void reliable_ack_debug_print(const struct reliable_ack *ack, char *desc)
bool reliable_ack_read_packet_id(struct buffer *buf, packet_id_type *pid)
Read the packet ID of 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.
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.
const char * reliable_ack_print(struct buffer *buf, bool verbose, struct gc_arena *gc)
bool reliable_ack_acknowledge_packet_id(struct reliable_ack *ack, packet_id_type pid)
Record a packet ID for later acknowledgment.
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.
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.
#define N_ACK_RETRANSMIT
We retry sending a packet early if this many later packets have been ACKed.
bool reliable_can_get(const struct reliable *rel)
Check whether a reliable structure has any free buffers available for use.
void reliable_send_purge(struct reliable *rel, const struct reliable_ack *ack)
Remove acknowledged packets from a reliable structure.
struct buffer * reliable_get_buf(struct reliable *rel)
Get the buffer of a free reliable entry in which to store a packet.
struct buffer * reliable_send(struct reliable *rel, int *opcode)
Get the next packet to send to the remote peer.
bool reliable_can_send(const struct reliable *rel)
Check whether a reliable structure has any active entries ready to be (re)sent.
bool reliable_empty(const struct reliable *rel)
Check whether a reliable structure is empty.
void reliable_debug_print(const struct reliable *rel, char *desc)
bool reliable_not_replay(const struct reliable *rel, packet_id_type id)
Check that a received packet's ID is not a replay.
#define RELIABLE_ACK_SIZE
The maximum number of packet IDs waiting to be acknowledged which can be stored in one reliable_ack s...
interval_t reliable_send_timeout(const struct reliable *rel)
Determined how many seconds until the earliest resend should be attempted.
#define RELIABLE_CAPACITY
The maximum number of packets that the reliability layer for one VPN tunnel in one direction can stor...
struct reliable_entry * reliable_get_entry_sequenced(struct reliable *rel)
Get the buffer of the next sequential and active entry.
void reliable_init(struct reliable *rel, int buf_size, int offset, int array_size, bool hold)
Initialize a reliable structure.
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.
void reliable_mark_deleted(struct reliable *rel, struct buffer *buf)
Remove an entry from a reliable structure.
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.
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 update_time(void)
uint64_t packet_id_print_type
static packet_id_type subtract_pid(const packet_id_type test, const packet_id_type base)
static bool reliable_ack_packet_id_present(struct reliable_ack *ack, packet_id_type pid)
static bool reliable_pid_in_range1(const packet_id_type test, const packet_id_type base, const unsigned int extent)
static bool reliable_pid_min(const packet_id_type p1, const packet_id_type p2)
static bool reliable_pid_in_range2(const packet_id_type test, const packet_id_type base, const unsigned int extent)
Reliability Layer module header file.
const char * session_id_print(const struct session_id *sid, struct gc_arena *gc)
static bool session_id_write(const struct session_id *sid, struct buffer *buf)
static bool session_id_equal(const struct session_id *sid1, const struct session_id *sid2)
static bool session_id_defined(const struct session_id *sid1)
static bool session_id_read(struct session_id *sid, struct buffer *buf)
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
int offset
Offset in bytes of the actual content within the allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
The acknowledgment structure in which packet IDs are stored for later acknowledgment.
packet_id_type packet_id[RELIABLE_ACK_SIZE]
The structure in which the reliability layer stores a single incoming or outgoing packet.
The reliability layer storage structure for one VPN tunnel's control channel in one direction.
struct reliable_entry array[RELIABLE_CAPACITY]
interval_t initial_timeout
int offset
Offset of the bufs in the reliable_entry array.