Skip to contentSkip to conversation

net: remove dev_validate_header() and net_device::min_header_len

PATCH In review Willem de Bruijn 2 participants 8 messages Nov 24

Subsystems (5)
lore
Share & tools
lore

Willem de Bruijn

author maintainer
#0 lore raw

cover net: remove dev_validate_header() and net_device::min_header_len

From: Willem de Bruijn <[email protected]>

Remove unused link-layer header validation plumbing, clean up the remaining af_packet users, and drop net_device::min_header_len.

Mostly cleanup, with two user-visible changes:

- Patch 4: on devices that set hard_header_len but have no link layer header (e.g., PPP), SOCK_RAW and TX_RING sends now always have skb->network_header at the start of the packet, not only for short packets.
- Patch 5: on SOCK_DGRAM, the VLAN TCI of non-offloaded tags is now reported on all Ethernet devices, including those with hard_header_len > ETH_HLEN, and is 0 on non-Ethernet devices.

1. Drop stale Ethernet fields (including min_header_len) in IPA modem.
2. Remove header_ops->validate and dev_validate_header().
3. Move af_packet TX header length checks ahead of skb allocation.
4. Reset network header on all headerless devices via dev_has_header().
5. Use ARPHRD_ETHER / ARPHRD_LOOPBACK and ETH_HLEN in vlan_get_tci().
6. Remove unused net_device::min_header_len.

Testing (under vng):
- tools/testing/selftests/net: psock_snd.sh, psock_tpacket, and txring_overwrite.
- Custom tests for short/zero header validation (SOCK_RAW, SOCK_DGRAM, SOCK_PACKET, TX_RING), non-offloaded outgoing VLAN TCI capture (AUXDATA, TPACKET_V2, TPACKET_V3), and 48B/100B IPv6 TX over sit (SOCK_RAW, SOCK_PACKET, TX_RING).

Willem de Bruijn (6):
net: ipa: remove ethernet-specific artifacts from modem netdev setup
net: remove header_ops->validate and dev_validate_header()
packet: validate TX header length before skb allocation
packet: reset network header on all headerless devices
packet: use Ethernet header length in vlan_get_tci()
net: remove unused net_device::min_header_len

 .../networking/net_cachelines/net_device.rst  |  1 -
 drivers/net/ipa/ipa_modem.c                   |  4 -
 drivers/net/loopback.c                        |  1 -
 include/linux/netdevice.h                     | 18 -----
 net/ethernet/eth.c                            |  1 -
 net/packet/af_packet.c                        | 80 ++++++++-----------
 6 files changed, 32 insertions(+), 73 deletions(-)
Signature · 1 line
2.56.1.839.g22a8290db9-goog
author maintainer
#1 lore raw

PATCH 1/6 net: ipa: remove ethernet-specific artifacts from modem netdev setup

From: Willem de Bruijn <[email protected]>

Commit 75944b040bbc ("net: ipa: open-code ether_setup()") open-coded ether_setup(), including fields that do not apply to this headerless ARPHRD_RAWIP device:

- min_header_len = ETH_HLEN, while hard_header_len is 0
- an Ethernet broadcast address, while addr_len is 0
- clearing IFF_BROADCAST | IFF_MULTICAST, which are never set

Remove these and the now unused etherdevice.h include.

With min_header_len left at 0, the device behaves like other headerless devices (such as tun and rmnet) in af_packet's vlan_get_tci(), where min_header_len == hard_header_len instead of returning early on the mismatch. Normal IPA traffic uses ETH_P_MAP rather than a VLAN ethertype, so it is unaffected.

---
 drivers/net/ipa/ipa_modem.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/net/ipa/ipa_modem.c +0 -4
index d84c1dbd3b1a..e8392d9d3a4f 100644
@@ -5,7 +5,6 @@
  */
 
 #include <linux/errno.h>
-#include <linux/etherdevice.h>
 #include <linux/if_arp.h>
 #include <linux/if_rmnet.h>
 #include <linux/netdevice.h>
@@ -223,15 +222,12 @@ static void ipa_modem_netdev_setup(struct net_device *netdev)
 	netdev->header_ops = NULL;
 	netdev->type = ARPHRD_RAWIP;
 	netdev->hard_header_len = 0;
-	netdev->min_header_len = ETH_HLEN;
 	netdev->min_mtu = ETH_MIN_MTU;
 	netdev->max_mtu = IPA_MTU;
 	netdev->mtu = netdev->max_mtu;
 	netdev->addr_len = 0;
 	netdev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
