xref: /onnv-gate/usr/src/uts/common/net/pfpolicy.h (revision 10824:c47254a96e5d)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
53055Sdanmcd  * Common Development and Distribution License (the "License").
63055Sdanmcd  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*10824SMark.Fenwick@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_NET_PFPOLICY_H
270Sstevel@tonic-gate #define	_NET_PFPOLICY_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * Definitions and structures for PF_POLICY version 1.
310Sstevel@tonic-gate  *
320Sstevel@tonic-gate  * This local protocol provides an interface allowing utilities to
330Sstevel@tonic-gate  * manage a system's IPsec System Policy Database; see RFC2401 for a
340Sstevel@tonic-gate  * conceptual overview of the SPD.
350Sstevel@tonic-gate  * The basic encoding is modelled on PF_KEY version 2; see pfkeyv2.h
360Sstevel@tonic-gate  * and RFC2367 for more information.
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate 
390Sstevel@tonic-gate #ifdef	__cplusplus
400Sstevel@tonic-gate extern "C" {
410Sstevel@tonic-gate #endif
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #define	PF_POLICY_V1		1
440Sstevel@tonic-gate #define	PF_POLICY_REVISION	200304L
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /*
470Sstevel@tonic-gate  * Base PF_POLICY message header.  Each request/response starts with
480Sstevel@tonic-gate  * one of these, followed by some number of extensions.  Each
490Sstevel@tonic-gate  * extension type appears at most once in a message.  spd_msg_len
500Sstevel@tonic-gate  * contains the total length of the message including header.
510Sstevel@tonic-gate  */
520Sstevel@tonic-gate typedef struct spd_msg
530Sstevel@tonic-gate {
540Sstevel@tonic-gate 	uint8_t spd_msg_version;	/* PF_POLICY_V1 */
550Sstevel@tonic-gate 	uint8_t spd_msg_type;		/* ADD, DELETE, QUERY, ... */
560Sstevel@tonic-gate 	uint8_t spd_msg_errno;		/* Unix errno space; mbz on request */
570Sstevel@tonic-gate 	uint8_t spd_msg_spdid;		/* which policy db instance */
580Sstevel@tonic-gate 	uint16_t spd_msg_len;		/* in 64-bit words */
590Sstevel@tonic-gate 	uint16_t spd_msg_diagnostic;	/* additional error reason */
600Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
610Sstevel@tonic-gate 	union {
620Sstevel@tonic-gate 		struct {
630Sstevel@tonic-gate 			uint32_t spd_msg_useq;		/* set by sender */
640Sstevel@tonic-gate 			uint32_t spd_msg_upid;		/* set by sender */
650Sstevel@tonic-gate 		} spd_msg_actual;
660Sstevel@tonic-gate 		uint64_t spd_msg_alignment;
670Sstevel@tonic-gate 	} spd_msg_u;
680Sstevel@tonic-gate #define	spd_msg_seq spd_msg_u.spd_msg_actual.spd_msg_useq
690Sstevel@tonic-gate #define	spd_msg_pid spd_msg_u.spd_msg_actual.spd_msg_upid
700Sstevel@tonic-gate } spd_msg_t;
710Sstevel@tonic-gate 
720Sstevel@tonic-gate /*
730Sstevel@tonic-gate  * Command numbers, found in spd_msg_type.
740Sstevel@tonic-gate  */
750Sstevel@tonic-gate #define	SPD_RESERVED				0
760Sstevel@tonic-gate #define	SPD_MIN					1
770Sstevel@tonic-gate #define	SPD_FLUSH				1
780Sstevel@tonic-gate #define	SPD_ADDRULE				2
790Sstevel@tonic-gate #define	SPD_DELETERULE				3
800Sstevel@tonic-gate #define	SPD_FLIP				4
810Sstevel@tonic-gate #define	SPD_LOOKUP				5
820Sstevel@tonic-gate #define	SPD_DUMP				6
830Sstevel@tonic-gate #define	SPD_CLONE				7
840Sstevel@tonic-gate #define	SPD_ALGLIST				8
850Sstevel@tonic-gate #define	SPD_DUMPALGS				9
860Sstevel@tonic-gate #define	SPD_UPDATEALGS				10
870Sstevel@tonic-gate #define	SPD_MAX					10
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * Well-known policy db instances, found in spd_msg_spdid
910Sstevel@tonic-gate  */
920Sstevel@tonic-gate #define	SPD_ACTIVE		0	/* The currently active instance */
930Sstevel@tonic-gate #define	SPD_STANDBY		1 	/* "on deck" standby SPD */
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate  * The spd_msg_t is followed by extensions, which start with the
970Sstevel@tonic-gate  * following header; each extension structure includes the length and
980Sstevel@tonic-gate  * type fields internally as an overlay to simplify parsing and
990Sstevel@tonic-gate  * construction.
1000Sstevel@tonic-gate  */
1010Sstevel@tonic-gate typedef struct spd_ext
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
1040Sstevel@tonic-gate 	union {
1050Sstevel@tonic-gate 		struct {
1060Sstevel@tonic-gate 			uint16_t spd_ext_ulen;		/* in 64-bit words */
1070Sstevel@tonic-gate 			uint16_t spd_ext_utype;		/* 0 is reserved */
1080Sstevel@tonic-gate 		} spd_ext_actual;
1090Sstevel@tonic-gate 		uint64_t spd_ext_alignment;
1100Sstevel@tonic-gate 	} spd_ext_u;
1110Sstevel@tonic-gate #define	spd_ext_len spd_ext_u.spd_ext_actual.spd_ext_ulen
1120Sstevel@tonic-gate #define	spd_ext_type spd_ext_u.spd_ext_actual.spd_ext_utype
1130Sstevel@tonic-gate } spd_ext_t;
1140Sstevel@tonic-gate 
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate  * Extension numbers, found in spd_ext_type.
1170Sstevel@tonic-gate  */
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate #define	SPD_EXT_LCLPORT				1
1200Sstevel@tonic-gate #define	SPD_EXT_REMPORT				2
1210Sstevel@tonic-gate #define	SPD_EXT_PROTO				3
1220Sstevel@tonic-gate #define	SPD_EXT_LCLADDR				4
1230Sstevel@tonic-gate #define	SPD_EXT_REMADDR				5
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate #define	SPD_EXT_ACTION				6
1260Sstevel@tonic-gate #define	SPD_EXT_RULE				7
1270Sstevel@tonic-gate #define	SPD_EXT_RULESET				8
1283055Sdanmcd #define	SPD_EXT_ICMP_TYPECODE  			9
1290Sstevel@tonic-gate 
1303055Sdanmcd #define	SPD_EXT_TUN_NAME			10
1313055Sdanmcd 
1323055Sdanmcd #define	SPD_EXT_MAX				10
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate /*
1350Sstevel@tonic-gate  * base policy rule (attributes which every rule has)
1360Sstevel@tonic-gate  *
1370Sstevel@tonic-gate  * spd_rule_index MBZ on a SPD_ADD, and is assigned by the kernel.
1380Sstevel@tonic-gate  * subsequent deletes can operate either by specifying selectors or by
1390Sstevel@tonic-gate  * specifying a non-zero rule index.
1400Sstevel@tonic-gate  */
1410Sstevel@tonic-gate struct spd_rule
1420Sstevel@tonic-gate {
1430Sstevel@tonic-gate 	uint16_t spd_rule_len;
1440Sstevel@tonic-gate 	uint16_t spd_rule_type;		/* SPD_EXT_RULE */
1450Sstevel@tonic-gate 	uint32_t spd_rule_priority;
1460Sstevel@tonic-gate 	uint32_t spd_rule_flags;	/* INBOUND, OUTBOUND, ... */
1470Sstevel@tonic-gate 	uint32_t spd_rule_unused;
1480Sstevel@tonic-gate 	uint64_t spd_rule_index;	/* unique rule identifier. */
1490Sstevel@tonic-gate };
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate /*
1520Sstevel@tonic-gate  * Flags for spd_rule.spd_rule_flags
1530Sstevel@tonic-gate  */
1540Sstevel@tonic-gate #define	SPD_RULE_FLAG_INBOUND		0x0001
1550Sstevel@tonic-gate #define	SPD_RULE_FLAG_OUTBOUND		0x0002
1563055Sdanmcd /* Only applies to tunnel policy heads. */
1573055Sdanmcd #define	SPD_RULE_FLAG_TUNNEL		0x0004
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate /*
1600Sstevel@tonic-gate  * Address selectors.   Different from PF_KEY because we want a
1610Sstevel@tonic-gate  * more precise format for wildcards on ports/protocol.
1620Sstevel@tonic-gate  */
1630Sstevel@tonic-gate typedef struct spd_address {
1640Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
1650Sstevel@tonic-gate 	union {
1660Sstevel@tonic-gate 		struct {
1670Sstevel@tonic-gate 			uint16_t spd_address_ulen;
1680Sstevel@tonic-gate 			uint16_t spd_address_uexttype;	/* SRC, DST */
1690Sstevel@tonic-gate 			uint8_t spd_address_uaf;	/* address family. */
1700Sstevel@tonic-gate 			uint8_t spd_address_uprefixlen;	/* Prefix len (bits). */
1710Sstevel@tonic-gate 			uint16_t spd_address_ureserved2; /* Padding */
1720Sstevel@tonic-gate 		} spd_address_actual;
1730Sstevel@tonic-gate 		uint64_t spd_address_alignment;
1740Sstevel@tonic-gate 	} spd_address_u;
1750Sstevel@tonic-gate 	/*
1760Sstevel@tonic-gate 	 * .. followed by 4 bytes of IPv4 or 16 bytes of IPv6 address,
1770Sstevel@tonic-gate 	 * padded up to next uint64_t
1780Sstevel@tonic-gate 	 */
1790Sstevel@tonic-gate #define	spd_address_len	\
1800Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_ulen
1810Sstevel@tonic-gate #define	spd_address_exttype \
1820Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_uexttype
1830Sstevel@tonic-gate #define	spd_address_af \
1840Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_uaf
1850Sstevel@tonic-gate #define	spd_address_prefixlen \
1860Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_uprefixlen
1870Sstevel@tonic-gate #define	spd_address_reserved2 \
1880Sstevel@tonic-gate 	spd_address_u.spd_address_actual.spd_address_ureserved2
1890Sstevel@tonic-gate } spd_address_t;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate /*
1920Sstevel@tonic-gate  * Protocol selector
1930Sstevel@tonic-gate  */
1940Sstevel@tonic-gate struct spd_proto
1950Sstevel@tonic-gate {
1960Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
1970Sstevel@tonic-gate 	union {
1980Sstevel@tonic-gate 		struct {
1990Sstevel@tonic-gate 			uint16_t spd_proto_ulen;
2000Sstevel@tonic-gate 			uint16_t spd_proto_uexttype;		/* PROTO */
2010Sstevel@tonic-gate 			uint8_t spd_proto_unumber;		/* IPPROTO_* */
2020Sstevel@tonic-gate 			uint8_t	spd_proto_ureserved1;		 /* pad */
2030Sstevel@tonic-gate 			uint16_t spd_proto_ureserved2;		 /* pad */
2040Sstevel@tonic-gate 		} spd_proto_actual;
2050Sstevel@tonic-gate 		uint64_t spd_proto_alignment;
2060Sstevel@tonic-gate 	} spd_proto_u;
2070Sstevel@tonic-gate #define	spd_proto_len spd_proto_u.spd_proto_actual.spd_proto_ulen
2080Sstevel@tonic-gate #define	spd_proto_exttype spd_proto_u.spd_proto_actual.spd_proto_uexttype
2090Sstevel@tonic-gate #define	spd_proto_number spd_proto_u.spd_proto_actual.spd_proto_unumber
2100Sstevel@tonic-gate #define	spd_proto_reserved1 spd_proto_u.spd_proto_actual.spd_proto_ureserved1
2110Sstevel@tonic-gate #define	spd_proto_reserved2 spd_proto_u.spd_proto_actual.spd_proto_ureserved2
2120Sstevel@tonic-gate };
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate  * Port selector.  We only support minport==maxport at present.
2160Sstevel@tonic-gate  */
2170Sstevel@tonic-gate struct spd_portrange
2180Sstevel@tonic-gate {
2190Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
2200Sstevel@tonic-gate 	union {
2210Sstevel@tonic-gate 		struct {
2220Sstevel@tonic-gate 			uint16_t spd_ports_ulen;
2230Sstevel@tonic-gate 			uint16_t spd_ports_uexttype;	/* LCLPORT, REMPORT */
2240Sstevel@tonic-gate 			uint16_t spd_ports_uminport;	/* min port */
2250Sstevel@tonic-gate 			uint16_t spd_ports_umaxport;	/* max port */
2260Sstevel@tonic-gate 		} spd_ports_actual;
2270Sstevel@tonic-gate 		uint64_t spd_ports_alignment;
2280Sstevel@tonic-gate 	} spd_ports_u;
2290Sstevel@tonic-gate #define	spd_ports_len spd_ports_u.spd_ports_actual.spd_ports_ulen
2300Sstevel@tonic-gate #define	spd_ports_exttype spd_ports_u.spd_ports_actual.spd_ports_uexttype
2310Sstevel@tonic-gate #define	spd_ports_minport spd_ports_u.spd_ports_actual.spd_ports_uminport
2320Sstevel@tonic-gate #define	spd_ports_maxport spd_ports_u.spd_ports_actual.spd_ports_umaxport
2330Sstevel@tonic-gate };
2340Sstevel@tonic-gate 
2350Sstevel@tonic-gate /*
2360Sstevel@tonic-gate  * ICMP type selector.
2370Sstevel@tonic-gate  */
2380Sstevel@tonic-gate struct spd_typecode
2390Sstevel@tonic-gate {
2400Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
2410Sstevel@tonic-gate 	union {
2420Sstevel@tonic-gate 		struct {
2430Sstevel@tonic-gate 			uint16_t spd_typecode_ulen;
2440Sstevel@tonic-gate 			uint16_t spd_typecode_uexttype;	/* ICMP_TYPECODE */
2450Sstevel@tonic-gate 			uint8_t  spd_typecode_utype;
2460Sstevel@tonic-gate 			uint8_t  spd_typecode_utype_end;
2470Sstevel@tonic-gate 			uint8_t  spd_typecode_ucode;
2480Sstevel@tonic-gate 			uint8_t  spd_typecode_ucode_end;
2490Sstevel@tonic-gate 		} spd_typecode_actual;
2500Sstevel@tonic-gate 		uint64_t spd_typecode_alignment;
2510Sstevel@tonic-gate 	} spd_typecode_u;
2520Sstevel@tonic-gate #define	spd_typecode_len	\
2530Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_ulen
2540Sstevel@tonic-gate #define	spd_typecode_exttype	\
2550Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_uexttype
2560Sstevel@tonic-gate #define	spd_typecode_type	\
2570Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_utype
2580Sstevel@tonic-gate #define	spd_typecode_type_end	\
2590Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_utype_end
2600Sstevel@tonic-gate #define	spd_typecode_code	\
2610Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_ucode
2620Sstevel@tonic-gate #define	spd_typecode_code_end	\
2630Sstevel@tonic-gate     spd_typecode_u.spd_typecode_actual.spd_typecode_ucode_end
2640Sstevel@tonic-gate };
2650Sstevel@tonic-gate 
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate /*
2680Sstevel@tonic-gate  * Actions, specifying what happens to packets which match selectors.
2690Sstevel@tonic-gate  * This extension is followed by some number of spd_attribute tag-value pairs
2700Sstevel@tonic-gate  * which encode one or more alternative policies; see below for
2710Sstevel@tonic-gate  * the encoding used.
2720Sstevel@tonic-gate  */
2730Sstevel@tonic-gate struct spd_ext_actions
2740Sstevel@tonic-gate {
2750Sstevel@tonic-gate 	/* Union is for guaranteeing 64-bit alignment. */
2760Sstevel@tonic-gate 	union {
2770Sstevel@tonic-gate 		struct {
2780Sstevel@tonic-gate 			uint16_t spd_actions_ulen;
2790Sstevel@tonic-gate 			uint16_t spd_actions_uexttype;	/* ACTION */
2800Sstevel@tonic-gate 			uint16_t spd_actions_ucount;	/* # of alternatives */
2810Sstevel@tonic-gate 			uint16_t spd_actions_ureserved;
2820Sstevel@tonic-gate 		} spd_actions_actual;
2830Sstevel@tonic-gate 		uint64_t spd_actions_alignment;
2840Sstevel@tonic-gate 	} spd_actions_u;
2850Sstevel@tonic-gate #define	spd_actions_len \
2860Sstevel@tonic-gate 	spd_actions_u.spd_actions_actual.spd_actions_ulen
2870Sstevel@tonic-gate #define	spd_actions_exttype \
2880Sstevel@tonic-gate 	spd_actions_u.spd_actions_actual.spd_actions_uexttype
2890Sstevel@tonic-gate #define	spd_actions_count \
2900Sstevel@tonic-gate 	spd_actions_u.spd_actions_actual.spd_actions_ucount
2910Sstevel@tonic-gate #define	spd_actions_reserved \
2920Sstevel@tonic-gate 	spd_actions_u.spd_actions_actual.spd_actions_ureserved
2930Sstevel@tonic-gate };
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate /*
2960Sstevel@tonic-gate  * Extensible encoding for requested SA attributes.
2970Sstevel@tonic-gate  * To allow additional attributes to be added, we use a simple-to-interpret
2980Sstevel@tonic-gate  * (tag, value) encoding to fill in attributes in a list of alternatives.
2990Sstevel@tonic-gate  *
3000Sstevel@tonic-gate  * We fill in alternatives one at a time, starting with most-preferred,
3010Sstevel@tonic-gate  * proceeding to least-preferred.
3020Sstevel@tonic-gate  *
3030Sstevel@tonic-gate  * Conceptually, we are filling in attributes of a "template", and
3040Sstevel@tonic-gate  * then copying that template value into the list of alternatives when
3050Sstevel@tonic-gate  * we see a SPD_ATTR_END or SPD_ATTR_NEXT.
3060Sstevel@tonic-gate  *
3070Sstevel@tonic-gate  * The template is not changed by SPD_ATTR_NEXT, so that attributes common to
3080Sstevel@tonic-gate  * all alternatives need only be mentioned once.
3090Sstevel@tonic-gate  *
3100Sstevel@tonic-gate  * spd_actions_count is the maximum number of alternatives present; it
3110Sstevel@tonic-gate  * should be one greater than the number of SPD_ATTR_NEXT opcodes
3120Sstevel@tonic-gate  * present in the sequence.
3130Sstevel@tonic-gate  */
3140Sstevel@tonic-gate 
3150Sstevel@tonic-gate struct spd_attribute
3160Sstevel@tonic-gate {
3170Sstevel@tonic-gate 	union {
3180Sstevel@tonic-gate 		struct {
3190Sstevel@tonic-gate 			uint32_t	spd_attr_utag;
3200Sstevel@tonic-gate 			uint32_t	spd_attr_uvalue;
3210Sstevel@tonic-gate 		} spd_attribute_actual;
3220Sstevel@tonic-gate 		uint64_t spd_attribute_alignment;
3230Sstevel@tonic-gate 	} spd_attribute_u;
3240Sstevel@tonic-gate #define	spd_attr_tag spd_attribute_u.spd_attribute_actual.spd_attr_utag
3250Sstevel@tonic-gate #define	spd_attr_value spd_attribute_u.spd_attribute_actual.spd_attr_uvalue
3260Sstevel@tonic-gate };
3270Sstevel@tonic-gate 
328*10824SMark.Fenwick@Sun.COM /*
329*10824SMark.Fenwick@Sun.COM  * These flags are used by the kernel algorithm structures and by ipsecalgs(1m).
330*10824SMark.Fenwick@Sun.COM  * ALG_FLAG_KERNELCHECKED is used by ipsecalgs(1m) to tag ipsecalgent_t as
331*10824SMark.Fenwick@Sun.COM  * kernel verified. ALG_FLAG_VALID is only meaningful if set by the kernel.
332*10824SMark.Fenwick@Sun.COM  */
333*10824SMark.Fenwick@Sun.COM #define	ALG_FLAG_VALID		0x01
334*10824SMark.Fenwick@Sun.COM #define	ALG_FLAG_COUNTERMODE	0x02
335*10824SMark.Fenwick@Sun.COM #define	ALG_FLAG_COMBINED	0x04
336*10824SMark.Fenwick@Sun.COM #define	ALG_FLAG_CCM		0x08
337*10824SMark.Fenwick@Sun.COM #define	ALG_FLAG_GCM		0x10
338*10824SMark.Fenwick@Sun.COM #define	ALG_FLAG_KERNELCHECKED	0x80000000
339*10824SMark.Fenwick@Sun.COM 
3400Sstevel@tonic-gate #define	SPD_ATTR_NOP	0x00000000	/* space filler */
3410Sstevel@tonic-gate #define	SPD_ATTR_END	0x00000001	/* end of description */
3420Sstevel@tonic-gate #define	SPD_ATTR_EMPTY	0x00000002	/* reset template to default */
3430Sstevel@tonic-gate #define	SPD_ATTR_NEXT	0x00000003	/* start filling next alternative */
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate #define	SPD_ATTR_TYPE			0x00000100
3460Sstevel@tonic-gate #define	SPD_ATTR_FLAGS			0x00000101
3470Sstevel@tonic-gate #define	SPD_ATTR_AH_AUTH		0x00000102
3480Sstevel@tonic-gate #define	SPD_ATTR_ESP_ENCR		0x00000103
3490Sstevel@tonic-gate #define	SPD_ATTR_ESP_AUTH		0x00000104
3500Sstevel@tonic-gate #define	SPD_ATTR_ENCR_MINBITS		0x00000105
3510Sstevel@tonic-gate #define	SPD_ATTR_ENCR_MAXBITS		0x00000106
3520Sstevel@tonic-gate #define	SPD_ATTR_AH_MINBITS		0x00000107
3530Sstevel@tonic-gate #define	SPD_ATTR_AH_MAXBITS		0x00000108
3540Sstevel@tonic-gate #define	SPD_ATTR_LIFE_SOFT_TIME		0x00000109
3550Sstevel@tonic-gate #define	SPD_ATTR_LIFE_HARD_TIME		0x0000010a
3560Sstevel@tonic-gate #define	SPD_ATTR_LIFE_SOFT_BYTES	0x0000010b
3570Sstevel@tonic-gate #define	SPD_ATTR_LIFE_HARD_BYTES	0x0000010c
3580Sstevel@tonic-gate #define	SPD_ATTR_KM_PROTO		0x0000010d
3590Sstevel@tonic-gate #define	SPD_ATTR_KM_COOKIE		0x0000010e
3600Sstevel@tonic-gate #define	SPD_ATTR_REPLAY_DEPTH		0x0000010f
3610Sstevel@tonic-gate #define	SPD_ATTR_ESPA_MINBITS		0x00000110
3620Sstevel@tonic-gate #define	SPD_ATTR_ESPA_MAXBITS		0x00000111
3630Sstevel@tonic-gate #define	SPD_ATTR_ENCR_DEFBITS		0x00000112
3640Sstevel@tonic-gate #define	SPD_ATTR_ENCR_INCRBITS		0x00000113
3650Sstevel@tonic-gate #define	SPD_ATTR_AH_DEFBITS		0x00000114
3660Sstevel@tonic-gate #define	SPD_ATTR_AH_INCRBITS		0x00000115
3670Sstevel@tonic-gate #define	SPD_ATTR_ESPA_DEFBITS		0x00000116
3680Sstevel@tonic-gate #define	SPD_ATTR_ESPA_INCRBITS		0x00000117
3690Sstevel@tonic-gate #define	SPD_ATTR_ALG_ID			0x00000118
3700Sstevel@tonic-gate #define	SPD_ATTR_ALG_PROTO		0x00000119
3710Sstevel@tonic-gate #define	SPD_ATTR_ALG_INCRBITS		0x0000011a
3720Sstevel@tonic-gate #define	SPD_ATTR_ALG_NKEYSIZES		0x0000011b
3730Sstevel@tonic-gate #define	SPD_ATTR_ALG_KEYSIZE		0x0000011c
3740Sstevel@tonic-gate #define	SPD_ATTR_ALG_NBLOCKSIZES	0x0000011d
3750Sstevel@tonic-gate #define	SPD_ATTR_ALG_BLOCKSIZE		0x0000011e
3760Sstevel@tonic-gate #define	SPD_ATTR_ALG_MECHNAME		0x0000011f
3770Sstevel@tonic-gate #define	SPD_ATTR_PROTO_ID		0x00000120
3780Sstevel@tonic-gate #define	SPD_ATTR_PROTO_EXEC_MODE	0x00000121
379*10824SMark.Fenwick@Sun.COM #define	SPD_ATTR_ALG_NPARAMS		0x00000122
380*10824SMark.Fenwick@Sun.COM #define	SPD_ATTR_ALG_PARAMS		0x00000123
381*10824SMark.Fenwick@Sun.COM #define	SPD_ATTR_ALG_FLAGS		0x00000124
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate /*
3843055Sdanmcd  * An interface extension identifies a network interface.
3853055Sdanmcd  * It is used for configuring Tunnel Mode policies on a tunnelling
3863055Sdanmcd  * interface for now.
3873055Sdanmcd  */
3883055Sdanmcd typedef struct spd_if_s {
3893055Sdanmcd 	union {
3903055Sdanmcd 		struct {
3913055Sdanmcd 			uint16_t spd_if_ulen;
3923055Sdanmcd 			uint16_t spd_if_uexttype;
3933055Sdanmcd 			union {
3943055Sdanmcd 				uint8_t spd_if_iuname[4];
3953055Sdanmcd 				uint32_t spd_if_iuindex;
3963055Sdanmcd 			} spd_if_iu;
3973055Sdanmcd 		} spd_if_actual;
3983055Sdanmcd 		uint64_t spd_if_alignment;
3993055Sdanmcd 	} spd_if_u;
4003055Sdanmcd #define	spd_if_len spd_if_u.spd_if_actual.spd_if_ulen
4013055Sdanmcd #define	spd_if_exttype spd_if_u.spd_if_actual.spd_if_uexttype
4023055Sdanmcd #define	spd_if_name spd_if_u.spd_if_actual.spd_if_iu.spd_if_iuname
4033055Sdanmcd #define	spd_if_index spd_if_u.spd_if_actual.spd_if_iu.spd_if_iuindex
4043055Sdanmcd } spd_if_t;
4053055Sdanmcd 
4063055Sdanmcd /*
4070Sstevel@tonic-gate  * Minimum, maximum key lengths in bits.
4080Sstevel@tonic-gate  */
4090Sstevel@tonic-gate #define	SPD_MIN_MINBITS		0x0000
4100Sstevel@tonic-gate #define	SPD_MAX_MAXBITS		0xffff
4110Sstevel@tonic-gate 
4120Sstevel@tonic-gate /*
4130Sstevel@tonic-gate  * IPsec action types (in SPD_ATTR_TYPE attribute)
4140Sstevel@tonic-gate  */
4150Sstevel@tonic-gate #define	SPD_ACTTYPE_DROP	0x0001
4160Sstevel@tonic-gate #define	SPD_ACTTYPE_PASS	0x0002
4170Sstevel@tonic-gate #define	SPD_ACTTYPE_IPSEC	0x0003
4180Sstevel@tonic-gate 
4190Sstevel@tonic-gate /*
4200Sstevel@tonic-gate  * Action flags (in SPD_ATTR_FLAGS attribute)
4210Sstevel@tonic-gate  */
4220Sstevel@tonic-gate #define	SPD_APPLY_AH		0x0001
4230Sstevel@tonic-gate #define	SPD_APPLY_ESP		0x0002
4240Sstevel@tonic-gate #define	SPD_APPLY_SE		0x0004  /* self-encapsulation */
4250Sstevel@tonic-gate #define	SPD_APPLY_COMP		0x0008	/* compression; NYI */
4260Sstevel@tonic-gate #define	SPD_APPLY_UNIQUE	0x0010	/* unique per-flow SA */
4270Sstevel@tonic-gate #define	SPD_APPLY_BYPASS	0x0020	/* bypass policy */
4280Sstevel@tonic-gate #define	SPD_APPLY_ESPA		0x0040 	/* ESP authentication */
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate /*
4310Sstevel@tonic-gate  * SW crypto execution modes.
4320Sstevel@tonic-gate  */
4330Sstevel@tonic-gate #define	SPD_ALG_EXEC_MODE_SYNC		1	/* synchronous */
4340Sstevel@tonic-gate #define	SPD_ALG_EXEC_MODE_ASYNC		2	/* asynchronous */
4350Sstevel@tonic-gate 
4360Sstevel@tonic-gate /*
4370Sstevel@tonic-gate  * SPD_DUMP protocol:
4380Sstevel@tonic-gate  *
4390Sstevel@tonic-gate  * We do not want to force an stack to have to read-lock the entire
4400Sstevel@tonic-gate  * SPD for the duration of the dump, but we want management apps to be
4410Sstevel@tonic-gate  * able to get a consistent snapshot of the SPD.
4420Sstevel@tonic-gate  *
4430Sstevel@tonic-gate  * Therefore, we make optimistic locking assumptions.
4440Sstevel@tonic-gate  *
4450Sstevel@tonic-gate  * The response to a SPD_DUMP request consists of multiple spd_msg
4460Sstevel@tonic-gate  * records, all with spd_msg_type == SPD_DUMP and spd_msg_{seq,pid}
4470Sstevel@tonic-gate  * matching the request.
4480Sstevel@tonic-gate  *
4490Sstevel@tonic-gate  * There is one header, then a sequence of policy rule records (one
4500Sstevel@tonic-gate  * rule per record), then a trailer.
4510Sstevel@tonic-gate  *
4520Sstevel@tonic-gate  * The header and trailer both contain a single SPD_EXT_RULESET
4530Sstevel@tonic-gate  * containing a version number and rule count.  The dump was "good" if
4540Sstevel@tonic-gate  * header version == trailer version, and the number of rules read by
4550Sstevel@tonic-gate  * the application matches the rule count in the trailer.  The rule
4560Sstevel@tonic-gate  * count in the header is unused and should be set to zero.
4570Sstevel@tonic-gate  *
4580Sstevel@tonic-gate  * In between, each rule record contains a set of extensions which, if
4590Sstevel@tonic-gate  * used in an SPD_ADD request, would recreate an equivalent rule.
4600Sstevel@tonic-gate  *
4610Sstevel@tonic-gate  * If rules were added to the SPD during the dump, the dump may be
4620Sstevel@tonic-gate  * truncated or otherwise incomplete; the management application
4630Sstevel@tonic-gate  * should re-try the dump in this case.
4640Sstevel@tonic-gate  */
4650Sstevel@tonic-gate 
4660Sstevel@tonic-gate /*
4670Sstevel@tonic-gate  * Ruleset extension, used at the start and end of a SPD_DUMP.
4680Sstevel@tonic-gate  */
4690Sstevel@tonic-gate typedef struct spd_ruleset_ext
4700Sstevel@tonic-gate {
4710Sstevel@tonic-gate 	uint16_t spd_ruleset_len;	/* 2 x 64 bits */
4720Sstevel@tonic-gate 	uint16_t spd_ruleset_type;	/* SPD_EXT_RULESET */
4730Sstevel@tonic-gate 	uint32_t spd_ruleset_count;	/* only valid in trailer */
4740Sstevel@tonic-gate 	uint64_t spd_ruleset_version;	/* version number */
4750Sstevel@tonic-gate } spd_ruleset_ext_t;
4760Sstevel@tonic-gate 
4770Sstevel@tonic-gate /*
4780Sstevel@tonic-gate  * Diagnostic codes.  These supplement error messages.  Be sure to
4790Sstevel@tonic-gate  * update libipsecutil's spdsock_diag() if you change any of these.
4800Sstevel@tonic-gate  */
4810Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_NONE			0
4820Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNKNOWN_EXT		1
4830Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_BAD_EXTLEN		2
4840Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_NO_RULE_EXT		3
4850Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_BAD_ADDR_LEN		4
4860Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MIXED_AF			5
4870Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_NO_MEM		6
4880Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_WRONG_ACT_COUNT	7
4890Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_BAD_TYPE		8
4900Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_BAD_FLAGS		9
4910Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ADD_INCON_FLAGS		10
4920Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_LCLPORT 	11
4930Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_LCLPORT	12
4940Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_REMPORT	13
4950Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_REMPORT	14
4960Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_PROTO		15
4970Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_PROTO		16
4980Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_LCLADDR	17
4990Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_LCLADDR	18
5000Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_REMADDR	19
5010Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_REMADDR	20
5020Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_ACTION		21
5030Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_ACTION		22
5040Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_RULE		23
5050Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_RULE		24
5060Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_RULESET	25
5070Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_RULESET	26
5080Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_INVALID_RULE_INDEX	27
5090Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_BAD_SPDID		28
5100Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_BAD_MSG_TYPE		29
5110Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_AH_ALG		30
5120Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_ESP_ENCR_ALG	31
5130Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_ESP_AUTH_ALG	32
5140Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_AH_KEYSIZE	33
5150Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_ESP_ENCR_KEYSIZE	34
5160Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_UNSUPP_ESP_AUTH_KEYSIZE	35
5170Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_NO_ACTION_EXT		36
5180Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_ID_RANGE		37
5190Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_NUM_KEY_SIZES	38
5200Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_NUM_BLOCK_SIZES	39
5210Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_MECH_NAME_LEN	40
5220Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_ALG_IPSEC_NOT_LOADED	41
5230Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_MALFORMED_ICMP_TYPECODE	42
5240Sstevel@tonic-gate #define	SPD_DIAGNOSTIC_DUPLICATE_ICMP_TYPECODE	43
5253055Sdanmcd #define	SPD_DIAGNOSTIC_NOT_GLOBAL_OP		44
5263055Sdanmcd #define	SPD_DIAGNOSTIC_NO_TUNNEL_SELECTORS	45
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate /*
5290Sstevel@tonic-gate  * Helper macros.
5300Sstevel@tonic-gate  */
5310Sstevel@tonic-gate #define	SPD_64TO8(x)	((x) << 3)
5320Sstevel@tonic-gate #define	SPD_8TO64(x)	((x) >> 3)
5330Sstevel@tonic-gate #define	SPD_8TO1(x)	((x) << 3)
5340Sstevel@tonic-gate #define	SPD_1TO8(x)	((x) >> 3)
5350Sstevel@tonic-gate 
5360Sstevel@tonic-gate #ifdef	__cplusplus
5370Sstevel@tonic-gate }
5380Sstevel@tonic-gate #endif
5390Sstevel@tonic-gate 
5400Sstevel@tonic-gate #endif	/* _NET_PFPOLICY_H */
541