All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <nikolay@redhat.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org, Vlad Yasevich <vyasevic@redhat.com>,
	Daniel Borkman <dborkman@redhat.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH net] net: fix wrong mac_len calculation for vlans
Date: Wed, 28 May 2014 17:35:54 +0200	[thread overview]
Message-ID: <5386025A.3030104@redhat.com> (raw)
In-Reply-To: <1401291540.3645.5.camel@edumazet-glaptop2.roam.corp.google.com>

On 05/28/2014 05:39 PM, Eric Dumazet wrote:
> On Wed, 2014-05-28 at 17:24 +0200, Nikolay Aleksandrov wrote:
> 
>>
>>  net/core/dev.c | 16 +++++++++++++++-
>>  1 file changed, 15 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/core/dev.c b/net/core/dev.c
>> index 9abc503b19b7..94167fc660b1 100644
>> --- a/net/core/dev.c
>> +++ b/net/core/dev.c
>> @@ -2283,8 +2283,8 @@ EXPORT_SYMBOL(skb_checksum_help);
>>  
>>  __be16 skb_network_protocol(struct sk_buff *skb, int *depth)
>>  {
>> +	unsigned int vlan_depth = skb->mac_len;
>>  	__be16 type = skb->protocol;
>> -	int vlan_depth = skb->mac_len;
>>  
>>  	/* Tunnel gso handlers can set protocol to ethernet. */
>>  	if (type == htons(ETH_P_TEB)) {
>> @@ -2297,6 +2297,20 @@ __be16 skb_network_protocol(struct sk_buff *skb, int *depth)
>>  		type = eth->h_proto;
>>  	}
>>  
>> +	/* if skb->protocol is 802.1Q/AD then the header should already be
>> +	 * present at mac_len - VLAN_HLEN (if mac_len > 0), or at
>> +	 * ETH_HLEN otherwise
>> +	 */
>> +	if (type == htons(ETH_P_8021Q) || type == htons(ETH_P_8021AD)) {
>> +		if (vlan_depth) {
>> +			if (unlikely(WARN_ON(vlan_depth < VLAN_HLEN)))
>> +				return 0;
>> +			vlan_depth -= VLAN_HLEN;
>> +		} else {
>> +			vlan_depth = ETH_HLEN;
>> +		}
>> +	}
> 
> It would be nice not having 4 tests in fast path for non vlan traffic
> 
>> +
>>  	while (type == htons(ETH_P_8021Q) || type == htons(ETH_P_8021AD)) {
>>  		struct vlan_hdr *vh;
>>  
> 
> Like :
> 
>        if (type == htons(ETH_P_8021Q) || type == htons(ETH_P_8021AD)) {
>                 if (vlan_depth) {
>                        if (unlikely(WARN_ON(vlan_depth < VLAN_HLEN)))
>                                return 0;
>                        vlan_depth -= VLAN_HLEN;
>                 } else {
>                        vlan_depth = ETH_HLEN;
>                 }
> 		do {
> 			struct vlan_hdr *vh;
> 
> 			if (unlikely(!pskb_may_pull(skb, vlan_depth + VLAN_HLEN)))
>  	                	return 0;
> 
>  	                vh = (struct vlan_hdr *)(skb->data + vlan_depth);
>  	                type = vh->h_vlan_encapsulated_proto;
>  	                vlan_depth += VLAN_HLEN;
> 		} while (type == htons(ETH_P_8021Q) || type == htons(ETH_P_8021AD));
>         }
> 	
> 
> 
Very good suggestion, I'll adjust the patch and post a v2.

Thanks,
 Nik

      reply	other threads:[~2014-05-28 15:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-28 15:24 [PATCH net] net: fix wrong mac_len calculation for vlans Nikolay Aleksandrov
2014-05-28 15:39 ` Eric Dumazet
2014-05-28 15:35   ` Nikolay Aleksandrov [this message]

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=5386025A.3030104@redhat.com \
    --to=nikolay@redhat.com \
    --cc=davem@davemloft.net \
    --cc=dborkman@redhat.com \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=vyasevic@redhat.com \
    /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 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.