From patchwork Mon Nov 28 15:23:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 128001 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C549CB6F7B for ; Tue, 29 Nov 2011 02:23:32 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751978Ab1K1PX2 (ORCPT ); Mon, 28 Nov 2011 10:23:28 -0500 Received: from mail-qy0-f174.google.com ([209.85.216.174]:64554 "EHLO mail-qy0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751291Ab1K1PX1 (ORCPT ); Mon, 28 Nov 2011 10:23:27 -0500 Received: by qyk4 with SMTP id 4so915615qyk.19 for ; Mon, 28 Nov 2011 07:23:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:subject:from:to:cc:date:content-type:x-mailer :content-transfer-encoding:mime-version; bh=h17VwykTadFVg9/52rAMT022UGxoq8HYDzRZ1TUuoB8=; b=VwybnSaRnHx3DZLe4jEQ33sATXvh0AWUNlspynFGar51bbXyEKz6KyhUEa+8X6ZTl/ ggZ8iEDNfM+34CAdjhDelEt+bZCPMP6UtJJlH1AZhi7+IZolucCSaObk3s+ZQBYzVMQt M2eJ8VlOYncreGET0bfbz1eywWStEOZPOrLh4= Received: by 10.229.72.81 with SMTP id l17mr4847249qcj.113.1322493806837; Mon, 28 Nov 2011 07:23:26 -0800 (PST) Received: from [10.150.51.211] (gw0.net.jmsp.net. [212.23.165.14]) by mx.google.com with ESMTPS id ed2sm34139217qab.15.2011.11.28.07.23.24 (version=SSLv3 cipher=OTHER); Mon, 28 Nov 2011 07:23:26 -0800 (PST) Message-ID: <1322493803.2292.70.camel@edumazet-HP-Compaq-6005-Pro-SFF-PC> Subject: [PATCH net-next 2/4] net: use skb_flow_dissect() in __skb_get_rxhash() From: Eric Dumazet To: David Miller Cc: netdev@vger.kernel.org, dev@openvswitch.org, chrisw@redhat.com, herbert@gondor.hengli.com.au, john.r.fastabend@intel.com, jpettit@nicira.com, Florian Westphal , Stephen Hemminger , jesse@nicira.com, jhs@mojatatu.com, Dan Siemon Date: Mon, 28 Nov 2011 16:23:23 +0100 X-Mailer: Evolution 3.2.1- Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org No functional changes. This uses the code we factorized in skb_flow_dissect() Signed-off-by: Eric Dumazet --- net/core/dev.c | 125 +++++------------------------------------------ 1 file changed, 14 insertions(+), 111 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/core/dev.c b/net/core/dev.c index 8afb244..962e3de 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -133,11 +133,9 @@ #include #include #include -#include -#include -#include #include #include +#include #include "net-sysfs.h" @@ -2598,123 +2596,28 @@ static inline void ____napi_schedule(struct softnet_data *sd, */ void __skb_get_rxhash(struct sk_buff *skb) { - int nhoff, hash = 0, poff; - const struct ipv6hdr *ip6; - const struct iphdr *ip; - const struct vlan_hdr *vlan; - u8 ip_proto; - u32 addr1, addr2; - u16 proto; - union { - u32 v32; - u16 v16[2]; - } ports; - - nhoff = skb_network_offset(skb); - proto = skb->protocol; - -again: - switch (proto) { - case __constant_htons(ETH_P_IP): -ip: - if (!pskb_may_pull(skb, sizeof(*ip) + nhoff)) - goto done; - - ip = (const struct iphdr *) (skb->data + nhoff); - if (ip_is_fragment(ip)) - ip_proto = 0; - else - ip_proto = ip->protocol; - addr1 = (__force u32) ip->saddr; - addr2 = (__force u32) ip->daddr; - nhoff += ip->ihl * 4; - break; - case __constant_htons(ETH_P_IPV6): -ipv6: - if (!pskb_may_pull(skb, sizeof(*ip6) + nhoff)) - goto done; - - ip6 = (const struct ipv6hdr *) (skb->data + nhoff); - ip_proto = ip6->nexthdr; - addr1 = (__force u32) ip6->saddr.s6_addr32[3]; - addr2 = (__force u32) ip6->daddr.s6_addr32[3]; - nhoff += 40; - break; - case __constant_htons(ETH_P_8021Q): - if (!pskb_may_pull(skb, sizeof(*vlan) + nhoff)) - goto done; - vlan = (const struct vlan_hdr *) (skb->data + nhoff); - proto = vlan->h_vlan_encapsulated_proto; - nhoff += sizeof(*vlan); - goto again; - case __constant_htons(ETH_P_PPP_SES): - if (!pskb_may_pull(skb, PPPOE_SES_HLEN + nhoff)) - goto done; - proto = *((__be16 *) (skb->data + nhoff + - sizeof(struct pppoe_hdr))); - nhoff += PPPOE_SES_HLEN; - switch (proto) { - case __constant_htons(PPP_IP): - goto ip; - case __constant_htons(PPP_IPV6): - goto ipv6; - default: - goto done; - } - default: - goto done; - } - - switch (ip_proto) { - case IPPROTO_GRE: - if (pskb_may_pull(skb, nhoff + 16)) { - u8 *h = skb->data + nhoff; - __be16 flags = *(__be16 *)h; + struct flow_keys keys; + u32 hash; - /* - * Only look inside GRE if version zero and no - * routing - */ - if (!(flags & (GRE_VERSION|GRE_ROUTING))) { - proto = *(__be16 *)(h + 2); - nhoff += 4; - if (flags & GRE_CSUM) - nhoff += 4; - if (flags & GRE_KEY) - nhoff += 4; - if (flags & GRE_SEQ) - nhoff += 4; - goto again; - } - } - break; - case IPPROTO_IPIP: - goto again; - default: - break; - } + if (!skb_flow_dissect(skb, &keys)) + return; - ports.v32 = 0; - poff = proto_ports_offset(ip_proto); - if (poff >= 0) { - nhoff += poff; - if (pskb_may_pull(skb, nhoff + 4)) { - ports.v32 = * (__force u32 *) (skb->data + nhoff); - if (ports.v16[1] < ports.v16[0]) - swap(ports.v16[0], ports.v16[1]); - skb->l4_rxhash = 1; - } + if (keys.ports) { + if ((__force u16)keys.port16[1] < (__force u16)keys.port16[0]) + swap(keys.port16[0], keys.port16[1]); + skb->l4_rxhash = 1; } /* get a consistent hash (same value on both flow directions) */ - if (addr2 < addr1) - swap(addr1, addr2); + if ((__force u32)keys.dst < (__force u32)keys.src) + swap(keys.dst, keys.src); - hash = jhash_3words(addr1, addr2, ports.v32, hashrnd); + hash = jhash_3words((__force u32)keys.dst, + (__force u32)keys.src, + (__force u32)keys.ports, hashrnd); if (!hash) hash = 1; -done: skb->rxhash = hash; } EXPORT_SYMBOL(__skb_get_rxhash);