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 3009712C805; Tue, 30 Apr 2024 11:30:09 +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=1714476609; cv=none; b=tXLFi/jpH1zun89lmxFp6Yzlu9JdZKF1xP+U/f2nug9yhNGaPTGAshyJLv98QdkzW/VSb2nWJ0Aze78dk+5NMJFdaity/QeHtd54NTTvYfeSW/cPe90JbB2v2wjCpRuR+n+HSZoCoOLHvh5j1GXcjRtvr1qMo5NBJ/fBXlCY7gI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714476609; c=relaxed/simple; bh=fDjd2iAGdyzglUlN9QcICJGvM3XBGfV3WJa1HwCQh4U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jz5L9CkhiubGUB8k3ay1HA+nOc9dIO8xjzrs5iFFIzEQMkNAFeWorr8TrJ22eOksbdTA2K+JiP0uo+H9XMkyHRjvLfhUGMoRkngQw2g3OAvPmLvwxXvR22mKHity7JwPARO00Hq11IVoehygqjOPhyJlgWrzAReUoctUW8jYebU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=dmzhYWDJ; 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="dmzhYWDJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA9CDC4AF19; Tue, 30 Apr 2024 11:30:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1714476609; bh=fDjd2iAGdyzglUlN9QcICJGvM3XBGfV3WJa1HwCQh4U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dmzhYWDJsV8nZTUW+ZX0qc8FgUPk5SRgKtUvsXpysQl+FD637EXPO1TBefAxba3Tg hKhiYvxzC2B8fZhLuEs6Zh8V/TaTAf8HscL6eTuOOHkt5Nu6PDdwjQolEdtLIhuKDn ISuZyEfVFQEp4+kOVcodqyNp3uOU6ekEphzZfz+w= 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 6.1 084/110] ethernet: Add helper for assigning packet type when dest address does not match device address Date: Tue, 30 Apr 2024 12:40:53 +0200 Message-ID: <20240430103050.047610283@linuxfoundation.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240430103047.561802595@linuxfoundation.org> References: <20240430103047.561802595@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 6.1-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 @@ -594,6 +594,31 @@ static inline void eth_hw_addr_gen(struc } /** + * 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 @@ -164,17 +164,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