From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 12D038801; Tue, 30 Apr 2024 11:18:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714475938; cv=none; b=sY68QYBKjhUepAnoONE1foz2s1QwPcRQuVfeHtBjafsioAuV095Hno4SY+3ceHi6iOMV5K9CdKNVIhwnuC99wLCfAjPz4Ds181ag3M3hFaO26gQqCU0fGK7DpGDAlG3Bzco+pCRLP3tTg7CH6KJxgG/OFjJvTxbkOhXZvQ+4ZRo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714475938; c=relaxed/simple; bh=tbyno/52mSSjF5KVcH7E4qMXYV5vcupKORoP5vMzYac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Cw0kk+iGZ3pG9sYKvzM0kijcK918vscGSy7X+h+gJF0yKTxzBcjKhPV+/jp94RbCVNPwAGX5wNiNCpcqfpTHe1v+HoNNcOkQZEZ5mSAO3QoA9p/xwOjDX9ikM7Aj3EZsWDc8q8di1yoe2iabtQIFMh4NLD1Mn1PCFZr+tfPVLwk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RA7c14KM; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="RA7c14KM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 45D0EC2BBFC; Tue, 30 Apr 2024 11:18:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1714475937; bh=tbyno/52mSSjF5KVcH7E4qMXYV5vcupKORoP5vMzYac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RA7c14KMxvaaYrrt0V22sjloQOqZ0e3smU0KrzT0oGomHCenwpO+uOv3vvaQhOO32 hoLwm6L02CJ6m/LVMVNtvVgxjdZu9VKEcPFNoOW9gjsQbGv02ErOzupih8JfSrMcxJ R1aNkxWtnFNI8buwDnczmkb0dAj1TBrq3CRVoKO4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Sabrina Dubroca , Rahul Rameshbabu , Jakub Kicinski Subject: [PATCH 5.15 63/80] ethernet: Add helper for assigning packet type when dest address does not match device address Date: Tue, 30 Apr 2024 12:40:35 +0200 Message-ID: <20240430103045.278505555@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430103043.397234724@linuxfoundation.org> References: <20240430103043.397234724@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.15-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rahul Rameshbabu commit 6e159fd653d7ebf6290358e0330a0cb8a75cf73b upstream. Enable reuse of logic in eth_type_trans for determining packet type. Suggested-by: Sabrina Dubroca Cc: stable@vger.kernel.org Signed-off-by: Rahul Rameshbabu Reviewed-by: Sabrina Dubroca Link: https://lore.kernel.org/r/20240423181319.115860-3-rrameshbabu@nvidia.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- include/linux/etherdevice.h | 25 +++++++++++++++++++++++++ net/ethernet/eth.c | 12 +----------- 2 files changed, 26 insertions(+), 11 deletions(-) --- a/include/linux/etherdevice.h +++ b/include/linux/etherdevice.h @@ -543,6 +543,31 @@ static inline unsigned long compare_ethe } /** + * eth_skb_pkt_type - Assign packet type if destination address does not match + * @skb: Assigned a packet type if address does not match @dev address + * @dev: Network device used to compare packet address against + * + * If the destination MAC address of the packet does not match the network + * device address, assign an appropriate packet type. + */ +static inline void eth_skb_pkt_type(struct sk_buff *skb, + const struct net_device *dev) +{ + const struct ethhdr *eth = eth_hdr(skb); + + if (unlikely(!ether_addr_equal_64bits(eth->h_dest, dev->dev_addr))) { + if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) { + if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast)) + skb->pkt_type = PACKET_BROADCAST; + else + skb->pkt_type = PACKET_MULTICAST; + } else { + skb->pkt_type = PACKET_OTHERHOST; + } + } +} + +/** * eth_skb_pad - Pad buffer to mininum number of octets for Ethernet frame * @skb: Buffer to pad * --- a/net/ethernet/eth.c +++ b/net/ethernet/eth.c @@ -163,17 +163,7 @@ __be16 eth_type_trans(struct sk_buff *sk eth = (struct ethhdr *)skb->data; skb_pull_inline(skb, ETH_HLEN); - if (unlikely(!ether_addr_equal_64bits(eth->h_dest, - dev->dev_addr))) { - if (unlikely(is_multicast_ether_addr_64bits(eth->h_dest))) { - if (ether_addr_equal_64bits(eth->h_dest, dev->broadcast)) - skb->pkt_type = PACKET_BROADCAST; - else - skb->pkt_type = PACKET_MULTICAST; - } else { - skb->pkt_type = PACKET_OTHERHOST; - } - } + eth_skb_pkt_type(skb, dev); /* * Some variants of DSA tagging don't have an ethertype field