From patchwork Thu Jun 2 20:15:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Ahern X-Patchwork-Id: 629431 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 3rLJR70kC5z9t83 for ; Fri, 3 Jun 2016 06:16:51 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=cumulusnetworks.com header.i=@cumulusnetworks.com header.b=cEApzO9f; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932658AbcFBUQo (ORCPT ); Thu, 2 Jun 2016 16:16:44 -0400 Received: from mail-pf0-f175.google.com ([209.85.192.175]:33760 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932532AbcFBUQm (ORCPT ); Thu, 2 Jun 2016 16:16:42 -0400 Received: by mail-pf0-f175.google.com with SMTP id b124so35099923pfb.0 for ; Thu, 02 Jun 2016 13:16:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cumulusnetworks.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4HiDBCrYyqMveUa4a38u2fFejtPN8o9GhFThcLhof5c=; b=cEApzO9fTiOHYCVGK5HJBNriKqlj10Ornz7A0r+21DAxeiFXk8QyH1xf1t6onlfjbV 4qY+ugo1ZSvC6uhpHAmTciYenmV7dYNWDncQJHMhcIBkiXzhtfEGt1BG6PA5hGR6LRHE MuO8B26jBfNBD2HV8j3JxOcneKwJrp/sZK00g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4HiDBCrYyqMveUa4a38u2fFejtPN8o9GhFThcLhof5c=; b=hb1LlgbOeXOyMkc88XcsL6prcGWmBrBFDN5ZC5YdlAyMZq7ihZrE1zezCVsdPb3zBz NW8CDkWmvfdDJ9oRkOM/v31kLm3Sa94NF9RprGXm8T0CGGy8Jlg5QpbS0mlIu7kKA9Cy aZ42VcS4d7QcltLepXwCrRI3UO7dFMZjt5kjzqtV6j1VGRf/J/gumgaWC784oJGmHHUD LrO6O2buEmBCobl+psgq8VbS1N1i991MNsaqg1wG1wdqSsioCSLOi31yXW2qDyj1e2mT YQ0Yymg8jj3jINU13S0SuIquwu0wfe0Fc5ZH+rYh65FPUoPLfcC4hnie1zfXt/EATeMx +Stw== X-Gm-Message-State: ALyK8tJRGsOX70E8R4OSDkz8rKpbdWee0Mnnw1oPJm+m2uZ99gXHgGK1pshD9l3h1WjbKvgP X-Received: by 10.98.66.142 with SMTP id h14mr8034457pfd.11.1464898601757; Thu, 02 Jun 2016 13:16:41 -0700 (PDT) Received: from kenny.cumulusnetworks.com. ([216.129.126.126]) by smtp.googlemail.com with ESMTPSA id z26sm2866388pff.0.2016.06.02.13.16.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 02 Jun 2016 13:16:41 -0700 (PDT) From: David Ahern To: netdev@vger.kernel.org Cc: David Ahern Subject: [PATCH net-next 1/3] net: vrf: Minor refactoring for local address patches Date: Thu, 2 Jun 2016 13:15:10 -0700 Message-Id: <1464898512-5157-2-git-send-email-dsa@cumulusnetworks.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1464898512-5157-1-git-send-email-dsa@cumulusnetworks.com> References: <1464898512-5157-1-git-send-email-dsa@cumulusnetworks.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Move the stripping of the ethernet header from is_ip_tx_frame into the ipv4 and ipv6 outbound functions. If the packet is destined to a local address the header is retained since the packet is sent back to netif_rx. Collapse vrf_send_v4_prep into vrf_process_v4_outbound. Signed-off-by: David Ahern --- drivers/net/vrf.c | 45 ++++++++++++++++++--------------------------- 1 file changed, 18 insertions(+), 27 deletions(-) diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c index aaac4c779047..d678aaeba572 100644 --- a/drivers/net/vrf.c +++ b/drivers/net/vrf.c @@ -125,6 +125,9 @@ static netdev_tx_t vrf_process_v6_outbound(struct sk_buff *skb, skb_dst_drop(skb); skb_dst_set(skb, dst); + /* strip the ethernet header added for pass through VRF device */ + __skb_pull(skb, skb_network_offset(skb)); + ret = ip6_local_out(net, skb->sk, skb); if (unlikely(net_xmit_eval(ret))) dev->stats.tx_errors++; @@ -145,29 +148,6 @@ static netdev_tx_t vrf_process_v6_outbound(struct sk_buff *skb, } #endif -static int vrf_send_v4_prep(struct sk_buff *skb, struct flowi4 *fl4, - struct net_device *vrf_dev) -{ - struct rtable *rt; - int err = 1; - - rt = ip_route_output_flow(dev_net(vrf_dev), fl4, NULL); - if (IS_ERR(rt)) - goto out; - - /* TO-DO: what about broadcast ? */ - if (rt->rt_type != RTN_UNICAST && rt->rt_type != RTN_LOCAL) { - ip_rt_put(rt); - goto out; - } - - skb_dst_drop(skb); - skb_dst_set(skb, &rt->dst); - err = 0; -out: - return err; -} - static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb, struct net_device *vrf_dev) { @@ -182,10 +162,24 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb, FLOWI_FLAG_SKIP_NH_OIF, .daddr = ip4h->daddr, }; + struct net *net = dev_net(vrf_dev); + struct rtable *rt; - if (vrf_send_v4_prep(skb, &fl4, vrf_dev)) + rt = ip_route_output_flow(net, &fl4, NULL); + if (IS_ERR(rt)) goto err; + if (rt->rt_type != RTN_UNICAST && rt->rt_type != RTN_LOCAL) { + ip_rt_put(rt); + goto err; + } + + skb_dst_drop(skb); + skb_dst_set(skb, &rt->dst); + + /* strip the ethernet header added for pass through VRF device */ + __skb_pull(skb, skb_network_offset(skb)); + if (!ip4h->saddr) { ip4h->saddr = inet_select_addr(skb_dst(skb)->dev, 0, RT_SCOPE_LINK); @@ -206,9 +200,6 @@ static netdev_tx_t vrf_process_v4_outbound(struct sk_buff *skb, static netdev_tx_t is_ip_tx_frame(struct sk_buff *skb, struct net_device *dev) { - /* strip the ethernet header added for pass through VRF device */ - __skb_pull(skb, skb_network_offset(skb)); - switch (skb->protocol) { case htons(ETH_P_IP): return vrf_process_v4_outbound(skb, dev);