From: arighi Date: Wed, 3 Nov 2010 09:46:51 +0000 (+0000) Subject: AT91SAM7X: gracefully drop bad frames read from the EMAC X-Git-Tag: 2.6.0~5^2~26 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=1cc52b017c6213f9e52e678d176b9eeaf2a892ca;p=bertos.git AT91SAM7X: gracefully drop bad frames read from the EMAC When a host in the same subnet changes their IP / mac address association, we could have some "deprecated" frames in the ethernet buffer. The hardware seems to explicitly mark them, cleaning the ownership bit. If this happens simply drop the frame and do not pass it to the upper layers. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4494 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/cpu/arm/drv/eth_at91.c b/bertos/cpu/arm/drv/eth_at91.c index 5d365b20..529d7af4 100644 --- a/bertos/cpu/arm/drv/eth_at91.c +++ b/bertos/cpu/arm/drv/eth_at91.c @@ -425,7 +425,11 @@ ssize_t eth_getFrame(uint8_t *buf, size_t len) rd_len += EMAC_RX_BUFSIZ; else rd_len += len - rd_len; - ASSERT(rx_buf_tab[rx_buf_idx].addr & RXBUF_OWNERSHIP); + if (UNLIKELY(!(rx_buf_tab[rx_buf_idx].addr & RXBUF_OWNERSHIP))) + { + LOG_INFO("bad frame found\n"); + return 0; + } rx_buf_tab[rx_buf_idx].addr &= ~RXBUF_OWNERSHIP; if (++rx_buf_idx >= EMAC_RX_DESCRIPTORS) rx_buf_idx = 0;