-	netdev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
 	netdev->priv_flags |= IFF_TX_SKB_SHARING;
-	eth_broadcast_addr(netdev->broadcast);
 
 	/* The endpoint is configured for QMAP */
 	netdev->needed_headroom = sizeof(struct rmnet_map_header);
Signature · 1 line
2.56.1.839.g22a8290db9-goog
Acked-by on v1 1/6
#2 lore raw

Re: [PATCH net-next 1/6] net: ipa: remove ethernet-specific artifacts from modem netdev setup

Quoted 12 lines · Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Commit 75944b040bbc ("net: ipa: open-code ether_setup()") open-coded ether_setup(), including fields that do not apply to this headerless ARPHRD_RAWIP device:

- min_header_len = ETH_HLEN, while hard_header_len is 0
- an Ethernet broadcast address, while addr_len is 0
- clearing IFF_BROADCAST | IFF_MULTICAST, which are never set

Remove these and the now unused etherdevice.h include.

Quoted 8 lines

With min_header_len left at 0, the device behaves like other headerless devices (such as tun and rmnet) in af_packet's vlan_get_tci(), where min_header_len == hard_header_len instead of returning early on the mismatch. Normal IPA traffic uses ETH_P_MAP rather than a VLAN ethertype, so it is unaffected.

This looks pretty reasonable to me. The "don't open-code" change was meant to avoid duplicate code. All the assignments were preserved, but I didn't fully understand how these fields were used.

For now I'll just ack this. If I manage to get my system up to test this, I'll do that and provide a Reviewed-by, but I'm not sure I'll get to that soon.

Quoted 32 lines
---
  drivers/net/ipa/ipa_modem.c | 4 ----
  1 file changed, 4 deletions(-)
drivers/net/ipa/ipa_modem.c +0 -4
index d84c1dbd3b1a..e8392d9d3a4f 100644
@@ -5,7 +5,6 @@
   */
 
  #include <linux/errno.h>
-#include <linux/etherdevice.h>
  #include <linux/if_arp.h>
  #include <linux/if_rmnet.h>
  #include <linux/netdevice.h>
@@ -223,15 +222,12 @@ static void ipa_modem_netdev_setup(struct net_device *netdev)
  	netdev->header_ops = NULL;
  	netdev->type = ARPHRD_RAWIP;
  	netdev->hard_header_len = 0;
-	netdev->min_header_len = ETH_HLEN;
  	netdev->min_mtu = ETH_MIN_MTU;
  	netdev->max_mtu = IPA_MTU;
  	netdev->mtu = netdev->max_mtu;
  	netdev->addr_len = 0;
  	netdev->tx_queue_len = DEFAULT_TX_QUEUE_LEN;
-	netdev->flags &= ~(IFF_BROADCAST | IFF_MULTICAST);
  	netdev->priv_flags |= IFF_TX_SKB_SHARING;
-	eth_broadcast_addr(netdev->broadcast);
 
  	/* The endpoint is configured for QMAP */
  	netdev->needed_headroom = sizeof(struct rmnet_map_header);
author maintainer
#3 lore raw

PATCH 2/6 net: remove header_ops->validate and dev_validate_header()

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

header_ops->validate was added in commit 2793a23aacbd ("net: validate variable length ll headers") for AX.25, its only implementation. AX.25 was removed in commit dd8d4bc28ad7 ("net: remove ax25 and amateur radio (hamradio) subsystem"), and the CAP_SYS_RAWIO bypass in dev_validate_header() was removed in commit 3b9a324e646d ("net: remove CAP_SYS_RAWIO zero-padding in dev_validate_header").

With both gone, dev_validate_header() only checks
len >= dev->hard_header_len. Remove header_ops->validate and dev_validate_header(), and replace the only callers in af_packet with direct checks against the already snapshotted hard_header_len.

---
 include/linux/netdevice.h | 16 ----------------
 net/packet/af_packet.c    |  7 +++----
 2 files changed, 3 insertions(+), 20 deletions(-)
include/linux/netdevice.h +0 -16
index 694b6d29f680..930899a7a577 100644
@@ -326,7 +326,6 @@ struct header_ops {
 	void	(*cache_update)(struct hh_cache *hh,
 				const struct net_device *dev,
 				const unsigned char *haddr);
-	bool	(*validate)(const char *ll_header, unsigned int len);
 	__be16	(*parse_protocol)(const struct sk_buff *skb);
 };
 
