[BACK]Return to gre.4 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / share / man / man4

File: [cvs.NetBSD.org] / src / share / man / man4 / gre.4 (download)

Revision 1.42, Sun Jan 4 22:55:02 2009 UTC (15 years, 3 months ago) by he
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, uebayasi-xip-base7, uebayasi-xip-base6, uebayasi-xip-base5, uebayasi-xip-base4, uebayasi-xip-base3, uebayasi-xip-base2, uebayasi-xip-base1, uebayasi-xip, riastradh-drm2-base, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-premerge-20091211, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, jym-xensuspend-nbase, jym-xensuspend-base, jym-xensuspend, cherry-xenmp-base, cherry-xenmp, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver
Branch point for: yamt-pagecache, tls-maxphys, riastradh-drm2
Changes since 1.41: +3 -4 lines

Get rid of an extranous .Ed request, and the warning about
unknown NetBSD version `A'.

.\" $NetBSD: gre.4,v 1.42 2009/01/04 22:55:02 he Exp $
.\"
.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Heiko W.Rupp <hwr@pilhuhn.de>
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd January 4, 2009
.Dt GRE 4
.Os
.Sh NAME
.Nm gre
.Nd encapsulating network device
.Sh SYNOPSIS
.Cd pseudo-device gre
.Sh DESCRIPTION
The
.Nm gre
network interface pseudo device encapsulates datagrams
into IP.
These encapsulated datagrams are routed to a destination host,
where they are decapsulated and further routed to their final destination.
The
.Dq tunnel
appears to the inner datagrams as one hop.
.Pp
.Nm
interfaces are dynamically created and destroyed with the
.Xr ifconfig 8
.Cm create
and
.Cm destroy
subcommands.
.Pp
This driver currently supports the following modes of operation:
.Bl -tag -width abc
.It GRE encapsulation (IP protocol number 47)
Encapsulated datagrams are
prepended an outer datagram and a GRE header.
The GRE header specifies the type of the encapsulated datagram and
thus allows for tunneling other protocols than IP like e.g. AppleTalk.
GRE mode is also the default tunnel mode on Cisco routers.
This is also the default mode of operation of the
.Sy gre Ns Ar X
interfaces.
.It GRE in UDP encapsulation
Encapsulated datagrams are prepended a GRE header, and then they
are sent over a UDP socket.
Userland may create the socket and
.Dq delegate
it to the kernel using the
.Dv GRESSOCK
.Xr ioctl 2 .
If userland does not supply a socket, then the kernel will create
one using the addresses and ports supplied by
.Xr ioctl 2 Ns s
.Dv SIOCSLIFPHYADDR ,
.Dv GRESADDRD ,
and/or
.Dv GRESADDRS .
.It MOBILE encapsulation (IP protocol number 55)
Datagrams are
encapsulated into IP, but with a shorter encapsulation.
The original IP header is modified and the modifications are inserted
between the so modified header and the original payload.
Like
.Xr gif 4 ,
only for IP in IP encapsulation.
.El
.Pp
The
.Sy gre Ns Ar X
interfaces support a number of
.Xr ioctl 2 Ns s ,
such as:
.Bl -tag -width aaa
.It GRESADDRS :
Set the IP address of the local tunnel end.
This is the source address set by or displayed by ifconfig for the
.Sy gre Ns Ar X
interface.
.It GRESADDRD :
Set the IP address of the remote tunnel end.
This is the destination address set by or displayed by ifconfig for the
.Sy gre Ns Ar X
interface.
.It GREGADDRS :
Query the IP address that is set for the local tunnel end.
This is the address the encapsulation header carries as local
address (i.e. the real address of the tunnel start point.)
.It GREGADDRD :
Query the IP address that is set for the remote tunnel end.
This is the address the encapsulated packets are sent to (i.e. the
real address of the remote tunnel endpoint.)
.It GRESPROTO :
Set the operation mode to the specified IP protocol value.
The protocol is passed to the interface in (struct ifreq)-\*[Gt]ifr_flags.
The operation mode can also be given as
.Bl -tag -width link0xxx
.It link0 link2
IPPROTO_UDP
.It link0 -link2
IPPROTO_GRE
.It -link0 -link2
IPPROTO_MOBILE
.El
.Pp
to
.Xr ifconfig 8 .
.It GREGPROTO :
Query operation mode.
.It GRESSOCK :
Delegate a socket from userland to a tunnel interface in UDP
encapsulation mode.
The file descriptor for the socket is passed in
(struct ifreq)-\*[Gt]ifr_value.
.El
.Pp
Note that the IP addresses of the tunnel endpoints may be the same as the
ones defined with
.Xr ifconfig 8
for the interface (as if IP is encapsulated), but need not be, as e.g. when
encapsulating AppleTalk.
.Sh EXAMPLES
.Ss Example 1: Basic GRE tunneling
Configuration example:
.Bd -literal
Host X-- Router A  --------------tunnel---------- Router D ----Host E
          |                                          |
           \\                                        /
            +----- Router B ----- Router C --------+
.Ed
.Pp
On Router A
.Pq Nx :
.Bd -literal
   # route add default B
   # ifconfig greN create
   # ifconfig greN A D netmask 0xffffffff linkX up
   # ifconfig greN tunnel A D
   # route add E D
.Ed
.Pp
On Router D (Cisco):
.Bd -literal
   Interface TunnelX
    ip unnumbered D   ! e.g. address from Ethernet interface
    tunnel source D   ! e.g. address from Ethernet interface
    tunnel destination A
   ip route C \*[Lt]some interface and mask\*[Gt]
   ip route A mask C
   ip route X mask tunnelX
.Ed
.Pp
or on Router D
.Pq Nx :
.Bd -literal
   # route add default C
   # ifconfig greN create
   # ifconfig greN D A
   # ifconfig tunnel greN D A
.Ed
.Pp
If all goes well, you should see packets flowing ;-)
.Pp
If you want to reach Router A over the tunnel (from Router D (Cisco)), then
you have to have an alias on Router A for e.g. the Ethernet interface like:
.Bd -literal
     ifconfig \*[Lt]etherif\*[Gt] alias Y
.Ed
.Pp
and on the Cisco
.Bd -literal
     ip route Y mask tunnelX
.Ed
.Ss Example 2: Linking private subnets
A similar setup can be used to create a link between two private networks
(for example in the 192.168 subnet) over the Internet:
.Bd -literal
192.168.1.* --- Router A  -------tunnel-------- Router B --- 192.168.2.*
                   \\                              /
                    \\                            /
                      +----- the Internet ------+
.Ed
.Pp
Assuming Router A has the (external) IP address A and the internal address
192.168.1.1, while Router B has external address B and internal address
192.168.2.1, the following commands will configure the tunnel:
.Pp
On Router A:
.Bd -literal
   # ifconfig greN create
   # ifconfig greN 192.168.1.1 192.168.2.1
   # ifconfig greN tunnel A B
   # route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
.Ed
.Pp
On Router B:
.Bd -literal
   # ifconfig greN create
   # ifconfig greN 192.168.2.1 192.168.1.1
   # ifconfig greN tunnel B A
   # route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
.Ed
.Ss Example 3: Encapsulating GRE in UDP
To setup the same tunnel as above, but using GRE in UDP encapsulation
instead of GRE encapsulation, set flags
.Ar link0
and
.Ar link2 ,
and specify source and destination UDP ports.
.Pp
On Router A:
.Bd -literal
   # ifconfig greN create
   # ifconfig greN link0 link2
   # ifconfig greN 192.168.1.1 192.168.2.1
   # ifconfig greN tunnel A,port-A B,port-B
   # route add -net 192.168.2 -netmask 255.255.255.0 192.168.2.1
.Ed
.Pp
On Router B:
.Bd -literal
   # ifconfig greN create
   # ifconfig greN link0 link2
   # ifconfig greN 192.168.2.1 192.168.1.1
   # ifconfig greN tunnel B,port-B A,port-A
   # route add -net 192.168.1 -netmask 255.255.255.0 192.168.1.1
.Ed
.Ss Example 4: Realizing IPv6 connectivity
Along these lines, you can use GRE tunnels to interconnect two IPv6
networks over an IPv4 infrastructure, or to hook up to the IPv6 internet
via an IPv4 tunnel to a Cisco router.
.Bd -literal
2001:db8:1::/64 -- NetBSD A  ---- Tunnel ---- Cisco B --- IPv6 Internet
                   \\                              /
                    \\                            /
                     +------ the Internet ------+
.Ed
.Pp
The example will use the following addressing:
.Bl -hang
.It Nx
A has the IPv4 address A and the IPv6 address 2001:db8:1::1 (connects
to internal network 2001:db8:1::/64).
.It Cisco B
has external IPv4 address B.
.It All the IPv6 internet world
is behind B, so A wants to route 0::0/0
(the IPv6 default route) into the tunnel.
.It The GRE tunnel
will use a transit network: 2001:db8:ffff::1/64 on
the
.Nx
side, and ::2/64 on the Cisco side.
.El
.Pp
Then the following commands will configure the tunnel:
.Pp
On Router A
.Pq Nx :
.Bd -literal
   # ifconfig greN create
   # ifconfig greN inet6 2001:db8:ffff::1/64
   # ifconfig greN tunnel A B
   # route add -inet6 2001:db8:ffff::/64 2001:db8:ffff::2 -ifp greN
   # route add -inet6 0::0/0 2001:db8:ffff::2 -ifp greN
.Ed
.Pp
On Router B (Cisco):
.Bd -literal
   Interface TunnelX
     tunnel mode gre ip
     ipv6 address 2001:db8:ffff::2/64   ! transfer network
     tunnel source B                    ! e.g. address from LAN interface
     tunnel destination A               ! where the tunnel is connected to
   ipv6 route 2001:db8::/64 TunnelX     ! route this network through tunnel
.Ed
.Sh NOTES
The MTU of
.Sy gre Ns Ar X
interfaces is set to 1476 by default to match the value used by Cisco routers.
This may not be an optimal value, depending on the link between the two tunnel
endpoints.
It can be adjusted via
.Xr ifconfig 8 .
.Pp
There needs to be a route to the decapsulating host that does not
run over the tunnel, as this would be a loop.
(This is not relevant for IPv6-over-IPv4 tunnels, of course.)
.Pp
In order to tell
.Xr ifconfig 8
to actually mark the interface as up, the keyword
.Dq up
must be given last on its command line.
.Pp
The kernel must be set to forward datagrams by either option
.Em GATEWAY
in the kernel config file or by issuing the appropriate option to
.Xr sysctl 8 .
.Sh SEE ALSO
.Xr atalk 4 ,
.Xr gif 4 ,
.Xr inet 4 ,
.Xr ip 4 ,
.Xr netintro 4 ,
.Xr options 4 ,
.Xr protocols 5 ,
.Xr ifconfig 8 ,
.Xr sysctl 8
.Pp
A description of GRE encapsulation can be found in RFC 1701 and RFC 1702.
.Pp
A description of MOBILE encapsulation can be found in RFC 2004.
.Sh AUTHORS
.An Heiko W.Rupp Aq hwr@pilhuhn.de
.An David Young Aq dyoung@NetBSD.org
.Pq GRE in UDP encapsulation, bug fixes
.Sh BUGS
The GRE RFCs are not yet fully implemented (no GRE options).
.Pp
The MOBILE encapsulation appears to have been broken since
it was first added to
.Nx ,
until August 2006.
It is known to interoperate with another
.Nm
in MOBILE mode, however, it has not been tested for interoperability
with any other implementation of RFC 2004.
.Pp
The
.Nx
base system does not
.Pq yet
contain a daemon for automatically establishing a UDP tunnel between
a host behind a NAT router and a host on the Internet.