Home | History | Annotate | Line # | Download | only in net
if_gre.h revision 1.34
      1 /*	$NetBSD: if_gre.h,v 1.34 2008/02/12 00:53:06 dyoung Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Heiko W.Rupp <hwr (at) pilhuhn.de>
      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  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _NET_IF_GRE_H_
     40 #define _NET_IF_GRE_H_
     41 
     42 #include <sys/evcnt.h>
     43 #include <sys/queue.h>
     44 #include <sys/mutex.h>
     45 #include <sys/condvar.h>
     46 #include <sys/malloc.h>
     47 #include <sys/mallocvar.h>
     48 
     49 #ifdef _KERNEL
     50 struct gre_soparm {
     51 	struct sockaddr_storage sp_src;	/* source of gre packets */
     52 	struct sockaddr_storage sp_dst;	/* destination of gre packets */
     53 	int		sp_type;	/* encapsulating socket type */
     54 	int		sp_proto;	/* encapsulating protocol */
     55 	int		sp_fd;
     56 	int		sp_bysock;	/* encapsulation configured by passing
     57 					 * socket, not by SIOCSLIFPHYADDR
     58 					 */
     59 };
     60 
     61 enum gre_state {
     62 	  GRE_S_IDLE = 0
     63 	, GRE_S_IOCTL
     64 	, GRE_S_DIE
     65 };
     66 
     67 #define	__cacheline_aligned	__attribute__((__aligned__(CACHE_LINE_SIZE)))
     68 
     69 struct gre_bufq {
     70 	volatile int	bq_prodidx;
     71 	volatile int	bq_considx;
     72 	size_t		bq_len __cacheline_aligned;
     73 	size_t		bq_lenmask;
     74 	volatile int	bq_drops;
     75 	struct mbuf	**bq_buf;
     76 };
     77 
     78 MALLOC_DECLARE(M_GRE_BUFQ);
     79 
     80 struct gre_softc {
     81 	struct ifnet		sc_if;
     82 	kmutex_t		sc_mtx;
     83 	kcondvar_t		sc_condvar;
     84 	struct gre_bufq		sc_snd;
     85 	struct gre_soparm	sc_soparm;
     86 	struct lwp		*sc_lwp;
     87 	volatile enum gre_state	sc_state;
     88 	volatile int		sc_waiters;
     89 	volatile int		sc_upcalls;
     90 	void			*sc_si;
     91 	struct socket		*sc_so;
     92 
     93 	struct evcnt		sc_recv_ev;
     94 	struct evcnt		sc_send_ev;
     95 
     96 	struct evcnt		sc_block_ev;
     97 	struct evcnt		sc_error_ev;
     98 	struct evcnt		sc_pullup_ev;
     99 	struct evcnt		sc_unsupp_ev;
    100 	struct evcnt		sc_oflow_ev;
    101 };
    102 
    103 struct gre_h {
    104 	uint16_t flags;		/* GRE flags */
    105 	uint16_t ptype;		/* protocol type of payload typically
    106 				 * ethernet protocol type
    107 				 */
    108 /*
    109  *  from here on: fields are optional, presence indicated by flags
    110  *
    111 	u_int_16 checksum	checksum (one-complements of GRE header
    112 				and payload
    113 				Present if (ck_pres | rt_pres == 1).
    114 				Valid if (ck_pres == 1).
    115 	u_int_16 offset		offset from start of routing filed to
    116 				first octet of active SRE (see below).
    117 				Present if (ck_pres | rt_pres == 1).
    118 				Valid if (rt_pres == 1).
    119 	u_int_32 key		inserted by encapsulator e.g. for
    120 				authentication
    121 				Present if (key_pres ==1 ).
    122 	u_int_32 seq_num	Sequence number to allow for packet order
    123 				Present if (seq_pres ==1 ).
    124 	struct gre_sre[] routing Routing fileds (see below)
    125 				Present if (rt_pres == 1)
    126  */
    127 } __packed;
    128 
    129 #define GRE_CP		0x8000  /* Checksum Present */
    130 #define GRE_RP		0x4000  /* Routing Present */
    131 #define GRE_KP		0x2000  /* Key Present */
    132 #define GRE_SP		0x1000  /* Sequence Present */
    133 #define GRE_SS		0x0800	/* Strict Source Route */
    134 
    135 /*
    136  * gre_sre defines a Source route Entry. These are needed if packets
    137  * should be routed over more than one tunnel hop by hop
    138  */
    139 struct gre_sre {
    140 	u_int16_t sre_family;	/* address family */
    141 	u_char	sre_offset;	/* offset to first octet of active entry */
    142 	u_char	sre_length;	/* number of octets in the SRE.
    143 				   sre_lengthl==0 -> last entry. */
    144 	u_char	*sre_rtinfo;	/* the routing information */
    145 };
    146 
    147 #define	GRE_TTL	30
    148 extern int ip_gre_ttl;
    149 #endif /* _KERNEL */
    150 
    151 /*
    152  * ioctls needed to manipulate the interface
    153  */
    154 
    155 #define GRESADDRS	_IOW('i', 101, struct ifreq)
    156 #define GRESADDRD	_IOW('i', 102, struct ifreq)
    157 #define GREGADDRS	_IOWR('i', 103, struct ifreq)
    158 #define GREGADDRD	_IOWR('i', 104, struct ifreq)
    159 #define GRESPROTO	_IOW('i' , 105, struct ifreq)
    160 #define GREGPROTO	_IOWR('i', 106, struct ifreq)
    161 #define GRESSOCK	_IOW('i' , 107, struct ifreq)
    162 #define GREDSOCK	_IOW('i' , 108, struct ifreq)
    163 
    164 #endif /* !_NET_IF_GRE_H_ */
    165