From patchwork Wed Oct 28 18:43:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 316157 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 B8032C388F7 for ; Wed, 28 Oct 2020 21:55:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CADF2470E for ; Wed, 28 Oct 2020 21:55:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ua7p9eUz" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728487AbgJ1Vzj (ORCPT ); Wed, 28 Oct 2020 17:55:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49650 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726108AbgJ1Vzh (ORCPT ); Wed, 28 Oct 2020 17:55:37 -0400 Received: from mail-vs1-xe43.google.com (mail-vs1-xe43.google.com [IPv6:2607:f8b0:4864:20::e43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FCD7C0613CF; Wed, 28 Oct 2020 14:55:37 -0700 (PDT) Received: by mail-vs1-xe43.google.com with SMTP id n18so421890vsl.2; Wed, 28 Oct 2020 14:55: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=xlNmuHQ+BurcadNmXEhYfuLEuxMLXCWKJpkTUb50b+g=; b=ua7p9eUz0VZTYnprfPwzXc9tHlEBxA9jB2z0A5xuUACtbjVQnbEilkQyrxulVgUitI 6v8ZDuWz0+iueLRNUjGJCvCoJSNVHmE3hG+AAAOmIKox+vn/6D/3Ro+1RdJJTfHOsEx4 BkdKbv/TTD/oCT+bCdBsxD/3ND6dOB3Mh7i70wG2EH7m3XDbjQQs9Wd4ya77UDIH+oh2 6h/6Vl2ou1ykIwalJkchaBkIQbj4+JYaF9auLDCf5Vffzooa3+InOEaNtJPoo51y6LAS MdA3Z0Yr5c6LbLWFZSz98qGKXk2iX9xRiT8KkSeALGD9fiy5Bkd0s8jY0ZDr36OrxHUV RbDQ== 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=xlNmuHQ+BurcadNmXEhYfuLEuxMLXCWKJpkTUb50b+g=; b=V/R16T952+Y3aYzvEbupZuNvDuX0k2ROR1To6hviJDKC3peYb/Dy9m1fyvIZ7RhtlH Gkfw/K68nXGK5bWv8OSkTSJz8GWabWrhOm2ikf7Ceb/wwzw4KcDIuWgJn4AkvvFZbdoH XQjka5iD4RRnzQjk9WhUA71tPKGw76pHNTFu+TGlop21B3wZEPW6/Vwsko5HfU4a2D4w v2yd1sabeLTDKFNE5dOQ1t1gah8SuqYpzEYT5K/i/Z8n/gb5DEBwxpNuvpzaOxu4jNZ8 MAo65kKKqQCKiUP33wgkSuz9d7whOyRRcULm1ZOGN/GQUcqcnxnOFgfekvmWQtjpKRO0 XV2w== X-Gm-Message-State: AOAM530hTv+sWSMD+R3xJLPIZ1CDG4V0WHr7m4hqpUt8LRx/gBNWL+Tl J16O8ZntZxbximNuHOenh0SqEyV40Mw= X-Google-Smtp-Source: ABdhPJyb6BDH2uHq4GsoWPXDBjiwAM1y6GE+lAkFDG1gsPzS/Xnd/5Izu/YUbjYDnTIGKDYpmWMEew== X-Received: by 2002:a17:902:b217:b029:d6:fba:ddd8 with SMTP id t23-20020a170902b217b02900d60fbaddd8mr606442plr.9.1603910600943; Wed, 28 Oct 2020 11:43:20 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:6d80:dec8:7340:3009]) by smtp.gmail.com with ESMTPSA id y27sm309785pfr.122.2020.10.28.11.43.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 11:43:20 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa Cc: Xie He Subject: [PATCH net-next v3 1/4] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames Date: Wed, 28 Oct 2020 11:43:07 -0700 Message-Id: <20201028184310.7017-2-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028184310.7017-1-xie.he.0141@gmail.com> References: <20201028184310.7017-1-xie.he.0141@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.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. Also add code to increase the stats.rx_dropped count whenever we drop a frame. 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 Wed Oct 28 18:43:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 316086 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,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 8EE13C4363A for ; Thu, 29 Oct 2020 02:02:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3670D20791 for ; Thu, 29 Oct 2020 02:02:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fvc9YZag" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727368AbgJ1Vsz (ORCPT ); Wed, 28 Oct 2020 17:48:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727976AbgJ1VsA (ORCPT ); Wed, 28 Oct 2020 17:48:00 -0400 Received: from mail-oi1-x243.google.com (mail-oi1-x243.google.com [IPv6:2607:f8b0:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A62D4C0613CF; Wed, 28 Oct 2020 14:48:00 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id f7so1145551oib.4; Wed, 28 Oct 2020 14:48:00 -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=A/cW/YFtK1RV+lsW86culRjQ8dc+fqZrnk+DqtqcbRM=; b=fvc9YZagg7e0AUWWuX4JxuRgCLq0vsNScsRdPpL4l+36rDx6K3L2V0MeNdBe1QPG9l wpmam7+A7lxg70omTP5YKHdZdiAvb1nFewEYSAcgMO1YAzlyruNcTxmkxifJvRdp7+BK AHM+jhJG4KaWenvTa5/2+quzyrQaXXdqM0efkiFm1cO7Dr1BC5/22x142PQsTkyD/OLM irxipl6cEVRCtBkIQatL9xUovDsAVmSWR2jKN2PPIyltFKfnawTYpTcQi1pEL4ZOFZmE Xcfu9ACDw5ur6pNeo7Vv5LX68bMkyu/Hyj+9upUXU4L0No12GtlCx2ONx31kxRKpbVV3 BrRQ== 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=A/cW/YFtK1RV+lsW86culRjQ8dc+fqZrnk+DqtqcbRM=; b=akLm1pTYShcBAP0EXBF7Fy76+MamA29tFo30NoPUG4ChieFjO30a2GxNEugES2p9zl VNP521u1sL/jgLh0ddlR6rCiH8rf9B99Y/rZ8Tq1FcKTz8FaXT5t8fL2qL5dc5cinZdW mjHTOMBlBwKmHHaDZXjcy5biEmP0UJX9aNyPte0WDBgcfyS7hTFJFTe4iFQfavEi+y+I Q4wV/6SFWXH1X5rg71nHFH5Me4/89vNKd3i4Qo4opsROqH223hUV4W2MZtdud5S/Pj0S ZkR/iBCGmglUSaK+uXS//9rb6mSG1cfVVB+Ifp1/6Ve5rQhESF1m6QyVnHFRlYTGkPua 8ayw== X-Gm-Message-State: AOAM532oX0cgD/b2xHs+9Fh3ekfNJBfBKD/Qq1NA7pOyJWkA6K4LdN9j cA3ru2Xa63muHQCLBwB91/YH0FXl1PY= X-Google-Smtp-Source: ABdhPJxWHcqu45Kcbd0ePFmJfXLdgetqSZap1gd/5TZTPWFANxYYv8CuQhVlBPXIYelDzr6MBiF0Ug== X-Received: by 2002:a17:90a:530c:: with SMTP id x12mr243701pjh.187.1603910603853; Wed, 28 Oct 2020 11:43:23 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:6d80:dec8:7340:3009]) by smtp.gmail.com with ESMTPSA id y27sm309785pfr.122.2020.10.28.11.43.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 11:43:23 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa Cc: Xie He Subject: [PATCH net-next v3 2/4] net: hdlc_fr: Change the use of "dev" in fr_rx to make the code cleaner Date: Wed, 28 Oct 2020 11:43:08 -0700 Message-Id: <20201028184310.7017-3-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028184310.7017-1-xie.he.0141@gmail.com> References: <20201028184310.7017-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 a 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 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 Wed Oct 28 18:43:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 316148 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 B55EDC4363A for ; Wed, 28 Oct 2020 22:16:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5CDFA2473C for ; Wed, 28 Oct 2020 22:16:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ELUyTpRX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731382AbgJ1WP6 (ORCPT ); Wed, 28 Oct 2020 18:15:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731371AbgJ1WP4 (ORCPT ); Wed, 28 Oct 2020 18:15:56 -0400 Received: from mail-il1-x141.google.com (mail-il1-x141.google.com [IPv6:2607:f8b0:4864:20::141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE5F3C0613CF; Wed, 28 Oct 2020 15:15:56 -0700 (PDT) Received: by mail-il1-x141.google.com with SMTP id v18so1102102ilg.1; Wed, 28 Oct 2020 15:15:56 -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=donn2UFyzsp8o09AnMw1yDwf0O8qrUs8C67gnMkzFZo=; b=ELUyTpRX5cW/picKo2/7a2EtmOuSOwFPG8ebEecIw1uNEDer6Oxk3kZt1WqqVa07bD 0ImQsjHIsBh4abYwpQ3sdH8pmeSDhxRcoT86o6RsEK/RKCtmW2+MUZxuz1XKfOI5cj7d gi8LKGDCJZ+xoa1z/oSGhewmc2tbmTyiIC1X6BhG2me+L6I9CIU3rCa3LkfgnluunbXG UsXOfM0sffB53/vLXwsNnsRvFvptP5KcX79onFiHyrsguWqwDnopPja3IASi4vr2FFiN XgvdDLy0KrunaDCd765qMM1kJZ/GdJELNz+5Mlpi2wBwA4iV2Yoxparl8sEnYZbsVgM1 aTpw== 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=donn2UFyzsp8o09AnMw1yDwf0O8qrUs8C67gnMkzFZo=; b=MEjfnOJwJIuJEgWvCVHIXl1NNDpMckuA/qz+Kg2bOskXDlFbtgDIJ6kF6b1/rOOhw4 mPejN1kWdwj0bORGl+/Wch/mDY0tI63bWogHhPRqt9JIWqoFAHs3k4Iw/EI3mRH13pZm ECHR3uAPZsnwfgubg2Wh+y8ZD1TJvS61ii6YEyBZ3idOGNDecSXP8DOQi6L84hZ5X32Q WUF/UK53/rIjuBHjrC4XsK/x8/WHGEF5JwlQ04lneVorgmJaxYwN4HKx1BLl7e1tRBvH 1hhvtsTmhs7OtIFaO4QmhSmnkXTWQ4q1XrIfEhi1H1qgcnkYpDfkMESra1GYZ3AsfJqD 4YFw== X-Gm-Message-State: AOAM533Xmaj8GsFGT4SLFss2qn1X3SYSIuj15696Vik5XizQpYJ8pP0R i0V33Bp4SXBHT86oDmb+Ute8FwP4BlM= X-Google-Smtp-Source: ABdhPJyr23yVrHvfodwKoqy5O6DIyu3UdTD+a8qCeNf+c00gUGG4djPtxJM9CVqvrQUAnVo9izofbA== X-Received: by 2002:a63:4e09:: with SMTP id c9mr705917pgb.128.1603910606371; Wed, 28 Oct 2020 11:43:26 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:6d80:dec8:7340:3009]) by smtp.gmail.com with ESMTPSA id y27sm309785pfr.122.2020.10.28.11.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 11:43:25 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa Cc: Xie He Subject: [PATCH net-next v3 3/4] net: hdlc_fr: Improve the initial checks when we receive an skb Date: Wed, 28 Oct 2020 11:43:09 -0700 Message-Id: <20201028184310.7017-4-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028184310.7017-1-xie.he.0141@gmail.com> References: <20201028184310.7017-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: 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 Wed Oct 28 18:43:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 311343 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 C60D6C5DF9D for ; Wed, 28 Oct 2020 21:43:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79FFF246CD for ; Wed, 28 Oct 2020 21:43:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SvAK/scd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726073AbgJ1VnG (ORCPT ); Wed, 28 Oct 2020 17:43:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726194AbgJ1Vm1 (ORCPT ); Wed, 28 Oct 2020 17:42:27 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41375C0613CF; Wed, 28 Oct 2020 14:42:26 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id bl9so520143qvb.10; Wed, 28 Oct 2020 14:42:26 -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=54O1P5r41ZqmIzJz6Cd1KDy/NA/5HzTXzjDHY93KBEk=; b=SvAK/scd9i8zmucASPPE0SJY+9hpd+wcgFjyfAITamR+ntzSOBz8f4DYp0hYKbiAR/ SHoVqPuX2KrL2kFgcFMytiTp9FlBtL/3A92g3Sph62WHLkQfIuJ9FlYBVt18lpzaTZuD X/NK38DqOWTz1bSt0ww7Hkw5hUV62lmDWRLCUs57aCdpyhkhLHFIGr82hJiy6Zt/wGyy rplDEarv7HMjExLzeGRILnBOrvnS64dupOOtDFgNlm8M7lDBIuIX6dffAj+Kyh5C2aTC chP0pJ9uAJPFQqa0xXB0mDg4tJj7JlbaB+2i70J3s/128nh/ZYE5AlNoyxcBvF1R6UZ5 qxcA== 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=54O1P5r41ZqmIzJz6Cd1KDy/NA/5HzTXzjDHY93KBEk=; b=VTDWrVjIKfxvXAcu7WyLLxH1LPbUVpVt04oButAcXsDDnatW6G8d/bRHlqjHMxKvYf cTMW6Dz/lk9KyPb7qR0vuZsSElQ1dmxtbG6lYTSED6b5ciDYOmOnm7s4UFKtUj2GGpgB AFLbsv7FtzLdD3uxR21mMCHZbF93Q78f+NmYxaowN5OqoViPWWoKE8FnnwCtq4+V9wmN 0YY6n2puAXQUfzXZbmAMFAPcEThthS7FstutF3BhxvhesgofrX0WXWyz/EkXjEgZLzfh AYXQSJVAgbWBph+I85AoYTdu5MYREs0dur4zaHpzE+pJUEtLdhTLcuD9tPjPDNT/rbHq 8w+g== X-Gm-Message-State: AOAM530lh4nGSFOS7lOPv45aGdWQgxYpaOsxKHYob3cwF3eNaRLEs3z5 Z5Bt5CkmKuRfiW1vSwxo6JHOUhkRIDw= X-Google-Smtp-Source: ABdhPJzSJJMbRYny8k6s/nXejJwvN/QxDVtFP4ttcGceGG5AHqT8JRvTSs7s/y9Wog9g3Rn5G7FQEg== X-Received: by 2002:a62:8c81:0:b029:164:3789:5478 with SMTP id m123-20020a628c810000b029016437895478mr335751pfd.44.1603910608987; Wed, 28 Oct 2020 11:43:28 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:6d80:dec8:7340:3009]) by smtp.gmail.com with ESMTPSA id y27sm309785pfr.122.2020.10.28.11.43.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 11:43:28 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Krzysztof Halasa Cc: Xie He Subject: [PATCH net-next v3 4/4] net: hdlc_fr: Add support for any Ethertype Date: Wed, 28 Oct 2020 11:43:10 -0700 Message-Id: <20201028184310.7017-5-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028184310.7017-1-xie.he.0141@gmail.com> References: <20201028184310.7017-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. Also add skb_reset_mac_header before we pass an skb (received on normal PVC devices) to upper layers. Because we don't use header_ops for normal PVC devices, we should hide the header from upper layer code in this case. Cc: Krzysztof Halasa Signed-off-by: Xie He --- drivers/net/wan/hdlc_fr.c | 76 ++++++++++++++++++++++++++------------- 1 file changed, 51 insertions(+), 25 deletions(-) diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c index 3639c2bfb141..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) { @@ -935,6 +974,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,35 +982,21 @@ 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) { - 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); - 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);