xref: /freebsd/share/man/man4/gre.4 (revision 78704ef45793e56c8e064611c05c9bb8a0067e9f)
1.\" $NetBSD: gre.4,v 1.28 2002/06/10 02:49:35 itojun Exp $
2.\"  $FreeBSD$
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
47The
48.Nm gre
49network interface pseudo device encapsulates datagrams
50into IP.  These encapsulated datagrams are routed to a destination host,
51where they are decapsulated and further routed to their final destination.
52The
53.Dq tunnel
54appears to the inner datagrams as one hop.
55.Pp
56.Nm
57interfaces are dynamically created and destroyed with the
58.Xr ifconfig 8
59.Cm create
60and
61.Cm destroy
62subcommands.
63.Pp
64This driver currently supports the following modes of operation:
65.Bl -tag -width abc
66.It GRE encapsulation (IP protocol number 47)
67Encapsulated datagrams are
68prepended an outer datagram and a GRE header.  The GRE header specifies
69the type of the encapsulated datagram and thus allows for tunneling other
70protocols than IP like e.g. AppleTalk.  GRE mode is also the default tunnel
71mode on Cisco routers.  This is also the default mode of operation of the
72.Sy gre Ns Ar X
73interfaces.
74.It MOBILE encapsulation (IP protocol number 55)
75Datagrams are
76encapsulated into IP, but with a shorter encapsulation.  The original
77IP header is modified and the modifications are inserted between the
78so modified header and the original payload.  Like
79.Xr gif 4 ,
80only for IP in IP encapsulation.
81.El
82.Pp
83The
84.Sy gre Ns Ar X
85interfaces support a number of
86.Xr ioctl 2 Ns s ,
87such as:
88.Bl -tag -width aaa
89.It GRESADDRS :
90Set the IP address of the local tunnel end.  This is the source address
91set by or displayed by ifconfig for the
92.Sy gre Ns Ar X
93interface.
94.It GRESADDRD :
95Set the IP address of the remote tunnel end.  This is the destination address
96set by or displayed by ifconfig for the
97.Sy gre Ns Ar X
98interface.
99.It GREGADDRS :
100Query the IP address that is set for the local tunnel end.  This is the
101address the encapsulation header carries as local address (i.e. the real
102address of the tunnel start point.)
103.It GREGADDRD :
104Query the IP address that is set for the remote tunnel end.  This is the
105address the encapsulated packets are sent to (i.e. the real address of
106the remote tunnel endpoint.)
107.It GRESPROTO :
108Set the operation mode to the specified IP protocol value.  The
109protocol is passed to the interface in (struct ifreq)-\*[Gt]ifr_flags.
110The operation mode can also be given as
111.Bl -tag -width link0xxx
112.It link0
113IPPROTO_GRE
114.It -link0
115IPPROTO_MOBILE
116.El
117.Pp
118to
119.Xr ifconfig 8 .
120.Pp
121The link1 flag is not used to choose encapsulation, but to modify the
122internal route search for the remote tunnel endpoint, see the
123.Sx BUGS
124section below.
125.It GREGPROTO :
126Query operation mode.
127.El
128.Pp
129Note that the IP addresses of the tunnel endpoints may be the same as the
130ones defined with
131.Xr ifconfig 8
132for the interface (as if IP is encapsulated), but need not be, as e.g. when
133encapsulating AppleTalk.
134.Sh EXAMPLES
135Configuration example:
136.Bd -literal
137Host X-- Host A  ----------------tunnel---------- cisco D------Host E
138          \\                                          |
139           \\                                        /
140             +------Host B----------Host C----------+
141.Ed
142On 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
151On 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
161OR
162On 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
171If all goes well, you should see packets flowing ;-)
172.Pp
173If you want to reach Host A over the tunnel (from Host D (Cisco)), then
174you 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
178and on the cisco
179.Bd -literal
180     ip route Y mask tunnelX
181.Ed
182.Pp
183A 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
186192.168.1.* --- Router A  -------tunnel-------- Router B --- 192.168.2.*
187                   \\                              /
188                    \\                            /
189                      +----- the Internet ------+
190.Ed
191Assuming router A has the (external) IP address A and the internal address
192192.168.1.1, while router B has external address B and internal address
193192.168.2.1, the following commands will configure the tunnel:
194.Pp
195On 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
203On 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
211Note that this is a safe situation where the link1 flag (as discussed in the
212.Sx BUGS
213section below) may (and probably should) be set.
214.Sh NOTES
215The MTU of
216.Sy gre Ns Ar X
217interfaces is set to 1476 by default to match the value used by Cisco routers.
218This may not be an optimal value, depending on the link between the two tunnel
219endpoints.  It can be adjusted via
220.Xr ifconfig 8 .
221.Pp
222For correct operation, the
223.Nm
224device needs a route to the destination that is less specific than the
225one over the tunnel.
226(Basically, there needs to be a route to the decapsulating host that
227does not run over the tunnel, as this would be a loop.)
228If the addresses are ambiguous, doing the
229.Xr ifconfig 8
230.Li tunnel
231step before the
232.Xr ifconfig 8
233call to set the
234.Sy gre Ns Ar X
235IP addresses will help to find a route outside the tunnel.
236.Pp
237In order to tell
238.Xr ifconfig 8
239to actually mark the interface as up, the keyword
240.Dq up
241must be given last on its command line.
242.Pp
243The kernel must be set to forward datagrams by either option
244.Em GATEWAY
245in 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
258A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
259.Pp
260A 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
264The compute_route() code in if_gre.c toggles the last bit of the
265IP-address to provoke the search for a less specific route than the
266one directly over the tunnel to prevent loops.  This is possibly not
267the best solution.
268.Pp
269To avoid the address munging described above, turn on the link1 flag
270on the
271.Xr ifconfig 8
272command line.
273This implies that the GRE packet destination and the ifconfig remote host
274are not the same IP addresses, and that the GRE destination does not route
275over the
276.Sy gre Ns Ar X
277interface itself.
278.Pp
279The GRE RFCs are not yet fully implemented (no GRE options).
280