1 1.38 knakahar /* $NetBSD: key.h,v 1.38 2022/12/08 08:05:03 knakahara Exp $ */ 2 1.36 maxv /* $FreeBSD: key.h,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $ */ 3 1.1 jonathan /* $KAME: key.h,v 1.21 2001/07/27 03:51:30 itojun Exp $ */ 4 1.1 jonathan 5 1.1 jonathan /* 6 1.1 jonathan * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 7 1.1 jonathan * All rights reserved. 8 1.1 jonathan * 9 1.1 jonathan * Redistribution and use in source and binary forms, with or without 10 1.1 jonathan * modification, are permitted provided that the following conditions 11 1.1 jonathan * are met: 12 1.1 jonathan * 1. Redistributions of source code must retain the above copyright 13 1.1 jonathan * notice, this list of conditions and the following disclaimer. 14 1.1 jonathan * 2. Redistributions in binary form must reproduce the above copyright 15 1.1 jonathan * notice, this list of conditions and the following disclaimer in the 16 1.1 jonathan * documentation and/or other materials provided with the distribution. 17 1.1 jonathan * 3. Neither the name of the project nor the names of its contributors 18 1.1 jonathan * may be used to endorse or promote products derived from this software 19 1.1 jonathan * without specific prior written permission. 20 1.1 jonathan * 21 1.1 jonathan * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 22 1.1 jonathan * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 1.1 jonathan * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 1.1 jonathan * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 25 1.1 jonathan * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 1.1 jonathan * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 1.1 jonathan * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 1.1 jonathan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 1.1 jonathan * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 1.1 jonathan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 1.1 jonathan * SUCH DAMAGE. 32 1.1 jonathan */ 33 1.1 jonathan 34 1.1 jonathan #ifndef _NETIPSEC_KEY_H_ 35 1.1 jonathan #define _NETIPSEC_KEY_H_ 36 1.1 jonathan 37 1.1 jonathan #ifdef _KERNEL 38 1.1 jonathan 39 1.1 jonathan struct secpolicy; 40 1.1 jonathan struct secpolicyindex; 41 1.1 jonathan struct ipsecrequest; 42 1.1 jonathan struct secasvar; 43 1.1 jonathan struct sockaddr; 44 1.1 jonathan struct socket; 45 1.1 jonathan struct secasindex; 46 1.1 jonathan union sockaddr_union; 47 1.1 jonathan 48 1.34 knakahar #include <net/pfkeyv2.h> 49 1.34 knakahar 50 1.34 knakahar struct sadb_msghdr { 51 1.34 knakahar struct sadb_msg *msg; 52 1.34 knakahar void *ext[SADB_EXT_MAX + 1]; 53 1.34 knakahar int extoff[SADB_EXT_MAX + 1]; 54 1.34 knakahar int extlen[SADB_EXT_MAX + 1]; 55 1.34 knakahar }; 56 1.34 knakahar 57 1.8 degroote int key_havesp(u_int dir); 58 1.20 ozaki struct secpolicy *key_lookup_sp_byspidx(const struct secpolicyindex *, u_int, 59 1.35 maxv const char *, int); 60 1.8 degroote struct secpolicy *key_newsp(const char*, int); 61 1.8 degroote struct secpolicy *key_gettunnel(const struct sockaddr *, 62 1.35 maxv const struct sockaddr *, const struct sockaddr *, 63 1.35 maxv const struct sockaddr *, const char *, int); 64 1.37 andvar /* NB: prepend with _ for KAME IPv6 compatibility */ 65 1.26 ozaki void key_init_sp(struct secpolicy *); 66 1.26 ozaki void key_free_sp(struct secpolicy *); 67 1.25 ozaki u_int key_sp_refcnt(const struct secpolicy *); 68 1.35 maxv void key_sp_ref(struct secpolicy *, const char *, int); 69 1.35 maxv void key_sp_unref(struct secpolicy *, const char *, int); 70 1.38 knakahar void key_sp_touch(struct secpolicy *); 71 1.35 maxv void key_sa_ref(struct secasvar *, const char *, int); 72 1.35 maxv void key_sa_unref(struct secasvar *, const char *, int); 73 1.28 ozaki u_int key_sa_refcnt(const struct secasvar *); 74 1.1 jonathan 75 1.26 ozaki void key_socksplist_add(struct secpolicy *); 76 1.26 ozaki 77 1.1 jonathan /* 78 1.1 jonathan * Access to the SADB are interlocked with splsoftnet. In particular, 79 1.1 jonathan * holders of SA's use this to block accesses by protocol processing 80 1.1 jonathan * that can happen either by network swi's or by continuations that 81 1.1 jonathan * occur on crypto callbacks. Much of this could go away if 82 1.1 jonathan * key_checkrequest were redone. 83 1.3 perry */ 84 1.20 ozaki #define KEY_LOOKUP_SP_BYSPIDX(spidx, dir) \ 85 1.20 ozaki key_lookup_sp_byspidx(spidx, dir, __func__, __LINE__) 86 1.1 jonathan #define KEY_NEWSP() \ 87 1.15 ozaki key_newsp(__func__, __LINE__) 88 1.1 jonathan #define KEY_GETTUNNEL(osrc, odst, isrc, idst) \ 89 1.15 ozaki key_gettunnel(osrc, odst, isrc, idst, __func__, __LINE__) 90 1.26 ozaki #define KEY_SP_UNREF(spp) \ 91 1.26 ozaki key_sp_unref(*(spp), __func__, __LINE__) 92 1.19 ozaki #define KEY_SP_REF(sp) \ 93 1.19 ozaki key_sp_ref(sp, __func__, __LINE__) 94 1.22 ozaki #define KEY_SA_REF(sav) \ 95 1.22 ozaki key_sa_ref(sav, __func__, __LINE__) 96 1.27 ozaki #define KEY_SA_UNREF(psav) \ 97 1.29 ozaki key_sa_unref(*(psav), __func__, __LINE__) 98 1.1 jonathan 99 1.20 ozaki struct secasvar *key_lookup_sa(const union sockaddr_union *, 100 1.35 maxv u_int, u_int32_t, u_int16_t, u_int16_t, const char *, int); 101 1.35 maxv void key_freesav(struct secasvar **, const char *, int); 102 1.30 ozaki struct secasvar *key_lookup_sa_bysaidx(const struct secasindex *); 103 1.1 jonathan 104 1.20 ozaki #define KEY_LOOKUP_SA(dst, proto, spi, sport, dport) \ 105 1.20 ozaki key_lookup_sa(dst, proto, spi, sport, dport, __func__, __LINE__) 106 1.1 jonathan 107 1.35 maxv int key_checktunnelsanity(struct secasvar *, u_int, void *, void *); 108 1.32 ozaki int key_checkrequest(const struct ipsecrequest *, const struct secasindex *, 109 1.31 ozaki struct secasvar **); 110 1.8 degroote 111 1.35 maxv struct secpolicy *key_msg2sp(const struct sadb_x_policy *, size_t, int *); 112 1.33 ozaki struct mbuf *key_sp2msg(const struct secpolicy *, int); 113 1.35 maxv int key_ismyaddr(const struct sockaddr *); 114 1.35 maxv int key_spdacquire(const struct secpolicy *); 115 1.35 maxv u_long key_random(void); 116 1.35 maxv void key_randomfill(void *, size_t); 117 1.35 maxv void key_freereg(struct socket *); 118 1.35 maxv int key_parse(struct mbuf *, struct socket *); 119 1.35 maxv void key_init(void); 120 1.35 maxv void key_sa_recordxfer(struct secasvar *, struct mbuf *); 121 1.35 maxv void key_sa_routechange(struct sockaddr *); 122 1.13 christos void key_update_used(void); 123 1.13 christos int key_get_used(void); 124 1.1 jonathan 125 1.35 maxv u_int16_t key_portfromsaddr(const union sockaddr_union *); 126 1.7 degroote 127 1.34 knakahar /* for ipsec(4) */ 128 1.34 knakahar struct secpolicy *key_kpi_spdadd(struct mbuf *); 129 1.34 knakahar int key_kpi_spddelete2(struct mbuf *); 130 1.34 knakahar u_int16_t key_newreqid(void); 131 1.7 degroote 132 1.1 jonathan #endif /* defined(_KERNEL) */ 133 1.4 elad #endif /* !_NETIPSEC_KEY_H_ */ 134