X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=datapath%2Fvlan.h;h=5d3573b5b974111cadc32d3bbcd4109e69a6770c;hb=2c57a420432de88b8a6f9ee54642c3841577ad7b;hp=dc900183d4babe13e576986eac8b9e19c4a46d4c;hpb=6e0ce48e27d5a845bdc8b57fb41bcec8a54f336a;p=sliver-openvswitch.git diff --git a/datapath/vlan.h b/datapath/vlan.h index dc900183d..5d3573b5b 100644 --- a/datapath/vlan.h +++ b/datapath/vlan.h @@ -1,9 +1,19 @@ /* - * Copyright (c) 2011 Nicira Networks. - * Distributed under the terms of the GNU GPL version 2. + * Copyright (c) 2007-2011 Nicira, Inc. * - * Significant portions of this file may be copied from parts of the Linux - * kernel, by Linus Torvalds and others. + * This program is free software; you can redistribute it and/or + * modify it under the terms of version 2 of the GNU General Public + * License as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA */ #ifndef VLAN_H @@ -13,6 +23,29 @@ #include #include +/** + * DOC: VLAN tag manipulation. + * + * &struct sk_buff handling of VLAN tags has evolved over time: + * + * In 2.6.26 and earlier, VLAN tags did not have any generic representation in + * an skb, other than as a raw 802.1Q header inside the packet data. + * + * In 2.6.27 &struct sk_buff added a @vlan_tci member. Between 2.6.27 and + * 2.6.32, its value was the raw contents of the 802.1Q TCI field, or zero if + * no 802.1Q header was present. This worked OK except for the corner case of + * an 802.1Q header with an all-0-bits TCI, which could not be represented. + * + * In 2.6.33, @vlan_tci semantics changed. Now, if an 802.1Q header is + * present, then the VLAN_TAG_PRESENT bit is always set. This fixes the + * all-0-bits TCI corner case. + * + * For compatibility we emulate the 2.6.33+ behavior on earlier kernel + * versions. The client must not access @vlan_tci directly. Instead, use + * vlan_get_tci() to read it or vlan_set_tci() to write it, with semantics + * equivalent to those on 2.6.33+. + */ + #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) #define NEED_VLAN_FIELD #endif @@ -22,11 +55,18 @@ static inline void vlan_copy_skb_tci(struct sk_buff *skb) { } static inline u16 vlan_get_tci(struct sk_buff *skb) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) + if (skb->vlan_tci) + return skb->vlan_tci | VLAN_TAG_PRESENT; +#endif return skb->vlan_tci; } static inline void vlan_set_tci(struct sk_buff *skb, u16 vlan_tci) { +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) + vlan_tci &= ~VLAN_TAG_PRESENT; +#endif skb->vlan_tci = vlan_tci; } #else @@ -43,4 +83,18 @@ u16 vlan_tx_tag_get(struct sk_buff *skb); #define __vlan_hwaccel_put_tag rpl__vlan_hwaccel_put_tag struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb, u16 vlan_tci); #endif /* NEED_VLAN_FIELD */ + +static inline int vlan_deaccel_tag(struct sk_buff *skb) +{ + if (!vlan_tx_tag_present(skb)) + return 0; + + skb = __vlan_put_tag(skb, vlan_tx_tag_get(skb)); + if (unlikely(!skb)) + return -ENOMEM; + + vlan_set_tci(skb, 0); + return 0; +} + #endif /* vlan.h */