From 4af297fc2018a4ab3f1e86dfdd94cf12dbf8a0c5 Mon Sep 17 00:00:00 2001 From: Sylvain Rochet Date: Sat, 13 Aug 2016 15:56:42 +0200 Subject: [PATCH] PPP: fix don't print valid LCP echo request/reply packets if the link is up The check for link up was missing, meaning valid LCP echo request/reply packets are filtered whatever the PPP state is, despite what the comment says. Fix it by checking the PPP state as we would like to have done when it was written. --- src/include/netif/ppp/ppp_impl.h | 2 +- src/netif/ppp/ppp.c | 4 ++-- src/netif/ppp/utils.c | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/include/netif/ppp/ppp_impl.h b/src/include/netif/ppp/ppp_impl.h index 8c60fef9..e9338de5 100644 --- a/src/include/netif/ppp/ppp_impl.h +++ b/src/include/netif/ppp/ppp_impl.h @@ -620,7 +620,7 @@ void ppp_warn(const char *fmt, ...); /* log a warning message */ void ppp_error(const char *fmt, ...); /* log an error message */ void ppp_fatal(const char *fmt, ...); /* log an error message and die(1) */ #if PRINTPKT_SUPPORT -void ppp_dump_packet(const char *tag, unsigned char *p, int len); +void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len); /* dump packet to debug log if interesting */ #endif /* PRINTPKT_SUPPORT */ diff --git a/src/netif/ppp/ppp.c b/src/netif/ppp/ppp.c index 75a10d2f..2f6ae11f 100644 --- a/src/netif/ppp/ppp.c +++ b/src/netif/ppp/ppp.c @@ -780,7 +780,7 @@ void ppp_input(ppp_pcb *pcb, struct pbuf *pb) { protocol = (((u8_t *)pb->payload)[0] << 8) | ((u8_t*)pb->payload)[1]; #if PRINTPKT_SUPPORT - ppp_dump_packet("rcvd", (unsigned char *)pb->payload, pb->len); + ppp_dump_packet(pcb, "rcvd", (unsigned char *)pb->payload, pb->len); #endif /* PRINTPKT_SUPPORT */ pbuf_header(pb, -(s16_t)sizeof(protocol)); @@ -1006,7 +1006,7 @@ struct pbuf *ppp_singlebuf(struct pbuf *p) { */ err_t ppp_write(ppp_pcb *pcb, struct pbuf *p) { #if PRINTPKT_SUPPORT - ppp_dump_packet("sent", (unsigned char *)p->payload+2, p->len-2); + ppp_dump_packet(pcb, "sent", (unsigned char *)p->payload+2, p->len-2); #endif /* PRINTPKT_SUPPORT */ return pcb->link_cb->write(pcb, pcb->link_ctx_cb, p); } diff --git a/src/netif/ppp/utils.c b/src/netif/ppp/utils.c index be53c0c6..1d44e9c3 100644 --- a/src/netif/ppp/utils.c +++ b/src/netif/ppp/utils.c @@ -702,7 +702,7 @@ void ppp_dbglog(const char *fmt, ...) { * ppp_dump_packet - print out a packet in readable form if it is interesting. * Assumes len >= PPP_HDRLEN. */ -void ppp_dump_packet(const char *tag, unsigned char *p, int len) { +void ppp_dump_packet(ppp_pcb *pcb, const char *tag, unsigned char *p, int len) { int proto; /* @@ -713,9 +713,9 @@ void ppp_dump_packet(const char *tag, unsigned char *p, int len) { return; /* - * don't print LCP echo request/reply packets if the link is up. + * don't print valid LCP echo request/reply packets if the link is up. */ - if (proto == PPP_LCP && len >= 2 + HEADERLEN) { + if (proto == PPP_LCP && pcb->phase == PPP_PHASE_RUNNING && len >= 2 + HEADERLEN) { unsigned char *lcp = p + 2; int l = (lcp[2] << 8) + lcp[3];