Skip to contentSkip to conversation

af-packet: Add flag to distinguish VID 0 from no-vlan.

PATCH Superseded [email protected] 2 participants 2 messages May 25, 2011 – May 26, 2011

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 af-packet: Add flag to distinguish VID 0 from no-vlan.

From: Ben Greear <[email protected]>

Currently, user-space cannot determine if a 0 tcp_vlan_tci means there is no VLAN tag or the VLAN ID was zero.

Add flag to make this explicit. User-space can check for TP_STATUS_VLAN_VALID || tp_vlan_tci > 0, which will be backwards compatible. Older could would have just checked for tp_vlan_tci, so it will work no worse than before.

---
:100644 100644 72bfa5a... 6d66ce1... M include/linux/if_packet.h
:100644 100644 658edd1... 885d76d... M net/packet/af_packet.c

 include/linux/if_packet.h |    1 +
 net/packet/af_packet.c    |    7 ++++++-
 2 files changed, 7 insertions(+), 1 deletions(-)
include/linux/if_packet.h +1 -0
index 72bfa5a..6d66ce1 100644
@@ -70,6 +70,7 @@ struct tpacket_auxdata {
 #define TP_STATUS_COPY		0x2
 #define TP_STATUS_LOSING	0x4
 #define TP_STATUS_CSUMNOTREADY	0x8
+#define TP_STATUS_VLAN_VALID   0x10 /* auxdata has valid tp_vlan_tci */
 
 /* Tx ring - header status */
 #define TP_STATUS_AVAILABLE	0x0
net/packet/af_packet.c +6 -1
index 658edd1..885d76d 100644
@@ -1772,7 +1772,12 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
 		aux.tp_snaplen = skb->len;
 		aux.tp_mac = 0;
 		aux.tp_net = skb_network_offset(skb);
-		aux.tp_vlan_tci = vlan_tx_tag_get(skb);
+		if (vlan_tx_tag_present(skb)) {
+			aux.tp_vlan_tci = vlan_tx_tag_get(skb);
+			aux.tp_status |= TP_STATUS_VLAN_VALID;
+		}
+		else
+			aux.tp_vlan_tci = 0;
 
 		put_cmsg(msg, SOL_PACKET, PACKET_AUXDATA, sizeof(aux), &aux);
 	}
Signature · 1 line
1.7.3.4
maintainer
#1 lore raw

From: [email protected]
Date: Wed, 25 May 2011 16:36:35 -0700

Quoted 11 lines

From: Ben Greear <[email protected]>

Currently, user-space cannot determine if a 0 tcp_vlan_tci means there is no VLAN tag or the VLAN ID was zero.

Add flag to make this explicit. User-space can check for TP_STATUS_VLAN_VALID || tp_vlan_tci > 0, which will be backwards compatible. Older could would have just checked for tp_vlan_tci, so it will work no worse than before.

Please do this in tpacket_rcv() too, otherwise the feature bit won't be available to mmap() users of AF_PACKET.

Thanks.