11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * VLAN An implementation of 802.1Q VLAN tagging. 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * Authors: Ben Greear <greearb@candelatech.com> 51da177e4SLinus Torvalds * 61da177e4SLinus Torvalds * This program is free software; you can redistribute it and/or 71da177e4SLinus Torvalds * modify it under the terms of the GNU General Public License 81da177e4SLinus Torvalds * as published by the Free Software Foundation; either version 91da177e4SLinus Torvalds * 2 of the License, or (at your option) any later version. 101da177e4SLinus Torvalds * 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds 131da177e4SLinus Torvalds #ifndef _LINUX_IF_VLAN_H_ 141da177e4SLinus Torvalds #define _LINUX_IF_VLAN_H_ 151da177e4SLinus Torvalds 161da177e4SLinus Torvalds #ifdef __KERNEL__ 171da177e4SLinus Torvalds #include <linux/netdevice.h> 180610d11bSStephen Hemminger #include <linux/etherdevice.h> 1965ac6a5fSJesse Gross #include <linux/rtnetlink.h> 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds #define VLAN_HLEN 4 /* The additional bytes (on top of the Ethernet header) 221da177e4SLinus Torvalds * that VLAN requires. 231da177e4SLinus Torvalds */ 241da177e4SLinus Torvalds #define VLAN_ETH_ALEN 6 /* Octets in one ethernet addr */ 251da177e4SLinus Torvalds #define VLAN_ETH_HLEN 18 /* Total octets in header. */ 261da177e4SLinus Torvalds #define VLAN_ETH_ZLEN 64 /* Min. octets in frame sans FCS */ 271da177e4SLinus Torvalds 281da177e4SLinus Torvalds /* 291da177e4SLinus Torvalds * According to 802.3ac, the packet can be 4 bytes longer. --Klika Jan 301da177e4SLinus Torvalds */ 311da177e4SLinus Torvalds #define VLAN_ETH_DATA_LEN 1500 /* Max. octets in payload */ 321da177e4SLinus Torvalds #define VLAN_ETH_FRAME_LEN 1518 /* Max. octets in frame sans FCS */ 331da177e4SLinus Torvalds 34740c15d0SPatrick McHardy /* 35740c15d0SPatrick McHardy * struct vlan_hdr - vlan header 36740c15d0SPatrick McHardy * @h_vlan_TCI: priority and VLAN ID 37740c15d0SPatrick McHardy * @h_vlan_encapsulated_proto: packet type ID or len 38740c15d0SPatrick McHardy */ 39740c15d0SPatrick McHardy struct vlan_hdr { 40740c15d0SPatrick McHardy __be16 h_vlan_TCI; 41740c15d0SPatrick McHardy __be16 h_vlan_encapsulated_proto; 42740c15d0SPatrick McHardy }; 43740c15d0SPatrick McHardy 44740c15d0SPatrick McHardy /** 45740c15d0SPatrick McHardy * struct vlan_ethhdr - vlan ethernet header (ethhdr + vlan_hdr) 46740c15d0SPatrick McHardy * @h_dest: destination ethernet address 47740c15d0SPatrick McHardy * @h_source: source ethernet address 48740c15d0SPatrick McHardy * @h_vlan_proto: ethernet protocol (always 0x8100) 49740c15d0SPatrick McHardy * @h_vlan_TCI: priority and VLAN ID 50740c15d0SPatrick McHardy * @h_vlan_encapsulated_proto: packet type ID or len 51740c15d0SPatrick McHardy */ 521da177e4SLinus Torvalds struct vlan_ethhdr { 53740c15d0SPatrick McHardy unsigned char h_dest[ETH_ALEN]; 54740c15d0SPatrick McHardy unsigned char h_source[ETH_ALEN]; 55740c15d0SPatrick McHardy __be16 h_vlan_proto; 56740c15d0SPatrick McHardy __be16 h_vlan_TCI; 57740c15d0SPatrick McHardy __be16 h_vlan_encapsulated_proto; 581da177e4SLinus Torvalds }; 591da177e4SLinus Torvalds 601da177e4SLinus Torvalds #include <linux/skbuff.h> 611da177e4SLinus Torvalds 621da177e4SLinus Torvalds static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb) 631da177e4SLinus Torvalds { 6498e399f8SArnaldo Carvalho de Melo return (struct vlan_ethhdr *)skb_mac_header(skb); 651da177e4SLinus Torvalds } 661da177e4SLinus Torvalds 6705423b24SEric Dumazet #define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */ 6805423b24SEric Dumazet #define VLAN_PRIO_SHIFT 13 6905423b24SEric Dumazet #define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator */ 7005423b24SEric Dumazet #define VLAN_TAG_PRESENT VLAN_CFI_MASK 7105423b24SEric Dumazet #define VLAN_VID_MASK 0x0fff /* VLAN Identifier */ 72b738127dSJesse Gross #define VLAN_N_VID 4096 731da177e4SLinus Torvalds 741da177e4SLinus Torvalds /* found in socket.c */ 75881d966bSEric W. Biederman extern void vlan_ioctl_set(int (*hook)(struct net *, void __user *)); 761da177e4SLinus Torvalds 771da177e4SLinus Torvalds /* if this changes, algorithm will have to be reworked because this 781da177e4SLinus Torvalds * depends on completely exhausting the VLAN identifier space. Thus 791da177e4SLinus Torvalds * it gives constant time look-up, but in many cases it wastes memory. 801da177e4SLinus Torvalds */ 815c15bdecSDan Aloni #define VLAN_GROUP_ARRAY_SPLIT_PARTS 8 82b738127dSJesse Gross #define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS) 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds struct vlan_group { 85a9fde260SPavel Emelyanov struct net_device *real_dev; /* The ethernet(like) device 86a9fde260SPavel Emelyanov * the vlan is attached to. 87a9fde260SPavel Emelyanov */ 88af301517SPatrick McHardy unsigned int nr_vlans; 891da177e4SLinus Torvalds struct hlist_node hlist; /* linked list */ 905c15bdecSDan Aloni struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS]; 911da177e4SLinus Torvalds struct rcu_head rcu; 921da177e4SLinus Torvalds }; 931da177e4SLinus Torvalds 94f0b5a0dcSEric Dumazet static inline struct net_device *vlan_group_get_device(struct vlan_group *vg, 959bb8582eSPatrick McHardy u16 vlan_id) 965c15bdecSDan Aloni { 975c15bdecSDan Aloni struct net_device **array; 985c15bdecSDan Aloni array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; 9967727184SPavel Emelyanov return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL; 1005c15bdecSDan Aloni } 1015c15bdecSDan Aloni 102f0b5a0dcSEric Dumazet static inline void vlan_group_set_device(struct vlan_group *vg, 1039bb8582eSPatrick McHardy u16 vlan_id, 1045c15bdecSDan Aloni struct net_device *dev) 1055c15bdecSDan Aloni { 1065c15bdecSDan Aloni struct net_device **array; 1075c15bdecSDan Aloni if (!vg) 1085c15bdecSDan Aloni return; 1095c15bdecSDan Aloni array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; 1105c15bdecSDan Aloni array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev; 1115c15bdecSDan Aloni } 1125c15bdecSDan Aloni 1136dcbbe25SNeil Horman static inline int is_vlan_dev(struct net_device *dev) 1146dcbbe25SNeil Horman { 1156dcbbe25SNeil Horman return dev->priv_flags & IFF_802_1Q_VLAN; 1166dcbbe25SNeil Horman } 1176dcbbe25SNeil Horman 11805423b24SEric Dumazet #define vlan_tx_tag_present(__skb) ((__skb)->vlan_tci & VLAN_TAG_PRESENT) 11905423b24SEric Dumazet #define vlan_tx_tag_get(__skb) ((__skb)->vlan_tci & ~VLAN_TAG_PRESENT) 1201da177e4SLinus Torvalds 1217750f403SPatrick McHardy #if defined(CONFIG_VLAN_8021Q) || defined(CONFIG_VLAN_8021Q_MODULE) 12265ac6a5fSJesse Gross 123*cec9c133SJiri Pirko extern struct net_device *__vlan_find_dev_deep(struct net_device *real_dev, 124*cec9c133SJiri Pirko u16 vlan_id); 12522d1ba74SPatrick McHardy extern struct net_device *vlan_dev_real_dev(const struct net_device *dev); 12622d1ba74SPatrick McHardy extern u16 vlan_dev_vlan_id(const struct net_device *dev); 12722d1ba74SPatrick McHardy 1287750f403SPatrick McHardy extern int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp, 1299bb8582eSPatrick McHardy u16 vlan_tci, int polling); 130bcc6d479SJiri Pirko extern bool vlan_do_receive(struct sk_buff **skb); 131bcc6d479SJiri Pirko extern struct sk_buff *vlan_untag(struct sk_buff *skb); 132c7c4b3b6SBen Hutchings extern gro_result_t 133c7c4b3b6SBen Hutchings vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp, 134e1c096e2SHerbert Xu unsigned int vlan_tci, struct sk_buff *skb); 135c7c4b3b6SBen Hutchings extern gro_result_t 136c7c4b3b6SBen Hutchings vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp, 13776620aafSHerbert Xu unsigned int vlan_tci); 1389b22ea56SPatrick McHardy 1397750f403SPatrick McHardy #else 140*cec9c133SJiri Pirko static inline struct net_device * 141*cec9c133SJiri Pirko __vlan_find_dev_deep(struct net_device *real_dev, u16 vlan_id) 142*cec9c133SJiri Pirko { 143*cec9c133SJiri Pirko return NULL; 144*cec9c133SJiri Pirko } 145*cec9c133SJiri Pirko 14622d1ba74SPatrick McHardy static inline struct net_device *vlan_dev_real_dev(const struct net_device *dev) 14722d1ba74SPatrick McHardy { 14822d1ba74SPatrick McHardy BUG(); 14922d1ba74SPatrick McHardy return NULL; 15022d1ba74SPatrick McHardy } 15122d1ba74SPatrick McHardy 15222d1ba74SPatrick McHardy static inline u16 vlan_dev_vlan_id(const struct net_device *dev) 15322d1ba74SPatrick McHardy { 15422d1ba74SPatrick McHardy BUG(); 15522d1ba74SPatrick McHardy return 0; 15622d1ba74SPatrick McHardy } 15722d1ba74SPatrick McHardy 1587750f403SPatrick McHardy static inline int __vlan_hwaccel_rx(struct sk_buff *skb, struct vlan_group *grp, 1599bb8582eSPatrick McHardy u16 vlan_tci, int polling) 1601da177e4SLinus Torvalds { 1617750f403SPatrick McHardy BUG(); 1627750f403SPatrick McHardy return NET_XMIT_SUCCESS; 1637ea49ed7SDavid S. Miller } 1649b22ea56SPatrick McHardy 165bcc6d479SJiri Pirko static inline bool vlan_do_receive(struct sk_buff **skb) 1669b22ea56SPatrick McHardy { 1670988c4c7SJesse Gross if ((*skb)->vlan_tci & VLAN_VID_MASK) 1680988c4c7SJesse Gross (*skb)->pkt_type = PACKET_OTHERHOST; 1693701e513SJesse Gross return false; 1709b22ea56SPatrick McHardy } 171e1c096e2SHerbert Xu 1726139e75fSDavid S. Miller static inline struct sk_buff *vlan_untag(struct sk_buff *skb) 173bcc6d479SJiri Pirko { 174bcc6d479SJiri Pirko return skb; 175bcc6d479SJiri Pirko } 176bcc6d479SJiri Pirko 177c7c4b3b6SBen Hutchings static inline gro_result_t 178c7c4b3b6SBen Hutchings vlan_gro_receive(struct napi_struct *napi, struct vlan_group *grp, 179e1c096e2SHerbert Xu unsigned int vlan_tci, struct sk_buff *skb) 180e1c096e2SHerbert Xu { 181c7c4b3b6SBen Hutchings return GRO_DROP; 182e1c096e2SHerbert Xu } 183e1c096e2SHerbert Xu 184c7c4b3b6SBen Hutchings static inline gro_result_t 185c7c4b3b6SBen Hutchings vlan_gro_frags(struct napi_struct *napi, struct vlan_group *grp, 186c7c4b3b6SBen Hutchings unsigned int vlan_tci) 187e1c096e2SHerbert Xu { 188c7c4b3b6SBen Hutchings return GRO_DROP; 189e1c096e2SHerbert Xu } 1907750f403SPatrick McHardy #endif 1911da177e4SLinus Torvalds 1929bb8582eSPatrick McHardy /** 1939bb8582eSPatrick McHardy * vlan_hwaccel_rx - netif_rx wrapper for VLAN RX acceleration 1949bb8582eSPatrick McHardy * @skb: buffer 1959bb8582eSPatrick McHardy * @grp: vlan group 1969bb8582eSPatrick McHardy * @vlan_tci: VLAN TCI as received from the card 1979bb8582eSPatrick McHardy */ 1981da177e4SLinus Torvalds static inline int vlan_hwaccel_rx(struct sk_buff *skb, 1991da177e4SLinus Torvalds struct vlan_group *grp, 2009bb8582eSPatrick McHardy u16 vlan_tci) 2011da177e4SLinus Torvalds { 2029bb8582eSPatrick McHardy return __vlan_hwaccel_rx(skb, grp, vlan_tci, 0); 2031da177e4SLinus Torvalds } 2041da177e4SLinus Torvalds 2059bb8582eSPatrick McHardy /** 2069bb8582eSPatrick McHardy * vlan_hwaccel_receive_skb - netif_receive_skb wrapper for VLAN RX acceleration 2079bb8582eSPatrick McHardy * @skb: buffer 2089bb8582eSPatrick McHardy * @grp: vlan group 2099bb8582eSPatrick McHardy * @vlan_tci: VLAN TCI as received from the card 2109bb8582eSPatrick McHardy */ 2111da177e4SLinus Torvalds static inline int vlan_hwaccel_receive_skb(struct sk_buff *skb, 2121da177e4SLinus Torvalds struct vlan_group *grp, 2139bb8582eSPatrick McHardy u16 vlan_tci) 2141da177e4SLinus Torvalds { 2159bb8582eSPatrick McHardy return __vlan_hwaccel_rx(skb, grp, vlan_tci, 1); 2161da177e4SLinus Torvalds } 2171da177e4SLinus Torvalds 2181da177e4SLinus Torvalds /** 2190b5c9db1SJiri Pirko * vlan_insert_tag - regular VLAN tag inserting 2201da177e4SLinus Torvalds * @skb: skbuff to tag 2219bb8582eSPatrick McHardy * @vlan_tci: VLAN TCI to insert 2221da177e4SLinus Torvalds * 2231da177e4SLinus Torvalds * Inserts the VLAN tag into @skb as part of the payload 2241da177e4SLinus Torvalds * Returns a VLAN tagged skb. If a new skb is created, @skb is freed. 2251da177e4SLinus Torvalds * 2261da177e4SLinus Torvalds * Following the skb_unshare() example, in case of error, the calling function 2271da177e4SLinus Torvalds * doesn't have to worry about freeing the original skb. 2280b5c9db1SJiri Pirko * 2290b5c9db1SJiri Pirko * Does not change skb->protocol so this function can be used during receive. 2301da177e4SLinus Torvalds */ 2310b5c9db1SJiri Pirko static inline struct sk_buff *vlan_insert_tag(struct sk_buff *skb, u16 vlan_tci) 2321da177e4SLinus Torvalds { 2331da177e4SLinus Torvalds struct vlan_ethhdr *veth; 2341da177e4SLinus Torvalds 23511a100f8SPatrick McHardy if (skb_cow_head(skb, VLAN_HLEN) < 0) { 23611a100f8SPatrick McHardy kfree_skb(skb); 2371da177e4SLinus Torvalds return NULL; 2381da177e4SLinus Torvalds } 2391da177e4SLinus Torvalds veth = (struct vlan_ethhdr *)skb_push(skb, VLAN_HLEN); 2401da177e4SLinus Torvalds 2411da177e4SLinus Torvalds /* Move the mac addresses to the beginning of the new header. */ 2421da177e4SLinus Torvalds memmove(skb->data, skb->data + VLAN_HLEN, 2 * VLAN_ETH_ALEN); 243e4dd6188SJarek Poplawski skb->mac_header -= VLAN_HLEN; 2441da177e4SLinus Torvalds 2451da177e4SLinus Torvalds /* first, the ethernet type */ 24657d3ae84SPatrick McHardy veth->h_vlan_proto = htons(ETH_P_8021Q); 2471da177e4SLinus Torvalds 2489bb8582eSPatrick McHardy /* now, the TCI */ 2499bb8582eSPatrick McHardy veth->h_vlan_TCI = htons(vlan_tci); 2501da177e4SLinus Torvalds 2510b5c9db1SJiri Pirko return skb; 2520b5c9db1SJiri Pirko } 2531da177e4SLinus Torvalds 2540b5c9db1SJiri Pirko /** 2550b5c9db1SJiri Pirko * __vlan_put_tag - regular VLAN tag inserting 2560b5c9db1SJiri Pirko * @skb: skbuff to tag 2570b5c9db1SJiri Pirko * @vlan_tci: VLAN TCI to insert 2580b5c9db1SJiri Pirko * 2590b5c9db1SJiri Pirko * Inserts the VLAN tag into @skb as part of the payload 2600b5c9db1SJiri Pirko * Returns a VLAN tagged skb. If a new skb is created, @skb is freed. 2610b5c9db1SJiri Pirko * 2620b5c9db1SJiri Pirko * Following the skb_unshare() example, in case of error, the calling function 2630b5c9db1SJiri Pirko * doesn't have to worry about freeing the original skb. 2640b5c9db1SJiri Pirko */ 2650b5c9db1SJiri Pirko static inline struct sk_buff *__vlan_put_tag(struct sk_buff *skb, u16 vlan_tci) 2660b5c9db1SJiri Pirko { 2670b5c9db1SJiri Pirko skb = vlan_insert_tag(skb, vlan_tci); 2680b5c9db1SJiri Pirko if (skb) 2690b5c9db1SJiri Pirko skb->protocol = htons(ETH_P_8021Q); 2701da177e4SLinus Torvalds return skb; 2711da177e4SLinus Torvalds } 2721da177e4SLinus Torvalds 2731da177e4SLinus Torvalds /** 2741da177e4SLinus Torvalds * __vlan_hwaccel_put_tag - hardware accelerated VLAN inserting 2751da177e4SLinus Torvalds * @skb: skbuff to tag 2769bb8582eSPatrick McHardy * @vlan_tci: VLAN TCI to insert 2771da177e4SLinus Torvalds * 2786aa895b0SPatrick McHardy * Puts the VLAN TCI in @skb->vlan_tci and lets the device do the rest 2791da177e4SLinus Torvalds */ 2809bb8582eSPatrick McHardy static inline struct sk_buff *__vlan_hwaccel_put_tag(struct sk_buff *skb, 2819bb8582eSPatrick McHardy u16 vlan_tci) 2821da177e4SLinus Torvalds { 28305423b24SEric Dumazet skb->vlan_tci = VLAN_TAG_PRESENT | vlan_tci; 2841da177e4SLinus Torvalds return skb; 2851da177e4SLinus Torvalds } 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds #define HAVE_VLAN_PUT_TAG 2881da177e4SLinus Torvalds 2891da177e4SLinus Torvalds /** 2901da177e4SLinus Torvalds * vlan_put_tag - inserts VLAN tag according to device features 2911da177e4SLinus Torvalds * @skb: skbuff to tag 2929bb8582eSPatrick McHardy * @vlan_tci: VLAN TCI to insert 2931da177e4SLinus Torvalds * 2941da177e4SLinus Torvalds * Assumes skb->dev is the target that will xmit this frame. 2951da177e4SLinus Torvalds * Returns a VLAN tagged skb. 2961da177e4SLinus Torvalds */ 2979bb8582eSPatrick McHardy static inline struct sk_buff *vlan_put_tag(struct sk_buff *skb, u16 vlan_tci) 2981da177e4SLinus Torvalds { 2991da177e4SLinus Torvalds if (skb->dev->features & NETIF_F_HW_VLAN_TX) { 3009bb8582eSPatrick McHardy return __vlan_hwaccel_put_tag(skb, vlan_tci); 3011da177e4SLinus Torvalds } else { 3029bb8582eSPatrick McHardy return __vlan_put_tag(skb, vlan_tci); 3031da177e4SLinus Torvalds } 3041da177e4SLinus Torvalds } 3051da177e4SLinus Torvalds 3061da177e4SLinus Torvalds /** 3071da177e4SLinus Torvalds * __vlan_get_tag - get the VLAN ID that is part of the payload 3081da177e4SLinus Torvalds * @skb: skbuff to query 3099bb8582eSPatrick McHardy * @vlan_tci: buffer to store vlaue 3101da177e4SLinus Torvalds * 3111da177e4SLinus Torvalds * Returns error if the skb is not of VLAN type 3121da177e4SLinus Torvalds */ 3139bb8582eSPatrick McHardy static inline int __vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci) 3141da177e4SLinus Torvalds { 3151da177e4SLinus Torvalds struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->data; 3161da177e4SLinus Torvalds 31757d3ae84SPatrick McHardy if (veth->h_vlan_proto != htons(ETH_P_8021Q)) { 3181da177e4SLinus Torvalds return -EINVAL; 3191da177e4SLinus Torvalds } 3201da177e4SLinus Torvalds 3219bb8582eSPatrick McHardy *vlan_tci = ntohs(veth->h_vlan_TCI); 3221da177e4SLinus Torvalds return 0; 3231da177e4SLinus Torvalds } 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds /** 3261da177e4SLinus Torvalds * __vlan_hwaccel_get_tag - get the VLAN ID that is in @skb->cb[] 3271da177e4SLinus Torvalds * @skb: skbuff to query 3289bb8582eSPatrick McHardy * @vlan_tci: buffer to store vlaue 3291da177e4SLinus Torvalds * 3306aa895b0SPatrick McHardy * Returns error if @skb->vlan_tci is not set correctly 3311da177e4SLinus Torvalds */ 33218149935SPatrick McHardy static inline int __vlan_hwaccel_get_tag(const struct sk_buff *skb, 3339bb8582eSPatrick McHardy u16 *vlan_tci) 3341da177e4SLinus Torvalds { 3356aa895b0SPatrick McHardy if (vlan_tx_tag_present(skb)) { 33605423b24SEric Dumazet *vlan_tci = vlan_tx_tag_get(skb); 3371da177e4SLinus Torvalds return 0; 3381da177e4SLinus Torvalds } else { 3399bb8582eSPatrick McHardy *vlan_tci = 0; 3401da177e4SLinus Torvalds return -EINVAL; 3411da177e4SLinus Torvalds } 3421da177e4SLinus Torvalds } 3431da177e4SLinus Torvalds 3441da177e4SLinus Torvalds #define HAVE_VLAN_GET_TAG 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds /** 3471da177e4SLinus Torvalds * vlan_get_tag - get the VLAN ID from the skb 3481da177e4SLinus Torvalds * @skb: skbuff to query 3499bb8582eSPatrick McHardy * @vlan_tci: buffer to store vlaue 3501da177e4SLinus Torvalds * 3511da177e4SLinus Torvalds * Returns error if the skb is not VLAN tagged 3521da177e4SLinus Torvalds */ 3539bb8582eSPatrick McHardy static inline int vlan_get_tag(const struct sk_buff *skb, u16 *vlan_tci) 3541da177e4SLinus Torvalds { 3551da177e4SLinus Torvalds if (skb->dev->features & NETIF_F_HW_VLAN_TX) { 3569bb8582eSPatrick McHardy return __vlan_hwaccel_get_tag(skb, vlan_tci); 3571da177e4SLinus Torvalds } else { 3589bb8582eSPatrick McHardy return __vlan_get_tag(skb, vlan_tci); 3591da177e4SLinus Torvalds } 3601da177e4SLinus Torvalds } 3611da177e4SLinus Torvalds 3620a85df00SHao Zheng /** 3630a85df00SHao Zheng * vlan_get_protocol - get protocol EtherType. 3640a85df00SHao Zheng * @skb: skbuff to query 3650a85df00SHao Zheng * 3660a85df00SHao Zheng * Returns the EtherType of the packet, regardless of whether it is 3670a85df00SHao Zheng * vlan encapsulated (normal or hardware accelerated) or not. 3680a85df00SHao Zheng */ 3690a85df00SHao Zheng static inline __be16 vlan_get_protocol(const struct sk_buff *skb) 3700a85df00SHao Zheng { 3710a85df00SHao Zheng __be16 protocol = 0; 3720a85df00SHao Zheng 3730a85df00SHao Zheng if (vlan_tx_tag_present(skb) || 3740a85df00SHao Zheng skb->protocol != cpu_to_be16(ETH_P_8021Q)) 3750a85df00SHao Zheng protocol = skb->protocol; 3760a85df00SHao Zheng else { 3770a85df00SHao Zheng __be16 proto, *protop; 3780a85df00SHao Zheng protop = skb_header_pointer(skb, offsetof(struct vlan_ethhdr, 3790a85df00SHao Zheng h_vlan_encapsulated_proto), 3800a85df00SHao Zheng sizeof(proto), &proto); 3810a85df00SHao Zheng if (likely(protop)) 3820a85df00SHao Zheng protocol = *protop; 3830a85df00SHao Zheng } 3840a85df00SHao Zheng 3850a85df00SHao Zheng return protocol; 3860a85df00SHao Zheng } 3871da177e4SLinus Torvalds #endif /* __KERNEL__ */ 3881da177e4SLinus Torvalds 3891da177e4SLinus Torvalds /* VLAN IOCTLs are found in sockios.h */ 3901da177e4SLinus Torvalds 3911da177e4SLinus Torvalds /* Passed in vlan_ioctl_args structure to determine behaviour. */ 3921da177e4SLinus Torvalds enum vlan_ioctl_cmds { 3931da177e4SLinus Torvalds ADD_VLAN_CMD, 3941da177e4SLinus Torvalds DEL_VLAN_CMD, 3951da177e4SLinus Torvalds SET_VLAN_INGRESS_PRIORITY_CMD, 3961da177e4SLinus Torvalds SET_VLAN_EGRESS_PRIORITY_CMD, 3971da177e4SLinus Torvalds GET_VLAN_INGRESS_PRIORITY_CMD, 3981da177e4SLinus Torvalds GET_VLAN_EGRESS_PRIORITY_CMD, 3991da177e4SLinus Torvalds SET_VLAN_NAME_TYPE_CMD, 4001da177e4SLinus Torvalds SET_VLAN_FLAG_CMD, 4011da177e4SLinus Torvalds GET_VLAN_REALDEV_NAME_CMD, /* If this works, you know it's a VLAN device, btw */ 4021da177e4SLinus Torvalds GET_VLAN_VID_CMD /* Get the VID of this VLAN (specified by name) */ 4031da177e4SLinus Torvalds }; 4041da177e4SLinus Torvalds 405a4bf3af4SPatrick McHardy enum vlan_flags { 406a4bf3af4SPatrick McHardy VLAN_FLAG_REORDER_HDR = 0x1, 40770c03b49SPatrick McHardy VLAN_FLAG_GVRP = 0x2, 4085e756593SPatrick McHardy VLAN_FLAG_LOOSE_BINDING = 0x4, 409a4bf3af4SPatrick McHardy }; 410a4bf3af4SPatrick McHardy 4111da177e4SLinus Torvalds enum vlan_name_types { 4121da177e4SLinus Torvalds VLAN_NAME_TYPE_PLUS_VID, /* Name will look like: vlan0005 */ 4131da177e4SLinus Torvalds VLAN_NAME_TYPE_RAW_PLUS_VID, /* name will look like: eth1.0005 */ 4141da177e4SLinus Torvalds VLAN_NAME_TYPE_PLUS_VID_NO_PAD, /* Name will look like: vlan5 */ 4151da177e4SLinus Torvalds VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD, /* Name will look like: eth0.5 */ 4161da177e4SLinus Torvalds VLAN_NAME_TYPE_HIGHEST 4171da177e4SLinus Torvalds }; 4181da177e4SLinus Torvalds 4191da177e4SLinus Torvalds struct vlan_ioctl_args { 4201da177e4SLinus Torvalds int cmd; /* Should be one of the vlan_ioctl_cmds enum above. */ 4211da177e4SLinus Torvalds char device1[24]; 4221da177e4SLinus Torvalds 4231da177e4SLinus Torvalds union { 4241da177e4SLinus Torvalds char device2[24]; 4251da177e4SLinus Torvalds int VID; 4261da177e4SLinus Torvalds unsigned int skb_priority; 4271da177e4SLinus Torvalds unsigned int name_type; 4281da177e4SLinus Torvalds unsigned int bind_type; 4291da177e4SLinus Torvalds unsigned int flag; /* Matches vlan_dev_info flags */ 4301da177e4SLinus Torvalds } u; 4311da177e4SLinus Torvalds 4321da177e4SLinus Torvalds short vlan_qos; 4331da177e4SLinus Torvalds }; 4341da177e4SLinus Torvalds 4351da177e4SLinus Torvalds #endif /* !(_LINUX_IF_VLAN_H_) */ 436