p .Nm interfaces are dynamically created and destroyed with the .Xr ifconfig 8 .Cm create and .Cm destroy subcommands. The administrator must configure .Nm tunnel endpoint addresses. These addresses will be used for the outer IP header of ESP packets. The administrator also configures the protocol and addresses for the inner IP header with the .Xr ifconfig 8 .Cm inet or .Cm inet6 subcommands, and modify the routing table to route the packets through the .Nm interface.
p The packet processing is similar to .Xr gif 4 over .Xr ipsec 4 transport mode, however the security policy management is different. .Xr gif 4 over .Xr ipsec 4 transport mode expects userland programs to manage their security policies. In contrast, .Nm manages its security policies by itself: when the administrator sets up an .Nm tunnel source and destination address pair, the related security policies are created automatically in the kernel. They are automatically deleted when the tunnel is destroyed.
p It also means that .Nm ensures that both the in and out security policy pairs exist, that is, .Nm avoids the trouble caused when only one of the in and out security policy pair exists.
p There are four security policies generated by .Nm : one in and out pair for IPv4 and IPv6 each. These security policies are equivalent to the following .Xr ipsec.conf 5 configuration where src and dst are IP addresses specified to the tunnel: d -literal -offset indent spdadd "src" "dst" ipv4 -P out ipsec esp/transport//unique; spdadd "dst" "src" ipv4 -P in ipsec esp/transport//unique; spdadd "src" "dst" ipv6 -P out ipsec esp/transport//unique; spdadd "dst" "src" ipv6 -P in ipsec esp/transport//unique; .Ed
p The .Nm configuration will fail if such security policies already exist, and vice versa.
p The related security associations can be established by an IKE daemon such as .Xr racoon 8 . They can also be manipulated manually by .Xr setkey 8 with the .Fl u option which sets a security policy's unique id.
p Some .Xr ifconfig 8 parameters change the behaviour of .Nm . link0 can enable NAT-Traversal, link1 can enable ECN friendly mode like .Xr gif 4 , and link2 can enable forwarding inner IPv6 packets. Only link2 is set by default. If you use only IPv4 packets as inner packets, you would want to do d -literal -offset indent ifconfig ipsec0 -link2 .Ed
p to reduce security associations for IPv6 packets. .Sh EXAMPLES Configuration example: d -literal Out IP addr = 172.16.100.1 Out IP addr = 172.16.200.1 wm0 = 192.168.0.1/24 wm0 = 192.168.0.2/24 wm1 = 10.100.0.1/24 wm1 = 10.200.0.1/24 +------------+ +------------+ | NetBSD_A | | NetBSD_B | |------------| |------------| | [ipsec0] - - - - - - - - (tunnel) - - - - - - - - [ipsec0] | | [wm0]------------- ... --------------[wm0] | | | | | +---[wm1]----+ +----[wm1]---+ | | | | +------------+ +------------+ | Host_X | | Host_Y | +------------+ +------------+ .Ed
p Host_X and Host_Y will be able to communicate via an IPv4 IPsec tunnel.
p On NetBSD_A: d -literal # ifconfig wm0 inet 192.168.0.1/24 # ifconfig ipsec0 create # ifconfig ipsec0 tunnel 192.168.0.1 192.168.0.2 # ifconfig ipsec0 inet 172.16.100.1/32 172.16.200.1 start IKE daemon or set security associations manually. # ifconfig wm1 inet 10.100.0.1/24 # route add 10.200.0.1 172.16.100.1 .Ed
p On NetBSD_B: d -literal # ifconfig wm0 inet 192.168.0.2/24 # ifconfig ipsec0 create # ifconfig ipsec0 tunnel 192.168.0.2 192.168.0.1 # ifconfig ipsec0 inet 172.16.200.1/32 172.16.100.1 start IKE daemon or set security associations manually. # ifconfig wm1 inet 10.200.0.1/24 # route add 10.100.0.1 172.16.200.1 .Ed .Sh SEE ALSO .Xr gif 4 , .Xr inet 4 , .Xr inet6 4 , .Xr ipsec 4 , .Xr ifconfig 8 , .Xr racoon 8 , .Xr setkey 8 .Sh HISTORY The .Nm device first appeared in .Nx 8.0 . .Sh LIMITATIONS Currently, the .Nm interface supports the ESP protocol only. .Nm supports default port number (4500) only for NAT-Traversal.