PPP, PPPoS: only check open flag after events that may have changed it

Speed-up a little bit the PPPoS input parser by only checking the open
flag after calling the ppp_input function, the only one that can induce
a state change here.
This commit is contained in:
Sylvain Rochet 2020-10-22 20:47:08 +02:00
parent 22f13c24aa
commit a9f19cd7f1

View File

@ -489,20 +489,21 @@ pppos_input(ppp_pcb *ppp, const void *s, int l)
LWIP_ASSERT_CORE_LOCKED();
#endif
/* Don't even bother parsing data if we are disconnected.
* Added to that, ppp_input must never be called if the upper layer is down.
*/
PPPOS_PROTECT(lev);
if (!pppos->open) {
PPPOS_UNPROTECT(lev);
return;
}
PPPOS_UNPROTECT(lev);
PPPDEBUG(LOG_DEBUG, ("pppos_input[%d]: got %d bytes\n", ppp->netif->num, l));
while (l-- > 0) {
cur_char = *s_u8++;
PPPOS_PROTECT(lev);
/* ppp_input can disconnect the interface, we need to abort to prevent a memory
* leak if there are remaining bytes because pppos_connect and pppos_listen
* functions expect input buffer to be free. Furthermore there are no real
* reason to continue reading bytes if we are disconnected.
*/
if (!pppos->open) {
PPPOS_UNPROTECT(lev);
return;
}
escaped = ESCAPE_P(pppos->in_accm, cur_char);
PPPOS_UNPROTECT(lev);
@ -582,6 +583,14 @@ pppos_input(ppp_pcb *ppp, const void *s, int l)
}
#else /* PPP_INPROC_IRQ_SAFE */
ppp_input(ppp, inp);
/* ppp_input can disconnect the interface, we need to abort to prevent a memory
* leak if there are remaining bytes because pppos_connect and pppos_listen
* functions expect input buffer to be free. Furthermore there are no real
* reason to continue reading bytes if we are disconnected.
*/
if (!pppos->open) {
break;
}
#endif /* PPP_INPROC_IRQ_SAFE */
}