From patchwork Wed Nov 2 02:15:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13995 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3342203wru; Tue, 1 Nov 2022 19:16:55 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5Stnol0ZQ1bG/ubnkfzXdGNYvgickqzmeoP8Yy2D59CpsrrAiDcy6t4V3Pmf5g3T93K2y4 X-Received: by 2002:a17:907:948f:b0:7a8:6861:819a with SMTP id dm15-20020a170907948f00b007a86861819amr21784024ejc.30.1667355414825; Tue, 01 Nov 2022 19:16:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667355414; cv=none; d=google.com; s=arc-20160816; b=o4+9kjllrs95KVuV6DkIKINd0S9UXq9eSecq+3dmn8BsVdSnupCMbWSDOr25i83AHw DYAuG9e2pZkBQKE1Zpym5u6KfhJBJiQ7A5pbukwBRbSycfiE2RApof89cpDen/WzGVyZ k+nPC/TIEnKK1zlRtSsz5GRQmXU5SaH17B2yMj6dOpC+VqTIbv5ee2/A0+DZB8gvrJ6q GoOLRIHYhWQSbfSWJhQXbrbBoaJ/EVbNdXJ+9dpb2JUtKLoZNxs/WzM660gvlmGkeASs PWpLwrb2rGCTmuv84MRdO/8+52CIIDIM61QXgsrkliECrpH/LIjuSo3mbo/rabbw9O9G Wdog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=BHYXsl+YeyXYyju/6rUYI07itUbBD3udbH99pbNeSEM=; b=DiKD3o0yHj+VjWPYGtDNIlhsXQwm42691jJZ6GbRQAsPqnogRBtrqL4eY6KI2wN5KX +oT0zphiSwQRkcpi23famU6rxP2pr0BFiAe11Ll5lk6y4p2ouXWbbzMcpMmpyqyM3S1T uwSX84xUMFxJs61xI9nsTGPbtzsQbO5N73riIktR3fk+8skoQbLBAx9+pImoDs2AVS8g jWc/XULyuGb1XXcV0vtJgmfrYa8vsSc6dtn0sWl0PZkY0XXbjlENKSkIJ47kcS0T73yT mveuY9iHhKa6OXiR/sTCpue9TwP/xZXIoIxYoBKe4L1GC10Ykuzs/hHI2Gy+xqH9x8y8 wSVg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s3-20020a1709062ec300b00778d193ca81si11215215eji.550.2022.11.01.19.16.30; Tue, 01 Nov 2022 19:16:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229929AbiKBCPU (ORCPT + 99 others); Tue, 1 Nov 2022 22:15:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229534AbiKBCPT (ORCPT ); Tue, 1 Nov 2022 22:15:19 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8504F658D; Tue, 1 Nov 2022 19:15:16 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4N29TC38zzzmVVp; Wed, 2 Nov 2022 10:15:11 +0800 (CST) Received: from dggpemm500005.china.huawei.com (7.185.36.74) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 2 Nov 2022 10:15:14 +0800 Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Wed, 2 Nov 2022 10:15:14 +0800 From: Yunsheng Lin To: , , , CC: , Subject: [PATCH net-next] ipvlan: minor optimization for ipvlan outbound process Date: Wed, 2 Nov 2022 10:15:49 +0800 Message-ID: <20221102021549.12213-1-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748348871230862165?= X-GMAIL-MSGID: =?utf-8?q?1748348871230862165?= Avoid some local variable initialization and remove some redundant assignment in ipvlan outbound process. Signed-off-by: Yunsheng Lin --- drivers/net/ipvlan/ipvlan_core.c | 56 +++++++++++++++----------------- 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/drivers/net/ipvlan/ipvlan_core.c b/drivers/net/ipvlan/ipvlan_core.c index bb1c298c1e78..2b715035380b 100644 --- a/drivers/net/ipvlan/ipvlan_core.c +++ b/drivers/net/ipvlan/ipvlan_core.c @@ -417,7 +417,7 @@ static int ipvlan_process_v4_outbound(struct sk_buff *skb) struct net_device *dev = skb->dev; struct net *net = dev_net(dev); struct rtable *rt; - int err, ret = NET_XMIT_DROP; + int err; struct flowi4 fl4 = { .flowi4_oif = dev->ifindex, .flowi4_tos = RT_TOS(ip4h->tos), @@ -438,15 +438,14 @@ static int ipvlan_process_v4_outbound(struct sk_buff *skb) skb_dst_set(skb, &rt->dst); err = ip_local_out(net, skb->sk, skb); if (unlikely(net_xmit_eval(err))) - dev->stats.tx_errors++; - else - ret = NET_XMIT_SUCCESS; - goto out; + goto tx_errors_inc; + + return NET_XMIT_SUCCESS; err: - dev->stats.tx_errors++; kfree_skb(skb); -out: - return ret; +tx_errors_inc: + dev->stats.tx_errors++; + return NET_XMIT_DROP; } #if IS_ENABLED(CONFIG_IPV6) @@ -456,7 +455,7 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb) struct net_device *dev = skb->dev; struct net *net = dev_net(dev); struct dst_entry *dst; - int err, ret = NET_XMIT_DROP; + int err; struct flowi6 fl6 = { .flowi6_oif = dev->ifindex, .daddr = ip6h->daddr, @@ -469,22 +468,23 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb) dst = ip6_route_output(net, NULL, &fl6); if (dst->error) { - ret = dst->error; + err = dst->error; dst_release(dst); goto err; } skb_dst_set(skb, dst); err = ip6_local_out(net, skb->sk, skb); - if (unlikely(net_xmit_eval(err))) - dev->stats.tx_errors++; - else - ret = NET_XMIT_SUCCESS; - goto out; + if (unlikely(net_xmit_eval(err))) { + err = NET_XMIT_DROP; + goto tx_errors_inc; + } + + return NET_XMIT_SUCCESS; err: - dev->stats.tx_errors++; kfree_skb(skb); -out: - return ret; +tx_errors_inc: + dev->stats.tx_errors++; + return err; } #else static int ipvlan_process_v6_outbound(struct sk_buff *skb) @@ -495,8 +495,6 @@ static int ipvlan_process_v6_outbound(struct sk_buff *skb) static int ipvlan_process_outbound(struct sk_buff *skb) { - int ret = NET_XMIT_DROP; - /* The ipvlan is a pseudo-L2 device, so the packets that we receive * will have L2; which need to discarded and processed further * in the net-ns of the main-device. @@ -511,7 +509,7 @@ static int ipvlan_process_outbound(struct sk_buff *skb) "Dropped {multi|broad}cast of type=[%x]\n", ntohs(skb->protocol)); kfree_skb(skb); - goto out; + return NET_XMIT_DROP; } skb_pull(skb, sizeof(*ethh)); @@ -520,16 +518,14 @@ static int ipvlan_process_outbound(struct sk_buff *skb) } if (skb->protocol == htons(ETH_P_IPV6)) - ret = ipvlan_process_v6_outbound(skb); + return ipvlan_process_v6_outbound(skb); else if (skb->protocol == htons(ETH_P_IP)) - ret = ipvlan_process_v4_outbound(skb); - else { - pr_warn_ratelimited("Dropped outbound packet type=%x\n", - ntohs(skb->protocol)); - kfree_skb(skb); - } -out: - return ret; + return ipvlan_process_v4_outbound(skb); + + pr_warn_ratelimited("Dropped outbound packet type=%x\n", + ntohs(skb->protocol)); + kfree_skb(skb); + return NET_XMIT_DROP; } static void ipvlan_multicast_enqueue(struct ipvl_port *port,