From patchwork Sat Oct 31 00:37:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391386 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=gdcZPv+u; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNL0Q1G3zz9sPB for ; Sat, 31 Oct 2020 11:39:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726125AbgJaAir (ORCPT ); Fri, 30 Oct 2020 20:38:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbgJaAim (ORCPT ); Fri, 30 Oct 2020 20:38:42 -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 A7424C0613D5; Fri, 30 Oct 2020 17:38:42 -0700 (PDT) Received: by mail-pf1-x442.google.com with SMTP id 133so6694970pfx.11; Fri, 30 Oct 2020 17:38:42 -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=cjMCdG09ajCIeGjE6JAeqeJcdXO8wcIf1ld4hrAVODI=; b=gdcZPv+uFueEpQohSYWQNByAbTVm0ck9UEzSpmQcVx4O0KQ+T9Gbwn0BLk/ND2FE8B p5dwfYA1cYB23UMXc159mY9JV3ZUJr/q2UkDMsm1nof+lb3VyPNQGG5IC5Ny8e0nkVNy RQyUCJwzsGUYEZGXzfBLxYX4L2evdpZZN77+wWE1xMdG6BUQh8oa8j8fHB8cWTwHPSfi JE+uGngD4L5peDj3KjJWlmruww1hPpmdwg9E/4sHg5S3fDCl99wZ6M6E1SFzqmxmtAfD WE9ok7MPjHOZZbQE41v3XjqOHWvOsNeIdxqBcphPk5YFz3MOD44+gpRCfTKkDPhQSbJv 39Mw== 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=cjMCdG09ajCIeGjE6JAeqeJcdXO8wcIf1ld4hrAVODI=; b=FrNkqgP7E+h81z6XAT+jNgJCCPWOzAQMLnm55PoGse1tjPe2xLtlqOZK1SBjioPCsP eb8UHvn1zuxXy3vrKu3yNntlupGwEQMQMEuhVK1UbfwvjnO9R3dMghq9QYRloUxVhwY/ HhJgzSXr3IFKW3ijjPlf9eJhk0A9RE1ntcWNskfdm340uInLUNoe91gSs9H/Ux1Hthw1 A3sfq+T4FxKolv670WT9fUC5tzhQvddHyDz4QRMoA1sJNZ/wHdXZdJZ3QUiDjP99SsMr 6ExqvCi20sHtOEvIdoF3/oguuEoMtxwdhKHoaq0cy4GTUXY66+AGKNa9D/FxT8PmkNJC Mczw== X-Gm-Message-State: AOAM530kkm7+1J+rWyZLsJW/OF1JCeGF7MWX0HSD0+0plJvYCTuyvMVp Ide0UVzMdBTsY6zOF1jIP0g= X-Google-Smtp-Source: ABdhPJwzIshB5hKVZrESSfs4Ybl92hgrCXUjqrqkeN7akwhaDH5GYqGmyeW+Tj1h83hdetXiqMvZUg== X-Received: by 2002:a63:e642:: with SMTP id p2mr4231347pgj.79.1604104722318; Fri, 30 Oct 2020 17:38:42 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:48fd:1408:262f:a64b]) by smtp.gmail.com with ESMTPSA id ch21sm4596888pjb.24.2020.10.30.17.38.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:38:41 -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 v5 1/5] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames Date: Fri, 30 Oct 2020 17:37:27 -0700 Message-Id: <20201031003731.461437-2-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031003731.461437-1-xie.he.0141@gmail.com> References: <20201031003731.461437-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. Cc: Willem de Bruijn Cc: Krzysztof Halasa 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 00:37:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391385 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=lPoWcfM3; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNL0D2R9Gz9sPB for ; Sat, 31 Oct 2020 11:39:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726187AbgJaAiu (ORCPT ); Fri, 30 Oct 2020 20:38:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725768AbgJaAis (ORCPT ); Fri, 30 Oct 2020 20:38:48 -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 C85A7C0613D5; Fri, 30 Oct 2020 17:38:44 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id e7so6677578pfn.12; Fri, 30 Oct 2020 17:38:44 -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=8h2JMek6rlGihOwl8Mu+I5wUSstGoce0/ReWhGN5UM8=; b=lPoWcfM3PQHA3MLFteK5Nm9rTGO3e+PsDLnKI55LxhPU6CpG1tlPefWuxMpHm1L6pf P6VvoUbGlH8S6RjeqTFCFfCqQ0uB2sqFJuk1GeHx0DcWa+cI6CAq/LLLPDBQLZQ+chw8 44J1cV95PQqhtQ92Kyz+aW3tkOfiVTrVZ6tcObAeFxpRd2calk5Ojuy2PxrEfpZhlpTU vuhb0lbQb6jex1d+KQnn79zf4ZxQGEMcYzQuuLjwyZxuamytaeE48l3JMoqazd8BiDTR PXO7b1UTqYiGZL81cNkgMTZlie/ByimwgEz8h7rQOjWaoDhPifMrFhuoGDnbohrGA6x8 CC/A== 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=8h2JMek6rlGihOwl8Mu+I5wUSstGoce0/ReWhGN5UM8=; b=SHiIDpp7NQAiVopYoxD8sVDYNE6fbhmthy7Jn2pGubEvBQhSBM0m99HIhdgltGpf65 l8zMMDwrU1bg/UZwjTs5lNOpQkhWuM25c7WHwTL6rg+TZ3myqA5j3yC6RzawL04aZcOH e8JBwJRLqV03bocyujrtzCoNsBn32z3OBfmj2mMX8M2eXz9tN5OHS5nqjc7NQq0oNOLt deLCAwuIiY778EknZ759z3jUyUMHXnCLoCxO39icVVQXKwMqrzFGLR8nkkRM8f2mNMca m/jYM0C3JkUU5gYg9IMRP09Ub6isso8Iwu5YiGJBjTeLxJX/JPmV2n4k0Ekn22XiibKt gQeQ== X-Gm-Message-State: AOAM531X3l9x30nOBtGsO4kwqb4MJJjW5+fU8rYiQwZyBhmB9+pLAoLb gYvBkbgfR8Cvepl5z5XdItbSMqLYQm8= X-Google-Smtp-Source: ABdhPJz93pwC9Cfj6AJbt35aEErZO9ySXAJMkaGyij1NbL7bJkZ/ltoTVJSh+BjbMXFOZqgCeReM5w== X-Received: by 2002:a63:e54a:: with SMTP id z10mr4004701pgj.297.1604104724374; Fri, 30 Oct 2020 17:38:44 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:48fd:1408:262f:a64b]) by smtp.gmail.com with ESMTPSA id ch21sm4596888pjb.24.2020.10.30.17.38.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:38:43 -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 v5 2/5] net: hdlc_fr: Change the use of "dev" in fr_rx to make the code cleaner Date: Fri, 30 Oct 2020 17:37:28 -0700 Message-Id: <20201031003731.461437-3-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031003731.461437-1-xie.he.0141@gmail.com> References: <20201031003731.461437-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 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 00:37:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391387 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=MaIkNRuD; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNL0R3Gg3z9sPB for ; Sat, 31 Oct 2020 11:39:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726279AbgJaAjR (ORCPT ); Fri, 30 Oct 2020 20:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726117AbgJaAir (ORCPT ); Fri, 30 Oct 2020 20:38:47 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B3EBCC0613D7; Fri, 30 Oct 2020 17:38:46 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id m17so144350pjz.3; Fri, 30 Oct 2020 17:38: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=JN/b5liJNkCYHBYSnEufh73PPTqkvt+38op/HGk1BXE=; b=MaIkNRuDg5P7ZUvDC1p/js4ftSjHx4hFdH9TMRAPIh+bS/umoAdpht5Qw2Mdd3jKaR 284Ytc7iwB/qAQsRKzvpbHVzel5HPjSmxlPW7YLzPeqj+kY8m253nSNJcYIesHWl7WoG gpOlUGEp5jQOmBZTWQ6zAeaCzkE6D5g1WN+DQNdE/E66YCBRtGrVTslJWRD8RdSDuayW DiGcySG/Yfn8e/x6kEl+M590ha99nqbJ/B0dWj3rsROk4j6Z0/ZLcqjSI9QLr1dFBbRM ILgiec9tcoHjLsGGcCa4HEkqph7zo35LW267H1V3OJjNQq9TcQGppeGVHXXA5H84RI/c 8jHg== 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=JN/b5liJNkCYHBYSnEufh73PPTqkvt+38op/HGk1BXE=; b=I+W9ll2ZzQSJrn32nVmD4LFTOhoM9krY/hcJNEjPtU2GrknFFm6yqw5fOcc7Xee4EN HHlvWh6zc8mBVj8zlVHzj7yTXU07C+Tk/IKYXoh3Akcwb4Ny65ZKJaoKtzAXmVC0zbPS bVCVo7ZUoqvGJIxGFLpExNPEn8T82TSNoTD7Lfvj8WZQkZbFfm1h/f80hmJ6cgMj6KOn jL79QdaCPUzkgaBCGiNWhZEVPcQ9KFj6Pv81yXeulBLWNt6669tK6Xu5cnJXIjuxcVPP 15bHtT1b+RIzh+U67vDdQQk/3QgrW9vRCXk9NOJA0KP7H8M+Ph6B7tvtbnlMXwK4JS1d ZzpQ== X-Gm-Message-State: AOAM5308D2Hf1ZCtMoAeQKg/mIX2zWrU5rIL6YzAc6p2rFQMvUSxq3b9 QwGEAM9iHr1cQMwFaXSlTGA= X-Google-Smtp-Source: ABdhPJzZmVkGgVyH17eHpMWeIi4GBYbB/v7ibwq185wF7aPSXAuj73Gu+KuWAkhILs7VWKDfB/xbCw== X-Received: by 2002:a17:902:a589:b029:d6:856a:2978 with SMTP id az9-20020a170902a589b02900d6856a2978mr11152069plb.67.1604104726319; Fri, 30 Oct 2020 17:38:46 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:48fd:1408:262f:a64b]) by smtp.gmail.com with ESMTPSA id ch21sm4596888pjb.24.2020.10.30.17.38.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:38:45 -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 , Willem de Bruijn Subject: [PATCH net-next v5 3/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices Date: Fri, 30 Oct 2020 17:37:29 -0700 Message-Id: <20201031003731.461437-4-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031003731.461437-1-xie.he.0141@gmail.com> References: <20201031003731.461437-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 Acked-by: 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 00:37:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391384 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=uALSM4m8; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNL083SG0z9sSC for ; Sat, 31 Oct 2020 11:39:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726210AbgJaAiw (ORCPT ); Fri, 30 Oct 2020 20:38:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726155AbgJaAis (ORCPT ); Fri, 30 Oct 2020 20:38:48 -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 C305FC0613D9; Fri, 30 Oct 2020 17:38:48 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id 15so6525232pgd.12; Fri, 30 Oct 2020 17:38:48 -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=fH/DoVxYj9YJGUaw9Q701340pAXyR23j//JGf26ZwbY=; b=uALSM4m8ukaREcbEZZ58kVhrRgI8oqIx2pyTa8Wl7S3dzQ7W9BkY50drxvZylHA9n/ lIEFdVY+DWMiIGDhsNWgp+CrBUjJ6ZvA7GTwKsLCimjZmDL6a1jOIVO1JvgY8fCs6zFK HpN3741jvxlXIbxjMkrCiyzosYoDY62LQZZ35AFXtsB5sev+Lu6Hqr2ao2XPMMvrGG6o QpqaIJmN2rK1ON4vdz5IPlsOYMPjpY2oVIh4c0urDUtHAACuwPyGmS2cuaj1hh5lV+YR fO71V+qszosqHb4es4oVk8JW+KqrMHBhwKi9AxfcSeoymoJm0sovW63sE9wNP0ELJj1Z Xoiw== 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=fH/DoVxYj9YJGUaw9Q701340pAXyR23j//JGf26ZwbY=; b=LFCeGKwBnX3k4lBpRjrfJGgIGrY7rCy5qNGclfLgD/quc+wfiHTc196rsw/ap+a2n/ cy/B2PnT/ZwbzmXloW++nKn2QjF/sVsG+sadw/n6nnrRz1FkCOllu8toedFI7VL3IbXH lq/I/mfQL61JLNFcNcrSPdoP8WPh+//JMo7tgiG1P6wVqSWOUVxRyqlh+LVJU7uCvObn DLSV+OWzsgtq8TbTPY8teRHz8740J0dx5llM3Q5yG0CKBDiQ7V4iH99ZsU7HGIOKDB2q RkYYI5AbtILyr8t+8vdhdxH+kFSvRjFNqxBDSbz1k3AIyv416mFuy2dJWdf6xB+UNwfR ocZQ== X-Gm-Message-State: AOAM530CECei6aZp4wONreiwy7fwTkRSiq5U1X824M3FSaMMHqPZDnfB +sUa/jbzaMK3up/Q9LIj/6A= X-Google-Smtp-Source: ABdhPJz1gJU8qKuwm4hFM0eQusCwC9v/OnB79xWy3s6hFdIYxYylZ1xBk8Fn4V24dCIr8TZv/SdMJw== X-Received: by 2002:a63:134d:: with SMTP id 13mr4287915pgt.370.1604104728388; Fri, 30 Oct 2020 17:38:48 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:48fd:1408:262f:a64b]) by smtp.gmail.com with ESMTPSA id ch21sm4596888pjb.24.2020.10.30.17.38.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:38:47 -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 v5 4/5] net: hdlc_fr: Improve the initial checks when we receive an skb Date: Fri, 30 Oct 2020 17:37:30 -0700 Message-Id: <20201031003731.461437-5-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031003731.461437-1-xie.he.0141@gmail.com> References: <20201031003731.461437-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. If the address length is not 2 bytes, the control field and the protocol field would not be the 3rd and 4th byte as we assume. (Say if it is 3 bytes, then the control field and the protocol field would be the 4th and 5th byte instead.) 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 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 00:37:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391383 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=ke4x5VI4; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNKzz50Q2z9sPB for ; Sat, 31 Oct 2020 11:38:55 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726158AbgJaAix (ORCPT ); Fri, 30 Oct 2020 20:38:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726203AbgJaAiv (ORCPT ); Fri, 30 Oct 2020 20:38:51 -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 7CF65C0613D5; Fri, 30 Oct 2020 17:38:51 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id p21so145876pju.0; Fri, 30 Oct 2020 17:38:51 -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=w5CwQphJvfpbmXP3zNNqueP0Pdz1yc1mU4gwObshUtc=; b=ke4x5VI4T+/Zrg/OX1gA3I+Pq6rPgnyJwCJwwVNRdkcPKU1krfkAvrfpK1CFezuxFH utGcPUNHoFTHCWuV9DFTaJGZ7kzek7OTorxWM6fSLH/94VnDwGOvHpfqVp+WA4swh+mr l3IKmdGGna/vUvOpbQSqQyFDkPdI6vX2yBvvBHFqE63I2iJYtdQet82RleJ6aOMUvqd7 Rmpc5VpsYi7X4shcAbUl3GBIHrlOSk4yxIkASOjFhR0Gy9IddDrmAE8tCOUp483V9BPA qPnNAaul0Wmrw4NtNM9gUTxq+w3Na07h297jH/ewPm2vwfQqMP8zQxR992EKWgjUg9Ih I06w== 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=w5CwQphJvfpbmXP3zNNqueP0Pdz1yc1mU4gwObshUtc=; b=ZgTO1HDeM3Hj+duo6wnvksHAz2Zpx5FPpWktRdg6pueSZJNKC6SvRBFwakigltJ2Jj EoQraMigGKDa8pkziHj9B00d9f/A5Gs0JXp6z8JcwOI4hsUFnmkck85G9xwfTtG4MWVc c8Cx1ZRN18ETIoqAXdgWMOAUYOCrn+CD+y9T89KQ6UgkaCBTyI8mJYBlRkHQGHXCrHeZ c8xaO323yihnmNYAzAET36OWGrIL761SPjcTXqHFN0D3rF0SrPoMsZLle9lm+1s52Fbo elxcUpTgTyE+75dj/0LGvVL/s9BFnuW+uABtHCk6zU9EsNk3nDam3fcJBgkc1XCA4r6R xDqw== X-Gm-Message-State: AOAM531AL5zOFsNF7ILuOXsJwE0VqI85bg15U8qmYxrSyCc3j3yeRcCF GICzao//xFcYo9grCe8w1UQ= X-Google-Smtp-Source: ABdhPJwozCjap6b54P8DP2L71pEUmXXYz0dZqsOVttZVEMJk+MiHTrMeAu52PVZHREvQLLfFL6uANg== X-Received: by 2002:a17:90a:6301:: with SMTP id e1mr5890706pjj.131.1604104731116; Fri, 30 Oct 2020 17:38:51 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:48fd:1408:262f:a64b]) by smtp.gmail.com with ESMTPSA id ch21sm4596888pjb.24.2020.10.30.17.38.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:38:50 -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 , Willem de Bruijn Subject: [PATCH net-next v5 5/5] net: hdlc_fr: Add support for any Ethertype Date: Fri, 30 Oct 2020 17:37:31 -0700 Message-Id: <20201031003731.461437-6-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031003731.461437-1-xie.he.0141@gmail.com> References: <20201031003731.461437-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 Acked-by: 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);