@@ -3587,21 +3586,6 @@ static inline __be16 dev_parse_header_protocol(const struct sk_buff *skb)
 	return dev->header_ops->parse_protocol(skb);
 }
 
-/* ll_header must have at least hard_header_len allocated */
-static inline bool dev_validate_header(const struct net_device *dev,
-				       char *ll_header, int len)
-{
-	if (likely(len >= dev->hard_header_len))
-		return true;
-	if (len < dev->min_header_len)
-		return false;
-
-	if (dev->header_ops && dev->header_ops->validate)
-		return dev->header_ops->validate(ll_header, len);
-
-	return false;
-}
-
 static inline bool dev_has_header(const struct net_device *dev)
 {
 	return dev->header_ops && dev->header_ops->create;
net/packet/af_packet.c +3 -4
index 96c5216a9d6b..230b16742346 100644
@@ -2060,7 +2060,7 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
 		goto retry;
 	}
 
-	if (!dev_validate_header(dev, skb->data, len) || !skb->len) {
+	if (len < hard_header_len || !skb->len) {
 		err = -EINVAL;
 		goto out_unlock;
 	}
@@ -2644,7 +2644,7 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 		err = skb_store_bits(skb, 0, data, hdrlen);
 		if (unlikely(err))
 			return err;
-		if (!dev_validate_header(dev, skb->data, hdrlen))
+		if (hdrlen < hard_header_len)
 			return -EINVAL;
 
 		data += hdrlen;
@@ -3115,8 +3115,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 	if (err)
 		goto out_free;
 
-	if ((sock->type == SOCK_RAW &&
-	     !dev_validate_header(dev, skb->data, len)) || !skb->len) {
+	if ((sock->type == SOCK_RAW && len < hard_header_len) || !skb->len) {
 		err = -EINVAL;
 		goto out_free;
 	}
Signature · 1 line
2.56.1.839.g22a8290db9-goog
author maintainer
#4 lore raw

PATCH 3/6 packet: validate TX header length before skb allocation

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Now that dev_validate_header() is gone, TX header validation only compares length against hard_header_len and no longer needs the copied link layer header.

Simplify packet_sendmsg_spkt(), tpacket_snd(), and packet_snd() by validating against the snapshotted hard_header_len before skb allocation and copy. This removes the now unreachable len < hhlen network header reset in packet_sendmsg_spkt() and, since __packet_snd_vnet_parse() already enforces vnet_hdr.hdr_len <= tp_len, the redundant hdrlen clamp in tpacket_fill_skb().

A too short packet now fails with -EINVAL before, rather than after, allocation and copy errors (e.g., -ENOBUFS, -EAGAIN, -EFAULT).

---
 net/packet/af_packet.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)
net/packet/af_packet.c +19 -15
index 230b16742346..e8326cade94a 100644
@@ -2024,8 +2024,13 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
 	}
 
 	/* Keep the allocation-time header length across retry. */
-	if (!skb)
+	if (!skb) {
 		hard_header_len = READ_ONCE(dev->hard_header_len);
+		if (len < hard_header_len || !len) {
+			err = -EINVAL;
+			goto out_unlock;
+		}
+	}
 
 	err = -EMSGSIZE;
 	if (len > dev->mtu + hard_header_len + VLAN_HLEN + extra_len)
@@ -2051,8 +2056,6 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
 		if (hhlen) {
 			skb->data -= hhlen;
 			skb->tail -= hhlen;
-			if (len < hhlen)
-				skb_reset_network_header(skb);
 		}
 		err = memcpy_from_msg(skb_put(skb, len), msg, len);
 		if (err)
@@ -2060,10 +2063,6 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
 		goto retry;
 	}
 
-	if (len < hard_header_len || !skb->len) {
-		err = -EINVAL;
-		goto out_unlock;
-	}
 	if (len > (dev->mtu + hard_header_len + extra_len) &&
 	    !packet_extra_vlan_len_allowed(dev, skb)) {
 		err = -EMSGSIZE;
@@ -2637,18 +2636,14 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 		if (unlikely(err < 0))
 			return -EINVAL;
 	} else if (copylen) {
-		int hdrlen = min_t(int, copylen, tp_len);
-
 		skb_push(skb, hard_header_len);
 		skb_put(skb, copylen - hard_header_len);
-		err = skb_store_bits(skb, 0, data, hdrlen);
+		err = skb_store_bits(skb, 0, data, copylen);
 		if (unlikely(err))
 			return err;
-		if (hdrlen < hard_header_len)
-			return -EINVAL;
 
-		data += hdrlen;
-		to_write -= hdrlen;
+		data += copylen;
+		to_write -= copylen;
 	}
 
 	offset = offset_in_page(data);
