Skip to content

Commit fdcb9a5

Browse files
committed
Fixed regressions and addressed copilot's comments
1 parent 7578fbc commit fdcb9a5

9 files changed

Lines changed: 345 additions & 36 deletions

File tree

.github/workflows/stm32h563-m33mu-freertos.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
stm32h563_m33mu_echo_freertos:
1010
runs-on: ubuntu-latest
1111
container:
12-
image: ghcr.io/wolfssl/wolfboot-ci:v1.2
12+
image: ghcr.io/wolfssl/wolfboot-ci-m33mu:v1.2
1313
options: --privileged
1414
steps:
1515
- name: Checkout

.github/workflows/stm32h563-m33mu-ssh-tzen.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
timeout-minutes: 25
1313
container:
14-
image: ghcr.io/wolfssl/wolfboot-ci:v1.2
14+
image: ghcr.io/wolfssl/wolfboot-ci-m33mu:v1.2
1515
options: --privileged
1616

1717
steps:
@@ -72,7 +72,7 @@ jobs:
7272
dhcp-leasefile=/tmp/dnsmasq.leases
7373
log-dhcp
7474
CONF
75-
sudo dnsmasq --no-poll --conf-file=/tmp/dnsmasq.conf --pid-file=/tmp/dnsmasq.pid
75+
sudo dnsmasq --conf-file=/tmp/dnsmasq.conf --pid-file=/tmp/dnsmasq.pid
7676
7777
sudo m33mu src/port/stm32h563/app.bin \
7878
--cpu stm32h563 --tap:tap0 --uart-stdout --timeout 180 --quit-on-faults \

.github/workflows/stm32h563-m33mu.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
runs-on: ubuntu-latest
1212
timeout-minutes: 20
1313
container:
14-
image: ghcr.io/wolfssl/wolfboot-ci:v1.2
14+
image: ghcr.io/wolfssl/wolfboot-ci-m33mu:v1.2
1515
options: --privileged
1616

1717
steps:
@@ -57,7 +57,7 @@ jobs:
5757
dhcp-leasefile=/tmp/dnsmasq.leases
5858
log-dhcp
5959
EOF
60-
sudo dnsmasq --no-poll --conf-file=/tmp/dnsmasq.conf --pid-file=/tmp/dnsmasq.pid
60+
sudo dnsmasq --conf-file=/tmp/dnsmasq.conf --pid-file=/tmp/dnsmasq.pid
6161
6262
sudo m33mu src/port/stm32h563/app.bin \
6363
--cpu stm32h563 --tap:tap0 --uart-stdout --timeout 120 \
@@ -114,7 +114,7 @@ jobs:
114114
runs-on: ubuntu-latest
115115
timeout-minutes: 30
116116
container:
117-
image: ghcr.io/wolfssl/wolfboot-ci:v1.2
117+
image: ghcr.io/wolfssl/wolfboot-ci-m33mu:v1.2
118118
options: --privileged
119119

120120
steps:
@@ -173,7 +173,7 @@ jobs:
173173
dhcp-leasefile=/tmp/dnsmasq.leases
174174
log-dhcp
175175
EOF
176-
sudo dnsmasq --no-poll --conf-file=/tmp/dnsmasq.conf --pid-file=/tmp/dnsmasq.pid
176+
sudo dnsmasq --conf-file=/tmp/dnsmasq.conf --pid-file=/tmp/dnsmasq.pid
177177
178178
sudo m33mu src/port/stm32h563/app.bin \
179179
--cpu stm32h563 --tap:tap0 --uart-stdout --timeout 240 \
@@ -323,7 +323,7 @@ jobs:
323323
runs-on: ubuntu-latest
324324
timeout-minutes: 25
325325
container:
326-
image: ghcr.io/wolfssl/wolfboot-ci:v1.2
326+
image: ghcr.io/wolfssl/wolfboot-ci-m33mu:v1.2
327327
options: --privileged
328328

