1.\" $OpenBSD: gif.4,v 1.24 2009/11/24 19:13:07 jmc Exp $ 2.\" $KAME: gif.4,v 1.15 2000/04/19 09:39:42 itojun Exp $ 3.\" 4.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 3. Neither the name of the project nor the names of its contributors 16.\" may be used to endorse or promote products derived from this software 17.\" without specific prior written permission. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22.\" ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" SUCH DAMAGE. 30.\" 31.Dd $Mdocdate: November 24 2009 $ 32.Dt GIF 4 33.Os 34.Sh NAME 35.Nm gif 36.Nd generic tunnel interface 37.Sh SYNOPSIS 38.Cd "pseudo-device gif" 39.Sh DESCRIPTION 40The 41.Nm 42interface is a generic tunnelling pseudo-device for IPv4 and IPv6. 43It can tunnel IPv[46] over IPv[46] with behavior mainly based on 44RFC 1933 IPv6-over-IPv4, for a total of four possible combinations. 45When instead used as a member in a 46.Xr bridge 4 , 47it will tunnel Ethernet packets over IPv[46] using RFC 3378 EtherIP 48encapsulation (version 3), providing two more combinations. 49.Pp 50A 51.Nm 52interface can be created at runtime using the 53.Ic ifconfig gif Ns Ar N Ic create 54command or by setting up a 55.Xr hostname.if 5 56configuration file for 57.Xr netstart 8 . 58.Pp 59For all six modes the 60.Nm 61interface must be configured with the 62addresses used for the outer header. 63This can be done by using 64.Xr ifconfig 8 's 65.Ic tunnel 66command (which uses the 67.Dv SIOCSIFPHYADDR 68ioctl). 69.Pp 70For the IPv[46] over IPv[46] modes the addresses of the inner 71header must be configured by using 72.Xr ifconfig 8 73in the normal way. 74Note that IPv6 link-local address 75.Pq those start with Li fe80:: 76will be automatically configured whenever possible. 77One may need to remove any IPv6 link-local address manually using 78.Xr ifconfig 8 , 79to disable the use of IPv6 as inner header, for example when 80a pure IPv4-over-IPv6 tunnel is required. 81The routing table can be used to direct packets toward the 82.Nm 83interface. 84.Pp 85For the Ethernet-over-IP modes the 86.Nm 87interface must be made a member of a 88.Xr bridge 4 . 89The 90.Xr sysctl 3 91variable 92.Dv net.inet.etherip.allow 93must be set to 1, unless 94.Xr ipsec 4 95is being used to protect the traffic. 96Ethernet frames are then encapsulated and sent across the network 97to another 98.Xr bridge 4 , 99which decapsulates the datagram and processes the resulting Ethernet 100frame as if it had originated on a normal Ethernet interface. 101This effectively allows a layer 2 network to be extended from one point to 102another, possibly through the Internet. 103This mechanism may be used in 104conjunction with IPsec by specifying the appropriate IPsec flows 105between the two bridges. 106To only protect the bridge traffic between 107the two bridges, the transport protocol 97 (etherip) selector may be 108used in 109.Xr ipsec.conf 5 . 110Otherwise, the Ethernet frames will be sent in the clear between the 111two bridges. 112.Sh EXAMPLES 113Given two physically separate Ethernet networks, a bridge can 114be used as follows to make them appear as the same local area network. 115If bridge1 on network1 has the external IP address 1.2.3.4 on fxp0, 116bridge2 on network2 has the external IP address 4.3.2.1 on fxp0, and 117both bridges have fxp1 on their internal network (network1 and network2, 118respectively), the following configuration can be used to bridge 119network1 and network2. 120.Pp 121First create the bridge interface, 122adding the encapsulation interface and internal Ethernet interface 123to the bridge interface: 124.Bd -literal -offset indent 125# ifconfig bridge0 add gif0 add fxp1 126.Ed 127.Pp 128Create and configure the gif0 interface: 129.Bd -literal -offset indent 130(on bridge 1) # ifconfig gif0 tunnel 1.2.3.4 4.3.2.1 131(on bridge 2) # ifconfig gif0 tunnel 4.3.2.1 1.2.3.4 132.Ed 133.Pp 134Create Security Associations (SAs) between the external IP address of each 135bridge and matching ingress flows by using the following 136.Xr ipsec.conf 5 137file on bridge1: 138.Bd -literal -offset indent 139esp from 1.2.3.4 to 4.3.2.1 spi 0x4242:0x4243 \e 140 authkey file "auth1:auth2" enckey file "enc1:enc2" 141flow esp proto etherip from 1.2.3.4 to 4.3.2.1 142.Ed 143.Pp 144Now load these rules into the kernel by issuing the 145.Xr ipsecctl 8 146command: 147.Bd -literal -offset indent 148# ipsecctl -f ipsec.conf 149.Ed 150.Pp 151Appropriate 152.Xr ipsec.conf 5 153for bridge2: 154.Bd -literal -offset indent 155esp from 4.3.2.1 to 1.2.3.4 spi 0x4243:0x4242 \e 156 authkey file "auth2:auth1" enckey file "enc2:enc1" 157flow esp proto etherip from 4.3.2.1 to 1.2.3.4 158.Ed 159.Pp 160And load them: 161.Bd -literal -offset indent 162# ipsecctl -f ipsec.conf 163.Ed 164.Pp 165To use dynamic (as opposed to static) keying, 166use this 167.Xr ipsec.conf 5 168on bridge1: 169.Bd -literal -offset indent 170ike esp proto etherip from 1.2.3.4 to 4.3.2.1 171.Ed 172.Pp 173And on bridge2: 174.Bd -literal -offset indent 175ike esp proto etherip from 4.3.2.1 to 1.2.3.4 176.Ed 177.Pp 178Bring up the internal interface (if not already up) and encapsulation 179interface: 180.Bd -literal -offset indent 181# ifconfig fxp1 up 182# ifconfig gif0 up 183.Ed 184.Pp 185Finally, bring the bridge interface up and allow it to start processing 186frames: 187.Pp 188.Dl # ifconfig bridge0 up link2 189.Pp 190The internal interface on each bridge need not have an IP 191address: the bridge can function without it. 192.Pp 193Note: It is possible to put the above commands in the 194.Xr hostname.if 5 195files, using the 196.Sq !\& 197operator. 198.Sh SEE ALSO 199.Xr sysctl 3 , 200.Xr bridge 4 , 201.Xr inet 4 , 202.Xr inet6 4 , 203.Xr ipsec 4 , 204.Xr hostname.if 5 , 205.Xr ifconfig 8 , 206.Xr netstart 8 207.Rs 208.%A R. Gilligan 209.%A E. Nordmark 210.%B RFC 1933 211.%T Transition Mechanisms for IPv6 Hosts and Routers 212.%D April 1996 213.Re 214.Rs 215.%A R. Housley 216.%A S. Hollenbeck 217.%B RFC 3378 218.%T EtherIP: Tunneling Ethernet Frames in IP Datagrams 219.%D September 2002 220.Re 221.Sh HISTORY 222The 223.Nm 224device first appeared in WIDE hydrangea IPv6 kit. 225.Sh BUGS 226There are many tunnelling protocol specifications, 227defined differently from each other. 228.Nm 229may not interoperate with peers which are based on different specifications, 230and are picky about outer header fields. 231For example, you cannot usually use 232.Nm 233to talk with IPsec devices that use IPsec tunnel mode. 234.Pp 235The current code does not check if the ingress address 236.Pq outer source address 237configured to 238.Nm 239makes sense. 240Make sure to configure an address which belongs to your node. 241Otherwise, your node will not be able to receive packets from the peer, 242and your node will generate packets with a spoofed source address. 243.Pp 244If the outer protocol is IPv6, path MTU discovery for encapsulated packet 245may affect communication over the interface. 246.Pp 247When used in conjunction with a 248.Xr bridge 4 249interface, 250only one bridge tunnel may be operational for every pair of 251source/destination addresses. 252If more than one 253.Nm 254interface is configured with the same pair of outer addresses, the 255one with the lowest index number will receive all traffic. 256