@@ -2878,6 +2873,10 @@ static int tpacket_snd(struct packet_sock *po, struct msghdr *msg)
 						    vnet_hdr.hdr_len);
 			has_vnet_hdr = true;
 		}
+		if (unlikely(tp_len < reserve)) {
+			tp_len = -EINVAL;
+			goto tpacket_error;
+		}
 		/* Prevent the byte count from wrapping into a negative errno */
 		if (unlikely(tp_len > INT_MAX - len_sum))
 			break;
@@ -3086,6 +3085,11 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 	    (len > dev->mtu + reserve + VLAN_HLEN + extra_len))
 		goto out_unlock;
 
+	if (unlikely(len < reserve)) {
+		err = -EINVAL;
+		goto out_unlock;
+	}
+
 	err = -ENOBUFS;
 	hlen = LL_RESERVED_SPACE_EX(dev, hard_header_len);
 	tlen = dev->needed_tailroom;
@@ -3115,7 +3119,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 	if (err)
 		goto out_free;
 
-	if ((sock->type == SOCK_RAW && len < hard_header_len) || !skb->len) {
+	if (unlikely(!skb->len)) {
 		err = -EINVAL;
 		goto out_free;
 	}
Signature · 1 line
2.56.1.839.g22a8290db9-goog
author maintainer
#5 lore raw

PATCH 4/6 packet: reset network header on all headerless devices

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

Some devices without a userspace-visible link layer header (!dev_has_header()) still set hard_header_len > 0 instead of needed_headroom to reserve space for headers they prepend internally in ndo_start_xmit() (e.g., PPP, mctp-usb, routed br2684, and previously sit). On SOCK_RAW sends, af_packet reserves hard_header_len and leaves skb->network_header pointing that many bytes into the L3 header.

Commit 88a8121dc1d3 ("af_packet: fix raw sockets over 6in4 tunnel") added a workaround in packet_snd(), explicitly noting in its commit message that it was temporary and left to be cleaned up in net-next. That heuristic misses longer packets and misfires on non-Ethernet devices with a link layer header where min_header_len is 0.

Replace it with !dev_has_header(dev) in packet_snd() and apply the same in tpacket_fill_skb().

For consistency, also switch packet_sendmsg_spkt() from dev->header_ops to dev_has_header(dev). This has no effect today: the only header_ops without ->create is ip_tunnel_header_ops, and all devices using it have hard_header_len 0.

---
 net/packet/af_packet.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
net/packet/af_packet.c +4 -3
index e8326cade94a..bf0ad6d5c1e3 100644
@@ -2039,7 +2039,7 @@ static int packet_sendmsg_spkt(struct socket *sock, struct msghdr *msg,
 	if (!skb) {
 		size_t reserved = LL_RESERVED_SPACE_EX(dev, hard_header_len);
 		int tlen = dev->needed_tailroom;
-		unsigned int hhlen = dev->header_ops ? hard_header_len : 0;
+		unsigned int hhlen = dev_has_header(dev) ? hard_header_len : 0;
 
 		rcu_read_unlock();
 		skb = sock_wmalloc(sk, len + reserved + tlen, 0, GFP_KERNEL);
@@ -2638,6 +2638,8 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 	} else if (copylen) {
 		skb_push(skb, hard_header_len);
 		skb_put(skb, copylen - hard_header_len);
+		if (!dev_has_header(dev))
+			skb_reset_network_header(skb);
 		err = skb_store_bits(skb, 0, data, copylen);
 		if (unlikely(err))
 			return err;
@@ -3109,8 +3111,7 @@ static int packet_snd(struct socket *sock, struct msghdr *msg, size_t len)
 			goto out_free;
 	} else if (reserve) {
 		skb_reserve(skb, -reserve);
-		if (len < reserve + sizeof(struct ipv6hdr) &&
-		    dev->min_header_len != hard_header_len)
+		if (!dev_has_header(dev))
 			skb_reset_network_header(skb);
 	}
 
Signature · 1 line
2.56.1.839.g22a8290db9-goog
author maintainer
#6 lore raw

PATCH 5/6 packet: use Ethernet header length in vlan_get_tci()

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

vlan_get_tci() uses dev->min_header_len to locate the outer 802.1Q/AD header on SOCK_DGRAM captures, with an is_vlan_dev() fallback that has been obsolete since commit 447cbe95ebb9 ("vlan: fix skb_under_panic and races when toggling HW VLAN offload") stopped adding VLAN_HLEN to vlandev->hard_header_len.

Only Ethernet and loopback devices set min_header_len (to ETH_HLEN). Check ARPHRD_ETHER / ARPHRD_LOOPBACK and read at ETH_HLEN directly instead, removing the last min_header_len reader and letting packet_recvmsg() use sll->sll_hatype without an RCU device lookup.

This changes the reported TCI in three cases:

- Ethernet devices with hard_header_len > ETH_HLEN (e.g., smsc95xx, rndis_host) previously failed the min_header_len == hard_header_len test and reported TCI 0. They now report the TCI.
- Non-Ethernet devices with hard_header_len 0 (e.g., tun, rmnet) previously read a VLAN header at the MAC offset. They now report TCI 0.
- packet_recvmsg() previously omitted the VLAN fields if the device had been unregistered since the packet was queued. It now fills them from the queued skb.

---
 net/packet/af_packet.c | 38 +++++++++-----------------------------
 1 file changed, 9 insertions(+), 29 deletions(-)
net/packet/af_packet.c +9 -29
index bf0ad6d5c1e3..b169d3e11b17 100644
@@ -547,29 +547,18 @@ static void *packet_current_frame(struct packet_sock *po,
 	return packet_lookup_frame(po, rb, rb->head, status);
 }
 
-static u16 vlan_get_tci(const struct sk_buff *skb, struct net_device *dev)
+static u16 vlan_get_tci(const struct sk_buff *skb, unsigned short type)
 {
 	struct vlan_hdr vhdr, *vh;
-	unsigned int header_len;
 
-	if (!dev)
+	if (type != ARPHRD_ETHER && type != ARPHRD_LOOPBACK)
 		return 0;
 
 	/* In the SOCK_DGRAM scenario, skb data starts at the network
 	 * protocol, which is after the VLAN headers. The outer VLAN
-	 * header is at the hard_header_len offset in non-variable
-	 * length link layer headers. If it's a VLAN device, the
-	 * min_header_len should be used to exclude the VLAN header
-	 * size.
+	 * header is at the ETH_HLEN offset from the MAC header.
 	 */
-	if (dev->min_header_len == dev->hard_header_len)
-		header_len = dev->hard_header_len;
-	else if (is_vlan_dev(dev))
-		header_len = dev->min_header_len;
-	else
-		return 0;
-
-	vh = skb_header_pointer(skb, skb_mac_offset(skb) + header_len,
+	vh = skb_header_pointer(skb, skb_mac_offset(skb) + ETH_HLEN,
 				sizeof(vhdr), &vhdr);
 	if (unlikely(!vh))
 		return 0;
@@ -1012,7 +1001,7 @@ static void prb_fill_vlan_info(struct tpacket_kbdq_core *pkc,
 		ppd->hv1.tp_vlan_tpid = ntohs(pkc->skb->vlan_proto);
 		ppd->tp_status = TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
 	} else if (unlikely(po->sk.sk_type == SOCK_DGRAM && eth_type_vlan(pkc->skb->protocol))) {
-		ppd->hv1.tp_vlan_tci = vlan_get_tci(pkc->skb, pkc->skb->dev);
+		ppd->hv1.tp_vlan_tci = vlan_get_tci(pkc->skb, pkc->skb->dev->type);
 		ppd->hv1.tp_vlan_tpid = ntohs(pkc->skb->protocol);
 		ppd->tp_status = TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
 	} else {
@@ -2454,7 +2443,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev,
 			h.h2->tp_vlan_tpid = ntohs(skb->vlan_proto);
 			status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
 		} else if (unlikely(sk->sk_type == SOCK_DGRAM && eth_type_vlan(skb->protocol))) {
-			h.h2->tp_vlan_tci = vlan_get_tci(skb, skb->dev);
+			h.h2->tp_vlan_tci = vlan_get_tci(skb, dev->type);
 			h.h2->tp_vlan_tpid = ntohs(skb->protocol);
 			status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
 		} else {
@@ -3626,19 +3615,10 @@ static int packet_recvmsg(struct socket *sock, struct msghdr *msg, size_t len,
 			aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
 		} else if (unlikely(sock->type == SOCK_DGRAM && eth_type_vlan(skb->protocol))) {
 			struct sockaddr_ll *sll = &PACKET_SKB_CB(skb)->sa.ll;
-			struct net_device *dev;
 
-			rcu_read_lock();
-			dev = dev_get_by_index_rcu(sock_net(sk), sll->sll_ifindex);
-			if (dev) {
-				aux.tp_vlan_tci = vlan_get_tci(skb, dev);
-				aux.tp_vlan_tpid = ntohs(skb->protocol);
-				aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
-			} else {
-				aux.tp_vlan_tci = 0;
-				aux.tp_vlan_tpid = 0;
-			}
-			rcu_read_unlock();
+			aux.tp_vlan_tci = vlan_get_tci(skb, sll->sll_hatype);
+			aux.tp_vlan_tpid = ntohs(skb->protocol);
+			aux.tp_status |= TP_STATUS_VLAN_VALID | TP_STATUS_VLAN_TPID_VALID;
 		} else {
 			aux.tp_vlan_tci = 0;
 			aux.tp_vlan_tpid = 0;
Signature · 1 line
2.56.1.839.g22a8290db9-goog
author maintainer
#7 lore raw

PATCH 6/6 net: remove unused net_device::min_header_len

In reply to Willem de Bruijn

From: Willem de Bruijn <[email protected]>

dev->min_header_len was introduced in commit 217e6fa24ce2 ("net:
introduce device min_header_len") for dev_validate_header() when header_ops->validate and the CAP_SYS_RAWIO bypass could accept frames shorter than hard_header_len.

Now that dev_validate_header() and the remaining workarounds in af_packet have been removed, dev->min_header_len has no readers left. Remove the field from struct net_device along with its remaining assignments in ether_setup() and loopback setup.

---
 Documentation/networking/net_cachelines/net_device.rst | 1 -
 drivers/net/loopback.c                                 | 1 -
 include/linux/netdevice.h                              | 2 --
 net/ethernet/eth.c                                     | 1 -
 4 files changed, 5 deletions(-)
Documentation/networking/net_cachelines/net_device.rst +0 -1
index 7620d3fcb8dc..f73ea0069432 100644
@@ -46,7 +46,6 @@ netdev_features_t                   gso_partial_features        read_mostly
 unsigned_int                        min_mtu
 unsigned_int                        max_mtu
 unsigned_short                      type
-unsigned_char                       min_header_len
 unsigned_char                       name_assign_type
 int                                 group
 struct net_device_stats             stats
drivers/net/loopback.c +0 -1
index 1e6d1b7d71ba..6fdf00c223b9 100644
@@ -173,7 +173,6 @@ static void gen_lo_setup(struct net_device *dev,
 {
 	dev->mtu		= mtu;
 	dev->hard_header_len	= ETH_HLEN;	/* 14	*/
-	dev->min_header_len	= ETH_HLEN;	/* 14	*/
 	dev->addr_len		= ETH_ALEN;	/* 6	*/
 	dev->type		= ARPHRD_LOOPBACK;	/* 0x0001*/
 	dev->flags		= IFF_LOOPBACK;
include/linux/netdevice.h +0 -2
index 930899a7a577..2a1b3f48bed5 100644
@@ -1929,7 +1929,6 @@ enum netdev_reg_state {
  *	@max_mtu:	Interface Maximum MTU value
  *	@type:		Interface hardware type
  *	@hard_header_len: Maximum hardware header length.
- *	@min_header_len:  Minimum hardware header length
  *
  *	@needed_headroom: Extra headroom the hardware may need, but not in all
  *			  cases can this be guaranteed
@@ -2292,7 +2291,6 @@ struct net_device {
 	unsigned int		min_mtu;
 	unsigned int		max_mtu;
 	unsigned short		type;
-	unsigned char		min_header_len;
 	unsigned char		name_assign_type;
 
 	int			group;
net/ethernet/eth.c +0 -1
index 39aab0f8035a..db39527d4704 100644
@@ -330,7 +330,6 @@ void ether_setup(struct net_device *dev)
 	dev->header_ops		= &eth_header_ops;
 	dev->type		= ARPHRD_ETHER;
 	dev->hard_header_len 	= ETH_HLEN;
-	dev->min_header_len	= ETH_HLEN;
 	dev->mtu		= ETH_DATA_LEN;
 	dev->min_mtu		= ETH_MIN_MTU;
 	dev->max_mtu		= ETH_DATA_LEN;
Signature · 1 line
2.56.1.839.g22a8290db9-goog