329329
steps:
@@ -385,7 +385,7 @@ jobs:
385385
dhcp-leasefile=/tmp/dnsmasq.leases
386386
log-dhcp
387387
CONF
388-
sudo dnsmasq --no-poll --conf-file=/tmp/dnsmasq.conf --pid-file=/tmp/dnsmasq.pid
388+
sudo dnsmasq --conf-file=/tmp/dnsmasq.conf --pid-file=/tmp/dnsmasq.pid
389389
390390
sudo tcpdump -i tap0 -nn -U -w /tmp/https-test.pcap > /tmp/tcpdump.log 2>&1 &
391391
echo $! > /tmp/tcpdump.pid

src/test/unit/unit.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ Suite *wolf_suite(void)
342342
tcase_add_test(tc_utils, test_udp_try_recv_remote_ip_matches_local_ip);
343343
tcase_add_test(tc_utils, test_udp_try_recv_unmatched_port_sends_icmp_unreachable);
344344
tcase_add_test(tc_utils, test_udp_try_recv_unmatched_nonlocal_dst_does_not_send_icmp);
345-
tcase_add_test(tc_utils, test_udp_try_recv_full_fifo_drop_does_not_set_readable_or_suppress_icmp);
345+
tcase_add_test(tc_utils, test_udp_try_recv_full_fifo_drop_does_not_set_readable_or_send_icmp);
346346
tcase_add_test(tc_utils, test_dns_callback_bad_flags);
347347
tcase_add_test(tc_utils, test_dns_callback_truncated_response_aborts_query);
348348
tcase_add_test(tc_utils, test_dns_callback_bad_name);
@@ -426,9 +426,11 @@ Suite *wolf_suite(void)
426426
tcase_add_test(tc_utils, test_tcp_rto_cb_syn_sent_requeues_syn_and_arms_timer);
427427
tcase_add_test(tc_utils, test_tcp_input_synack_cancels_control_rto);
428428
tcase_add_test(tc_utils, test_tcp_rto_cb_last_ack_requeues_finack_and_arms_timer);
429+
tcase_add_test(tc_utils, test_tcp_rto_cb_last_ack_full_txbuf_keeps_retry_budget);
429430
tcase_add_test(tc_utils, test_tcp_ctrl_state_needs_rto_fin_wait_1_waits_for_payload_drain);
430431
tcase_add_test(tc_utils, test_tcp_rto_cb_fin_wait_1_with_data_uses_data_recovery);
431432
tcase_add_test(tc_utils, test_tcp_rto_cb_fin_wait_1_no_data_requeues_finack);
433+
tcase_add_test(tc_utils, test_tcp_rto_cb_fin_wait_1_no_data_full_txbuf_keeps_retry_budget);
432434
tcase_add_test(tc_utils, test_tcp_ack_fin_wait_1_ack_of_fin_moves_to_fin_wait_2_and_arms_timeout);
433435
tcase_add_test(tc_utils, test_tcp_ack_closing_ack_of_fin_moves_to_time_wait_and_stops_timer);
434436
tcase_add_test(tc_utils, test_tcp_rto_cb_control_retry_cap_closes_socket);
@@ -440,6 +442,8 @@ Suite *wolf_suite(void)
440442
tcase_add_test(tc_utils, test_sock_close_udp_icmp);
441443
tcase_add_test(tc_utils, test_sock_close_invalid_fds);
442444
tcase_add_test(tc_utils, test_sock_close_tcp_fin_wait_1);
445+
tcase_add_test(tc_utils, test_sock_close_tcp_established_full_txbuf_preserves_state);
446+
tcase_add_test(tc_utils, test_sock_close_tcp_close_wait_full_txbuf_preserves_state);
443447
tcase_add_test(tc_utils, test_sock_close_tcp_other_state_closes);
444448
tcase_add_test(tc_utils, test_sock_close_tcp_cancels_rto_timer);
445449
tcase_add_test(tc_utils, test_sock_close_tcp_closed_returns_minus_one);
@@ -470,6 +474,7 @@ Suite *wolf_suite(void)
470474
tcase_add_test(tc_utils, test_tcp_input_filter_drop);
471475
tcase_add_test(tc_utils, test_tcp_input_port_mismatch_skips_socket);
472476
tcase_add_test(tc_utils, test_tcp_input_remote_ip_mismatch_skips_socket);
477+
tcase_add_test(tc_utils, test_tcp_input_local_ip_mismatch_preserves_if_idx);
473478
tcase_add_test(tc_utils, test_tcp_input_unmatched_ack_sends_rst);
474479
tcase_add_test(tc_utils, test_tcp_input_unmatched_ack_nonlocal_dst_does_not_send_rst);
475480
tcase_add_test(tc_utils, test_tcp_input_unmatched_syn_sends_rst_ack);
@@ -744,6 +749,7 @@ Suite *wolf_suite(void)
744749
tcase_add_test(tc_proto, test_regression_syn_on_established_not_silently_processed);
745750
tcase_add_test(tc_proto, test_regression_syn_on_last_ack_not_silently_processed);
746751
tcase_add_test(tc_proto, test_regression_full_txbuf_still_sends_pure_ack);
752+
tcase_add_test(tc_proto, test_regression_loopback_immediate_pure_ack_uses_loopback_ll);
747753
tcase_add_test(tc_proto, test_regression_fast_recovery_cwnd_ssthresh_rfc5681);
748754
tcase_add_test(tc_proto, test_regression_paws_rejects_stale_timestamp);
749755
tcase_add_test(tc_proto, test_regression_paws_accepts_wrapped_newer_timestamp);
@@ -754,6 +760,7 @@ Suite *wolf_suite(void)
754760
tcase_add_test(tc_proto, test_regression_last_ack_rejects_out_of_window_segment);
755761
tcase_add_test(tc_proto, test_regression_dns_id_never_zero);
756762
tcase_add_test(tc_proto, test_tcp_input_listen_synack_sends_rst_and_stays_listen);
763+
tcase_add_test(tc_proto, test_tcp_input_listen_accept_final_ack_does_not_send_rst);
757764

