vlan: Add function to retrieve EtherType from vlan packets.
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> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
		
					parent
					
						
							
								167c25e4c5
							
						
					
				
			
			
				commit
				
					
						0a85df0046
					
				
			
		
					 1 changed files with 25 additions and 0 deletions
				
			
		| 
						 | 
					@ -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__ */
 | 
					#endif /* __KERNEL__ */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* VLAN IOCTLs are found in sockios.h */
 | 
					/* VLAN IOCTLs are found in sockios.h */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue