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