datapath: Use vlan acceleration for vlan operations.
[sliver-openvswitch.git] / datapath / vlan.h
1 /*
2  * Copyright (c) 2011 Nicira Networks.
3  * Distributed under the terms of the GNU GPL version 2.
4  *
5  * Significant portions of this file may be copied from parts of the Linux
6  * kernel, by Linus Torvalds and others.
7  */
8
9 #ifndef VLAN_H
10 #define VLAN_H 1
11
12 #include <linux/if_vlan.h>
13 #include <linux/skbuff.h>
14 #include <linux/version.h>
15
16 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
17 #define NEED_VLAN_FIELD
18 #endif
19
20 #ifndef NEED_VLAN_FIELD
21 static inline void vlan_copy_skb_tci(struct sk_buff *skb) { }
22
23 static inline u16 vlan_get_tci(struct sk_buff *skb)
24 {
25         return skb->vlan_tci;
26 }
27
28 static inline void vlan_set_tci(struct sk_buff *skb, u16 vlan_tci)
29 {
30         skb->vlan_tci = vlan_tci;
31 }
32 #else
33 void vlan_copy_skb_tci(struct sk_buff *skb);
34 u16 vlan_get_tci(struct sk_buff *skb);
35 void vlan_set_tci(struct sk_buff *skb, u16 vlan_tci);
36
37 #undef vlan_tx_tag_present
38 bool vlan_tx_tag_present(struct sk_buff *skb);
39
40 #undef vlan_tx_tag_get
41 u16 vlan_tx_tag_get(struct sk_buff *skb);
42
43 #define __vlan_hwaccel_put_tag rpl__vlan_hwaccel_put_tag
44 struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb, u16 vlan_tci);
45 #endif /* NEED_VLAN_FIELD */
46
47 static inline int vlan_deaccel_tag(struct sk_buff *skb)
48 {
49         if (!vlan_tx_tag_present(skb))
50                 return 0;
51
52         skb = __vlan_put_tag(skb, vlan_tx_tag_get(skb));
53         if (unlikely(!skb))
54                 return -ENOMEM;
55
56         vlan_set_tci(skb, 0);
57         return 0;
58 }
59
60 #endif /* vlan.h */