Skip to content

TCP congestion control fixes#18

Merged
gasbytes merged 9 commits intowolfSSL:masterfrom
danielinux:tcp-congestion-control-fixes
Feb 5, 2026
Merged

TCP congestion control fixes#18
gasbytes merged 9 commits intowolfSSL:masterfrom
danielinux:tcp-congestion-control-fixes

Conversation

@danielinux
Copy link
Member

Improve TCP Tx fifo handling, wrap arounds and associated BSD socket calls. extend unit test coverage.

Copilot AI review requested due to automatic review settings February 5, 2026 07:47
@danielinux danielinux changed the title Tcp congestion control fixes TCP congestion control fixes Feb 5, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves TCP transmit FIFO handling and wraparound logic, adds error checking for BSD socket calls, and significantly extends unit test coverage for the TCP/IP stack implementation.

Changes:

  • Modified FIFO space calculation to return contiguous space only when wrapped, preventing buffer overrun issues
  • Added explicit contiguous space check in fifo_push to prevent wraparound writes
  • Added error handling for fifo_push calls in wolfIP_sock_sendto for TCP, UDP, and ICMP protocols
  • Fixed PKT_FLAG_SENT clearing in tcp_ack to allow retransmission of acknowledged packets
  • Modified wolfIP_sock_accept to set addrlen even when addr is NULL (POSIX compliance)
  • Changed pthread_mutex_lock to pthread_mutex_trylock with busy-wait in BSD socket wrapper
  • Added 90+ new unit tests covering socket operations, FIFO edge cases, and timer heap operations
  • Added test infrastructure for mocking random number generation

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/wolfip.c Core FIFO handling improvements for wraparound safety, error handling for buffer operations, TCP ACK flag fixes
src/test/unit/unit.c Extensive new test coverage for sockets, FIFOs, timers, and routing with 90+ new test cases
src/port/posix/bsd_socket.c Modified mutex acquisition strategy in blocking call wrapper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Restored blocking pthread_mutex (improved performance in TCP sender)
- fifo_push now considers wrapping around if possible, when the packet
  is bigger than the offered contiguous space at the end of the buffer,
  while there could be space at the beginning before tail pointer if the
  fifo wraps around.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Fix in-flight calculation, bound cwnd to RWND
- Only perform congestion control increases when traffic is CWND-limited
- Add missing window scaling options parsing & sending per RFC7323
@danielinux danielinux requested a review from Copilot February 5, 2026 13:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 17 comments.

Comments suppressed due to low confidence (1)

src/wolfip.c:1876

  • In the duplicate ACK path, the conditions on lines 1867-1870 check if ack != t->sock.tcp.snd_una and bytes_in_flight == 0, returning early if true. However, the duplicate ACK logic should only trigger when ack == snd_una AND there are bytes in flight. The early returns are correct, but the logic that follows assumes a duplicate ACK scenario without verifying that this is actually a duplicate (i.e., that we've seen this ACK value before). The fast retransmit logic then unconditionally reduces ssthresh and cwnd, which could incorrectly trigger on the first ACK with a given value. Consider adding a duplicate ACK counter to ensure the fast retransmit only triggers after receiving three duplicate ACKs as per RFC 5681.
        /* Duplicate ack (no advance in snd_una). */
        if (ack != t->sock.tcp.snd_una)
            return;
        if (t->sock.tcp.bytes_in_flight == 0)
            return;
        t->sock.tcp.ssthresh = t->sock.tcp.cwnd / 2;
        if (t->sock.tcp.ssthresh < 2 * TCP_MSS) {
            t->sock.tcp.ssthresh = 2 * TCP_MSS;
        }
        t->sock.tcp.cwnd = t->sock.tcp.ssthresh + TCP_MSS;
        t->sock.tcp.cwnd_count = 0;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Addressed all review comments.

+ fixed 3 x dup to enter fast retransmit
+ fixed window scaling calculation
+ added capped budget for main poll
@danielinux danielinux requested a review from gasbytes February 5, 2026 16:34
@danielinux danielinux requested a review from gasbytes February 5, 2026 18:24
@gasbytes gasbytes merged commit ac1a6fc into wolfSSL:master Feb 5, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants