You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/11/11 20:10:41 UTC

[GitHub] [incubator-nuttx] pkarashchenko commented on a diff in pull request #7510: net/tcp: Avoid starting TCP sequence number from 0

pkarashchenko commented on code in PR #7510:
URL: https://github.com/apache/incubator-nuttx/pull/7510#discussion_r1020528328


##########
net/tcp/tcp_seqno.c:
##########
@@ -142,6 +144,34 @@ uint32_t tcp_addsequence(FAR uint8_t *seqno, uint16_t len)
 
 void tcp_initsequence(FAR uint8_t *seqno)
 {
+  int ret;
+
+  /* Get a random TCP sequence number */
+
+  ret = getrandom(&g_tcpsequence, sizeof(uint32_t), 0);

Review Comment:
   @xiaoxiang781216 do you propose not to call `getrandom` if `g_tcpsequence` is non-zero? If yes, then all the next values will be
   ```
     g_tcpsequence = g_tcpsequence % 2000000000;
   ...
     if (g_tcpsequence < 1000000000)
       {
         g_tcpsequence += 1000000000;
       }
   ```



##########
net/tcp/tcp_send.c:
##########
@@ -329,6 +332,20 @@ static void tcp_sendcommon(FAR struct net_driver_s *dev,
     }
 #endif /* CONFIG_NET_IPv4 */
 
+  /* If this is the very first connection, seqno and sndseq will be 0!
+   * Rational:
+   * We need to make tcp->seqno random because some servers will not accept
+   * it starting from zero. The way to do it is making the sndseq random
+   * because it will be "memcpyied" to tcp->seqno.
+   */
+
+  seqno = tcp_getsequence(tcp->seqno);

Review Comment:
   Yeah. This point is also not clear to me



-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org