xref: /linux/include/linux/if_vlan.h (revision d32435391974e39c35ade4d115f17c538a96a708)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  * VLAN		An implementation of 802.1Q VLAN tagging.
31da177e4SLinus Torvalds  *
41da177e4SLinus Torvalds  * Authors:	Ben Greear <greearb@candelatech.com>
51da177e4SLinus Torvalds  *
61da177e4SLinus Torvalds  *		This program is free software; you can redistribute it and/or
71da177e4SLinus Torvalds  *		modify it under the terms of the GNU General Public License
81da177e4SLinus Torvalds  *		as published by the Free Software Foundation; either version
91da177e4SLinus Torvalds  *		2 of the License, or (at your option) any later version.
101da177e4SLinus Torvalds  *
111da177e4SLinus Torvalds  */
121da177e4SLinus Torvalds #ifndef _LINUX_IF_VLAN_H_
131da177e4SLinus Torvalds #define _LINUX_IF_VLAN_H_
141da177e4SLinus Torvalds 
151da177e4SLinus Torvalds #include <linux/netdevice.h>
160610d11bSStephen Hemminger #include <linux/etherdevice.h>
1765ac6a5fSJesse Gross #include <linux/rtnetlink.h>
18187f1882SPaul Gortmaker #include <linux/bug.h>
19607ca46eSDavid Howells #include <uapi/linux/if_vlan.h>
201da177e4SLinus Torvalds 
21a3f671b3SJoe Perches #define VLAN_HLEN	4		/* The additional bytes required by VLAN
22a3f671b3SJoe Perches 					 * (in addition to the Ethernet header)
231da177e4SLinus Torvalds 					 */
241da177e4SLinus Torvalds #define VLAN_ETH_HLEN	18		/* Total octets in header.	 */
251da177e4SLinus Torvalds #define VLAN_ETH_ZLEN	64		/* Min. octets in frame sans FCS */
261da177e4SLinus Torvalds 
271da177e4SLinus Torvalds /*
281da177e4SLinus Torvalds  * According to 802.3ac, the packet can be 4 bytes longer. --Klika Jan
291da177e4SLinus Torvalds  */
301da177e4SLinus Torvalds #define VLAN_ETH_DATA_LEN	1500	/* Max. octets in payload	 */
311da177e4SLinus Torvalds #define VLAN_ETH_FRAME_LEN	1518	/* Max. octets in frame sans FCS */
321da177e4SLinus Torvalds 
33740c15d0SPatrick McHardy /*
34740c15d0SPatrick McHardy  * 	struct vlan_hdr - vlan header
35740c15d0SPatrick McHardy  * 	@h_vlan_TCI: priority and VLAN ID
36740c15d0SPatrick McHardy  *	@h_vlan_encapsulated_proto: packet type ID or len
37740c15d0SPatrick McHardy  */
38740c15d0SPatrick McHardy struct vlan_hdr {
39740c15d0SPatrick McHardy 	__be16	h_vlan_TCI;
40740c15d0SPatrick McHardy 	__be16	h_vlan_encapsulated_proto;
41740c15d0SPatrick McHardy };
42740c15d0SPatrick McHardy 
43740c15d0SPatrick McHardy /**
44740c15d0SPatrick McHardy  *	struct vlan_ethhdr - vlan ethernet header (ethhdr + vlan_hdr)
45740c15d0SPatrick McHardy  *	@h_dest: destination ethernet address
46740c15d0SPatrick McHardy  *	@h_source: source ethernet address
47a7bf5804SOlaf Hering  *	@h_vlan_proto: ethernet protocol
48740c15d0SPatrick McHardy  *	@h_vlan_TCI: priority and VLAN ID
49740c15d0SPatrick McHardy  *	@h_vlan_encapsulated_proto: packet type ID or len
50740c15d0SPatrick McHardy  */
511da177e4SLinus Torvalds struct vlan_ethhdr {
52740c15d0SPatrick McHardy 	unsigned char	h_dest[ETH_ALEN];
53740c15d0SPatrick McHardy 	unsigned char	h_source[ETH_ALEN];
54740c15d0SPatrick McHardy 	__be16		h_vlan_proto;
55740c15d0SPatrick McHardy 	__be16		h_vlan_TCI;
56740c15d0SPatrick McHardy 	__be16		h_vlan_encapsulated_proto;
571da177e4SLinus Torvalds };
581da177e4SLinus Torvalds 
591da177e4SLinus Torvalds #include <linux/skbuff.h>
601da177e4SLinus Torvalds 
611da177e4SLinus Torvalds static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)
621da177e4SLinus Torvalds {
6398e399f8SArnaldo Carvalho de Melo 	return (struct vlan_ethhdr *)skb_mac_header(skb);
641da177e4SLinus Torvalds }
651da177e4SLinus Torvalds 
6605423b24SEric Dumazet #define VLAN_PRIO_MASK		0xe000 /* Priority Code Point */
6705423b24SEric Dumazet #define VLAN_PRIO_SHIFT		13
6805423b24SEric Dumazet #define VLAN_CFI_MASK		0x1000 /* Canonical Format Indicator */
6905423b24SEric Dumazet #define VLAN_TAG_PRESENT	VLAN_CFI_MASK
7005423b24SEric Dumazet #define VLAN_VID_MASK		0x0fff /* VLAN Identifier */
71b738127dSJesse Gross #define VLAN_N_VID		4096
721da177e4SLinus Torvalds 
731da177e4SLinus Torvalds /* found in socket.c */
74881d966bSEric W. Biederman extern void vlan_ioctl_set(int (*hook)(struct net *, void __user *));
751da177e4SLinus Torvalds 
766dcbbe25SNeil Horman static inline int is_vlan_dev(struct net_device *dev)
776dcbbe25SNeil Horman {
786dcbbe25SNeil Horman         return dev->priv_flags & IFF_802_1Q_VLAN;
796dcbbe25SNeil Horman }
806dcbbe25SNeil Horman 
8105423b24SEric Dumazet #define vlan_tx_tag_present(__skb)	((__skb)->vlan_tci & VLAN_TAG_PRESENT)
8205423b24SEric Dumazet #define vlan_tx_tag_get(__skb)		((__skb)->vlan_tci & ~VLAN_TAG_PRESENT)
83d4b812deSEric Dumazet #define vlan_tx_tag_get_id(__skb)	((__skb)->vlan_tci & VLAN_VID_MASK)
841da177e4SLinus Torvalds 
857750f403SPatrick McHardy #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE)
8665ac6a5fSJesse Gross 
87cec9c133SJiri Pirko extern struct net_device *__vlan_find_dev_deep(struct net_device *real_dev,
881fd9b1fcSPatrick McHardy 					       __be16 vlan_proto, u16 vlan_id);
8922d1ba74SPatrick McHardy extern struct net_device *vlan_dev_real_dev(const struct net_device *dev);
9022d1ba74SPatrick McHardy extern u16 vlan_dev_vlan_id(const struct net_device *dev);
91*d3243539SEyal Perry extern u16 vlan_dev_get_egress_qos_mask(struct net_device *dev,
92*d3243539SEyal Perry 					u32 skprio);
9348cc32d3SFlorian Zumbiehl extern bool vlan_do_receive(struct sk_buff **skb);
94bcc6d479SJiri Pirko extern struct sk_buff *vlan_untag(struct sk_buff *skb);
959b22ea56SPatrick McHardy 
9680d5c368SPatrick McHardy extern int vlan_vid_add(struct net_device *dev, __be16 proto, u16 vid);
9780d5c368SPatrick McHardy extern void vlan_vid_del(struct net_device *dev, __be16 proto, u16 vid);
9887002b03SJiri Pirko 
99348a1443SJiri Pirko extern int vlan_vids_add_by_dev(struct net_device *dev,
100348a1443SJiri Pirko 				const struct net_device *by_dev);
101348a1443SJiri Pirko extern void vlan_vids_del_by_dev(struct net_device *dev,
102348a1443SJiri Pirko 				 const struct net_device *by_dev);
1039b361c13SJiri Pirko 
1049b361c13SJiri Pirko extern bool vlan_uses_dev(const struct net_device *dev);
1057750f403SPatrick McHardy #else
106cec9c133SJiri Pirko static inline struct net_device *
1079fae27b3SPatrick McHardy __vlan_find_dev_deep(struct net_device *real_dev,
1089fae27b3SPatrick McHardy 		     __be16 vlan_proto, u16 vlan_id)
109cec9c133SJiri Pirko {
110cec9c133SJiri Pirko 	return NULL;
111cec9c133SJiri Pirko }
112cec9c133SJiri Pirko 
11322d1ba74SPatrick McHardy static inline struct net_device *vlan_dev_real_dev(const struct net_device *dev)
11422d1ba74SPatrick McHardy {
11522d1ba74SPatrick McHardy 	BUG();
11622d1ba74SPatrick McHardy 	return NULL;
11722d1ba74SPatrick McHardy }
11822d1ba74SPatrick McHardy 
11922d1ba74SPatrick McHardy static inline u16 vlan_dev_vlan_id(const struct net_device *dev)
12022d1ba74SPatrick McHardy {
12122d1ba74SPatrick McHardy 	BUG();
12222d1ba74SPatrick McHardy 	return 0;
12322d1ba74SPatrick McHardy }
12422d1ba74SPatrick McHardy 
125*d3243539SEyal Perry static inline u16 vlan_dev_get_egress_qos_mask(struct net_device *dev,
126*d3243539SEyal Perry 					       u32 skprio)
127*d3243539SEyal Perry {
128*d3243539SEyal Perry 	return 0;
129*d3243539SEyal Perry }
130*d3243539SEyal Perry 
13148cc32d3SFlorian Zumbiehl static inline bool vlan_do_receive(struct sk_buff **skb)
1329b22ea56SPatrick McHardy {
1333701e513SJesse Gross 	return false;
1349b22ea56SPatrick McHardy }
135e1c096e2SHerbert Xu 
1366139e75fSDavid S. Miller static inline struct sk_buff *vlan_untag(struct sk_buff *skb)
137bcc6d479SJiri Pirko {
138bcc6d479SJiri Pirko 	return skb;
139bcc6d479SJiri Pirko }
14087002b03SJiri Pirko 
1419fae27b3SPatrick McHardy static inline int vlan_vid_add(struct net_device *dev, __be16 proto, u16 vid)
14287002b03SJiri Pirko {
14387002b03SJiri Pirko 	return 0;
14487002b03SJiri Pirko }
14587002b03SJiri Pirko 
1469fae27b3SPatrick McHardy static inline void vlan_vid_del(struct net_device *dev, __be16 proto, u16 vid)
14787002b03SJiri Pirko {
14887002b03SJiri Pirko }
149348a1443SJiri Pirko 
150348a1443SJiri Pirko static inline int vlan_vids_add_by_dev(struct net_device *dev,
151348a1443SJiri Pirko 				       const struct net_device *by_dev)
152348a1443SJiri Pirko {
153348a1443SJiri Pirko 	return 0;
154348a1443SJiri Pirko }
155348a1443SJiri Pirko 
156348a1443SJiri Pirko static inline void vlan_vids_del_by_dev(struct net_device *dev,
157348a1443SJiri Pirko 					const struct net_device *by_dev)
158348a1443SJiri Pirko {
159348a1443SJiri Pirko }
1609b361c13SJiri Pirko 
1619b361c13SJiri Pirko static inline bool vlan_uses_dev(const struct net_device *dev)
1629b361c13SJiri Pirko {
1639b361c13SJiri Pirko 	return false;
1649b361c13SJiri Pirko }
1657750f403SPatrick McHardy #endif
1661da177e4SLinus Torvalds 
16786a9bad3SPatrick McHardy static inline bool vlan_hw_offload_capable(netdev_features_t features,
16886a9bad3SPatrick McHardy 					   __be16 proto)
16986a9bad3SPatrick McHardy {
17086a9bad3SPatrick McHardy 	if (proto == htons(ETH_P_8021Q) && features & NETIF_F_HW_VLAN_CTAG_TX)
17186a9bad3SPatrick McHardy 		return true;
1728ad227ffSPatrick McHardy 	if (proto == htons(ETH_P_8021AD) && features & NETIF_F_HW_VLAN_STAG_TX)
1738ad227ffSPatrick McHardy 		return true;
17486a9bad3SPatrick McHardy 	return false;
17586a9bad3SPatrick McHardy }
17686a9bad3SPatrick McHardy 
1779bb8582eSPatrick McHardy /**
1780b5c9db1SJiri Pirko  * vlan_insert_tag - regular VLAN tag inserting
1791da177e4SLinus Torvalds  * @skb: skbuff to tag
18086a9bad3SPatrick McHardy  * @vlan_proto: VLAN encapsulation protocol
1819bb8582eSPatrick McHardy  * @vlan_tci: VLAN TCI to insert
1821da177e4SLinus Torvalds  *
1831da177e4SLinus Torvalds  * Inserts the VLAN tag into @skb as part of the payload
1841da177e4SLinus Torvalds  * Returns a VLAN tagged skb. If a new skb is created, @skb is freed.
1851da177e4SLinus Torvalds  *
1861da177e4SLinus Torvalds  * Following the skb_unshare() example, in case of error, the calling function
1871da177e4SLinus Torvalds  * doesn't have to worry about freeing the original skb.
1880b5c9db1SJiri Pirko  *
1890b5c9db1SJiri Pirko  * Does not change skb->protocol so this function can be used during receive.
1901da177e4SLinus Torvalds  */
19186a9bad3SPatrick McHardy static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb,
19286a9bad3SPatrick McHardy 					      __be16 vlan_proto, u16 vlan_tci)
1931da177e4SLinus Torvalds {
1941da177e4SLinus Torvalds 	struct vlan_ethhdr *veth;
1951da177e4SLinus Torvalds 
19611a100f8SPatrick McHardy 	if (skb_cow_head(skb, VLAN_HLEN) < 0) {
19711a100f8SPatrick McHardy 		kfree_skb(skb);
1981da177e4SLinus Torvalds 		return NULL;
1991da177e4SLinus Torvalds 	}
2001da177e4SLinus Torvalds 	veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
2011da177e4SLinus Torvalds 
2021da177e4SLinus Torvalds 	/* Move the mac addresses to the beginning of the new header. */
203a3f671b3SJoe Perches 	memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
204e4dd6188SJarek Poplawski 	skb->mac_header -= VLAN_HLEN;
2051da177e4SLinus Torvalds 
2061da177e4SLinus Torvalds 	/* first, the ethernet type */
20786a9bad3SPatrick McHardy 	veth->h_vlan_proto = vlan_proto;
2081da177e4SLinus Torvalds 
2099bb8582eSPatrick McHardy 	/* now, the TCI */
2109bb8582eSPatrick McHardy 	veth->h_vlan_TCI = htons(vlan_tci);
2111da177e4SLinus Torvalds 
2120b5c9db1SJiri Pirko 	return skb;
2130b5c9db1SJiri Pirko }
2141da177e4SLinus Torvalds 
2150b5c9db1SJiri Pirko /**
2160b5c9db1SJiri Pirko  * __vlan_put_tag - regular VLAN tag inserting
2170b5c9db1SJiri Pirko  * @skb: skbuff to tag
2180b5c9db1SJiri Pirko  * @vlan_tci: VLAN TCI to insert
2190b5c9db1SJiri Pirko  *
2200b5c9db1SJiri Pirko  * Inserts the VLAN tag into @skb as part of the payload
2210b5c9db1SJiri Pirko  * Returns a VLAN tagged skb. If a new skb is created, @skb is freed.
2220b5c9db1SJiri Pirko  *
2230b5c9db1SJiri Pirko  * Following the skb_unshare() example, in case of error, the calling function
2240b5c9db1SJiri Pirko  * doesn't have to worry about freeing the original skb.
2250b5c9db1SJiri Pirko  */
22686a9bad3SPatrick McHardy static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb,
22786a9bad3SPatrick McHardy 					     __be16 vlan_proto, u16 vlan_tci)
2280b5c9db1SJiri Pirko {
22986a9bad3SPatrick McHardy 	skb = vlan_insert_tag(skb, vlan_proto, vlan_tci);
2300b5c9db1SJiri Pirko 	if (skb)
23186a9bad3SPatrick McHardy 		skb->protocol = vlan_proto;
2321da177e4SLinus Torvalds 	return skb;
2331da177e4SLinus Torvalds }
2341da177e4SLinus Torvalds 
2351da177e4SLinus Torvalds /**
2361da177e4SLinus Torvalds  * __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting
2371da177e4SLinus Torvalds  * @skb: skbuff to tag
23886a9bad3SPatrick McHardy  * @vlan_proto: VLAN encapsulation protocol
2399bb8582eSPatrick McHardy  * @vlan_tci: VLAN TCI to insert
2401da177e4SLinus Torvalds  *
2416aa895b0SPatrick McHardy  * Puts the VLAN TCI in @skb->vlan_tci and lets the device do the rest
2421da177e4SLinus Torvalds  */
2439bb8582eSPatrick McHardy static inline struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb,
24486a9bad3SPatrick McHardy 						     __be16 vlan_proto,
2459bb8582eSPatrick McHardy 						     u16 vlan_tci)
2461da177e4SLinus Torvalds {
24786a9bad3SPatrick McHardy 	skb->vlan_proto = vlan_proto;
24805423b24SEric Dumazet 	skb->vlan_tci = VLAN_TAG_PRESENT | vlan_tci;
2491da177e4SLinus Torvalds 	return skb;
2501da177e4SLinus Torvalds }
2511da177e4SLinus Torvalds 
2521da177e4SLinus Torvalds /**
2531da177e4SLinus Torvalds  * vlan_put_tag - inserts VLAN tag according to device features
2541da177e4SLinus Torvalds  * @skb: skbuff to tag
2559bb8582eSPatrick McHardy  * @vlan_tci: VLAN TCI to insert
2561da177e4SLinus Torvalds  *
2571da177e4SLinus Torvalds  * Assumes skb->dev is the target that will xmit this frame.
2581da177e4SLinus Torvalds  * Returns a VLAN tagged skb.
2591da177e4SLinus Torvalds  */
26086a9bad3SPatrick McHardy static inline struct sk_buff *vlan_put_tag(struct sk_buff *skb,
26186a9bad3SPatrick McHardy 					   __be16 vlan_proto, u16 vlan_tci)
2621da177e4SLinus Torvalds {
26386a9bad3SPatrick McHardy 	if (vlan_hw_offload_capable(skb->dev->features, vlan_proto)) {
26486a9bad3SPatrick McHardy 		return __vlan_hwaccel_put_tag(skb, vlan_proto, vlan_tci);
2651da177e4SLinus Torvalds 	} else {
26686a9bad3SPatrick McHardy 		return __vlan_put_tag(skb, vlan_proto, vlan_tci);
2671da177e4SLinus Torvalds 	}
2681da177e4SLinus Torvalds }
2691da177e4SLinus Torvalds 
2701da177e4SLinus Torvalds /**
2711da177e4SLinus Torvalds  * __vlan_get_tag - get the VLAN ID that is part of the payload
2721da177e4SLinus Torvalds  * @skb: skbuff to query
2739bb8582eSPatrick McHardy  * @vlan_tci: buffer to store vlaue
2741da177e4SLinus Torvalds  *
2751da177e4SLinus Torvalds  * Returns error if the skb is not of VLAN type
2761da177e4SLinus Torvalds  */
2779bb8582eSPatrick McHardy static inline int __vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
2781da177e4SLinus Torvalds {
2791da177e4SLinus Torvalds 	struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->data;
2801da177e4SLinus Torvalds 
2818ad227ffSPatrick McHardy 	if (veth->h_vlan_proto != htons(ETH_P_8021Q) &&
2828ad227ffSPatrick McHardy 	    veth->h_vlan_proto != htons(ETH_P_8021AD))
2831da177e4SLinus Torvalds 		return -EINVAL;
2841da177e4SLinus Torvalds 
2859bb8582eSPatrick McHardy 	*vlan_tci = ntohs(veth->h_vlan_TCI);
2861da177e4SLinus Torvalds 	return 0;
2871da177e4SLinus Torvalds }
2881da177e4SLinus Torvalds 
2891da177e4SLinus Torvalds /**
2901da177e4SLinus Torvalds  * __vlan_hwaccel_get_tag - get the VLAN ID that is in @skb->cb[]
2911da177e4SLinus Torvalds  * @skb: skbuff to query
2929bb8582eSPatrick McHardy  * @vlan_tci: buffer to store vlaue
2931da177e4SLinus Torvalds  *
2946aa895b0SPatrick McHardy  * Returns error if @skb->vlan_tci is not set correctly
2951da177e4SLinus Torvalds  */
29618149935SPatrick McHardy static inline int __vlan_hwaccel_get_tag(const struct sk_buff *skb,
2979bb8582eSPatrick McHardy 					 u16 *vlan_tci)
2981da177e4SLinus Torvalds {
2996aa895b0SPatrick McHardy 	if (vlan_tx_tag_present(skb)) {
30005423b24SEric Dumazet 		*vlan_tci = vlan_tx_tag_get(skb);
3011da177e4SLinus Torvalds 		return 0;
3021da177e4SLinus Torvalds 	} else {
3039bb8582eSPatrick McHardy 		*vlan_tci = 0;
3041da177e4SLinus Torvalds 		return -EINVAL;
3051da177e4SLinus Torvalds 	}
3061da177e4SLinus Torvalds }
3071da177e4SLinus Torvalds 
3081da177e4SLinus Torvalds #define HAVE_VLAN_GET_TAG
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds /**
3111da177e4SLinus Torvalds  * vlan_get_tag - get the VLAN ID from the skb
3121da177e4SLinus Torvalds  * @skb: skbuff to query
3139bb8582eSPatrick McHardy  * @vlan_tci: buffer to store vlaue
3141da177e4SLinus Torvalds  *
3151da177e4SLinus Torvalds  * Returns error if the skb is not VLAN tagged
3161da177e4SLinus Torvalds  */
3179bb8582eSPatrick McHardy static inline int vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci)
3181da177e4SLinus Torvalds {
319f646968fSPatrick McHardy 	if (skb->dev->features & NETIF_F_HW_VLAN_CTAG_TX) {
3209bb8582eSPatrick McHardy 		return __vlan_hwaccel_get_tag(skb, vlan_tci);
3211da177e4SLinus Torvalds 	} else {
3229bb8582eSPatrick McHardy 		return __vlan_get_tag(skb, vlan_tci);
3231da177e4SLinus Torvalds 	}
3241da177e4SLinus Torvalds }
3251da177e4SLinus Torvalds 
3260a85df00SHao Zheng /**
3270a85df00SHao Zheng  * vlan_get_protocol - get protocol EtherType.
3280a85df00SHao Zheng  * @skb: skbuff to query
3290a85df00SHao Zheng  *
3300a85df00SHao Zheng  * Returns the EtherType of the packet, regardless of whether it is
3310a85df00SHao Zheng  * vlan encapsulated (normal or hardware accelerated) or not.
3320a85df00SHao Zheng  */
3330a85df00SHao Zheng static inline __be16 vlan_get_protocol(const struct sk_buff *skb)
3340a85df00SHao Zheng {
3350a85df00SHao Zheng 	__be16 protocol = 0;
3360a85df00SHao Zheng 
3370a85df00SHao Zheng 	if (vlan_tx_tag_present(skb) ||
3380a85df00SHao Zheng 	     skb->protocol != cpu_to_be16(ETH_P_8021Q))
3390a85df00SHao Zheng 		protocol = skb->protocol;
3400a85df00SHao Zheng 	else {
3410a85df00SHao Zheng 		__be16 proto, *protop;
3420a85df00SHao Zheng 		protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr,
3430a85df00SHao Zheng 						h_vlan_encapsulated_proto),
3440a85df00SHao Zheng 						sizeof(proto), &proto);
3450a85df00SHao Zheng 		if (likely(protop))
3460a85df00SHao Zheng 			protocol = *protop;
3470a85df00SHao Zheng 	}
3480a85df00SHao Zheng 
3490a85df00SHao Zheng 	return protocol;
3500a85df00SHao Zheng }
351396cf943SPravin B Shelar 
352396cf943SPravin B Shelar static inline void vlan_set_encap_proto(struct sk_buff *skb,
353396cf943SPravin B Shelar 					struct vlan_hdr *vhdr)
354396cf943SPravin B Shelar {
355396cf943SPravin B Shelar 	__be16 proto;
356da8c8724SCong Wang 	unsigned short *rawp;
357396cf943SPravin B Shelar 
358396cf943SPravin B Shelar 	/*
359396cf943SPravin B Shelar 	 * Was a VLAN packet, grab the encapsulated protocol, which the layer
360396cf943SPravin B Shelar 	 * three protocols care about.
361396cf943SPravin B Shelar 	 */
362396cf943SPravin B Shelar 
363396cf943SPravin B Shelar 	proto = vhdr->h_vlan_encapsulated_proto;
364e5c5d22eSSimon Horman 	if (ntohs(proto) >= ETH_P_802_3_MIN) {
365396cf943SPravin B Shelar 		skb->protocol = proto;
366396cf943SPravin B Shelar 		return;
367396cf943SPravin B Shelar 	}
368396cf943SPravin B Shelar 
369da8c8724SCong Wang 	rawp = (unsigned short *)(vhdr + 1);
370da8c8724SCong Wang 	if (*rawp == 0xFFFF)
371396cf943SPravin B Shelar 		/*
372396cf943SPravin B Shelar 		 * This is a magic hack to spot IPX packets. Older Novell
373396cf943SPravin B Shelar 		 * breaks the protocol design and runs IPX over 802.3 without
374396cf943SPravin B Shelar 		 * an 802.2 LLC layer. We look for FFFF which isn't a used
375396cf943SPravin B Shelar 		 * 802.2 SSAP/DSAP. This won't work for fault tolerant netware
376396cf943SPravin B Shelar 		 * but does for the rest.
377396cf943SPravin B Shelar 		 */
378396cf943SPravin B Shelar 		skb->protocol = htons(ETH_P_802_3);
379396cf943SPravin B Shelar 	else
380396cf943SPravin B Shelar 		/*
381396cf943SPravin B Shelar 		 * Real 802.2 LLC
382396cf943SPravin B Shelar 		 */
383396cf943SPravin B Shelar 		skb->protocol = htons(ETH_P_802_2);
384396cf943SPravin B Shelar }
3851da177e4SLinus Torvalds #endif /* !(_LINUX_IF_VLAN_H_) */
386