xref: /titanic_52/usr/src/uts/common/net/pfpolicy.h (revision 8810c16b934a2ad4f27aa86f95b0e8cec1c6ea46)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*8810c16bSdanmcd  * Common Development and Distribution License (the "License").
6*8810c16bSdanmcd  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*8810c16bSdanmcd  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_NET_PFPOLICY_H
277c478bd9Sstevel@tonic-gate #define	_NET_PFPOLICY_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate /*
327c478bd9Sstevel@tonic-gate  * Definitions and structures for PF_POLICY version 1.
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * This local protocol provides an interface allowing utilities to
357c478bd9Sstevel@tonic-gate  * manage a system's IPsec System Policy Database; see RFC2401 for a
367c478bd9Sstevel@tonic-gate  * conceptual overview of the SPD.
377c478bd9Sstevel@tonic-gate  * The basic encoding is modelled on PF_KEY version 2; see pfkeyv2.h
387c478bd9Sstevel@tonic-gate  * and RFC2367 for more information.
397c478bd9Sstevel@tonic-gate  */
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
427c478bd9Sstevel@tonic-gate extern "C" {
437c478bd9Sstevel@tonic-gate #endif
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	PF_POLICY_V1		1
467c478bd9Sstevel@tonic-gate #define	PF_POLICY_REVISION	200304L
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Base PF_POLICY message header.  Each request/response starts with
507c478bd9Sstevel@tonic-gate  * one of these, followed by some number of extensions.  Each
517c478bd9Sstevel@tonic-gate  * extension type appears at most once in a message.  spd_msg_len
527c478bd9Sstevel@tonic-gate  * contains the total length of the message including header.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate typedef struct spd_msg
557c478bd9Sstevel@tonic-gate {
567c478bd9Sstevel@tonic-gate 	uint8_t spd_msg_version;	/* PF_POLICY_V1 */
577c478bd9Sstevel@tonic-gate 	uint8_t spd_msg_type;		/* ADD, DELETE, QUERY, ... */
587c478bd9Sstevel@tonic-gate 	uint8_t spd_msg_errno;		/* Unix errno space; mbz on request */
597c478bd9Sstevel@tonic-gate 	uint8_t spd_msg_spdid;		/* which policy db instance */
607c478bd9Sstevel@tonic-gate 	uint16_t spd_msg_len;		/* in 64-bit words */
617c478bd9Sstevel@tonic-gate 	uint16_t spd_msg_diagnostic;	/* additional error reason */
627c478bd9Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
637c478bd9Sstevel@tonic-gate 	union {
647c478bd9Sstevel@tonic-gate 		struct {
657c478bd9Sstevel@tonic-gate 			uint32_t spd_msg_useq;		/* set by sender */
667c478bd9Sstevel@tonic-gate 			uint32_t spd_msg_upid;		/* set by sender */
677c478bd9Sstevel@tonic-gate 		} spd_msg_actual;
687c478bd9Sstevel@tonic-gate 		uint64_t spd_msg_alignment;
697c478bd9Sstevel@tonic-gate 	} spd_msg_u;
707c478bd9Sstevel@tonic-gate #define	spd_msg_seq spd_msg_u.spd_msg_actual.spd_msg_useq
717c478bd9Sstevel@tonic-gate #define	spd_msg_pid spd_msg_u.spd_msg_actual.spd_msg_upid
727c478bd9Sstevel@tonic-gate } spd_msg_t;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * Command numbers, found in spd_msg_type.
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate #define	SPD_RESERVED				0
787c478bd9Sstevel@tonic-gate #define	SPD_MIN					1
797c478bd9Sstevel@tonic-gate #define	SPD_FLUSH				1
807c478bd9Sstevel@tonic-gate #define	SPD_ADDRULE				2
817c478bd9Sstevel@tonic-gate #define	SPD_DELETERULE				3
827c478bd9Sstevel@tonic-gate #define	SPD_FLIP				4
837c478bd9Sstevel@tonic-gate #define	SPD_LOOKUP				5
847c478bd9Sstevel@tonic-gate #define	SPD_DUMP				6
857c478bd9Sstevel@tonic-gate #define	SPD_CLONE				7
867c478bd9Sstevel@tonic-gate #define	SPD_ALGLIST				8
877c478bd9Sstevel@tonic-gate #define	SPD_DUMPALGS				9
887c478bd9Sstevel@tonic-gate #define	SPD_UPDATEALGS				10
897c478bd9Sstevel@tonic-gate #define	SPD_MAX					10
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate /*
927c478bd9Sstevel@tonic-gate  * Well-known policy db instances, found in spd_msg_spdid
937c478bd9Sstevel@tonic-gate  */
947c478bd9Sstevel@tonic-gate #define	SPD_ACTIVE		0	/* The currently active instance */
957c478bd9Sstevel@tonic-gate #define	SPD_STANDBY		1 	/* "on deck" standby SPD */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate /*
987c478bd9Sstevel@tonic-gate  * The spd_msg_t is followed by extensions, which start with the
997c478bd9Sstevel@tonic-gate  * following header; each extension structure includes the length and
1007c478bd9Sstevel@tonic-gate  * type fields internally as an overlay to simplify parsing and
1017c478bd9Sstevel@tonic-gate  * construction.
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate typedef struct spd_ext
1047c478bd9Sstevel@tonic-gate {
1057c478bd9Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
1067c478bd9Sstevel@tonic-gate 	union {
1077c478bd9Sstevel@tonic-gate 		struct {
1087c478bd9Sstevel@tonic-gate 			uint16_t spd_ext_ulen;		/* in 64-bit words */
1097c478bd9Sstevel@tonic-gate 			uint16_t spd_ext_utype;		/* 0 is reserved */
1107c478bd9Sstevel@tonic-gate 		} spd_ext_actual;
1117c478bd9Sstevel@tonic-gate 		uint64_t spd_ext_alignment;
1127c478bd9Sstevel@tonic-gate 	} spd_ext_u;
1137c478bd9Sstevel@tonic-gate #define	spd_ext_len spd_ext_u.spd_ext_actual.spd_ext_ulen
1147c478bd9Sstevel@tonic-gate #define	spd_ext_type spd_ext_u.spd_ext_actual.spd_ext_utype
1157c478bd9Sstevel@tonic-gate } spd_ext_t;
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Extension numbers, found in spd_ext_type.
1197c478bd9Sstevel@tonic-gate  */
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate #define	SPD_EXT_LCLPORT				1
1227c478bd9Sstevel@tonic-gate #define	SPD_EXT_REMPORT				2
1237c478bd9Sstevel@tonic-gate #define	SPD_EXT_PROTO				3
1247c478bd9Sstevel@tonic-gate #define	SPD_EXT_LCLADDR				4
1257c478bd9Sstevel@tonic-gate #define	SPD_EXT_REMADDR				5
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate #define	SPD_EXT_ACTION				6
1287c478bd9Sstevel@tonic-gate #define	SPD_EXT_RULE				7
1297c478bd9Sstevel@tonic-gate #define	SPD_EXT_RULESET				8
1307c478bd9Sstevel@tonic-gate #define	SPD_EXT_ICMP_TYPECODE  			9
1317c478bd9Sstevel@tonic-gate 
132*8810c16bSdanmcd #define	SPD_EXT_TUN_NAME			10
133*8810c16bSdanmcd 
134*8810c16bSdanmcd #define	SPD_EXT_MAX				10
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate /*
1377c478bd9Sstevel@tonic-gate  * base policy rule (attributes which every rule has)
1387c478bd9Sstevel@tonic-gate  *
1397c478bd9Sstevel@tonic-gate  * spd_rule_index MBZ on a SPD_ADD, and is assigned by the kernel.
1407c478bd9Sstevel@tonic-gate  * subsequent deletes can operate either by specifying selectors or by
1417c478bd9Sstevel@tonic-gate  * specifying a non-zero rule index.
1427c478bd9Sstevel@tonic-gate  */
1437c478bd9Sstevel@tonic-gate struct spd_rule
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate 	uint16_t spd_rule_len;
1467c478bd9Sstevel@tonic-gate 	uint16_t spd_rule_type;		/* SPD_EXT_RULE */
1477c478bd9Sstevel@tonic-gate 	uint32_t spd_rule_priority;
1487c478bd9Sstevel@tonic-gate 	uint32_t spd_rule_flags;	/* INBOUND, OUTBOUND, ... */
1497c478bd9Sstevel@tonic-gate 	uint32_t spd_rule_unused;
1507c478bd9Sstevel@tonic-gate 	uint64_t spd_rule_index;	/* unique rule identifier. */
1517c478bd9Sstevel@tonic-gate };
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate /*
1547c478bd9Sstevel@tonic-gate  * Flags for spd_rule.spd_rule_flags
1557c478bd9Sstevel@tonic-gate  */
1567c478bd9Sstevel@tonic-gate #define	SPD_RULE_FLAG_INBOUND		0x0001
1577c478bd9Sstevel@tonic-gate #define	SPD_RULE_FLAG_OUTBOUND		0x0002
158*8810c16bSdanmcd /* Only applies to tunnel policy heads. */
159*8810c16bSdanmcd #define	SPD_RULE_FLAG_TUNNEL		0x0004
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate /*
1627c478bd9Sstevel@tonic-gate  * Address selectors.   Different from PF_KEY because we want a
1637c478bd9Sstevel@tonic-gate  * more precise format for wildcards on ports/protocol.
1647c478bd9Sstevel@tonic-gate  */
1657c478bd9Sstevel@tonic-gate typedef struct spd_address {
1667c478bd9Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
1677c478bd9Sstevel@tonic-gate 	union {
1687c478bd9Sstevel@tonic-gate 		struct {
1697c478bd9Sstevel@tonic-gate 			uint16_t spd_address_ulen;
1707c478bd9Sstevel@tonic-gate 			uint16_t spd_address_uexttype;	/* SRC, DST */
1717c478bd9Sstevel@tonic-gate 			uint8_t spd_address_uaf;	/* address family. */
1727c478bd9Sstevel@tonic-gate 			uint8_t spd_address_uprefixlen;	/* Prefix len (bits). */
1737c478bd9Sstevel@tonic-gate 			uint16_t spd_address_ureserved2; /* Padding */
1747c478bd9Sstevel@tonic-gate 		} spd_address_actual;
1757c478bd9Sstevel@tonic-gate 		uint64_t spd_address_alignment;
1767c478bd9Sstevel@tonic-gate 	} spd_address_u;
1777c478bd9Sstevel@tonic-gate 	/*
1787c478bd9Sstevel@tonic-gate 	 * .. followed by 4 bytes of IPv4 or 16 bytes of IPv6 address,
1797c478bd9Sstevel@tonic-gate 	 * padded up to next uint64_t
1807c478bd9Sstevel@tonic-gate 	 */
1817c478bd9Sstevel@tonic-gate #define	spd_address_len	\
1827c478bd9Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_ulen
1837c478bd9Sstevel@tonic-gate #define	spd_address_exttype \
1847c478bd9Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_uexttype
1857c478bd9Sstevel@tonic-gate #define	spd_address_af \
1867c478bd9Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_uaf
1877c478bd9Sstevel@tonic-gate #define	spd_address_prefixlen \
1887c478bd9Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_uprefixlen
1897c478bd9Sstevel@tonic-gate #define	spd_address_reserved2 \
1907c478bd9Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_ureserved2
1917c478bd9Sstevel@tonic-gate } spd_address_t;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate /*
1947c478bd9Sstevel@tonic-gate  * Protocol selector
1957c478bd9Sstevel@tonic-gate  */
1967c478bd9Sstevel@tonic-gate struct spd_proto
1977c478bd9Sstevel@tonic-gate {
1987c478bd9Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
1997c478bd9Sstevel@tonic-gate 	union {
2007c478bd9Sstevel@tonic-gate 		struct {
2017c478bd9Sstevel@tonic-gate 			uint16_t spd_proto_ulen;
2027c478bd9Sstevel@tonic-gate 			uint16_t spd_proto_uexttype;		/* PROTO */
2037c478bd9Sstevel@tonic-gate 			uint8_t spd_proto_unumber;		/* IPPROTO_* */
2047c478bd9Sstevel@tonic-gate 			uint8_t	spd_proto_ureserved1;		 /* pad */
2057c478bd9Sstevel@tonic-gate 			uint16_t spd_proto_ureserved2;		 /* pad */
2067c478bd9Sstevel@tonic-gate 		} spd_proto_actual;
2077c478bd9Sstevel@tonic-gate 		uint64_t spd_proto_alignment;
2087c478bd9Sstevel@tonic-gate 	} spd_proto_u;
2097c478bd9Sstevel@tonic-gate #define	spd_proto_len spd_proto_u.spd_proto_actual.spd_proto_ulen
2107c478bd9Sstevel@tonic-gate #define	spd_proto_exttype spd_proto_u.spd_proto_actual.spd_proto_uexttype
2117c478bd9Sstevel@tonic-gate #define	spd_proto_number spd_proto_u.spd_proto_actual.spd_proto_unumber
2127c478bd9Sstevel@tonic-gate #define	spd_proto_reserved1 spd_proto_u.spd_proto_actual.spd_proto_ureserved1
2137c478bd9Sstevel@tonic-gate #define	spd_proto_reserved2 spd_proto_u.spd_proto_actual.spd_proto_ureserved2
2147c478bd9Sstevel@tonic-gate };
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate /*
2177c478bd9Sstevel@tonic-gate  * Port selector.  We only support minport==maxport at present.
2187c478bd9Sstevel@tonic-gate  */
2197c478bd9Sstevel@tonic-gate struct spd_portrange
2207c478bd9Sstevel@tonic-gate {
2217c478bd9Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
2227c478bd9Sstevel@tonic-gate 	union {
2237c478bd9Sstevel@tonic-gate 		struct {
2247c478bd9Sstevel@tonic-gate 			uint16_t spd_ports_ulen;
2257c478bd9Sstevel@tonic-gate 			uint16_t spd_ports_uexttype;	/* LCLPORT, REMPORT */
2267c478bd9Sstevel@tonic-gate 			uint16_t spd_ports_uminport;	/* min port */
2277c478bd9Sstevel@tonic-gate 			uint16_t spd_ports_umaxport;	/* max port */
2287c478bd9Sstevel@tonic-gate 		} spd_ports_actual;
2297c478bd9Sstevel@tonic-gate 		uint64_t spd_ports_alignment;
2307c478bd9Sstevel@tonic-gate 	} spd_ports_u;
2317c478bd9Sstevel@tonic-gate #define	spd_ports_len spd_ports_u.spd_ports_actual.spd_ports_ulen
2327c478bd9Sstevel@tonic-gate #define	spd_ports_exttype spd_ports_u.spd_ports_actual.spd_ports_uexttype
2337c478bd9Sstevel@tonic-gate #define	spd_ports_minport spd_ports_u.spd_ports_actual.spd_ports_uminport
2347c478bd9Sstevel@tonic-gate #define	spd_ports_maxport spd_ports_u.spd_ports_actual.spd_ports_umaxport
2357c478bd9Sstevel@tonic-gate };
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate /*
2387c478bd9Sstevel@tonic-gate  * ICMP type selector.
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate struct spd_typecode
2417c478bd9Sstevel@tonic-gate {
2427c478bd9Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
2437c478bd9Sstevel@tonic-gate 	union {
2447c478bd9Sstevel@tonic-gate 		struct {
2457c478bd9Sstevel@tonic-gate 			uint16_t spd_typecode_ulen;
2467c478bd9Sstevel@tonic-gate 			uint16_t spd_typecode_uexttype;	/* ICMP_TYPECODE */
2477c478bd9Sstevel@tonic-gate 			uint8_t  spd_typecode_utype;
2487c478bd9Sstevel@tonic-gate 			uint8_t  spd_typecode_utype_end;
2497c478bd9Sstevel@tonic-gate 			uint8_t  spd_typecode_ucode;
2507c478bd9Sstevel@tonic-gate 			uint8_t  spd_typecode_ucode_end;
2517c478bd9Sstevel@tonic-gate 		} spd_typecode_actual;
2527c478bd9Sstevel@tonic-gate 		uint64_t spd_typecode_alignment;
2537c478bd9Sstevel@tonic-gate 	} spd_typecode_u;
2547c478bd9Sstevel@tonic-gate #define	spd_typecode_len	\
2557c478bd9Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_ulen
2567c478bd9Sstevel@tonic-gate #define	spd_typecode_exttype	\
2577c478bd9Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_uexttype
2587c478bd9Sstevel@tonic-gate #define	spd_typecode_type	\
2597c478bd9Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_utype
2607c478bd9Sstevel@tonic-gate #define	spd_typecode_type_end	\
2617c478bd9Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_utype_end
2627c478bd9Sstevel@tonic-gate #define	spd_typecode_code	\
2637c478bd9Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_ucode
2647c478bd9Sstevel@tonic-gate #define	spd_typecode_code_end	\
2657c478bd9Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_ucode_end
2667c478bd9Sstevel@tonic-gate };
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate /*
2707c478bd9Sstevel@tonic-gate  * Actions, specifying what happens to packets which match selectors.
2717c478bd9Sstevel@tonic-gate  * This extension is followed by some number of spd_attribute tag-value pairs
2727c478bd9Sstevel@tonic-gate  * which encode one or more alternative policies; see below for
2737c478bd9Sstevel@tonic-gate  * the encoding used.
2747c478bd9Sstevel@tonic-gate  */
2757c478bd9Sstevel@tonic-gate struct spd_ext_actions
2767c478bd9Sstevel@tonic-gate {
2777c478bd9Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
2787c478bd9Sstevel@tonic-gate 	union {
2797c478bd9Sstevel@tonic-gate 		struct {
2807c478bd9Sstevel@tonic-gate 			uint16_t spd_actions_ulen;
2817c478bd9Sstevel@tonic-gate 			uint16_t spd_actions_uexttype;	/* ACTION */
2827c478bd9Sstevel@tonic-gate 			uint16_t spd_actions_ucount;	/* # of alternatives */
2837c478bd9Sstevel@tonic-gate 			uint16_t spd_actions_ureserved;
2847c478bd9Sstevel@tonic-gate 		} spd_actions_actual;
2857c478bd9Sstevel@tonic-gate 		uint64_t spd_actions_alignment;
2867c478bd9Sstevel@tonic-gate 	} spd_actions_u;
2877c478bd9Sstevel@tonic-gate #define	spd_actions_len \
2887c478bd9Sstevel@tonic-gate 	spd_actions_u.spd_actions_actual.spd_actions_ulen
2897c478bd9Sstevel@tonic-gate #define	spd_actions_exttype \
2907c478bd9Sstevel@tonic-gate 	spd_actions_u.spd_actions_actual.spd_actions_uexttype
2917c478bd9Sstevel@tonic-gate #define	spd_actions_count \
2927c478bd9Sstevel@tonic-gate 	spd_actions_u.spd_actions_actual.spd_actions_ucount
2937c478bd9Sstevel@tonic-gate #define	spd_actions_reserved \
2947c478bd9Sstevel@tonic-gate 	spd_actions_u.spd_actions_actual.spd_actions_ureserved
2957c478bd9Sstevel@tonic-gate };
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate /*
2987c478bd9Sstevel@tonic-gate  * Extensible encoding for requested SA attributes.
2997c478bd9Sstevel@tonic-gate  * To allow additional attributes to be added, we use a simple-to-interpret
3007c478bd9Sstevel@tonic-gate  * (tag, value) encoding to fill in attributes in a list of alternatives.
3017c478bd9Sstevel@tonic-gate  *
3027c478bd9Sstevel@tonic-gate  * We fill in alternatives one at a time, starting with most-preferred,
3037c478bd9Sstevel@tonic-gate  * proceeding to least-preferred.
3047c478bd9Sstevel@tonic-gate  *
3057c478bd9Sstevel@tonic-gate  * Conceptually, we are filling in attributes of a "template", and
3067c478bd9Sstevel@tonic-gate  * then copying that template value into the list of alternatives when
3077c478bd9Sstevel@tonic-gate  * we see a SPD_ATTR_END or SPD_ATTR_NEXT.
3087c478bd9Sstevel@tonic-gate  *
3097c478bd9Sstevel@tonic-gate  * The template is not changed by SPD_ATTR_NEXT, so that attributes common to
3107c478bd9Sstevel@tonic-gate  * all alternatives need only be mentioned once.
3117c478bd9Sstevel@tonic-gate  *
3127c478bd9Sstevel@tonic-gate  * spd_actions_count is the maximum number of alternatives present; it
3137c478bd9Sstevel@tonic-gate  * should be one greater than the number of SPD_ATTR_NEXT opcodes
3147c478bd9Sstevel@tonic-gate  * present in the sequence.
3157c478bd9Sstevel@tonic-gate  */
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate struct spd_attribute
3187c478bd9Sstevel@tonic-gate {
3197c478bd9Sstevel@tonic-gate 	union {
3207c478bd9Sstevel@tonic-gate 		struct {
3217c478bd9Sstevel@tonic-gate 			uint32_t	spd_attr_utag;
3227c478bd9Sstevel@tonic-gate 			uint32_t	spd_attr_uvalue;
3237c478bd9Sstevel@tonic-gate 		} spd_attribute_actual;
3247c478bd9Sstevel@tonic-gate 		uint64_t spd_attribute_alignment;
3257c478bd9Sstevel@tonic-gate 	} spd_attribute_u;
3267c478bd9Sstevel@tonic-gate #define	spd_attr_tag spd_attribute_u.spd_attribute_actual.spd_attr_utag
3277c478bd9Sstevel@tonic-gate #define	spd_attr_value spd_attribute_u.spd_attribute_actual.spd_attr_uvalue
3287c478bd9Sstevel@tonic-gate };
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate #define	SPD_ATTR_NOP	0x00000000	/* space filler */
3317c478bd9Sstevel@tonic-gate #define	SPD_ATTR_END	0x00000001	/* end of description */
3327c478bd9Sstevel@tonic-gate #define	SPD_ATTR_EMPTY	0x00000002	/* reset template to default */
3337c478bd9Sstevel@tonic-gate #define	SPD_ATTR_NEXT	0x00000003	/* start filling next alternative */
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate #define	SPD_ATTR_TYPE			0x00000100
3367c478bd9Sstevel@tonic-gate #define	SPD_ATTR_FLAGS			0x00000101
3377c478bd9Sstevel@tonic-gate #define	SPD_ATTR_AH_AUTH		0x00000102
3387c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ESP_ENCR		0x00000103
3397c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ESP_AUTH		0x00000104
3407c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ENCR_MINBITS		0x00000105
3417c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ENCR_MAXBITS		0x00000106
3427c478bd9Sstevel@tonic-gate #define	SPD_ATTR_AH_MINBITS		0x00000107
3437c478bd9Sstevel@tonic-gate #define	SPD_ATTR_AH_MAXBITS		0x00000108
3447c478bd9Sstevel@tonic-gate #define	SPD_ATTR_LIFE_SOFT_TIME		0x00000109
3457c478bd9Sstevel@tonic-gate #define	SPD_ATTR_LIFE_HARD_TIME		0x0000010a
3467c478bd9Sstevel@tonic-gate #define	SPD_ATTR_LIFE_SOFT_BYTES	0x0000010b
3477c478bd9Sstevel@tonic-gate #define	SPD_ATTR_LIFE_HARD_BYTES	0x0000010c
3487c478bd9Sstevel@tonic-gate #define	SPD_ATTR_KM_PROTO		0x0000010d
3497c478bd9Sstevel@tonic-gate #define	SPD_ATTR_KM_COOKIE		0x0000010e
3507c478bd9Sstevel@tonic-gate #define	SPD_ATTR_REPLAY_DEPTH		0x0000010f
3517c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ESPA_MINBITS		0x00000110
3527c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ESPA_MAXBITS		0x00000111
3537c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ENCR_DEFBITS		0x00000112
3547c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ENCR_INCRBITS		0x00000113
3557c478bd9Sstevel@tonic-gate #define	SPD_ATTR_AH_DEFBITS		0x00000114
3567c478bd9Sstevel@tonic-gate #define	SPD_ATTR_AH_INCRBITS		0x00000115
3577c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ESPA_DEFBITS		0x00000116
3587c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ESPA_INCRBITS		0x00000117
3597c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ALG_ID			0x00000118
3607c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ALG_PROTO		0x00000119
3617c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ALG_INCRBITS		0x0000011a
3627c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ALG_NKEYSIZES		0x0000011b
3637c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ALG_KEYSIZE		0x0000011c
3647c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ALG_NBLOCKSIZES	0x0000011d
3657c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ALG_BLOCKSIZE		0x0000011e
3667c478bd9Sstevel@tonic-gate #define	SPD_ATTR_ALG_MECHNAME		0x0000011f
3677c478bd9Sstevel@tonic-gate #define	SPD_ATTR_PROTO_ID		0x00000120
3687c478bd9Sstevel@tonic-gate #define	SPD_ATTR_PROTO_EXEC_MODE	0x00000121
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate /*
371*8810c16bSdanmcd  * An interface extension identifies a network interface.
372*8810c16bSdanmcd  * It is used for configuring Tunnel Mode policies on a tunnelling
373*8810c16bSdanmcd  * interface for now.
374*8810c16bSdanmcd  */
375*8810c16bSdanmcd typedef struct spd_if_s {
376*8810c16bSdanmcd 	union {
377*8810c16bSdanmcd 		struct {
378*8810c16bSdanmcd 			uint16_t spd_if_ulen;
379*8810c16bSdanmcd 			uint16_t spd_if_uexttype;
380*8810c16bSdanmcd 			union {
381*8810c16bSdanmcd 				uint8_t spd_if_iuname[4];
382*8810c16bSdanmcd 				uint32_t spd_if_iuindex;
383*8810c16bSdanmcd 			} spd_if_iu;
384*8810c16bSdanmcd 		} spd_if_actual;
385*8810c16bSdanmcd 		uint64_t spd_if_alignment;
386*8810c16bSdanmcd 	} spd_if_u;
387*8810c16bSdanmcd #define	spd_if_len spd_if_u.spd_if_actual.spd_if_ulen
388*8810c16bSdanmcd #define	spd_if_exttype spd_if_u.spd_if_actual.spd_if_uexttype
389*8810c16bSdanmcd #define	spd_if_name spd_if_u.spd_if_actual.spd_if_iu.spd_if_iuname
390*8810c16bSdanmcd #define	spd_if_index spd_if_u.spd_if_actual.spd_if_iu.spd_if_iuindex
391*8810c16bSdanmcd } spd_if_t;
392*8810c16bSdanmcd 
393*8810c16bSdanmcd /*
3947c478bd9Sstevel@tonic-gate  * Minimum, maximum key lengths in bits.
3957c478bd9Sstevel@tonic-gate  */
3967c478bd9Sstevel@tonic-gate #define	SPD_MIN_MINBITS		0x0000
3977c478bd9Sstevel@tonic-gate #define	SPD_MAX_MAXBITS		0xffff
3987c478bd9Sstevel@tonic-gate 
3997c478bd9Sstevel@tonic-gate /*
4007c478bd9Sstevel@tonic-gate  * IPsec action types (in SPD_ATTR_TYPE attribute)
4017c478bd9Sstevel@tonic-gate  */
4027c478bd9Sstevel@tonic-gate #define	SPD_ACTTYPE_DROP	0x0001
4037c478bd9Sstevel@tonic-gate #define	SPD_ACTTYPE_PASS	0x0002
4047c478bd9Sstevel@tonic-gate #define	SPD_ACTTYPE_IPSEC	0x0003
4057c478bd9Sstevel@tonic-gate 
4067c478bd9Sstevel@tonic-gate /*
4077c478bd9Sstevel@tonic-gate  * Action flags (in SPD_ATTR_FLAGS attribute)
4087c478bd9Sstevel@tonic-gate  */
4097c478bd9Sstevel@tonic-gate #define	SPD_APPLY_AH		0x0001
4107c478bd9Sstevel@tonic-gate #define	SPD_APPLY_ESP		0x0002
4117c478bd9Sstevel@tonic-gate #define	SPD_APPLY_SE		0x0004  /* self-encapsulation */
4127c478bd9Sstevel@tonic-gate #define	SPD_APPLY_COMP		0x0008	/* compression; NYI */
4137c478bd9Sstevel@tonic-gate #define	SPD_APPLY_UNIQUE	0x0010	/* unique per-flow SA */
4147c478bd9Sstevel@tonic-gate #define	SPD_APPLY_BYPASS	0x0020	/* bypass policy */
4157c478bd9Sstevel@tonic-gate #define	SPD_APPLY_ESPA		0x0040 	/* ESP authentication */
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate /*
4187c478bd9Sstevel@tonic-gate  * SW crypto execution modes.
4197c478bd9Sstevel@tonic-gate  */
4207c478bd9Sstevel@tonic-gate #define	SPD_ALG_EXEC_MODE_SYNC		1	/* synchronous */
4217c478bd9Sstevel@tonic-gate #define	SPD_ALG_EXEC_MODE_ASYNC		2	/* asynchronous */
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate /*
4247c478bd9Sstevel@tonic-gate  * SPD_DUMP protocol:
4257c478bd9Sstevel@tonic-gate  *
4267c478bd9Sstevel@tonic-gate  * We do not want to force an stack to have to read-lock the entire
4277c478bd9Sstevel@tonic-gate  * SPD for the duration of the dump, but we want management apps to be
4287c478bd9Sstevel@tonic-gate  * able to get a consistent snapshot of the SPD.
4297c478bd9Sstevel@tonic-gate  *
4307c478bd9Sstevel@tonic-gate  * Therefore, we make optimistic locking assumptions.
4317c478bd9Sstevel@tonic-gate  *
4327c478bd9Sstevel@tonic-gate  * The response to a SPD_DUMP request consists of multiple spd_msg
4337c478bd9Sstevel@tonic-gate  * records, all with spd_msg_type == SPD_DUMP and spd_msg_{seq,pid}
4347c478bd9Sstevel@tonic-gate  * matching the request.
4357c478bd9Sstevel@tonic-gate  *
4367c478bd9Sstevel@tonic-gate  * There is one header, then a sequence of policy rule records (one
4377c478bd9Sstevel@tonic-gate  * rule per record), then a trailer.
4387c478bd9Sstevel@tonic-gate  *
4397c478bd9Sstevel@tonic-gate  * The header and trailer both contain a single SPD_EXT_RULESET
4407c478bd9Sstevel@tonic-gate  * containing a version number and rule count.  The dump was "good" if
4417c478bd9Sstevel@tonic-gate  * header version == trailer version, and the number of rules read by
4427c478bd9Sstevel@tonic-gate  * the application matches the rule count in the trailer.  The rule
4437c478bd9Sstevel@tonic-gate  * count in the header is unused and should be set to zero.
4447c478bd9Sstevel@tonic-gate  *
4457c478bd9Sstevel@tonic-gate  * In between, each rule record contains a set of extensions which, if
4467c478bd9Sstevel@tonic-gate  * used in an SPD_ADD request, would recreate an equivalent rule.
4477c478bd9Sstevel@tonic-gate  *
4487c478bd9Sstevel@tonic-gate  * If rules were added to the SPD during the dump, the dump may be
4497c478bd9Sstevel@tonic-gate  * truncated or otherwise incomplete; the management application
4507c478bd9Sstevel@tonic-gate  * should re-try the dump in this case.
4517c478bd9Sstevel@tonic-gate  */
4527c478bd9Sstevel@tonic-gate 
4537c478bd9Sstevel@tonic-gate /*
4547c478bd9Sstevel@tonic-gate  * Ruleset extension, used at the start and end of a SPD_DUMP.
4557c478bd9Sstevel@tonic-gate  */
4567c478bd9Sstevel@tonic-gate typedef struct spd_ruleset_ext
4577c478bd9Sstevel@tonic-gate {
4587c478bd9Sstevel@tonic-gate 	uint16_t spd_ruleset_len;	/* 2 x 64 bits */
4597c478bd9Sstevel@tonic-gate 	uint16_t spd_ruleset_type;	/* SPD_EXT_RULESET */
4607c478bd9Sstevel@tonic-gate 	uint32_t spd_ruleset_count;	/* only valid in trailer */
4617c478bd9Sstevel@tonic-gate 	uint64_t spd_ruleset_version;	/* version number */
4627c478bd9Sstevel@tonic-gate } spd_ruleset_ext_t;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate /*
4657c478bd9Sstevel@tonic-gate  * Diagnostic codes.  These supplement error messages.  Be sure to
4667c478bd9Sstevel@tonic-gate  * update libipsecutil's spdsock_diag() if you change any of these.
4677c478bd9Sstevel@tonic-gate  */
4687c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_NONE			0
4697c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNKNOWN_EXT		1
4707c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_BAD_EXTLEN		2
4717c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_NO_RULE_EXT		3
4727c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_BAD_ADDR_LEN		4
4737c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MIXED_AF			5
4747c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_NO_MEM		6
4757c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_WRONG_ACT_COUNT	7
4767c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_BAD_TYPE		8
4777c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_BAD_FLAGS		9
4787c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_INCON_FLAGS		10
4797c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_LCLPORT 	11
4807c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_LCLPORT	12
4817c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_REMPORT	13
4827c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_REMPORT	14
4837c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_PROTO		15
4847c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_PROTO		16
4857c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_LCLADDR	17
4867c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_LCLADDR	18
4877c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_REMADDR	19
4887c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_REMADDR	20
4897c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_ACTION		21
4907c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_ACTION		22
4917c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_RULE		23
4927c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_RULE		24
4937c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_RULESET	25
4947c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_RULESET	26
4957c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_INVALID_RULE_INDEX	27
4967c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_BAD_SPDID		28
4977c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_BAD_MSG_TYPE		29
4987c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_AH_ALG		30
4997c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_ESP_ENCR_ALG	31
5007c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_ESP_AUTH_ALG	32
5017c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_AH_KEYSIZE	33
5027c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_ESP_ENCR_KEYSIZE	34
5037c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_ESP_AUTH_KEYSIZE	35
5047c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_NO_ACTION_EXT		36
5057c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_ID_RANGE		37
5067c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_NUM_KEY_SIZES	38
5077c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_NUM_BLOCK_SIZES	39
5087c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_MECH_NAME_LEN	40
5097c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_IPSEC_NOT_LOADED	41
5107c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_ICMP_TYPECODE	42
5117c478bd9Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_ICMP_TYPECODE	43
512*8810c16bSdanmcd #define	SPD_DIAGNOSTIC_NOT_GLOBAL_OP		44
513*8810c16bSdanmcd #define	SPD_DIAGNOSTIC_NO_TUNNEL_SELECTORS	45
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate /*
5167c478bd9Sstevel@tonic-gate  * Helper macros.
5177c478bd9Sstevel@tonic-gate  */
5187c478bd9Sstevel@tonic-gate #define	SPD_64TO8(x)	((x) << 3)
5197c478bd9Sstevel@tonic-gate #define	SPD_8TO64(x)	((x) >> 3)
5207c478bd9Sstevel@tonic-gate #define	SPD_8TO1(x)	((x) << 3)
5217c478bd9Sstevel@tonic-gate #define	SPD_1TO8(x)	((x) >> 3)
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate #endif
5267c478bd9Sstevel@tonic-gate 
5277c478bd9Sstevel@tonic-gate #endif	/* _NET_PFPOLICY_H */
528