compat: Added support for SLES12 SP1
[~tnikolova/compat/.git] / include / linux / if_vlan.h
1 #ifndef LINUX_IF_VLAN_H
2 #define LINUX_IF_VLAN_H
3
4 #include "../../compat/config.h"
5
6 #include_next <linux/if_vlan.h>
7
8 #ifndef skb_vlan_tag_present
9 #define skb_vlan_tag_present vlan_tx_tag_present
10 #define skb_vlan_tag_get vlan_tx_tag_get
11 #define skb_vlan_tag_get_id vlan_tx_tag_get_id
12 #endif
13
14 #ifndef HAVE_IS_VLAN_DEV
15 static inline int is_vlan_dev(struct net_device *dev)
16 {
17         return dev->priv_flags & IFF_802_1Q_VLAN;
18 }
19 #endif
20
21 #ifndef ETH_P_8021AD
22 #define ETH_P_8021AD    0x88A8          /* 802.1ad Service VLAN         */
23 #endif
24
25 #ifndef HAVE_VLAN_GET_PROTOCOL
26 /**
27  * vlan_get_protocol - get protocol EtherType.
28  * @skb: skbuff to query
29  * @type: first vlan protocol
30  * @depth: buffer to store length of eth and vlan tags in bytes
31  *
32  * Returns the EtherType of the packet, regardless of whether it is
33  * vlan encapsulated (normal or hardware accelerated) or not.
34  */
35 static inline __be16 __vlan_get_protocol(struct sk_buff *skb, __be16 type,
36                                          int *depth)
37 {
38         unsigned int vlan_depth = skb->mac_len;
39
40         /* if type is 802.1Q/AD then the header should already be
41          * present at mac_len - VLAN_HLEN (if mac_len > 0), or at
42          * ETH_HLEN otherwise
43          */
44         if (type == htons(ETH_P_8021Q) || type == htons(ETH_P_8021AD)) {
45                 if (vlan_depth) {
46                         if (WARN_ON(vlan_depth < VLAN_HLEN))
47                                 return 0;
48                         vlan_depth -= VLAN_HLEN;
49                 } else {
50                         vlan_depth = ETH_HLEN;
51                 }
52                 do {
53                         struct vlan_hdr *vh;
54
55                         if (unlikely(!pskb_may_pull(skb,
56                                                     vlan_depth + VLAN_HLEN)))
57                                 return 0;
58
59                         vh = (struct vlan_hdr *)(skb->data + vlan_depth);
60                         type = vh->h_vlan_encapsulated_proto;
61                         vlan_depth += VLAN_HLEN;
62                 } while (type == htons(ETH_P_8021Q) ||
63                          type == htons(ETH_P_8021AD));
64         }
65
66         if (depth)
67                 *depth = vlan_depth;
68
69         return type;
70 }
71 #endif
72
73 #endif /* LINUX_IF_VLAN_H */