All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH] api: net: fix length check in eth_receive()
@ 2012-06-22 21:24 Michael Walle
  2012-06-25 20:25 ` Joe Hershberger
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Walle @ 2012-06-22 21:24 UTC (permalink / raw)
  To: u-boot

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 <michael@walle.cc>
Cc: Joe Hershberger <joe.hershberger@gmail.com>
Cc: Rafal Jaworowski <raj@semihalf.com>
Cc: Piotr Kruszynski <ppk@semihalf.com>
---
 net/eth.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/net/eth.c b/net/eth.c
index d526264..09249c9 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -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];
-- 
1.7.2.5

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] api: net: fix length check in eth_receive()
  2012-06-22 21:24 [U-Boot] [PATCH] api: net: fix length check in eth_receive() Michael Walle
@ 2012-06-25 20:25 ` Joe Hershberger
  2012-06-25 20:50   ` Michael Walle
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Hershberger @ 2012-06-25 20:25 UTC (permalink / raw)
  To: u-boot

Hi Michael,

On Fri, Jun 22, 2012 at 4:24 PM, Michael Walle <michael@walle.cc> wrote:
> 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 <michael@walle.cc>
> Cc: Joe Hershberger <joe.hershberger@gmail.com>
> Cc: Rafal Jaworowski <raj@semihalf.com>
> Cc: Piotr Kruszynski <ppk@semihalf.com>
> ---
> ?net/eth.c | ? ?5 +----
> ?1 files changed, 1 insertions(+), 4 deletions(-)
>
> diff --git a/net/eth.c b/net/eth.c
> index d526264..09249c9 100644
> --- a/net/eth.c
> +++ b/net/eth.c
> @@ -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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] api: net: fix length check in eth_receive()
  2012-06-25 20:25 ` Joe Hershberger
@ 2012-06-25 20:50   ` Michael Walle
  2012-09-28 15:48     ` Joe Hershberger
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Walle @ 2012-06-25 20:50 UTC (permalink / raw)
  To: u-boot


[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:
> Hi Michael,
> 
> On Fri, Jun 22, 2012 at 4:24 PM, Michael Walle <michael@walle.cc> wrote:
> > 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 <michael@walle.cc>
> > Cc: Joe Hershberger <joe.hershberger@gmail.com>
> > Cc: Rafal Jaworowski <raj@semihalf.com>
> > Cc: Piotr Kruszynski <ppk@semihalf.com>
> > ---
> >  net/eth.c |    5 +----
> >  1 files changed, 1 insertions(+), 4 deletions(-)
> > 
> > diff --git a/net/eth.c b/net/eth.c
> > index d526264..09249c9 100644
> > --- a/net/eth.c
> > +++ b/net/eth.c
> > @@ -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.

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 ;)

-- 
michael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [U-Boot] [PATCH] api: net: fix length check in eth_receive()
  2012-06-25 20:50   ` Michael Walle
@ 2012-09-28 15:48     ` Joe Hershberger
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Hershberger @ 2012-09-28 15:48 UTC (permalink / raw)
  To: u-boot

Hi Michael,

On Mon, Jun 25, 2012 at 3:50 PM, Michael Walle <michael@walle.cc> wrote:
>
> [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:
>> Hi Michael,
>>
>> On Fri, Jun 22, 2012 at 4:24 PM, Michael Walle <michael@walle.cc> wrote:
>> > 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 <michael@walle.cc>
>> > Cc: Joe Hershberger <joe.hershberger@gmail.com>
>> > Cc: Rafal Jaworowski <raj@semihalf.com>
>> > Cc: Piotr Kruszynski <ppk@semihalf.com>
>> > ---

Applied, thanks.

-Joe

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-09-28 15:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-22 21:24 [U-Boot] [PATCH] api: net: fix length check in eth_receive() Michael Walle
2012-06-25 20:25 ` Joe Hershberger
2012-06-25 20:50   ` Michael Walle
2012-09-28 15:48     ` Joe Hershberger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.