xref: /netbsd-src/sys/net/if_gre.h (revision 3cec974c61d7fac0a37c0377723a33214a458c8b)
1 /*	$NetBSD: if_gre.h,v 1.8 2000/12/12 18:00:26 thorpej 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@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 struct gre_softc {
45 	struct ifnet sc_if;
46 	LIST_ENTRY(gre_softc) sc_list;
47 	int gre_unit;
48 	int gre_flags;
49 	struct    in_addr g_src;  /* source address of gre packets */
50 	struct    in_addr g_dst;  /* destination address of gre packets */
51 	struct route route;	/* routing entry that determines, where a
52                                    encapsulated packet should go */
53 	u_char g_proto;		/* protocol of encapsulator */
54 };
55 
56 
57 struct gre_h {
58 	u_int16_t flags;	/* GRE flags */
59 	u_int16_t ptype;	/* protocol type of payload typically
60                                Ether protocol type*/
61 /*
62  *  from here on: fields are optional, presence indicated by flags
63  *
64 	u_int_16 checksum	 checksum (one-complements of GRE header
65                              and payload
66                              Present if (ck_pres | rt_pres == 1).
67                              Valid if (ck_pres == 1).
68 	u_int_16 offset			 offset from start of routing filed to
69                              first octet of active SRE (see below).
70                              Present if (ck_pres | rt_pres == 1).
71                              Valid if (rt_pres == 1).
72     u_int_32 key             inserted by encapsulator e.g. for
73                              authentication
74                              Present if (key_pres ==1 ).
75     u_int_32 seq_num         Sequence number to allow for packet order
76                              Present if (seq_pres ==1 ).
77 
78     struct gre_sre[] routing Routing fileds (see below)
79                              Present if (rt_pres == 1)
80 */
81 } __attribute__((__packed__));
82 
83 struct greip {
84 	struct ip gi_i;
85 	struct gre_h  gi_g;
86 } __attribute__((__packed__));
87 
88 #define gi_pr           gi_i.ip_p
89 #define gi_len          gi_i.ip_len
90 #define gi_src          gi_i.ip_src
91 #define gi_dst          gi_i.ip_dst
92 #define gi_ptype	gi_g.ptype
93 #define gi_flags	gi_g.flags
94 
95 #define GRE_CP          0x8000  /* Checksum Present */
96 #define GRE_RP          0x4000  /* Routing Present */
97 #define GRE_KP          0x2000  /* Key Present */
98 #define GRE_SP          0x1000  /* Sequence Present */
99 #define GRE_SS		0x0800	/* Strict Source Route */
100 
101 /* gre_sre defines a Source route Entry. These are needed if packets
102  *  should be routed over more than one tunnel hop by hop
103  */
104 
105 struct gre_sre {
106 	u_int16_t sre_family;	/* adress family */
107 	u_char  sre_offset;	/* offset to first octet of active entry */
108 	u_char  sre_length;	/* number of octets in the SRE.
109                                sre_lengthl==0 -> last entry. */
110 	u_char  *sre_rtinfo;	/* the routing information */
111 };
112 
113 struct greioctl {
114 	int unit;
115 	struct    in_addr addr;
116 };
117 
118 /* for mobile encaps */
119 
120 struct mobile_h {
121 	u_int16_t proto;		/* protocol and S-bit */
122 	u_int16_t hcrc;			/* header checksum */
123 	u_int32_t odst;			/* original destination address */
124 	u_int32_t osrc;			/* original source addr, if S-bit set */
125 } __attribute__((__packed__));
126 
127 struct mobip_h {
128 	struct ip       mi;
129 	struct mobile_h mh;
130 } __attribute__((__packed__));
131 
132 
133 #define MOB_H_SIZ_S		(sizeof(struct mobile_h) - sizeof(u_int32_t))
134 #define MOB_H_SIZ_L		(sizeof(struct mobile_h))
135 #define MOB_H_SBIT	0x0080
136 
137 
138 /*
139  * ioctls needed to manipulate the interface
140  */
141 
142 #define GRESADDRS       _IOW('i', 101, struct ifreq)
143 #define GRESADDRD       _IOW('i', 102, struct ifreq)
144 #define GREGADDRS       _IOWR('i', 103, struct ifreq)
145 #define GREGADDRD       _IOWR('i', 104, struct ifreq)
146 #define GRESPROTO       _IOW('i' , 105, struct ifreq)
147 #define GREGPROTO       _IOWR('i', 106, struct ifreq)
148 
149 #ifdef _KERNEL
150 LIST_HEAD(gre_softc_head, gre_softc);
151 extern struct gre_softc_head gre_softc_list;
152 
153 int     gre_ioctl __P((struct ifnet *, u_long, caddr_t));
154 int     gre_output __P((struct ifnet *, struct mbuf *, struct sockaddr *,
155 	    struct rtentry *rt));
156 u_short	gre_in_cksum(u_short *p, u_int len);
157 #endif /* _KERNEL */
158 
159 #endif
160