758765
tcase_add_test(tc_utils, test_transport_checksum);
759766
tcase_add_test(tc_utils, test_iphdr_set_checksum);

src/test/unit/unit_tests_dns_dhcp.c

Lines changed: 127 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3241,6 +3241,38 @@ START_TEST(test_tcp_rto_cb_last_ack_requeues_finack_and_arms_timer)
32413241
}
32423242
END_TEST
32433243

3244+
START_TEST(test_tcp_rto_cb_last_ack_full_txbuf_keeps_retry_budget)
3245+
{
3246+
struct wolfIP s;
3247+
struct tsocket *ts;
3248+
3249+
wolfIP_init(&s);
3250+
ts = &s.tcpsockets[0];
3251+
memset(ts, 0, sizeof(*ts));
3252+
ts->proto = WI_IPPROTO_TCP;
3253+
ts->S = &s;
3254+
ts->sock.tcp.state = TCP_LAST_ACK;
3255+
ts->sock.tcp.rto = 100;
3256+
ts->sock.tcp.ctrl_rto_retries = 2;
3257+
ts->src_port = 12345;
3258+
ts->dst_port = 5001;
3259+
ts->local_ip = 0x0A000001U;
3260+
ts->remote_ip = 0x0A000002U;
3261+
fifo_init(&ts->sock.tcp.txbuf, ts->txmem, TXBUF_SIZE);
3262+
ts->sock.tcp.txbuf.head = 0;
3263+
ts->sock.tcp.txbuf.tail = 0;
3264+
ts->sock.tcp.txbuf.h_wrap = ts->sock.tcp.txbuf.size;
3265+
3266+
s.last_tick = 1000;
3267+
tcp_rto_cb(ts);
3268+
3269+
ck_assert_uint_eq(ts->sock.tcp.ctrl_rto_retries, 2);
3270+
ck_assert_uint_eq(ts->sock.tcp.ctrl_rto_active, 1);
3271+
ck_assert_int_ne(ts->sock.tcp.tmr_rto, NO_TIMER);
3272+
ck_assert_uint_eq(find_timer_expiry(&s, ts->sock.tcp.tmr_rto), 1400U);
3273+
}
3274+
END_TEST
3275+
32443276
START_TEST(test_tcp_ctrl_state_needs_rto_fin_wait_1_waits_for_payload_drain)
32453277
{
32463278
struct wolfIP s;
@@ -3333,6 +3365,39 @@ START_TEST(test_tcp_rto_cb_fin_wait_1_no_data_requeues_finack)
33333365
}
33343366
END_TEST
33353367

