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: 1390679 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=baJ1Kikz; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CMmVg5Hw6z9sSn for ; Fri, 30 Oct 2020 13:30:03 +1100 (AEDT) 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:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1390680 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=o4iPEbAi; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CMmVw0BLrz9sSn for ; Fri, 30 Oct 2020 13:30:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726261AbgJ3CaM (ORCPT ); Thu, 29 Oct 2020 22:30:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725831AbgJ3CaL (ORCPT ); Thu, 29 Oct 2020 22:30:11 -0400 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0069C0613CF; Thu, 29 Oct 2020 19:30:11 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id x13so3971825pfa.9; Thu, 29 Oct 2020 19:30:11 -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=JIZS4htOoo4rnqCYlSkF4xOfl6ObrKYt6xUCei1ECWY=; b=o4iPEbAieJ75MepEPc+iiWkr13LVENIVgzrejTHiQ3x1lJeKCOUFWWq/EQO9baDUL8 AAYUC4QaUl1MsKk3R6lKA3ln2JmYNCK8eQeSkxiSIk72ExHOlSYFjjaUHsNWfvm1jtVF hAVz/5YLVtb4ETI+xDApd8UCFhLhOdcRLt3lueb24CNzgX7+YPcVphv2OTIDawuRRnXS x0XIR8MCgqg8VG00kC/p1O3MHM/ESpW1AXXmMYIqG8tD3+QY69j3KvMIhfqP6hGV0Z3z i6D0lyLo+Fq3x7C0tbnE50hj+tcDncBDlZ+aT3w5NwpKIO8bK5gNHSqWQllB4TXwRRFk YBGg== 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=JIZS4htOoo4rnqCYlSkF4xOfl6ObrKYt6xUCei1ECWY=; b=HanGgQZOM8yE8Y2Z5dr/HyCqySJ6Ruv76xx9ZfeAqWXUrOAi8K64d7bKjwroQBNMBR zQE+ul+3g4Thiv+Op0V1VUg444GuWPQ0LKc+sbnJw3ghl89mF7zLS6koploXrSy35X6z lZGKFXo7l3Hy2Q+510EytRXsBVrEyodXOrW/5j9soLAliJMvLGxo9uozAyzOETPOxz5H 1KWIXuiUU3lGDushd8Id0cyPuXcRpjDomhYltKJOQWVwML/FYwCoFYFJWLd0ex40ZI7Y jyWJAVzpdzye97hDGAyG4kragBGB6zml5A0DWGPd02DTnnKJ+omNynu2kVBC+kvXTvRE AIuA== X-Gm-Message-State: AOAM532cFPMfi4+kVJAfs+gNJyNFNRlHL9S+MaKh1bPwuf5DEvhFMQ61 QBUA5yPyrwC13IVUBXpk5MigJGzXdvA= X-Google-Smtp-Source: ABdhPJzWx97/Kvfsg5VBwdd8Kf6Zu5aZBHVm+Xw8wAvmNR92sLKaicMrm1lcI5exADyJg4ZM3I6WCQ== X-Received: by 2002:aa7:9622:0:b029:160:7bc:4d00 with SMTP id r2-20020aa796220000b029016007bc4d00mr7240809pfg.51.1604025011230; Thu, 29 Oct 2020 19:30:11 -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.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 19:30:10 -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 2/5] net: hdlc_fr: Change the use of "dev" in fr_rx to make the code cleaner Date: Thu, 29 Oct 2020 19:28:36 -0700 Message-Id: <20201030022839.438135-3-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 The eth_type_trans function is called when we receive frames carrying Ethernet frames. This function expects a non-NULL pointer as an argument, and assigns it directly to skb->dev. However, the code handling other types of frames first assigns the pointer to "dev", and then at the end checks whether the value is NULL, and if it is not NULL, assigns it to skb->dev. The two flows are different. Mixing them in this function makes the code messy. It's better that we convert the second flow to align with how eth_type_trans does things. So this patch changes the code to: first make sure the pointer is not NULL, then assign it directly to skb->dev. "dev" is no longer needed until the end where we use it to update stats. Cc: Willem de Bruijn Cc: Krzysztof Halasa Signed-off-by: Xie He --- drivers/net/wan/hdlc_fr.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c index c774eff44534..ac65f5c435ef 100644 --- a/drivers/net/wan/hdlc_fr.c +++ b/drivers/net/wan/hdlc_fr.c @@ -880,7 +880,7 @@ static int fr_rx(struct sk_buff *skb) u8 *data = skb->data; u16 dlci; struct pvc_device *pvc; - struct net_device *dev = NULL; + struct net_device *dev; if (skb->len <= 4 || fh->ea1 || data[2] != FR_UI) goto rx_error; @@ -930,13 +930,17 @@ static int fr_rx(struct sk_buff *skb) } if (data[3] == NLPID_IP) { + if (!pvc->main) + goto rx_drop; skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */ - dev = pvc->main; + skb->dev = pvc->main; skb->protocol = htons(ETH_P_IP); } else if (data[3] == NLPID_IPV6) { + if (!pvc->main) + goto rx_drop; skb_pull(skb, 4); /* Remove 4-byte header (hdr, UI, NLPID) */ - dev = pvc->main; + skb->dev = pvc->main; skb->protocol = htons(ETH_P_IPV6); } else if (skb->len > 10 && data[3] == FR_PAD && @@ -950,13 +954,16 @@ static int fr_rx(struct sk_buff *skb) case ETH_P_IPX: case ETH_P_IP: /* a long variant */ case ETH_P_IPV6: - dev = pvc->main; + if (!pvc->main) + goto rx_drop; + skb->dev = pvc->main; skb->protocol = htons(pid); break; case 0x80C20007: /* bridged Ethernet frame */ - if ((dev = pvc->ether) != NULL) - skb->protocol = eth_type_trans(skb, dev); + if (!pvc->ether) + goto rx_drop; + skb->protocol = eth_type_trans(skb, pvc->ether); break; default: @@ -970,17 +977,13 @@ static int fr_rx(struct sk_buff *skb) goto rx_drop; } - if (dev) { - dev->stats.rx_packets++; /* PVC traffic */ - dev->stats.rx_bytes += skb->len; - if (pvc->state.becn) - dev->stats.rx_compressed++; - skb->dev = dev; - netif_rx(skb); - return NET_RX_SUCCESS; - } else { - goto rx_drop; - } + dev = skb->dev; + dev->stats.rx_packets++; /* PVC traffic */ + dev->stats.rx_bytes += skb->len; + if (pvc->state.becn) + dev->stats.rx_compressed++; + netif_rx(skb); + return NET_RX_SUCCESS; rx_error: frad->stats.rx_errors++; /* Mark error */ From patchwork Fri Oct 30 02:28:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1390681 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=GJQ8PtnZ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CMmW73lkzz9sSn for ; Fri, 30 Oct 2020 13:30:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726297AbgJ3CaZ (ORCPT ); Thu, 29 Oct 2020 22:30:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726057AbgJ3CaX (ORCPT ); Thu, 29 Oct 2020 22:30:23 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15A19C0613CF; Thu, 29 Oct 2020 19:30:23 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id r10so3916384pgb.10; Thu, 29 Oct 2020 19:30:23 -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=B/7mr9at8aiFOt20RGTnPfBfr8OJELJGRx4fnyFdhVY=; b=GJQ8PtnZApmXB+RWDiwdR/Ie54aWpuDdciUE6GRIGU4i5scEBoCJZWoOcP0zpS4umm s91cXSD6S+RnIoj3E7GwGc0PXn3j1V7ugSH7sMJqZ3fIeXzIzRcdokKPqgPAtb3GHLlI 4Aekdn1+pqklGd6JI556X2/2ubwBmpRebIniDeoxyV+cjApk766h1WP8JKfmAnPCY6XW wNcPpAUZODX8iCSSknJqS8icSldyjxXdaMDQwsCLWPvxPpISDcgjBXRlANs8nsI0i3Bx /sjz4AggzLULNhoUfrmyfrCxDQqzsnynOI4aA0feZHWKFBGfcSpjYjoRuLoLdxP8+tcC GH4A== 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=B/7mr9at8aiFOt20RGTnPfBfr8OJELJGRx4fnyFdhVY=; b=bfGIWuQK+1uUebN11/MbuUM5Fk3TyCBqu2ls3Vrbxpnyt5iejwhTSXTjyDfiXkaWCO 7oGNzTesO7DIB873oqxTSQCEBPSmlFxTSJj/2f3ufCdI0tmtjBPxe4hxZPAO3TfKJtR8 PsNUGmxwKuvu87YNiwBAYYswrL4ExKOcF6rC+OemsHrhdtzhnHbVXabXMGWVmTjiri5B fkiUDo53nde7q01CRSvvsyQrmunft+WzCi2csadS3P6xjvsfoPVX2hhUECbPOnuY+/FS lUygZ+Pc2Rd7NghNS9QlZDfgWfDmLX9gvMxOHtfp+isXNVOzJRzWFvO8hQMEGC5qHIIY gStA== X-Gm-Message-State: AOAM530fYWH2yeLPZLdwspMID8ESa2evhicctp1FBBJu83c6AuTEaXPa gS3YawBA6he5aZzi33mArehT+iKJYuo= X-Google-Smtp-Source: ABdhPJzYAMEvf7Rzsp9xQu4cRdfgJ0a9Dc5srYHfsgwkz/I39XsKmgRLqNFu3Q1p74bVAT7F/vO9/Q== X-Received: by 2002:a62:5251:0:b029:164:3604:578d with SMTP id g78-20020a6252510000b02901643604578dmr7507679pfb.51.1604025022710; Thu, 29 Oct 2020 19:30:22 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 19:30:22 -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 3/5] net: hdlc_fr: Improve the initial checks when we receive an skb Date: Thu, 29 Oct 2020 19:28:37 -0700 Message-Id: <20201030022839.438135-4-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. Change the skb->len check from "<= 4" to "< 4". At first we only need to ensure a 4-byte header is present. We indeed normally need the 5th byte, too, but it'd be more logical and cleaner to check its existence when we actually need it. 2. Add an fh->ea2 check to the initial checks in fr_rx. fh->ea2 == 1 means the second address byte is the final address byte. We only support the case where the address length is 2 bytes. Cc: Willem de Bruijn Cc: Krzysztof Halasa Signed-off-by: Xie He --- drivers/net/wan/hdlc_fr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c index ac65f5c435ef..3639c2bfb141 100644 --- a/drivers/net/wan/hdlc_fr.c +++ b/drivers/net/wan/hdlc_fr.c @@ -882,7 +882,7 @@ static int fr_rx(struct sk_buff *skb) struct pvc_device *pvc; struct net_device *dev; - if (skb->len <= 4 || fh->ea1 || data[2] != FR_UI) + if (skb->len < 4 || fh->ea1 || !fh->ea2 || data[2] != FR_UI) goto rx_error; dlci = q922_to_dlci(skb->data); 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: 1390682 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=uVR8AlzN; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CMmWF4TQPz9sSn for ; Fri, 30 Oct 2020 13:30:33 +1100 (AEDT) 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 */ From patchwork Fri Oct 30 02:28:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1390683 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=sIPVkoX/; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CMmWQ4S5Fz9sSn for ; Fri, 30 Oct 2020 13:30:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726340AbgJ3Caj (ORCPT ); Thu, 29 Oct 2020 22:30:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726197AbgJ3Cah (ORCPT ); Thu, 29 Oct 2020 22:30:37 -0400 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44110C0613CF; Thu, 29 Oct 2020 19:30:37 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id o3so3908736pgr.11; Thu, 29 Oct 2020 19:30:37 -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=g7bH88D4g/VYGOa3hWMRp6XP+GTlXN0P1WC9N4Q2/XM=; b=sIPVkoX/Of6nVZG0ZQgVEkv9eNrnT5+MLWijSKMQbASTMC4PXi8b+L2jK+WSCb12I2 rfzmY8ocgI9WK/Z4GFsF7Z2kU7rnTSDlzGasss0mN5YOb88P2MWW3SChA1B5PYj+XB2I kJNeB95XEqJMVTz+DpoaPPEt8njOiIgrORPkp53nZQk37TTadn2it2iO6fJm3KXzEHWg aroSeUO2kcm2plv5TQB9siuRYYT8neLqRjXBSV3YP+Z0mnUWzobdzdMUVQSYmmuJ6ZFp aKeoU2Pg/DUf8Rbac59vFyzcs01F6JFxMSIBriLKvcElFtFTnahjusIKEXJWj6thO8wF K7xg== 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=g7bH88D4g/VYGOa3hWMRp6XP+GTlXN0P1WC9N4Q2/XM=; b=NM23zp4bwwNtzSsVzMaWAYEDBoi0C5g6TxX2qA2xckqahc9TwtDOs+tZkAOSRC3O0+ e5P9jBwaWYeGA2k3vsZnmJ1FmR5jTiHasdBAnRes8zPKsGsIin0SKl5Y1L1Uwe0+8Ddr NS3fVSnsXaAmHL6A/ZuQuggJoesqk/BFUuJZ+iY3MfrS0BdzoEJLE99oSYiMJu6B/Vtd VMyAIEtNUv8AS0x4dXnang99d0eU15P1wVPTJls3KKczAiu5koO9eSbEFVTuTX6ehwvE WTCw46H0LN9az/BNuDzePi+UXJ3AoF5d1awHUMTnPEXigwULpYTuvWYILH+ZWIE37Tp4 V94w== X-Gm-Message-State: AOAM531qoXbkw82+3cHNolDJFT3zT3gfnGjSRFfbidQFBnzswiuZK0mE +3zsfcqL1QBa4b9YBzFaojA= X-Google-Smtp-Source: ABdhPJxaWSHPgJMIvnjBMqb0MKb8E8b7ORoASIJ2qcWWVTBzFsOJt3fNIkTg+R+jiGT58y7Q+xSCCA== X-Received: by 2002:a65:5a0d:: with SMTP id y13mr230777pgs.436.1604025036855; Thu, 29 Oct 2020 19:30:36 -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.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Oct 2020 19:30:36 -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 5/5] net: hdlc_fr: Add support for any Ethertype Date: Thu, 29 Oct 2020 19:28:39 -0700 Message-Id: <20201030022839.438135-6-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 Change the fr_rx function to make this driver support any Ethertype when receiving skbs on normal (non-Ethernet-emulating) PVC devices. (This driver is already able to handle any Ethertype when sending.) Originally in the fr_rx function, the code that parses the long (10-byte) header only recognizes a few Ethertype values and drops frames with other Ethertype values. This patch replaces this code to make fr_rx support any Ethertype. This patch also creates a new function fr_snap_parse as part of the new code. Cc: Willem de Bruijn Cc: Krzysztof Halasa Signed-off-by: Xie He Acked-by: Willem de Bruijn --- drivers/net/wan/hdlc_fr.c | 75 +++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 26 deletions(-) diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c index 9a37575686b9..e95efc14bc97 100644 --- a/drivers/net/wan/hdlc_fr.c +++ b/drivers/net/wan/hdlc_fr.c @@ -871,6 +871,45 @@ static int fr_lmi_recv(struct net_device *dev, struct sk_buff *skb) return 0; } +static int fr_snap_parse(struct sk_buff *skb, struct pvc_device *pvc) +{ + /* OUI 00-00-00 indicates an Ethertype follows */ + if (skb->data[0] == 0x00 && + skb->data[1] == 0x00 && + skb->data[2] == 0x00) { + if (!pvc->main) + return -1; + skb->dev = pvc->main; + skb->protocol = *(__be16 *)(skb->data + 3); /* Ethertype */ + skb_pull(skb, 5); + skb_reset_mac_header(skb); + return 0; + + /* OUI 00-80-C2 stands for the 802.1 organization */ + } else if (skb->data[0] == 0x00 && + skb->data[1] == 0x80 && + skb->data[2] == 0xC2) { + /* PID 00-07 stands for Ethernet frames without FCS */ + if (skb->data[3] == 0x00 && + skb->data[4] == 0x07) { + if (!pvc->ether) + return -1; + skb_pull(skb, 5); + if (skb->len < ETH_HLEN) + return -1; + skb->protocol = eth_type_trans(skb, pvc->ether); + return 0; + + /* PID unsupported */ + } else { + return -1; + } + + /* OUI unsupported */ + } else { + return -1; + } +} static int fr_rx(struct sk_buff *skb) { @@ -945,35 +984,19 @@ static int fr_rx(struct sk_buff *skb) 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) { - u16 oui = ntohs(*(__be16*)(data + 6)); - u16 pid = ntohs(*(__be16*)(data + 8)); - skb_pull(skb, 10); - - switch ((((u32)oui) << 16) | pid) { - case ETH_P_ARP: /* routed frame with SNAP */ - case ETH_P_IPX: - case ETH_P_IP: /* a long variant */ - case ETH_P_IPV6: - if (!pvc->main) - goto rx_drop; - skb->dev = pvc->main; - skb->protocol = htons(pid); - skb_reset_mac_header(skb); - break; - - case 0x80C20007: /* bridged Ethernet frame */ - if (!pvc->ether) + } else if (data[3] == FR_PAD) { + if (skb->len < 5) + goto rx_error; + if (data[4] == NLPID_SNAP) { /* A SNAP header follows */ + skb_pull(skb, 5); + if (skb->len < 5) /* Incomplete SNAP header */ + goto rx_error; + if (fr_snap_parse(skb, pvc)) goto rx_drop; - skb->protocol = eth_type_trans(skb, pvc->ether); - break; - - default: - netdev_info(frad, "Unsupported protocol, OUI=%x PID=%x\n", - oui, pid); + } else { goto rx_drop; } + } else { netdev_info(frad, "Unsupported protocol, NLPID=%x length=%i\n", data[3], skb->len);