Skip to content

Commit c2db895

Browse files
authored
Merge pull request #84 from danielinux/fixes-20260322
Add DNS query timeout/retries. Add DHCP lease renewal. Fixes for TCP, ARP, ICMP.
2 parents 5dbd9ca + a4a73ef commit c2db895

7 files changed

Lines changed: 881 additions & 36 deletions

File tree

src/test/unit/unit.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ Suite *wolf_suite(void)
117117
#endif
118118
tcase_add_test(tc_utils, test_wolfip_ipconfig_ex_per_interface);
119119
tcase_add_test(tc_utils, test_wolfip_poll_executes_timers_and_callbacks);
120+
tcase_add_test(tc_utils, test_wolfip_poll_preserves_tcp_events_raised_during_callback);
120121
tcase_add_test(tc_utils, test_filter_notify_tcp_metadata);
121122
tcase_add_test(tc_utils, test_filter_dispatch_no_callback);
122123
tcase_add_test(tc_utils, test_filter_dispatch_mask_not_set);
@@ -237,6 +238,7 @@ Suite *wolf_suite(void)
237238
tcase_add_test(tc_utils, test_sock_connect_icmp_primary_fallback);
238239
tcase_add_test(tc_utils, test_sock_connect_tcp_filter_drop);
239240
tcase_add_test(tc_utils, test_sock_connect_tcp_src_port_low);
241+
tcase_add_test(tc_utils, test_sock_connect_tcp_initial_seq_randomized);
240242
tcase_add_test(tc_utils, test_sock_sendto_more_error_paths);
241243
tcase_add_test(tc_utils, test_sock_sendto_udp_no_dest);
242244
tcase_add_test(tc_utils, test_sock_sendto_udp_sets_dest_and_assigns);
@@ -290,6 +292,8 @@ Suite *wolf_suite(void)
290292
tcase_add_test(tc_utils, test_poll_icmp_send_on_arp_hit);
291293
tcase_add_test(tc_utils, test_dhcp_timer_cb_paths);
292294
tcase_add_test(tc_utils, test_dhcp_client_init_and_bound);
295+
tcase_add_test(tc_utils, test_dhcp_send_request_renewing_sets_ciaddr_and_rebind_deadline);
296+
tcase_add_test(tc_utils, test_dhcp_send_request_rebinding_broadcasts_to_lease_expiry);
293297
tcase_add_test(tc_utils, test_dhcp_poll_offer_and_ack);
294298
tcase_add_test(tc_utils, test_dns_callback_ptr_response);
295299
tcase_add_test(tc_utils, test_udp_try_recv_short_frame);
@@ -348,6 +352,12 @@ Suite *wolf_suite(void)
348352
tcase_add_test(tc_utils, test_dns_skip_and_copy_name);
349353
tcase_add_test(tc_utils, test_sock_opts_and_names);
350354
tcase_add_test(tc_utils, test_dns_send_query_errors);
355+
tcase_add_test(tc_utils, test_dns_schedule_timer_initial_jitter_and_cancel);
356+
tcase_add_test(tc_utils, test_dns_schedule_timer_caps_large_retry_shift);
357+
tcase_add_test(tc_utils, test_dns_send_query_schedules_timeout);
358+
tcase_add_test(tc_utils, test_dns_resend_query_uses_stored_query_buffer);
359+
tcase_add_test(tc_utils, test_dns_abort_query_clears_timer_and_query_state);
360+
tcase_add_test(tc_utils, test_dns_timeout_retries_then_aborts_and_allows_new_query);
351361
tcase_add_test(tc_utils, test_dns_send_query_invalid_name);
352362
tcase_add_test(tc_utils, test_dns_wrapper_apis);
353363
tcase_add_test(tc_utils, test_wolfip_static_instance_apis);
@@ -383,6 +393,8 @@ Suite *wolf_suite(void)
383393
tcase_add_test(tc_utils, test_tcp_input_syn_sent_unexpected_flags);
384394
tcase_add_test(tc_utils, test_tcp_input_syn_sent_synack_transitions);
385395
tcase_add_test(tc_utils, test_tcp_input_syn_sent_synack_invalid_ack_rejected);
396+
tcase_add_test(tc_utils, test_tcp_input_syn_listen_does_not_scale_syn_window);
397+
tcase_add_test(tc_utils, test_tcp_input_syn_sent_does_not_scale_synack_window);
386398
tcase_add_test(tc_utils, test_tcp_parse_sack_wraparound_block_accepted);
387399
tcase_add_test(tc_utils, test_tcp_input_rst_bad_seq_ignored);
388400
tcase_add_test(tc_utils, test_tcp_input_rst_seq_in_window_sends_ack);
@@ -577,6 +589,7 @@ Suite *wolf_suite(void)
577589
tcase_add_test(tc_proto, test_arp_recv_request_other_ip_no_reply);
578590
tcase_add_test(tc_proto, test_arp_recv_null_stack);
579591
tcase_add_test(tc_proto, test_arp_recv_request_sends_reply);
592+
tcase_add_test(tc_proto, test_arp_recv_request_does_not_store_self_neighbor);
580593
tcase_add_test(tc_proto, test_arp_recv_request_no_send_fn);
581594
tcase_add_test(tc_proto, test_wolfip_if_for_local_ip_paths);
582595
tcase_add_test(tc_proto, test_wolfip_if_for_local_ip_null_found);
@@ -640,6 +653,8 @@ Suite *wolf_suite(void)
640653
tcase_add_test(tc_proto, test_udp_recvfrom_src_equals_local_ip_does_not_persist_remote);
641654
tcase_add_test(tc_proto, test_dns_query_and_callback_a);
642655
tcase_add_test(tc_proto, test_dhcp_parse_offer_and_ack);
656+
tcase_add_test(tc_proto, test_dhcp_schedule_lease_timer_defaults_t1_t2);
657+
tcase_add_test(tc_proto, test_dhcp_schedule_lease_timer_small_lease_clamps_t1_t2);
643658
tcase_add_test(tc_proto, test_dhcp_parse_offer_defaults_mask_when_missing);
644659
tcase_add_test(tc_proto, test_dhcp_parse_offer_rejects_mismatched_xid);
645660
tcase_add_test(tc_proto, test_dhcp_parse_ack_rejects_mismatched_xid);
@@ -652,6 +667,7 @@ Suite *wolf_suite(void)
652667
tcase_add_test(tc_proto, test_regression_udp_inflated_udp_len);
653668
tcase_add_test(tc_proto, test_regression_udp_len_below_header_discards_and_unblocks);
654669
tcase_add_test(tc_proto, test_regression_udp_payload_exceeds_buffer_discards_and_unblocks);
670+
tcase_add_test(tc_proto, test_regression_icmp_payload_exceeds_buffer_discards_and_unblocks);
655671
tcase_add_test(tc_proto, test_regression_tcp_ip_len_below_ip_header);
656672

