Initial import from FreeBSD RELENG_4:
[dragonfly.git] / share / man / man4 / gre.4
1 .\" $NetBSD: gre.4,v 1.28 2002/06/10 02:49:35 itojun Exp $
2 .\"  $FreeBSD: src/share/man/man4/gre.4,v 1.1.2.1 2002/12/01 14:03:11 sobomax Exp $
3 .\"
4 .\" Copyright 1998 (c) 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 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 .Dd June 9, 2002
39 .Dt GRE 4
40 .Os
41 .Sh NAME
42 .Nm gre
43 .Nd encapsulating network device
44 .Sh SYNOPSIS
45 .Cd pseudo-device gre
46 .Sh DESCRIPTION
47 The
48 .Nm gre
49 network interface pseudo device encapsulates datagrams
50 into IP.  These encapsulated datagrams are routed to a destination host,
51 where they are decapsulated and further routed to their final destination.
52 The
53 .Dq tunnel
54 appears to the inner datagrams as one hop.
55 .Pp
56 .Nm
57 interfaces are dynamically created and destroyed with the
58 .Xr ifconfig 8
59 .Cm create
60 and
61 .Cm destroy
62 subcommands.
63 .Pp
64 This driver currently supports the following modes of operation:
65 .Bl -tag -width abc
66 .It GRE encapsulation (IP protocol number 47)
67 Encapsulated datagrams are
68 prepended an outer datagram and a GRE header.  The GRE header specifies
69 the type of the encapsulated datagram and thus allows for tunneling other
70 protocols than IP like e.g. AppleTalk.  GRE mode is also the default tunnel
71 mode on Cisco routers.  This is also the default mode of operation of the
72 .Sy gre Ns Ar X
73 interfaces.
74 .It MOBILE encapsulation (IP protocol number 55)
75 Datagrams are
76 encapsulated into IP, but with a shorter encapsulation.  The original
77 IP header is modified and the modifications are inserted between the
78 so modified header and the original payload.  Like
79 .Xr gif 4 ,
80 only for IP in IP encapsulation.
81 .El
82 .Pp
83 The
84 .Sy gre Ns Ar X
85 interfaces support a number of
86 .Xr ioctl 2 Ns s ,
87 such as:
88 .Bl -tag -width aaa
89 .It GRESADDRS :
90 Set the IP address of the local tunnel end.  This is the source address
91 set by or displayed by ifconfig for the
92 .Sy gre Ns Ar X
93 interface.
94 .It GRESADDRD :
95 Set the IP address of the remote tunnel end.  This is the destination address
96 set by or displayed by ifconfig for the
97 .Sy gre Ns Ar X
98 interface.
99 .It GREGADDRS :
100 Query the IP address that is set for the local tunnel end.  This is the
101 address the encapsulation header carries as local address (i.e. the real
102 address of the tunnel start point.)
103 .It GREGADDRD :
104 Query the IP address that is set for the remote tunnel end.  This is the
105 address the encapsulated packets are sent to (i.e. the real address of
106 the remote tunnel endpoint.)
107 .It GRESPROTO :
108 Set the operation mode to the specified IP protocol value.  The
109 protocol is passed to the interface in (struct ifreq)-\*[Gt]ifr_flags.
110 The operation mode can also be given as
111 .Bl -tag -width link0xxx
112 .It link0
113 IPPROTO_GRE
114 .It -link0
115 IPPROTO_MOBILE
116 .El
117 .Pp
118 to
119 .Xr ifconfig 8 .
120 .Pp
121 The link1 flag is not used to choose encapsulation, but to modify the
122 internal route search for the remote tunnel endpoint, see the
123 .Sx BUGS
124 section below.
125 .It GREGPROTO :
126 Query operation mode.
127 .El
128 .Pp
129 Note that the IP addresses of the tunnel endpoints may be the same as the
130 ones defined with
131 .Xr ifconfig 8
132 for the interface (as if IP is encapsulated), but need not be, as e.g. when
133 encapsulating AppleTalk.
134 .Sh EXAMPLES
135 Configuration example:
136 .Bd -literal
137 Host X-- Host A  ----------------tunnel---------- cisco D------Host E
138           \\                                          |
139            \\                                        /
140              +------Host B----------Host C----------+
141 .Ed
142 On host A
143 .Ns ( Nx ) :
144 .Bd -literal
145    # route add default B
146    # ifconfig greN create
147    # ifconfig greN A D netmask 0xffffffff linkX up
148    # ifconfig greN tunnel A D
149    # route add E D
150 .Ed
151 On Host D (Cisco):
152 .Bd -literal
153    Interface TunnelX
154     ip unnumbered D   ! e.g. address from Ethernet interface
155     tunnel source D   ! e.g. address from Ethernet interface
156     tunnel destination A
157    ip route C \*[Lt]some interface and mask\*[Gt]
158    ip route A mask C
159    ip route X mask tunnelX
160 .Ed
161 OR
162 On Host D
163 .Ns ( Nx ) :
164 .Bd -literal
165    # route add default C
166    # ifconfig greN create
167    # ifconfig greN D A
168    # ifconfig tunnel greN D A
169 .Ed
170 .Pp
171 If all goes well, you should see packets flowing ;-)
172 .Pp
173 If you want to reach Host A over the tunnel (from Host D (Cisco)), then
174 you have to have an alias on Host A for e.g. the Ethernet interface like:
175 .Bd -literal
176      ifconfig \*[Lt]etherif\*[Gt] alias Y
177 .Ed
178 and on the cisco
179 .Bd -literal
180      ip route Y mask tunnelX
181 .Ed
182 .Pp
183 A similar setup can be used to create a link between two private networks
184 (for example in the 192.168 subnet) over the Internet:
185 .Bd -literal
186 192.168.1.* --- Router A  -------tunnel-------- Router B --- 192.168.2.*
187                    \\                              /
188                     \\                            /
189                       +----- the Internet ------+
190 .Ed
191 Assuming router A has the (external) IP address A and the internal address
192 192.168.1.1, while router B has external address B and internal address
193 192.168.2.1, the following commands will configure the tunnel:
194 .Pp
195 On router A:
196 .Bd -literal
197    # ifconfig greN create
198    # ifconfig greN 192.168.1.1 192.168.2.1 link1
199    # ifconfig greN tunnel A B
200    # route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
201 .Ed
202 .Pp
203 On router B:
204 .Bd -literal
205    # ifconfig greN create
206    # ifconfig greN 192.168.2.1 192.168.1.1 link1
207    # ifconfig greN tunnel B A
208    # route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
209 .Ed
210 .Pp
211 Note that this is a safe situation where the link1 flag (as discussed in the
212 .Sx BUGS
213 section below) may (and probably should) be set.
214 .Sh NOTES
215 The MTU of
216 .Sy gre Ns Ar X
217 interfaces is set to 1476 by default to match the value used by Cisco routers.
218 This may not be an optimal value, depending on the link between the two tunnel
219 endpoints.  It can be adjusted via
220 .Xr ifconfig 8 .
221 .Pp
222 For correct operation, the
223 .Nm
224 device needs a route to the destination that is less specific than the
225 one over the tunnel.
226 (Basically, there needs to be a route to the decapsulating host that
227 does not run over the tunnel, as this would be a loop.)
228 If the addresses are ambiguous, doing the
229 .Xr ifconfig 8
230 .Li tunnel
231 step before the
232 .Xr ifconfig 8
233 call to set the
234 .Sy gre Ns Ar X
235 IP addresses will help to find a route outside the tunnel.
236 .Pp
237 In order to tell
238 .Xr ifconfig 8
239 to actually mark the interface as up, the keyword
240 .Dq up
241 must be given last on its command line.
242 .Pp
243 The kernel must be set to forward datagrams by either option
244 .Em GATEWAY
245 in the kernel config file or by issuing the appropriate option to
246 .Xr sysctl 8 .
247 .Sh SEE ALSO
248 .Xr atalk 4 ,
249 .Xr gif 4 ,
250 .Xr inet 4 ,
251 .Xr ip 4 ,
252 .Xr netintro 4 ,
253 .Xr options 4 ,
254 .Xr protocols 5 ,
255 .Xr ifconfig 8 ,
256 .Xr sysctl 8
257 .Pp
258 A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
259 .Pp
260 A description of MOBILE encapsulation can be found in RFC 2004.
261 .Sh AUTHORS
262 .An Heiko W.Rupp Aq hwr@pilhuhn.de
263 .Sh BUGS
264 The compute_route() code in if_gre.c toggles the last bit of the
265 IP-address to provoke the search for a less specific route than the
266 one directly over the tunnel to prevent loops.  This is possibly not
267 the best solution.
268 .Pp
269 To avoid the address munging described above, turn on the link1 flag
270 on the
271 .Xr ifconfig 8
272 command line.
273 This implies that the GRE packet destination and the ifconfig remote host
274 are not the same IP addresses, and that the GRE destination does not route
275 over the
276 .Sy gre Ns Ar X
277 interface itself.
278 .Pp
279 The GRE RFCs are not yet fully implemented (no GRE options).