]> git.saurik.com Git - apple/ipsec.git/blob - ipsec-tools/racoon/policy.h
ipsec-146.3.tar.gz
[apple/ipsec.git] / ipsec-tools / racoon / policy.h
1 /* $Id: policy.h,v 1.5 2004/06/11 16:00:17 ludvigm Exp $ */
2
3 /*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #ifndef _POLICY_H
33 #define _POLICY_H
34
35 #include <sys/queue.h>
36
37 /* refs. ipsec.h */
38 /*
39 * Security Policy Index
40 * NOTE: Ensure to be same address family and upper layer protocol.
41 * NOTE: ul_proto, port number, uid, gid:
42 * ANY: reserved for waldcard.
43 * 0 to (~0 - 1): is one of the number of each value.
44 */
45 struct policyindex {
46 u_int8_t dir; /* direction of packet flow, see blow */
47 struct sockaddr_storage src; /* IP src address for SP */
48 struct sockaddr_storage dst; /* IP dst address for SP */
49 u_int8_t prefs; /* prefix length in bits for src */
50 u_int8_t prefd; /* prefix length in bits for dst */
51 u_int16_t ul_proto; /* upper layer Protocol */
52 u_int32_t priority; /* priority for the policy */
53 };
54
55 /* Security Policy Data Base */
56 struct secpolicy {
57 TAILQ_ENTRY(secpolicy) chain;
58
59 struct policyindex spidx; /* selector */
60 u_int32_t id; /* It's unique number on the system. */
61
62 u_int policy; /* DISCARD, NONE or IPSEC, see keyv2.h */
63 struct ipsecrequest *req;
64 /* pointer to the ipsec request tree, */
65 /* if policy == IPSEC else this value == NULL.*/
66 };
67
68 /* Security Assocciation Index */
69 /* NOTE: Ensure to be same address family */
70 struct secasindex {
71 struct sockaddr_storage src; /* srouce address for SA */
72 struct sockaddr_storage dst; /* destination address for SA */
73 u_int16_t proto; /* IPPROTO_ESP or IPPROTO_AH */
74 u_int8_t mode; /* mode of protocol, see ipsec.h */
75 u_int32_t reqid; /* reqid id who owned this SA */
76 /* see IPSEC_MANUAL_REQID_MAX. */
77 };
78
79 /* Request for IPsec */
80 struct ipsecrequest {
81 struct ipsecrequest *next;
82 /* pointer to next structure */
83 /* If NULL, it means the end of chain. */
84
85 struct secasindex saidx;/* hint for search proper SA */
86 /* if __ss_len == 0 then no address specified.*/
87 u_int level; /* IPsec level defined below. */
88
89 struct secpolicy *sp; /* back pointer to SP */
90 };
91
92 #ifdef HAVE_PFKEY_POLICY_PRIORITY
93 #define KEY_SETSECSPIDX(_dir, s, d, ps, pd, ulp, _priority, idx) \
94 do { \
95 bzero((idx), sizeof(struct policyindex)); \
96 (idx)->dir = (_dir); \
97 (idx)->prefs = (ps); \
98 (idx)->prefd = (pd); \
99 (idx)->ul_proto = (ulp); \
100 (idx)->priority = (_priority); \
101 memcpy(&(idx)->src, (s), sysdep_sa_len((struct sockaddr *)(s))); \
102 memcpy(&(idx)->dst, (d), sysdep_sa_len((struct sockaddr *)(d))); \
103 } while (0)
104 #else
105 #define KEY_SETSECSPIDX(_dir, s, d, ps, pd, ulp, idx) \
106 do { \
107 bzero((idx), sizeof(struct policyindex)); \
108 (idx)->dir = (_dir); \
109 (idx)->prefs = (ps); \
110 (idx)->prefd = (pd); \
111 (idx)->ul_proto = (ulp); \
112 memcpy(&(idx)->src, (s), sysdep_sa_len((struct sockaddr *)(s))); \
113 memcpy(&(idx)->dst, (d), sysdep_sa_len((struct sockaddr *)(d))); \
114 } while (0)
115 #endif
116
117 struct ph2handle;
118 struct policyindex;
119 extern struct secpolicy *getsp __P((struct policyindex *));
120 extern struct secpolicy *getsp_r __P((struct policyindex *, struct ph2handle *));
121 struct secpolicy *getspbyspid __P((u_int32_t));
122 extern int cmpspidxstrict __P((struct policyindex *, struct policyindex *));
123 extern int cmpspidxwild __P((struct policyindex *, struct policyindex *));
124 extern struct secpolicy *newsp __P((void));
125 extern void delsp __P((struct secpolicy *));
126 extern void delsp_bothdir __P((struct policyindex *));
127 extern void inssp __P((struct secpolicy *));
128 extern void remsp __P((struct secpolicy *));
129 extern void flushsp __P((void));
130 extern void initsp __P((void));
131 extern struct ipsecrequest *newipsecreq __P((void));
132 extern int policies_installed __P((void));
133
134 extern const char *spidx2str __P((const struct policyindex *));
135
136 #endif /* _POLICY_H */