]> granicus.if.org Git - esp-idf/commitdiff
lwip: Use hardware RNG for LWIP_RAND(), use LWIP_RAND() for random port assignment
authorAngus Gratton <angus@espressif.com>
Thu, 20 Jul 2017 00:04:20 +0000 (10:04 +1000)
committerAngus Gratton <gus@projectgus.com>
Thu, 7 Sep 2017 06:32:05 +0000 (16:32 +1000)
components/lwip/core/tcp.c
components/lwip/include/lwip/port/arch/sys_arch.h
components/lwip/include/lwip/port/lwipopts.h

index 3ad5903d9ec802556dcf70dbdab5a025388b27cf..1f915128a4763cf78d83e7870ccb0f75c9e02abc 100755 (executable)
@@ -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. */
index 8d30ef171dc450cf02a2d8cc620a521badc0ac0a..716fd9fa53e336ab60361bc6316e7c5e1a252efa 100644 (file)
@@ -67,7 +67,6 @@ typedef struct sys_mbox_s {
 #define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )\r
 #define sys_sem_set_invalid( x ) ( ( *x ) = NULL )\r
 \r
-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);
index 49c2174bf3b8145a5f74b86b5d3db4fdd6623e4a..7bc4021e5a9f1b52001791ab02740a27381c9fdd 100644 (file)
@@ -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
 
 /*
    ------------------------------------