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