]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netkey/keydb.c
2 * Copyright (c) 2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 /* $KAME: keydb.c,v 1.61 2000/03/25 07:24:13 sumikawa Exp $ */
32 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
33 * All rights reserved.
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
38 * 1. Redistributions of source code must retain the above copyright
39 * notice, this list of conditions and the following disclaimer.
40 * 2. Redistributions in binary form must reproduce the above copyright
41 * notice, this list of conditions and the following disclaimer in the
42 * documentation and/or other materials provided with the distribution.
43 * 3. Neither the name of the project nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 #include <sys/types.h>
61 #include <sys/socket.h>
62 #include <sys/param.h>
63 #include <sys/systm.h>
64 #include <sys/kernel.h>
65 #include <sys/malloc.h>
66 #include <sys/errno.h>
67 #include <sys/queue.h>
70 #include <net/route.h>
72 #include <netinet/in.h>
74 #include <net/pfkeyv2.h>
75 #include <netkey/keydb.h>
76 #include <netinet6/ipsec.h>
78 #include <net/net_osdep.h>
80 extern lck_mtx_t
*sadb_mutex
;
82 MALLOC_DEFINE(M_SECA
, "key mgmt", "security associations, key management");
84 // static void keydb_delsecasvar(struct secasvar *); // not used
87 * secpolicy management
90 keydb_newsecpolicy(void)
94 lck_mtx_assert(sadb_mutex
, LCK_MTX_ASSERT_NOTOWNED
);
96 return (struct secpolicy
*)_MALLOC(sizeof(*p
), M_SECA
,
101 keydb_delsecpolicy(struct secpolicy
*p
)
107 * secashead management
110 keydb_newsecashead(void)
115 lck_mtx_assert(sadb_mutex
, LCK_MTX_ASSERT_OWNED
);
117 p
= (struct secashead
*)_MALLOC(sizeof(*p
), M_SECA
, M_NOWAIT
| M_ZERO
);
119 lck_mtx_unlock(sadb_mutex
);
120 p
= (struct secashead
*)_MALLOC(sizeof(*p
), M_SECA
,
122 lck_mtx_lock(sadb_mutex
);
126 for (i
= 0; i
< sizeof(p
->savtree
)/sizeof(p
->savtree
[0]); i
++)
127 LIST_INIT(&p
->savtree
[i
]);
133 keydb_delsecashead(p
)
143 * secasvar management (reference counted)
150 lck_mtx_assert(sadb_mutex
, LCK_MTX_ASSERT_NOTOWNED
);
152 p
= (struct secasvar
*)_MALLOC(sizeof(*p
), M_SECA
, M_WAITOK
);
155 bzero(p
, sizeof(*p
));
165 lck_mtx_assert(sadb_mutex
, LCK_MTX_ASSERT_OWNED
);
171 keydb_freesecasvar(p
)
175 lck_mtx_assert(sadb_mutex
, LCK_MTX_ASSERT_OWNED
);
178 /* negative refcnt will cause panic intentionally */
180 keydb_delsecasvar(p
);
189 panic("keydb_delsecasvar called with refcnt != 0");
196 * secreplay management
199 keydb_newsecreplay(size_t wsize
)
203 lck_mtx_assert(sadb_mutex
, LCK_MTX_ASSERT_OWNED
);
205 p
= (struct secreplay
*)_MALLOC(sizeof(*p
), M_SECA
, M_NOWAIT
| M_ZERO
);
207 lck_mtx_unlock(sadb_mutex
);
208 p
= (struct secreplay
*)_MALLOC(sizeof(*p
), M_SECA
,
210 lck_mtx_lock(sadb_mutex
);
216 p
->bitmap
= (caddr_t
)_MALLOC(wsize
, M_SECA
, M_NOWAIT
| M_ZERO
);
218 lck_mtx_unlock(sadb_mutex
);
219 p
->bitmap
= (caddr_t
)_MALLOC(wsize
, M_SECA
,
221 lck_mtx_lock(sadb_mutex
);
233 keydb_delsecreplay(struct secreplay
*p
)
236 _FREE(p
->bitmap
, M_SECA
);
249 p
= (struct secreg
*)_MALLOC(sizeof(*p
), M_SECA
, M_WAITOK
);
251 bzero(p
, sizeof(*p
));