Home | History | Annotate | Line # | Download | only in net
      1 /*	$NetBSD: if_vlanvar.h,v 1.17 2022/06/20 08:02:25 yamaguchi 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 /* Configuration structure for SIOCSETVLAN and SIOCGETVLAN ioctls. */
     75 struct vlanreq {
     76 	char		vlr_parent[IFNAMSIZ];
     77 	uint16_t	vlr_tag;
     78 };
     79 
     80 #define	SIOCSETVLAN	SIOCSIFGENERIC
     81 #define	SIOCGETVLAN	SIOCGIFGENERIC
     82 
     83 #ifdef _KERNEL
     84 struct mbuf *	vlan_input(struct ifnet *, struct mbuf *);
     85 
     86 /*
     87  * Locking notes:
     88  * + ifv_list.list is protected by ifv_list.lock (an adaptive mutex)
     89  *     ifv_list.list is list of all ifvlans, and it is used to avoid
     90  *     unload while busy.
     91  * + ifv_hash.lists is protected by
     92  *   - ifv_hash.lock (an adaptive mutex) for writer
     93  *   - pserialize for reader
     94  *     ifv_hash.lists is hashed list of all configured
     95  *     vlan interface, and it is used to avoid unload while busy.
     96  * + ifvlan->ifv_linkmib is protected by
     97  *   - ifvlan->ifv_lock (an adaptive mutex) for writer
     98  *   - ifv_linkmib->ifvm_psref for reader
     99  *     ifvlan->ifv_linkmib is used for variant values while tagging
    100  *     and untagging
    101  *
    102  * Locking order:
    103  *     - ifv_list.lock => struct ifvlan->ifv_lock
    104  *     - struct ifvlan->ifv_lock => ifv_hash.lock
    105  * Other mutexes must not hold simultaneously
    106  *
    107  *   NOTICE
    108  *     - ifvlan must not have a variant value while tagging and
    109  *       untagging. Such variant values must be in ifvlan->ifv_mib
    110  *     - ifvlan->ifv_mib is modified like read-copy-update.
    111  *       So, once we dereference ifvlan->ifv_mib,
    112  *       we must keep the pointer during the same context. If we
    113  *       re-dereference ifvlan->ifv_mib, the ifv_mib may be other
    114  *       one because of concurrent writer processing.
    115  */
    116 #endif	/* _KERNEL */
    117 
    118 #endif	/* !_NET_IF_VLANVAR_H_ */
    119