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