1 /* $KAME: remoteconf.c,v 1.28 2001/10/02 03:46:41 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/types.h>
33 #include <sys/param.h>
34 #include <sys/socket.h>
35 #include <sys/queue.h>
37 #include <netinet/in.h>
38 #include <netkey/key_var.h>
40 #ifdef IPV6_INRIA_VERSION
41 #include <netinet/ipsec.h>
43 #include <netinet6/ipsec.h>
58 #include "isakmp_var.h"
60 #include "ipsec_doi.h"
62 #include "remoteconf.h"
63 #include "localconf.h"
64 #include "grabmyaddr.h"
69 static LIST_HEAD(_rmtree
, remoteconf
) rmtree
;
73 * search remote configuration.
74 * don't use port number to search if its value is either IPSEC_PORT_ANY.
75 * If matching anonymous entry, then new entry is copied from anonymous entry.
76 * If no anonymous entry found, then return NULL.
78 * Other: remote configuration entry.
82 struct sockaddr
*remote
;
85 struct remoteconf
*anon
= NULL
;
87 char buf
[NI_MAXHOST
+ NI_MAXSERV
+ 10];
88 char addr
[NI_MAXHOST
], port
[NI_MAXSERV
];
92 switch (remote
->sa_family
) {
94 if (((struct sockaddr_in
*)remote
)->sin_port
!= IPSEC_PORT_ANY
)
99 if (((struct sockaddr_in6
*)remote
)->sin6_port
!= IPSEC_PORT_ANY
)
104 plog(LLV_ERROR
, LOCATION
, NULL
,
105 "invalid family: %d\n", remote
->sa_family
);
109 GETNAMEINFO(remote
, addr
, port
);
110 snprintf(buf
, sizeof(buf
), "%s%s%s%s", addr
,
112 withport
? port
: "",
113 withport
? "]" : "");
115 LIST_FOREACH(p
, &rmtree
, chain
) {
116 if ((!withport
&& cmpsaddrwop(remote
, p
->remote
) == 0)
117 || (withport
&& cmpsaddrstrict(remote
, p
->remote
) == 0)) {
118 plog(LLV_DEBUG
, LOCATION
, NULL
,
119 "configuration found for %s.\n", buf
);
123 /* save the pointer to the anonymous configuration */
124 if (p
->remote
->sa_family
== AF_UNSPEC
)
129 plog(LLV_DEBUG
, LOCATION
, NULL
,
130 "anonymous configuration selected for %s.\n", buf
);
134 plog(LLV_DEBUG
, LOCATION
, NULL
,
135 "no remote configuration found.\n");
142 struct remoteconf
*new;
144 new = racoon_calloc(1, sizeof(*new));
148 new->proposal
= NULL
;
151 new->doitype
= IPSEC_DOI
;
152 new->sittype
= IPSECDOI_SIT_IDENTITY_ONLY
;
153 new->idvtype
= IDTYPE_ADDRESS
;
154 new->idvtype_p
= IDTYPE_ADDRESS
;
155 new->nonce_size
= DEFAULT_NONCE_SIZE
;
156 new->keepalive
= FALSE
;
157 new->passive
= FALSE
;
158 new->ini_contact
= TRUE
;
159 new->pcheck_level
= PROP_CHECK_STRICT
;
160 new->verify_identifier
= FALSE
;
161 new->verify_cert
= TRUE
;
162 new->getcert_method
= ISAKMP_GETCERT_PAYLOAD
;
163 new->send_cert
= TRUE
;
165 new->support_mip6
= FALSE
;
166 new->gen_policy
= FALSE
;
167 new->retry_counter
= lcconf
->retry_counter
;
168 new->retry_interval
= lcconf
->retry_interval
;
175 struct remoteconf
*rmconf
;
178 deletypes(rmconf
->etypes
);
180 oakley_dhgrp_free(rmconf
->dhgrp
);
181 if (rmconf
->proposal
)
182 delisakmpsa(rmconf
->proposal
);
191 oakley_dhgrp_free(sa
->dhgrp
);
193 delisakmpsa(sa
->next
);
211 * insert into head of list.
215 struct remoteconf
*new;
217 LIST_INSERT_HEAD(&rmtree
, new, chain
);
222 struct remoteconf
*rmconf
;
224 LIST_REMOVE(rmconf
, chain
);
230 struct remoteconf
*p
, *next
;
232 for (p
= LIST_FIRST(&rmtree
); p
; p
= next
) {
233 next
= LIST_NEXT(p
, chain
);
245 /* check exchange type to be acceptable */
247 check_etypeok(rmconf
, etype
)
248 struct remoteconf
*rmconf
;
253 for (e
= rmconf
->etypes
; e
!= NULL
; e
= e
->next
) {
254 if (e
->type
== etype
)
265 struct isakmpsa
*new;
267 new = racoon_calloc(1, sizeof(*new));
272 * Just for sanity, make sure this is initialized. This is
273 * filled in for real when the ISAKMP proposal is configured.
275 new->vendorid
= VENDORID_UNKNOWN
;
287 * insert into tail of list.
290 insisakmpsa(new, rmconf
)
291 struct isakmpsa
*new;
292 struct remoteconf
*rmconf
;
296 new->rmconf
= rmconf
;
298 if (rmconf
->proposal
== NULL
) {
299 rmconf
->proposal
= new;
303 for (p
= rmconf
->proposal
; p
->next
!= NULL
; p
= p
->next
)
312 const struct remoteconf
*rmconf
;
314 if (rmconf
->remote
->sa_family
== AF_UNSPEC
)
316 return saddr2str(rmconf
->remote
);