FreeBSD/Linux Kernel Cross Reference
sys/net/if_vlan_var.h
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$
30 */
31
32 #ifndef _NET_IF_VLAN_VAR_H_
33 #define _NET_IF_VLAN_VAR_H_ 1
34
35 struct ether_vlan_header {
36 u_char evl_dhost[ETHER_ADDR_LEN];
37 u_char evl_shost[ETHER_ADDR_LEN];
38 u_int16_t evl_encap_proto;
39 u_int16_t evl_tag;
40 u_int16_t evl_proto;
41 };
42
43 #define EVL_VLID_MASK 0x0FFF
44 #define EVL_VLANOFTAG(tag) ((tag) & EVL_VLID_MASK)
45 #define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7)
46
47 /* sysctl(3) tags, for compatibility purposes */
48 #define VLANCTL_PROTO 1
49 #define VLANCTL_MAX 2
50
51 /*
52 * Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls.
53 */
54 struct vlanreq {
55 char vlr_parent[IFNAMSIZ];
56 u_short vlr_tag;
57 };
58 #define SIOCSETVLAN SIOCSIFGENERIC
59 #define SIOCGETVLAN SIOCGIFGENERIC
60
61 #ifdef _KERNEL
62 /*
63 * Drivers that are capable of adding and removing the VLAN header
64 * in hardware indicate they support this by marking IFCAP_VLAN_HWTAGGING
65 * in if_capabilities. Drivers for hardware that is capable
66 * of handling larger MTU's that may include a software-appended
67 * VLAN header w/o lowering the normal MTU should mark IFCAP_VLAN_MTU
68 * in if_capabilities; this notifies the VLAN code it can leave the
69 * MTU on the vlan interface at the normal setting.
70 */
71
72 /*
73 * Drivers that support hardware VLAN tagging pass a packet's tag
74 * up through the stack by appending a packet tag with this value.
75 * Output is handled likewise, the driver must locate the packet
76 * tag to extract the VLAN tag. The following macros are used to
77 * do this work. On input, do:
78 *
79 * VLAN_INPUT_TAG(ifp, m, tag,);
80 *
81 * to mark the packet m with the specified VLAN tag. The last
82 * parameter provides code to execute in case of an error. On
83 * output the driver should check mbuf to see if a VLAN tag is
84 * present and only then check for a tag; this is done with:
85 *
86 * struct m_tag *mtag;
87 * mtag = VLAN_OUTPUT_TAG(ifp, m);
88 * if (mtag != NULL) {
89 * ... = VLAN_TAG_VALUE(mtag);
90 * ... pass tag to hardware ...
91 * }
92 *
93 * Note that a driver must indicate it supports hardware VLAN
94 * tagging by marking IFCAP_VLAN_HWTAGGING in if_capabilities.
95 */
96 #define MTAG_VLAN 1035328035
97 #define MTAG_VLAN_TAG 0 /* tag of VLAN interface */
98
99 /*
100 * This macro must expand to a lvalue so that it can be used
101 * to set a tag with a simple assignment.
102 */
103 #define VLAN_TAG_VALUE(_mt) (*(u_int *)((_mt) + 1))
104
105 /*
106 * This macro is kept for API compatibility.
107 */
108 #define VLAN_INPUT_TAG(_ifp, _m, _t, _errcase) do { \
109 struct m_tag *mtag; \
110 mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG, \
111 sizeof (u_int), M_NOWAIT); \
112 if (mtag != NULL) { \
113 VLAN_TAG_VALUE(mtag) = (_t); \
114 m_tag_prepend((_m), mtag); \
115 (_m)->m_flags |= M_VLANTAG; \
116 } else { \
117 (_ifp)->if_ierrors++; \
118 m_freem(_m); \
119 _errcase; \
120 } \
121 } while (0)
122
123 /*
124 * This macro is equal to VLAN_INPUT_TAG() in HEAD.
125 */
126 #define VLAN_INPUT_TAG_NEW(_ifp, _m, _t) do { \
127 struct m_tag *mtag; \
128 mtag = m_tag_alloc(MTAG_VLAN, MTAG_VLAN_TAG, \
129 sizeof (u_int), M_NOWAIT); \
130 if (mtag != NULL) { \
131 VLAN_TAG_VALUE(mtag) = (_t); \
132 m_tag_prepend((_m), mtag); \
133 (_m)->m_flags |= M_VLANTAG; \
134 } else { \
135 (_ifp)->if_ierrors++; \
136 m_freem(_m); \
137 _m = NULL; \
138 } \
139 } while (0)
140
141 #define VLAN_OUTPUT_TAG(_ifp, _m) \
142 ((_m)->m_flags & M_VLANTAG ? \
143 m_tag_locate((_m), MTAG_VLAN, MTAG_VLAN_TAG, NULL) : NULL)
144 #endif /* _KERNEL */
145
146 #endif /* _NET_IF_VLAN_VAR_H_ */
Cache object: cf45b9ae451a21cab10c0fe1fa8ab169
|