Skip to contentSkip to conversation

network: Allow af_packet to transmit +4 bytes for VLAN packets.

PATCH Applied [email protected] 3 participants 3 messages Feb 11, 2011 – Feb 12, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 network: Allow af_packet to transmit +4 bytes for VLAN packets.

From: Ben Greear <[email protected]>

This allows user-space to send a '1500' MTU VLAN packet on a 1500 MTU ethernet frame. The extra 4 bytes of a VLAN header is not usually charged against the MTU when other parts of the network stack is transmitting vlans...

---

v2: Fix ETH_HLEN to be VLAN_HLEN

:100644 100644 91cb1d7... eb39d70... M net/packet/af_packet.c

 net/packet/af_packet.c |   31 +++++++++++++++++++++++++++++--
 1 files changed, 29 insertions(+), 2 deletions(-)
net/packet/af_packet.c +29 -2
index 91cb1d7..eb39d70 100644
@@ -466,7 +466,7 @@ retry:
 	 */
 
 	err = -EMSGSIZE;
-	if (len > dev->mtu + dev->hard_header_len)
+	if (len > dev->mtu + dev->hard_header_len + VLAN_HLEN)
 		goto out_unlock;
 
 	if (!skb) {
@@ -497,6 +497,19 @@ retry:
 		goto retry;
 	}
 
+	if (len > (dev->mtu + dev->hard_header_len)) {
+		/* Earlier code assumed this would be a VLAN pkt,
+		 * double-check this now that we have the actual
+		 * packet in hand.
+		 */
+		struct ethhdr *ehdr;
+		skb_reset_mac_header(skb);
+		ehdr = eth_hdr(skb);
+		if (ehdr->h_proto != htons(ETH_P_8021Q)) {
+			err = -EMSGSIZE;
+			goto out_unlock;
+		}
+	}
 
 	skb->protocol = proto;
 	skb->dev = dev;
@@ -1200,7 +1213,7 @@ static int packet_snd(struct socket *sock,
 	}
 
 	err = -EMSGSIZE;
-	if (!gso_type && (len > dev->mtu+reserve))
+	if (!gso_type && (len > dev->mtu + reserve + VLAN_HLEN))
 		goto out_unlock;
 
 	err = -ENOBUFS;
@@ -1225,6 +1238,20 @@ static int packet_snd(struct socket *sock,
 	if (err < 0)
 		goto out_free;
 
+	if (!gso_type && (len > dev->mtu + reserve)) {
+		/* Earlier code assumed this would be a VLAN pkt,
+		 * double-check this now that we have the actual
+		 * packet in hand.
+		 */
+		struct ethhdr *ehdr;
+		skb_reset_mac_header(skb);
+		ehdr = eth_hdr(skb);
+		if (ehdr->h_proto != htons(ETH_P_8021Q)) {
+			err = -EMSGSIZE;
+			goto out_free;
+		}
+	}
+
 	skb->protocol = proto;
 	skb->dev = dev;
 	skb->priority = sk->sk_priority;
Signature · 1 line
1.7.2.3
Reviewed-by on v2 2/2
#1 lore raw

Le vendredi 11 février 2011 à 11:35 -0800, [email protected] a écrit :

Quoted 9 lines

From: Ben Greear <[email protected]>

This allows user-space to send a '1500' MTU VLAN packet on a 1500 MTU ethernet frame. The extra 4 bytes of a VLAN header is not usually charged against the MTU when other parts of the network stack is transmitting vlans...

---

maintainer Applied
#2 lore raw

From: Eric Dumazet <[email protected]>
Date: Fri, 11 Feb 2011 23:18:38 +0100

Quoted 9 lines

Le vendredi 11 février 2011 à 11:35 -0800, [email protected] a écrit :

Quoted 7 lines

From: Ben Greear <[email protected]>

This allows user-space to send a '1500' MTU VLAN packet on a 1500 MTU ethernet frame. The extra 4 bytes of a VLAN header is not usually charged against the MTU when other parts of the network stack is transmitting vlans...

Quoted 4 lines
Quoted 2 lines

---

Applied to net-next-2.6, thanks.