3368+
START_TEST(test_tcp_rto_cb_fin_wait_1_no_data_full_txbuf_keeps_retry_budget)
3369+
{
3370+
struct wolfIP s;
3371+
struct tsocket *ts;
3372+
3373+
wolfIP_init(&s);
3374+
ts = &s.tcpsockets[0];
3375+
memset(ts, 0, sizeof(*ts));
3376+
ts->proto = WI_IPPROTO_TCP;
3377+
ts->S = &s;
3378+
ts->sock.tcp.state = TCP_FIN_WAIT_1;
3379+
ts->sock.tcp.rto = 100;
3380+
ts->sock.tcp.ctrl_rto_retries = 2;
3381+
ts->src_port = 12345;
3382+
ts->dst_port = 5001;
3383+
ts->local_ip = 0x0A000001U;
3384+
ts->remote_ip = 0x0A000002U;
3385+
ts->sock.tcp.bytes_in_flight = 0;
3386+
fifo_init(&ts->sock.tcp.txbuf, ts->txmem, TXBUF_SIZE);
3387+
ts->sock.tcp.txbuf.head = 0;
3388+
ts->sock.tcp.txbuf.tail = 0;
3389+
ts->sock.tcp.txbuf.h_wrap = ts->sock.tcp.txbuf.size;
3390+
3391+
s.last_tick = 1000;
3392+
tcp_rto_cb(ts);
3393+
3394+
ck_assert_uint_eq(ts->sock.tcp.ctrl_rto_retries, 2);
3395+
ck_assert_uint_eq(ts->sock.tcp.ctrl_rto_active, 1);
3396+
ck_assert_int_ne(ts->sock.tcp.tmr_rto, NO_TIMER);
3397+
ck_assert_uint_eq(find_timer_expiry(&s, ts->sock.tcp.tmr_rto), 1400U);
3398+
}
3399+
END_TEST
3400+
33363401
START_TEST(test_tcp_ack_fin_wait_1_ack_of_fin_moves_to_fin_wait_2_and_arms_timeout)
33373402
{
33383403
struct wolfIP s;
@@ -3990,6 +4055,66 @@ START_TEST(test_sock_close_tcp_fin_wait_1)
39904055
}
39914056
END_TEST
39924057

