xref: /freebsd/share/man/man4/gre.4 (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1.\" $NetBSD: gre.4,v 1.28 2002/06/10 02:49:35 itojun Exp $
2.\"
3.\" Copyright 1998 (c) The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Heiko W.Rupp <hwr@pilhuhn.de>
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"     This product includes software developed by the NetBSD
20.\"	Foundation, Inc. and its contributors.
21.\" 4. Neither the name of the The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.\" $FreeBSD$
38.\"
39.Dd June 9, 2002
40.Dt GRE 4
41.Os
42.Sh NAME
43.Nm gre
44.Nd encapsulating network device
45.Sh SYNOPSIS
46To compile the
47.Ns Nm
48device into the kernel, place the following line in the kernel
49configuration file:
50.Bd -ragged -offset indent
51.Cd "device gre"
52.Ed
53.Pp
54Alternatively, to load the
55.Ns Nm
56device as a module at boot time, place the following line in
57.Xr loader.conf 5 :
58.Bd -literal -offset indent
59if_gre_load="YES"
60.Ed
61.Sh DESCRIPTION
62The
63.Nm
64network interface pseudo device encapsulates datagrams
65into IP.
66These encapsulated datagrams are routed to a destination host,
67where they are decapsulated and further routed to their final destination.
68The
69.Dq tunnel
70appears to the inner datagrams as one hop.
71.Pp
72.Nm
73interfaces are dynamically created and destroyed with the
74.Xr ifconfig 8
75.Cm create
76and
77.Cm destroy
78subcommands.
79.Pp
80This driver currently supports the following modes of operation:
81.Bl -tag -width indent
82.It "GRE encapsulation (IP protocol number 47)"
83Encapsulated datagrams are
84prepended an outer datagram and a GRE header.
85The GRE header specifies
86the type of the encapsulated datagram and thus allows for tunneling other
87protocols than IP like e.g.\& AppleTalk.
88GRE mode is also the default tunnel mode on Cisco routers.
89This is also the default mode of operation of the
90.Nm
91interfaces.
92As part of the GRE mode,
93.Nm
94also supports Cisco WCCP protocol, both version 1 and version 2.
95Since there is no reliable way to distinguish between WCCP versions, it
96should be configured manually using the
97.Cm link2
98flag.
99If the
100.Cm link2
101flag is not set (default), then WCCP version 1 is selected.
102.It "MOBILE encapsulation (IP protocol number 55)"
103Datagrams are
104encapsulated into IP, but with a shorter encapsulation.
105The original
106IP header is modified and the modifications are inserted between the
107so modified header and the original payload.
108Like
109.Xr gif 4 ,
110only for IP-in-IP encapsulation.
111.El
112.Pp
113The
114.Nm
115interfaces support a number of
116.Xr ioctl 2 Ns s ,
117such as:
118.Bl -tag -width ".Dv GRESADDRS"
119.It Dv GRESADDRS
120Set the IP address of the local tunnel end.
121This is the source address
122set by or displayed by
123.Xr ifconfig 8
124for the
125.Nm
126interface.
127.It Dv GRESADDRD
128Set the IP address of the remote tunnel end.
129This is the destination address
130set by or displayed by
131.Xr ifconfig 8
132for the
133.Nm
134interface.
135.It Dv GREGADDRS
136Query the IP address that is set for the local tunnel end.
137This is the
138address the encapsulation header carries as local address (i.e., the real
139address of the tunnel start point).
140.It Dv GREGADDRD
141Query the IP address that is set for the remote tunnel end.
142This is the
143address the encapsulated packets are sent to (i.e., the real address of
144the remote tunnel endpoint).
145.It Dv GRESPROTO
146Set the operation mode to the specified IP protocol value.
147The
148protocol is passed to the interface in
149.Po Vt "struct ifreq" Pc Ns Li -> Ns Va ifr_flags .
150The operation mode can also be given as
151.Pp
152.Bl -tag -width ".Cm -link0" -compact
153.It Cm link0
154.Dv IPPROTO_GRE
155.It Cm -link0
156.Dv IPPROTO_MOBILE
157.El
158.Pp
159to
160.Xr ifconfig 8 .
161.Pp
162The
163.Cm link1
164flag is not used to choose encapsulation, but to modify the
165internal route search for the remote tunnel endpoint, see the
166.Sx BUGS
167section below.
168.It Dv GREGPROTO
169Query operation mode.
170.El
171.Pp
172Note that the IP addresses of the tunnel endpoints may be the same as the
173ones defined with
174.Xr ifconfig 8
175for the interface (as if IP is encapsulated), but need not be, as e.g.\& when
176encapsulating AppleTalk.
177.Sh EXAMPLES
178Configuration example:
179.Bd -literal
180Host X-- Host A  ----------------tunnel---------- Cisco D------Host E
181          \\                                          |
182           \\                                        /
183            +------Host B----------Host C----------+
184.Ed
185.Pp
186On host A
187.Pq Fx :
188.Bd -literal -offset indent
189route add default B
190ifconfig greN create
191ifconfig greN A D netmask 0xffffffff linkX up
192ifconfig greN tunnel A D
193route add E D
194.Ed
195.Pp
196On Host D (Cisco):
197.Bd -literal -offset indent
198Interface TunnelX
199 ip unnumbered D   ! e.g. address from Ethernet interface
200 tunnel source D   ! e.g. address from Ethernet interface
201 tunnel destination A
202ip route C <some interface and mask>
203ip route A mask C
204ip route X mask tunnelX
205.Ed
206.Pp
207OR
208.Pp
209On Host D
210.Pq Fx :
211.Bd -literal -offset indent
212route add default C
213ifconfig greN create
214ifconfig greN D A
215ifconfig greN tunnel D A
216.Ed
217.Pp
218If all goes well, you should see packets flowing ;-)
219.Pp
220If you want to reach Host A over the tunnel (from Host D (Cisco)), then
221you have to have an alias on Host A for e.g.\& the Ethernet interface like:
222.Pp
223.Dl "ifconfig <etherif> alias Y"
224.Pp
225and on the Cisco:
226.Pp
227.Dl "ip route Y mask tunnelX"
228.Pp
229A similar setup can be used to create a link between two private networks
230(for example in the 192.168 subnet) over the Internet:
231.Bd -literal
232192.168.1.* --- Router A  -------tunnel-------- Router B --- 192.168.2.*
233                   \\                              /
234                    \\                            /
235                     +------ the Internet ------+
236.Ed
237.Pp
238Assuming router A has the (external) IP address A and the internal address
239192.168.1.1, while router B has external address B and internal address
240192.168.2.1, the following commands will configure the tunnel:
241.Pp
242On router A:
243.Bd -literal -offset indent
244ifconfig greN create
245ifconfig greN 192.168.1.1 192.168.2.1 link1
246ifconfig greN tunnel A B
247route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
248.Ed
249.Pp
250On router B:
251.Bd -literal -offset indent
252ifconfig greN create
253ifconfig greN 192.168.2.1 192.168.1.1 link1
254ifconfig greN tunnel B A
255route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
256.Ed
257.Pp
258Note that this is a safe situation where the
259.Cm link1
260flag (as discussed in the
261.Sx BUGS
262section below) may (and probably should) be set.
263.Sh NOTES
264The MTU of
265.Nm
266interfaces is set to 1476 by default, to match the value used by Cisco routers.
267This may not be an optimal value, depending on the link between the two tunnel
268endpoints.
269It can be adjusted via
270.Xr ifconfig 8 .
271.Pp
272For correct operation, the
273.Nm
274device needs a route to the destination that is less specific than the
275one over the tunnel.
276(Basically, there needs to be a route to the decapsulating host that
277does not run over the tunnel, as this would be a loop.)
278If the addresses are ambiguous, doing the
279.Nm ifconfig Cm tunnel
280step before the
281.Xr ifconfig 8
282call to set the
283.Nm
284IP addresses will help to find a route outside the tunnel.
285.Pp
286In order to tell
287.Xr ifconfig 8
288to actually mark the interface as
289.Dq up ,
290the keyword
291.Cm up
292must be given last on its command line.
293.Pp
294The kernel must be set to forward datagrams by setting the
295.Va net.inet.ip.forwarding
296.Xr sysctl 8
297variable to non-zero.
298.Sh SEE ALSO
299.\" Xr atalk 4 ,
300.Xr gif 4 ,
301.Xr inet 4 ,
302.Xr ip 4 ,
303.Xr netintro 4 ,
304.\" Xr options 4 ,
305.Xr protocols 5 ,
306.Xr ifconfig 8 ,
307.Xr sysctl 8
308.Pp
309A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
310.Pp
311A description of MOBILE encapsulation can be found in RFC 2004.
312.Sh AUTHORS
313.An Heiko W.Rupp Aq hwr@pilhuhn.de
314.Sh BUGS
315The
316.Fn compute_route
317code in
318.Pa if_gre.c
319toggles the last bit of the
320IP-address to provoke the search for a less specific route than the
321one directly over the tunnel to prevent loops.
322This is possibly not the best solution.
323.Pp
324To avoid the address munging described above, turn on the
325.Cm link1
326flag on the
327.Xr ifconfig 8
328command line.
329This implies that the GRE packet destination and the ifconfig remote host
330are not the same IP addresses, and that the GRE destination does not route
331over the
332.Nm
333interface itself.
334.Pp
335The GRE RFCs are not yet fully implemented (no GRE options).
336