diff mbox

[4/5] Accept short frames from netmap software rings

Message ID 1397034218-2971-5-git-send-email-ciprian.barbu@linaro.org
State Accepted
Headers show

Commit Message

Ciprian Barbu April 9, 2014, 9:03 a.m. UTC
Since packets from the network stack are mostly valid, we decided to pad them to
a minimum of OD_ETH_LEN_MIN. The odp_packet_parse function is intended to be
used for parsing frames for physical wired ethernet devices which are supposed
to conform to IEEE 802.3 minimum frame length. Padding frames from the network
stack (SW ring) is the prefered choice at the moment.

Signed-off-by: Ciprian Barbu <ciprian.barbu@linaro.org>
---
 platform/linux-generic/source/odp_packet_netmap.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/source/odp_packet_netmap.c b/platform/linux-generic/source/odp_packet_netmap.c
index f5cc500..e54964b 100644
--- a/platform/linux-generic/source/odp_packet_netmap.c
+++ b/platform/linux-generic/source/odp_packet_netmap.c
@@ -292,14 +292,26 @@  int recv_pkt_netmap(pkt_netmap_t * const pkt_nm, odp_packet_t pkt_table[],
 			rxring->head = nm_ring_next(rxring, cur);
 			rxring->cur = rxring->head;
 
+			pkt_buf = odp_packet_buf_addr(pkt);
+			l2_hdr = pkt_buf + pkt_nm->frame_offset;
+
 			if (frame_len > pkt_nm->max_frame_len) {
-				ODP_ERR("Data partially lost %u %lu!\n",
+				ODP_ERR("RX: frame too big %u %lu!\n",
 					frame_len, pkt_nm->max_frame_len);
-				frame_len = pkt_nm->max_frame_len;
+				/* drop the frame, reuse pkt next interation */
+				continue;
+			}
+			if (odp_unlikely(frame_len < ODP_ETH_LEN_MIN)) {
+				if (odp_unlikely(pkt_nm->netmap_mode !=
+						 ODP_NETMAP_MODE_SW)) {
+					ODP_ERR("RX: Frame truncated: %u\n",
+						(unsigned)frame_len);
+					continue;
+				}
+				memset(l2_hdr + frame_len, 0,
+				       ODP_ETH_LEN_MIN - frame_len);
+				frame_len = ODP_ETH_LEN_MIN;
 			}
-
-			pkt_buf = odp_packet_buf_addr(pkt);
-			l2_hdr = pkt_buf + pkt_nm->frame_offset;
 
 			/* For now copy the data in the mbuf,
 			   worry about zero-copy later */