xref: /openbsd/sys/net/if_gre.h (revision 898184e3)
1 /*      $OpenBSD: if_gre.h,v 1.13 2010/06/26 19:49:54 claudio Exp $ */
2 /*	$NetBSD: if_gre.h,v 1.5 1999/11/19 20:41:19 thorpej Exp $ */
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  *
20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #ifndef _NET_IF_GRE_H
34 #define _NET_IF_GRE_H
35 
36 struct gre_softc {
37 	struct ifnet		sc_if;
38 	LIST_ENTRY(gre_softc)	sc_list;
39 	struct timeout		sc_ka_hold;
40 	struct timeout		sc_ka_snd;
41 	struct in_addr		g_src;  /* source address of gre packets */
42 	struct in_addr		g_dst;  /* destination address of gre packets */
43 	struct route		route;	/* routing entry that determines, where
44 					   an encapsulated packet should go */
45 	u_int  g_rtableid;	/* routing table used for the tunnel */
46 	int			gre_unit;
47 	int			gre_flags;
48 	int			sc_ka_timout;
49 	int			sc_ka_holdmax;
50 	int			sc_ka_holdcnt;
51 	int			sc_ka_cnt;
52 	u_char			g_proto;	/* protocol of encapsulator */
53 	u_char			sc_ka_state;
54 #define GRE_STATE_UKNWN	0
55 #define GRE_STATE_DOWN	1
56 #define GRE_STATE_HOLD	2
57 #define GRE_STATE_UP	3
58 };
59 
60 
61 struct gre_h {
62 	u_int16_t flags;	/* GRE flags */
63 	u_int16_t ptype;	/* protocol type of payload typically
64                                Ether protocol type*/
65 /*
66  *  from here on: fields are optional, presence indicated by flags
67  *
68 	u_int_16 checksum	 checksum (one-complements of GRE header
69                              and payload
70                              Present if (ck_pres | rt_pres == 1).
71                              Valid if (ck_pres == 1).
72 	u_int_16 offset			 offset from start of routing filed to
73                              first octet of active SRE (see below).
74                              Present if (ck_pres | rt_pres == 1).
75                              Valid if (rt_pres == 1).
76 	u_int_32 key         inserted by encapsulator e.g. for
77                              authentication
78                              Present if (key_pres ==1 ).
79 	u_int_32 seq_num     Sequence number to allow for packet order
80                              Present if (seq_pres ==1 ).
81 
82     struct gre_sre[] routing Routing fileds (see below)
83                              Present if (rt_pres == 1)
84 */
85 } __packed;
86 
87 struct greip {
88 	struct ip gi_i;
89 	struct gre_h  gi_g;
90 } __packed;
91 
92 #define gi_pr           gi_i.ip_p
93 #define gi_len          gi_i.ip_len
94 #define gi_src          gi_i.ip_src
95 #define gi_dst          gi_i.ip_dst
96 #define gi_ptype	gi_g.ptype
97 #define gi_flags	gi_g.flags
98 
99 #define GRE_CP          0x8000  /* Checksum Present */
100 #define GRE_RP          0x4000  /* Routing Present */
101 #define GRE_KP          0x2000  /* Key Present */
102 #define GRE_SP          0x1000  /* Sequence Present */
103 #define GRE_SS		0x0800	/* Strict Source Route */
104 
105 /* gre_sre defines a Source route Entry. These are needed if packets
106  *  should be routed over more than one tunnel hop by hop
107  */
108 
109 struct gre_sre {
110 	u_int16_t sre_family;	/* address family */
111 	u_char  sre_offset;	/* offset to first octet of active entry */
112 	u_char  sre_length;	/* number of octets in the SRE.
113                                sre_lengthl==0 -> last entry. */
114 	u_char  *sre_rtinfo;	/* the routing information */
115 };
116 
117 struct greioctl {
118 	int unit;
119 	struct    in_addr addr;
120 };
121 
122 /* for mobile encaps */
123 
124 struct mobile_h {
125 	u_int16_t proto;		/* protocol and S-bit */
126 	u_int16_t hcrc;			/* header checksum */
127 	u_int32_t odst;			/* original destination address */
128 	u_int32_t osrc;			/* original source addr, if S-bit set */
129 } __packed;
130 
131 struct mobip_h {
132 	struct ip       mi;
133 	struct mobile_h mh;
134 } __packed;
135 
136 
137 #define MOB_H_SIZ_S		(sizeof(struct mobile_h) - sizeof(u_int32_t))
138 #define MOB_H_SIZ_L		(sizeof(struct mobile_h))
139 #define MOB_H_SBIT	0x0080
140 
141 
142 /*
143  * ioctls needed to manipulate the interface
144  */
145 
146 #ifdef _KERNEL
147 extern  LIST_HEAD(gre_softc_head, gre_softc) gre_softc_list;
148 extern  int gre_allow;
149 extern  int gre_wccp;
150 extern  int ip_mobile_allow;
151 
152 void	greattach(int);
153 int     gre_ioctl(struct ifnet *, u_long, caddr_t);
154 int     gre_output(struct ifnet *, struct mbuf *, struct sockaddr *,
155 	    struct rtentry *);
156 u_int16_t gre_in_cksum(u_int16_t *, u_int);
157 void	gre_recv_keepalive(struct gre_softc *);
158 #endif /* _KERNEL */
159 #endif /* _NET_IF_GRE_H_ */
160