54 const unsigned int extent)
64 const unsigned int extent)
66 if (base + extent >= base)
68 if (test < base + extent)
75 if ((test + 0x80000000u) < (base + 0x80000000u) + extent)
97 for (
int i = 0;
i < ack->
len; ++
i)
113 if (
buf_read(buf, &net_pid,
sizeof(net_pid)))
157 dmsg(
D_REL_LOW,
"ACK read BAD SESSION-ID FROM REMOTE, local=%s, remote=%s",
172 if (!
buf_read(buf, &count,
sizeof(count)))
176 for (
int i = 0;
i < count; ++
i)
179 if (!
buf_read(buf, &net_pid,
sizeof(net_pid)))
208 for (
int i = n - 1;
i >= 0;
i--)
213 if (ack_mru->
len == 0)
219 bool idfound =
false;
224 for (
int j = 0; j < ack_mru->
len; j++)
249 const struct session_id *sid,
int max,
bool prepend)
290 for (
i = 0,
j = n;
j <
ack->len;)
292 ack->packet_id[
i++] =
ack->packet_id[
j++];
353 rel->
size = array_size;
355 for (
int i = 0;
i < rel->
size; ++
i)
370 for (
int i = 0;
i < rel->
size; ++
i)
382 for (
int i = 0;
i < rel->
size; ++
i)
397 for (
int i = 0;
i < ack->
len; ++
i)
400 for (
int j = 0; j < rel->
size; ++j)
440 for (
int i = 0;
i <
rel->size; ++
i)
456 for (
int i = 0;
i < rel->
size; ++
i)
465 dmsg(
D_REL_LOW,
"ACK no free receive buffer available: %s", reliable_print_ids(rel, &
gc));
479 for (
int i = 0;
i < rel->
size; ++
i)
492 reliable_print_ids(rel, &
gc));
520 for (
int i = 0;
i <
rel->size; ++
i)
536 bool min_id_defined =
false;
539 for (
int i = 0;
i < rel->
size; ++
i)
546 min_id_defined =
true;
569 for (
int i = 0;
i <
rel->size; ++
i)
576 min_id_defined =
true;
589 dmsg(
D_REL_LOW,
"ACK output sequence broken: %s", reliable_print_ids(rel, &
gc));
599 for (
int i = 0;
i < rel->
size; ++
i)
615 int n_active = 0, n_current = 0;
616 for (
int i = 0;
i < rel->
size; ++
i)
629 dmsg(
D_REL_DEBUG,
"ACK reliable_can_send active=%d current=%d : %s", n_active, n_current,
630 reliable_print_ids(rel, &
gc));
633 return n_current > 0 && !rel->
hold;
641 const time_t local_now =
now;
643 for (
int i = 0;
i < rel->
size; ++
i)
679 for (
int i = 0;
i < rel->
size; ++
i)
697 const time_t local_now =
now;
699 for (
int i = 0;
i < rel->
size; ++
i)
716 dmsg(
D_REL_DEBUG,
"ACK reliable_send_timeout %d %s", (
int)ret, reliable_print_ids(rel, &
gc));
730 for (
int i = 0;
i < rel->
size; ++
i)
762 for (
int i = 0;
i < rel->
size; ++
i)
789 for (
int i = 0;
i < rel->
size; ++
i)
807 printf(
"********* struct reliable_ack %s\n", desc);
808 for (
int i = 0;
i < ack->
len; ++
i)
819 printf(
"********* struct reliable %s\n", desc);
822 printf(
" now=%" PRIi64
"\n", (int64_t)
now);
823 for (
int i = 0;
i < rel->
size; ++
i)
829 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_a...
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 ...
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.
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.