PPP: improve randomization of LCP magic number after power-up

magic_init() is first time called from ppp_init(), which is called from
lwip_init(). If system has no RTC, sys_jiffies() returns same value in
this moment after every power-up or system reset. This value used in LCP
magic number generation after ppp_connect(), which leads to same magic
number after every restart. Subsequent magic_randomize() calls takes
place in ppp_input(), after magic number generation.

Call magic_randomize() somewhere near start of ppp_connect() (and
ppp_listen()) as it might be called later at a random time.

Signed-off-by: Sylvain Rochet <gradator@gradator.net>
This commit is contained in:
Sylvain Rochet 2018-08-31 10:12:50 +02:00
parent dac4cb05f7
commit fa3826a1d3

View File

@ -276,6 +276,8 @@ err_t ppp_connect(ppp_pcb *pcb, u16_t holdoff) {
PPPDEBUG(LOG_DEBUG, ("ppp_connect[%d]: holdoff=%d\n", pcb->netif->num, holdoff));
magic_randomize();
if (holdoff == 0) {
ppp_do_connect(pcb);
return ERR_OK;
@ -303,6 +305,8 @@ err_t ppp_listen(ppp_pcb *pcb) {
PPPDEBUG(LOG_DEBUG, ("ppp_listen[%d]\n", pcb->netif->num));
magic_randomize();
if (pcb->link_cb->listen) {
new_phase(pcb, PPP_PHASE_INITIALIZE);
pcb->link_cb->listen(pcb, pcb->link_ctx_cb);