if_vlanvar.h revision 1.10 1 /* $NetBSD: if_vlanvar.h,v 1.10 2017/06/07 03:53:11 knakahara Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Andrew Doran.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 /*
33 * Copyright 1998 Massachusetts Institute of Technology
34 *
35 * Permission to use, copy, modify, and distribute this software and
36 * its documentation for any purpose and without fee is hereby
37 * granted, provided that both the above copyright notice and this
38 * permission notice appear in all copies, that both the above
39 * copyright notice and this permission notice appear in all
40 * supporting documentation, and that the name of M.I.T. not be used
41 * in advertising or publicity pertaining to distribution of the
42 * software without specific, written prior permission. M.I.T. makes
43 * no representations about the suitability of this software for any
44 * purpose. It is provided "as is" without express or implied
45 * warranty.
46 *
47 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS
48 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
49 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
50 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
51 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
53 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
54 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
55 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
56 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
57 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * from FreeBSD: if_vlan_var.h,v 1.3 1999/08/28 00:48:24 peter Exp
61 */
62
63 #ifndef _NET_IF_VLANVAR_H_
64 #define _NET_IF_VLANVAR_H_
65
66 struct ether_vlan_header {
67 uint8_t evl_dhost[ETHER_ADDR_LEN];
68 uint8_t evl_shost[ETHER_ADDR_LEN];
69 uint16_t evl_encap_proto;
70 uint16_t evl_tag;
71 uint16_t evl_proto;
72 } __packed;
73
74 #define EVL_VLANOFTAG(tag) ((tag) & 4095)
75 #define EVL_PRIOFTAG(tag) (((tag) >> 13) & 7)
76
77 /* Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls. */
78 struct vlanreq {
79 char vlr_parent[IFNAMSIZ];
80 u_short vlr_tag;
81 };
82
83 #define SIOCSETVLAN SIOCSIFGENERIC
84 #define SIOCGETVLAN SIOCGIFGENERIC
85
86 #ifdef _KERNEL
87 void vlan_input(struct ifnet *, struct mbuf *);
88 void vlan_ifdetach(struct ifnet *);
89
90 /*
91 * Locking notes:
92 * + ifv_list.list is protected by ifv_list.lock (an adaptive mutex)
93 * ifv_list.list is list of all ifvlans, and it is used to avoid
94 * unload while busy.
95 * + ifv_hash.lists is protected by
96 * - ifv_hash.lock (an adaptive mutex) for writer
97 * - pserialize for reader
98 * ifv_hash.lists is hashed list of all configured
99 * vlan interface, and it is used to avoid unload while busy.
100 * + ifvlan->ifv_linkmib is protected by
101 * - ifvlan->ifv_lock (an adaptive mutex) for writer
102 * - ifv_linkmib->ifvm_psref for reader
103 * ifvlan->ifv_linkmib is used for variant values while tagging
104 * and untagging
105 *
106 * Locking order:
107 * - ifv_list.lock => struct ifvlan->ifv_lock
108 * - struct ifvlan->ifv_lock => ifv_hash.lock
109 * Other mutexes must not hold simultaneously
110 *
111 * NOTICE
112 * - ifvlan must not have a variant value while tagging and
113 * untagging. Such variant values must be in ifvlan->ifv_mib
114 * - ifvlan->ifv_mib is modified like read-copy-update.
115 * So, once we dereference ifvlan->ifv_mib,
116 * we must keep the pointer during the same context. If we
117 * re-dereference ifvlan->ifv_mib, the ifv_mib may be other
118 * one because of concurrent writer processing.
119 */
120 #endif /* _KERNEL */
121
122 #endif /* !_NET_IF_VLANVAR_H_ */
123