657673
tcase_add_test(tc_utils, test_transport_checksum);

src/test/unit/unit_tests_api.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
static struct wolfIP *poll_rearm_stack;
2+
static int poll_rearm_cb_calls;
3+
static int poll_rearm_recv_len;
4+
5+
static void test_poll_rearm_tcp_cb(int sock_fd, uint16_t events, void *arg)
6+
{
7+
uint8_t buf[8];
8+
9+
(void)arg;
10+
poll_rearm_cb_calls++;
11+
ck_assert_ptr_nonnull(poll_rearm_stack);
12+
ck_assert_uint_eq(events & CB_EVENT_READABLE, CB_EVENT_READABLE);
13+
ck_assert_int_eq(wolfIP_sock_recvfrom(poll_rearm_stack, sock_fd, buf,
14+
(size_t)poll_rearm_recv_len, 0, NULL, NULL), poll_rearm_recv_len);
15+
}
16+
117
START_TEST(test_wolfip_poll_executes_timers_and_callbacks)
218
{
319
struct wolfIP s;
@@ -31,6 +47,39 @@ START_TEST(test_wolfip_poll_executes_timers_and_callbacks)
3147
}
3248
END_TEST
3349

50+
START_TEST(test_wolfip_poll_preserves_tcp_events_raised_during_callback)
51+
{
52+
struct wolfIP s;
53+
int tcp_sd;
54+
struct tsocket *ts;
55+
uint8_t payload[8] = {0};
56+
57+
wolfIP_init(&s);
58+
mock_link_init(&s);
59+
60+
tcp_sd = wolfIP_sock_socket(&s, AF_INET, IPSTACK_SOCK_STREAM, WI_IPPROTO_TCP);
61+
ck_assert_int_gt(tcp_sd, 0);
62+
ts = &s.tcpsockets[SOCKET_UNMARK(tcp_sd)];
63+
ts->sock.tcp.state = TCP_ESTABLISHED;
64+
queue_init(&ts->sock.tcp.rxbuf, ts->rxmem, RXBUF_SIZE, 0);
65+
ck_assert_int_eq(queue_insert(&ts->sock.tcp.rxbuf, payload, 0, sizeof(payload)), 0);
66+
67+
poll_rearm_stack = &s;
68+
poll_rearm_cb_calls = 0;
69+
poll_rearm_recv_len = 4;
70+
wolfIP_register_callback(&s, tcp_sd, test_poll_rearm_tcp_cb, NULL);
71+
ts->events = CB_EVENT_READABLE;
72+
73+
(void)wolfIP_poll(&s, 100);
74+
ck_assert_int_eq(poll_rearm_cb_calls, 1);
75+
ck_assert_uint_eq(ts->events & CB_EVENT_READABLE, CB_EVENT_READABLE);
76+
77+
(void)wolfIP_poll(&s, 101);
78+
ck_assert_int_eq(poll_rearm_cb_calls, 2);
79+
ck_assert_uint_eq(ts->events & CB_EVENT_READABLE, 0U);
80+
}
81+
END_TEST
82+
3483
START_TEST(test_filter_notify_tcp_metadata)
3584
{
3685
struct wolfIP s;

0 commit comments

Comments
 (0)