4058+
START_TEST(test_sock_close_tcp_established_full_txbuf_preserves_state)
4059+
{
4060+
struct wolfIP s;
4061+
struct tsocket *ts;
4062+
int sd;
4063+
4064+
wolfIP_init(&s);
4065+
mock_link_init(&s);
4066+
4067+
sd = wolfIP_sock_socket(&s, AF_INET, IPSTACK_SOCK_STREAM, WI_IPPROTO_TCP);
4068+
ck_assert_int_gt(sd, 0);
4069+
ts = &s.tcpsockets[SOCKET_UNMARK(sd)];
4070+
ts->sock.tcp.state = TCP_ESTABLISHED;
4071+
ts->src_port = 12345;
4072+
ts->dst_port = 5001;
4073+
ts->local_ip = 0x0A000001U;
4074+
ts->remote_ip = 0x0A000002U;
4075+
fifo_init(&ts->sock.tcp.txbuf, ts->txmem, TXBUF_SIZE);
4076+
ts->sock.tcp.txbuf.head = 0;
4077+
ts->sock.tcp.txbuf.tail = 0;
4078+
ts->sock.tcp.txbuf.h_wrap = ts->sock.tcp.txbuf.size;
4079+
4080+
ck_assert_int_eq(wolfIP_sock_close(&s, sd), -WOLFIP_EAGAIN);
4081+
ck_assert_int_eq(ts->sock.tcp.state, TCP_ESTABLISHED);
4082+
ck_assert_uint_eq(ts->sock.tcp.ctrl_rto_active, 0);
4083+
ck_assert_uint_eq(ts->sock.tcp.ctrl_rto_retries, 0);
4084+
ck_assert_uint_eq(ts->sock.tcp.tmr_rto, NO_TIMER);
4085+
}
4086+
END_TEST
4087+
4088+
START_TEST(test_sock_close_tcp_close_wait_full_txbuf_preserves_state)
4089+
{
4090+
struct wolfIP s;
4091+
struct tsocket *ts;
4092+
int sd;
4093+
4094+
wolfIP_init(&s);
4095+
mock_link_init(&s);
4096+
4097+
sd = wolfIP_sock_socket(&s, AF_INET, IPSTACK_SOCK_STREAM, WI_IPPROTO_TCP);
4098+
ck_assert_int_gt(sd, 0);
4099+
ts = &s.tcpsockets[SOCKET_UNMARK(sd)];
4100+
ts->sock.tcp.state = TCP_CLOSE_WAIT;
4101+
ts->src_port = 12345;
4102+
ts->dst_port = 5001;
4103+
ts->local_ip = 0x0A000001U;
4104+
ts->remote_ip = 0x0A000002U;
4105+
fifo_init(&ts->sock.tcp.txbuf, ts->txmem, TXBUF_SIZE);
4106+
ts->sock.tcp.txbuf.head = 0;
4107+
ts->sock.tcp.txbuf.tail = 0;
4108+
ts->sock.tcp.txbuf.h_wrap = ts->sock.tcp.txbuf.size;
4109+
4110+
ck_assert_int_eq(wolfIP_sock_close(&s, sd), -WOLFIP_EAGAIN);
4111+
ck_assert_int_eq(ts->sock.tcp.state, TCP_CLOSE_WAIT);
4112+
ck_assert_uint_eq(ts->sock.tcp.ctrl_rto_active, 0);
4113+
ck_assert_uint_eq(ts->sock.tcp.ctrl_rto_retries, 0);
4114+
ck_assert_uint_eq(ts->sock.tcp.tmr_rto, NO_TIMER);
4115+
}
4116+
END_TEST
4117+
39934118
START_TEST(test_sock_close_tcp_fin_wait_1_repeated_close_keeps_fin_wait_2_path)
39944119
{
39954120
struct wolfIP s;
@@ -4751,13 +4876,12 @@ START_TEST(test_udp_try_recv_unmatched_nonlocal_dst_does_not_send_icmp)
47514876
}
47524877
END_TEST
47534878

