1 #ifndef __LINUX_IF_VLAN_WRAPPER_H
2 #define __LINUX_IF_VLAN_WRAPPER_H 1
4 #include <linux/skbuff.h>
5 #include <linux/version.h>
6 #include_next <linux/if_vlan.h>
8 #ifndef HAVE_VLAN_INSERT_TAG_SET_PROTO
10 * The behavior of __vlan_put_tag()/vlan_insert_tag_set_proto() has changed
13 * - In 2.6.26 and earlier, it adjusted both MAC and network header
14 * pointers. (The latter didn't make any sense.)
16 * - In 2.6.27 and 2.6.28, it did not adjust any header pointers at all.
18 * - In 2.6.29 and later, it adjusts the MAC header pointer only.
20 * - In 3.19 and later, it was renamed to vlan_insert_tag_set_proto()
22 * This is the version from 2.6.33. We unconditionally substitute this version
23 * to avoid the need to guess whether the version in the kernel tree is
26 #define vlan_insert_tag_set_proto(skb, proto, vlan_tci) \
27 rpl_vlan_insert_tag_set_proto(skb, vlan_tci)
28 static inline struct sk_buff *rpl_vlan_insert_tag_set_proto(struct sk_buff *skb,
31 struct vlan_ethhdr *veth;
33 if (skb_cow_head(skb, VLAN_HLEN) < 0) {
37 veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
39 /* Move the mac addresses to the beginning of the new header. */
40 memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
41 skb->mac_header -= VLAN_HLEN;
43 /* first, the ethernet type */
44 veth->h_vlan_proto = htons(ETH_P_8021Q);
47 veth->h_vlan_TCI = htons(vlan_tci);
49 skb->protocol = htons(ETH_P_8021Q);
55 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,19,0)
57 * __vlan_hwaccel_push_inside - pushes vlan tag to the payload
60 * Pushes the VLAN tag from @skb->vlan_tci inside to the payload.
62 * Following the skb_unshare() example, in case of error, the calling function
63 * doesn't have to worry about freeing the original skb.
65 static inline struct sk_buff *__vlan_hwaccel_push_inside(struct sk_buff *skb)
67 skb = vlan_insert_tag_set_proto(skb, skb->vlan_proto,
68 vlan_tx_tag_get(skb));
74 * vlan_hwaccel_push_inside - pushes vlan tag to the payload
77 * Checks is tag is present in @skb->vlan_tci and if it is, it pushes the
78 * VLAN tag from @skb->vlan_tci inside to the payload.
80 * Following the skb_unshare() example, in case of error, the calling function
81 * doesn't have to worry about freeing the original skb.
83 static inline struct sk_buff *vlan_hwaccel_push_inside(struct sk_buff *skb)
85 if (vlan_tx_tag_present(skb))
86 skb = __vlan_hwaccel_push_inside(skb);
91 #if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
92 static inline struct sk_buff *rpl___vlan_hwaccel_put_tag(struct sk_buff *skb,
96 return __vlan_hwaccel_put_tag(skb, vlan_tci);
99 #define __vlan_hwaccel_put_tag rpl___vlan_hwaccel_put_tag
102 /* All of these were introduced in a single commit preceding 2.6.33, so
103 * presumably all of them or none of them are present. */
104 #ifndef VLAN_PRIO_MASK
105 #define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
106 #define VLAN_PRIO_SHIFT 13
107 #define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */
108 #define VLAN_TAG_PRESENT VLAN_CFI_MASK
111 #ifndef HAVE_VLAN_SET_ENCAP_PROTO
112 static inline void vlan_set_encap_proto(struct sk_buff *skb, struct vlan_hdr *vhdr)
118 * Was a VLAN packet, grab the encapsulated protocol, which the layer
119 * three protocols care about.
122 proto = vhdr->h_vlan_encapsulated_proto;
123 if (ntohs(proto) >= 1536) {
124 skb->protocol = proto;
129 if (*(unsigned short *) rawp == 0xFFFF)
131 * This is a magic hack to spot IPX packets. Older Novell
132 * breaks the protocol design and runs IPX over 802.3 without
133 * an 802.2 LLC layer. We look for FFFF which isn't a used
134 * 802.2 SSAP/DSAP. This won't work for fault tolerant netware
135 * but does for the rest.
137 skb->protocol = htons(ETH_P_802_3);
142 skb->protocol = htons(ETH_P_802_2);
146 #ifndef HAVE___VLAN_INSERT_TAG
147 /* Kernels which don't have __vlan_insert_tag() also don't have skb->vlan_proto
148 * so ignore the proto paramter.
150 #define __vlan_insert_tag(skb, proto, tci) rpl_vlan_insert_tag(skb, tci)
151 static inline int rpl_vlan_insert_tag(struct sk_buff *skb, u16 vlan_tci)
153 struct vlan_ethhdr *veth;
155 if (skb_cow_head(skb, VLAN_HLEN) < 0)
158 veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN);
160 /* Move the mac addresses to the beginning of the new header. */
161 memmove(skb->data, skb->data + VLAN_HLEN, 2 * ETH_ALEN);
162 skb->mac_header -= VLAN_HLEN;
164 /* first, the ethernet type */
165 veth->h_vlan_proto = htons(ETH_P_8021Q);
168 veth->h_vlan_TCI = htons(vlan_tci);
174 #ifndef skb_vlan_tag_present
175 #define skb_vlan_tag_present(skb) vlan_tx_tag_present(skb)
176 #define skb_vlan_tag_get(skb) vlan_tx_tag_get(skb)
179 #endif /* linux/if_vlan.h wrapper */