ipsec_info.h revision 3448:aaf16568054b
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef	_INET_IPSEC_INFO_H
27#define	_INET_IPSEC_INFO_H
28
29#pragma ident	"%Z%%M%	%I%	%E% SMI"
30
31#ifdef	__cplusplus
32extern "C" {
33#endif
34
35#include <sys/crypto/common.h>
36
37/*
38 * IPsec informational messages.  These are M_CTL STREAMS messages, which
39 * convey IPsec information between various IP and related modules.  The
40 * messages come in a few flavors:
41 *
42 *	* IPSEC_{IN,OUT}  -  These show what IPsec action have been taken (for
43 *	  inbound datagrams), or need to be taken (for outbound datagrams).
44 *	  They flow between AH/ESP and IP.
45 *
46 *	* Keysock consumer interface  -  These messages are wrappers for
47 *	  PF_KEY messages.  They flow between AH/ESP and keysock.
48 *
49 * Some of these messages include pointers such as a netstack_t pointer.
50 * We do not explicitly reference count those with netstack_hold/rele,
51 * since we depend on IP's ability to discard all of the IPSEC_{IN,OUT}
52 * messages in order to handle the ipsa pointers.
53 * We have special logic when doing asynch callouts to kEF for which we
54 * verify netstack_t pointer using the netstackid_t.
55 */
56
57/*
58 * The IPsec M_CTL value MUST be something that will not be even close
59 * to an IPv4 or IPv6 header.  This means the first byte must not be
60 * 0x40 - 0x4f or 0x60-0x6f.  For big-endian machines, this is fixable with
61 * the IPSEC_M_CTL prefix.  For little-endian machines, the actual M_CTL
62 * _type_ must not be in the aforementioned ranges.
63 *
64 * The reason for this avoidance is because M_CTL's with a real IPv4/IPv6
65 * datagram get sent from to TCP or UDP when an ICMP datagram affects a
66 * TCP/UDP session.
67 */
68#define	IPSEC_M_CTL	0x73706900
69
70/*
71 * M_CTL types for IPsec messages.  Remember, the values 0x40 - 0x4f and 0x60
72 * - 0x6f are not to be used because of potential little-endian confusion.
73 *
74 * Offsets 1-25 (decimal) are in use, spread through this file.
75 * Check for duplicates through the whole file before adding.
76 */
77
78/*
79 * IPSEC_{IN,OUT} policy expressors.
80 */
81#define	IPSEC_IN	(IPSEC_M_CTL + 1)
82#define	IPSEC_OUT	(IPSEC_M_CTL + 2)
83
84/*
85 * This is used for communication between IP and IPSEC (AH/ESP)
86 * for Inbound datagrams. IPSEC_IN is allocated by IP before IPSEC
87 * processing begins. On return spi fields are initialized so that
88 * IP can locate the security associations later on for doing policy
89 * checks. For loopback case, IPSEC processing is not done. But the
90 * attributes of the security are reflected in <foo>_done fields below.
91 * The code in policy check infers that it is a loopback case and
92 * would not try to get the associations.
93 *
94 * The comment below (and for other netstack_t references) refers
95 * to the fact that we only do netstack_hold in particular cases,
96 * such as the references from open streams (ill_t and conn_t's
97 * pointers). Internally within IP we rely on IP's ability to cleanup e.g.
98 * ire_t's when an ill goes away.
99 */
100typedef struct ipsec_in_s {
101	uint32_t ipsec_in_type;
102	uint32_t ipsec_in_len;
103	frtn_t ipsec_in_frtn;		/* for esballoc() callback */
104	struct ipsa_s 	*ipsec_in_ah_sa;	/* SA for AH */
105	struct ipsa_s 	*ipsec_in_esp_sa;	/* SA for ESP */
106
107	struct ipsec_policy_head_s *ipsec_in_policy;
108	struct ipsec_action_s *ipsec_in_action; /* how we made it in.. */
109	unsigned int
110		ipsec_in_secure : 1,	/* Is the message attached secure ? */
111		ipsec_in_v4 : 1,	/* Is this an ipv4 packet ? */
112		ipsec_in_loopback : 1,	/* Is this a loopback request ? */
113		ipsec_in_dont_check : 1, /* Used by TCP to avoid policy check */
114
115		ipsec_in_decaps : 1,	/* Was this packet decapsulated from */
116					/* a matching inner packet? */
117		ipsec_in_attach_if : 1,	/* Don't load spread this packet */
118		ipsec_in_accelerated : 1, /* hardware accelerated packet */
119
120		ipsec_in_icmp_loopback : 1, /* Looped-back ICMP packet, */
121					    /* all should trust this. */
122		ipsec_in_pad_bits : 24;
123
124	int    ipsec_in_ill_index;	/* interface on which ipha_dst was */
125					/* configured when pkt was recv'd  */
126	int    ipsec_in_rill_index;	/* interface on which pkt was recv'd */
127	mblk_t *ipsec_in_da;		/* data attr. for accelerated pkts */
128
129	/*
130	 * For call to the kernel crypto framework. State needed during
131	 * the execution of a crypto request. Storing these here
132	 * allow us to avoid a separate allocation before calling the
133	 * crypto framework.
134	 */
135	size_t ipsec_in_skip_len;		/* len to skip for AH auth */
136	crypto_data_t ipsec_in_crypto_data;	/* single op crypto data */
137	crypto_dual_data_t ipsec_in_crypto_dual_data; /* for dual ops */
138	crypto_data_t ipsec_in_crypto_mac;	/* to store the MAC */
139
140	zoneid_t ipsec_in_zoneid;	/* target zone for the datagram */
141	netstack_t *ipsec_in_ns;	/* Does not have a netstack_hold */
142	netstackid_t ipsec_in_stackid;	/* Used while waing for kEF callback */
143} ipsec_in_t;
144
145#define	IPSECOUT_MAX_ADDRLEN 4	/* Max addr len. (in 32-bit words) */
146/*
147 * This is used for communication between IP and IPSEC (AH/ESP)
148 * for Outbound datagrams. IPSEC_OUT is allocated by IP before IPSEC
149 * processing begins. On return SA fields are initialized so that
150 * IP can locate the security associations later on for doing policy
151 * checks.  The policy and the actions associated with this packet are
152 * stored in the ipsec_out_policy and ipsec_out_act fields respectively.
153 * IPSEC_OUT is also used to carry non-ipsec information when conn is
154 * absent or the conn information is lost across the calls to ARP.
155 * example: message from ARP or from ICMP error routines.
156 */
157typedef struct ipsec_out_s {
158	uint32_t ipsec_out_type;
159	uint32_t ipsec_out_len;
160	frtn_t ipsec_out_frtn;		/* for esballoc() callback */
161	struct ipsec_policy_head_s *ipsec_out_polhead;
162	ipsec_latch_t		*ipsec_out_latch;
163	struct ipsec_policy_s 	*ipsec_out_policy; /* why are we here? */
164	struct ipsec_action_s	*ipsec_out_act;	/* what do we want? */
165	struct ipsa_s	*ipsec_out_ah_sa; /* AH SA used for the packet */
166	struct ipsa_s	*ipsec_out_esp_sa; /* ESP SA used for the packet */
167	/*
168	 * NOTE: "Source" and "Dest" are w.r.t. outbound datagrams.  Ports can
169	 *	 be zero, and the protocol number is needed to make the ports
170	 *	 significant.
171	 */
172	uint16_t ipsec_out_src_port;	/* Source port number of d-gram. */
173	uint16_t ipsec_out_dst_port;	/* Destination port number of d-gram. */
174	uint8_t  ipsec_out_icmp_type;	/* ICMP type of d-gram */
175	uint8_t  ipsec_out_icmp_code;	/* ICMP code of d-gram */
176
177	sa_family_t ipsec_out_inaf;	/* Inner address family */
178	uint32_t ipsec_out_insrc[IPSECOUT_MAX_ADDRLEN];	/* Inner src address */
179	uint32_t ipsec_out_indst[IPSECOUT_MAX_ADDRLEN];	/* Inner dest address */
180	uint8_t  ipsec_out_insrcpfx;	/* Inner source prefix */
181	uint8_t  ipsec_out_indstpfx;	/* Inner destination prefix */
182
183	uint_t ipsec_out_ill_index;	/* ill index used for multicast etc. */
184	uint8_t ipsec_out_proto;	/* IP protocol number for d-gram. */
185	unsigned int
186		ipsec_out_tunnel : 1,	/* Tunnel mode? */
187		ipsec_out_use_global_policy : 1, /* Inherit global policy ? */
188		ipsec_out_secure : 1,	/* Is this secure ? */
189		ipsec_out_proc_begin : 1, /* IPSEC processing begun */
190		/*
191		 * Following five values reflects the values stored
192		 * in conn.
193		 */
194		ipsec_out_multicast_loop : 1,
195		ipsec_out_dontroute : 1,
196		ipsec_out_reserved : 1,
197		ipsec_out_v4 : 1,
198
199		ipsec_out_attach_if : 1,
200		ipsec_out_unspec_src : 1,	/* IPv6 ip6i_t info */
201		ipsec_out_reachable : 1, 	/* NDP reachability info */
202		/*
203		 * Following bit is used by ip_mrtun_forward to convey
204		 * xmit_ill information along with ICMP error msg
205		 */
206		ipsec_out_xmit_if: 1,
207
208		ipsec_out_failed: 1,
209		ipsec_out_se_done: 1,
210		ipsec_out_esp_done: 1,
211		ipsec_out_ah_done: 1,
212
213		ipsec_out_need_policy: 1,
214
215		/*
216		 * To indicate that packet must be accelerated, i.e.
217		 * ICV or encryption performed, by Provider.
218		 */
219		ipsec_out_accelerated : 1,
220		/*
221		 * Used by IP to tell IPsec that the outbound ill for this
222		 * packet supports acceleration of the AH or ESP prototocol.
223		 * If set, ipsec_out_capab_ill_index contains the
224		 * index of the ill.
225		 */
226		ipsec_out_is_capab_ill : 1,
227		/*
228		 * Indicates ICMP message destined for self.  These
229		 * messages are to be trusted by all receivers.
230		 */
231		ipsec_out_icmp_loopback: 1,
232		ipsec_out_ip_nexthop : 1,	/* IP_NEXTHOP option is set */
233		ipsec_out_pad_bits : 11;
234	cred_t	*ipsec_out_cred;
235	uint32_t ipsec_out_capab_ill_index;
236
237	/*
238	 * For call to the kernel crypto framework. State needed during
239	 * the execution of a crypto request. Storing these here
240	 * allow us to avoid a separate allocation before calling the
241	 * crypto framework.
242	 */
243	size_t ipsec_out_skip_len;		/* len to skip for AH auth */
244	crypto_data_t ipsec_out_crypto_data;	/* single op crypto data */
245	crypto_dual_data_t ipsec_out_crypto_dual_data; /* for dual ops */
246	crypto_data_t ipsec_out_crypto_mac;	/* to store the MAC */
247
248	zoneid_t ipsec_out_zoneid;	/* source zone for the datagram */
249	in6_addr_t ipsec_out_nexthop_v6;	/* nexthop IP address */
250#define	ipsec_out_nexthop_addr V4_PART_OF_V6(ipsec_out_nexthop_v6)
251	netstack_t *ipsec_out_ns;	/* Does not have a netstack_hold */
252	netstackid_t ipsec_out_stackid;	/* Used while waing for kEF callback */
253} ipsec_out_t;
254
255/*
256 * This is used to mark the ipsec_out_t *req* fields
257 * when the operation is done without affecting the
258 * requests.
259 */
260#define	IPSEC_REQ_DONE		0x80000000
261/*
262 * Operation could not be performed by the AH/ESP
263 * module.
264 */
265#define	IPSEC_REQ_FAILED	0x40000000
266
267/*
268 * Keysock consumer interface.
269 *
270 * The driver/module keysock (which is a driver to PF_KEY sockets, but is
271 * a module to 'consumers' like AH and ESP) uses keysock consumer interface
272 * messages to pass on PF_KEY messages to consumers who process and act upon
273 * them.
274 */
275#define	KEYSOCK_IN		(IPSEC_M_CTL + 3)
276#define	KEYSOCK_OUT		(IPSEC_M_CTL + 4)
277#define	KEYSOCK_OUT_ERR		(IPSEC_M_CTL + 5)
278#define	KEYSOCK_HELLO		(IPSEC_M_CTL + 6)
279#define	KEYSOCK_HELLO_ACK	(IPSEC_M_CTL + 7)
280
281/*
282 * KEYSOCK_HELLO is sent by keysock to a consumer when it is pushed on top
283 * of one (i.e. opened as a module).
284 *
285 * NOTE: Keysock_hello is simply an ipsec_info_t
286 */
287
288/* TUN_HELLO is just like KEYSOCK_HELLO, except for tunnels to talk with IP. */
289#define	TUN_HELLO		KEYSOCK_HELLO
290
291/*
292 * KEYSOCK_HELLO_ACK is sent by a consumer to acknowledge a KEYSOCK_HELLO.
293 * It contains the PF_KEYv2 sa_type, so keysock can redirect PF_KEY messages
294 * to the right consumer.
295 */
296typedef struct keysock_hello_ack_s {
297	uint32_t ks_hello_type;
298	uint32_t ks_hello_len;
299	uint8_t ks_hello_satype;	/* PF_KEYv2 sa_type of ks client */
300} keysock_hello_ack_t;
301
302#define	KS_IN_ADDR_UNKNOWN 0
303#define	KS_IN_ADDR_NOTTHERE 1
304#define	KS_IN_ADDR_UNSPEC 2
305#define	KS_IN_ADDR_ME 3
306#define	KS_IN_ADDR_NOTME 4
307#define	KS_IN_ADDR_MBCAST 5
308#define	KS_IN_ADDR_DONTCARE 6
309
310/*
311 * KEYSOCK_IN is a PF_KEY message from a PF_KEY socket destined for a consumer.
312 */
313typedef struct keysock_in_s {
314	uint32_t ks_in_type;
315	uint32_t ks_in_len;
316	/*
317	 * NOTE:	These pointers MUST be into the M_DATA that follows
318	 *		this M_CTL message.  If they aren't, weirdness
319	 *		results.
320	 */
321	struct sadb_ext *ks_in_extv[SADB_EXT_MAX + 1];
322	int ks_in_srctype;	/* Source address type. */
323	int ks_in_dsttype;	/* Dest address type. */
324	minor_t ks_in_serial;	/* Serial # of sending socket. */
325} keysock_in_t;
326
327/*
328 * KEYSOCK_OUT is a PF_KEY message from a consumer destined for a PF_KEY
329 * socket.
330 */
331typedef struct keysock_out_s {
332	uint32_t ks_out_type;
333	uint32_t ks_out_len;
334	minor_t ks_out_serial;	/* Serial # of sending socket. */
335} keysock_out_t;
336
337/*
338 * KEYSOCK_OUT_ERR is sent to a consumer from keysock if for some reason
339 * keysock could not find a PF_KEY socket to deliver a consumer-originated
340 * message (e.g. SADB_ACQUIRE).
341 */
342typedef struct keysock_out_err_s {
343	uint32_t ks_err_type;
344	uint32_t ks_err_len;
345	minor_t ks_err_serial;
346	int ks_err_errno;
347	/*
348	 * Other, richer error information may end up going here eventually.
349	 */
350} keysock_out_err_t;
351
352/*
353 * M_CTL message type for sending inbound pkt information between IP & ULP.
354 * These are _not_ related to IPsec in any way, but are here so that there is
355 * one place where all these values are defined which makes it easier to track.
356 * The choice of this value has the same rationale as explained above.
357 */
358#define	IN_PKTINFO		(IPSEC_M_CTL + 24)
359
360
361/*
362 * IPSEC_CTL messages are used by IPsec to send control type requests
363 * to IP. Such a control message is currently used by IPsec to request
364 * that IP send the contents of an IPsec SA or the entire SADB to
365 * every IPsec hardware acceleration capable provider.
366 */
367
368#define	IPSEC_CTL		(IPSEC_M_CTL + 25)
369
370typedef struct ipsec_ctl_s {
371	uint32_t ipsec_ctl_type;
372	uint32_t ipsec_ctl_len;
373	uint_t ipsec_ctl_sa_type;
374	void *ipsec_ctl_sa;
375} ipsec_ctl_t;
376
377
378/*
379 * All IPsec informational messages are placed into the ipsec_info_t
380 * union, so that allocation can be done once, and IPsec informational
381 * messages can be recycled.
382 */
383typedef union ipsec_info_u {
384	struct {
385		uint32_t ipsec_allu_type;
386		uint32_t ipsec_allu_len;	/* In bytes */
387	} ipsec_allu;
388	ipsec_in_t ipsec_in;
389	ipsec_out_t ipsec_out;
390	keysock_hello_ack_t keysock_hello_ack;
391	keysock_in_t keysock_in;
392	keysock_out_t keysock_out;
393	keysock_out_err_t keysock_out_err;
394	ipsec_ctl_t ipsec_ctl;
395} ipsec_info_t;
396#define	ipsec_info_type ipsec_allu.ipsec_allu_type
397#define	ipsec_info_len ipsec_allu.ipsec_allu_len
398
399#ifdef	__cplusplus
400}
401#endif
402
403#endif	/* _INET_IPSEC_INFO_H */
404