if_vlan_var.h revision 167126
154331Sarchie/*- 254331Sarchie * Copyright 1998 Massachusetts Institute of Technology 3139823Simp * 4139823Simp * Permission to use, copy, modify, and distribute this software and 5139823Simp * its documentation for any purpose and without fee is hereby 654331Sarchie * granted, provided that both the above copyright notice and this 754331Sarchie * permission notice appear in all copies, that both the above 854331Sarchie * copyright notice and this permission notice appear in all 954331Sarchie * supporting documentation, and that the name of M.I.T. not be used 1054331Sarchie * in advertising or publicity pertaining to distribution of the 1154331Sarchie * software without specific, written prior permission. M.I.T. makes 1254331Sarchie * no representations about the suitability of this software for any 1354331Sarchie * purpose. It is provided "as is" without express or implied 1454331Sarchie * warranty. 1554331Sarchie * 1654331Sarchie * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 1754331Sarchie * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 1854331Sarchie * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1954331Sarchie * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 2054331Sarchie * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2154331Sarchie * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2254331Sarchie * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 2354331Sarchie * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 2454331Sarchie * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2554331Sarchie * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 2654331Sarchie * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2754331Sarchie * SUCH DAMAGE. 2854331Sarchie * 2954331Sarchie * $FreeBSD: head/sys/net/if_vlan_var.h 167126 2007-02-28 22:05:30Z bms $ 3054331Sarchie */ 3154331Sarchie 3254331Sarchie#ifndef _NET_IF_VLAN_VAR_H_ 3354331Sarchie#define _NET_IF_VLAN_VAR_H_ 1 3454331Sarchie 3554331Sarchiestruct ether_vlan_header { 3654331Sarchie u_char evl_dhost[ETHER_ADDR_LEN]; 3754331Sarchie u_char evl_shost[ETHER_ADDR_LEN]; 3867506Sjulian u_int16_t evl_encap_proto; 3954331Sarchie u_int16_t evl_tag; 4054331Sarchie u_int16_t evl_proto; 4154331Sarchie}; 4254331Sarchie 4354331Sarchie#define EVL_VLID_MASK 0x0FFF 4454331Sarchie#define EVL_PRI_MASK 0xE000 4554331Sarchie#define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK) 4654331Sarchie#define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7) 4754331Sarchie#define EVL_CFIOFTAG(tag) (((tag) >> 12) & 1) 4854331Sarchie#define EVL_MAKETAG(vlid, pri, cfi) \ 4954331Sarchie ((((((pri) & 7) << 1) | ((cfi) & 1)) << 12) | ((vlid) & EVL_VLID_MASK)) 5054331Sarchie 5154331Sarchie/* Set the VLAN ID in an mbuf packet header non-destructively. */ 5254331Sarchie#define EVL_APPLY_VLID(m, vlid) \ 5354331Sarchie do { \ 5454331Sarchie if ((m)->m_flags & M_VLANTAG) { \ 5554331Sarchie (m)->m_pkthdr.ether_vtag &= EVL_VLID_MASK; \ 5654331Sarchie (m)->m_pkthdr.ether_vtag |= (vlid); \ 5754331Sarchie } else { \ 5854331Sarchie (m)->m_pkthdr.ether_vtag = (vlid); \ 5954331Sarchie (m)->m_flags |= M_VLANTAG; \ 6054331Sarchie } \ 6154331Sarchie } while (0) 6254331Sarchie 6354331Sarchie/* Set the priority ID in an mbuf packet header non-destructively. */ 6454331Sarchie#define EVL_APPLY_PRI(m, pri) \ 6554331Sarchie do { \ 6654331Sarchie if ((m)->m_flags & M_VLANTAG) { \ 6754331Sarchie uint16_t __vlantag = (m)->m_pkthdr.ether_vtag; \ 6854331Sarchie (m)->m_pkthdr.ether_vtag |= EVL_MAKETAG( \ 6954331Sarchie EVL_VLANOFTAG(__vlantag), (pri), \ 7054331Sarchie EVL_CFIOFTAG(__vlantag)); \ 7154331Sarchie } else { \ 7254331Sarchie (m)->m_pkthdr.ether_vtag = \ 7354331Sarchie EVL_MAKETAG(0, (pri), 0); \ 7454331Sarchie (m)->m_flags |= M_VLANTAG; \ 7554331Sarchie } \ 7654331Sarchie } while (0) 7754331Sarchie 7854331Sarchie/* sysctl(3) tags, for compatibility purposes */ 7954331Sarchie#define VLANCTL_PROTO 1 8054331Sarchie#define VLANCTL_MAX 2 8154331Sarchie 8254331Sarchie/* 8354331Sarchie * Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls. 8454331Sarchie */ 8554331Sarchiestruct vlanreq { 8654331Sarchie char vlr_parent[IFNAMSIZ]; 8754331Sarchie u_short vlr_tag; 8854331Sarchie}; 8954331Sarchie#define SIOCSETVLAN SIOCSIFGENERIC 9054331Sarchie#define SIOCGETVLAN SIOCGIFGENERIC 9154331Sarchie 9254331Sarchie#ifdef _KERNEL 9354331Sarchie/* 9454331Sarchie * Drivers that are capable of adding and removing the VLAN header 9554331Sarchie * in hardware indicate they support this by marking IFCAP_VLAN_HWTAGGING 9654331Sarchie * in if_capabilities. Drivers for hardware that is capable 9754331Sarchie * of handling larger MTU's that may include a software-appended 9854331Sarchie * VLAN header w/o lowering the normal MTU should mark IFCAP_VLAN_MTU 9954331Sarchie * in if_capabilities; this notifies the VLAN code it can leave the 10054331Sarchie * MTU on the vlan interface at the normal setting. 10154331Sarchie */ 10254331Sarchie 10354331Sarchie/* 10454331Sarchie * VLAN tags are stored in host byte order. Byte swapping may be 10554331Sarchie * necessary. 10654331Sarchie * 10754331Sarchie * Drivers that support hardware VLAN tag stripping fill in the 10854331Sarchie * received VLAN tag (containing both vlan and priority information) 10954331Sarchie * into the ether_vtag mbuf packet header field: 11054331Sarchie * 11154331Sarchie * m->m_pkthdr.ether_vtag = vlan_id; // ntohs()? 11254331Sarchie * m->m_flags |= M_VLANTAG; 11354331Sarchie * 11454331Sarchie * to mark the packet m with the specified VLAN tag. 11554331Sarchie * 11662222Sarchie * On output the driver should check the mbuf for the M_VLANTAG 11763822Sarchie * flag to see if a VLAN tag is present and valid: 11854331Sarchie * 11954331Sarchie * if (m->m_flags & M_VLANTAG) { 12062222Sarchie * ... = m->m_pkthdr.ether_vtag; // htons()? 12162222Sarchie * ... pass tag to hardware ... 12294667Sarchie * } 123134865Sglebius * 12454331Sarchie * Note that a driver must indicate it supports hardware VLAN 12563852Sarchie * stripping/insertion by marking IFCAP_VLAN_HWTAGGING in 12663852Sarchie * if_capabilities. 12763852Sarchie */ 12863852Sarchie 12963852Sarchie#define VLAN_CAPABILITIES(_ifp) do { \ 13063852Sarchie if ((_ifp)->if_vlantrunk != NULL) \ 13163852Sarchie (*vlan_trunk_cap_p)(_ifp); \ 13262222Sarchie} while (0) 13354331Sarchie 13454331Sarchieextern void (*vlan_trunk_cap_p)(struct ifnet *); 13554331Sarchie#endif /* _KERNEL */ 13654331Sarchie 13754331Sarchie#endif /* _NET_IF_VLAN_VAR_H_ */ 13860009Sarchie