Home | History | Annotate | Line # | Download | only in net
if_gre.h revision 1.22.2.1
      1  1.22.2.1    skrll /*	$NetBSD: if_gre.h,v 1.22.2.1 2007/09/03 10:23:10 skrll 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.6  thorpej #include <sys/queue.h>
     43      1.22   dyoung #include <sys/mutex.h>
     44      1.22   dyoung #include <sys/condvar.h>
     45       1.6  thorpej 
     46      1.17   dyoung #ifdef _KERNEL
     47      1.17   dyoung struct gre_soparm {
     48      1.17   dyoung 	struct in_addr	sp_src;		/* source address of gre packets */
     49      1.17   dyoung 	struct in_addr	sp_dst;		/* destination address of gre packets */
     50      1.17   dyoung 	in_port_t	sp_srcport;	/* source port of gre packets */
     51      1.17   dyoung 	in_port_t	sp_dstport;	/* destination port of gre packets */
     52  1.22.2.1    skrll 	struct file	*sp_fp;
     53      1.17   dyoung };
     54      1.17   dyoung 
     55       1.1      hwr struct gre_softc {
     56      1.17   dyoung 	struct ifnet		sc_if;
     57      1.22   dyoung 	kmutex_t		sc_mtx;
     58      1.22   dyoung 	kcondvar_t		sc_soparm_cv;
     59      1.22   dyoung 	kcondvar_t		sc_join_cv;
     60      1.22   dyoung 	kcondvar_t		sc_work_cv;
     61      1.22   dyoung 	int			sc_haswork;
     62      1.22   dyoung 	int			sc_running;
     63  1.22.2.1    skrll 	int			sc_dying;
     64      1.17   dyoung 	struct ifqueue		sc_snd;
     65      1.18   dyoung 	struct gre_soparm	sc_soparm;
     66  1.22.2.1    skrll 	struct gre_soparm	sc_newsoparm;
     67      1.17   dyoung 	LIST_ENTRY(gre_softc)	sc_list;
     68  1.22.2.1    skrll 	struct route route;	/* routing entry that determines where a
     69       1.9   itojun 				   encapsulated packet should go */
     70      1.19   dyoung 	int			sc_proto;	/* protocol of encapsulator */
     71  1.22.2.1    skrll 	struct uio		sc_uio;
     72      1.14    perry };
     73  1.22.2.1    skrll 
     74  1.22.2.1    skrll #define	sc_src		sc_newsoparm.sp_src
     75  1.22.2.1    skrll #define	sc_srcport	sc_newsoparm.sp_srcport
     76  1.22.2.1    skrll #define	sc_dst		sc_newsoparm.sp_dst
     77  1.22.2.1    skrll #define	sc_dstport	sc_newsoparm.sp_dstport
     78       1.1      hwr 
     79       1.1      hwr struct gre_h {
     80       1.1      hwr 	u_int16_t flags;	/* GRE flags */
     81      1.14    perry 	u_int16_t ptype;	/* protocol type of payload typically
     82       1.9   itojun 				   Ether protocol type*/
     83      1.14    perry /*
     84      1.14    perry  *  from here on: fields are optional, presence indicated by flags
     85       1.1      hwr  *
     86       1.9   itojun 	u_int_16 checksum	checksum (one-complements of GRE header
     87       1.9   itojun 				and payload
     88       1.9   itojun 				Present if (ck_pres | rt_pres == 1).
     89       1.9   itojun 				Valid if (ck_pres == 1).
     90       1.9   itojun 	u_int_16 offset		offset from start of routing filed to
     91       1.9   itojun 				first octet of active SRE (see below).
     92       1.9   itojun 				Present if (ck_pres | rt_pres == 1).
     93       1.9   itojun 				Valid if (rt_pres == 1).
     94       1.9   itojun 	u_int_32 key		inserted by encapsulator e.g. for
     95       1.9   itojun 				authentication
     96       1.9   itojun 				Present if (key_pres ==1 ).
     97       1.9   itojun 	u_int_32 seq_num	Sequence number to allow for packet order
     98       1.9   itojun 				Present if (seq_pres ==1 ).
     99       1.9   itojun 	struct gre_sre[] routing Routing fileds (see below)
    100       1.9   itojun 				Present if (rt_pres == 1)
    101       1.9   itojun  */
    102       1.5  thorpej } __attribute__((__packed__));
    103       1.1      hwr 
    104       1.1      hwr struct greip {
    105       1.1      hwr 	struct ip gi_i;
    106       1.1      hwr 	struct gre_h  gi_g;
    107       1.5  thorpej } __attribute__((__packed__));
    108       1.1      hwr 
    109       1.9   itojun #define gi_pr		gi_i.ip_p
    110       1.9   itojun #define gi_len		gi_i.ip_len
    111       1.9   itojun #define gi_src		gi_i.ip_src
    112       1.9   itojun #define gi_dst		gi_i.ip_dst
    113       1.1      hwr #define gi_ptype	gi_g.ptype
    114       1.1      hwr #define gi_flags	gi_g.flags
    115       1.1      hwr 
    116       1.9   itojun #define GRE_CP		0x8000  /* Checksum Present */
    117       1.9   itojun #define GRE_RP		0x4000  /* Routing Present */
    118       1.9   itojun #define GRE_KP		0x2000  /* Key Present */
    119       1.9   itojun #define GRE_SP		0x1000  /* Sequence Present */
    120       1.1      hwr #define GRE_SS		0x0800	/* Strict Source Route */
    121       1.1      hwr 
    122       1.9   itojun /*
    123       1.9   itojun  * gre_sre defines a Source route Entry. These are needed if packets
    124       1.9   itojun  * should be routed over more than one tunnel hop by hop
    125       1.1      hwr  */
    126       1.1      hwr struct gre_sre {
    127      1.13      wiz 	u_int16_t sre_family;	/* address family */
    128       1.9   itojun 	u_char	sre_offset;	/* offset to first octet of active entry */
    129      1.14    perry 	u_char	sre_length;	/* number of octets in the SRE.
    130       1.9   itojun 				   sre_lengthl==0 -> last entry. */
    131       1.9   itojun 	u_char	*sre_rtinfo;	/* the routing information */
    132       1.1      hwr };
    133       1.1      hwr 
    134       1.2      hwr /* for mobile encaps */
    135       1.2      hwr 
    136       1.2      hwr struct mobile_h {
    137       1.2      hwr 	u_int16_t proto;		/* protocol and S-bit */
    138       1.2      hwr 	u_int16_t hcrc;			/* header checksum */
    139       1.2      hwr 	u_int32_t odst;			/* original destination address */
    140       1.2      hwr 	u_int32_t osrc;			/* original source addr, if S-bit set */
    141       1.5  thorpej } __attribute__((__packed__));
    142       1.2      hwr 
    143       1.2      hwr struct mobip_h {
    144       1.9   itojun 	struct ip	mi;
    145       1.9   itojun 	struct mobile_h	mh;
    146       1.5  thorpej } __attribute__((__packed__));
    147       1.2      hwr 
    148       1.2      hwr 
    149       1.2      hwr #define MOB_H_SIZ_S		(sizeof(struct mobile_h) - sizeof(u_int32_t))
    150       1.2      hwr #define MOB_H_SIZ_L		(sizeof(struct mobile_h))
    151       1.2      hwr #define MOB_H_SBIT	0x0080
    152       1.2      hwr 
    153      1.10   martin #define	GRE_TTL	30
    154      1.10   martin extern int ip_gre_ttl;
    155      1.17   dyoung #endif /* _KERNEL */
    156       1.2      hwr 
    157      1.14    perry /*
    158      1.14    perry  * ioctls needed to manipulate the interface
    159       1.2      hwr  */
    160       1.2      hwr 
    161       1.9   itojun #define GRESADDRS	_IOW('i', 101, struct ifreq)
    162      1.14    perry #define GRESADDRD	_IOW('i', 102, struct ifreq)
    163       1.9   itojun #define GREGADDRS	_IOWR('i', 103, struct ifreq)
    164       1.9   itojun #define GREGADDRD	_IOWR('i', 104, struct ifreq)
    165       1.9   itojun #define GRESPROTO	_IOW('i' , 105, struct ifreq)
    166       1.9   itojun #define GREGPROTO	_IOWR('i', 106, struct ifreq)
    167      1.18   dyoung #define GRESSOCK	_IOW('i' , 107, struct ifreq)
    168      1.18   dyoung #define GREDSOCK	_IOW('i' , 108, struct ifreq)
    169       1.2      hwr 
    170       1.4  thorpej #ifdef _KERNEL
    171       1.7  thorpej LIST_HEAD(gre_softc_head, gre_softc);
    172       1.7  thorpej extern struct gre_softc_head gre_softc_list;
    173       1.2      hwr 
    174      1.12   itojun u_int16_t gre_in_cksum(u_short *, u_int);
    175      1.22   dyoung int gre_input3(struct gre_softc *, struct mbuf *, int, const struct gre_h *,
    176      1.22   dyoung     int);
    177       1.4  thorpej #endif /* _KERNEL */
    178       1.1      hwr 
    179      1.15     elad #endif /* !_NET_IF_GRE_H_ */
    180