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