4754-
START_TEST(test_udp_try_recv_full_fifo_drop_does_not_set_readable_or_suppress_icmp)
4879+
START_TEST(test_udp_try_recv_full_fifo_drop_does_not_set_readable_or_send_icmp)
47554880
{
47564881
struct wolfIP s;
47574882
struct tsocket *ts;
47584883
uint8_t udp_buf[sizeof(struct wolfIP_udp_datagram) + 4];
47594884
struct wolfIP_udp_datagram *udp = (struct wolfIP_udp_datagram *)udp_buf;
4760-
struct wolfIP_icmp_dest_unreachable_packet *icmp;
47614885
uint32_t local_ip = 0x0A000001U;
47624886
uint32_t remote_ip = 0x0A000002U;
47634887
uint8_t src_mac[6] = {0x20, 0x21, 0x22, 0x23, 0x24, 0x25};
@@ -4811,12 +4935,7 @@ START_TEST(test_udp_try_recv_full_fifo_drop_does_not_set_readable_or_suppress_ic
48114935
ck_assert_uint_eq(ts->sock.udp.rxbuf.head, head_before);
48124936
ck_assert_uint_eq(ts->sock.udp.rxbuf.tail, tail_before);
48134937
ck_assert_uint_eq(ts->sock.udp.rxbuf.h_wrap, h_wrap_before);
4814-
ck_assert_uint_eq(last_frame_sent_size,
4815-
sizeof(struct wolfIP_icmp_dest_unreachable_packet));
4816-
4817-
icmp = (struct wolfIP_icmp_dest_unreachable_packet *)last_frame_sent;
4818-
ck_assert_uint_eq(icmp->type, 3U);
4819-
ck_assert_uint_eq(icmp->code, 3U);
4938+
ck_assert_uint_eq(last_frame_sent_size, 0U);
48204939
}
48214940
END_TEST
48224941

src/test/unit/unit_tests_proto.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4754,6 +4754,52 @@ START_TEST(test_regression_full_txbuf_still_sends_pure_ack)
47544754
}
47554755
END_TEST
47564756

4757+
START_TEST(test_regression_loopback_immediate_pure_ack_uses_loopback_ll)
4758+
{
4759+
struct wolfIP s;
4760+
struct tsocket *ts;
4761+
struct wolfIP_ll_dev *loop;
4762+
struct wolfIP_tcp_seg seg;
4763+
4764+
wolfIP_init(&s);
4765+
loop = wolfIP_getdev_ex(&s, TEST_LOOPBACK_IF);
4766+
ck_assert_ptr_nonnull(loop);
4767+
loop->send = mock_send;
4768+
last_frame_sent_size = 0;
4769+
memset(last_frame_sent, 0, sizeof(last_frame_sent));
4770+
4771+
ts = &s.tcpsockets[0];
4772+
memset(ts, 0, sizeof(*ts));
4773+
ts->proto = WI_IPPROTO_TCP;
4774+
ts->S = &s;
4775+
ts->if_idx = TEST_LOOPBACK_IF;
4776+
ts->sock.tcp.state = TCP_ESTABLISHED;
4777+
ts->sock.tcp.ack = 100;
4778+
ts->sock.tcp.seq = 1000;
4779+
ts->sock.tcp.snd_una = 900;
4780+
ts->sock.tcp.cwnd = TXBUF_SIZE;
4781+
ts->sock.tcp.peer_rwnd = TXBUF_SIZE;
4782+
ts->src_port = 1234;
4783+
ts->dst_port = 4321;
4784+
ts->local_ip = 0x7F000001U;
4785+
ts->remote_ip = 0x7F000001U;
4786+
memset(&seg, 0, sizeof(seg));
4787+
seg.src_port = ee16(ts->src_port);
4788+
seg.dst_port = ee16(ts->dst_port);
4789+
seg.seq = ee32(ts->sock.tcp.seq);
4790+
seg.ack = ee32(ts->sock.tcp.ack);
4791+
seg.hlen = TCP_HEADER_LEN << 2;
4792+
seg.flags = TCP_FLAG_ACK;
4793+
4794+
ck_assert_int_eq(tcp_send_empty_immediate(ts, &seg,
4795+
(uint32_t)sizeof(seg)), 0);
4796+
ck_assert_uint_eq(ts->sock.tcp.last_ack, ts->sock.tcp.ack);
4797+
ck_assert_uint_eq(last_frame_sent_size, (uint32_t)sizeof(seg));
4798+
ck_assert_mem_eq(seg.ip.eth.dst, loop->mac, 6);
4799+
ck_assert_mem_eq(seg.ip.eth.src, loop->mac, 6);
4800+
}
4801+
END_TEST
4802+
47574803

47584804
/* RFC 5681 §3.2: fast recovery deviates in multiple ways.
47594805
* (a) ssthresh uses cwnd/2 instead of max(FlightSize/2, 2*SMSS)

0 commit comments

Comments
 (0)