Просмотр исходного кода

lwip: Use hardware RNG for LWIP_RAND(), use LWIP_RAND() for random port assignment

Angus Gratton 8 лет назад
Родитель
Сommit
73b3ae8a2d

+ 5 - 7
components/lwip/core/tcp.c

@@ -696,14 +696,12 @@ tcp_new_port(void)
 again:
 
 #if ESP_RANDOM_TCP_PORT
-	tcp_port = system_get_time();
-	if (tcp_port < 0)
-		tcp_port = LWIP_RAND() - tcp_port;
-	tcp_port %= TCP_LOCAL_PORT_RANGE_START;
+  tcp_port = abs(LWIP_RAND()) % (TCP_LOCAL_PORT_RANGE_END - TCP_LOCAL_PORT_RANGE_START);
+  tcp_port += TCP_LOCAL_PORT_RANGE_START;
 #else
-      if (tcp_port++ == TCP_LOCAL_PORT_RANGE_END) {
-            tcp_port = TCP_LOCAL_PORT_RANGE_START;
-      }
+  if (tcp_port++ == TCP_LOCAL_PORT_RANGE_END) {
+    tcp_port = TCP_LOCAL_PORT_RANGE_START;
+  }
 #endif
 
   /* Check all PCB lists. */

+ 0 - 1
components/lwip/include/lwip/port/arch/sys_arch.h

@@ -67,7 +67,6 @@ typedef struct sys_mbox_s {
 #define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )
 #define sys_sem_set_invalid( x ) ( ( *x ) = NULL )
 
-uint32_t system_get_time(void);
 void sys_delay_ms(uint32_t ms);
 sys_sem_t* sys_thread_sem_init(void);
 void sys_thread_sem_deinit(void);

+ 2 - 1
components/lwip/include/lwip/port/lwipopts.h

@@ -37,6 +37,7 @@
 #include <sys/time.h>
 #include <sys/fcntl.h>
 #include "esp_task.h"
+#include "esp_system.h"
 #include "sdkconfig.h"
 
 /* Enable all Espressif-only options */
@@ -65,7 +66,7 @@
  */
 #define SMEMCPY(dst,src,len)            memcpy(dst,src,len)
 
-#define LWIP_RAND       rand
+#define LWIP_RAND       esp_random
 
 /*
    ------------------------------------