1 /* $KAME: sainfo.c,v 1.15 2001/11/16 04:12:59 sakane 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/param.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <sys/queue.h>
37 #include <netkey/key_var.h>
38 #include <netinet/in.h>
39 #include <netinet6/ipsec.h>
53 #include "localconf.h"
54 #include "isakmp_var.h"
56 #include "ipsec_doi.h"
59 #include "algorithm.h"
63 static LIST_HEAD(_sitree
, sainfo
) sitree
;
66 * modules for ipsec sa info
69 * return matching entry.
70 * no matching entry found and if there is anonymous entry, return it.
72 * XXX by each data type, should be changed to compare the buffer.
76 const vchar_t
*src
, *dst
;
78 struct sainfo
*s
= NULL
;
79 struct sainfo
*anonymous
= NULL
;
81 LIST_FOREACH(s
, &sitree
, chain
) {
82 if (s
->idsrc
== NULL
) {
89 if (anonymous
!= NULL
)
94 if (memcmp(src
->v
, s
->idsrc
->v
, s
->idsrc
->l
) == 0
95 && memcmp(dst
->v
, s
->iddst
->v
, s
->iddst
->l
) == 0)
100 plog(LLV_DEBUG
, LOCATION
, NULL
,
101 "anonymous sainfo selected.\n");
111 new = racoon_calloc(1, sizeof(*new));
115 new->idvtype
= IDTYPE_ADDRESS
;
116 new->lifetime
= IPSECDOI_ATTR_SA_LD_SEC_DEFAULT
;
117 new->lifebyte
= IPSECDOI_ATTR_SA_LD_KB_MAX
;
128 for (i
= 0; i
< MAXALGCLASS
; i
++)
129 delsainfoalg(si
->algs
[i
]);
143 LIST_INSERT_HEAD(&sitree
, new, chain
);
150 LIST_REMOVE(si
, chain
);
156 struct sainfo
*s
, *next
;
158 for (s
= LIST_FIRST(&sitree
); s
; s
= next
) {
159 next
= LIST_NEXT(s
, chain
);
174 struct sainfoalg
*new;
176 new = racoon_calloc(1, sizeof(*new));
185 struct sainfoalg
*alg
;
187 struct sainfoalg
*a
, *next
;
189 for (a
= alg
; a
; a
= next
) {
196 inssainfoalg(head
, new)
197 struct sainfoalg
**head
;
198 struct sainfoalg
*new;
202 for (a
= *head
; a
&& a
->next
; a
= a
->next
)
212 const struct sainfo
*si
;
214 static char buf
[256];
216 if (si
->idsrc
== NULL
)
219 snprintf(buf
, sizeof(buf
), "%s", ipsecdoi_id2str(si
->idsrc
));
220 snprintf(buf
+ strlen(buf
), sizeof(buf
) - strlen(buf
),
221 " %s", ipsecdoi_id2str(si
->iddst
));