if_vlan_var.h revision 124096
1207753Smm/* 2207753Smm * Copyright 1998 Massachusetts Institute of Technology 3207753Smm * 4207753Smm * Permission to use, copy, modify, and distribute this software and 5207753Smm * its documentation for any purpose and without fee is hereby 6207753Smm * granted, provided that both the above copyright notice and this 7207753Smm * permission notice appear in all copies, that both the above 8207753Smm * copyright notice and this permission notice appear in all 9207753Smm * supporting documentation, and that the name of M.I.T. not be used 10207753Smm * in advertising or publicity pertaining to distribution of the 11207753Smm * software without specific, written prior permission. M.I.T. makes 12207753Smm * no representations about the suitability of this software for any 13207753Smm * purpose. It is provided "as is" without express or implied 14207753Smm * warranty. 15207753Smm * 16207753Smm * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 17207753Smm * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 18207753Smm * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19207753Smm * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 20207753Smm * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21207753Smm * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22207753Smm * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23207753Smm * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24207753Smm * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25207753Smm * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 26207753Smm * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27207753Smm * SUCH DAMAGE. 28207753Smm * 29207753Smm * $FreeBSD: head/sys/net/if_vlan_var.h 124096 2004-01-03 03:33:39Z sam $ 30207753Smm */ 31207753Smm 32207753Smm#ifndef _NET_IF_VLAN_VAR_H_ 33207753Smm#define _NET_IF_VLAN_VAR_H_ 1 34207753Smm 35207753Smmstruct ether_vlan_header { 36207753Smm u_char evl_dhost[ETHER_ADDR_LEN]; 37207753Smm u_char evl_shost[ETHER_ADDR_LEN]; 38207753Smm u_int16_t evl_encap_proto; 39207753Smm u_int16_t evl_tag; 40207753Smm u_int16_t evl_proto; 41207753Smm}; 42207753Smm 43207753Smm#define EVL_VLID_MASK 0x0FFF 44207753Smm#define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK) 45207753Smm#define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7) 46207753Smm 47207753Smm/* sysctl(3) tags, for compatibility purposes */ 48207753Smm#define VLANCTL_PROTO 1 49207753Smm#define VLANCTL_MAX 2 50207753Smm 51207753Smm/* 52207753Smm * Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls. 53207753Smm */ 54207753Smmstruct vlanreq { 55207753Smm char vlr_parent[IFNAMSIZ]; 56207753Smm u_short vlr_tag; 57207753Smm}; 58207753Smm#define SIOCSETVLAN SIOCSIFGENERIC 59207753Smm#define SIOCGETVLAN SIOCGIFGENERIC 60207753Smm 61207753Smm#ifdef _KERNEL 62207753Smm/* 63207753Smm * Drivers that are capable of adding and removing the VLAN header 64207753Smm * in hardware indicate they support this by marking IFCAP_VLAN_HWTAGGING 65207753Smm * in if_capabilities. Drivers for hardware that is also capable 66207753Smm * of handling larger MTU's that may include a software-appended 67207753Smm * VLAN header w/o lowering the normal MTU should mark IFCAP_VLA_MTU 68207753Smm * in if_capabilities; this notfies the VLAN code it can leave the 69207753Smm * MTU on the vlan interface at the normal setting. 70207753Smm */ 71207753Smm 72207753Smm/* 73207753Smm * Drivers that support hardware VLAN tagging pass a packet's tag 74207753Smm * up through the stack by appending a packet tag with this value. 75207753Smm * Output is handled likewise, the driver must locate the packet 76207753Smm * tag to extract the VLAN tag. The following macros are used to 77207753Smm * do this work. On input, do: 78207753Smm * 79207753Smm * VLAN_INPUT_TAG(ifp, m, tag,); 80207753Smm * 81207753Smm * to mark the packet m with the specified VLAN tag. The last 82207753Smm * parameter provides code to execute in case of an error. On 83207753Smm * output the driver should check ifnet to see if any VLANs are 84207753Smm * in use and only then check for a packet tag; this is done with: 85207753Smm * 86207753Smm * struct m_tag *mtag; 87207753Smm * mtag = VLAN_OUTPUT_TAG(ifp, m); 88207753Smm * if (mtag != NULL) { 89207753Smm * ... = VLAN_TAG_VALUE(mtag); 90207753Smm * ... pass tag to hardware ... 91207753Smm * } 92207753Smm * 93207753Smm * Note that a driver must indicate it supports hardware VLAN 94207753Smm * tagging by marking IFCAP_VLAN_HWTAGGING in if_capabilities. 95207753Smm */ 96207753Smm#define MTAG_VLAN 1035328035 97207753Smm#define MTAG_VLAN_TAG 0 /* tag of VLAN interface */ 98207753Smm 99207753Smm#define VLAN_INPUT_TAG(_ifp, _m, _t, _errcase) do { \ 100207753Smm struct m_tag *mtag; \ 101207753Smm mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG, \ 102207753Smm sizeof (u_int), M_NOWAIT); \ 103207753Smm if (mtag == NULL) { \ 104207753Smm (_ifp)->if_ierrors++; \ 105207753Smm m_freem(_m); \ 106207753Smm _errcase; \ 107207753Smm } \ 108207753Smm *(u_int *)(mtag+1) = (_t); \ 109207753Smm m_tag_prepend((_m), mtag); \ 110207753Smm} while (0) 111207753Smm 112207753Smm#define VLAN_OUTPUT_TAG(_ifp, _m) \ 113207753Smm ((_ifp)->if_nvlans != 0 ? \ 114207753Smm m_tag_locate((_m), MTAG_VLAN, MTAG_VLAN_TAG, NULL) : NULL) 115207753Smm#define VLAN_TAG_VALUE(_mt) (*(u_int *)((_mt)+1)) 116207753Smm#endif /* _KERNEL */ 117207753Smm 118207753Smm#endif /* _NET_IF_VLAN_VAR_H_ */ 119207753Smm