xref: /freebsd/sys/net/if_vlan_var.h (revision c398230b64aea809cb7c5cea8db580af7097920c)
1c398230bSWarner Losh /*-
22cc2df49SGarrett Wollman  * Copyright 1998 Massachusetts Institute of Technology
32cc2df49SGarrett Wollman  *
42cc2df49SGarrett Wollman  * Permission to use, copy, modify, and distribute this software and
52cc2df49SGarrett Wollman  * its documentation for any purpose and without fee is hereby
62cc2df49SGarrett Wollman  * granted, provided that both the above copyright notice and this
72cc2df49SGarrett Wollman  * permission notice appear in all copies, that both the above
82cc2df49SGarrett Wollman  * copyright notice and this permission notice appear in all
92cc2df49SGarrett Wollman  * supporting documentation, and that the name of M.I.T. not be used
102cc2df49SGarrett Wollman  * in advertising or publicity pertaining to distribution of the
112cc2df49SGarrett Wollman  * software without specific, written prior permission.  M.I.T. makes
122cc2df49SGarrett Wollman  * no representations about the suitability of this software for any
132cc2df49SGarrett Wollman  * purpose.  It is provided "as is" without express or implied
142cc2df49SGarrett Wollman  * warranty.
152cc2df49SGarrett Wollman  *
162cc2df49SGarrett Wollman  * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
172cc2df49SGarrett Wollman  * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
182cc2df49SGarrett Wollman  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
192cc2df49SGarrett Wollman  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
202cc2df49SGarrett Wollman  * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212cc2df49SGarrett Wollman  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222cc2df49SGarrett Wollman  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
232cc2df49SGarrett Wollman  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
242cc2df49SGarrett Wollman  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
252cc2df49SGarrett Wollman  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
262cc2df49SGarrett Wollman  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
272cc2df49SGarrett Wollman  * SUCH DAMAGE.
282cc2df49SGarrett Wollman  *
29c3aac50fSPeter Wemm  * $FreeBSD$
302cc2df49SGarrett Wollman  */
312cc2df49SGarrett Wollman 
322cc2df49SGarrett Wollman #ifndef _NET_IF_VLAN_VAR_H_
332cc2df49SGarrett Wollman #define	_NET_IF_VLAN_VAR_H_	1
342cc2df49SGarrett Wollman 
352cc2df49SGarrett Wollman struct	ether_vlan_header {
362cc2df49SGarrett Wollman 	u_char	evl_dhost[ETHER_ADDR_LEN];
372cc2df49SGarrett Wollman 	u_char	evl_shost[ETHER_ADDR_LEN];
382cc2df49SGarrett Wollman 	u_int16_t evl_encap_proto;
392cc2df49SGarrett Wollman 	u_int16_t evl_tag;
402cc2df49SGarrett Wollman 	u_int16_t evl_proto;
412cc2df49SGarrett Wollman };
422cc2df49SGarrett Wollman 
43fb88a3e0SBill Paul #define EVL_VLID_MASK	0x0FFF
44fb88a3e0SBill Paul #define	EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK)
452cc2df49SGarrett Wollman #define	EVL_PRIOFTAG(tag) (((tag) >> 13) & 7)
462cc2df49SGarrett Wollman 
472cc2df49SGarrett Wollman /* sysctl(3) tags, for compatibility purposes */
482cc2df49SGarrett Wollman #define	VLANCTL_PROTO	1
492cc2df49SGarrett Wollman #define	VLANCTL_MAX	2
502cc2df49SGarrett Wollman 
512cc2df49SGarrett Wollman /*
522cc2df49SGarrett Wollman  * Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls.
532cc2df49SGarrett Wollman  */
542cc2df49SGarrett Wollman struct	vlanreq {
552cc2df49SGarrett Wollman 	char	vlr_parent[IFNAMSIZ];
562cc2df49SGarrett Wollman 	u_short	vlr_tag;
572cc2df49SGarrett Wollman };
582cc2df49SGarrett Wollman #define	SIOCSETVLAN	SIOCSIFGENERIC
592cc2df49SGarrett Wollman #define	SIOCGETVLAN	SIOCGIFGENERIC
602cc2df49SGarrett Wollman 
61a3814acfSSam Leffler #ifdef _KERNEL
62a3814acfSSam Leffler /*
63a3814acfSSam Leffler  * Drivers that are capable of adding and removing the VLAN header
64a3814acfSSam Leffler  * in hardware indicate they support this by marking IFCAP_VLAN_HWTAGGING
65a4e16dddSYaroslav Tykhiy  * in if_capabilities.  Drivers for hardware that is capable
66a3814acfSSam Leffler  * of handling larger MTU's that may include a software-appended
67a4e16dddSYaroslav Tykhiy  * VLAN header w/o lowering the normal MTU should mark IFCAP_VLAN_MTU
68a4e16dddSYaroslav Tykhiy  * in if_capabilities; this notifies the VLAN code it can leave the
69a3814acfSSam Leffler  * MTU on the vlan interface at the normal setting.
70a3814acfSSam Leffler  */
71a3814acfSSam Leffler 
72a3814acfSSam Leffler /*
73a3814acfSSam Leffler  * Drivers that support hardware VLAN tagging pass a packet's tag
74a3814acfSSam Leffler  * up through the stack by appending a packet tag with this value.
75a3814acfSSam Leffler  * Output is handled likewise, the driver must locate the packet
76a3814acfSSam Leffler  * tag to extract the VLAN tag.  The following macros are used to
77a3814acfSSam Leffler  * do this work.  On input, do:
78a3814acfSSam Leffler  *
79a3814acfSSam Leffler  *	VLAN_INPUT_TAG(ifp, m, tag,);
80a3814acfSSam Leffler  *
81a3814acfSSam Leffler  * to mark the packet m with the specified VLAN tag.  The last
82a3814acfSSam Leffler  * parameter provides code to execute in case of an error.  On
83a3814acfSSam Leffler  * output the driver should check ifnet to see if any VLANs are
84a3814acfSSam Leffler  * in use and only then check for a packet tag; this is done with:
85a3814acfSSam Leffler  *
86a3814acfSSam Leffler  *	struct m_tag *mtag;
87a3814acfSSam Leffler  *	mtag = VLAN_OUTPUT_TAG(ifp, m);
88a3814acfSSam Leffler  *	if (mtag != NULL) {
89a3814acfSSam Leffler  *		... = VLAN_TAG_VALUE(mtag);
90a3814acfSSam Leffler  *		... pass tag to hardware ...
91a3814acfSSam Leffler  *	}
92a3814acfSSam Leffler  *
93a3814acfSSam Leffler  * Note that a driver must indicate it supports hardware VLAN
94a3814acfSSam Leffler  * tagging by marking IFCAP_VLAN_HWTAGGING in if_capabilities.
95a3814acfSSam Leffler  */
96a3814acfSSam Leffler #define	MTAG_VLAN	1035328035
97a3814acfSSam Leffler #define	MTAG_VLAN_TAG	0		/* tag of VLAN interface */
98a3814acfSSam Leffler 
99a3814acfSSam Leffler #define	VLAN_INPUT_TAG(_ifp, _m, _t, _errcase) do {		\
100a3814acfSSam Leffler 	struct m_tag *mtag;					\
1015016de40SSam Leffler 	mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG,		\
1025016de40SSam Leffler 			   sizeof (u_int), M_NOWAIT);		\
103a3814acfSSam Leffler 	if (mtag == NULL) {					\
104a3814acfSSam Leffler 		(_ifp)->if_ierrors++;				\
105a3814acfSSam Leffler 		m_freem(_m);					\
106a3814acfSSam Leffler 		_errcase;					\
107a3814acfSSam Leffler 	}							\
108a3814acfSSam Leffler 	*(u_int *)(mtag+1) = (_t);				\
109a3814acfSSam Leffler 	m_tag_prepend((_m), mtag);				\
110a3814acfSSam Leffler } while (0)
111a3814acfSSam Leffler 
112a3814acfSSam Leffler #define	VLAN_OUTPUT_TAG(_ifp, _m)				\
113a3814acfSSam Leffler 	((_ifp)->if_nvlans != 0 ?				\
114a3814acfSSam Leffler 		m_tag_locate((_m), MTAG_VLAN, MTAG_VLAN_TAG, NULL) : NULL)
115a3814acfSSam Leffler #define	VLAN_TAG_VALUE(_mt)	(*(u_int *)((_mt)+1))
116a3814acfSSam Leffler #endif /* _KERNEL */
117a3814acfSSam Leffler 
1182cc2df49SGarrett Wollman #endif /* _NET_IF_VLAN_VAR_H_ */
119