AT91SAM7X: gracefully drop bad frames read from the EMAC
authorarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 3 Nov 2010 09:46:51 +0000 (09:46 +0000)
committerarighi <arighi@38d2e660-2303-0410-9eaa-f027e97ec537>
Wed, 3 Nov 2010 09:46:51 +0000 (09:46 +0000)
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

index 5d365b20ae712b720c8a7d43816b300fd0cf52de..529d7af4e5473b51045ef1ec435e108abc9edc7a 100644 (file)
@@ -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;