From patchwork Fri Oct 30 02:28:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 316005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 065C1C2D0A3 for ; Fri, 30 Oct 2020 02:30:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B1CA2076B for ; Fri, 30 Oct 2020 02:30:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="baJ1Kikz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726196AbgJ3CaA (ORCPT ); Thu, 29 Oct 2020 22:30:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725781AbgJ3CaA (ORCPT ); Thu, 29 Oct 2020 22:30:00 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DB70C0613CF; Thu, 29 Oct 2020 19:29:58 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id g12so3921120pgm.8; Thu, 29 Oct 2020 19:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EFNt3m3IFv4Esg6Z6+NQabAOK7nwYfSwuit4QZ/gwa8=; b=baJ1KikzA9uMG56fIb1/ZLdJzwk2jWFBf7i0T/YJLq9NUHO2wipQcN5zcPsq1M5k/7 CF66BLCN27cY+F/GCdZA0w1qbkwl7PVIH5EgF0eQnGaFVAe9Nbz+v5b+7+2xd65vjXk0 Jg1GeBzqIEXX5QU7atrKLf78Zu9yACySm7Os3rKCopB75H3b2jt460/8Ebhek5fIr3k9 foZC2Ofa6kCgVzOFxtcMzv1vRxiZEaTR2rIFn7wFNkwjgAE/QOTAYyaG8G1qCXbH62wE H87MS8vU3AOL2Y/PdTe54YlNSYJacaAfmvK8mwqiK5eLKIIcE+DpfaKCVc4ySyHqhspa SV6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EFNt3m3IFv4Esg6Z6+NQabAOK7nwYfSwuit4QZ/gwa8=; b=JMs/p7HAbamY74UybvzaFK/TPhoEuMYA+JeRc5tOOPQBC4K4uLeB09Ie6MaUmq/Vyq Nvz5+z/bvs1mMYBlgnW0WB5k1DuAqSLBHQeMeIT0lTEUTBJDoWuA4HxqkweRYk215O3T ZFDL7o6BtmPrFNBEEhUGZxEW6RKyLSINCq9x/0wctzJV7DFD3x3ALpTbpn0ppe2nsCSr PgZYm8G9tMgefIK47KJQApZeDhZnwTXL/HT5QIS6gtfoJjRGUniAckWpJ/a9NVEh9N6i JOWVbQzos9yYoGB+5ao/yWfwAWjVcBLvVNJ9IFSds76qHDZEqYNF/WZQra0Xx2Z0KVU1 xEHw== X-Gm-Message-State: AOAM533avcMMxAxSYT9FaxdckUnA0EWcilJYpYiggLSHetnFk7o3lF3u Jjdn9LqNk4Le4GWN1UlGAv4= X-Google-Smtp-Source: ABdhPJx6cpLARbPfA5Jl9Rr+XlUV2zIIzzvvdDTsivaAbU/KuQnJ3mFr//fr5bDkVo9nj/bQ1xJSXQ== X-Received: by 2002:a17:90a:d983:: with SMTP id d3mr128592pjv.144.1604024998182; Thu, 29 Oct 2020 19:29:58 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:dd13:d62a:9d03:9a42]) by smtp.gmail.com with ESMTPSA id i24sm4216588pfd.7.2020.10.29.19.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 19:29:57 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn , Krzysztof Halasa Cc: Xie He Subject: [PATCH net-next v4 1/5] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames Date: Thu, 29 Oct 2020 19:28:35 -0700 Message-Id: <20201030022839.438135-2-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201030022839.438135-1-xie.he.0141@gmail.com> References: <20201030022839.438135-1-xie.he.0141@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 1. When the fr_rx function drops a received frame (because the protocol type is not supported, or because the PVC virtual device that corresponds to the DLCI number and the protocol type doesn't exist), the function frees the skb and returns. The code for freeing the skb and returning is repeated several times, this patch uses "goto rx_drop" to replace them so that the code looks cleaner. 2. Add code to increase the stats.rx_dropped count whenever we drop a frame. Increase the stats.rx_dropped count both after "goto rx_drop" and after "goto rx_error" because I think we should increase this value whenever an skb is dropped. Cc: Willem de Bruijn Cc: Krzysztof Halasa Signed-off-by: Xie He --- drivers/net/wan/hdlc_fr.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c index 409e5a7ad8e2..c774eff44534 100644 --- a/drivers/net/wan/hdlc_fr.c +++ b/drivers/net/wan/hdlc_fr.c @@ -904,8 +904,7 @@ static int fr_rx(struct sk_buff *skb) netdev_info(frad, "No PVC for received frame's DLCI %d\n", dlci); #endif - dev_kfree_skb_any(skb); - return NET_RX_DROP; + goto rx_drop; } if (pvc->state.fecn != fh->fecn) { @@ -963,14 +962,12 @@ static int fr_rx(struct sk_buff *skb) default: netdev_info(frad, "Unsupported protocol, OUI=%x PID=%x\n", oui, pid); - dev_kfree_skb_any(skb); - return NET_RX_DROP; + goto rx_drop; } } else { netdev_info(frad, "Unsupported protocol, NLPID=%x length=%i\n", data[3], skb->len); - dev_kfree_skb_any(skb); - return NET_RX_DROP; + goto rx_drop; } if (dev) { @@ -982,12 +979,13 @@ static int fr_rx(struct sk_buff *skb) netif_rx(skb); return NET_RX_SUCCESS; } else { - dev_kfree_skb_any(skb); - return NET_RX_DROP; + goto rx_drop; } - rx_error: +rx_error: frad->stats.rx_errors++; /* Mark error */ +rx_drop: + frad->stats.rx_dropped++; dev_kfree_skb_any(skb); return NET_RX_DROP; } From patchwork Fri Oct 30 02:28:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 316004 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3244AC2D0A3 for ; Fri, 30 Oct 2020 02:30:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C7BBE20756 for ; Fri, 30 Oct 2020 02:30:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uVR8AlzN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726320AbgJ3Caa (ORCPT ); Thu, 29 Oct 2020 22:30:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726057AbgJ3Caa (ORCPT ); Thu, 29 Oct 2020 22:30:30 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51C4FC0613CF; Thu, 29 Oct 2020 19:30:30 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id e7so3955855pfn.12; Thu, 29 Oct 2020 19:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=j6uvYZsdn9TjVvj7gx86V/39t9vFMxPa68xHa2VlZqY=; b=uVR8AlzNizv4t265Ok/jlnDW1uCEPkvT7AwY1qXZoV4G5n4PXgU3QGP36ag0UiIosC C28NLyMp5uVkmwbw9CE3HkZzSBtz6AE1VMO5JulI4C07XQwWL624B6fhR7+jAUktsQqK DLy073Zb7XE3fkKwD8vPU23CScz3reyvMJ38Np+D+mmDMb1n1rKzyomfljxSLwkIb9hA 1OcBmXBcFDXtGPDRANKIWoFR2N/iRDyVbhsJqRY2AwLNL9dNOC4PSLCRKg/XxC/gcWJN MJ2NVTHZ9SnR/AFcCwngCMtNfaMOOvvJypjEN8nKy2Fqy+/+Llx2VA8AdFcOMyWj22ef 1PcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j6uvYZsdn9TjVvj7gx86V/39t9vFMxPa68xHa2VlZqY=; b=D7YAkR6UDqa0DlBrQwsf8yXBkeE4SJ/mnWfdPmhEiY79HlrMMuKH4I0ImqPd55U5Ro vKffvibmgFbrJSSA4ewtq3NYj0AwR5lGs68yTpt2qK7X7kFuIVgeeCYovTMvASYngy3Q uy76zfzvSTtgffIHKXmx1zdyDJV66oQcrhHXKgoU4rFxv3qrCFbjKGYPgrdG3LiJ/7PE FV8kOJAgel9FUuYlyscjq239v8BzePnLFUJuWR9/HHwm7/TWMAV2tzDkbHWDdhwnIQBM jZAbtBf1pjh2o5QSnio0118QOqJ6lJQkfenZ47MnkrfYQB0kSjynD8wOX80+xu2rFI39 gBsg== X-Gm-Message-State: AOAM531aYczfUb8X6huQyTn4BPw7r1zubZ5VM8sDHjbQhGG3Hqp4vWCh vy5OWZTVqj2NWv3epdXp9iM= X-Google-Smtp-Source: ABdhPJyu1EPaHSCFZlovbQkLQnsN71kwV97oCj6PF+lOtnD37yOzU4TgofXiQeQtazI/n6hxRYVH+w== X-Received: by 2002:a63:105e:: with SMTP id 30mr224588pgq.33.1604025029908; Thu, 29 Oct 2020 19:30:29 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:dd13:d62a:9d03:9a42]) by smtp.gmail.com with ESMTPSA id i24sm4216588pfd.7.2020.10.29.19.30.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 19:30:29 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn , Krzysztof Halasa Cc: Xie He Subject: [PATCH net-next v4 4/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices Date: Thu, 29 Oct 2020 19:28:38 -0700 Message-Id: <20201030022839.438135-5-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201030022839.438135-1-xie.he.0141@gmail.com> References: <20201030022839.438135-1-xie.he.0141@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When an skb is received on a normal (non-Ethernet-emulating) PVC device, call skb_reset_mac_header before we pass it to upper layers. This is because normal PVC devices don't have header_ops, so any header we have would not be visible to upper layer code when sending, so the header shouldn't be visible to upper layer code when receiving, either. Cc: Willem de Bruijn Cc: Krzysztof Halasa Signed-off-by: Xie He Acked-by: Willem de Bruijn --- drivers/net/wan/hdlc_fr.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c index 3639c2bfb141..9a37575686b9 100644 --- a/drivers/net/wan/hdlc_fr.c +++ b/drivers/net/wan/hdlc_fr.c @@ -935,6 +935,7 @@ static int fr_rx(struct sk_buff *skb) skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */ skb->dev = pvc->main; skb->protocol = htons(ETH_P_IP); + skb_reset_mac_header(skb); } else if (data[3] == NLPID_IPV6) { if (!pvc->main) @@ -942,6 +943,7 @@ static int fr_rx(struct sk_buff *skb) skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */ skb->dev = pvc->main; skb->protocol = htons(ETH_P_IPV6); + skb_reset_mac_header(skb); } else if (skb->len > 10 && data[3] == FR_PAD && data[4] == NLPID_SNAP && data[5] == FR_PAD) { @@ -958,6 +960,7 @@ static int fr_rx(struct sk_buff *skb) goto rx_drop; skb->dev = pvc->main; skb->protocol = htons(pid); + skb_reset_mac_header(skb); break; case 0x80C20007: /* bridged Ethernet frame */