From patchwork Wed Oct 28 10:57:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 316130 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 C06B3C4363A for ; Wed, 28 Oct 2020 22:50:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65F2B20732 for ; Wed, 28 Oct 2020 22:50:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PKxE3xP/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389531AbgJ1WuF (ORCPT ); Wed, 28 Oct 2020 18:50:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389459AbgJ1WtQ (ORCPT ); Wed, 28 Oct 2020 18:49:16 -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 66FABC0613CF; Wed, 28 Oct 2020 15:49:16 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id h6so734269pgk.4; Wed, 28 Oct 2020 15:49:16 -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=PKxE3xP/JzhxCXC9xc9VcOMaEeH41Fp1vAVLYXvbr/UcZa6AvEhiC5PrvPmfb4oSPu YFq64YKVHoZewsVowHUwvsLgYA9ILCEmkB/iN5uKHtzrO2YUjkH7RzyiZPxxc0mxhePV jv1dpbV+8fujEh5BKZPbed279Rx1IRsLNZdSqk5h1YiL0oYeMfT5CL/aronCy8OllAAD VttxFU4i+Mh+wKMUK6VOr8UR7Ias1+dyWicGygRqurCePrCLIvcTHXraF22KEju5t6W0 fIAsXJ9l9oKdJ+yhWhfhjK9Tg07iNeAGj3NW9hNnMdSsWSO/R7OQnhxaCymC5yfoaagl 41Lg== 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=XmE+6htB6VkfTPTdMCPzQWk8PkTu10LWKrk7LXW+IMemuOEIdpHpUqatswV62UAu1+ nBXPMqWEDbhXxYpGfPnxgmr3yN0qokF709n8MQrjLP2wz7O5EMdnjxaILQL/NYDIFw1I Y7Qb7np+p1C2yPAdDN5TWjg0/DSt6WBias6nJkzg3qUUILf3PGl2pXRpjTLNEsIQN3vd 5JiBhK4W/cpV71MpEBp0NsOWakMqAa6XUBXck7187zB1zdrSDGfzXoL0Fjq93t+5cqsG vcQ0Kg5CmkjA2cAU7ifL5iqya273OvkmSg2B1v4+S+hNuoKGqj0psQA/nDYn5Vw/R8L+ FbOA== X-Gm-Message-State: AOAM531KPPJqmexK9+HkIt/jk2W8ehytFrBOjBFpHFRtZwBWKZJDp50z 0hCF7m2HOfZlULT/nDBSXI2ny3e5QUM= X-Google-Smtp-Source: ABdhPJzR/50Cvki4QOdiAEIFpTQPSl3W+0IduE+iI0wuY7/YptCUkm0sFcZnU/njVHopJ6z9v/eAgw== X-Received: by 2002:a17:902:9695:b029:d3:8b4f:558c with SMTP id n21-20020a1709029695b02900d38b4f558cmr6797176plp.27.1603882670711; Wed, 28 Oct 2020 03:57:50 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:a46c:8b86:395a:7a3d]) by smtp.gmail.com with ESMTPSA id 65sm557863pge.37.2020.10.28.03.57.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 03:57:50 -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 1/4] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames Date: Wed, 28 Oct 2020 03:57:02 -0700 Message-Id: <20201028105705.460551-2-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028105705.460551-1-xie.he.0141@gmail.com> References: <20201028105705.460551-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 10:57:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 311310 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 C9F50C4363A for ; Wed, 28 Oct 2020 22:55:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D9A320732 for ; Wed, 28 Oct 2020 22:55:06 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E3cy/fT0" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389745AbgJ1Wyw (ORCPT ); Wed, 28 Oct 2020 18:54:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388439AbgJ1Wyf (ORCPT ); Wed, 28 Oct 2020 18:54:35 -0400 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A76B6C0613CF; Wed, 28 Oct 2020 15:54:34 -0700 (PDT) Received: by mail-oi1-x244.google.com with SMTP id z23so1326835oic.1; Wed, 28 Oct 2020 15:54:34 -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=UEQBkEXiJOfBE5LzS0jxlJBj5IlPjaXUmPkuEF50Xpo=; b=E3cy/fT07MNJXvIqKs8Ay+Od40l7u8VQgFHMmrPTYIcEtp91rFYrJRtfCN5Yi9pQ7q lAtrmR6EKuawCWn84aNM9AKjn6apJcLp0iEJIM7Ttjj0sIKdbVi3u/xn7qAKb8C1A7h6 OawNqGyneFTjh/XxH5iIR4Awd/W4HCEU3L9LlLOO9WyUYerQqlLriqDn7MCj9HAKayXV t8vYy8CPHfeNYDW5NcHH/3nC0Sg+eruF5qO6R8trzqeXzskpbgMgtLl2yvYS2Nv7h761 zVD1IIOTWUzxW9t/NEkuM8rT2KYmppvgFxJxwH2Lmm6S3KrAsnLcltyt50eGFLYjcEn1 mXyg== 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=UEQBkEXiJOfBE5LzS0jxlJBj5IlPjaXUmPkuEF50Xpo=; b=U49ryd3OBmaQLmnxsU8yuNdjsBhL25hh0hhmkW1LjeWRETdOEjlIY+nCq3IBIP0Al3 lA1d89dkncvx5/KncjcEFqYEqs+246yJdLvacCi1YLm3YUFba5gZm+OsynhwsAatQBzx 7N0SeMR/gFvUAHVpY6V3mgXIqNPyjxC3aWokYR2DlHWKS+G8Q/VQQqBh3pebWb/Sk1J2 1wx+74OGnHZNfElEmO3PBFQUqBrURhynydGzWFeMgt9zxzVpI3JxKa6kZwZfnJw2Wvyp WVmSwwQne8yoUohdADBXnyt5zV8wfK6ZXKZT45THpiGmM6evLE6I8DW1jii/p1WEVxOi b+6g== X-Gm-Message-State: AOAM531L4Js5CzTHy08H9sXQVUSMIkaZWcYKjGW2o4QFL3M3WvW+OV48 GBDEfxO1p9+AhANyaf2SN7B7C8JpHsU= X-Google-Smtp-Source: ABdhPJwZHZX2/Z3qoeSvLZlJdb/IZ4Y4uUPQVCXbUpXEyHQTg3krOYoj3p5ikKw2CzqOuXw9wKn67Q== X-Received: by 2002:a17:90b:17c4:: with SMTP id me4mr6438096pjb.120.1603882676309; Wed, 28 Oct 2020 03:57:56 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:a46c:8b86:395a:7a3d]) by smtp.gmail.com with ESMTPSA id 65sm557863pge.37.2020.10.28.03.57.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 03:57:55 -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 2/4] net: hdlc_fr: Change the use of "dev" in fr_fx to make the code cleaner Date: Wed, 28 Oct 2020 03:57:03 -0700 Message-Id: <20201028105705.460551-3-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028105705.460551-1-xie.he.0141@gmail.com> References: <20201028105705.460551-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 a 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. Letting them co-exist 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 10:57:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 316160 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 392D5C388F7 for ; Wed, 28 Oct 2020 21:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CCE522245A for ; Wed, 28 Oct 2020 21:51:09 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FZESs+U1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728145AbgJ1VvI (ORCPT ); Wed, 28 Oct 2020 17:51:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728124AbgJ1VvE (ORCPT ); Wed, 28 Oct 2020 17:51:04 -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 9E1ACC0613CF; Wed, 28 Oct 2020 14:51:04 -0700 (PDT) Received: by mail-vs1-xe43.google.com with SMTP id b3so401080vsc.5; Wed, 28 Oct 2020 14:51:04 -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=ZgaymEmZcwxxsKVYh/F35SxRK5AS1vNWLJ9SX/my/Ac=; b=FZESs+U1d6sdbxRLH0jg9AXZ+yso0T3lAdUEm1/pGjJykilNBfVc1W462V4HFS4uuV uevITlOOCBo+e2d7Lb21N0rQ1BJ6T6twTtQryZCXGsHxJKEoQbUu/vCy5+6unnqla5e/ m8sXJ7mKMhjYrX5js/6FQjfsqbIQ74xUVtipNBoILMcI1vQuyqOki9lHZ+fJ6hJpGP0M au7JZxLu2+Dh/QKiB6fx6KWpOxAdXwkXC8CbzGg1f2hgwhHWuOlwDaBXBrCE0dAIiNwg KggqBUn56qDexBDgJ5tskpakEnAdEzvwK/koeblf/9yW8uU2o2ggvdTuqo/oFQSfI55k KXQA== 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=ZgaymEmZcwxxsKVYh/F35SxRK5AS1vNWLJ9SX/my/Ac=; b=niRhlNm3eNGOaA3KxPt1MkpviCKnCwIP9/TZj/LTIUrxB80TK4sBdZ53fGv8lTGGck LkKkMhAml6C3U46vT/t9d+DAFbmvW3q1syu0vLBvznfh58fmRK2oWt9f7WE9W8s8pEvB pwGBwBCiUhcS7Hs4mkkDj8plebB/JGVImGhYalSYpqnjTDLVPAbjGcX8QILcIEyxi69G /7+v0QhDcrEzYxCRSv6V0I3gBH8O8tCa1XKV7jW/TIoU2z88tr+n/O/+nYgcRwcGDQWS vJPXrgitOf+x3JKQtdLR1wxVz8upCnS++bDpwjFzOF4mtWf4aNuw956e+Z0gwUHrAbEB M1sw== X-Gm-Message-State: AOAM531DoUrwd1hEEFrIpXcZPCt5GApOfirR4EpwSgW8TTQm820jNLbW 3P1QVpUL5fu2xAUyDVPjrAOzQYrxKY4= X-Google-Smtp-Source: ABdhPJxVKLbcv9Q4AuWMalLmnvAx18i9bzgMyTiuxqf0aFwQWWPSRHhIU3ufIjJEJ5oVHG3F49TDMQ== X-Received: by 2002:a62:878f:0:b029:155:ec80:9658 with SMTP id i137-20020a62878f0000b0290155ec809658mr6745127pfe.57.1603882682137; Wed, 28 Oct 2020 03:58:02 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:a46c:8b86:395a:7a3d]) by smtp.gmail.com with ESMTPSA id 65sm557863pge.37.2020.10.28.03.58.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 03:58:01 -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 3/4] net: hdlc_fr: Improve the initial check when we receive an skb Date: Wed, 28 Oct 2020 03:57:04 -0700 Message-Id: <20201028105705.460551-4-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028105705.460551-1-xie.he.0141@gmail.com> References: <20201028105705.460551-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_fx. 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 10:57:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 311324 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 63879C55179 for ; Wed, 28 Oct 2020 22:16:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0588E2475F for ; Wed, 28 Oct 2020 22:16:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N8I4ct81" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731423AbgJ1WQf (ORCPT ); Wed, 28 Oct 2020 18:16:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731409AbgJ1WQe (ORCPT ); Wed, 28 Oct 2020 18:16:34 -0400 Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [IPv6:2607:f8b0:4864:20::a36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA3F0C0613CF; Wed, 28 Oct 2020 15:16:33 -0700 (PDT) Received: by mail-vk1-xa36.google.com with SMTP id k125so268039vka.11; Wed, 28 Oct 2020 15:16: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=54O1P5r41ZqmIzJz6Cd1KDy/NA/5HzTXzjDHY93KBEk=; b=N8I4ct81omE1XtvRZHjctZAkol6O9k13TNi4ukv2kfCe3GkrWMDRu4nuV/oXSDY6L9 Gk0kT1QBCTpYowC5p1vkhoSpgu2lWLhDr0J/JYMEu1umas6BnnQhbs0+prRmiy5ApMRW 3L5mDkMivj5G1WWMZWG1uZFfbFN8Trr4JoIJRZPgIOwu//nqC/6KZLios4JAH1JKL7SG 2nnkW7NFC5SCL+WxnKIOkjnMmXC4ourZTYpfuTNScdwUz93UZBwJyvpGnzV8ROUkDQYY D6aD4ZLaWqddB9c8dAmzS3v3ncbPQPJ22Q0Mas5SuRD1VhddowHfLKVzBvPpdo+z1GsG U1Iw== 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=DAbFBblQWohDnfB0IOl6POm0jxaxozB9TQBoYXokxPp7JWDjSbcHka2BQ3CTf4umzv 8LQogv75c/+enftCE5Zo6vjLvpBJN5YU85bjNtBRIWP+vKCxcHHK3S6u2LyCwq8S9JBL tm9B3XgDbwh0AcyOZLRVnE7SMFQUtb5bBIxJYkUyM/bpK3sj89VmeG+baa/++9yPrsQM a6x7Iyr54ja2UTbTqQdbNMQ7G4T2RotcP8xD8RIDi1Z0niQomUYHQylLM8nVs3whDcmu s6qoS2sOYqYnZ7X0aAaPiinal1SbmWIAlGGjYnGxHpyJKc4ReOjzOBEK+n1qopquQSSA FyfQ== X-Gm-Message-State: AOAM533JnGTQdOyIjmDcEd4vrPenL88vJVyIL18IB//W1vA1C1dVLhVA MZJDMon/xbCjvRNJkgCysPAkNmgb3T4= X-Google-Smtp-Source: ABdhPJy6nbU25F3kPXbCO+raQW+HdqwjR+pRwlQ/qztyo1tdyaT7BxFbdKO3SuH8xC+6oYKxf8tleA== X-Received: by 2002:aa7:80c9:0:b029:164:4ca1:fff with SMTP id a9-20020aa780c90000b02901644ca10fffmr5383299pfn.11.1603882688819; Wed, 28 Oct 2020 03:58:08 -0700 (PDT) Received: from shane-XPS-13-9380.hsd1.ca.comcast.net ([2601:646:8800:1c00:a46c:8b86:395a:7a3d]) by smtp.gmail.com with ESMTPSA id 65sm557863pge.37.2020.10.28.03.58.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 03:58:08 -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 4/4] net: hdlc_fr: Add support for any Ethertype Date: Wed, 28 Oct 2020 03:57:05 -0700 Message-Id: <20201028105705.460551-5-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028105705.460551-1-xie.he.0141@gmail.com> References: <20201028105705.460551-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);