xref: /netbsd-src/share/man/man4/ipsec.4 (revision 9ddb6ab554e70fb9bbd90c3d96b812bc57755a14)
1.\"	$NetBSD: ipsec.4,v 1.37 2012/01/23 00:02:42 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 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.
79The previous implementation is still supported for a transition
80period.
81See
82.Xr kame_ipsec 4
83for details.
84.Ss Kernel interface
85.Nm
86is controlled by key management engine and policy engine,
87in the operating system kernel.
88.Pp
89Key management engine can be accessed from the userland by using
90.Dv PF_KEY
91sockets.
92The
93.Dv PF_KEY
94socket API is defined in RFC2367.
95.Pp
96Policy engine can be controlled by extended part of
97.Dv PF_KEY
98API,
99.Xr setsockopt 2
100operations, and
101.Xr sysctl 3
102interface.
103The kernel implements
104extended version of
105.Dv PF_KEY
106interface, and allows you to define IPsec policy like per-packet filters.
107.Xr setsockopt 2
108interface is used to define per-socket behavior, and
109.Xr sysctl 3
110interface is used to define host-wide default behavior.
111.Pp
112The kernel code does not implement dynamic encryption key exchange protocol
113like IKE
114.Pq Internet Key Exchange .
115That should be implemented as userland programs
116.Pq usually as daemons ,
117by using the above described APIs.
118.\"
119.Ss Policy management
120The kernel implements experimental policy management code.
121You can manage the IPsec policy in two ways.
122One is to configure per-socket policy using
123.Xr setsockopt 2 .
124The other is to configure kernel packet filter-based policy using
125.Dv PF_KEY
126interface, via
127.Xr setkey 8 .
128In both cases, IPsec policy must be specified with syntax described in
129.Xr ipsec_set_policy 3 .
130.Pp
131With
132.Xr setsockopt 2 ,
133you can define IPsec policy in per-socket basis.
134You can enforce particular IPsec policy onto packets that go through
135particular socket.
136.Pp
137With
138.Xr setkey 8
139you can define IPsec policy against packets,
140using sort of packet filtering rule.
141Refer to
142.Xr setkey 8
143on how to use it.
144.Pp
145In the latter case,
146.Dq Li default
147policy is allowed for use with
148.Xr setkey 8 .
149By configuring policy to
150.Li default ,
151you can refer system-wide
152.Xr sysctl 8
153variable for default settings.
154The following variables are available.
155.Li 1
156means
157.Dq Li use ,
158and
159.Li 2
160means
161.Dq Li require
162in the syntax.
163.Bl -column net.inet6.ipsec6.esp_trans_deflev integerxxx
164.It Sy Name Ta Sy Type Ta Sy Changeable
165.It net.inet.ipsec.esp_trans_deflev Ta integer Ta yes
166.It net.inet.ipsec.esp_net_deflev Ta integer Ta yes
167.It net.inet.ipsec.ah_trans_deflev Ta integer Ta yes
168.It net.inet.ipsec.ah_net_deflev Ta integer Ta yes
169.It net.inet6.ipsec6.esp_trans_deflev Ta integer Ta yes
170.It net.inet6.ipsec6.esp_net_deflev Ta integer Ta yes
171.It net.inet6.ipsec6.ah_trans_deflev Ta integer Ta yes
172.It net.inet6.ipsec6.ah_net_deflev Ta integer Ta yes
173.El
174.Pp
175If kernel finds no matching policy system wide default value is applied.
176System wide default is specified by the following
177.Xr sysctl 8
178variables.
179.Li 0
180means
181.Dq Li discard
182which asks the kernel to drop the packet.
183.Li 1
184means
185.Dq Li none .
186.Bl -column net.inet6.ipsec6.esp_trans_deflev integerxxx
187.It Sy Name Ta Sy Type Ta Sy Changeable
188.It net.inet.ipsec.def_policy Ta integer Ta yes
189.It net.inet6.ipsec6.def_policy Ta integer Ta yes
190.El
191.\"
192.Ss Miscellaneous sysctl variables
193The following variables are accessible via
194.Xr sysctl 8 ,
195for tweaking kernel IPsec behavior:
196.Bl -column net.inet6.ipsec6.esp_trans_deflev integerxxx
197.It Sy Name Ta Sy Type Ta Sy Changeable
198.It net.inet.ipsec.ah_cleartos Ta integer Ta yes
199.It net.inet.ipsec.ah_offsetmask Ta integer Ta yes
200.It net.inet.ipsec.dfbit Ta integer Ta yes
201.It net.inet.ipsec.ecn Ta integer Ta yes
202.It net.inet.ipsec.debug Ta integer Ta yes
203.It net.inet6.ipsec6.ecn Ta integer Ta yes
204.It net.inet6.ipsec6.debug Ta integer Ta yes
205.El
206.Pp
207The variables are interpreted as follows:
208.Bl -tag -width "123456"
209.It Li ipsec.ah_cleartos
210If set to non-zero, the kernel clears type-of-service field in the IPv4 header
211during AH authentication data computation.
212The variable is for tweaking AH behavior to interoperate with devices that
213implement RFC1826 AH.
214It should be set to non-zero
215.Pq clear the type-of-service field
216for RFC2402 conformance.
217.It Li ipsec.ah_offsetmask
218During AH authentication data computation, the kernel will include
21916bit fragment offset field
220.Pq including flag bits
221in IPv4 header, after computing logical AND with the variable.
222The variable is for tweaking AH behavior to interoperate with devices that
223implement RFC1826 AH.
224It should be set to zero
225.Pq clear the fragment offset field during computation
226for RFC2402 conformance.
227.It Li ipsec.dfbit
228The variable configures the kernel behavior on IPv4 IPsec tunnel encapsulation.
229If set to 0, DF bit on the outer IPv4 header will be cleared.
2301 means that the outer DF bit is set regardless from the inner DF bit.
2312 means that the DF bit is copied from the inner header to the outer.
232The variable is supplied to conform to RFC2401 chapter 6.1.
233.It Li ipsec.ecn
234If set to non-zero, IPv4 IPsec tunnel encapsulation/decapsulation behavior will
235be friendly to ECN
236.Pq explicit congestion notification ,
237as documented in
238.Li draft-ietf-ipsec-ecn-02.txt .
239.Xr gif 4
240talks more about the behavior.
241.It Li ipsec.debug
242If set to non-zero, debug messages will be generated via
243.Xr syslog 3 .
244.El
245.Pp
246Variables under
247.Li net.inet6.ipsec6
248tree has similar meaning as the
249.Li net.inet.ipsec
250counterpart.
251.\"
252.Sh PROTOCOLS
253The
254.Nm
255protocol works like plug-in to
256.Xr inet 4
257and
258.Xr inet6 4
259protocols.
260Therefore,
261.Nm
262supports most of the protocols defined upon those IP-layer protocols.
263Some of the protocols, like
264.Xr icmp 4
265or
266.Xr icmp6 4 ,
267may behave differently with
268.Nm ipsec .
269This is because
270.Nm
271can prevent
272.Xr icmp 4
273or
274.Xr icmp6 4
275routines from looking into IP payload.
276.\"
277.Sh SEE ALSO
278.Xr ioctl 2 ,
279.Xr socket 2 ,
280.Xr ipsec_set_policy 3 ,
281.Xr fast_ipsec 4 ,
282.Xr icmp6 4 ,
283.Xr intro 4 ,
284.Xr ip6 4 ,
285.Xr kame_ipsec 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
299The IPsec 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