xref: /freebsd/share/man/man4/gre.4 (revision e28a4053)
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.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.\" $FreeBSD$
31.\"
32.Dd June 20, 2008
33.Dt GRE 4
34.Os
35.Sh NAME
36.Nm gre
37.Nd encapsulating network device
38.Sh SYNOPSIS
39To compile the
40.Ns Nm
41device into the kernel, place the following line in the kernel
42configuration file:
43.Bd -ragged -offset indent
44.Cd "device gre"
45.Ed
46.Pp
47Alternatively, to load the
48.Ns Nm
49device as a module at boot time, place the following line in
50.Xr loader.conf 5 :
51.Bd -literal -offset indent
52if_gre_load="YES"
53.Ed
54.Sh DESCRIPTION
55The
56.Nm
57network interface pseudo device encapsulates datagrams
58into IP.
59These encapsulated datagrams are routed to a destination host,
60where they are decapsulated and further routed to their final destination.
61The
62.Dq tunnel
63appears to the inner datagrams as one hop.
64.Pp
65.Nm
66interfaces are dynamically created and destroyed with the
67.Xr ifconfig 8
68.Cm create
69and
70.Cm destroy
71subcommands.
72.Pp
73This driver currently supports the following modes of operation:
74.Bl -tag -width indent
75.It "GRE encapsulation (IP protocol number 47)"
76Encapsulated datagrams are
77prepended an outer datagram and a GRE header.
78The GRE header specifies
79the type of the encapsulated datagram and thus allows for tunneling other
80protocols than IP like e.g.\& AppleTalk.
81GRE mode is also the default tunnel mode on Cisco routers.
82This is also the default mode of operation of the
83.Nm
84interfaces.
85As part of the GRE mode,
86.Nm
87also supports Cisco WCCP protocol, both version 1 and version 2.
88Since there is no reliable way to distinguish between WCCP versions, it
89should be configured manually using the
90.Cm link2
91flag.
92If the
93.Cm link2
94flag is not set (default), then WCCP version 1 is selected.
95.It "MOBILE encapsulation (IP protocol number 55)"
96Datagrams are
97encapsulated into IP, but with a shorter encapsulation.
98The original
99IP header is modified and the modifications are inserted between the
100so modified header and the original payload.
101Like
102.Xr gif 4 ,
103only for IP-in-IP encapsulation.
104.El
105.Pp
106The
107.Nm
108interfaces support a number of
109.Xr ioctl 2 Ns s ,
110such as:
111.Bl -tag -width ".Dv GRESADDRS"
112.It Dv GRESADDRS
113Set the IP address of the local tunnel end.
114This is the source address
115set by or displayed by
116.Xr ifconfig 8
117for the
118.Nm
119interface.
120.It Dv GRESADDRD
121Set the IP address of the remote tunnel end.
122This is the destination address
123set by or displayed by
124.Xr ifconfig 8
125for the
126.Nm
127interface.
128.It Dv GREGADDRS
129Query the IP address that is set for the local tunnel end.
130This is the
131address the encapsulation header carries as local address (i.e., the real
132address of the tunnel start point).
133.It Dv GREGADDRD
134Query the IP address that is set for the remote tunnel end.
135This is the
136address the encapsulated packets are sent to (i.e., the real address of
137the remote tunnel endpoint).
138.It Dv GRESPROTO
139Set the operation mode to the specified IP protocol value.
140The
141protocol is passed to the interface in
142.Po Vt "struct ifreq" Pc Ns Li -> Ns Va ifr_flags .
143The operation mode can also be given as
144.Pp
145.Bl -tag -width ".Cm -link0" -compact
146.It Cm link0
147.Dv IPPROTO_GRE
148.It Cm -link0
149.Dv IPPROTO_MOBILE
150.El
151.Pp
152to
153.Xr ifconfig 8 .
154.Pp
155The
156.Cm link1
157flag is not used to choose encapsulation, but to modify the
158internal route search for the remote tunnel endpoint, see the
159.Sx BUGS
160section below.
161.It Dv GREGPROTO
162Query operation mode.
163.It Dv GRESKEY
164Set the GRE key used for outgoing packets.
165A value of 0 disables the key option.
166.It Dv GREGKEY
167Get the GRE key currently used for outgoing packets.
1680 means no outgoing key.
169.El
170.Pp
171Note that the IP addresses of the tunnel endpoints may be the same as the
172ones defined with
173.Xr ifconfig 8
174for the interface (as if IP is encapsulated), but need not be, as e.g.\& when
175encapsulating AppleTalk.
176.Sh EXAMPLES
177Configuration example:
178.Bd -literal
179Host X-- Host A  ----------------tunnel---------- Cisco D------Host E
180          \\                                          |
181           \\                                        /
182            +------Host B----------Host C----------+
183.Ed
184.Pp
185On host A
186.Pq Fx :
187.Bd -literal -offset indent
188route add default B
189ifconfig greN create
190ifconfig greN A D netmask 0xffffffff linkX up
191ifconfig greN tunnel A D
192route add E D
193.Ed
194.Pp
195On Host D (Cisco):
196.Bd -literal -offset indent
197Interface TunnelX
198 ip unnumbered D   ! e.g. address from Ethernet interface
199 tunnel source D   ! e.g. address from Ethernet interface
200 tunnel destination A
201ip route C <some interface and mask>
202ip route A mask C
203ip route X mask tunnelX
204.Ed
205.Pp
206OR
207.Pp
208On Host D
209.Pq Fx :
210.Bd -literal -offset indent
211route add default C
212ifconfig greN create
213ifconfig greN D A
214ifconfig greN tunnel D A
215.Ed
216.Pp
217If all goes well, you should see packets flowing ;-)
218.Pp
219If you want to reach Host A over the tunnel (from Host D (Cisco)), then
220you have to have an alias on Host A for e.g.\& the Ethernet interface like:
221.Pp
222.Dl "ifconfig <etherif> alias Y"
223.Pp
224and on the Cisco:
225.Pp
226.Dl "ip route Y mask tunnelX"
227.Pp
228A similar setup can be used to create a link between two private networks
229(for example in the 192.168 subnet) over the Internet:
230.Bd -literal
231192.168.1.* --- Router A  -------tunnel-------- Router B --- 192.168.2.*
232                   \\                              /
233                    \\                            /
234                     +------ the Internet ------+
235.Ed
236.Pp
237Assuming router A has the (external) IP address A and the internal address
238192.168.1.1, while router B has external address B and internal address
239192.168.2.1, the following commands will configure the tunnel:
240.Pp
241On router A:
242.Bd -literal -offset indent
243ifconfig greN create
244ifconfig greN 192.168.1.1 192.168.2.1 link1
245ifconfig greN tunnel A B
246route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
247.Ed
248.Pp
249On router B:
250.Bd -literal -offset indent
251ifconfig greN create
252ifconfig greN 192.168.2.1 192.168.1.1 link1
253ifconfig greN tunnel B A
254route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
255.Ed
256.Pp
257Note that this is a safe situation where the
258.Cm link1
259flag (as discussed in the
260.Sx BUGS
261section below) may (and probably should) be set.
262.Sh NOTES
263The MTU of
264.Nm
265interfaces is set to 1476 by default, to match the value used by Cisco routers.
266If grekey is set this is lowered to 1472.
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 current implementation uses the key only for outgoing packets.
336Incoming packets with a different key or without a key will be treated as if they
337would belong to this interface.
338.Pp
339RFC1701 is not fully supported, however all unsupported features have been
340deprecated in RFC2784.
341