From 1cc52b017c6213f9e52e678d176b9eeaf2a892ca Mon Sep 17 00:00:00 2001 From: arighi Date: Wed, 3 Nov 2010 09:46:51 +0000 Subject: [PATCH] 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 --- bertos/cpu/arm/drv/eth_at91.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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; -- 2.25.1