netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Duyck <alexander.duyck@gmail.com>
To: Florian Fainelli <f.fainelli@gmail.com>,
	Alexander Duyck <alexander.h.duyck@redhat.com>,
	netdev@vger.kernel.org
Cc: davem@davemloft.net
Subject: Re: [net-next PATCH 1/5] etherdevice: Add function for handling padding frame to ETH_ZLEN
Date: Tue, 25 Nov 2014 18:44:46 -0800	[thread overview]
Message-ID: <54753E9E.9040801@gmail.com> (raw)
In-Reply-To: <54752525.4040509@gmail.com>

On 11/25/2014 04:56 PM, Florian Fainelli wrote:
> On 25/11/14 14:44, Alexander Duyck wrote:
>> This patch adds a simple function for padding a frame up to the minimum
>> size for for Ethernet.  The motivation behind it is that there are a number
>> of implementations throughout the network device drivers that are all doing
>> the same thing, but each a little bit differently and as a result several
>> implementations contain bugs such as updating the length without updating
>> the tail offset and other similar issues.
>>
>> Signed-off-by: Alexander Duyck <alexander.h.duyck@redhat.com>
>> ---
>>  include/linux/etherdevice.h |   21 +++++++++++++++++++++
>>  1 file changed, 21 insertions(+)
>>
>> diff --git a/include/linux/etherdevice.h b/include/linux/etherdevice.h
>> index 733980f..7e436f3 100644
>> --- a/include/linux/etherdevice.h
>> +++ b/include/linux/etherdevice.h
>> @@ -392,4 +392,25 @@ static inline unsigned long compare_ether_header(const void *a, const void *b)
>>  #endif
>>  }
>>  
>> +/**
>> + * eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame
>> + * @skb: Buffer to pad
>> + *
>> + * An Ethernet frame should have a minimum size of 60 bytes.  This function
>> + * takes short frames and pads them with zeros up to the 60 byte limit.
> 
> minimum size without FCS
> 
>> + */
>> +static inline int eth_skb_pad(struct sk_buff *skb)
>> +{
>> +	unsigned int size = skb->len;
>> +
>> +	if (unlikely(size < ETH_ZLEN)) {
>> +		size = ETH_ZLEN - size;
>> +		if (skb_pad(skb, size))
>> +			return -ENOMEM;
>> +		__skb_put(skb, size);
>> +	}
> 
> most drivers call skb_padto(skb, ETH_ZLEN), besides the extra
> __skb_put() here, this is not different.

Yes, but the __skb_put is the difference.  Calling skb_padto() only
zeros out the bytes following the tail, but it doesn't add the extra
bytes to the frame nor does it update the tail.  As such if we only call
skb_padto() before handing a short frame off to the network stack the
network stack will still have issues with it being too short.

The difference between the two is that skb_padto() is really meant for
transmit, whereas eth_skb_pad is really meant for receive.

- Alex

  reply	other threads:[~2014-11-26  2:44 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-25 22:43 [net-next PATCH 0/5] net: Add helper for padding short Ethernet frames Alexander Duyck
2014-11-25 22:44 ` [net-next PATCH 1/5] etherdevice: Add function for handling padding frame to ETH_ZLEN Alexander Duyck
2014-11-26  0:56   ` Florian Fainelli
2014-11-26  2:44     ` Alexander Duyck [this message]
2014-11-25 22:44 ` [net-next PATCH 2/5] ethernet/intel: Use eth_skb_pad helper Alexander Duyck
2014-11-25 23:14   ` Eric Dumazet
2014-11-26  0:44     ` Alexander Duyck
2014-11-26  1:05       ` Florian Fainelli
2014-11-26  1:43       ` Eric Dumazet
2014-11-26  3:19         ` David Miller
2014-11-26  4:01           ` Eric Dumazet
2014-11-26 20:41             ` David Miller
2014-11-25 22:44 ` [net-next PATCH 3/5] niu: " Alexander Duyck
2014-11-25 22:44 ` [net-next PATCH 4/5] myri10ge: use " Alexander Duyck
2014-11-25 22:44 ` [net-next PATCH 5/5] r8169: Use eth_skb_pad function Alexander Duyck
2014-11-26  0:02   ` Francois Romieu
2014-11-26  0:33     ` Alexander Duyck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=54753E9E.9040801@gmail.com \
    --to=alexander.duyck@gmail.com \
    --cc=alexander.h.duyck@redhat.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).