cederom commented on PR #22144:
URL: https://github.com/apache/nuttx/pull/22144#issuecomment-7072273558
**Commit 1 (`64980a8`, clear `d_sndlen`): correct.** It clears `d_sndlen`
right after `d_len` is set, before any state path runs. The only paths that
read it are the ones that don't reset it themselves, so no other behaviour
changes.
**Commit 2 (`dc71005`, no ACK for an empty segment after a gap): needs one
more check.**
- The new code lets an empty segment with `seq > rcvseq` go on to
`tcp_snd_wnd_update()` and the state machine, but nothing checks the right edge
of the receive window.
- RFC 9293 §3.10.7.4 only accepts an empty segment if `RCV.NXT =< SEG.SEQ <
RCV.NXT+RCV.WND`. A segment beyond the window should still get the ACK and be
dropped, which is what the old code did.
- What goes wrong: such a segment sets `snd_wl1 = seq` far ahead. After
that, valid segments have `seq < wl1`, so the `wl1 < seq` and `wl1 == seq`
conditions in `tcp_snd_wnd_update()` both fail. Window updates that come with a
new ACK are then ignored, and `snd_wnd` can only shrink. The sender drifts
toward zero-window probing.
- That segment can be stale or spoofed. Its sequence number only has to be
ahead of `rcvseq` (anywhere up to 2³¹), not inside the window.
- Suggested fix: only take the new path when `TCP_SEQ_LT(seq,
conn->rcv_adv)`, the advertised right edge. Otherwise keep
`tcp_input_dropack()`.
- A smaller side effect: in SYN_RCVD, an empty segment after a gap with a
valid ACK now finishes the handshake. That is allowed by the RFC, but worth
stating in the commit message.
**Commit 3 (`e6bd937`, first SYN is not a retransmission): correct.**
- `tcp_synack()` goes through `tcp_send()` with the timer flag, which starts
the retransmission timer at `TCP_RTO`.
- I checked the timing with the defaults: resends at 1.5, 4.5, 10.5, 22.5
and 46.5 s, then the connect fails at 70.5 s. That matches the "70 s, was 69 s"
in the commit message.
- Nits:
- `TCP_SYNFIRST` is `0x100` while `0x80` is free. If that's on purpose,
please say why.
- `NET_TCP_MAXSYNRTX` in `net/tcp/Kconfig` has no help text, and its
meaning changes here (one more SYN is sent). A one-line help saying "number of
SYN resends after the first SYN" would make the change visible.
- The new fast path skips `tcp_setsequence(conn->sndseq,
conn->rexmit_seq)`, which the SYN_SENT resend case does. The two values are
equal at that point, so it's harmless, just inconsistent.
**Commit 5 (`4ad8f55`, blocking `connect()` ends at `SO_SNDTIMEO`): correct,
and matches Linux.**
- Using `tc_result` when the handler finished just before the wait ended
fixes a real race.
- The `_SS_ISCONNECTING` change in `tcp_start_monitor()` is safe: the
connect handler clears that flag on `TCP_CONNECTED`, so a successful blocking
connect is unaffected.
- **Behaviour change for apps:** I found two in nuttx-apps that set
`SO_SNDTIMEO` before a blocking `connect()` and treat any error as fatal:
- `netutils/webclient/webclient.c`, with its configured timeout;
- `system/nxplayer/nxplayer.c`, with a hard-coded 10 s.
A handshake slower than that now fails with `EINPROGRESS` instead of
waiting. That's what Linux does, but it should go in the PR's Impact section.
- Follow-up, not a blocker: a second `connect()` while the handshake is
still running reaches `tcp_connect()`, which returns `-EISCONN` because the
state isn't `TCP_ALLOCATED`. Linux returns `EALREADY`. Non-blocking sockets
already had this problem, but blocking callers can now hit it too.
- Nit: `psock_teardown_callbacks(&state, -EINPROGRESS)` calls
`tcp_stop_monitor()` because the status is negative. Nothing is registered yet,
so nothing happens, but `ret != -EINPROGRESS ? ret : OK` would read more
clearly.
**Doc commits (`4f037b2`, `f5f3cef`): fine.** They use tab indentation, the
same as the existing lines in those files.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]