1.\" $NetBSD: ipsec.4,v 1.41 2017/05/21 09:13:46 wiz Exp $ 2.\" $KAME: ipsec.4,v 1.17 2001/06/27 15:25:10 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 March 6, 2017 32.Dt IPSEC 4 33.Os 34.Sh NAME 35.Nm ipsec 36.Nd IP security protocol 37.Sh DESCRIPTION 38.Nm 39is a security protocol in the Internet Protocol (IP) layer. 40.Nm 41is defined for both IPv4 and IPv6 42.Po 43.Xr inet 4 44and 45.Xr inet6 4 46.Pc . 47.Nm 48consists of two sub-protocols: 49.Bl -hang 50.It Em Encapsulated Security Payload Pq ESP 51protects IP payloads from wire-tapping (interception) by encrypting them with 52secret key cryptography algorithms. 53.It Em Authentication Header Pq AH 54guarantees the integrity of IP packets 55and protects them from intermediate alteration or impersonation, 56by attaching cryptographic checksums computed by one-way hash functions. 57.El 58.Pp 59.Nm 60has two operation modes: 61.Bl -hang 62.It Em Transport mode 63is for protecting peer-to-peer communication between end nodes. 64.It Em Tunnel mode 65includes IP-in-IP encapsulation operation 66and is designed for security gateways, as in Virtual Private Network 67.Pq Tn VPN 68configurations. 69.El 70.Pp 71Since version 6, 72.Nx 73uses the IPSEC implementation formerly known as FAST_IPSEC. 74Its specifics and kernel options are described in the 75.Xr fast_ipsec 4 76manual page. 77.Ss Kernel interface 78.Nm 79is controlled by two engines in the kernel: one for key management 80and one for policy. 81.Pp 82The key management engine can be accessed from userland by using 83.Dv PF_KEY 84sockets. 85The 86.Dv PF_KEY 87socket API is defined in RFC2367. 88.Pp 89The policy engine can be controlled through the 90.Dv PF_KEY 91API, 92.Xr setsockopt 2 93operations, and 94the 95.Xr sysctl 3 96interface. 97The kernel implements an 98extended version of the 99.Dv PF_KEY 100interface and allows you to define IPsec policy like per-packet filters. 101.Xr setsockopt 2 102is used to define per-socket behavior, and 103.Xr sysctl 3 104is used to define host-wide default behavior. 105.Pp 106The kernel does not implement dynamic encryption key exchange protocols 107like IKE 108.Pq Internet Key Exchange . 109That should be done in userland 110.Pq usually as a daemon , 111using the APIs described above. 112.\" 113.Ss Policy management 114The kernel implements experimental policy management code. 115You can manage the IPsec policy in two ways. 116One is to configure per-socket policy using 117.Xr setsockopt 2 . 118The other is to configure kernel packet filter-based policy using the 119.Dv PF_KEY 120interface, via 121.Xr setkey 8 . 122In both cases, IPsec policy must be specified with syntax described in 123.Xr ipsec_set_policy 3 . 124.Pp 125With 126.Xr setsockopt 2 , 127you can define IPsec policy on a per-socket basis. 128You can enforce particular IPsec policy on packets that go through a 129particular socket. 130.Pp 131With 132.Xr setkey 8 133you can define IPsec policy for packets using a form of packet 134filtering rules. 135See 136.Xr setkey 8 137for details. 138.Pp 139In the latter case, 140.Dq Li default 141policy is allowed for use with 142.Xr setkey 8 . 143By configuring policy to 144.Li default , 145you can refer to system-wide 146.Xr sysctl 8 147variables for default settings. 148The following variables are available. 149.Li 1 150means 151.Dq Li use , 152and 153.Li 2 154means 155.Dq Li require 156in the syntax. 157.Bl -column net.inet6.ipsec6.esp_trans_deflev integerxxx 158.It Sy Name Ta Sy Type Ta Sy Changeable 159.It net.inet.ipsec.esp_trans_deflev Ta integer Ta yes 160.It net.inet.ipsec.esp_net_deflev Ta integer Ta yes 161.It net.inet.ipsec.ah_trans_deflev Ta integer Ta yes 162.It net.inet.ipsec.ah_net_deflev Ta integer Ta yes 163.It net.inet6.ipsec6.esp_trans_deflev Ta integer Ta yes 164.It net.inet6.ipsec6.esp_net_deflev Ta integer Ta yes 165.It net.inet6.ipsec6.ah_trans_deflev Ta integer Ta yes 166.It net.inet6.ipsec6.ah_net_deflev Ta integer Ta yes 167.El 168.Pp 169If the kernel finds no matching policy, the system-wide default 170value is applied. 171System-wide defaults are specified by the following 172.Xr sysctl 8 173variables. 174.Li 0 175means 176.Dq Li discard 177which asks the kernel to drop the packet. 178.Li 1 179means 180.Dq Li none . 181.Bl -column net.inet6.ipsec6.esp_trans_deflev integerxxx 182.It Sy Name Ta Sy Type Ta Sy Changeable 183.It net.inet.ipsec.def_policy Ta integer Ta yes 184.It net.inet6.ipsec6.def_policy Ta integer Ta yes 185.El 186.\" 187.Ss Miscellaneous sysctl variables 188The following variables are accessible via 189.Xr sysctl 8 , 190for tweaking kernel IPsec behavior: 191.Bl -column net.inet6.ipsec6.esp_trans_deflev integerxxx 192.It Sy Name Ta Sy Type Ta Sy Changeable 193.It net.inet.ipsec.ah_cleartos Ta integer Ta yes 194.It net.inet.ipsec.ah_offsetmask Ta integer Ta yes 195.It net.inet.ipsec.crypto_support Ta integer Ta yes 196.It net.inet.ipsec.dfbit Ta integer Ta yes 197.It net.inet.ipsec.ecn Ta integer Ta yes 198.It net.inet.ipsec.debug Ta integer Ta yes 199.It net.inet6.ipsec6.ecn Ta integer Ta yes 200.It net.inet6.ipsec6.debug Ta integer Ta yes 201.El 202.Pp 203The variables are interpreted as follows: 204.Bl -tag -width "123456" 205.It Li ipsec.ah_cleartos 206If set to non-zero, the kernel clears the type-of-service field in the 207IPv4 header during AH authentication data computation. 208The variable is for tweaking AH behavior to interoperate with devices that 209implement RFC1826 AH. 210It should be set to non-zero 211.Pq clear the type-of-service field 212for RFC2402 conformance. 213.It Li ipsec.ah_offsetmask 214During AH authentication data computation, the kernel will include a 21516 bit fragment offset field 216.Pq including flag bits 217in the IPv4 header, after computing logical AND with the variable. 218The variable is for tweaking AH behavior to interoperate with devices that 219implement RFC1826 AH. 220It should be set to zero 221.Pq clear the fragment offset field during computation 222for RFC2402 conformance. 223.It Li ipsec.crypto_support 224This variable configures the kernel behavior for selecting encryption drivers. 225If set to > 0, the kernel will select a hardware encryption driver first. 226If set to < 0, the kernel will select a software encryption driver first. 227If set to 0, the kernel will select either a hardware or software driver. 228.It Li ipsec.dfbit 229This variable configures the kernel behavior on IPv4 IPsec tunnel encapsulation. 230If set to 0, the DF bit on the outer IPv4 header will be cleared. 2311 means that the outer DF bit is set from the inner DF bit. 2322 means that the DF bit is copied from the inner header to the outer. 233The variable is supplied to conform to RFC2401 chapter 6.1. 234.It Li ipsec.ecn 235If set to non-zero, IPv4 IPsec tunnel encapsulation/decapsulation behavior will 236be friendly to ECN 237.Pq explicit congestion notification , 238as documented in 239.Li draft-ietf-ipsec-ecn-02.txt . 240.Xr gif 4 241talks more about the behavior. 242.It Li ipsec.debug 243If set to non-zero, debug messages will be generated via 244.Xr syslog 3 . 245.El 246.Pp 247Variables under the 248.Li net.inet6.ipsec6 249tree have similar meanings to their 250.Li net.inet.ipsec 251counterparts. 252.\" 253.Sh PROTOCOLS 254The 255.Nm 256protocol works like a plug-in to 257.Xr inet 4 258and 259.Xr inet6 4 260protocols. 261Therefore, 262.Nm 263supports most of the protocols defined upon those IP-layer protocols. 264Some of the protocols, like 265.Xr icmp 4 266or 267.Xr icmp6 4 , 268may behave differently with 269.Nm ipsec . 270This is because 271.Nm 272can prevent 273.Xr icmp 4 274or 275.Xr icmp6 4 276routines from looking into IP payload. 277.\" 278.Sh SEE ALSO 279.Xr ioctl 2 , 280.Xr socket 2 , 281.Xr ipsec_set_policy 3 , 282.Xr fast_ipsec 4 , 283.Xr icmp6 4 , 284.Xr intro 4 , 285.Xr ip6 4 , 286.Xr racoon 8 , 287.Xr setkey 8 , 288.Xr sysctl 8 289.Sh STANDARDS 290.Rs 291.%A Daniel L. McDonald 292.%A Craig Metz 293.%A Bao G. Phan 294.%T "PF_KEY Key Management API, Version 2" 295.%R RFC 296.%N 2367 297.Re 298.Sh BUGS 299IPsec support is subject to change as the IPsec protocols develop. 300.Pp 301There is no single standard for policy engine API, 302so the policy engine API described herein is just for the version 303introduced by KAME. 304.Pp 305AH and tunnel mode encapsulation may not work as you might expect. 306If you configure inbound 307.Dq require 308policy against AH tunnel or any IPsec encapsulating policy with AH 309.Po 310like 311.Dq Li esp/tunnel/A-B/use ah/transport/A-B/require 312.Pc , 313tunneled packets will be rejected. 314This is because we enforce policy check on inner packet on reception, 315and AH authenticates encapsulating 316.Pq outer 317packet, not the encapsulated 318.Pq inner 319packet 320.Po 321so for the receiving kernel there's no sign of authenticity 322.Pc . 323The issue will be solved when we revamp our policy engine to keep all the 324packet decapsulation history. 325.Pp 326Under certain condition, 327truncated result may be raised from the kernel 328against 329.Dv SADB_DUMP 330and 331.Dv SADB_SPDDUMP 332operation on 333.Dv PF_KEY 334socket. 335This occurs if there are too many database entries in the kernel 336and socket buffer for the 337.Dv PF_KEY 338socket is insufficient. 339If you manipulate many IPsec key/policy database entries, 340increase the size of socket buffer or use 341.Xr sysctl 8 342interface. 343