netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-2.6 v2 1/3] vlan: Add function to retrieve EtherType from vlan packets.
@ 2010-11-11 23:47 Jesse Gross
  2010-11-11 23:47 ` [PATCH net-2.6 v2 2/3] bnx2x: Look inside vlan when determining checksum proto Jesse Gross
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jesse Gross @ 2010-11-11 23:47 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Hao Zheng

From: Hao Zheng <hzheng@nicira.com>

Depending on how a packet is vlan tagged (i.e. hardware accelerated or
not), the encapsulated protocol is stored in different locations.  This
provides a consistent method of accessing that protocol, which is needed
by drivers, security checks, etc.

Signed-off-by: Hao Zheng <hzheng@nicira.com>
Signed-off-by: Jesse Gross <jesse@nicira.com>
--
Changes from v1:
* Use skb_header_pointer() instead of pskb_may_pull() when retrieving
possibly paged data inside the vlan header to avoid invalidating the
pointers of callers.
---
 include/linux/if_vlan.h |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h
index c2f3a72..635e1fa 100644
--- a/include/linux/if_vlan.h
+++ b/include/linux/if_vlan.h
@@ -339,6 +339,31 @@ static inline int vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
 	}
 }
 
+/**
+ * vlan_get_protocol - get protocol EtherType.
+ * @skb: skbuff to query
+ *
+ * Returns the EtherType of the packet, regardless of whether it is
+ * vlan encapsulated (normal or hardware accelerated) or not.
+ */
+static inline __be16 vlan_get_protocol(const struct sk_buff *skb)
+{
+	__be16 protocol = 0;
+
+	if (vlan_tx_tag_present(skb) ||
+	     skb->protocol != cpu_to_be16(ETH_P_8021Q))
+		protocol = skb->protocol;
+	else {
+		__be16 proto, *protop;
+		protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr,
+						h_vlan_encapsulated_proto),
+						sizeof(proto), &proto);
+		if (likely(protop))
+			protocol = *protop;
+	}
+
+	return protocol;
+}
 #endif /* __KERNEL__ */
 
 /* VLAN IOCTLs are found in sockios.h */
-- 
1.7.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-11-12 20:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-11 23:47 [PATCH net-2.6 v2 1/3] vlan: Add function to retrieve EtherType from vlan packets Jesse Gross
2010-11-11 23:47 ` [PATCH net-2.6 v2 2/3] bnx2x: Look inside vlan when determining checksum proto Jesse Gross
2010-11-12 20:24   ` David Miller
2010-11-11 23:47 ` [PATCH net-2.6 v2 3/3] ixgbe: Look inside vlan when determining offload protocol Jesse Gross
2010-11-12 20:24   ` David Miller
2010-11-12 20:24 ` [PATCH net-2.6 v2 1/3] vlan: Add function to retrieve EtherType from vlan packets David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).