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