]> git.saurik.com Git - apple/network_cmds.git/blame - racoon.tproj/policy.h
network_cmds-245.19.tar.gz
[apple/network_cmds.git] / racoon.tproj / policy.h
CommitLineData
ac2f15b3 1/* $KAME: policy.h,v 1.18 2001/10/02 04:10:17 sakane Exp $ */
7ba0088d
A
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 */
2b484d24
A
31#ifndef __POLICY_H__
32#define __POLICY_H__
33
7ba0088d
A
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 */
45struct 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};
53
54/* Security Policy Data Base */
55struct secpolicy {
56 TAILQ_ENTRY(secpolicy) chain;
57
58 struct policyindex spidx; /* selector */
59 u_int32_t id; /* It's unique number on the system. */
60
61 u_int policy; /* DISCARD, NONE or IPSEC, see keyv2.h */
62 struct ipsecrequest *req;
63 /* pointer to the ipsec request tree, */
64 /* if policy == IPSEC else this value == NULL.*/
65};
66
67/* Security Assocciation Index */
68/* NOTE: Ensure to be same address family */
69struct secasindex {
70 struct sockaddr_storage src; /* srouce address for SA */
71 struct sockaddr_storage dst; /* destination address for SA */
72 u_int16_t proto; /* IPPROTO_ESP or IPPROTO_AH */
73 u_int8_t mode; /* mode of protocol, see ipsec.h */
74 u_int32_t reqid; /* reqid id who owned this SA */
75 /* see IPSEC_MANUAL_REQID_MAX. */
76};
77
78/* Request for IPsec */
79struct ipsecrequest {
80 struct ipsecrequest *next;
81 /* pointer to next structure */
82 /* If NULL, it means the end of chain. */
83
84 struct secasindex saidx;/* hint for search proper SA */
85 /* if __ss_len == 0 then no address specified.*/
86 u_int level; /* IPsec level defined below. */
87
88 struct secpolicy *sp; /* back pointer to SP */
89};
90
91#define KEY_SETSECSPIDX(_dir, s, d, ps, pd, ulp, idx) \
92do { \
93 bzero((idx), sizeof(struct policyindex)); \
94 (idx)->dir = (_dir); \
95 (idx)->prefs = (ps); \
96 (idx)->prefd = (pd); \
97 (idx)->ul_proto = (ulp); \
98 memcpy(&(idx)->src, (s), ((struct sockaddr *)(s))->sa_len); \
99 memcpy(&(idx)->dst, (d), ((struct sockaddr *)(d))->sa_len); \
100} while (0)
101
102struct ph2handle;
103struct policyindex;
104extern struct secpolicy *getsp __P((struct policyindex *));
105extern struct secpolicy *getsp_r __P((struct policyindex *));
106struct secpolicy *getspbyspid __P((u_int32_t));
107extern int cmpspidxstrict __P((struct policyindex *, struct policyindex *));
108extern int cmpspidxwild __P((struct policyindex *, struct policyindex *));
109extern struct secpolicy *newsp __P((void));
110extern void delsp __P((struct secpolicy *));
111extern void delsp_bothdir __P((struct policyindex *));
112extern void inssp __P((struct secpolicy *));
113extern void remsp __P((struct secpolicy *));
114extern void flushsp __P((void));
115extern void initsp __P((void));
116extern struct ipsecrequest *newipsecreq __P((void));
117
118extern const char *spidx2str __P((const struct policyindex *));
2b484d24
A
119
120
121#endif /* __POLICY_H__ */
122