Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / ipsec-tools / src / libipsec / libpfkey.h
1 /* $Id: libpfkey.h,v 1.7 2004/06/07 09:18:46 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 _LIBPFKEY_H
33 #define _LIBPFKEY_H
34
35 #ifndef KAME_LIBPFKEY_H
36 #define KAME_LIBPFKEY_H
37
38 #define PRIORITY_LOW        0xC0000000
39 #define PRIORITY_DEFAULT    0x80000000
40 #define PRIORITY_HIGH       0x40000000
41
42 #define PRIORITY_OFFSET_POSITIVE_MAX    0x3fffffff
43 #define PRIORITY_OFFSET_NEGATIVE_MAX    0x40000000
44
45 struct sadb_msg;
46 extern void pfkey_sadump __P((struct sadb_msg *));
47 extern void pfkey_spdump __P((struct sadb_msg *));
48
49 struct sockaddr;
50 struct sadb_alg;
51
52 /* IPsec Library Routines */
53
54 int ipsec_check_keylen __P((u_int, u_int, u_int));
55 int ipsec_check_keylen2 __P((u_int, u_int, u_int));
56 int ipsec_get_keylen __P((u_int, u_int, struct sadb_alg *));
57 char *ipsec_dump_policy __P((caddr_t policy, char *delimiter));
58 void ipsec_hexdump __P((caddr_t buf, int len));
59 int  ipsec_get_policylen __P((caddr_t policy));
60 caddr_t ipsec_set_policy __P((char *msg, int msglen));
61 const char *ipsec_strerror __P((void));
62 void kdebug_sadb __P((struct sadb_msg *base));
63
64
65 /* PFKey Routines */
66
67 u_int pfkey_set_softrate __P((u_int, u_int));
68 u_int pfkey_get_softrate __P((u_int));
69 int pfkey_send_getspi __P((int, u_int, u_int, struct sockaddr *,
70         struct sockaddr *, u_int32_t, u_int32_t, u_int32_t, u_int32_t));
71 int pfkey_send_update __P((int, u_int, u_int, struct sockaddr *,
72         struct sockaddr *, u_int32_t, u_int32_t, u_int,
73         caddr_t, u_int, u_int, u_int, u_int, u_int, u_int32_t, u_int64_t,
74         u_int64_t, u_int64_t, u_int32_t));
75 int pfkey_send_update_nat __P((int, u_int, u_int, struct sockaddr *,
76         struct sockaddr *, u_int32_t, u_int32_t, u_int,
77         caddr_t, u_int, u_int, u_int, u_int, u_int, u_int32_t, u_int64_t,
78         u_int64_t, u_int64_t, u_int32_t,
79         u_int8_t, u_int16_t, u_int16_t, struct sockaddr *));
80 int pfkey_send_add __P((int, u_int, u_int, struct sockaddr *,
81         struct sockaddr *, u_int32_t, u_int32_t, u_int,
82         caddr_t, u_int, u_int, u_int, u_int, u_int, u_int32_t, u_int64_t,
83         u_int64_t, u_int64_t, u_int32_t));
84 int pfkey_send_add_nat __P((int, u_int, u_int, struct sockaddr *,
85         struct sockaddr *, u_int32_t, u_int32_t, u_int,
86         caddr_t, u_int, u_int, u_int, u_int, u_int, u_int32_t, u_int64_t,
87         u_int64_t, u_int64_t, u_int32_t,
88         u_int8_t, u_int16_t, u_int16_t, struct sockaddr *));
89 int pfkey_send_delete __P((int, u_int, u_int,
90         struct sockaddr *, struct sockaddr *, u_int32_t));
91 int pfkey_send_delete_all __P((int, u_int, u_int,
92         struct sockaddr *, struct sockaddr *));
93 int pfkey_send_get __P((int, u_int, u_int,
94         struct sockaddr *, struct sockaddr *, u_int32_t));
95 int pfkey_send_register __P((int, u_int));
96 int pfkey_recv_register __P((int));
97 int pfkey_set_supported __P((struct sadb_msg *, int));
98 int pfkey_send_flush __P((int, u_int));
99 int pfkey_send_dump __P((int, u_int));
100 int pfkey_send_promisc_toggle __P((int, int));
101 int pfkey_send_spdadd __P((int, struct sockaddr *, u_int,
102         struct sockaddr *, u_int, u_int, caddr_t, int, u_int32_t));
103 int pfkey_send_spdadd2 __P((int, struct sockaddr *, u_int,
104         struct sockaddr *, u_int, u_int, u_int64_t, u_int64_t,
105         caddr_t, int, u_int32_t));
106 int pfkey_send_spdupdate __P((int, struct sockaddr *, u_int,
107         struct sockaddr *, u_int, u_int, caddr_t, int, u_int32_t));
108 int pfkey_send_spdupdate2 __P((int, struct sockaddr *, u_int,
109         struct sockaddr *, u_int, u_int, u_int64_t, u_int64_t,
110         caddr_t, int, u_int32_t));
111 int pfkey_send_spddelete __P((int, struct sockaddr *, u_int,
112         struct sockaddr *, u_int, u_int, caddr_t, int, u_int32_t));
113 int pfkey_send_spddelete2 __P((int, u_int32_t));
114 int pfkey_send_spdget __P((int, u_int32_t));
115 int pfkey_send_spdsetidx __P((int, struct sockaddr *, u_int,
116         struct sockaddr *, u_int, u_int, caddr_t, int, u_int32_t));
117 int pfkey_send_spdflush __P((int));
118 int pfkey_send_spddump __P((int));
119
120 int pfkey_open __P((void));
121 void pfkey_close __P((int));
122 struct sadb_msg *pfkey_recv __P((int));
123 int pfkey_send __P((int, struct sadb_msg *, int));
124 int pfkey_align __P((struct sadb_msg *, caddr_t *));
125 int pfkey_check __P((caddr_t *));
126
127 #ifndef __SYSDEP_SA_LEN__
128 #define __SYSDEP_SA_LEN__
129 #include <netinet/in.h>
130
131 #ifndef IPPROTO_IPV4
132 #define IPPROTO_IPV4 IPPROTO_IPIP
133 #endif
134
135 #ifndef IPPROTO_IPCOMP
136 #define IPPROTO_IPCOMP IPPROTO_COMP
137 #endif
138
139 static inline u_int8_t
140 sysdep_sa_len (const struct sockaddr *sa)
141 {
142 #ifdef __linux__
143   switch (sa->sa_family)
144     {
145     case AF_INET:
146       return sizeof (struct sockaddr_in);
147     case AF_INET6:
148       return sizeof (struct sockaddr_in6);
149     }
150   // log_print ("sysdep_sa_len: unknown sa family %d", sa->sa_family);
151   return sizeof (struct sockaddr_in);
152 #else
153   return sa->sa_len;
154 #endif
155 }
156 #endif
157
158 #endif /* KAME_LIBPFKEY_H */
159
160 #endif /* _LIBPFKEY_H */