From patchwork Wed Oct 28 13:18: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: 1389510 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=OMer9Pgu; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CM2tx3J5Tz9sTR for ; Thu, 29 Oct 2020 09:15:05 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731262AbgJ1WPB (ORCPT ); Wed, 28 Oct 2020 18:15:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731169AbgJ1WO6 (ORCPT ); Wed, 28 Oct 2020 18:14:58 -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 16679C0613CF; Wed, 28 Oct 2020 15:14:58 -0700 (PDT) Received: by mail-oi1-x243.google.com with SMTP id f7so1216033oib.4; Wed, 28 Oct 2020 15:14:58 -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=OMer9PgudM2qrnbUBtpwUrHKq3k0ysrbxREBqVzxytSi+h1XUebQZKhGd8T1a21x/7 KLLr8uJLR3LWoZqz0ohhgd6mE/aFUso3eocvUB3kuRCwnTRz8vlfgjMY0U2Pv0pCLSHw oZ2As9OT8T3o0ewzcovm0oY5SQCzimZyfF4pmrDKazKL2OCDGZ6Tpd8daQqs/8uCPxgn fSoRDIoG2v9hH0xw1lqJkPazOjaPUz/YFDUPKyGwnLXkZbfB2n8ZAc0f4MMBXGAjlLuC r0lq/VjBn2+ys+/oJ7lP6oeYcq+GdZqQxGQ8fdoDR9scy6AugICXe3a1r4r0Szfz6ZbP LIzw== 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=pAaZoG49tZNQgHobAbtXbS1EITe2yegMMncS/fZ8zSMD/1Aa6pMhFA4XezScUKPQlc T3P045Ndmfi8RUhcyzeyzxrAsrcYprWItQ98bP4bpSih30xN89mloN/Bay9o1K5AyfOB NADMnM/YaQYY0RAaE4vUMHwfuW1Fz7+wRhvrsMw/FJN/AD61wlhMRabdapz/OxRapek7 Kh5ggqxAklg1e8Ybv8cRh8cEK3uy/HcLyd4vmGKITwqKZqmsxCD5zugTOGIMGqFWkRo3 WYYB4oYBUvO/NbXZl76jgMucV/x3RG8vHkKGPej9X9KWrrrJV5bQ2rrUiF3zCP0XUd5u PfAw== X-Gm-Message-State: AOAM532lTD1nl46diOGX/1kjfYA5gj/OMzyhml6Uav9s9JlbenqPqclx M+fgHpHA9Lh9v8qkDSoPTktPLAbDpZU= X-Google-Smtp-Source: ABdhPJzcQJwRp+BDmVFqn5LbXNMh8FhmEkJagKVbZ7eeJAu5pfxzsGivllrVnXFTHF0W6gLfgteIow== X-Received: by 2002:a17:90a:ba8d:: with SMTP id t13mr6655997pjr.38.1603891181528; Wed, 28 Oct 2020 06:19:41 -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 r8sm7058032pgn.30.2020.10.28.06.19.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 06:19:40 -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 v2 1/4] net: hdlc_fr: Simpify fr_rx by using "goto rx_drop" to drop frames Date: Wed, 28 Oct 2020 06:18:04 -0700 Message-Id: <20201028131807.3371-2-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028131807.3371-1-xie.he.0141@gmail.com> References: <20201028131807.3371-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 13:18: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: 1389555 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=A1/dBuGT; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CM3Ly5xvRz9sPB for ; Thu, 29 Oct 2020 09:35:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388217AbgJ1Wfo (ORCPT ); Wed, 28 Oct 2020 18:35:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387530AbgJ1Wej (ORCPT ); Wed, 28 Oct 2020 18:34:39 -0400 Received: from mail-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30D0DC0613CF; Wed, 28 Oct 2020 15:34:39 -0700 (PDT) Received: by mail-io1-xd41.google.com with SMTP id h21so1217372iob.10; Wed, 28 Oct 2020 15:34:39 -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=9mzi0JBUWMjjpbb/aO3F5Bvz2ioWTlLDQ0MTMYGD0gk=; b=A1/dBuGTNsdbhqUwe1pmvgkSyAMym/wvYPt6+WyE1l8CC5VtgLIT4qzDJpclvl9wB7 w2KzQkFH7YNGpJR9kUbnHJUEgSTCOB8sJ7d6P9Yg2zwtPGmFYLKsRFb1Uf5hT4C0PKLR P2YeNqZLufSHfwwzc+s5esdbIVWyA85zED2VXBniTwX7KM/rdQuhRWy7yjzKwvLfxPow pdZ8diRBT109Ye7tyY8znxlEUmyAPPdpG8zmjwOFmwU/sTLnf5NyWI3Ig2icuI+ZqZpw n/7Y7ZNW/z80L2IXNp0krtsDj82SxmQleD18iRj8Ghy2STXc7JwqUC73qw3TPNP7KUph jvsg== 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=9mzi0JBUWMjjpbb/aO3F5Bvz2ioWTlLDQ0MTMYGD0gk=; b=STZMYFVqwYMXr2z8+8lg5kKicCAsshulaMpDM9kMlOPQ6WEoqRwkMZ4/qkor1SCtTS u29Msi+D7CNoSvPvfN57gUSFD9A8qDV8XNA+6LbMiNOOxQQEkmajSGdydA7oYn4HUXFB TcuJjHB2itvgWp0ZZoIX5XI8PzMueZuokEWZ6t7Gh9Q7PPnk+GXhuJfGTnGwqqhHtYXx uOwmnc4oWjx/E9+/NtevSypJMKljhn+3zMQFPKkLLQz/MXL+LWGHvghnz3kM7mvfIDVR 5lIBGFHJkEdTU6rDn4GYBLXkUCDT7LuY+3MgmJokJzWo8Z2CdTDA5at+YZy0Lhz+bRAK BT4A== X-Gm-Message-State: AOAM530Xqz5ATKIMRxG5Ac51iI7Vd+gvFDZyoLKXAQGYASVnjYWOBx3l Kfe/qLT7FkTA7m2uK9uQ8Tj4s77WGr8= X-Google-Smtp-Source: ABdhPJynfIJJQrGHTggTvKAqZJZ0Y3W3B63/F4iYZ6dbXOSsQ23wwBiQwNbG3ngRM7xzu44FjZXGPw== X-Received: by 2002:a63:6243:: with SMTP id w64mr6307831pgb.228.1603891188228; Wed, 28 Oct 2020 06:19:48 -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 r8sm7058032pgn.30.2020.10.28.06.19.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 06:19:47 -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 v2 2/4] net: hdlc_fr: Change the use of "dev" in fr_rx to make the code cleaner Date: Wed, 28 Oct 2020 06:18:05 -0700 Message-Id: <20201028131807.3371-3-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028131807.3371-1-xie.he.0141@gmail.com> References: <20201028131807.3371-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. 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 13:18:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xie He X-Patchwork-Id: 1389561 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=NqrrPl5I; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CM3Sg6J4Lz9s0b for ; Thu, 29 Oct 2020 09:40:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389095AbgJ1Wku (ORCPT ); Wed, 28 Oct 2020 18:40:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389070AbgJ1Wks (ORCPT ); Wed, 28 Oct 2020 18:40:48 -0400 Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B38E7C0613CF; Wed, 28 Oct 2020 15:40:47 -0700 (PDT) Received: by mail-pl1-x644.google.com with SMTP id b19so360360pld.0; Wed, 28 Oct 2020 15:40:47 -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=NqrrPl5IAyqECj76dMGuM5xm0RZ8Rj4wyDANCyUbxak5WfXMSUyNgEQpwgTwH0hNXA vRE5OQhTwoy+hPQUX38GvmZ/Cb31P5hS4C34PM/Xf2RgHhMQsDrKCu+08N1H76Cqxssk f1yPZFJRoS0UFf6h3tXs0cdd5IVYo/x/v84OCS/PfelbxTwxr7/EfBnO5PWt7/DXM5az O2dExDvPxJoeJilvFLa3NdqejDOGmHwweQBXGysoGMGhoGPQR2nUrIJQavjBx7BHb2H2 qvXrlEO5jvqSIqReEc4kxy8uWjtMW+nrgYUIGpxpbzjQxCZ/C1IaF5vnKSWJUvmdCAIr SaQw== 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=aQS90mTuGr9dcuWCthu/4iWt2MqneLco0mTrQRNfw2uN8nbPJbD8amdYxIAYyE+zPL LL+N06gmjfPpBjba50fXFU7hDdMqUjGPOmEmSQ0J56Gucp8R+fzeKlZ+EflEj3pykOHG /D0tKzvLuus4k6lLPALX9lx/jkUnqfWHVIePsiMNYWbgBzBoGP2RaSoBvF29kv/ojALY /0MyiyOIzgtE2pUmmzCXKAu2zQuCS5CFQ4eHcCzZw5V5fqBEANU91OUu8rfT1BC9Z57H p1rwmL4QHra1OTbUmWZ77hgyPbLVzUiFCioSft+9tOmeD6RMSuFvSlMHqgKkxnxxWTjR ls9A== X-Gm-Message-State: AOAM5322k3yn9yQMEB0kmyG10yycC3JPj0gE7jQvgXk2sb7QwGfOSG1e qmDDk5ReZEl5t2GqBXXeBvNJKPEvrTQ= X-Google-Smtp-Source: ABdhPJwwqxKGvnkuElikx8r2ZmXj4J4dw/eIAsTBCBcc5R6EwV9aBOXJh9cadR+PMdDSrN0BBfwVXw== X-Received: by 2002:a17:902:b492:b029:d4:d88c:d1a7 with SMTP id y18-20020a170902b492b02900d4d88cd1a7mr7508840plr.15.1603891193194; Wed, 28 Oct 2020 06:19:53 -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 r8sm7058032pgn.30.2020.10.28.06.19.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 06:19:52 -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 v2 3/4] net: hdlc_fr: Improve the initial check when we receive an skb Date: Wed, 28 Oct 2020 06:18:06 -0700 Message-Id: <20201028131807.3371-4-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028131807.3371-1-xie.he.0141@gmail.com> References: <20201028131807.3371-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 13:18: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: 1389559 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=XCF4m1HV; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CM3SC62YHz9sPB for ; Thu, 29 Oct 2020 09:40:27 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389023AbgJ1Wk0 (ORCPT ); Wed, 28 Oct 2020 18:40:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388993AbgJ1Wjp (ORCPT ); Wed, 28 Oct 2020 18:39:45 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7FB5C0613CF; Wed, 28 Oct 2020 15:39:45 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id o3so691986pgr.11; Wed, 28 Oct 2020 15:39:45 -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=XCF4m1HVkmRrcltQqxsijiiFPKHfs8kk0Us3sHpeOY/zbvnvF2P6UdvDNC0ufURVpr yUImZSALFkl24OnsWQ8+Jzmj7kDfw+Wb5qw79bnFenwOUEfx5u9UV1s8JOSxNIa6ye/k u3tNDsFBy7fROx8vBAv5LLDKzBjHr+S5Q7LqbNYRNfOGLkMnRnS7ertbSm5RGywo+8kS 8vHdH13sIBinxU9yhNptNDsdq+AOsCUACtk8Ix71buxhj7r2yVuL+kaSJgVUwz31tHva hjvxwmFWpmy73p7B7hhY5BYnVTscT5O5GaFE2gmHqZDBmr9ewss0Tx+vWav302UdVwnl 4+AA== 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=M8YbS7WbZRz5PxGYX23NzCP2HpT6Hu8YdYeZosKmqAcDElvNPltn64K+I1JRjVwm5b d7l4mJNVowjkcoGg3omc5HZ8LyZSdkGXbHmzD/mmN1FrC3tnUcT20ldJayOYnbMRu7tH BO8Jsw4QrNhqn0FlBAMs3K9zLJugRQGw7lHjStrevMCxZrNHvBBLK8cD3Ze4EN3KoD+f 8a6v+TBv/iealJbCLqjWA9VWqMLsAk4sTqjfa3v1Ju+gv/cZ9i9rEpxtHfUKaH5WNHXW mC4yYLNtwcbGEUvlU/tvjJ/JD2JANoRQYgklFnHA8jsL4xETLt1jiv5fzm18euM8auRu KuDg== X-Gm-Message-State: AOAM5312MZ6OrOI+cQZqKi/ymbSOt954a0Ujz/imKlyw61M4l+aWAJLm dcxsZpbm9iR9dsyB66GSCYikfQ9H8d4= X-Google-Smtp-Source: ABdhPJyBAjlVX65T+li+CFU0JXEgGicV+Sjvsba5+EbiJIIkuOAE3M/ABnYGs0iLE/3JcW97Natz/Q== X-Received: by 2002:aa7:83c9:0:b029:158:11ce:4672 with SMTP id j9-20020aa783c90000b029015811ce4672mr7279936pfn.23.1603891201731; Wed, 28 Oct 2020 06:20:01 -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 r8sm7058032pgn.30.2020.10.28.06.19.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Oct 2020 06:20: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 v2 4/4] net: hdlc_fr: Add support for any Ethertype Date: Wed, 28 Oct 2020 06:18:07 -0700 Message-Id: <20201028131807.3371-5-xie.he.0141@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201028131807.3371-1-xie.he.0141@gmail.com> References: <20201028131807.3371-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);