xref: /freebsd/sys/net/if_gre.h (revision 4b2eaea43fec8e8792be611dea204071a10b655a)
1 /*	$NetBSD: if_gre.h,v 1.10 2002/02/24 17:22:20 martin Exp $ */
2 /*	 $FreeBSD$ */
3 
4 /*
5  * Copyright (c) 1998 The NetBSD Foundation, Inc.
6  * All rights reserved
7  *
8  * This code is derived from software contributed to The NetBSD Foundation
9  * by Heiko W.Rupp <hwr@pilhuhn.de>
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *        This product includes software developed by the NetBSD
22  *        Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #ifndef _NET_IF_GRE_H
41 #define _NET_IF_GRE_H
42 
43 #include <sys/ioccom.h>
44 #ifdef _KERNEL
45 #include <sys/queue.h>
46 
47 struct gre_softc {
48 	struct ifnet sc_if;
49 	LIST_ENTRY(gre_softc) sc_list;
50 	int gre_unit;
51 	int gre_flags;
52 	struct in_addr g_src;	/* source address of gre packets */
53 	struct in_addr g_dst;	/* destination address of gre packets */
54 	struct route route;	/* routing entry that determines, where a
55 				   encapsulated packet should go */
56 	u_char g_proto;		/* protocol of encapsulator */
57 
58 	const struct encaptab *encap;	/* encapsulation cookie */
59 
60 	int called;		/* infinite recursion preventer */
61 };
62 
63 
64 struct gre_h {
65 	u_int16_t flags;	/* GRE flags */
66 	u_int16_t ptype;	/* protocol type of payload typically
67 				   Ether protocol type*/
68 /*
69  *  from here on: fields are optional, presence indicated by flags
70  *
71 	u_int_16 checksum	checksum (one-complements of GRE header
72 				and payload
73 				Present if (ck_pres | rt_pres == 1).
74 				Valid if (ck_pres == 1).
75 	u_int_16 offset		offset from start of routing filed to
76 				first octet of active SRE (see below).
77 				Present if (ck_pres | rt_pres == 1).
78 				Valid if (rt_pres == 1).
79 	u_int_32 key		inserted by encapsulator e.g. for
80 				authentication
81 				Present if (key_pres ==1 ).
82 	u_int_32 seq_num	Sequence number to allow for packet order
83 				Present if (seq_pres ==1 ).
84 	struct gre_sre[] routing Routing fileds (see below)
85 				Present if (rt_pres == 1)
86  */
87 } __packed;
88 
89 struct greip {
90 	struct ip gi_i;
91 	struct gre_h  gi_g;
92 } __packed;
93 
94 #define gi_pr		gi_i.ip_p
95 #define gi_len		gi_i.ip_len
96 #define gi_src		gi_i.ip_src
97 #define gi_dst		gi_i.ip_dst
98 #define gi_ptype	gi_g.ptype
99 #define gi_flags	gi_g.flags
100 
101 #define GRE_CP		0x8000  /* Checksum Present */
102 #define GRE_RP		0x4000  /* Routing Present */
103 #define GRE_KP		0x2000  /* Key Present */
104 #define GRE_SP		0x1000  /* Sequence Present */
105 #define GRE_SS		0x0800	/* Strict Source Route */
106 
107 /*
108  * CISCO uses special type for GRE tunnel created as part of WCCP
109  * connection, while in fact those packets are just IPv4 encapsulated
110  * into GRE.
111  */
112 #define WCCP_PROTOCOL_TYPE	0x883E
113 
114 /*
115  * gre_sre defines a Source route Entry. These are needed if packets
116  * should be routed over more than one tunnel hop by hop
117  */
118 struct gre_sre {
119 	u_int16_t sre_family;	/* adress family */
120 	u_char	sre_offset;	/* offset to first octet of active entry */
121 	u_char	sre_length;	/* number of octets in the SRE.
122 				   sre_lengthl==0 -> last entry. */
123 	u_char	*sre_rtinfo;	/* the routing information */
124 };
125 
126 struct greioctl {
127 	int unit;
128 	struct in_addr addr;
129 };
130 
131 /* for mobile encaps */
132 
133 struct mobile_h {
134 	u_int16_t proto;		/* protocol and S-bit */
135 	u_int16_t hcrc;			/* header checksum */
136 	u_int32_t odst;			/* original destination address */
137 	u_int32_t osrc;			/* original source addr, if S-bit set */
138 } __packed;
139 
140 struct mobip_h {
141 	struct ip	mi;
142 	struct mobile_h	mh;
143 } __packed;
144 
145 
146 #define MOB_H_SIZ_S		(sizeof(struct mobile_h) - sizeof(u_int32_t))
147 #define MOB_H_SIZ_L		(sizeof(struct mobile_h))
148 #define MOB_H_SBIT	0x0080
149 
150 #define	GRE_TTL	30
151 
152 #endif /* _KERNEL */
153 
154 /*
155  * ioctls needed to manipulate the interface
156  */
157 
158 #define GRESADDRS	_IOW('i', 101, struct ifreq)
159 #define GRESADDRD	_IOW('i', 102, struct ifreq)
160 #define GREGADDRS	_IOWR('i', 103, struct ifreq)
161 #define GREGADDRD	_IOWR('i', 104, struct ifreq)
162 #define GRESPROTO	_IOW('i' , 105, struct ifreq)
163 #define GREGPROTO	_IOWR('i', 106, struct ifreq)
164 
165 #ifdef _KERNEL
166 LIST_HEAD(gre_softc_head, gre_softc);
167 extern struct gre_softc_head gre_softc_list;
168 
169 u_short	gre_in_cksum(u_short *p, u_int len);
170 #endif /* _KERNEL */
171 
172 #endif
173