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