85 assert_int_equal(data->
pis.
id, 1);
97 assert_int_equal(data->
pis.
id, 1);
111 assert_int_equal(data->
pis.
id, 1);
124 assert_int_equal(data->
pis.
id, 1);
157 assert_int_equal(data->
pis.
id, 1);
167 assert_non_null(rel);
226 assert_int_equal(buf.
len, 8);
227 uint8_t expected_header[8] = { 0x00, 0x23, 0, 0, 0, 0, 0, 1 };
228 assert_memory_equal(
BPTR(&buf), expected_header, 8);
235 data->pis.id = 0xfa079ab9d2e8;
238 uint8_t expected_header_48[8] = { 0xff, 0xfe, 0xfa, 0x07, 0x9a, 0xb9, 0xd2, 0xe9 };
239 assert_memory_equal(
BPTR(&buf_48), expected_header_48, 8);
243 data->pis.id = 0xfffffffffffe;
246 uint8_t expected_header_of[8] = { 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
247 assert_memory_equal(
BPTR(&buf_of), expected_header_of, 8);
256 assert_int_equal(pin.
id, 1);
259 assert_int_equal(pin.
id, 0xfa079ab9d2e9);
262 assert_int_equal(pin.
id, 0xffffffffffff);
268 struct reliable_ack ack = { .len = 4, .packet_id = { 2, 1, 3, 2 } };
274 assert_int_equal(mru_ack.
len, 3);
275 assert_int_equal(mru_ack.
packet_id[0], 2);
276 assert_int_equal(mru_ack.
packet_id[1], 1);
277 assert_int_equal(mru_ack.
packet_id[2], 3);
281 assert_int_equal(mru_ack.
len, 3);
282 assert_int_equal(mru_ack.
packet_id[0], 2);
283 assert_int_equal(mru_ack.
packet_id[1], 1);
284 assert_int_equal(mru_ack.
packet_id[2], 3);
290 assert_int_equal(mru_ack2.
packet_id[0], 2);
291 assert_int_equal(mru_ack2.
packet_id[1], 1);
292 assert_int_equal(mru_ack2.
packet_id[2], 3);
296 struct reliable_ack ack2 = { .len = 3, .packet_id = { 3, 2, 42 } };
298 assert_int_equal(mru_ack2.
packet_id[0], 3);
299 assert_int_equal(mru_ack2.
packet_id[1], 2);
300 assert_int_equal(mru_ack2.
packet_id[2], 1);
305 assert_int_equal(mru_ack.
len, 3);
306 assert_int_equal(mru_ack.
packet_id[0], 2);
307 assert_int_equal(mru_ack.
packet_id[1], 1);
308 assert_int_equal(mru_ack.
packet_id[2], 3);
312 assert_int_equal(mru_ack.
len, 3);
313 assert_int_equal(mru_ack.
packet_id[0], 2);
314 assert_int_equal(mru_ack.
packet_id[1], 1);
315 assert_int_equal(mru_ack.
packet_id[2], 3);
317 struct reliable_ack ack3 = { .len = 7, .packet_id = { 5, 6, 7, 8, 9, 10, 11 } };
322 struct reliable_ack expected_ack = { .len = 8, .packet_id = { 5, 6, 7, 8, 9, 10, 11, 2 } };
323 assert_int_equal(mru_ack.
len, expected_ack.
len);
383#define SANE_TIMEOUT_BOUND (10 * 1000 * 1000)
389 assert_non_null(rel);
418 for (
int i = 0; i < 40; ++i)
426 assert_ptr_equal(buf, &e->
buf);
458 struct reliable_ack ack = { .len = 1, .packet_id = { 0x40000000 } };
462 assert_int_equal(e->
n_acks, 0);
479 struct reliable_ack ack = { .len = 1, .packet_id = { 0xFFFFFFFF } };
483 assert_int_equal(e->
n_acks, 0);
512 struct reliable_ack ack = { .len = 1, .packet_id = { 2 } };
518 assert_int_equal(e0->
n_acks, 1);
544#define CHAR_N_SEND_BUFFERS 6
545#define CHAR_OPCODE_CONTROL_V1 4
566 assert_true(base + extent >= base);
568 return id < base + extent;
580 for (
int i = 0; i < rel->
size; ++i)
674 for (
size_t a = 0; a < n_anchors; a++)
684 for (
size_t i = 0; i <
SIZE(ids); i++)
690 assert_int_equal(oracle(&rel, ids[i]),
recv_filter(&rel, ids[i]));
697 assert_int_equal(oracle(&rel, ids[i]),
recv_filter(&rel, ids[i]));
741 for (
size_t i = 0; i <
SIZE(bases); i++)
789 for (
size_t a = 0; a < n_anchors; a++)
798 for (
size_t i = 0; i <
SIZE(ids); i++)
889 for (
size_t i = 0; i <
SIZE(wrapped); i++)
906 const packet_id_type midpoint[] = { 0x7FFFFFFF, 0x80000000, 0x80000001 };
908 for (
size_t i = 0; i <
SIZE(midpoint); i++)
980 expect_assert_failure(
982 expect_assert_failure(
992 const struct CMUnitTest tests[] = {
1029 return cmocka_run_group_tests_name(
"packet_id tests", tests, NULL, NULL);
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
#define BPTR(buf)
Return a pointer to the start of the buffer content.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
void reliable_free(struct reliable *rel)
Free allocated memory associated with a reliable structure and the pointer itself.
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...
int reliable_get_num_output_sequenced_available(const struct reliable *rel)
Counts the number of free buffers in output that can be potentially used for sending.
bool reliable_pid_in_send_window(const struct reliable *rel, packet_id_type pid)
Check whether pid is one of the RELIABLE_CAPACITY ids below rel->packet_id, and so could still be out...
#define N_ACK_RETRANSMIT
We retry sending a packet early if this many later packets have been ACKed.
void reliable_mark_active_incoming(struct reliable *rel, const struct buffer *buf, packet_id_type pid, int opcode)
Mark the reliable entry associated with the given buffer as active incoming.
void reliable_send_purge(struct reliable *rel, const struct reliable_ack *ack)
Remove acknowledged packets from a reliable structure.
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_not_replay(const struct reliable *rel, packet_id_type id)
Check that a received packet's ID is not a replay and is inside the receive window.
#define RELIABLE_CAPACITY
The maximum number of packets that the reliability layer for one VPN tunnel in one direction can stor...
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.
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.
uint16_t packet_id_read_epoch(struct packet_id_net *pin, struct buffer *buf)
Reads the packet ID containing both the epoch and the per-epoch counter from the buf.
bool packet_id_write_epoch(struct packet_id_send *p, uint16_t epoch, struct buffer *buf)
Writes the packet ID containing both the epoch and the packet id to the buffer specified by buf.
bool packet_id_write(struct packet_id_send *p, struct buffer *buf, bool long_form, bool prepend)
Write a packet ID to buf, and update the packet ID state.
Reliability Layer module header file.
Wrapper structure for dynamically allocated memory.
int capacity
Size in bytes of memory allocated by malloc().
uint8_t * data
Pointer to the 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.
Data structure for describing the packet id that is received/send to the network.
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]
packet_id_type packet_id
Packet ID for the next packet to be sent out.
interval_t initial_timeout
struct packet_id_send pis
struct test_packet_id_write_data::@165330142221073303145237133103267144356214050261 test_buf_data
static void openvpn_unit_test_setup(void)
Sets up the environment for unit tests like making both stderr and stdout non-buffered to avoid messa...
static const packet_id_type char_anchors[]
static void test_recv_filter_characterization(void **state)
static bool ref_not_replay(const struct reliable *rel, packet_id_type id)
static void test_reliable_send_matches_can_send(void **state)
static enum recv_verdict ref_recv_filter(const struct reliable *rel, packet_id_type id)
static void test_recv_window_bounded_at_wrap(void **state)
static int test_packet_id_write_setup(void **state)
static void test_packet_id_write_epoch(void **state)
static void test_reliable_send_ignores_entry_ahead(void **state)
static bool ref_pid_min(packet_id_type p1, packet_id_type p2)
static void test_reliable_send_picks_oldest(void **state)
static void test_packet_id_write_long_prepend(void **state)
static void test_packet_id_write_short_wrap(void **state)
static void test_mark_active_incoming_accepts_window(void **state)
static const packet_id_type char_offsets[]
static bool ref_pid_in_send_window(const struct reliable *rel, packet_id_type pid)
static void sweep_recv_filter(const packet_id_type *anchors, size_t n_anchors, enum recv_verdict(*oracle)(const struct reliable *, packet_id_type))
static enum recv_verdict ref_recv_filter_bounded(const struct reliable *rel, packet_id_type id)
static void test_packet_id_write_short_prepend(void **state)
static void test_wont_break_sequentiality_accepts_next_id(void **state)
static void test_packet_id_window(void **state)
static void test_reliable_backoff_is_bounded(void **state)
#define SANE_TIMEOUT_BOUND
static void sweep_send_window(const packet_id_type *anchors, size_t n_anchors)
static void test_reliable_purge_ignores_forged_acks(void **state)
static void test_packet_id_write_long(void **state)
static int test_packet_id_write_teardown(void **state)
#define CHAR_OPCODE_CONTROL_V1
static void test_reliable_purge_legitimate_ack(void **state)
static void test_get_buf_output_sequenced_boundary(void **state)
#define CHAR_N_SEND_BUFFERS
static void test_get_num_output_sequenced_available(void **state)
static struct reliable * test_reliable_new(void)
static void test_copy_acks_to_lru(void **state)
static const packet_id_type char_anchors_high[]
static enum recv_verdict recv_filter(const struct reliable *rel, packet_id_type id)
static void test_recv_filter_high_base(void **state)
static bool ref_wont_break_sequentiality(const struct reliable *rel, packet_id_type id)
static void test_send_window_characterization(void **state)
static void test_mark_active_incoming_rejects_past_ids(void **state)
static void test_packet_id_write_long_wrap(void **state)
static void test_packet_id_write_short(void **state)