From patchwork Tue Jun 18 00:49:45 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pravin B Shelar X-Patchwork-Id: 252080 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 AC5C12C029D for ; Tue, 18 Jun 2013 10:49:52 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752620Ab3FRAtu (ORCPT ); Mon, 17 Jun 2013 20:49:50 -0400 Received: from na3sys009aog121.obsmtp.com ([74.125.149.145]:55383 "HELO na3sys009aog121.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751982Ab3FRAtt (ORCPT ); Mon, 17 Jun 2013 20:49:49 -0400 Received: from mail-pa0-f41.google.com ([209.85.220.41]) (using TLSv1) by na3sys009aob121.postini.com ([74.125.148.12]) with SMTP ID DSNKUb+urHz/ELqUwK/DshPTf57BVsx+HN+E@postini.com; Mon, 17 Jun 2013 17:49:49 PDT Received: by mail-pa0-f41.google.com with SMTP id bj3so3430501pad.28 for ; Mon, 17 Jun 2013 17:49:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=qzdmxD8r/ST5IFpedM2uGdlFn3/G4Np9A0zwvcdnKNc=; b=XRGwedQdzuwDmhx7JAIB5etBTQUGTyeeiFWzTUU8YiXQ5RUxAIvJJPqxtkgdqTWDQQ PbR5yQSBI6p0SYS2jXhvX9ptNNoZB6yhwJpYTgb9PXzcY4TbZ+kqoebqlGWr+DMRp7he wJ2xkffZbsILrO1lkXoSSNsAxsS8C3UmyaFS4FwJVBfC86wbNucsZLIAtAsrKBzSVdwp KOerHVkRn5KzClXg/kB77iZoLAs3Tf0Yd+O15UgrbOCtTnP33oCB2nXGBRhKfA60f+kd Y1/RU6LAZOk3FcKqUAkE7i709fhNM6S3R9tD2ZMrz1NdoKKEOxgHZWtjGl14d7aWCW+J 3idQ== X-Received: by 10.67.21.229 with SMTP id hn5mr6796636pad.135.1371516588394; Mon, 17 Jun 2013 17:49:48 -0700 (PDT) X-Received: by 10.67.21.229 with SMTP id hn5mr6796632pad.135.1371516588323; Mon, 17 Jun 2013 17:49:48 -0700 (PDT) Received: from localhost ([75.98.92.113]) by mx.google.com with ESMTPSA id i16sm16907782pag.18.2013.06.17.17.49.46 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Mon, 17 Jun 2013 17:49:47 -0700 (PDT) From: Pravin B Shelar To: netdev@vger.kernel.org, dev@openvswitch.org Cc: Pravin B Shelar Subject: [PATCH net-next v2 03/12] gre: export gre_build_header() function. Date: Mon, 17 Jun 2013 17:49:45 -0700 Message-Id: <1371516585-17739-1-git-send-email-pshelar@nicira.com> X-Mailer: git-send-email 1.8.2.135.g7b592fa X-Gm-Message-State: ALoCoQl8RUDE6gbLBDCJfJAh0yUgQR18FJKHCShFIpGh2egsrNLN4x4edmoXzjmT7T7ixKoHTlVg4YR9I4BWgFpeeCnu7n7uHuUBqKzSMC27/12FXuvmc9SIVfNXw9bt6uFW7WSZ5laVAY4PfxDADgGcNnhH/TUJrnaDBhWYpRJucAKn9lqDKWs= Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is required for ovs gre module. Signed-off-by: Pravin B Shelar --- include/net/gre.h | 2 ++ net/ipv4/gre.c | 32 ++++++++++++++++++++++++++++++++ net/ipv4/ip_gre.c | 40 +--------------------------------------- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/include/net/gre.h b/include/net/gre.h index c6ea0c7..cbb9d51 100644 --- a/include/net/gre.h +++ b/include/net/gre.h @@ -32,6 +32,8 @@ struct gre_cisco_protocol { int gre_cisco_register(struct gre_cisco_protocol *proto); int gre_cisco_unregister(struct gre_cisco_protocol *proto); +void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi, + int hdr_len); static inline int ip_gre_calc_hlen(__be16 o_flags) { diff --git a/net/ipv4/gre.c b/net/ipv4/gre.c index 8b9a373..1cbc465 100644 --- a/net/ipv4/gre.c +++ b/net/ipv4/gre.c @@ -61,6 +61,38 @@ int gre_del_protocol(const struct gre_protocol *proto, u8 version) } EXPORT_SYMBOL_GPL(gre_del_protocol); +void gre_build_header(struct sk_buff *skb, const struct tnl_ptk_info *tpi, + int hdr_len) +{ + struct gre_base_hdr *greh; + + skb_push(skb, hdr_len); + + greh = (struct gre_base_hdr *)skb->data; + greh->flags = tnl_flags_to_gre_flags(tpi->flags); + greh->protocol = tpi->proto; + + if (tpi->flags&(TUNNEL_KEY|TUNNEL_CSUM|TUNNEL_SEQ)) { + __be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len - 4); + + if (tpi->flags&TUNNEL_SEQ) { + *ptr = tpi->seq; + ptr--; + } + if (tpi->flags&TUNNEL_KEY) { + *ptr = tpi->key; + ptr--; + } + if (tpi->flags&TUNNEL_CSUM && + !(skb_shinfo(skb)->gso_type & SKB_GSO_GRE)) { + *ptr = 0; + *(__sum16 *)ptr = csum_fold(skb_checksum(skb, 0, + skb->len, 0)); + } + } +} +EXPORT_SYMBOL_GPL(gre_build_header); + static __sum16 check_checksum(struct sk_buff *skb) { __sum16 csum = 0; diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 19863a8..362c7c4 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -248,40 +248,6 @@ error: return ERR_PTR(err); } -static struct sk_buff *gre_build_header(struct sk_buff *skb, - const struct tnl_ptk_info *tpi, - int hdr_len) -{ - struct gre_base_hdr *greh; - - skb_push(skb, hdr_len); - - greh = (struct gre_base_hdr *)skb->data; - greh->flags = tnl_flags_to_gre_flags(tpi->flags); - greh->protocol = tpi->proto; - - if (tpi->flags&(TUNNEL_KEY|TUNNEL_CSUM|TUNNEL_SEQ)) { - __be32 *ptr = (__be32 *)(((u8 *)greh) + hdr_len - 4); - - if (tpi->flags&TUNNEL_SEQ) { - *ptr = tpi->seq; - ptr--; - } - if (tpi->flags&TUNNEL_KEY) { - *ptr = tpi->key; - ptr--; - } - if (tpi->flags&TUNNEL_CSUM && - !(skb_shinfo(skb)->gso_type & SKB_GSO_GRE)) { - *(__sum16 *)ptr = 0; - *(__sum16 *)ptr = csum_fold(skb_checksum(skb, 0, - skb->len, 0)); - } - } - - return skb; -} - static void __gre_xmit(struct sk_buff *skb, struct net_device *dev, const struct iphdr *tnl_params, __be16 proto) @@ -302,11 +268,7 @@ static void __gre_xmit(struct sk_buff *skb, struct net_device *dev, tpi.seq = htonl(tunnel->o_seqno); /* Push GRE header. */ - skb = gre_build_header(skb, &tpi, tunnel->hlen); - if (unlikely(!skb)) { - dev->stats.tx_dropped++; - return; - } + gre_build_header(skb, &tpi, tunnel->hlen); ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol); }