188768458SSam Leffler /* $KAME: key.h,v 1.21 2001/07/27 03:51:30 itojun Exp $ */ 288768458SSam Leffler 3c398230bSWarner Losh /*- 451369649SPedro F. Giffuni * SPDX-License-Identifier: BSD-3-Clause 551369649SPedro F. Giffuni * 688768458SSam Leffler * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 788768458SSam Leffler * All rights reserved. 888768458SSam Leffler * 988768458SSam Leffler * Redistribution and use in source and binary forms, with or without 1088768458SSam Leffler * modification, are permitted provided that the following conditions 1188768458SSam Leffler * are met: 1288768458SSam Leffler * 1. Redistributions of source code must retain the above copyright 1388768458SSam Leffler * notice, this list of conditions and the following disclaimer. 1488768458SSam Leffler * 2. Redistributions in binary form must reproduce the above copyright 1588768458SSam Leffler * notice, this list of conditions and the following disclaimer in the 1688768458SSam Leffler * documentation and/or other materials provided with the distribution. 1788768458SSam Leffler * 3. Neither the name of the project nor the names of its contributors 1888768458SSam Leffler * may be used to endorse or promote products derived from this software 1988768458SSam Leffler * without specific prior written permission. 2088768458SSam Leffler * 2188768458SSam Leffler * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2288768458SSam Leffler * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2388768458SSam Leffler * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2488768458SSam Leffler * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2588768458SSam Leffler * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2688768458SSam Leffler * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2788768458SSam Leffler * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2888768458SSam Leffler * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2988768458SSam Leffler * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3088768458SSam Leffler * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3188768458SSam Leffler * SUCH DAMAGE. 3288768458SSam Leffler */ 3388768458SSam Leffler 3488768458SSam Leffler #ifndef _NETIPSEC_KEY_H_ 3588768458SSam Leffler #define _NETIPSEC_KEY_H_ 3688768458SSam Leffler 3788768458SSam Leffler #ifdef _KERNEL 3888768458SSam Leffler 39*ef2a572bSKonstantin Belousov struct mbuf; 4088768458SSam Leffler struct secpolicy; 4188768458SSam Leffler struct secpolicyindex; 4288768458SSam Leffler struct secasvar; 4388768458SSam Leffler struct sockaddr; 4488768458SSam Leffler struct socket; 4588768458SSam Leffler struct sadb_msg; 4688768458SSam Leffler struct sadb_x_policy; 4788768458SSam Leffler struct secasindex; 4888768458SSam Leffler union sockaddr_union; 490ddfd867SAndrey V. Elsukov struct xformsw; 5088768458SSam Leffler 51fcf59617SAndrey V. Elsukov struct secpolicy *key_newsp(void); 52fcf59617SAndrey V. Elsukov struct secpolicy *key_allocsp(struct secpolicyindex *, u_int); 5354ac7b96SKonstantin Belousov struct secpolicy *key_do_allocsp(struct secpolicyindex *spidx, u_int dir); 54fcf59617SAndrey V. Elsukov struct secpolicy *key_msg2sp(struct sadb_x_policy *, size_t, int *); 55fcf59617SAndrey V. Elsukov int key_sp2msg(struct secpolicy *, void *, size_t *); 56fcf59617SAndrey V. Elsukov void key_addref(struct secpolicy *); 57fcf59617SAndrey V. Elsukov void key_freesp(struct secpolicy **); 58fcf59617SAndrey V. Elsukov int key_spdacquire(struct secpolicy *); 59fcf59617SAndrey V. Elsukov int key_havesp(u_int); 60c1bfe8c5SMateusz Guzik int key_havesp_any(void); 61fcf59617SAndrey V. Elsukov void key_bumpspgen(void); 62fcf59617SAndrey V. Elsukov uint32_t key_getspgen(void); 63fcf59617SAndrey V. Elsukov uint32_t key_newreqid(void); 64*ef2a572bSKonstantin Belousov struct mbuf *key_setaccelif(const char *ifname); 6588768458SSam Leffler 66fcf59617SAndrey V. Elsukov struct secasvar *key_allocsa(union sockaddr_union *, uint8_t, uint32_t); 67fcf59617SAndrey V. Elsukov struct secasvar *key_allocsa_tunnel(union sockaddr_union *, 68fcf59617SAndrey V. Elsukov union sockaddr_union *, uint8_t); 69fcf59617SAndrey V. Elsukov struct secasvar *key_allocsa_policy(struct secpolicy *, 70fcf59617SAndrey V. Elsukov const struct secasindex *, int *); 71fcf59617SAndrey V. Elsukov struct secasvar *key_allocsa_tcpmd5(struct secasindex *); 72fcf59617SAndrey V. Elsukov void key_freesav(struct secasvar **); 7388768458SSam Leffler 74fcf59617SAndrey V. Elsukov int key_sockaddrcmp(const struct sockaddr *, const struct sockaddr *, int); 75fcf59617SAndrey V. Elsukov int key_sockaddrcmp_withmask(const struct sockaddr *, const struct sockaddr *, 76fcf59617SAndrey V. Elsukov size_t); 7788768458SSam Leffler 78fcf59617SAndrey V. Elsukov int key_register_ifnet(struct secpolicy **, u_int); 79fcf59617SAndrey V. Elsukov void key_unregister_ifnet(struct secpolicy **, u_int); 8088768458SSam Leffler 810ddfd867SAndrey V. Elsukov void key_delete_xform(const struct xformsw *); 820ddfd867SAndrey V. Elsukov 8318961126SAndrey V. Elsukov extern u_long key_random(void); 8418961126SAndrey V. Elsukov extern void key_freereg(struct socket *); 8518961126SAndrey V. Elsukov extern int key_parse(struct mbuf *, struct socket *); 8618961126SAndrey V. Elsukov extern void key_sa_recordxfer(struct secasvar *, struct mbuf *); 87fcf59617SAndrey V. Elsukov uint16_t key_portfromsaddr(struct sockaddr *); 88fcf59617SAndrey V. Elsukov void key_porttosaddr(struct sockaddr *, uint16_t port); 8988768458SSam Leffler 90*ef2a572bSKonstantin Belousov struct rm_priotracker; 91*ef2a572bSKonstantin Belousov void ipsec_sahtree_runlock(struct rm_priotracker *); 92*ef2a572bSKonstantin Belousov void ipsec_sahtree_rlock(struct rm_priotracker *); 93*ef2a572bSKonstantin Belousov 9488768458SSam Leffler #ifdef MALLOC_DECLARE 956464079fSSam Leffler MALLOC_DECLARE(M_IPSEC_SA); 966464079fSSam Leffler MALLOC_DECLARE(M_IPSEC_SAH); 976464079fSSam Leffler MALLOC_DECLARE(M_IPSEC_SP); 986464079fSSam Leffler MALLOC_DECLARE(M_IPSEC_SR); 996464079fSSam Leffler MALLOC_DECLARE(M_IPSEC_MISC); 1006464079fSSam Leffler MALLOC_DECLARE(M_IPSEC_SAQ); 1016464079fSSam Leffler MALLOC_DECLARE(M_IPSEC_SAR); 1026464079fSSam Leffler MALLOC_DECLARE(M_IPSEC_INPCB); 10388768458SSam Leffler #endif /* MALLOC_DECLARE */ 10488768458SSam Leffler 10588768458SSam Leffler #endif /* defined(_KERNEL) */ 10688768458SSam Leffler #endif /* _NETIPSEC_KEY_H_ */ 107