From 047c3c6528eaa6eb42cd6cb882e05edbcf2bd4a3 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Fri, 15 Jun 2018 01:33:07 +0200 Subject: [PATCH] PPP, PPPoL2TP: take care of Ns/Nr wraparounds It can't be an issue since we only send and receive a few L2TP control packets and we don't care about anything received next other than sending Ack packet. For the sake of correctness properly handle Ns/Nr counters wraparounds, it doesn't add more code anyway. Signed-off-by: Sylvain Rochet --- src/netif/ppp/pppol2tp.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/netif/ppp/pppol2tp.c b/src/netif/ppp/pppol2tp.c index e2562ce5..9d679fea 100644 --- a/src/netif/ppp/pppol2tp.c +++ b/src/netif/ppp/pppol2tp.c @@ -498,7 +498,7 @@ static void pppol2tp_dispatch_control_packet(pppol2tp_pcb *l2tp, u16_t port, str /* printf("L2TP CTRL INPUT, ns=%d, nr=%d, len=%d\n", ns, nr, p->len); */ /* Handle the special case of the ICCN acknowledge */ - if (l2tp->phase == PPPOL2TP_STATE_ICCN_SENT && l2tp->peer_nr > l2tp->our_ns) { + if (l2tp->phase == PPPOL2TP_STATE_ICCN_SENT && (s16_t)(l2tp->peer_nr - l2tp->our_ns) > 0) { l2tp->phase = PPPOL2TP_STATE_DATA; ppp_start(l2tp->ppp); /* notify upper layers */ } @@ -742,7 +742,7 @@ static void pppol2tp_timeout(void *arg) { return; } PPPDEBUG(LOG_DEBUG, ("pppol2tp: icrq_retried=%d\n", l2tp->icrq_retried)); - if (l2tp->peer_nr <= l2tp->our_ns -1) { /* the SCCCN was not acknowledged */ + if ((s16_t)(l2tp->peer_nr - l2tp->our_ns) < 0) { /* the SCCCN was not acknowledged */ if ((err = pppol2tp_send_scccn(l2tp, l2tp->our_ns -1)) != 0) { l2tp->icrq_retried--; PPPDEBUG(LOG_DEBUG, ("pppol2tp: failed to send SCCCN, error=%d\n", err));