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

This commit is contained in:
Angus Gratton 2017-07-20 10:04:20 +10:00 committed by Angus Gratton
parent 72995bfcec
commit 73b3ae8a2d
3 changed files with 7 additions and 9 deletions

View file

@ -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. */

View file

@ -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);

View 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
/*
------------------------------------