The
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 “tunnel” appears to the inner datagrams as one hop.
gre interfaces are dynamically created and destroyed with the
ifconfig(8) create and
destroy subcommands.
This driver currently supports the following modes of operation:
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 greX interfaces.
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 “delegate” it to the kernel using the
GRESSOCK ioctl(2). If userland does not supply a socket, then the kernel will create one using the addresses and ports supplied by
ioctl(2)s
SIOCSLIFPHYADDR,
GRESADDRD, and/or
GRESADDRS.
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
gif(4), only for IP in IP encapsulation.
The
greX interfaces support a number of
ioctl(2)s, such as:
GRESADDRS:
Set the IP address of the local tunnel end. This is the source address set by or displayed by ifconfig for the greX interface.
GRESADDRD:
Set the IP address of the remote tunnel end. This is the destination address set by or displayed by ifconfig for the greX interface.
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.)
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.)
GRESPROTO:
Set the operation mode to 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 -link2
IPPROTO_MOBILE
to
ifconfig(8).
GREGPROTO:
Query operation mode.
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)->ifr_value.
Note that the IP addresses of the tunnel endpoints may be the same as the ones defined with
ifconfig(8) for the interface (as if IP is encapsulated), but need not be, as e.g. when encapsulating AppleTalk.