From patchwork Sat Oct 31 00:49:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391391 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=kacWA0sZ; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNLDD0Mfqz9sSG for ; Sat, 31 Oct 2020 11:49:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726107AbgJaAt2 (ORCPT ); Fri, 30 Oct 2020 20:49:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbgJaAt0 (ORCPT ); Fri, 30 Oct 2020 20:49:26 -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 BC3F7C0613D5; Fri, 30 Oct 2020 17:49:26 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id e7so6687820pfn.12; Fri, 30 Oct 2020 17:49: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=cjMCdG09ajCIeGjE6JAeqeJcdXO8wcIf1ld4hrAVODI=; b=kacWA0sZ8POUDiEBWao8MwtlPpE6rQS55B5KMXefLuvui5CLrhXgf8qwPz2gT7EvSc HSqR9aFTqlDmRPoVExgP7m0x+bxMNUq0pKGJbdkP6ARetVgDFTKsquvhloHoe2B+gkAL yCZueTyIWOLb9BP+gB77dpkDuF2gj16B0E9ZjOSWuahy3jmiMqf5/C7EenJSi4XDYIe+ oTUpMtz02Id7aSHP7tAtnGpfFy8tsxAaq77woeGhwA4YLIh0TxGM8kJPLlpYwoKVv56A wEpDbET/XvTGXavUcSO6zwtGGH/kroaewUEJIZtH7XN+k0c+e4lP/0C/hAktzrt/TCGu LvjA== 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=s8RNUWaxWUIDMBMXrFgZKZMlZY3mQdrPwZ0r2j7qlzB5HijhesH3kIILbgN7TI6JTB rw0ejOIz3gqtru+NkqH3GWcis6CTk50PC8JWEkSRO2I1xOcNRfc/RTJjx/2CCU37eOk1 mz2F2TSWyKThgUONBRRSBIbFPvR2lG0MM0InrMULez5Ip40ZBVaQz0W+RK6xbS8+E+14 JwPC8fpXBb/o8F3/burmRVE5C3TL+6zPb2nRjRl4mt3fv4Bp/qoGdJyfC5ctTKCIbBJM xfrFP27o/aUlea25KHtzp/vHrRiQJt8wpMnX+HDq4AFsh0h1uat3d863vIkuZViHfQ/X AspQ== X-Gm-Message-State: AOAM531P7lKh1y9vjTgA1yNqhers0UM07cb0BLbEUbiTLjsjXTEc5O2y YcWuPMMHh9WoXyCcF4c38nI= X-Google-Smtp-Source: ABdhPJxrVWbCTmTRWoxCktTa4fEfrM1pUb5OyFqBptFLh4a7EHskHnWBYUOEp9GoHH8Wz7wQK3Vmtw== X-Received: by 2002:aa7:9e4a:0:b029:152:54d1:bffa with SMTP id z10-20020aa79e4a0000b029015254d1bffamr11592683pfq.6.1604105366362; Fri, 30 Oct 2020 17:49:26 -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 w10sm4466634pjy.57.2020.10.30.17.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:49:25 -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 v6 1/5] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames Date: Fri, 30 Oct 2020 17:49:14 -0700 Message-Id: <20201031004918.463475-2-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031004918.463475-1-xie.he.0141@gmail.com> References: <20201031004918.463475-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:49:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391392 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=BKu1c5cI; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNLDH049Xz9sSG for ; Sat, 31 Oct 2020 11:49:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726160AbgJaAtc (ORCPT ); Fri, 30 Oct 2020 20:49:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725536AbgJaAt3 (ORCPT ); Fri, 30 Oct 2020 20:49:29 -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 B94DBC0613D5; Fri, 30 Oct 2020 17:49:29 -0700 (PDT) Received: by mail-pg1-x541.google.com with SMTP id r10so6544032pgb.10; Fri, 30 Oct 2020 17:49:29 -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=BKu1c5cIW9EuvKvwr5Y/rbF/W2POVUViwHkgxC7Eq4wZTPuR8IslzkcQZ2ngJbxRK3 V9Hds6Wb8nQXeXTdzVfz8QiFErbJVB54Io9r+nqJAKwApNcLstzNLqoS0LVfCAuLXK1j MHQEYtkYfvP152BygLQ+uDSucAv8Sl9zGSINtWQTs0sZ1ZlibE4drMnNd8wZvucfEokZ iZ/YwkLG7j5cRY4suoHK/k6EmI7shg1H7wPDI9FY3YLVhQh0JpF67K0Ms2kmZedt4CQg EJDYhvAZa/PlJMTp3tmxSlo0V5q5cxpbF50r+rr/ZGaJWmQzgcB/n05ZpY8WEU5QvG10 o1GQ== 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=Vy0mkDl49AxVHyY/Si+RPu6c8NMcoA73DRGFKLcULIwbCE+5qFgCGOP9M4Tf/2MhfT sGxcdC6gNE9ojsbbh27uMeUxp5Pb17Gn0zbqIh+MByCoBiUW0NS65eflHp7+LuIs/53c x9jDDgzBdG9RNwrE8t3XgC0FvBdiC3nSZGod00GVjOVEeJ1qxHztigujc0nTO6WdaIgX gbFMVxJXhyCM0CUUxVUw9LNTt5pbNQQ10h4BbBGLds5pBgKIrm6SIm9h0pUVmS94ejzw fx3zHOXxq+mPrAtZnqL3a4Qs3aik2T/3l/jVw132RejzlOdvV4MbMjMZhsGjeTT9lWmg Dwjg== X-Gm-Message-State: AOAM533FSPBpUdR9H2lJ/DXsG5iSfLMk+b+f1jVqgWh4GC7eWRavYnPW T51QJYt1w3lGvZZmcYKJ2mE= X-Google-Smtp-Source: ABdhPJxtM1hB9X3ucPtskYDOfBDugcsbkk8yPwdJYh9ftsBXJ4AGP+RUfmc95q2CLRpv9f4Oe/q9uw== X-Received: by 2002:a63:af4c:: with SMTP id s12mr4142660pgo.395.1604105369309; Fri, 30 Oct 2020 17:49:29 -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 w10sm4466634pjy.57.2020.10.30.17.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:49:28 -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 v6 2/5] net: hdlc_fr: Change the use of "dev" in fr_rx to make the code cleaner Date: Fri, 30 Oct 2020 17:49:15 -0700 Message-Id: <20201031004918.463475-3-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031004918.463475-1-xie.he.0141@gmail.com> References: <20201031004918.463475-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:49:16 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391394 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=JECAtufr; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNLDP4pxHz9sSG for ; Sat, 31 Oct 2020 11:49:41 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726234AbgJaAth (ORCPT ); Fri, 30 Oct 2020 20:49:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726159AbgJaAtc (ORCPT ); Fri, 30 Oct 2020 20:49:32 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37133C0613D5; Fri, 30 Oct 2020 17:49:32 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id i7so4625175pgh.6; Fri, 30 Oct 2020 17:49:32 -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=JECAtufreVaCdx9L/TIcWPLKWw4PhHbLCNcVhNZqm6f3LNten2zwoD5qw0//F1tOxd 3SJjxm9Vv9/QWYUcBuedZ05Y6WonPyBN70oF5phSbD2IqI+tYTQtnvvpSrNPTwQgNKmP Ciqz9Yaugf9qknrthU2urDmZrqBToQJt7pR/OPIlJzxtVULs3jN7aQLL1dEins16jq9I ZFPN1q2L5SksUr/yzo5qpFFytvU9kLSdR0eF5uNAu0G2zVMwQU9FmNiaoudBHUYBcfTv 35bGZw6lTA2Y7DqKLvFcKz+uEQCergT/C0Lj0lCzc5KAb9LdB6CSfMVtH/ZNJZNotq4m uWmg== 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=eQ6JyTEdYlbSDAshmH7zQPR3FJvCENy5Atkt0s+vtmhiq/mfutlkSsjsHU9MDSRlp3 608KaKtkfKGJ78ErSpNMEya9DMG1LW418odVTozpNMEou3Otcj9Qe+nVgMlaWWiFOiiw RtN0dN47spw/LMjCNfAWZBoD0/o+Joqn6yfmv5wEbX26h+4IGr1ADqiCahuOJxAnDK2r pmnPqg8zIZzpP9cUqVQRSn5+J3aN2iq64EDlIMiUARaalckQKOS0oFqVaRResSbSLWwg ZVT2Lt2Giix5+xwvgSBJHE4zpYDZk56n0UvwvVs7Kqd8OGRy8kAPAt4M7M443/tgR1iM YG+g== X-Gm-Message-State: AOAM531ha537ViiDQq3h/qtsbAuHom8Oy75bQwMEiuOz4UVOt08li0tb tNf20C2xBsOyo8mUkAtKWZI= X-Google-Smtp-Source: ABdhPJwS44rbr0Vdyyxty1C2KpckuYhFDd+jQv/Jpq53RqOzuzBLOqgwlQIui5cnBrizx8HZ6qpe9A== X-Received: by 2002:a63:cd48:: with SMTP id a8mr4045216pgj.83.1604105371879; Fri, 30 Oct 2020 17:49:31 -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 w10sm4466634pjy.57.2020.10.30.17.49.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:49:31 -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 v6 3/5] net: hdlc_fr: Do skb_reset_mac_header for skbs received on normal PVC devices Date: Fri, 30 Oct 2020 17:49:16 -0700 Message-Id: <20201031004918.463475-4-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031004918.463475-1-xie.he.0141@gmail.com> References: <20201031004918.463475-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:49:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391393 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=Uyw7yJz2; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNLDJ6sbdz9sPB for ; Sat, 31 Oct 2020 11:49:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726209AbgJaAtg (ORCPT ); Fri, 30 Oct 2020 20:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726166AbgJaAte (ORCPT ); Fri, 30 Oct 2020 20:49:34 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 767F1C0613D7; Fri, 30 Oct 2020 17:49:34 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id e7so6687922pfn.12; Fri, 30 Oct 2020 17:49: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=A5VISFliYPxBF2FZExW90UdGjgnJGxgyq60Vib8f+PE=; b=Uyw7yJz2TKpGOMI5vjaMS08xQhltlgoTS7NgEH1NX7eqFJ4k6zEZRu/R29o5XCYmfX 1n0S2yiC7SBx8mhnkBoR0QtDSK9XuGvS/rv1IL0T4GYPbYiNM/UlchfmCiICalW+ake9 4jcP6F3BNBOONzGxds/PI4RTpUqIRrLK6/IP5mFzUhsBFSdl1kORSGJkBKmUEqoZrzE5 lPs8AAAGM3AiGGV+eej6Eaf+L7Eq/VkKdnITzIXajXjr/lm1nY8fLtHS+DgWcd5vAppx yY4VNob1VVYk/qe3NOFiYO3x0uV5G2syAAny29jeeN5tsKK06AJGte4WSv+puCCNMj3p ShPg== 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=A5VISFliYPxBF2FZExW90UdGjgnJGxgyq60Vib8f+PE=; b=bzRHFayzYUtgiKvOXrZfn1syFSoUCk038CilyEDITry9T07nt5oZfmYuapTE9zJIzT Pf4cO4+DHil6Shv/MmZ1hcSHbwQl08XXeVRZuToo1l2hJxUeMRlQol1dRR9G9haYwsne nQbdhA1k1jfRs88TIv9sivqLhXuhlyr6hh65u/CmF2LFmdXgudYsgmaHo71fqZO2dNxs EiqSxe5fhA9RaOBm9AjMGP/UWiXsPGCfN1mFfwFJCd3voaVA5Xgsi9C3GOwdX/r27BbI HbGiJzsya8uKGSqVRWrRINnq+L2OO6gMFZ1JUkztphYOnEPK4SdbIsYLIuJly3X8hmT4 gUKA== X-Gm-Message-State: AOAM530G5l4SUs4weh+qRyaqA/akGq9xXIRO/PQd15N1/myTxsut8r4r ok4BT4IKMjlvd5hsWTULAJ0= X-Google-Smtp-Source: ABdhPJwkHz0sVZ6C3l26bMVu/d59I5cwiBwcKjVrP/N/uYmbqF/1OZVFUdngNi2OWf/OZxC4mwF1Og== X-Received: by 2002:a63:e642:: with SMTP id p2mr4259835pgj.79.1604105374079; Fri, 30 Oct 2020 17:49:34 -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 w10sm4466634pjy.57.2020.10.30.17.49.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:49:33 -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 v6 4/5] net: hdlc_fr: Improve the initial checks when we receive an skb Date: Fri, 30 Oct 2020 17:49:17 -0700 Message-Id: <20201031004918.463475-5-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031004918.463475-1-xie.he.0141@gmail.com> References: <20201031004918.463475-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 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 Acked-by: Willem de Bruijn --- 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:49:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1391395 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=T7hoTmna; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CNLDR0Trhz9sSG for ; Sat, 31 Oct 2020 11:49:43 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726275AbgJaAtl (ORCPT ); Fri, 30 Oct 2020 20:49:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726242AbgJaAti (ORCPT ); Fri, 30 Oct 2020 20:49:38 -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 60B8EC0613D7; Fri, 30 Oct 2020 17:49:37 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id p21so155086pju.0; Fri, 30 Oct 2020 17:49: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=w5CwQphJvfpbmXP3zNNqueP0Pdz1yc1mU4gwObshUtc=; b=T7hoTmnaB2+J+oGcp5JTKi0yawz5jXI3CG7HBxOnKl0IaG87eeaVo3OV5AB0Af8+5J Qpag1vCMWxOKNeEpS3Fr5xSI+Qda3OWaH6EkPDJsa6ia5X3p4DmDT2QerRM1F8vLUGX1 3kAMDczDi6L9EgJftfax9g/B69zWEQ61H1jac+9mI542HJJ6JY4GdXtXjyJMVnBRXeTE +XKSo6dgIXXONYfzMR5Avut8GxqTBZBH+Jzdq5r0sk2Psv7o3rYq8+ElAlKIZWMesKV/ uSkDFvrq1LXijuvPhoBbU0kQjn7TkEoyjWd03Mtt054fcwo3w5mEc9gh7aOmbgRMF0YF rzng== 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=IS0TUZbzsJBefISsUZLhIQR+HduXfITZcXX7QlrQhd4tN6vdsrp5DCT46tTUVm2xs8 x0O0utxcDUs1+G6+YZroA4cN67vqSuFW4j1SPS9XFddAr4VBPNELkSFmfHG0WqR4EqXB PGMCu3gloYzsKKUCHByc19f+lJs5BtEyRy7HwyldifWAgj2ABOvGflMv6U0akehyyDmX pMnAKnsR8W9Dh52y4pnCcbMT20BRciJQ6fyKe8Y3arUvjuV1LJ3EMoVwVDSwuJ0GJDfc Gw5DJ+AO/+Lt6VkBZvl2z6h6N4R6QAPJzb75yt/mlUieny+7SmZGHU8b1mPKBPLmuSby hvSQ== X-Gm-Message-State: AOAM531Xdz3m64NfepeUEFoBbOUCPxvcbUZJaYCeYG/4tqqbF5iOUgLb SOlgp7MMso8tcuLY6eznLdjDmLk0p3s= X-Google-Smtp-Source: ABdhPJxYlHpnKcFAxAIolOd5zvSxAvXyejMGhgnqSgM+YbOKd8jTHZrzRrgoBS/fzRO+9eLv/JjcTg== X-Received: by 2002:a17:90b:e8e:: with SMTP id fv14mr5881193pjb.94.1604105376937; Fri, 30 Oct 2020 17:49:36 -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 w10sm4466634pjy.57.2020.10.30.17.49.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 17:49:36 -0700 (PDT) From: Xie He To: Jakub Kicinski , "David S. Miller" , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Willem de Bruijn , Krzysztof Halasa Cc: Xie He , Willem de Bruijn Subject: [PATCH net-next v6 5/5] net: hdlc_fr: Add support for any Ethertype Date: Fri, 30 Oct 2020 17:49:18 -0700 Message-Id: <20201031004918.463475-6-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20201031004918.463475-1-xie.he.0141@gmail.com> References: <20201031004918.463475-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);