]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netkey/keydb.c
1 /* $KAME: keydb.c,v 1.61 2000/03/25 07:24:13 sumikawa Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/types.h>
33 #include <sys/socket.h>
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/errno.h>
39 #include <sys/queue.h>
42 #include <net/route.h>
44 #include <netinet/in.h>
46 #include <net/pfkeyv2.h>
47 #include <netkey/keydb.h>
48 #include <netinet6/ipsec.h>
50 #include <net/net_osdep.h>
52 MALLOC_DEFINE(M_SECA
, "key mgmt", "security associations, key management");
54 static void keydb_delsecasvar(struct secasvar
*);
57 * secpolicy management
64 p
= (struct secpolicy
*)_MALLOC(sizeof(*p
), M_SECA
, M_WAITOK
);
80 * secashead management
88 p
= (struct secashead
*)_MALLOC(sizeof(*p
), M_SECA
, M_WAITOK
);
92 for (i
= 0; i
< sizeof(p
->savtree
)/sizeof(p
->savtree
[0]); i
++)
93 LIST_INIT(&p
->savtree
[i
]);
106 * secasvar management (reference counted)
113 p
= (struct secasvar
*)_MALLOC(sizeof(*p
), M_SECA
, M_WAITOK
);
116 bzero(p
, sizeof(*p
));
133 keydb_freesecasvar(p
)
140 /* negative refcnt will cause panic intentionally */
142 keydb_delsecasvar(p
);
152 panic("keydb_delsecasvar called with refcnt != 0");
158 * secreplay management
161 keydb_newsecreplay(wsize
)
166 p
= (struct secreplay
*)_MALLOC(sizeof(*p
), M_SECA
, M_WAITOK
);
170 bzero(p
, sizeof(*p
));
172 p
->bitmap
= (caddr_t
)_MALLOC(wsize
, M_SECA
, M_WAITOK
);
177 bzero(p
->bitmap
, wsize
);
184 keydb_delsecreplay(p
)
189 _FREE(p
->bitmap
, M_SECA
);
201 p
= (struct secreg
*)_MALLOC(sizeof(*p
), M_SECA
, M_WAITOK
);
203 bzero(p
, sizeof(*p
));