1 /*- 2 * Copyright 1998 Massachusetts Institute of Technology 3 * 4 * Permission to use, copy, modify, and distribute this software and 5 * its documentation for any purpose and without fee is hereby 6 * granted, provided that both the above copyright notice and this 7 * permission notice appear in all copies, that both the above 8 * copyright notice and this permission notice appear in all 9 * supporting documentation, and that the name of M.I.T. not be used 10 * in advertising or publicity pertaining to distribution of the 11 * software without specific, written prior permission. M.I.T. makes 12 * no representations about the suitability of this software for any 13 * purpose. It is provided "as is" without express or implied 14 * warranty. 15 * 16 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 17 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 20 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $FreeBSD: src/sys/net/if_vlan_var.h,v 1.26 2007/02/28 22:05:30 bms Exp $ 30 */ 31 32 #ifndef _FBSD_COMPAT_NET_IF_VLAN_VAR_H_ 33 #define _FBSD_COMPAT_NET_IF_VLAN_VAR_H_ 1 34 35 #include <net/if.h> 36 37 struct ether_vlan_header { 38 u_char evl_dhost[ETHER_ADDR_LEN]; 39 u_char evl_shost[ETHER_ADDR_LEN]; 40 u_int16_t evl_encap_proto; 41 u_int16_t evl_tag; 42 u_int16_t evl_proto; 43 }; 44 45 #define EVL_VLID_MASK 0x0FFF 46 #define EVL_PRI_MASK 0xE000 47 #define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK) 48 #define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7) 49 #define EVL_CFIOFTAG(tag) (((tag) >> 12) & 1) 50 #define EVL_MAKETAG(vlid, pri, cfi) \ 51 ((((((pri) & 7) << 1) | ((cfi) & 1)) << 12) | ((vlid) & EVL_VLID_MASK)) 52 53 /* Set the VLAN ID in an mbuf packet header non-destructively. */ 54 #define EVL_APPLY_VLID(m, vlid) \ 55 do { \ 56 if ((m)->m_flags & M_VLANTAG) { \ 57 (m)->m_pkthdr.ether_vtag &= EVL_VLID_MASK; \ 58 (m)->m_pkthdr.ether_vtag |= (vlid); \ 59 } else { \ 60 (m)->m_pkthdr.ether_vtag = (vlid); \ 61 (m)->m_flags |= M_VLANTAG; \ 62 } \ 63 } while (0) 64 65 /* Set the priority ID in an mbuf packet header non-destructively. */ 66 #define EVL_APPLY_PRI(m, pri) \ 67 do { \ 68 if ((m)->m_flags & M_VLANTAG) { \ 69 uint16_t __vlantag = (m)->m_pkthdr.ether_vtag; \ 70 (m)->m_pkthdr.ether_vtag |= EVL_MAKETAG( \ 71 EVL_VLANOFTAG(__vlantag), (pri), \ 72 EVL_CFIOFTAG(__vlantag)); \ 73 } else { \ 74 (m)->m_pkthdr.ether_vtag = \ 75 EVL_MAKETAG(0, (pri), 0); \ 76 (m)->m_flags |= M_VLANTAG; \ 77 } \ 78 } while (0) 79 80 /* sysctl(3) tags, for compatibility purposes */ 81 #define VLANCTL_PROTO 1 82 #define VLANCTL_MAX 2 83 84 /* 85 * Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls. 86 */ 87 struct vlanreq { 88 char vlr_parent[IFNAMSIZ]; 89 u_short vlr_tag; 90 }; 91 #define SIOCSETVLAN SIOCSIFGENERIC 92 #define SIOCGETVLAN SIOCGIFGENERIC 93 94 #ifdef _KERNEL 95 /* 96 * Drivers that are capable of adding and removing the VLAN header 97 * in hardware indicate they support this by marking IFCAP_VLAN_HWTAGGING 98 * in if_capabilities. Drivers for hardware that is capable 99 * of handling larger MTU's that may include a software-appended 100 * VLAN header w/o lowering the normal MTU should mark IFCAP_VLAN_MTU 101 * in if_capabilities; this notifies the VLAN code it can leave the 102 * MTU on the vlan interface at the normal setting. 103 */ 104 105 /* 106 * VLAN tags are stored in host byte order. Byte swapping may be 107 * necessary. 108 * 109 * Drivers that support hardware VLAN tag stripping fill in the 110 * received VLAN tag (containing both vlan and priority information) 111 * into the ether_vtag mbuf packet header field: 112 * 113 * m->m_pkthdr.ether_vtag = vlan_id; // ntohs()? 114 * m->m_flags |= M_VLANTAG; 115 * 116 * to mark the packet m with the specified VLAN tag. 117 * 118 * On output the driver should check the mbuf for the M_VLANTAG 119 * flag to see if a VLAN tag is present and valid: 120 * 121 * if (m->m_flags & M_VLANTAG) { 122 * ... = m->m_pkthdr.ether_vtag; // htons()? 123 * ... pass tag to hardware ... 124 * } 125 * 126 * Note that a driver must indicate it supports hardware VLAN 127 * stripping/insertion by marking IFCAP_VLAN_HWTAGGING in 128 * if_capabilities. 129 */ 130 131 #define VLAN_CAPABILITIES(_ifp) do { \ 132 } while (0) 133 134 extern void (*vlan_trunk_cap_p)(struct ifnet *); 135 #endif /* _KERNEL */ 136 137 #endif /* _FBSD_COMPAT_NET_IF_VLAN_VAR_H_ */ 138