diff options
| author | Hao Zheng <hzheng@nicira.com> | 2010-11-11 08:47:57 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2010-11-12 15:30:57 -0500 |
| commit | 0a85df004667c99efc31fab07386823eefce3be5 (patch) | |
| tree | 2fe059bc77f52e3cdb6ab665e41dd1eba9d4fc08 | |
| parent | 167c25e4c5501f8b7e37f949d23652975c5a769c (diff) | |
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>
| -rw-r--r-- | 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 c2f3a72712ce..635e1faec412 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) | |||
| 339 | } | 339 | } |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | /** | ||
| 343 | * vlan_get_protocol - get protocol EtherType. | ||
| 344 | * @skb: skbuff to query | ||
| 345 | * | ||
| 346 | * Returns the EtherType of the packet, regardless of whether it is | ||
| 347 | * vlan encapsulated (normal or hardware accelerated) or not. | ||
| 348 | */ | ||
| 349 | static inline __be16 vlan_get_protocol(const struct sk_buff *skb) | ||
| 350 | { | ||
| 351 | __be16 protocol = 0; | ||
| 352 | |||
| 353 | if (vlan_tx_tag_present(skb) || | ||
| 354 | skb->protocol != cpu_to_be16(ETH_P_8021Q)) | ||
| 355 | protocol = skb->protocol; | ||
| 356 | else { | ||
| 357 | __be16 proto, *protop; | ||
| 358 | protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr, | ||
| 359 | h_vlan_encapsulated_proto), | ||
| 360 | sizeof(proto), &proto); | ||
| 361 | if (likely(protop)) | ||
| 362 | protocol = *protop; | ||
| 363 | } | ||
| 364 | |||
| 365 | return protocol; | ||
| 366 | } | ||
| 342 | #endif /* __KERNEL__ */ | 367 | #endif /* __KERNEL__ */ |
| 343 | 368 | ||
| 344 | /* VLAN IOCTLs are found in sockios.h */ | 369 | /* VLAN IOCTLs are found in sockios.h */ |
