From patchwork Sat Oct 31 18:10: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: 11871527 X-Patchwork-Delegate: kuba@kernel.org 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 F272CC55178 for ; Sat, 31 Oct 2020 18:11:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A14A72068D for ; Sat, 31 Oct 2020 18:11:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eLzZ0AwC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728247AbgJaSLU (ORCPT ); Sat, 31 Oct 2020 14:11:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbgJaSLU (ORCPT ); Sat, 31 Oct 2020 14:11:20 -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 20353C0617A6; Sat, 31 Oct 2020 11:11:20 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id r10so7537977pgb.10; Sat, 31 Oct 2020 11:11:20 -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=kgjTZ7AtCZGnMu7reRKzrJNKspD5ReY/6YK7OXZaldU=; b=eLzZ0AwCNFLsBFfwc8wDaxDh9stLAj2iJ18DsxYB/ojqQJjoSbuy0ISnXTphd35ovz CJgSQDhs5MrQL3h/Q91QyVeR5lVcBXx5n7WyXKQL3siMRM7Y/uFO2EEFZv6PIyIVgQpz iRq7H2+ktsrJZZvGd4hlVkVaBP8pBMT0W9SeHcAPMoG8RYNA+PA3oDV5Znbu5MSW2S3I YeHj2pXkB2pA9+OzTlm3zlyeA015xK50D/nvkdBOlIoIGJWPLiAAs1tx52cNu0XRcy6h rcxIfc9Lf1qM+m0N8f+DmjJnVys2zYprjs8pZa3NKxN/795y+CZON+AeOKJTU18PuhcY Rp8w== 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=kgjTZ7AtCZGnMu7reRKzrJNKspD5ReY/6YK7OXZaldU=; b=X6I01qz4zLvRjzA7E7+q1pXmTIFMlYfEiU0kTdaiBikyzIRwS9Sy/x3cqc3uZ3JaVg DdRaEz2azNxppJvW5Dc4OX1VmnijC406Bcv1eATw/MbbfUEhvalaKKgdMGAIdpW0p8X/ /IgUFMfLzM6OpW/c8Bmzg0a0HUhN9CocduKLuiSksd58XmxbcFRWn/VynlDauEVyAwPt 6/2uVKE34+lcSbTBxix1cwgyBRZkrwE0nru/e7Ey8WLetbDleSCmon2mzpgddR658+X5 HcZcR4o1tAkTsT7O5XK5w3LQ0DAMUA7cJgJXrxRYXv7crNRlLBnzg/iRN8fCo0ZdJSpk NvvQ== X-Gm-Message-State: AOAM530csj88G4x0sUPD1IwqvJE2bYYpvBtjBa3CRLRK4dxFgWURGMPc jxoEZ9kW+DnwByYaVqdE0UM= X-Google-Smtp-Source: ABdhPJwuu95auB3fJKNZFFXvW7jTyWVqcJb3o7Mf+EO1juTlf8iuYGw4FtzJC71hy5tB94kzf1Pu0w== X-Received: by 2002:a63:5421:: with SMTP id i33mr7314056pgb.316.1604167879672; Sat, 31 Oct 2020 11:11:19 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:32f8:16e7:6105:7fb5]) by smtp.gmail.com with ESMTPSA id n6sm6967137pjj.34.2020.10.31.11.11.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Oct 2020 11:11:19 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa , Willem de Bruijn Cc: Xie He Subject: [PATCH net-next v7 1/5] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames Date: Sat, 31 Oct 2020 11:10:39 -0700 Message-Id: <20201031181043.805329-2-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031181043.805329-1-xie.he.0141@gmail.com> References: <20201031181043.805329-1-xie.he.0141@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org 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. Cc: Krzysztof Halasa Cc: Willem de Bruijn Signed-off-by: Xie He --- drivers/net/wan/hdlc_fr.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c index 409e5a7ad8e2..4db0e01b96a9 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,12 @@ 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: dev_kfree_skb_any(skb); return NET_RX_DROP; } From patchwork Sat Oct 31 18:10:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 11871529 X-Patchwork-Delegate: kuba@kernel.org 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=ham 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 B4718C388F7 for ; Sat, 31 Oct 2020 18:11:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 64A50206DD for ; Sat, 31 Oct 2020 18:11:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IxcElbdF" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728272AbgJaSLe (ORCPT ); Sat, 31 Oct 2020 14:11:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbgJaSLe (ORCPT ); Sat, 31 Oct 2020 14:11:34 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0032DC0617A6; Sat, 31 Oct 2020 11:11:33 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id z3so1343555pfz.6; Sat, 31 Oct 2020 11:11:33 -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=2ZRH0OzxUypIK1b/aMoXuBb/y6XgbaeCstQDTI1G9UY=; b=IxcElbdFkcgYTe6k5qR9zKCQIVmdby5pRjYwJHfUt8FX6IqcRrItr8NLtmziwXY/az mIcslyNeCzKTAeqbf9m9U8Cdp9CUAOgbkxtZp2KUL7GMRXjpjVsFg42FPxqcGlPzlsCb o+Lj+jQB96evj9xQ+MmuK2MncvEAOvNGQc1vqP5dIlCfhXqJlR2364QR194JkGUpj0GV MMiWJdG1DYTatcJ+3LmIGcekERg/0sTrB8mnO2t7e1u2d3rbzbg7REfhJSZbbJWuTymJ 1Ea1kbNOdudZWAJl7FsTXT6p2oEsXUvUj9+NPQg6T1JO/zv8/RRlNkAT1KECaHxRFwIv Yp1w== 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=2ZRH0OzxUypIK1b/aMoXuBb/y6XgbaeCstQDTI1G9UY=; b=Rn4ECjh3QCEv0xj3aGA15Bh+GPxINthikEWJifOmyqKakBsaaKHvLFdV+CHd2kkexR 8IyjWOaytoRSPQ1YWc36qIVpm3ELccPuon39BFNVWNm0gBYHSR9YonhLcFFQOnRQtmBQ iA4B3cVjjdOqq1IqicummqfrvNn5fbmgdPcVR0RPNwetKv2wsR08cPSOsmxveURzLxH6 J+BfxJRjUCv/NfkV/elA+cRAwCfwi2DeiARAXqARHFOw+lDMDvhsGFC7SKh18qJFgdic kjWB5P3ljKzYI1FRQHG7c/ECuP8JmmoXsKAN61asw9Oqt++pFkxRmxis6QysSTolQKlw TcNQ== X-Gm-Message-State: AOAM533sLdegeCbyvI/w7ccweUMdyJTj5fanqYfYrJNSU8NBFSooG6Sb yejWIMUa13kgB91+EL/SLZwbBDF3jOs= X-Google-Smtp-Source: ABdhPJwQwxMlTnslt1Tz2wnT9qcZhKp5jlmk1AqCMGi2QNa7eiDd5oj+nqLVOa67EPEDIBdJPRFUzg== X-Received: by 2002:a62:7b47:0:b029:18a:ab71:7821 with SMTP id w68-20020a627b470000b029018aab717821mr4321187pfc.3.1604167893479; Sat, 31 Oct 2020 11:11:33 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:32f8:16e7:6105:7fb5]) by smtp.gmail.com with ESMTPSA id n6sm6967137pjj.34.2020.10.31.11.11.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Oct 2020 11:11:33 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa , Willem de Bruijn Cc: Xie He Subject: [PATCH net-next v7 2/5] net: hdlc_fr: Change the use of "dev" in fr_rx to make the code cleaner Date: Sat, 31 Oct 2020 11:10:40 -0700 Message-Id: <20201031181043.805329-3-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031181043.805329-1-xie.he.0141@gmail.com> References: <20201031181043.805329-1-xie.he.0141@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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: Krzysztof Halasa Cc: Willem de Bruijn 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 4db0e01b96a9..71ee9b60d91b 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 Sat Oct 31 18:10:41 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 11871531 X-Patchwork-Delegate: kuba@kernel.org 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 6EA62C388F9 for ; Sat, 31 Oct 2020 18:11:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FEDE2068D for ; Sat, 31 Oct 2020 18:11:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b2HQaM9b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728284AbgJaSLr (ORCPT ); Sat, 31 Oct 2020 14:11:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbgJaSLq (ORCPT ); Sat, 31 Oct 2020 14:11:46 -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 D711FC0617A6; Sat, 31 Oct 2020 11:11:46 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id k9so5857202pgt.9; Sat, 31 Oct 2020 11:11:46 -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=4OdtTTsb5oeQcbyGruvkyQTB5rSp5snExHVKrgbeYhs=; b=b2HQaM9bDwVaJZGMnqXVrOHjGpNMIAil1UOmN2Q/SkHERrnbPZW+C11CUSavFQhTuZ xhZDBL5lzob7l+saB3ifrhMs47dd8XYun5mebYVpQC+jHvyoPOmcgJbvPLTnw0URpCut dykeA5gEuG2B7++bvVVoU+81iHyRsWZzZwi0n9l8+OmgVMhBcmB1pZi4UGSb6uT2CGy0 VG96fYUCK28W/9cC2nM7WFtPaLd2d/fr3RS2rtg6QV1w9Pm80Duz05VflrwY/KNQEL5M MpriPXYPUcUKQEIsYhLkWB1a0NS6oGuZqycxDeEgrXj48nnLz7wMTx4tRnU09metbKqw 1B9g== 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=4OdtTTsb5oeQcbyGruvkyQTB5rSp5snExHVKrgbeYhs=; b=I1AwgPdjQ8Zu4M63co+CQ/nMQrTX9KrZq+1CSn5TwD3wMaJAlykZJuv/DEWEOANlhk KA2pe/IsJ+z18rClBORN8lgMG7Y1UViB3Xb+VNalYHSeecTdLnnM6GUuy/ab3BdES+FM YQ16+vghdHyDkFwJRAZkp6U5jZpAsrnfA8owQNK717cRlJLHg8Ug1JDwH7Q6eKXHP934 oBu0x+ReX3g2aI0OBsKkgvGMG5DkG33GWbud5FtXUYBRkkNsF+/MLpaRCyVCZjFGVzJr 9Q1fcOIR3Bz1ZJhpQjUB3azvzaayi4R2kOX/C4die8jcQP78JADSmAHgXwREclMPrcbK Pcpg== X-Gm-Message-State: AOAM5317OHDHWCsQMYeRrixoz0ZGwe0ziH2xMT7kz0ILWX2gOnxU190k mk41tbaokTg/JegASbcSqUw= X-Google-Smtp-Source: ABdhPJwQHfWFbnndm62dCjmdUfizBXIAMudribvjIBhRN3fSmtVcaPgXr84h4mEvefbpHBzmYVqLAg== X-Received: by 2002:a63:5b64:: with SMTP id l36mr7045365pgm.435.1604167906480; Sat, 31 Oct 2020 11:11:46 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:32f8:16e7:6105:7fb5]) by smtp.gmail.com with ESMTPSA id n6sm6967137pjj.34.2020.10.31.11.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Oct 2020 11:11:46 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa , Willem de Bruijn Cc: Xie He Subject: [PATCH net-next v7 3/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices Date: Sat, 31 Oct 2020 11:10:41 -0700 Message-Id: <20201031181043.805329-4-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031181043.805329-1-xie.he.0141@gmail.com> References: <20201031181043.805329-1-xie.he.0141@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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: Krzysztof Halasa Cc: Willem de Bruijn Signed-off-by: Xie He --- 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 71ee9b60d91b..eb83116aa9df 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 Sat Oct 31 18:10:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 11871535 X-Patchwork-Delegate: kuba@kernel.org 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 08D7AC55179 for ; Sat, 31 Oct 2020 18:12:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0B02206D5 for ; Sat, 31 Oct 2020 18:12:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hKvZamZT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728296AbgJaSL7 (ORCPT ); Sat, 31 Oct 2020 14:11:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbgJaSL7 (ORCPT ); Sat, 31 Oct 2020 14:11:59 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25BF4C0617A6; Sat, 31 Oct 2020 11:11:59 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id ie6so403021pjb.0; Sat, 31 Oct 2020 11:11:59 -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=AMBn+rYkg3m7MdrionOcBnXTX9dRZwUBNceirhydnOk=; b=hKvZamZTb25e33AB+8VwWxH330WIl0POFvf7Rfyx7DHPRUoZVZrNtNNkz6QKFc1Utm rwnFzczRZdxUfLKeXNuATbMg5sSjo3sbGwJEehw50CxxKbMmKHbO+jG2iAsrnNDSiyxx aQg97tq0GcvLAv7nd9Sg4ZVkosnMTxRY1ZCyDPOFC2f0MDwyBNhmestTTLNu80w50JWM i97p+zWBS4k51ZmNDttob0rdmBGxpiF+0iZjlIVsnF2SOfm6Mst81WGf0Tl+AblvlIvr l5GQ0nE0uac/hw9fjeFtXydTLW5ifIlb/vj91CynqjfLReQpWANKa8aUYzlYpTGC/4Mi zFmg== 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=AMBn+rYkg3m7MdrionOcBnXTX9dRZwUBNceirhydnOk=; b=YCNPGb5InR0zaly2hUcHPPBJ2jBbcw31sgT9W3pkxGII8VnXS+qRKmNX9hS6uSPYIT xnNRSSyF4fa/RMMsX/M51h+tGcjcN4OdbPDtRhqcHsCvGQSnUWwm4SAHrG9SBHTPQ83v iG7wXWg9Bq9CoQPkN71zelqbQzjtAB+Jfn1W27M+Sb708d7/fdUqXC+RxE9sZ88B5fTC te3pkrZEyB/zAxll8mifWNHMm1K6AMNx4rfuT75vEp06pSbhkNQ2zQnQNsBLWWBMzvJr QAZdytR1d46ef15YBtzOAB1ZWkbSYYtB7tmQYCn5yA6tKJoNbGfRPj1gcdtNHXa3iHqL UMlA== X-Gm-Message-State: AOAM5324qdyEYZebIZ1H1/ckVN9Mm9rpp3C66+fL5Wcwz/BpBi2/GQpe wZ3Wif0Zko9NLtGNuXrwgf8= X-Google-Smtp-Source: ABdhPJy7cxBykrG/vdL/UwPP80XqDpzuk/yzPsAkY6yIg2wVQ/CvrC6VM4FH2YL0EW9EXZTjEiSzdQ== X-Received: by 2002:a17:902:7046:b029:d5:a5e3:4701 with SMTP id h6-20020a1709027046b02900d5a5e34701mr14157624plt.57.1604167918755; Sat, 31 Oct 2020 11:11:58 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:32f8:16e7:6105:7fb5]) by smtp.gmail.com with ESMTPSA id n6sm6967137pjj.34.2020.10.31.11.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Oct 2020 11:11:58 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa , Willem de Bruijn Cc: Xie He Subject: [PATCH net-next v7 4/5] net: hdlc_fr: Improve the initial checks when we receive an skb Date: Sat, 31 Oct 2020 11:10:42 -0700 Message-Id: <20201031181043.805329-5-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031181043.805329-1-xie.he.0141@gmail.com> References: <20201031181043.805329-1-xie.he.0141@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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: Krzysztof Halasa Cc: Willem de Bruijn 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 eb83116aa9df..98444f1d8cc3 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 Sat Oct 31 18:10:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 11871537 X-Patchwork-Delegate: kuba@kernel.org 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 B55F3C388F7 for ; Sat, 31 Oct 2020 18:12:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 759BA20679 for ; Sat, 31 Oct 2020 18:12:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Wbylnzq3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728319AbgJaSMO (ORCPT ); Sat, 31 Oct 2020 14:12:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727120AbgJaSMN (ORCPT ); Sat, 31 Oct 2020 14:12:13 -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 47F02C0617A6; Sat, 31 Oct 2020 11:12:13 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id 133so7714639pfx.11; Sat, 31 Oct 2020 11:12:13 -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=Jz6x+g+xbqRpPTzzyKWaisQhdh5VoS5Zw+hJtNIjDSU=; b=Wbylnzq3WLJpP9giv3tONeDQu6NBOEsxnRLPldc5hJISiPhq1CVWhCKOKptQhxCCrE rEizpfuepS759FTRhxMJ0ukacbKfMX98wIE4Ot2FuvdiBOYI5rNTtXF40wdX6t4Jbj8i SmZVaoJ1SbIO1uzhKAU0i+/NNyK0oQo55iiA4BjmcwBEJ6X9S20Y9ulwE4aLwZMx0BB8 kWqZq19WTBgXGn8QNRhy8xfX36rkkhOJJzG21H1XmKY1GKyGiVBBiPjujAA2YP/yDSh4 aMIL4z3fgcDBf4YyDKFb4cnxEPEut3tLKL+7Pgi0lSstV7OHgskgCdyMiDX/knbNwhpw iksw== 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=Jz6x+g+xbqRpPTzzyKWaisQhdh5VoS5Zw+hJtNIjDSU=; b=NuVHDVjEMTkqz8SpEIHG4mk3d/N8yhZwO8Oq2SOw0aQGpa5b5PPQspH6MDev1K3T7P 7GyG8hfBl5CfkQXQhxIZdoIjaesBL1vz52PAvtpVbWURJtGw+LsALI6pOTQGUjRvZgI+ nsLMsqLakJuBn+7VukpLHNd70D2O3NU4DHtPd9p7CQD7nIXavISROFjtwH7PwpOY553E WC5t6sPRMJy9u8oW/FtaS+FpBR/OAWkD/7iTriP06h8uAayq4ePGZrd0IOLgnZRj3axH 8QnWdSNwccxQeZYM8Zqw9oHze8AOKMdDy9pzxFjLk3MkiwkrNFNRs6FJFR3FrdVG1BlU Tb8w== X-Gm-Message-State: AOAM533xPlOyofj7ApeY4BbBwf1Stc85on1oKQ328VTB6IhEX03B57bn RfVlW23zRTvd3BKGbnHgK10= X-Google-Smtp-Source: ABdhPJxs6lTpBPQ0vGfBF254AcR8omT9nNEqrInpWYRBnFsDt2ZDWMqzrPYLBJUsWuEcri7IuYo1Fw== X-Received: by 2002:aa7:8815:0:b029:163:c712:81ad with SMTP id c21-20020aa788150000b0290163c71281admr14762157pfo.74.1604167932871; Sat, 31 Oct 2020 11:12:12 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:32f8:16e7:6105:7fb5]) by smtp.gmail.com with ESMTPSA id n6sm6967137pjj.34.2020.10.31.11.12.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Oct 2020 11:12:12 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa , Willem de Bruijn Cc: Xie He Subject: [PATCH net-next v7 5/5] net: hdlc_fr: Add support for any Ethertype Date: Sat, 31 Oct 2020 11:10:43 -0700 Message-Id: <20201031181043.805329-6-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031181043.805329-1-xie.he.0141@gmail.com> References: <20201031181043.805329-1-xie.he.0141@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@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: Krzysztof Halasa Cc: Willem de Bruijn Signed-off-by: Xie He --- 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 98444f1d8cc3..0720f5f92caa 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);