1 /* $NetBSD: isakmp_cfg.c,v 1.12.6.1 2007/06/07 20:06:34 manu Exp $ */
3 /* Id: isakmp_cfg.c,v 1.55 2006/08/22 18:17:17 manubsd Exp */
6 * Copyright (C) 2004-2006 Emmanuel Dreyfus
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include <sys/types.h>
37 #include <sys/param.h>
38 #include <sys/socket.h>
39 #include <sys/queue.h>
52 #include <netinet/in.h>
53 #include <arpa/inet.h>
59 #if TIME_WITH_SYS_TIME
60 # include <sys/time.h>
64 # include <sys/time.h>
87 #include "isakmp_var.h"
91 #include "remoteconf.h"
92 #include "localconf.h"
93 #include "crypto_openssl.h"
94 #include "isakmp_inf.h"
95 #include "isakmp_xauth.h"
96 #include "isakmp_unity.h"
97 #include "isakmp_cfg.h"
99 #include "vpn_control.h"
100 #include "vpn_control_var.h"
101 #include "ike_session.h"
102 #include "ipsecSessionTracer.h"
103 #include "ipsecMessageTracer.h"
104 #include "nattraversal.h"
106 struct isakmp_cfg_config isakmp_cfg_config
;
108 static vchar_t
*buffer_cat (vchar_t
*s
, vchar_t
*append
);
109 static vchar_t
*isakmp_cfg_net (phase1_handle_t
*, struct isakmp_data
*);
111 static vchar_t
*isakmp_cfg_void (phase1_handle_t
*, struct isakmp_data
*);
113 static vchar_t
*isakmp_cfg_addr4 (phase1_handle_t
*,
114 struct isakmp_data
*, in_addr_t
*);
115 static void isakmp_cfg_getaddr4 (struct isakmp_data
*, struct in_addr
*);
116 static vchar_t
*isakmp_cfg_addr4_list (phase1_handle_t
*,
117 struct isakmp_data
*, in_addr_t
*, int);
118 static void isakmp_cfg_appendaddr4 (struct isakmp_data
*,
119 struct in_addr
*, int *, int);
120 static void isakmp_cfg_getstring (struct isakmp_data
*,char *);
121 void isakmp_cfg_iplist_to_str (char *, int, void *, int);
123 #define ISAKMP_CFG_LOGIN 1
124 #define ISAKMP_CFG_LOGOUT 2
127 * Handle an ISAKMP config mode packet
128 * We expect HDR, HASH, ATTR
131 isakmp_cfg_r(iph1
, msg
)
132 phase1_handle_t
*iph1
;
135 struct isakmp
*packet
;
136 struct isakmp_gen
*ph
;
141 struct isakmp_ivm
*ivm
;
142 phase2_handle_t
*iph2
;
145 /* Check that the packet is long enough to have a header */
146 if (msg
->l
< sizeof(*packet
)) {
147 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
148 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
149 CONSTSTR("MODE-Config. Unexpected short packet"),
150 CONSTSTR("Failed to process short MODE-Config packet"));
151 plog(ASL_LEVEL_ERR
, "Unexpected short packet\n");
155 packet
= (struct isakmp
*)msg
->v
;
157 /* Is it encrypted? It should be encrypted */
158 if ((packet
->flags
& ISAKMP_FLAG_E
) == 0) {
159 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
160 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
161 CONSTSTR("MODE-Config. User credentials sent in cleartext"),
162 CONSTSTR("Dropped cleattext User credentials"));
164 "User credentials sent in cleartext!\n");
169 * Decrypt the packet. If this is the beginning of a new
170 * exchange, reinitialize the IV
172 if (iph1
->mode_cfg
->ivm
== NULL
||
173 iph1
->mode_cfg
->last_msgid
!= packet
->msgid
)
174 iph1
->mode_cfg
->ivm
=
175 isakmp_cfg_newiv(iph1
, packet
->msgid
);
176 ivm
= iph1
->mode_cfg
->ivm
;
178 dmsg
= oakley_do_decrypt(iph1
, msg
, ivm
->iv
, ivm
->ive
);
180 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
181 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
182 CONSTSTR("MODE-Config. Failed to decrypt packet"),
183 CONSTSTR("Failed to decrypt MODE-Config packet"));
185 "failed to decrypt message\n");
189 plog(ASL_LEVEL_NOTICE
, "MODE_CFG packet\n");
191 /* Now work with the decrypted packet */
192 packet
= (struct isakmp
*)dmsg
->v
;
193 tlen
= dmsg
->l
- sizeof(*packet
);
194 ph
= (struct isakmp_gen
*)(packet
+ 1);
197 while ((tlen
> 0) && (np
!= ISAKMP_NPTYPE_NONE
)) {
198 /* Check that the payload header fits in the packet */
199 if (tlen
< sizeof(*ph
)) {
200 plog(ASL_LEVEL_WARNING
,
201 "Short payload header\n");
205 /* Check that the payload fits in the packet */
206 if (tlen
< ntohs(ph
->len
)) {
207 plog(ASL_LEVEL_WARNING
,
212 plog(ASL_LEVEL_DEBUG
, "Seen payload %d\n", np
);
215 case ISAKMP_NPTYPE_HASH
: {
219 struct isakmp_gen
*nph
;
221 plen
= ntohs(ph
->len
);
222 nph
= (struct isakmp_gen
*)((char *)ph
+ plen
);
223 plen
= ntohs(nph
->len
);
224 /* Check that the hash payload fits in the packet */
225 if (tlen
< (plen
+ ntohs(ph
->len
))) {
226 plog(ASL_LEVEL_WARNING
,
227 "Invalid Hash payload. len %d, overall-len %d\n",
233 if ((payload
= vmalloc(plen
)) == NULL
) {
235 "Cannot allocate memory\n");
238 memcpy(payload
->v
, nph
, plen
);
240 if ((check
= oakley_compute_hash1(iph1
,
241 packet
->msgid
, payload
)) == NULL
) {
243 "Cannot compute hash\n");
248 if (timingsafe_bcmp(ph
+ 1, check
->v
, check
->l
) != 0) {
250 "Hash verification failed\n");
259 case ISAKMP_NPTYPE_ATTR
: {
260 struct isakmp_pl_attr
*attrpl
;
262 attrpl
= (struct isakmp_pl_attr
*)ph
;
263 isakmp_cfg_attr_r(iph1
, packet
->msgid
, attrpl
, msg
);
268 plog(ASL_LEVEL_WARNING
,
269 "Unexpected next payload %d\n", np
);
270 /* Skip to the next payload */
274 /* Move to the next payload */
276 tlen
-= ntohs(ph
->len
);
278 ph
= (struct isakmp_gen
*)(npp
+ ntohs(ph
->len
));
282 /* find phase 2 in case pkt scheduled for resend */
283 iph2
= ike_session_getph2bymsgid(iph1
, packet
->msgid
);
285 goto out
; /* no resend scheduled */
286 SCHED_KILL(iph2
->scr
); /* turn off schedule */
287 ike_session_unlink_phase2(iph2
);
289 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
290 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_SUCC
,
291 CONSTSTR("MODE-Config"),
295 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
296 IPSECSESSIONEVENTCODE_IKE_PACKET_RX_FAIL
,
297 CONSTSTR("MODE-Config"),
298 CONSTSTR("Failed to process Mode-Config packet"));
304 isakmp_cfg_attr_r(iph1
, msgid
, attrpl
, msg
)
305 phase1_handle_t
*iph1
;
307 struct isakmp_pl_attr
*attrpl
;
310 int type
= attrpl
->type
;
312 plog(ASL_LEVEL_NOTICE
,
313 "Configuration exchange type %s\n", s_isakmp_cfg_ptype(type
));
316 /* ignore, but this is the time to reinit the IV */
317 oakley_delivm(iph1
->mode_cfg
->ivm
);
318 iph1
->mode_cfg
->ivm
= NULL
;
322 case ISAKMP_CFG_REPLY
:
323 return isakmp_cfg_reply(iph1
, attrpl
);
326 case ISAKMP_CFG_REQUEST
:
328 return isakmp_cfg_request(iph1
, attrpl
, msg
);
333 return isakmp_cfg_set(iph1
, attrpl
, msg
);
337 plog(ASL_LEVEL_WARNING
,
338 "Unepected configuration exchange type %d\n", type
);
347 isakmp_cfg_reply(iph1
, attrpl
)
348 phase1_handle_t
*iph1
;
349 struct isakmp_pl_attr
*attrpl
;
351 struct isakmp_data
*attr
;
358 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_GOT_REPLY
)
359 return 0; /* already received this - duplicate packet */
361 tlen
= ntohs(attrpl
->h
.len
);
362 attr
= (struct isakmp_data
*)(attrpl
+ 1);
363 tlen
-= sizeof(*attrpl
);
366 type
= ntohs(attr
->type
);
368 /* Handle short attributes */
369 if ((type
& ISAKMP_GEN_MASK
) == ISAKMP_GEN_TV
) {
370 type
&= ~ISAKMP_GEN_MASK
;
372 plog(ASL_LEVEL_DEBUG
,
373 "Short attribute %s = %d\n",
374 s_isakmp_cfg_type(type
), ntohs(attr
->lorv
));
378 if ((error
= xauth_attr_reply(iph1
,
379 attr
, ntohs(attrpl
->id
))) != 0)
386 plog(ASL_LEVEL_WARNING
,
387 "Ignored short attribute %s\n",
388 s_isakmp_cfg_type(type
));
392 tlen
-= sizeof(*attr
);
397 type
= ntohs(attr
->type
);
398 alen
= ntohs(attr
->lorv
);
400 /* Check that the attribute fit in the packet */
403 "Short attribute %s\n",
404 s_isakmp_cfg_type(type
));
408 plog(ASL_LEVEL_DEBUG
,
409 "Attribute %s, len %zu\n",
410 s_isakmp_cfg_type(type
), alen
);
414 case XAUTH_USER_NAME
:
415 case XAUTH_USER_PASSWORD
:
418 case XAUTH_CHALLENGE
:
423 if ((error
= xauth_attr_reply(iph1
,
424 attr
, ntohs(attrpl
->id
))) != 0)
427 case INTERNAL_IP4_ADDRESS
:
428 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_GOT_ADDR4
) == 0) {
429 isakmp_cfg_getaddr4(attr
, &iph1
->mode_cfg
->addr4
);
430 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_GOT_ADDR4
;
433 case INTERNAL_IP4_NETMASK
:
434 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_GOT_MASK4
) == 0) {
435 isakmp_cfg_getaddr4(attr
, &iph1
->mode_cfg
->mask4
);
436 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_GOT_MASK4
;
439 case INTERNAL_IP4_DNS
:
440 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_GOT_DNS4
) == 0) {
441 isakmp_cfg_appendaddr4(attr
,
442 &iph1
->mode_cfg
->dns4
[iph1
->mode_cfg
->dns4_index
],
443 &iph1
->mode_cfg
->dns4_index
, MAXNS
);
444 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_GOT_DNS4
;
447 case INTERNAL_IP4_NBNS
:
448 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_GOT_WINS4
) == 0) {
449 isakmp_cfg_appendaddr4(attr
,
450 &iph1
->mode_cfg
->wins4
[iph1
->mode_cfg
->wins4_index
],
451 &iph1
->mode_cfg
->wins4_index
, MAXNS
);
452 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_GOT_WINS4
;
455 case UNITY_DEF_DOMAIN
:
456 if ((iph1
->mode_cfg
->flags
& ISAKMP_CFG_GOT_DEFAULT_DOMAIN
) == 0) {
457 isakmp_cfg_getstring(attr
,
458 iph1
->mode_cfg
->default_domain
);
459 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_GOT_DEFAULT_DOMAIN
;
462 case UNITY_SPLIT_INCLUDE
:
463 case UNITY_LOCAL_LAN
:
464 case UNITY_SPLITDNS_NAME
:
466 case UNITY_SAVE_PASSWD
:
467 case UNITY_NATT_PORT
:
469 case UNITY_BACKUP_SERVERS
:
470 case UNITY_DDNS_HOSTNAME
:
471 case APPLICATION_VERSION
:
473 isakmp_unity_reply(iph1
, attr
);
475 case INTERNAL_IP4_SUBNET
:
476 case INTERNAL_ADDRESS_EXPIRY
:
477 if (iph1
->started_by_api
)
478 break; /* not actually ignored - don't fall thru */
481 plog(ASL_LEVEL_WARNING
,
482 "Ignored attribute %s\n",
483 s_isakmp_cfg_type(type
));
488 attr
= (struct isakmp_data
*)(npp
+ sizeof(*attr
) + alen
);
489 tlen
-= (sizeof(*attr
) + alen
);
491 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_GOT_REPLY
;
493 if (iph1
->started_by_api
|| (iph1
->is_rekey
&& iph1
->parent_session
&& iph1
->parent_session
->is_client
)) {
494 /* connection was started by API - save attr list for passing to VPN controller */
495 if (iph1
->mode_cfg
->attr_list
!= NULL
) /* shouldn't happen */
496 vfree(iph1
->mode_cfg
->attr_list
);
497 if (ntohs(attrpl
->h
.len
) < sizeof(*attrpl
)) {
499 "invalid cfg-attr-list, attr-len %d\n",
500 ntohs(attrpl
->h
.len
));
503 alen
= ntohs(attrpl
->h
.len
) - sizeof(*attrpl
);
504 if ((iph1
->mode_cfg
->attr_list
= vmalloc(alen
)) == NULL
) {
506 "Cannot allocate memory for mode-cfg attribute list\n");
509 memcpy(iph1
->mode_cfg
->attr_list
->v
, attrpl
+ 1, alen
);
513 #ifdef ENABLE_VPNCONTROL_PORT
514 if (FSM_STATE_IS_ESTABLISHED(iph1
->status
))
515 vpncontrol_notify_phase_change(0, FROM_LOCAL
, iph1
, NULL
);
522 isakmp_cfg_request(iph1
, attrpl
, msg
)
523 phase1_handle_t
*iph1
;
524 struct isakmp_pl_attr
*attrpl
;
527 struct isakmp_data
*attr
;
531 vchar_t
*payload
= NULL
;
532 struct isakmp_pl_attr
*reply
;
537 tlen
= ntohs(attrpl
->h
.len
);
538 attr
= (struct isakmp_data
*)(attrpl
+ 1);
539 tlen
-= sizeof(*attrpl
);
542 * if started_by_api then we are a VPN client and if we receive
543 * a mode-cfg request it needs to go to the VPN controller to
544 * retrieve the appropriate data (name, pw, pin, etc.)
546 if (iph1
->started_by_api
|| ike_session_is_client_ph1_rekey(iph1
)) {
548 * if we already received this one - ignore it
549 * we are waiting for a reply from the vpn control socket
551 if (iph1
->xauth_awaiting_userinput
)
554 /* otherwise - save the msg id and call and send the status notification */
555 iph1
->pended_xauth_id
= attrpl
->id
; /* network byte order */
556 if (vpncontrol_notify_need_authinfo(iph1
, attrpl
+ 1, tlen
))
558 iph1
->xauth_awaiting_userinput
= 1;
559 iph1
->xauth_awaiting_userinput_msg
= vdup(msg
); // dup the message for later
560 ike_session_start_xauth_timer(iph1
);
562 IPSECLOGASLMSG("IPSec Extended Authentication requested.\n");
567 if ((payload
= vmalloc(sizeof(*reply
))) == NULL
) {
568 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
571 memset(payload
->v
, 0, sizeof(*reply
));
575 type
= ntohs(attr
->type
);
577 /* Handle short attributes */
578 if ((type
& ISAKMP_GEN_MASK
) == ISAKMP_GEN_TV
) {
579 type
&= ~ISAKMP_GEN_MASK
;
581 plog(ASL_LEVEL_DEBUG
,
582 "Short attribute %s = %d\n",
583 s_isakmp_cfg_type(type
), ntohs(attr
->lorv
));
587 reply_attr
= isakmp_xauth_req(iph1
, attr
);
590 plog(ASL_LEVEL_WARNING
,
591 "Ignored short attribute %s\n",
592 s_isakmp_cfg_type(type
));
596 tlen
-= sizeof(*attr
);
599 if (reply_attr
!= NULL
) {
600 payload
= buffer_cat(payload
, reply_attr
);
607 type
= ntohs(attr
->type
);
608 alen
= ntohs(attr
->lorv
);
610 /* Check that the attribute fit in the packet */
613 "Short attribute %s\n",
614 s_isakmp_cfg_type(type
));
618 plog(ASL_LEVEL_DEBUG
,
619 "Attribute %s, len %zu\n",
620 s_isakmp_cfg_type(type
), alen
);
623 case INTERNAL_IP4_ADDRESS
:
624 case INTERNAL_IP4_NETMASK
:
625 case INTERNAL_IP4_DNS
:
626 case INTERNAL_IP4_NBNS
:
627 case INTERNAL_IP4_SUBNET
:
628 reply_attr
= isakmp_cfg_net(iph1
, attr
);
632 case XAUTH_USER_NAME
:
633 case XAUTH_USER_PASSWORD
:
636 case XAUTH_CHALLENGE
:
641 reply_attr
= isakmp_xauth_req(iph1
, attr
);
644 case APPLICATION_VERSION
:
645 reply_attr
= isakmp_cfg_string(iph1
,
646 attr
, ISAKMP_CFG_RACOON_VERSION
);
651 case UNITY_SAVE_PASSWD
:
652 case UNITY_DEF_DOMAIN
:
653 case UNITY_DDNS_HOSTNAME
:
655 case UNITY_SPLITDNS_NAME
:
656 case UNITY_SPLIT_INCLUDE
:
657 case UNITY_LOCAL_LAN
:
658 case UNITY_NATT_PORT
:
659 case UNITY_BACKUP_SERVERS
:
660 reply_attr
= isakmp_unity_req(iph1
, attr
);
663 case INTERNAL_ADDRESS_EXPIRY
:
665 plog(ASL_LEVEL_WARNING
,
666 "Ignored attribute %s\n",
667 s_isakmp_cfg_type(type
));
672 attr
= (struct isakmp_data
*)(npp
+ sizeof(*attr
) + alen
);
673 tlen
-= (sizeof(*attr
) + alen
);
675 if (reply_attr
!= NULL
) {
676 payload
= buffer_cat(payload
, reply_attr
);
681 reply
= (struct isakmp_pl_attr
*)payload
->v
;
682 reply
->h
.len
= htons(payload
->l
);
683 reply
->type
= ISAKMP_CFG_REPLY
;
684 reply
->id
= attrpl
->id
;
686 plog(ASL_LEVEL_NOTICE
,
687 "Sending MODE_CFG REPLY\n");
689 error
= isakmp_cfg_send(iph1
, payload
,
690 ISAKMP_NPTYPE_ATTR
, ISAKMP_FLAG_E
, 0, 0, msg
);
700 isakmp_cfg_set(iph1
, attrpl
, msg
)
701 phase1_handle_t
*iph1
;
702 struct isakmp_pl_attr
*attrpl
;
705 struct isakmp_data
*attr
;
710 struct isakmp_pl_attr
*reply
;
715 if ((payload
= vmalloc(sizeof(*reply
))) == NULL
) {
716 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
719 memset(payload
->v
, 0, sizeof(*reply
));
721 tlen
= ntohs(attrpl
->h
.len
);
722 attr
= (struct isakmp_data
*)(attrpl
+ 1);
723 tlen
-= sizeof(*attrpl
);
726 * We should send ack for the attributes we accepted
730 type
= ntohs(attr
->type
);
732 plog(ASL_LEVEL_DEBUG
,
734 s_isakmp_cfg_type(type
& ~ISAKMP_GEN_MASK
));
736 switch (type
& ~ISAKMP_GEN_MASK
) {
738 reply_attr
= isakmp_xauth_set(iph1
, attr
);
741 plog(ASL_LEVEL_DEBUG
,
742 "Unexpected SET attribute %s\n",
743 s_isakmp_cfg_type(type
& ~ISAKMP_GEN_MASK
));
747 if (reply_attr
!= NULL
) {
748 payload
= buffer_cat(payload
, reply_attr
);
753 * Move to next attribute. If we run out of the packet,
754 * tlen becomes negative and we exit.
756 if ((type
& ISAKMP_GEN_MASK
) == ISAKMP_GEN_TV
) {
757 tlen
-= sizeof(*attr
);
760 alen
= ntohs(attr
->lorv
);
761 tlen
-= (sizeof(*attr
) + alen
);
763 attr
= (struct isakmp_data
*)
764 (npp
+ sizeof(*attr
) + alen
);
768 reply
= (struct isakmp_pl_attr
*)payload
->v
;
769 reply
->h
.len
= htons(payload
->l
);
770 reply
->type
= ISAKMP_CFG_ACK
;
771 reply
->id
= attrpl
->id
;
773 plog(ASL_LEVEL_NOTICE
,
774 "Sending MODE_CFG ACK\n");
776 error
= isakmp_cfg_send(iph1
, payload
,
777 ISAKMP_NPTYPE_ATTR
, ISAKMP_FLAG_E
, 0, 0, msg
);
779 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_DELETE_PH1
) {
780 if (FSM_STATE_IS_ESTABLISHED(iph1
->status
))
781 isakmp_info_send_d1(iph1
);
782 isakmp_ph1expire(iph1
);
788 * If required, request ISAKMP mode config information: ignore rekeys
790 if ((iph1
!= NULL
) && (!iph1
->is_rekey
) && (iph1
->rmconf
->mode_cfg
) && (error
== 0))
791 error
= isakmp_cfg_getconfig(iph1
);
798 buffer_cat(s
, append
)
804 new = vmalloc(s
->l
+ append
->l
);
807 "Cannot allocate memory\n");
811 memcpy(new->v
, s
->v
, s
->l
);
812 memcpy(new->v
+ s
->l
, append
->v
, append
->l
);
819 isakmp_cfg_net(iph1
, attr
)
820 phase1_handle_t
*iph1
;
821 struct isakmp_data
*attr
;
826 type
= ntohs(attr
->type
);
829 * Don't give an address to a peer that did not succeed Xauth
831 if (xauth_check(iph1
) != 0) {
833 "Attempt to start phase config whereas Xauth failed\n");
837 confsource
= isakmp_cfg_config
.confsource
;
839 * If we have to fall back to a local
840 * configuration source, we will jump
841 * back to this point.
845 case INTERNAL_IP4_ADDRESS
:
847 case ISAKMP_CFG_CONF_LOCAL
:
848 if (isakmp_cfg_getport(iph1
) == -1) {
850 "Port pool depleted\n");
854 iph1
->mode_cfg
->addr4
.s_addr
=
855 htonl(ntohl(isakmp_cfg_config
.network4
)
856 + iph1
->mode_cfg
->port
);
857 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_ADDR4_LOCAL
;
862 "Unexpected confsource\n");
865 return isakmp_cfg_addr4(iph1
,
866 attr
, &iph1
->mode_cfg
->addr4
.s_addr
);
869 case INTERNAL_IP4_NETMASK
:
871 case ISAKMP_CFG_CONF_LOCAL
:
872 iph1
->mode_cfg
->mask4
.s_addr
873 = isakmp_cfg_config
.netmask4
;
874 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_MASK4_LOCAL
;
879 "Unexpected confsource\n");
881 return isakmp_cfg_addr4(iph1
, attr
,
882 &iph1
->mode_cfg
->mask4
.s_addr
);
885 case INTERNAL_IP4_DNS
:
886 return isakmp_cfg_addr4_list(iph1
,
887 attr
, &isakmp_cfg_config
.dns4
[0],
888 isakmp_cfg_config
.dns4_index
);
891 case INTERNAL_IP4_NBNS
:
892 return isakmp_cfg_addr4_list(iph1
,
893 attr
, &isakmp_cfg_config
.nbns4
[0],
894 isakmp_cfg_config
.nbns4_index
);
897 case INTERNAL_IP4_SUBNET
:
898 return isakmp_cfg_addr4(iph1
,
899 attr
, &isakmp_cfg_config
.network4
);
903 plog(ASL_LEVEL_ERR
, "Unexpected type %d\n", type
);
911 isakmp_cfg_void(iph1
, attr
)
912 phase1_handle_t
*iph1
;
913 struct isakmp_data
*attr
;
916 struct isakmp_data
*new;
918 if ((buffer
= vmalloc(sizeof(*attr
))) == NULL
) {
919 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
923 new = (struct isakmp_data
*)buffer
->v
;
925 new->type
= attr
->type
;
926 new->lorv
= htons(0);
933 isakmp_cfg_copy(iph1
, attr
)
934 phase1_handle_t
*iph1
;
935 struct isakmp_data
*attr
;
940 if ((ntohs(attr
->type
) & ISAKMP_GEN_MASK
) == ISAKMP_GEN_TLV
)
941 len
= ntohs(attr
->lorv
);
943 if ((buffer
= vmalloc(sizeof(*attr
) + len
)) == NULL
) {
944 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
948 memcpy(buffer
->v
, attr
, sizeof(*attr
) + ntohs(attr
->lorv
));
954 isakmp_cfg_short(iph1
, attr
, value
)
955 phase1_handle_t
*iph1
;
956 struct isakmp_data
*attr
;
960 struct isakmp_data
*new;
963 if ((buffer
= vmalloc(sizeof(*attr
))) == NULL
) {
964 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
968 new = (struct isakmp_data
*)buffer
->v
;
969 type
= ntohs(attr
->type
) & ~ISAKMP_GEN_MASK
;
971 new->type
= htons(type
| ISAKMP_GEN_TV
);
972 new->lorv
= htons(value
);
978 isakmp_cfg_varlen(iph1
, attr
, string
, len
)
979 phase1_handle_t
*iph1
;
980 struct isakmp_data
*attr
;
985 struct isakmp_data
*new;
988 if ((buffer
= vmalloc(sizeof(*attr
) + len
)) == NULL
) {
989 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
993 new = (struct isakmp_data
*)buffer
->v
;
995 new->type
= attr
->type
;
996 new->lorv
= htons(len
);
997 data
= (char *)(new + 1);
999 memcpy(data
, string
, len
);
1004 isakmp_cfg_string(iph1
, attr
, string
)
1005 phase1_handle_t
*iph1
;
1006 struct isakmp_data
*attr
;
1009 size_t len
= strlen(string
);
1010 return isakmp_cfg_varlen(iph1
, attr
, string
, len
);
1014 isakmp_cfg_addr4(iph1
, attr
, addr
)
1015 phase1_handle_t
*iph1
;
1016 struct isakmp_data
*attr
;
1020 struct isakmp_data
*new;
1023 len
= sizeof(*addr
);
1024 if ((buffer
= vmalloc(sizeof(*attr
) + len
)) == NULL
) {
1025 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
1029 new = (struct isakmp_data
*)buffer
->v
;
1031 new->type
= attr
->type
;
1032 new->lorv
= htons(len
);
1033 memcpy(new + 1, addr
, len
);
1039 isakmp_cfg_addr4_list(iph1
, attr
, addr
, nbr
)
1040 phase1_handle_t
*iph1
;
1041 struct isakmp_data
*attr
;
1046 vchar_t
*buffer
= NULL
;
1047 vchar_t
*bufone
= NULL
;
1048 struct isakmp_data
*new;
1052 len
= sizeof(*addr
);
1053 if ((buffer
= vmalloc(0)) == NULL
) {
1054 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
1057 for(i
= 0; i
< nbr
; i
++) {
1058 if ((bufone
= vmalloc(sizeof(*attr
) + len
)) == NULL
) {
1060 "Cannot allocate memory\n");
1063 new = (struct isakmp_data
*)bufone
->v
;
1064 new->type
= attr
->type
;
1065 new->lorv
= htons(len
);
1066 memcpy(new + 1, &addr
[i
], len
);
1067 new += (len
+ sizeof(*attr
));
1068 buffer
= buffer_cat(buffer
, bufone
);
1075 if ((error
!= 0) && (buffer
!= NULL
)) {
1084 isakmp_cfg_newiv(iph1
, msgid
)
1085 phase1_handle_t
*iph1
;
1088 struct isakmp_cfg_state
*ics
= iph1
->mode_cfg
;
1092 "isakmp_cfg_newiv called without mode config state\n");
1096 if (ics
->ivm
!= NULL
)
1097 oakley_delivm(ics
->ivm
);
1099 ics
->ivm
= oakley_newiv2(iph1
, msgid
);
1100 ics
->last_msgid
= msgid
;
1105 /* Derived from isakmp_info_send_common */
1107 isakmp_cfg_send(iph1
, payload
, np
, flags
, new_exchange
, retry_count
, msg
)
1108 phase1_handle_t
*iph1
;
1116 phase2_handle_t
*iph2
= NULL
;
1117 vchar_t
*hash
= NULL
;
1118 struct isakmp
*isakmp
;
1119 struct isakmp_gen
*gen
;
1123 struct isakmp_cfg_state
*ics
= iph1
->mode_cfg
;
1125 /* Check if phase 1 is established */
1126 if ((!FSM_STATE_IS_ESTABLISHED(iph1
->status
)) ||
1127 (iph1
->local
== NULL
) ||
1128 (iph1
->remote
== NULL
)) {
1130 "ISAKMP mode config exchange with immature phase 1\n");
1134 /* add new entry to isakmp status table */
1135 iph2
= ike_session_newph2(ISAKMP_VERSION_NUMBER_IKEV1
, PHASE2_TYPE_CFG
);
1138 "failed to allocate ph2");
1142 iph2
->dst
= dupsaddr(iph1
->remote
);
1143 if (iph2
->dst
== NULL
) {
1145 "failed to duplicate remote address");
1146 ike_session_delph2(iph2
);
1149 iph2
->src
= dupsaddr(iph1
->local
);
1150 if (iph2
->src
== NULL
) {
1152 "failed to duplicate local address");
1153 ike_session_delph2(iph2
);
1157 switch (iph1
->remote
->ss_family
) {
1159 #if (!defined(ENABLE_NATT)) || (defined(BROKEN_NATT))
1160 ((struct sockaddr_in
*)iph2
->dst
)->sin_port
= 0;
1161 ((struct sockaddr_in
*)iph2
->src
)->sin_port
= 0;
1166 #if (!defined(ENABLE_NATT)) || (defined(BROKEN_NATT))
1167 ((struct sockaddr_in6
*)iph2
->dst
)->sin6_port
= 0;
1168 ((struct sockaddr_in6
*)iph2
->src
)->sin6_port
= 0;
1174 "invalid family: %d\n", iph1
->remote
->ss_family
);
1175 ike_session_delph2(iph2
);
1178 iph2
->side
= INITIATOR
;
1179 fsm_set_state(&iph2
->status
, IKEV1_STATE_INFO
);
1182 iph2
->msgid
= isakmp_newmsgid2(iph1
);
1184 iph2
->msgid
= iph1
->msgid
;
1186 /* get IV and HASH(1) if skeyid_a was generated. */
1187 if (iph1
->skeyid_a
!= NULL
) {
1189 if (isakmp_cfg_newiv(iph1
, iph2
->msgid
) == NULL
) {
1191 "failed to generate IV");
1192 ike_session_delph2(iph2
);
1197 /* generate HASH(1) */
1198 hash
= oakley_compute_hash1(iph1
, iph2
->msgid
, payload
);
1201 "failed to generate HASH");
1202 ike_session_delph2(iph2
);
1206 /* initialized total buffer length */
1208 tlen
+= sizeof(*gen
);
1210 /* IKE-SA is not established */
1213 /* initialized total buffer length */
1216 if ((flags
& ISAKMP_FLAG_A
) == 0)
1217 iph2
->flags
= (hash
== NULL
? 0 : ISAKMP_FLAG_E
);
1219 iph2
->flags
= (hash
== NULL
? 0 : ISAKMP_FLAG_A
);
1221 ike_session_link_ph2_to_ph1(iph1
, iph2
);
1223 tlen
+= sizeof(*isakmp
) + payload
->l
;
1225 /* create buffer for isakmp payload */
1226 iph2
->sendbuf
= vmalloc(tlen
);
1227 if (iph2
->sendbuf
== NULL
) {
1229 "failed to get buffer to send.\n");
1233 /* create isakmp header */
1234 isakmp
= (struct isakmp
*)iph2
->sendbuf
->v
;
1235 memcpy(&isakmp
->i_ck
, &iph1
->index
.i_ck
, sizeof(cookie_t
));
1236 memcpy(&isakmp
->r_ck
, &iph1
->index
.r_ck
, sizeof(cookie_t
));
1237 isakmp
->np
= hash
== NULL
? (np
& 0xff) : ISAKMP_NPTYPE_HASH
;
1238 isakmp
->v
= iph1
->version
;
1239 isakmp
->etype
= ISAKMP_ETYPE_CFG
;
1240 isakmp
->flags
= iph2
->flags
;
1241 memcpy(&isakmp
->msgid
, &iph2
->msgid
, sizeof(isakmp
->msgid
));
1242 isakmp
->len
= htonl(tlen
);
1243 p
= (char *)(isakmp
+ 1);
1245 /* create HASH payload */
1247 gen
= (struct isakmp_gen
*)p
;
1248 gen
->np
= np
& 0xff;
1249 gen
->len
= htons(sizeof(*gen
) + hash
->l
);
1251 memcpy(p
, hash
->v
, hash
->l
);
1256 memcpy(p
, payload
->v
, payload
->l
);
1259 #ifdef HAVE_PRINT_ISAKMP_C
1260 isakmp_printpacket(iph2
->sendbuf
, iph1
->local
, iph1
->remote
, 1);
1263 plog(ASL_LEVEL_NOTICE
, "MODE_CFG packet to send\n");
1266 if (ISSET(isakmp
->flags
, ISAKMP_FLAG_E
)) {
1269 tmp
= oakley_do_encrypt(iph1
, iph2
->sendbuf
,
1270 ics
->ivm
->ive
, ics
->ivm
->iv
);
1271 VPTRINIT(iph2
->sendbuf
);
1274 "failed to encrypt packet");
1277 iph2
->sendbuf
= tmp
;
1280 /* HDR*, HASH(1), ATTR */
1282 if (retry_count
> 0) {
1283 iph2
->retry_counter
= retry_count
;
1284 if (isakmp_ph2resend(iph2
) < 0) {
1286 "failed to resend packet");
1287 VPTRINIT(iph2
->sendbuf
);
1290 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1291 IPSECSESSIONEVENTCODE_IKEV1_CFG_RETRANSMIT
,
1292 CONSTSTR("Mode-Config retransmit"),
1298 if (isakmp_send(iph2
->ph1
, iph2
->sendbuf
) < 0) {
1300 "failed to send packet");
1301 VPTRINIT(iph2
->sendbuf
);
1305 /* the sending message is added to the received-list. */
1306 if (ike_session_add_recvdpkt(iph1
->remote
, iph1
->local
, iph2
->sendbuf
, msg
,
1307 PH2_NON_ESP_EXTRA_LEN(iph2
, iph2
->sendbuf
), PH1_FRAG_FLAGS(iph1
)) == -1) {
1308 plog(ASL_LEVEL_ERR
,
1309 "failed to add a response packet to the tree.\n");
1313 plog(ASL_LEVEL_NOTICE
,
1314 "sendto mode config %s.\n", s_isakmp_nptype(np
));
1317 * XXX We might need to resend the message...
1321 VPTRINIT(iph2
->sendbuf
);
1323 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1324 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_SUCC
,
1325 CONSTSTR("Mode-Config message"),
1330 IPSECSESSIONTRACEREVENT(iph1
->parent_session
,
1331 IPSECSESSIONEVENTCODE_IKE_PACKET_TX_FAIL
,
1332 CONSTSTR("Mode-Config message"),
1333 CONSTSTR("Failed to transmit Mode-Config message"));
1335 ike_session_unlink_phase2(iph2
);
1344 isakmp_cfg_rmstate(phase1_handle_t
*iph1
)
1346 struct isakmp_cfg_state
**state
= &iph1
->mode_cfg
;
1351 if ((*state
)->flags
& ISAKMP_CFG_PORT_ALLOCATED
)
1352 isakmp_cfg_putport(iph1
, (*state
)->port
);
1354 /* Delete the IV if it's still there */
1356 oakley_delivm((*state
)->ivm
);
1357 (*state
)->ivm
= NULL
;
1360 /* Free any allocated splitnet lists */
1361 if((*state
)->split_include
!= NULL
)
1362 splitnet_list_free((*state
)->split_include
,
1363 &(*state
)->include_count
);
1364 if((*state
)->split_local
!= NULL
)
1365 splitnet_list_free((*state
)->split_local
,
1366 &(*state
)->local_count
);
1368 xauth_rmstate(&(*state
)->xauth
);
1370 if ((*state
)->attr_list
)
1371 vfree((*state
)->attr_list
);
1373 racoon_free((*state
));
1379 struct isakmp_cfg_state
*
1380 isakmp_cfg_mkstate(void)
1382 struct isakmp_cfg_state
*state
;
1384 if ((state
= racoon_malloc(sizeof(*state
))) == NULL
) {
1386 "Cannot allocate memory for mode config state\n");
1389 memset(state
, 0, sizeof(*state
));
1395 isakmp_cfg_getport(iph1
)
1396 phase1_handle_t
*iph1
;
1399 size_t size
= isakmp_cfg_config
.pool_size
;
1401 if (iph1
->mode_cfg
->flags
& ISAKMP_CFG_PORT_ALLOCATED
)
1402 return iph1
->mode_cfg
->port
;
1404 if (isakmp_cfg_config
.port_pool
== NULL
) {
1406 "isakmp_cfg_config.port_pool == NULL\n");
1410 for (i
= 0; i
< size
; i
++) {
1411 if (isakmp_cfg_config
.port_pool
[i
].used
== 0)
1417 "No more addresses available\n");
1421 isakmp_cfg_config
.port_pool
[i
].used
= 1;
1423 plog(ASL_LEVEL_NOTICE
, "Using port %d\n", i
);
1425 iph1
->mode_cfg
->flags
|= ISAKMP_CFG_PORT_ALLOCATED
;
1426 iph1
->mode_cfg
->port
= i
;
1432 isakmp_cfg_putport(iph1
, index
)
1433 phase1_handle_t
*iph1
;
1436 if (isakmp_cfg_config
.port_pool
== NULL
) {
1438 "isakmp_cfg_config.port_pool == NULL\n");
1442 if (isakmp_cfg_config
.port_pool
[index
].used
== 0) {
1444 "Attempt to release an unallocated address (port %d)\n",
1449 isakmp_cfg_config
.port_pool
[index
].used
= 0;
1450 iph1
->mode_cfg
->flags
&= ISAKMP_CFG_PORT_ALLOCATED
;
1452 plog(ASL_LEVEL_NOTICE
, "Released port %d\n", index
);
1459 isakmp_cfg_getconfig(iph1
)
1460 phase1_handle_t
*iph1
;
1463 struct isakmp_pl_attr
*attrpl
;
1464 struct isakmp_data
*attr
;
1466 vchar_t
*version
= NULL
;
1471 INTERNAL_IP4_ADDRESS
,
1472 INTERNAL_IP4_NETMASK
,
1475 INTERNAL_ADDRESS_EXPIRY
,
1476 APPLICATION_VERSION
,
1479 UNITY_SPLITDNS_NAME
,
1480 UNITY_SPLIT_INCLUDE
,
1484 attrcount
= sizeof(attrlist
) / sizeof(*attrlist
);
1485 len
= sizeof(*attrpl
) + sizeof(*attr
) * attrcount
;
1487 if (iph1
->started_by_api
) {
1488 if (iph1
->remote
->ss_family
== AF_INET
) {
1489 struct vpnctl_socket_elem
*sock_elem
;
1490 struct bound_addr
*bound_addr
;
1493 address
= ((struct sockaddr_in
*)iph1
->remote
)->sin_addr
.s_addr
;
1494 LIST_FOREACH(sock_elem
, &lcconf
->vpnctl_comm_socks
, chain
) {
1495 LIST_FOREACH(bound_addr
, &sock_elem
->bound_addresses
, chain
) {
1496 if (bound_addr
->address
== address
) {
1497 if ((version
= bound_addr
->version
))
1498 len
+= bound_addr
->version
->l
;
1506 if ((buffer
= vmalloc(len
)) == NULL
) {
1507 plog(ASL_LEVEL_ERR
, "Cannot allocate memory\n");
1511 attrpl
= (struct isakmp_pl_attr
*)buffer
->v
;
1512 attrpl
->h
.len
= htons(len
);
1513 attrpl
->type
= ISAKMP_CFG_REQUEST
;
1514 attrpl
->id
= htons((u_int16_t
)(eay_random() & 0xffff));
1516 attr
= (struct isakmp_data
*)(attrpl
+ 1);
1518 for (i
= 0; i
< attrcount
; i
++) {
1519 switch (attrlist
[i
]) {
1520 case APPLICATION_VERSION
:
1522 attr
->type
= htons(attrlist
[i
]);
1523 attr
->lorv
= htons(version
->l
);
1524 memcpy(attr
+ 1, version
->v
, version
->l
);
1525 attr
= (struct isakmp_data
*)(((char *)(attr
+ 1)) + version
->l
);
1527 } else /* fall thru */;
1529 attr
->type
= htons(attrlist
[i
]);
1530 attr
->lorv
= htons(0);
1536 plog(ASL_LEVEL_NOTICE
,
1537 "Sending MODE_CFG REQUEST\n");
1539 error
= isakmp_cfg_send(iph1
, buffer
,
1540 ISAKMP_NPTYPE_ATTR
, ISAKMP_FLAG_E
, 1, iph1
->rmconf
->retry_counter
, NULL
);
1544 IPSECLOGASLMSG("IPSec Network Configuration requested.\n");
1550 isakmp_cfg_getaddr4(attr
, ip
)
1551 struct isakmp_data
*attr
;
1554 size_t alen
= ntohs(attr
->lorv
);
1557 if (alen
!= sizeof(*ip
)) {
1558 plog(ASL_LEVEL_ERR
, "Bad IPv4 address len\n");
1562 addr
= ALIGNED_CAST(in_addr_t
*)(attr
+ 1); // Wcast-align fix (void*) - attr comes from packet data in a vchar_t
1569 isakmp_cfg_appendaddr4(attr
, ip
, num
, max
)
1570 struct isakmp_data
*attr
;
1575 size_t alen
= ntohs(attr
->lorv
);
1578 if (alen
!= sizeof(*ip
)) {
1579 plog(ASL_LEVEL_ERR
, "Bad IPv4 address len\n");
1583 plog(ASL_LEVEL_ERR
, "Too many addresses given\n");
1587 addr
= ALIGNED_CAST(in_addr_t
*)(attr
+ 1); // Wcast-align fix (void*) - attr comes from packet data in a vchar_t
1595 isakmp_cfg_getstring(attr
, str
)
1596 struct isakmp_data
*attr
;
1599 size_t alen
= ntohs(attr
->lorv
);
1601 src
= (char *)(attr
+ 1);
1603 memcpy(str
, src
, (alen
> MAXPATHLEN
? MAXPATHLEN
: alen
));
1611 isakmp_cfg_iplist_to_str(dest
, count
, addr
, withmask
)
1620 struct unity_network tmp
;
1621 for(i
= 0, p
= 0; i
< count
; i
++) {
1623 l
= sizeof(struct unity_network
);
1625 l
= sizeof(struct in_addr
);
1626 memcpy(&tmp
, addr
, l
);
1628 if((uint32_t)tmp
.addr4
.s_addr
== 0)
1631 inet_ntop(AF_INET
, &tmp
.addr4
, dest
+ p
, IP_MAX
);
1632 p
+= strlen(dest
+ p
);
1636 inet_ntop(AF_INET
, &tmp
.mask4
, dest
+ p
, IP_MAX
);
1637 p
+= strlen(dest
+ p
);
1649 isakmp_cfg_resize_pool(size
)
1652 struct isakmp_cfg_port
*new_pool
;
1656 if (size
== isakmp_cfg_config
.pool_size
)
1659 plog(ASL_LEVEL_NOTICE
,
1660 "Resize address pool from %zu to %d\n",
1661 isakmp_cfg_config
.pool_size
, size
);
1663 /* If a pool already exists, check if we can shrink it */
1664 if ((isakmp_cfg_config
.port_pool
!= NULL
) &&
1665 (size
< isakmp_cfg_config
.pool_size
)) {
1666 for (i
= isakmp_cfg_config
.pool_size
-1; i
>= size
; --i
) {
1667 if (isakmp_cfg_config
.port_pool
[i
].used
) {
1669 "resize pool from %zu to %d impossible "
1670 "port %d is in use\n",
1671 isakmp_cfg_config
.pool_size
, size
, i
);
1678 len
= size
* sizeof(*isakmp_cfg_config
.port_pool
);
1679 new_pool
= racoon_realloc(isakmp_cfg_config
.port_pool
, len
);
1680 if (new_pool
== NULL
) {
1682 "resize pool from %zu to %d impossible: %s",
1683 isakmp_cfg_config
.pool_size
, size
, strerror(errno
));
1687 /* If size increase, intialize correctly the new records */
1688 if (size
> isakmp_cfg_config
.pool_size
) {
1692 unit
= sizeof(*isakmp_cfg_config
.port_pool
);
1693 old_size
= isakmp_cfg_config
.pool_size
;
1695 bzero((char *)new_pool
+ (old_size
* unit
),
1696 (size
- old_size
) * unit
);
1699 isakmp_cfg_config
.port_pool
= new_pool
;
1700 isakmp_cfg_config
.pool_size
= size
;
1706 isakmp_cfg_init(cold
)
1714 isakmp_cfg_config
.network4
= (in_addr_t
)0x00000000;
1715 isakmp_cfg_config
.netmask4
= (in_addr_t
)0x00000000;
1716 for (i
= 0; i
< MAXNS
; i
++)
1717 isakmp_cfg_config
.dns4
[i
] = (in_addr_t
)0x00000000;
1718 isakmp_cfg_config
.dns4_index
= 0;
1719 for (i
= 0; i
< MAXWINS
; i
++)
1720 isakmp_cfg_config
.nbns4
[i
] = (in_addr_t
)0x00000000;
1721 isakmp_cfg_config
.nbns4_index
= 0;
1722 if (cold
!= ISAKMP_CFG_INIT_COLD
) {
1723 if (isakmp_cfg_config
.port_pool
) {
1724 racoon_free(isakmp_cfg_config
.port_pool
);
1727 isakmp_cfg_config
.port_pool
= NULL
;
1728 isakmp_cfg_config
.pool_size
= 0;
1729 isakmp_cfg_config
.authsource
= ISAKMP_CFG_AUTH_SYSTEM
;
1730 isakmp_cfg_config
.groupsource
= ISAKMP_CFG_GROUP_SYSTEM
;
1731 if (cold
!= ISAKMP_CFG_INIT_COLD
) {
1732 if (isakmp_cfg_config
.grouplist
!= NULL
) {
1733 for (i
= 0; i
< isakmp_cfg_config
.groupcount
; i
++)
1734 racoon_free(isakmp_cfg_config
.grouplist
[i
]);
1735 racoon_free(isakmp_cfg_config
.grouplist
);
1738 isakmp_cfg_config
.grouplist
= NULL
;
1739 isakmp_cfg_config
.groupcount
= 0;
1740 isakmp_cfg_config
.confsource
= ISAKMP_CFG_CONF_LOCAL
;
1741 isakmp_cfg_config
.accounting
= ISAKMP_CFG_ACCT_NONE
;
1742 isakmp_cfg_config
.auth_throttle
= THROTTLE_PENALTY
;
1743 strlcpy(isakmp_cfg_config
.default_domain
, ISAKMP_CFG_DEFAULT_DOMAIN
,
1744 sizeof(isakmp_cfg_config
.default_domain
));
1745 strlcpy(isakmp_cfg_config
.motd
, ISAKMP_CFG_MOTD
, sizeof(isakmp_cfg_config
.motd
));
1747 if (cold
!= ISAKMP_CFG_INIT_COLD
)
1748 if (isakmp_cfg_config
.splitnet_list
!= NULL
)
1749 splitnet_list_free(isakmp_cfg_config
.splitnet_list
,
1750 &isakmp_cfg_config
.splitnet_count
);
1751 isakmp_cfg_config
.splitnet_list
= NULL
;
1752 isakmp_cfg_config
.splitnet_count
= 0;
1753 isakmp_cfg_config
.splitnet_type
= 0;
1755 isakmp_cfg_config
.pfs_group
= 0;
1756 isakmp_cfg_config
.save_passwd
= 0;
1758 if (cold
!= ISAKMP_CFG_INIT_COLD
)
1759 if (isakmp_cfg_config
.splitdns_list
!= NULL
)
1760 racoon_free(isakmp_cfg_config
.splitdns_list
);
1761 isakmp_cfg_config
.splitdns_list
= NULL
;
1762 isakmp_cfg_config
.splitdns_len
= 0;
1765 if (cold
== ISAKMP_CFG_INIT_COLD
) {
1766 if ((error
= isakmp_cfg_resize_pool(ISAKMP_CFG_MAX_CNX
)) != 0)