Home | History | Annotate | Line # | Download | only in net
if_gre.h revision 1.38
      1 /*	$NetBSD: if_gre.h,v 1.38 2008/05/15 04:03:53 dyoung Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1998, 2008 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  * This code is derived from software contributed to The NetBSD Foundation
     11  * by David Young <dyoung (at) NetBSD.org>
     12  *
     13  * Redistribution and use in source and binary forms, with or without
     14  * modification, are permitted provided that the following conditions
     15  * are met:
     16  * 1. Redistributions of source code must retain the above copyright
     17  *    notice, this list of conditions and the following disclaimer.
     18  * 2. Redistributions in binary form must reproduce the above copyright
     19  *    notice, this list of conditions and the following disclaimer in the
     20  *    documentation and/or other materials provided with the distribution.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     32  * POSSIBILITY OF SUCH DAMAGE.
     33  *
     34  * This material is based upon work partially supported by NSF
     35  * under Contract No. NSF CNS-0626584.
     36  */
     37 
     38 #ifndef _NET_IF_GRE_H_
     39 #define _NET_IF_GRE_H_
     40 
     41 #include <sys/evcnt.h>
     42 #include <sys/queue.h>
     43 #include <sys/mutex.h>
     44 #include <sys/condvar.h>
     45 #include <sys/malloc.h>
     46 #include <sys/mallocvar.h>
     47 
     48 #ifdef _KERNEL
     49 struct gre_soparm {
     50 	struct socket		*sp_so;
     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 	bool		sp_bysock;	/* encapsulation configured by passing
     56 					 * socket, not by SIOCSLIFPHYADDR
     57 					 */
     58 };
     59 
     60 enum gre_state {
     61 	  GRE_S_IDLE = 0
     62 	, GRE_S_IOCTL
     63 	, GRE_S_DIE
     64 };
     65 
     66 #define	__cacheline_aligned	__attribute__((__aligned__(CACHE_LINE_SIZE)))
     67 
     68 struct gre_bufq {
     69 	volatile int	bq_prodidx;
     70 	volatile int	bq_considx;
     71 	size_t		bq_len __cacheline_aligned;
     72 	size_t		bq_lenmask;
     73 	volatile int	bq_drops;
     74 	struct mbuf	**bq_buf;
     75 };
     76 
     77 MALLOC_DECLARE(M_GRE_BUFQ);
     78 
     79 enum gre_msg {
     80 	  GRE_M_NONE = 0
     81 	, GRE_M_SETFP
     82 	, GRE_M_DELFP
     83 	, GRE_M_STOP
     84 	, GRE_M_OK
     85 	, GRE_M_ERR
     86 };
     87 
     88 struct gre_softc {
     89 	struct ifnet		sc_if;
     90 	kmutex_t		sc_mtx;
     91 	kcondvar_t		sc_condvar;
     92 	kcondvar_t		sc_fp_condvar;
     93 	struct gre_bufq		sc_snd;
     94 	struct gre_soparm	sc_soparm;
     95 	volatile enum gre_state	sc_state;
     96 	volatile int		sc_waiters;
     97 	volatile int		sc_fp_waiters;
     98 	void			*sc_si;
     99 
    100 	struct evcnt		sc_recv_ev;
    101 	struct evcnt		sc_send_ev;
    102 
    103 	struct evcnt		sc_block_ev;
    104 	struct evcnt		sc_error_ev;
    105 	struct evcnt		sc_pullup_ev;
    106 	struct evcnt		sc_unsupp_ev;
    107 	struct evcnt		sc_oflow_ev;
    108 	file_t	* volatile	sc_fp;
    109 	volatile enum gre_msg	sc_msg;
    110 	int			sc_fd;
    111 };
    112 
    113 struct gre_h {
    114 	uint16_t flags;		/* GRE flags */
    115 	uint16_t ptype;		/* protocol type of payload typically
    116 				 * ethernet protocol type
    117 				 */
    118 /*
    119  *  from here on: fields are optional, presence indicated by flags
    120  *
    121 	u_int_16 checksum	checksum (one-complements of GRE header
    122 				and payload
    123 				Present if (ck_pres | rt_pres == 1).
    124 				Valid if (ck_pres == 1).
    125 	u_int_16 offset		offset from start of routing filed to
    126 				first octet of active SRE (see below).
    127 				Present if (ck_pres | rt_pres == 1).
    128 				Valid if (rt_pres == 1).
    129 	u_int_32 key		inserted by encapsulator e.g. for
    130 				authentication
    131 				Present if (key_pres ==1 ).
    132 	u_int_32 seq_num	Sequence number to allow for packet order
    133 				Present if (seq_pres ==1 ).
    134 	struct gre_sre[] routing Routing fileds (see below)
    135 				Present if (rt_pres == 1)
    136  */
    137 } __packed;
    138 
    139 #define GRE_CP		0x8000  /* Checksum Present */
    140 #define GRE_RP		0x4000  /* Routing Present */
    141 #define GRE_KP		0x2000  /* Key Present */
    142 #define GRE_SP		0x1000  /* Sequence Present */
    143 #define GRE_SS		0x0800	/* Strict Source Route */
    144 
    145 /*
    146  * gre_sre defines a Source route Entry. These are needed if packets
    147  * should be routed over more than one tunnel hop by hop
    148  */
    149 struct gre_sre {
    150 	uint16_t sre_family;	/* address family */
    151 	u_char	sre_offset;	/* offset to first octet of active entry */
    152 	u_char	sre_length;	/* number of octets in the SRE.
    153 				   sre_lengthl==0 -> last entry. */
    154 	u_char	*sre_rtinfo;	/* the routing information */
    155 };
    156 
    157 #define	GRE_TTL	30
    158 extern int ip_gre_ttl;
    159 #endif /* _KERNEL */
    160 
    161 /*
    162  * ioctls needed to manipulate the interface
    163  */
    164 
    165 #define GRESADDRS	_IOW('i', 101, struct ifreq)
    166 #define GRESADDRD	_IOW('i', 102, struct ifreq)
    167 #define GREGADDRS	_IOWR('i', 103, struct ifreq)
    168 #define GREGADDRD	_IOWR('i', 104, struct ifreq)
    169 #define GRESPROTO	_IOW('i' , 105, struct ifreq)
    170 #define GREGPROTO	_IOWR('i', 106, struct ifreq)
    171 #define GRESSOCK	_IOW('i' , 107, struct ifreq)
    172 #define GREDSOCK	_IOW('i' , 108, struct ifreq)
    173 
    174 #endif /* !_NET_IF_GRE_H_ */
    175