1/* $KAME: key.h,v 1.21 2001/07/27 03:51:30 itojun Exp $ */
2
3/*-
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#ifndef _NETIPSEC_KEY_H_
35#define _NETIPSEC_KEY_H_
36
37#ifdef _KERNEL
38
39struct mbuf;
40struct secpolicy;
41struct secpolicyindex;
42struct secasvar;
43struct sockaddr;
44struct socket;
45struct sadb_msg;
46struct sadb_x_policy;
47struct secasindex;
48union sockaddr_union;
49struct xformsw;
50
51struct secpolicy *key_newsp(void);
52struct secpolicy *key_allocsp(struct secpolicyindex *, u_int);
53struct secpolicy *key_do_allocsp(struct secpolicyindex *spidx, u_int dir);
54struct secpolicy *key_msg2sp(struct sadb_x_policy *, size_t, int *);
55int key_sp2msg(struct secpolicy *, void *, size_t *);
56void key_addref(struct secpolicy *);
57void key_freesp(struct secpolicy **);
58int key_spdacquire(struct secpolicy *);
59int key_havesp(u_int);
60int key_havesp_any(void);
61void key_bumpspgen(void);
62uint32_t key_getspgen(void);
63uint32_t key_newreqid(void);
64struct mbuf *key_setaccelif(const char *ifname);
65
66struct secasvar *key_allocsa(union sockaddr_union *, uint8_t, uint32_t);
67struct secasvar *key_allocsa_tunnel(union sockaddr_union *,
68 union sockaddr_union *, uint8_t);
69struct secasvar *key_allocsa_policy(struct secpolicy *,
70 const struct secasindex *, int *);
71struct secasvar *key_allocsa_tcpmd5(struct secasindex *);
72void key_freesav(struct secasvar **);
73
74int key_sockaddrcmp(const struct sockaddr *, const struct sockaddr *, int);
75int key_sockaddrcmp_withmask(const struct sockaddr *, const struct sockaddr *,
76 size_t);
77
78int key_register_ifnet(struct secpolicy **, u_int);
79void key_unregister_ifnet(struct secpolicy **, u_int);
80
81void key_delete_xform(const struct xformsw *);
82
83extern u_long key_random(void);
84extern void key_freereg(struct socket *);
85extern int key_parse(struct mbuf *, struct socket *);
86extern void key_sa_recordxfer(struct secasvar *, struct mbuf *);
87uint16_t key_portfromsaddr(struct sockaddr *);
88void key_porttosaddr(struct sockaddr *, uint16_t port);
89
90struct rm_priotracker;
91void ipsec_sahtree_runlock(struct rm_priotracker *);
92void ipsec_sahtree_rlock(struct rm_priotracker *);
93
94#ifdef MALLOC_DECLARE
95MALLOC_DECLARE(M_IPSEC_SA);
96MALLOC_DECLARE(M_IPSEC_SAH);
97MALLOC_DECLARE(M_IPSEC_SP);
98MALLOC_DECLARE(M_IPSEC_SR);
99MALLOC_DECLARE(M_IPSEC_MISC);
100MALLOC_DECLARE(M_IPSEC_SAQ);
101MALLOC_DECLARE(M_IPSEC_SAR);
102MALLOC_DECLARE(M_IPSEC_INPCB);
103#endif /* MALLOC_DECLARE */
104
105#endif /* defined(_KERNEL) */
106#endif /* _NETIPSEC_KEY_H_ */