xref: /freebsd/share/man/man4/gre.4 (revision 0e97acdf58fe27b09c4824a474b0344daf997c5f)
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
40driver into the kernel, place the following line in the kernel
41configuration file:
42.Bd -ragged -offset indent
43.Cd "device gre"
44.Ed
45.Pp
46Alternatively, to load the
47driver as a module at boot time, place the following line in
48.Xr loader.conf 5 :
49.Bd -literal -offset indent
50if_gre_load="YES"
51.Ed
52.Sh DESCRIPTION
53The
54.Nm
55network interface pseudo device encapsulates datagrams
56into IP.
57These encapsulated datagrams are routed to a destination host,
58where they are decapsulated and further routed to their final destination.
59The
60.Dq tunnel
61appears to the inner datagrams as one hop.
62.Pp
63.Nm
64interfaces are dynamically created and destroyed with the
65.Xr ifconfig 8
66.Cm create
67and
68.Cm destroy
69subcommands.
70.Pp
71This driver currently supports the following modes of operation:
72.Bl -tag -width indent
73.It "GRE encapsulation (IP protocol number 47)"
74Encapsulated datagrams are
75prepended an outer datagram and a GRE header.
76The GRE header specifies
77the type of the encapsulated datagram and thus allows for tunneling other
78protocols than IP.
79GRE mode is also the default tunnel mode on Cisco routers.
80This is also the default mode of operation of the
81.Nm
82interfaces.
83As part of the GRE mode,
84.Nm
85also supports Cisco WCCP protocol, both version 1 and version 2.
86Since there is no reliable way to distinguish between WCCP versions, it
87should be configured manually using the
88.Cm link2
89flag.
90If the
91.Cm link2
92flag is not set (default), then WCCP version 1 is selected.
93.It "MOBILE encapsulation (IP protocol number 55)"
94Datagrams are
95encapsulated into IP, but with a shorter encapsulation.
96The original
97IP header is modified and the modifications are inserted between the
98so modified header and the original payload.
99Like
100.Xr gif 4 ,
101only for IP-in-IP encapsulation.
102.El
103.Pp
104The
105.Nm
106interfaces support a number of
107.Xr ioctl 2 Ns s ,
108such as:
109.Bl -tag -width ".Dv GRESADDRS"
110.It Dv GRESADDRS
111Set the IP address of the local tunnel end.
112This is the source address
113set by or displayed by
114.Xr ifconfig 8
115for the
116.Nm
117interface.
118.It Dv GRESADDRD
119Set the IP address of the remote tunnel end.
120This is the destination address
121set by or displayed by
122.Xr ifconfig 8
123for the
124.Nm
125interface.
126.It Dv GREGADDRS
127Query the IP address that is set for the local tunnel end.
128This is the
129address the encapsulation header carries as local address (i.e., the real
130address of the tunnel start point).
131.It Dv GREGADDRD
132Query the IP address that is set for the remote tunnel end.
133This is the
134address the encapsulated packets are sent to (i.e., the real address of
135the remote tunnel endpoint).
136.It Dv GRESPROTO
137Set the operation mode to the specified IP protocol value.
138The
139protocol is passed to the interface in
140.Po Vt "struct ifreq" Pc Ns Li -> Ns Va ifr_flags .
141The operation mode can also be given as
142.Pp
143.Bl -tag -width ".Cm -link0" -compact
144.It Cm link0
145.Dv IPPROTO_GRE
146.It Cm -link0
147.Dv IPPROTO_MOBILE
148.El
149.Pp
150to
151.Xr ifconfig 8 .
152.Pp
153The
154.Cm link1
155flag is not used to choose encapsulation, but to modify the
156internal route search for the remote tunnel endpoint, see the
157.Sx BUGS
158section below.
159.It Dv GREGPROTO
160Query operation mode.
161.It Dv GRESKEY
162Set the GRE key used for outgoing packets.
163A value of 0 disables the key option.
164.It Dv GREGKEY
165Get the GRE key currently used for outgoing packets.
1660 means no outgoing key.
167.El
168.Pp
169Note that the IP addresses of the tunnel endpoints may be the same as the
170ones defined with
171.Xr ifconfig 8
172for the interface (as if IP is encapsulated), but need not be.
173.Sh EXAMPLES
174Configuration example:
175.Bd -literal
176Host X-- Host A  ----------------tunnel---------- Cisco D------Host E
177          \\                                          |
178           \\                                        /
179            +------Host B----------Host C----------+
180.Ed
181.Pp
182On host A
183.Pq Fx :
184.Bd -literal -offset indent
185route add default B
186ifconfig greN create
187ifconfig greN A D netmask 0xffffffff linkX up
188ifconfig greN tunnel A D
189route add E D
190.Ed
191.Pp
192On Host D (Cisco):
193.Bd -literal -offset indent
194Interface TunnelX
195 ip unnumbered D   ! e.g. address from Ethernet interface
196 tunnel source D   ! e.g. address from Ethernet interface
197 tunnel destination A
198ip route C <some interface and mask>
199ip route A mask C
200ip route X mask tunnelX
201.Ed
202.Pp
203OR
204.Pp
205On Host D
206.Pq Fx :
207.Bd -literal -offset indent
208route add default C
209ifconfig greN create
210ifconfig greN D A
211ifconfig greN tunnel D A
212.Ed
213.Pp
214If all goes well, you should see packets flowing ;-)
215.Pp
216If you want to reach Host A over the tunnel (from Host D (Cisco)), then
217you have to have an alias on Host A for e.g.\& the Ethernet interface like:
218.Pp
219.Dl "ifconfig <etherif> alias Y"
220.Pp
221and on the Cisco:
222.Pp
223.Dl "ip route Y mask tunnelX"
224.Pp
225A similar setup can be used to create a link between two private networks
226(for example in the 192.168 subnet) over the Internet:
227.Bd -literal
228192.168.1.* --- Router A  -------tunnel-------- Router B --- 192.168.2.*
229                   \\                              /
230                    \\                            /
231                     +------ the Internet ------+
232.Ed
233.Pp
234Assuming router A has the (external) IP address A and the internal address
235192.168.1.1, while router B has external address B and internal address
236192.168.2.1, the following commands will configure the tunnel:
237.Pp
238On router A:
239.Bd -literal -offset indent
240ifconfig greN create
241ifconfig greN 192.168.1.1 192.168.2.1 link1
242ifconfig greN tunnel A B
243route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
244.Ed
245.Pp
246On router B:
247.Bd -literal -offset indent
248ifconfig greN create
249ifconfig greN 192.168.2.1 192.168.1.1 link1
250ifconfig greN tunnel B A
251route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
252.Ed
253.Pp
254Note that this is a safe situation where the
255.Cm link1
256flag (as discussed in the
257.Sx BUGS
258section below) may (and probably should) be set.
259.Sh NOTES
260The MTU of
261.Nm
262interfaces is set to 1476 by default, to match the value used by Cisco routers.
263If grekey is set this is lowered to 1472.
264This may not be an optimal value, depending on the link between the two tunnel
265endpoints.
266It can be adjusted via
267.Xr ifconfig 8 .
268.Pp
269For correct operation, the
270.Nm
271device needs a route to the destination that is less specific than the
272one over the tunnel.
273(Basically, there needs to be a route to the decapsulating host that
274does not run over the tunnel, as this would be a loop.)
275If the addresses are ambiguous, doing the
276.Nm ifconfig Cm tunnel
277step before the
278.Xr ifconfig 8
279call to set the
280.Nm
281IP addresses will help to find a route outside the tunnel.
282.Pp
283In order to tell
284.Xr ifconfig 8
285to actually mark the interface as
286.Dq up ,
287the keyword
288.Cm up
289must be given last on its command line.
290.Pp
291The kernel must be set to forward datagrams by setting the
292.Va net.inet.ip.forwarding
293.Xr sysctl 8
294variable to non-zero.
295.Sh SEE ALSO
296.Xr gif 4 ,
297.Xr inet 4 ,
298.Xr ip 4 ,
299.Xr netintro 4 ,
300.\" Xr options 4 ,
301.Xr protocols 5 ,
302.Xr ifconfig 8 ,
303.Xr sysctl 8
304.Pp
305A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
306.Pp
307A description of MOBILE encapsulation can be found in RFC 2004.
308.Sh AUTHORS
309.An Heiko W.Rupp Aq Mt hwr@pilhuhn.de
310.Sh BUGS
311The
312.Fn compute_route
313code in
314.Pa if_gre.c
315toggles the last bit of the
316IP-address to provoke the search for a less specific route than the
317one directly over the tunnel to prevent loops.
318This is possibly not the best solution.
319.Pp
320To avoid the address munging described above, turn on the
321.Cm link1
322flag on the
323.Xr ifconfig 8
324command line.
325This implies that the GRE packet destination and the ifconfig remote host
326are not the same IP addresses, and that the GRE destination does not route
327over the
328.Nm
329interface itself.
330.Pp
331The current implementation uses the key only for outgoing packets.
332Incoming packets with a different key or without a key will be treated as if they
333would belong to this interface.
334.Pp
335RFC1701 is not fully supported, however all unsupported features have been
336deprecated in RFC2784.
337