GRE(4)

NAME
gre - encapsulating network device

SYNOPSIS
pseudo-device gre [count]

DESCRIPTION
The gre network interface is a pseudo device that allows to encapsulate datagrams into IP. These encapsulated datagrams are routed to a destination host, where they are decapsulated and further routed to their final destination. The so called ``tunnel'' appears to the inner datagrams like one hop.

This driver currently supports the following modes of operation:

GRE encapsulation (IP protocol number 47).
    Encapsulated datagrams are prepended by a 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 (not yet supported). GRE mode is also the default tunnel mode on Cisco routers. This is also the default mode of operation of the greX interfaces.

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 IPIP only for IP in IP encapsulation.

The network interfaces are named gre0, gre1 and so on, as many as have given on the pseudo-device line in the system config file. Each interface supports a number of ioctl(2)s, such as:

GRESADDRS:
    Set the IP address of the local tunnel end.

GRESADDRD:
    Set the IP address of the remote tunnel end.

GREGADDRS:
    Query the the IP address that is set for the local tunnel end.

GREGADDRD:
    Query the the IP address that is set for the remote tunnel end.

GRESPROTO:
    Set the operation mode to the the specified IP protocol value. The protocol is passed to the interface in (struct ifreq)->ifr_flags. The operation mode can also be given as

    link0
        IPPROTO_GRE

    link2
        IPPROTO_MOBILE
    to ifconfig. As the linkN flags are not mutually exclusive, modes must be set by applying positive and negative flags as e.g. ifconfig link0 -link1 -link2

GREGPROTO:
    Query operation mode.

Note that the IP addresses of the tunnel endpoints may be the same as the ones defined with ifconfig for the interface (as if IP is encapsulated), but need not be, as e.g. when encapsulating AppleTalk.

EXAMPLE
Configuration example: Host X-- Host A ----------------tunnel---------- cisco D------Host E \ | \ / +------Host B----------Host C----------+ On host A (NetBSD): # route add default B # ifconfig greN A D netmask 0xffffffff linkX up # greconfig -i greN -s A -d D # route add E D On Host D (Cisco): 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 <some interface and mask> ip route A mask C ip route X mask tunnelX OR On Host D (NetBSD): # route add default C # ifconfig greN D A

If all goes well, you should see packets flowing ;-)

If you want to reach Host A over the tunnel (from the Cisco D), then you have to have an alias on Host A for e.g. the ethernet interface like: ifconfig <etherif> alias Y and on the cisco ip route Y mask tunnelX

NOTE
For correct operation, the gre device needs a route to the destination, that is less specific than the one over the tunnel. (Basically, there needs to be a route to the decapsulating host that does not run over the tunnel, as this would be a loop ..)

In order to ifconfig to actually mark the interface as up, the keyword ``up'' must be given last on its command line.

The kernel must be set to forward datagrams by either option ``GATEWAY'' in the kernel config file or by issuing the appropriate option to sysctl.

SEE ALSO
netintro(4), ip(4), atalk(4), inet(4), ifconfig(8), greconfig(8), options(4), protocols(5), sysctl(8)

A description of GRE encapsulation can be found in RFC 1701, RFC 1702.

A description of MOBILE encapsulation can be found in RFC 2004.

BUGS
The compute_route() code in if_gre.c toggles the last bit of the IP-address to provoke the search for a less specific route than the one directly over the tunnel to prevent loops. This is possibly not the best solution.

GRE RFC not yet fully implemented (no GRE options), no other protocols yet than IP over IP.

Traceroute does not work yet over the tunnel :(

BPF does probably not yet work (it might, but last time I looked, it bombed, so I #if 0'd it out).

AUTHOR
Heiko W.Rupp <hwr@pilhuhn.de>