api: net: fix length check in eth_receive()
PATCH 1/1 api: net: fix length check in eth_receive()
If the requested length is too small to hold the received packet, eth_receive() will return -1 and will leave the packet in the receive buffers. Instead of returning an error in this case, we return the first portion of the received packet and remove it from the receive buffers.
This fixes FreeBSD's ubldr. Without this patch it will just stop receiving packets if the NIC receives more than PKTBUFSRX too large packets.
--- net/eth.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)
net/eth.c +1 -4
@@ -486,10 +486,7 @@ int eth_receive(void *packet, int length)return -1 ; } -if (length < eth_rcv_bufs[eth_rcv_current].length) -return -1 ; - - length = eth_rcv_bufs[eth_rcv_current].length; + length =min (eth_rcv_bufs[eth_rcv_current].length, length);for (i =0 ; i < length; i++) p[i] = eth_rcv_bufs[eth_rcv_current].data[i];
Signature · 1 line
1.7.2.5
PATCH 1/1 api: net: fix length check in eth_receive()
Hi Michael,
Quoted 21 lines · Michael Walle
If the requested length is too small to hold the received packet,
eth_receive()will return -1 and will leave the packet in the receive buffers. Instead of returning an error in this case, we return the first portion of the received packet and remove it from the receive buffers.This fixes FreeBSD's ubldr. Without this patch it will just stop receiving packets if the NIC receives more than PKTBUFSRX too large packets.
Signed-off-by Michael Walle <[email protected]>Cc Joe Hershberger <[email protected]>Cc Rafal Jaworowski <[email protected]>Cc Piotr Kruszynski <[email protected]>---
?net/eth.c | ? ?5 +----
?1 files changed, 1 insertions(+), 4 deletions(-)net/eth.c +0
-0
net/eth.c int eth_receive(void *packet, int length) · line 489
Quoted 8 lines
net/eth.c +1
-4@@ -486,10 +486,7 @@ int eth_receive(void *packet, int length) ? ? ? ? ? ? ? ? ? ? ? ?return -1; ? ? ? ?} - ? ? ? if (length < eth_rcv_bufs[eth_rcv_current].length) - ? ? ? ? ? ? ? return -1; - - ? ? ? length = eth_rcv_bufs[eth_rcv_current].length; + ? ? ? length = min(eth_rcv_bufs[eth_rcv_current].length, length);
Is it really a good idea to return a runt packet to the network protocols? I understand wanting to drop the too-big packet, but I think you should simply drop that packet before returning the error, but still error.
-Joe
PATCH 1/1 api: net: fix length check in eth_receive()
[removed Piotr Kruszynski from CC because mail address does not exist anymore]
Hi Joe,
Am Montag 25 Juni 2012, 22:25:56 schrieb Joe Hershberger:
Quoted 28 lines
Hi Michael,
Quoted 25 lines · Michael Walle
If the requested length is too small to hold the received packet,
eth_receive()will return -1 and will leave the packet in the receive buffers. Instead of returning an error in this case, we return the first portion of the received packet and remove it from the receive buffers.This fixes FreeBSD's ubldr. Without this patch it will just stop receiving packets if the NIC receives more than PKTBUFSRX too large packets.
Signed-off-by Michael Walle <[email protected]>Cc Joe Hershberger <[email protected]>Cc Rafal Jaworowski <[email protected]>Cc Piotr Kruszynski <[email protected]>--- net/eth.c | 5 +---- 1 files changed, 1 insertions(+), 4 deletions(-)net/eth.c +0
-0@@ -486,10 +486,7 @@ int eth_receive(void *packet, int length)return -1 ; }
Quoted 10 lines
net/eth.c int eth_receive(void *packet, int length) · line 489
Quoted 5 lines
net/eth.c +1
-4-if (length < eth_rcv_bufs[eth_rcv_current].length) -return -1 ; - - length = eth_rcv_bufs[eth_rcv_current].length; + length =min (eth_rcv_bufs[eth_rcv_current].length, length);Is it really a good idea to return a runt packet to the network protocols? I understand wanting to drop the too-big packet, but I think you should simply drop that packet before returning the error, but still error.
its the same behaviour as recv() with udp packets, isn't it?
see http://pubs.opengroup.org/onlinepubs/009695399/functions/recv.html
But i'm not set on this, maybe rafal could clarify this. My main point is to make ubldr working ;)
Signature · 1 line
michael
Joe Hershberger
AppliedPATCH 1/1 api: net: fix length check in eth_receive()
Hi Michael,
Quoted 23 lines · Michael Walle
[removed Piotr Kruszynski from CC because mail address does not exist anymore]
Hi Joe,
Am Montag 25 Juni 2012, 22:25:56 schrieb Joe Hershberger:
Quoted 17 lines
Hi Michael,
Quoted 14 lines · Michael Walle
If the requested length is too small to hold the received packet,
eth_receive()will return -1 and will leave the packet in the receive buffers. Instead of returning an error in this case, we return the first portion of the received packet and remove it from the receive buffers.This fixes FreeBSD's ubldr. Without this patch it will just stop receiving packets if the NIC receives more than PKTBUFSRX too large packets.
Signed-off-by Michael Walle <[email protected]>Cc Joe Hershberger <[email protected]>Cc Rafal Jaworowski <[email protected]>Cc Piotr Kruszynski <[email protected]>---
Applied, thanks.
-Joe