1 /* $KAME: isakmp.c,v 1.176 2002/08/28 04:08:30 itojun 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 <netkey/key_var.h>
38 #include <netinet/in.h>
44 #if TIME_WITH_SYS_TIME
45 # include <sys/time.h>
49 # include <sys/time.h>
60 #if !defined(HAVE_GETADDRINFO) || !defined(HAVE_GETNAMEINFO)
72 #include "remoteconf.h"
73 #include "localconf.h"
74 #include "grabmyaddr.h"
75 #include "isakmp_var.h"
79 #include "ipsec_doi.h"
81 #include "crypto_openssl.h"
83 #include "isakmp_ident.h"
84 #include "isakmp_agg.h"
85 #include "isakmp_base.h"
86 #include "isakmp_quick.h"
87 #include "isakmp_inf.h"
88 #include "isakmp_newg.h"
90 #ifndef HAVE_ARC4RANDOM
91 #include "arc4random.h"
94 static int nostate1
__P((struct ph1handle
*, vchar_t
*));
95 static int nostate2
__P((struct ph2handle
*, vchar_t
*));
97 extern caddr_t
val2str(const char *, size_t);
99 static int (*ph1exchange
[][2][PHASE1ST_MAX
])
100 __P((struct ph1handle
*, vchar_t
*)) = {
103 /* Identity Protection exchange */
105 { nostate1
, ident_i1send
, nostate1
, ident_i2recv
, ident_i2send
,
106 ident_i3recv
, ident_i3send
, ident_i4recv
, ident_i4send
, nostate1
, },
107 { nostate1
, ident_r1recv
, ident_r1send
, ident_r2recv
, ident_r2send
,
108 ident_r3recv
, ident_r3send
, nostate1
, nostate1
, nostate1
, },
110 /* Aggressive exchange */
112 { nostate1
, agg_i1send
, nostate1
, agg_i2recv
, agg_i2send
,
113 nostate1
, nostate1
, nostate1
, nostate1
, nostate1
, },
114 { nostate1
, agg_r1recv
, agg_r1send
, agg_r2recv
, agg_r2send
,
115 nostate1
, nostate1
, nostate1
, nostate1
, nostate1
, },
119 { nostate1
, base_i1send
, nostate1
, base_i2recv
, base_i2send
,
120 base_i3recv
, base_i3send
, nostate1
, nostate1
, nostate1
, },
121 { nostate1
, base_r1recv
, base_r1send
, base_r2recv
, base_r2send
,
122 nostate1
, nostate1
, nostate1
, nostate1
, nostate1
, },
126 static int (*ph2exchange
[][2][PHASE2ST_MAX
])
127 __P((struct ph2handle
*, vchar_t
*)) = {
130 /* Quick mode for IKE*/
132 { nostate2
, nostate2
, quick_i1prep
, nostate2
, quick_i1send
,
133 quick_i2recv
, quick_i2send
, quick_i3recv
, nostate2
, nostate2
, },
134 { nostate2
, quick_r1recv
, quick_r1prep
, nostate2
, quick_r2send
,
135 quick_r3recv
, quick_r3prep
, quick_r3send
, nostate2
, nostate2
, }
139 static u_char r_ck0
[] = { 0,0,0,0,0,0,0,0 }; /* used to verify the r_ck. */
141 static int isakmp_main
__P((vchar_t
*, struct sockaddr
*, struct sockaddr
*));
142 static int ph1_main
__P((struct ph1handle
*, vchar_t
*));
143 static int quick_main
__P((struct ph2handle
*, vchar_t
*));
144 static int isakmp_ph1begin_r
__P((vchar_t
*,
145 struct sockaddr
*, struct sockaddr
*, u_int8_t
));
146 static int isakmp_ph2begin_i
__P((struct ph1handle
*, struct ph2handle
*));
147 static int isakmp_ph2begin_r
__P((struct ph1handle
*, vchar_t
*));
148 static int etypesw1
__P((int));
149 static int etypesw2
__P((int));
152 * isakmp packet handler
155 isakmp_handler(so_isakmp
)
158 struct isakmp isakmp
;
159 struct sockaddr_storage remote
;
160 struct sockaddr_storage local
;
161 int remote_len
= sizeof(remote
);
162 int local_len
= sizeof(local
);
168 /* read message by MSG_PEEK */
169 while ((len
= recvfromto(so_isakmp
, (char *)&isakmp
, sizeof(isakmp
),
170 MSG_PEEK
, (struct sockaddr
*)&remote
, &remote_len
,
171 (struct sockaddr
*)&local
, &local_len
)) < 0) {
174 plog(LLV_ERROR
, LOCATION
, NULL
,
175 "failed to receive isakmp packet\n");
179 /* check isakmp header length, as well as sanity of header length */
180 if (len
< sizeof(isakmp
) || ntohl(isakmp
.len
) < sizeof(isakmp
)) {
181 plog(LLV_ERROR
, LOCATION
, (struct sockaddr
*)&remote
,
182 "packet shorter than isakmp header size.\n");
184 if ((len
= recvfrom(so_isakmp
, (char *)&isakmp
, sizeof(isakmp
),
185 0, (struct sockaddr
*)&remote
, &remote_len
)) < 0) {
186 plog(LLV_ERROR
, LOCATION
, NULL
,
187 "failed to receive isakmp packet\n");
192 /* read real message */
193 if ((buf
= vmalloc(ntohl(isakmp
.len
))) == NULL
) {
194 plog(LLV_ERROR
, LOCATION
, NULL
,
195 "failed to allocate reading buffer\n");
197 if ((len
= recvfrom(so_isakmp
, (char *)&isakmp
, sizeof(isakmp
),
198 0, (struct sockaddr
*)&remote
, &remote_len
)) < 0) {
199 plog(LLV_ERROR
, LOCATION
, NULL
,
200 "failed to receive isakmp packet\n");
205 while ((len
= recvfromto(so_isakmp
, buf
->v
, buf
->l
,
206 0, (struct sockaddr
*)&remote
, &remote_len
,
207 (struct sockaddr
*)&local
, &local_len
)) < 0) {
210 plog(LLV_ERROR
, LOCATION
, NULL
,
211 "failed to receive isakmp packet\n");
216 plog(LLV_ERROR
, LOCATION
, (struct sockaddr
*)&remote
,
217 "received invalid length, why ?\n");
221 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
222 plog(LLV_DEBUG
, LOCATION
, (struct sockaddr
*)&local
,
223 "%d bytes message received from %s\n",
224 len
, saddr2str((struct sockaddr
*)&remote
));
225 plogdump(LLV_DEBUG
, buf
->v
, buf
->l
);
227 /* avoid packets with malicious port/address */
228 switch (remote
.ss_family
) {
230 port
= ((struct sockaddr_in
*)&remote
)->sin_port
;
234 port
= ((struct sockaddr_in6
*)&remote
)->sin6_port
;
238 plog(LLV_ERROR
, LOCATION
, NULL
,
239 "invalid family: %d\n", remote
.ss_family
);
243 plog(LLV_ERROR
, LOCATION
, (struct sockaddr
*)&remote
,
244 "src port == 0 (valid as UDP but not with IKE)\n");
248 /* XXX: check sender whether to be allowed or not to accept */
250 /* XXX: I don't know how to check isakmp half connection attack. */
252 /* simply reply if the packet was processed. */
253 if (check_recvdpkt((struct sockaddr
*)&remote
,
254 (struct sockaddr
*)&local
, buf
)) {
255 plog(LLV_NOTIFY
, LOCATION
, NULL
,
256 "the packet is retransmitted by %s.\n",
257 saddr2str((struct sockaddr
*)&remote
));
262 /* isakmp main routine */
263 if (isakmp_main(buf
, (struct sockaddr
*)&remote
,
264 (struct sockaddr
*)&local
) != 0) goto end
;
277 * isakmp packet handler for natt port (4500)
280 isakmp_natt_handler(so_isakmp
)
283 u_char temp_buffer
[sizeof(struct isakmp
) + 4];
284 struct isakmp
*isakmp
= (struct isakmp
*)(temp_buffer
+ 4);
285 struct sockaddr_storage remote
;
286 struct sockaddr_storage local
;
287 int remote_len
= sizeof(remote
);
288 int local_len
= sizeof(local
);
294 /* read message by MSG_PEEK */
295 while ((len
= recvfromto(so_isakmp
, temp_buffer
, sizeof(temp_buffer
),
296 MSG_PEEK
, (struct sockaddr
*)&remote
, &remote_len
,
297 (struct sockaddr
*)&local
, &local_len
)) < 0) {
300 plog(LLV_ERROR
, LOCATION
, NULL
,
301 "failed to receive isakmp packet\n");
305 /* remove the four bytes of zeros on nat traversal port */
306 if (*(u_long
*)temp_buffer
!= 0L)
309 * This is a UDP encapsulated IPSec packet,
312 * TBD: Need a way to read the packet.
313 * The kernel intercepts these packets on Mac OS X
314 * but not all kernels will handle this the same way.
319 /* check isakmp header length */
320 if (len
< sizeof(temp_buffer
)) {
321 plog(LLV_ERROR
, LOCATION
, (struct sockaddr
*)&remote
,
322 "packet shorter than isakmp header size.\n");
324 if ((len
= recvfrom(so_isakmp
, (char *)temp_buffer
, sizeof(temp_buffer
),
325 0, (struct sockaddr
*)&remote
, &remote_len
)) < 0) {
326 plog(LLV_ERROR
, LOCATION
, NULL
,
327 "failed to receive isakmp packet\n");
332 /* read real message */
333 if ((buf
= vmalloc(ntohl(isakmp
->len
) + 4)) == NULL
) {
334 plog(LLV_ERROR
, LOCATION
, NULL
,
335 "failed to allocate reading buffer\n");
337 if ((len
= recvfrom(so_isakmp
, (char *)temp_buffer
, sizeof(temp_buffer
),
338 0, (struct sockaddr
*)&remote
, &remote_len
)) < 0) {
339 plog(LLV_ERROR
, LOCATION
, NULL
,
340 "failed to receive isakmp packet\n");
345 while ((len
= recvfromto(so_isakmp
, buf
->v
, buf
->l
,
346 0, (struct sockaddr
*)&remote
, &remote_len
,
347 (struct sockaddr
*)&local
, &local_len
)) < 0) {
350 plog(LLV_ERROR
, LOCATION
, NULL
,
351 "failed to receive isakmp packet\n");
356 plog(LLV_ERROR
, LOCATION
, (struct sockaddr
*)&remote
,
357 "received invalid length, header says %d, packet is %d bytes why ?\n",
363 * Discard first 4 bytes, they're either:
364 * 0 - this is IKE traffic
365 * !0 - first four bytes are the SPI of a UDP encapsulated IPSec packet
366 * The seond type of packet should be interecepted by the kernel
367 * or dropped before we get to this point.
370 vchar_t
*newbuf
= vmalloc(buf
->l
- 4);
373 plog(LLV_ERROR
, LOCATION
, (struct sockaddr
*)&remote
,
374 "couldn't allocate smaller buffer.\n");
377 memcpy(newbuf
->v
, buf
->v
+ 4, newbuf
->l
);
383 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
384 plog(LLV_DEBUG
, LOCATION
, (struct sockaddr
*)&local
,
385 "%d bytes message received from %s\n",
386 len
, saddr2str((struct sockaddr
*)&remote
));
387 plogdump(LLV_DEBUG
, buf
->v
, buf
->l
);
389 /* avoid packets with malicious port/address */
390 switch (remote
.ss_family
) {
392 port
= ((struct sockaddr_in
*)&remote
)->sin_port
;
396 port
= ((struct sockaddr_in6
*)&remote
)->sin6_port
;
400 plog(LLV_ERROR
, LOCATION
, NULL
,
401 "invalid family: %d\n", remote
.ss_family
);
405 plog(LLV_ERROR
, LOCATION
, (struct sockaddr
*)&remote
,
406 "src port == 0 (valid as UDP but not with IKE)\n");
411 struct isakmp
*isakmp
= (struct isakmp
*)buf
->v
;
412 plog(LLV_DEBUG
, LOCATION
, (struct sockaddr
*)&remote
,
413 "natt receiving packet %.8X%.8X:%.8X%.8X %u\n",
414 *(u_long
*)isakmp
->i_ck
, *(u_long
*)&isakmp
->i_ck
[4],
415 *(u_long
*)isakmp
->r_ck
, *(u_long
*)&isakmp
->r_ck
[4],
419 /* XXX: check sender whether to be allowed or not to accept */
421 /* XXX: I don't know how to check isakmp half connection attack. */
423 /* simply reply if the packet was processed. */
424 if (check_recvdpkt((struct sockaddr
*)&remote
,
425 (struct sockaddr
*)&local
, buf
)) {
426 plog(LLV_NOTIFY
, LOCATION
, NULL
,
427 "the packet is retransmitted by %s.\n",
428 saddr2str((struct sockaddr
*)&remote
));
433 /* isakmp main routine */
434 if (isakmp_main(buf
, (struct sockaddr
*)&remote
,
435 (struct sockaddr
*)&local
) != 0) goto end
;
449 * main processing to handle isakmp payload
452 isakmp_main(msg
, remote
, local
)
454 struct sockaddr
*remote
, *local
;
456 struct isakmp
*isakmp
= (struct isakmp
*)msg
->v
;
457 isakmp_index
*index
= (isakmp_index
*)isakmp
;
458 u_int32_t msgid
= isakmp
->msgid
;
459 struct ph1handle
*iph1
;
461 #ifdef HAVE_PRINT_ISAKMP_C
462 isakmp_printpacket(msg
, remote
, local
, 0);
465 /* the initiator's cookie must not be zero */
466 if (memcmp(&isakmp
->i_ck
, r_ck0
, sizeof(cookie_t
)) == 0) {
467 plog(LLV_ERROR
, LOCATION
, remote
,
468 "malformed cookie received.\n");
472 /* Check the Major and Minor Version fields. */
474 * XXX Is is right to check version here ?
475 * I think it may no be here because the version depends
476 * on exchange status.
478 if (isakmp
->v
< ISAKMP_VERSION_NUMBER
) {
479 if (ISAKMP_GETMAJORV(isakmp
->v
) < ISAKMP_MAJOR_VERSION
) {
480 plog(LLV_ERROR
, LOCATION
, remote
,
481 "invalid major version %d.\n",
482 ISAKMP_GETMAJORV(isakmp
->v
));
485 #if ISAKMP_MINOR_VERSION > 0
486 if (ISAKMP_GETMINORV(isakmp
->v
) < ISAKMP_MINOR_VERSION
) {
487 plog(LLV_ERROR
, LOCATION
, remote
,
488 "invalid minor version %d.\n",
489 ISAKMP_GETMINORV(isakmp
->v
));
495 /* check the Flags field. */
496 /* XXX How is the exclusive check, E and A ? */
497 if (isakmp
->flags
& ~(ISAKMP_FLAG_E
| ISAKMP_FLAG_C
| ISAKMP_FLAG_A
)) {
498 plog(LLV_ERROR
, LOCATION
, remote
,
499 "invalid flag 0x%02x.\n", isakmp
->flags
);
503 /* ignore commit bit. */
504 if (ISSET(isakmp
->flags
, ISAKMP_FLAG_C
)) {
505 if (isakmp
->msgid
== 0) {
506 isakmp_info_send_nx(isakmp
, remote
, local
,
507 ISAKMP_NTYPE_INVALID_FLAGS
, NULL
);
508 plog(LLV_ERROR
, LOCATION
, remote
,
509 "Commit bit on phase1 forbidden.\n");
514 iph1
= getph1byindex(index
);
517 if (memcmp(&isakmp
->r_ck
, r_ck0
, sizeof(cookie_t
)) == 0 &&
518 iph1
->side
== INITIATOR
) {
519 plog(LLV_DEBUG
, LOCATION
, remote
,
520 "malformed cookie received or "
521 "the initiator's cookies collide.\n");
525 /* must be same addresses in one stream of a phase at least. */
526 if (cmpsaddrstrict(iph1
->remote
, remote
) != 0) {
528 if (iph1
->side
== RESPONDER
&&
529 (iph1
->natt_flags
& natt_remote_support
) != 0 &&
530 cmpsaddrwop(iph1
->remote
, remote
) == 0)
533 * If the initiator detects a NAT it may switch to a
534 * new port. Technically, the remote address may change
535 * as well, depending on the NAT. Handling that would
536 * require more changes.
538 * We should record the new remote port so we can
541 plog(LLV_WARNING
, LOCATION
, remote
,
542 "remote port changed from %s\n", saddr2str(iph1
->remote
));
543 memcpy(iph1
->remote
, remote
, iph1
->remote
->sa_len
);
544 memcpy(iph1
->local
, local
, iph1
->local
->sa_len
);
549 char *saddr_db
, *saddr_act
;
551 saddr_db
= strdup(saddr2str(iph1
->remote
));
552 saddr_act
= strdup(saddr2str(remote
));
554 plog(LLV_WARNING
, LOCATION
, remote
,
555 "remote address mismatched. db=%s, act=%s\n",
556 saddr_db
, saddr_act
);
558 racoon_free(saddr_db
);
559 racoon_free(saddr_act
);
563 * don't check of exchange type here because other type will be
564 * with same index, for example, informational exchange.
567 /* XXX more acceptable check */
570 switch (isakmp
->etype
) {
571 case ISAKMP_ETYPE_IDENT
:
572 case ISAKMP_ETYPE_AGG
:
573 case ISAKMP_ETYPE_BASE
:
574 /* phase 1 validity check */
575 if (isakmp
->msgid
!= 0) {
576 plog(LLV_ERROR
, LOCATION
, remote
,
577 "message id should be zero in phase1.\n");
581 /* search for isakmp status record of phase 1 */
584 * the packet must be the 1st message from a initiator
585 * or the 2nd message from the responder.
588 /* search for phase1 handle by index without r_ck */
589 iph1
= getph1byindex0(index
);
591 /*it must be the 1st message from a initiator.*/
592 if (memcmp(&isakmp
->r_ck
, r_ck0
,
593 sizeof(cookie_t
)) != 0) {
595 plog(LLV_DEBUG
, LOCATION
, remote
,
596 "malformed cookie received "
597 "or the spi expired.\n");
601 /* it must be responder's 1st exchange. */
602 if (isakmp_ph1begin_r(msg
, remote
, local
,
610 /* it must be the 2nd message from the responder. */
611 if (iph1
->side
!= INITIATOR
) {
612 plog(LLV_DEBUG
, LOCATION
, remote
,
613 "malformed cookie received. "
614 "it has to be as the initiator. %s\n",
615 isakmp_pindex(&iph1
->index
, 0));
621 * Don't delete phase 1 handler when the exchange type
622 * in handler is not equal to packet's one because of no
623 * authencication completed.
625 if (iph1
->etype
!= isakmp
->etype
) {
626 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
627 "exchange type is mismatched: "
628 "db=%s packet=%s, ignore it.\n",
629 s_isakmp_etype(iph1
->etype
),
630 s_isakmp_etype(isakmp
->etype
));
634 /* call main process of phase 1 */
635 if (ph1_main(iph1
, msg
) < 0) {
636 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
637 "phase1 negotiation failed.\n");
644 case ISAKMP_ETYPE_AUTH
:
645 plog(LLV_INFO
, LOCATION
, remote
,
646 "unsupported exchange %d received.\n",
650 case ISAKMP_ETYPE_INFO
:
651 case ISAKMP_ETYPE_ACKINFO
:
653 * iph1 must be present for Information message.
654 * if iph1 is null then trying to get the phase1 status
655 * as the packet from responder againt initiator's 1st
656 * exchange in phase 1.
657 * NOTE: We think such informational exchange should be ignored.
660 iph1
= getph1byindex0(index
);
662 plog(LLV_ERROR
, LOCATION
, remote
,
663 "unknown Informational "
664 "exchange received.\n");
667 if (cmpsaddrstrict(iph1
->remote
, remote
) != 0) {
668 plog(LLV_WARNING
, LOCATION
, remote
,
669 "remote address mismatched. "
671 saddr2str(iph1
->remote
));
675 if (isakmp_info_recv(iph1
, msg
) < 0)
679 case ISAKMP_ETYPE_QUICK
:
681 struct ph2handle
*iph2
;
684 isakmp_info_send_nx(isakmp
, remote
, local
,
685 ISAKMP_NTYPE_INVALID_COOKIE
, NULL
);
686 plog(LLV_ERROR
, LOCATION
, remote
,
687 "can't start the quick mode, "
688 "there is no ISAKMP-SA, %s\n",
689 isakmp_pindex((isakmp_index
*)&isakmp
->i_ck
,
694 /* check status of phase 1 whether negotiated or not. */
695 if (iph1
->status
!= PHASE1ST_ESTABLISHED
) {
696 plog(LLV_ERROR
, LOCATION
, remote
,
697 "can't start the quick mode, "
698 "there is no valid ISAKMP-SA, %s\n",
699 isakmp_pindex(&iph1
->index
, iph1
->msgid
));
703 /* search isakmp phase 2 stauts record. */
704 iph2
= getph2bymsgid(iph1
, msgid
);
706 /* it must be new negotiation as responder */
707 if (isakmp_ph2begin_r(iph1
, msg
) < 0)
715 * we keep to set commit bit during negotiation.
716 * When SA is configured, bit will be reset.
718 * don't initiate commit bit. should be fixed in the future.
720 if (ISSET(isakmp
->flags
, ISAKMP_FLAG_C
))
721 iph2
->flags
|= ISAKMP_FLAG_C
;
723 /* call main process of quick mode */
724 if (quick_main(iph2
, msg
) < 0) {
725 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
726 "phase2 negotiation failed.\n");
735 case ISAKMP_ETYPE_NEWGRP
:
737 plog(LLV_ERROR
, LOCATION
, remote
,
738 "Unknown new group mode exchange, "
739 "there is no ISAKMP-SA.\n");
742 isakmp_newgroup_r(iph1
, msg
);
745 case ISAKMP_ETYPE_NONE
:
747 plog(LLV_ERROR
, LOCATION
, NULL
,
748 "Invalid exchange type %d from %s.\n",
749 isakmp
->etype
, saddr2str(remote
));
757 * main function of phase 1.
761 struct ph1handle
*iph1
;
766 struct timeval start
, end
;
769 /* ignore a packet */
770 if (iph1
->status
== PHASE1ST_ESTABLISHED
)
774 gettimeofday(&start
, NULL
);
777 if (ph1exchange
[etypesw1(iph1
->etype
)]
779 [iph1
->status
] == NULL
) {
780 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
781 "why isn't the function defined.\n");
784 error
= (ph1exchange
[etypesw1(iph1
->etype
)]
786 [iph1
->status
])(iph1
, msg
);
790 * When an invalid packet is received on phase1, it should
791 * be selected to process this packet. That is to respond
792 * with a notify and delete phase 1 handler, OR not to respond
793 * and keep phase 1 handler.
795 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
796 "failed to pre-process packet.\n");
799 /* ignore the error and keep phase 1 handler */
804 /* free resend buffer */
805 if (iph1
->sendbuf
== NULL
) {
806 plog(LLV_ERROR
, LOCATION
, NULL
,
807 "no buffer found as sendbuf\n");
810 vfree(iph1
->sendbuf
);
811 iph1
->sendbuf
= NULL
;
813 /* turn off schedule */
815 SCHED_KILL(iph1
->scr
);
818 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
819 if ((ph1exchange
[etypesw1(iph1
->etype
)]
821 [iph1
->status
])(iph1
, msg
) != 0) {
822 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
823 "failed to process packet.\n");
828 gettimeofday(&end
, NULL
);
829 syslog(LOG_NOTICE
, "%s(%s): %8.6f",
830 "phase1", s_isakmp_state(iph1
->etype
, iph1
->side
, iph1
->status
),
831 timedelta(&start
, &end
));
833 if (iph1
->status
== PHASE1ST_ESTABLISHED
) {
836 gettimeofday(&iph1
->end
, NULL
);
837 syslog(LOG_NOTICE
, "%s(%s): %8.6f",
838 "phase1", s_isakmp_etype(iph1
->etype
),
839 timedelta(&iph1
->start
, &iph1
->end
));
842 /* save created date. */
843 (void)time(&iph1
->created
);
845 /* add to the schedule to expire, and seve back pointer. */
846 iph1
->sce
= sched_new(iph1
->approval
->lifetime
,
847 isakmp_ph1expire_stub
, iph1
);
849 /* INITIAL-CONTACT processing */
850 /* don't anything if local test mode. */
852 && iph1
->rmconf
->ini_contact
&& !getcontacted(iph1
->remote
)) {
853 /* send INITIAL-CONTACT */
854 isakmp_info_send_n1(iph1
,
855 ISAKMP_NTYPE_INITIAL_CONTACT
, NULL
);
856 /* insert a node into contacted list. */
857 if (inscontacted(iph1
->remote
) == -1) {
858 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
859 "failed to add contacted list.\n");
864 log_ph1established(iph1
);
865 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
872 * main function of quick mode.
875 quick_main(iph2
, msg
)
876 struct ph2handle
*iph2
;
879 struct isakmp
*isakmp
= (struct isakmp
*)msg
->v
;
882 struct timeval start
, end
;
885 /* ignore a packet */
886 if (iph2
->status
== PHASE2ST_ESTABLISHED
887 || iph2
->status
== PHASE2ST_GETSPISENT
)
891 gettimeofday(&start
, NULL
);
895 if (ph2exchange
[etypesw2(isakmp
->etype
)]
897 [iph2
->status
] == NULL
) {
898 plog(LLV_ERROR
, LOCATION
, iph2
->ph1
->remote
,
899 "why isn't the function defined.\n");
902 error
= (ph2exchange
[etypesw2(isakmp
->etype
)]
904 [iph2
->status
])(iph2
, msg
);
906 plog(LLV_ERROR
, LOCATION
, iph2
->ph1
->remote
,
907 "failed to pre-process packet.\n");
908 if (error
== ISAKMP_INTERNAL_ERROR
)
910 isakmp_info_send_n1(iph2
->ph1
, error
, NULL
);
914 /* when using commit bit, status will be reached here. */
915 if (iph2
->status
== PHASE2ST_ADDSA
)
918 /* free resend buffer */
919 if (iph2
->sendbuf
== NULL
) {
920 plog(LLV_ERROR
, LOCATION
, NULL
,
921 "no buffer found as sendbuf\n");
924 vfree(iph2
->sendbuf
);
925 iph2
->sendbuf
= NULL
;
927 /* turn off schedule */
929 SCHED_KILL(iph2
->scr
);
932 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
933 if ((ph2exchange
[etypesw2(isakmp
->etype
)]
935 [iph2
->status
])(iph2
, msg
) != 0) {
936 plog(LLV_ERROR
, LOCATION
, iph2
->ph1
->remote
,
937 "failed to process packet.\n");
942 gettimeofday(&end
, NULL
);
943 syslog(LOG_NOTICE
, "%s(%s): %8.6f",
945 s_isakmp_state(ISAKMP_ETYPE_QUICK
, iph2
->side
, iph2
->status
),
946 timedelta(&start
, &end
));
952 /* new negotiation of phase 1 for initiator */
954 isakmp_ph1begin_i(rmconf
, remote
)
955 struct remoteconf
*rmconf
;
956 struct sockaddr
*remote
;
958 struct ph1handle
*iph1
;
960 struct timeval start
, end
;
963 /* get new entry to isakmp status table. */
968 iph1
->status
= PHASE1ST_START
;
969 iph1
->rmconf
= rmconf
;
970 iph1
->side
= INITIATOR
;
971 iph1
->version
= ISAKMP_VERSION_NUMBER
;
976 iph1
->gssapi_state
= NULL
;
978 iph1
->approval
= NULL
;
980 /* XXX copy remote address */
981 if (copy_ph1addresses(iph1
, rmconf
, remote
, NULL
) < 0)
986 /* start phase 1 exchange */
987 iph1
->etype
= rmconf
->etypes
->type
;
989 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
993 a
= strdup(saddr2str(iph1
->local
));
994 plog(LLV_INFO
, LOCATION
, NULL
,
995 "initiate new phase 1 negotiation: %s<=>%s\n",
996 a
, saddr2str(iph1
->remote
));
999 plog(LLV_INFO
, LOCATION
, NULL
,
1001 s_isakmp_etype(iph1
->etype
));
1004 gettimeofday(&iph1
->start
, NULL
);
1005 gettimeofday(&start
, NULL
);
1007 /* start exchange */
1008 if ((ph1exchange
[etypesw1(iph1
->etype
)]
1010 [iph1
->status
])(iph1
, NULL
) != 0) {
1011 /* failed to start phase 1 negotiation */
1019 gettimeofday(&end
, NULL
);
1020 syslog(LOG_NOTICE
, "%s(%s): %8.6f",
1022 s_isakmp_state(iph1
->etype
, iph1
->side
, iph1
->status
),
1023 timedelta(&start
, &end
));
1029 /* new negotiation of phase 1 for responder */
1031 isakmp_ph1begin_r(msg
, remote
, local
, etype
)
1033 struct sockaddr
*remote
, *local
;
1036 struct isakmp
*isakmp
= (struct isakmp
*)msg
->v
;
1037 struct remoteconf
*rmconf
;
1038 struct ph1handle
*iph1
;
1039 struct etypes
*etypeok
;
1041 struct timeval start
, end
;
1044 /* look for my configuration */
1045 rmconf
= getrmconf(remote
);
1046 if (rmconf
== NULL
) {
1047 plog(LLV_ERROR
, LOCATION
, remote
,
1049 "configuration.\n");
1053 /* check to be acceptable exchange type */
1054 etypeok
= check_etypeok(rmconf
, etype
);
1055 if (etypeok
== NULL
) {
1056 plog(LLV_ERROR
, LOCATION
, remote
,
1057 "not acceptable %s mode\n", s_isakmp_etype(etype
));
1061 /* get new entry to isakmp status table. */
1066 memcpy(&iph1
->index
.i_ck
, &isakmp
->i_ck
, sizeof(iph1
->index
.i_ck
));
1067 iph1
->status
= PHASE1ST_START
;
1068 iph1
->rmconf
= rmconf
;
1070 iph1
->side
= RESPONDER
;
1071 iph1
->etype
= etypeok
->type
;
1072 iph1
->version
= isakmp
->v
;
1075 iph1
->gssapi_state
= NULL
;
1077 iph1
->approval
= NULL
;
1079 /* copy remote address */
1080 if (copy_ph1addresses(iph1
, rmconf
, remote
, local
) < 0)
1085 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
1089 a
= strdup(saddr2str(iph1
->local
));
1090 plog(LLV_INFO
, LOCATION
, NULL
,
1091 "respond new phase 1 negotiation: %s<=>%s\n",
1092 a
, saddr2str(iph1
->remote
));
1095 plog(LLV_INFO
, LOCATION
, NULL
,
1096 "begin %s mode.\n", s_isakmp_etype(etype
));
1099 gettimeofday(&iph1
->start
, NULL
);
1100 gettimeofday(&start
, NULL
);
1102 /* start exchange */
1103 if ((ph1exchange
[etypesw1(iph1
->etype
)]
1105 [iph1
->status
])(iph1
, msg
) < 0
1106 || (ph1exchange
[etypesw1(iph1
->etype
)]
1108 [iph1
->status
])(iph1
, msg
) < 0) {
1109 plog(LLV_ERROR
, LOCATION
, remote
,
1110 "failed to process packet.\n");
1116 gettimeofday(&end
, NULL
);
1117 syslog(LOG_NOTICE
, "%s(%s): %8.6f",
1119 s_isakmp_state(iph1
->etype
, iph1
->side
, iph1
->status
),
1120 timedelta(&start
, &end
));
1126 /* new negotiation of phase 2 for initiator */
1128 isakmp_ph2begin_i(iph1
, iph2
)
1129 struct ph1handle
*iph1
;
1130 struct ph2handle
*iph2
;
1132 /* found ISAKMP-SA. */
1133 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
1134 plog(LLV_DEBUG
, LOCATION
, NULL
, "begin QUICK mode.\n");
1137 a
= strdup(saddr2str(iph2
->src
));
1138 plog(LLV_INFO
, LOCATION
, NULL
,
1139 "initiate new phase 2 negotiation: %s<=>%s\n",
1140 a
, saddr2str(iph2
->dst
));
1145 gettimeofday(&iph2
->start
, NULL
);
1147 /* found isakmp-sa */
1148 bindph12(iph1
, iph2
);
1149 iph2
->status
= PHASE2ST_STATUS2
;
1151 if ((ph2exchange
[etypesw2(ISAKMP_ETYPE_QUICK
)]
1153 [iph2
->status
])(iph2
, NULL
) < 0) {
1155 /* release ipsecsa handler due to internal error. */
1163 /* new negotiation of phase 2 for responder */
1165 isakmp_ph2begin_r(iph1
, msg
)
1166 struct ph1handle
*iph1
;
1169 struct isakmp
*isakmp
= (struct isakmp
*)msg
->v
;
1170 struct ph2handle
*iph2
= 0;
1173 struct timeval start
, end
;
1178 plog(LLV_ERROR
, LOCATION
, NULL
,
1179 "failed to allocate phase2 entry.\n");
1184 iph2
->side
= RESPONDER
;
1185 iph2
->status
= PHASE2ST_START
;
1186 iph2
->flags
= isakmp
->flags
;
1187 iph2
->msgid
= isakmp
->msgid
;
1188 iph2
->seq
= pk_getseq();
1189 iph2
->ivm
= oakley_newiv2(iph1
, iph2
->msgid
);
1190 if (iph2
->ivm
== NULL
) {
1194 iph2
->dst
= dupsaddr(iph1
->remote
); /* XXX should be considered */
1195 if (iph2
->dst
== NULL
) {
1199 switch (iph2
->dst
->sa_family
) {
1201 ((struct sockaddr_in
*)iph2
->dst
)->sin_port
= 0;
1205 ((struct sockaddr_in6
*)iph2
->dst
)->sin6_port
= 0;
1209 plog(LLV_ERROR
, LOCATION
, NULL
,
1210 "invalid family: %d\n", iph2
->dst
->sa_family
);
1215 iph2
->src
= dupsaddr(iph1
->local
); /* XXX should be considered */
1216 if (iph2
->src
== NULL
) {
1220 switch (iph2
->src
->sa_family
) {
1222 ((struct sockaddr_in
*)iph2
->src
)->sin_port
= 0;
1226 ((struct sockaddr_in6
*)iph2
->src
)->sin6_port
= 0;
1230 plog(LLV_ERROR
, LOCATION
, NULL
,
1231 "invalid family: %d\n", iph2
->src
->sa_family
);
1236 /* add new entry to isakmp status table */
1238 bindph12(iph1
, iph2
);
1240 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
1244 a
= strdup(saddr2str(iph2
->src
));
1245 plog(LLV_INFO
, LOCATION
, NULL
,
1246 "respond new phase 2 negotiation: %s<=>%s\n",
1247 a
, saddr2str(iph2
->dst
));
1252 gettimeofday(&start
, NULL
);
1255 error
= (ph2exchange
[etypesw2(ISAKMP_ETYPE_QUICK
)]
1257 [iph2
->status
])(iph2
, msg
);
1259 plog(LLV_ERROR
, LOCATION
, iph1
->remote
,
1260 "failed to pre-process packet.\n");
1261 if (error
!= ISAKMP_INTERNAL_ERROR
)
1262 isakmp_info_send_n1(iph2
->ph1
, error
, NULL
);
1264 * release handler because it's wrong that ph2handle is kept
1265 * after failed to check message for responder's.
1274 plog(LLV_DEBUG
, LOCATION
, NULL
, "===\n");
1275 if ((ph2exchange
[etypesw2(isakmp
->etype
)]
1277 [iph2
->status
])(iph2
, msg
) < 0) {
1278 plog(LLV_ERROR
, LOCATION
, iph2
->ph1
->remote
,
1279 "failed to process packet.\n");
1280 /* don't release handler */
1284 gettimeofday(&end
, NULL
);
1285 syslog(LOG_NOTICE
, "%s(%s): %8.6f",
1287 s_isakmp_state(ISAKMP_ETYPE_QUICK
, iph2
->side
, iph2
->status
),
1288 timedelta(&start
, &end
));
1295 * parse ISAKMP payloads, without ISAKMP base header.
1298 isakmp_parsewoh(np0
, gen
, len
)
1300 struct isakmp_gen
*gen
;
1303 u_char np
= np0
& 0xff;
1306 struct isakmp_parse_t
*p
, *ep
;
1308 plog(LLV_DEBUG
, LOCATION
, NULL
, "begin.\n");
1311 * 5 is a magic number, but any value larger than 2 should be fine
1312 * as we do vrealloc() in the following loop.
1314 result
= vmalloc(sizeof(struct isakmp_parse_t
) * 5);
1315 if (result
== NULL
) {
1316 plog(LLV_ERROR
, LOCATION
, NULL
,
1317 "failed to get buffer.\n");
1320 p
= (struct isakmp_parse_t
*)result
->v
;
1321 ep
= (struct isakmp_parse_t
*)(result
->v
+ result
->l
- sizeof(*ep
));
1325 /* parse through general headers */
1326 while (0 < tlen
&& np
!= ISAKMP_NPTYPE_NONE
) {
1327 if (tlen
<= sizeof(struct isakmp_gen
)) {
1328 /* don't send information, see isakmp_ident_r1() */
1329 plog(LLV_ERROR
, LOCATION
, NULL
,
1330 "invalid length of payload\n");
1335 plog(LLV_DEBUG
, LOCATION
, NULL
,
1336 "seen nptype=%u(%s)\n", np
, s_isakmp_nptype(np
));
1339 p
->len
= ntohs(gen
->len
);
1340 if (p
->len
== 0 || p
->len
> tlen
) {
1341 plog(LLV_DEBUG
, LOCATION
, NULL
,
1342 "invalid length of payload\n");
1351 off
= p
- (struct isakmp_parse_t
*)result
->v
;
1352 result
= vrealloc(result
, result
->l
* 2);
1353 if (result
== NULL
) {
1354 plog(LLV_DEBUG
, LOCATION
, NULL
,
1355 "failed to realloc buffer.\n");
1359 ep
= (struct isakmp_parse_t
*)
1360 (result
->v
+ result
->l
- sizeof(*ep
));
1361 p
= (struct isakmp_parse_t
*)result
->v
;
1366 plen
= ntohs(gen
->len
);
1367 gen
= (struct isakmp_gen
*)((caddr_t
)gen
+ plen
);
1370 p
->type
= ISAKMP_NPTYPE_NONE
;
1374 plog(LLV_DEBUG
, LOCATION
, NULL
, "succeed.\n");
1380 * parse ISAKMP payloads, including ISAKMP base header.
1386 struct isakmp
*isakmp
= (struct isakmp
*)buf
->v
;
1387 struct isakmp_gen
*gen
;
1393 gen
= (struct isakmp_gen
*)(buf
->v
+ sizeof(*isakmp
));
1394 tlen
= buf
->l
- sizeof(struct isakmp
);
1395 result
= isakmp_parsewoh(np
, gen
, tlen
);
1404 /* initialize a isakmp status table */
1410 if (isakmp_open() < 0)
1421 * make strings containing i_cookie + r_cookie + msgid
1424 isakmp_pindex(index
, msgid
)
1425 const isakmp_index
*index
;
1426 const u_int32_t msgid
;
1428 static char buf
[64];
1432 memset(buf
, 0, sizeof(buf
));
1435 p
= (const u_char
*)index
;
1436 for (j
= 0, i
= 0; i
< sizeof(isakmp_index
); i
++) {
1437 snprintf((char *)&buf
[j
], sizeof(buf
) - j
, "%02x", p
[i
]);
1449 snprintf((char *)&buf
[j
], sizeof(buf
) - j
, ":%08x", ntohs(msgid
));
1455 isakmp_setup_socket(struct sockaddr
* in_addr
)
1462 if ((sock
= socket(in_addr
->sa_family
, SOCK_DGRAM
, 0)) < 0) {
1463 plog(LLV_ERROR
, LOCATION
, NULL
,
1464 "socket (%s)\n", strerror(errno
));
1468 /* receive my interface address on inbound packets. */
1469 switch (in_addr
->sa_family
) {
1471 if (setsockopt(sock
, IPPROTO_IP
, IP_RECVDSTADDR
,
1472 (const void *)&yes
, sizeof(yes
)) < 0) {
1473 plog(LLV_ERROR
, LOCATION
, NULL
,
1474 "setsockopt (%s)\n", strerror(errno
));
1482 #ifdef IPV6_RECVPKTINFO
1483 pktinfo
= IPV6_RECVPKTINFO
;
1484 #else /* old adv. API */
1485 pktinfo
= IPV6_PKTINFO
;
1486 #endif /* IPV6_RECVPKTINFO */
1488 pktinfo
= IPV6_RECVDSTADDR
;
1490 if (setsockopt(sock
, IPPROTO_IPV6
, pktinfo
,
1491 (const void *)&yes
, sizeof(yes
)) < 0)
1493 plog(LLV_ERROR
, LOCATION
, NULL
,
1494 "setsockopt(%d): %s\n",
1495 pktinfo
, strerror(errno
));
1503 #ifdef IPV6_USE_MIN_MTU
1504 if (in_addr
->sa_family
== AF_INET6
&&
1505 setsockopt(sock
, IPPROTO_IPV6
, IPV6_USE_MIN_MTU
,
1506 (void *)&yes
, sizeof(yes
)) < 0) {
1507 plog(LLV_ERROR
, LOCATION
, NULL
,
1508 "setsockopt (%s)\n", strerror(errno
));
1514 if (setsockopt_bypass(sock
, in_addr
->sa_family
) < 0) {
1519 if (bind(sock
, in_addr
, in_addr
->sa_len
) < 0) {
1520 plog(LLV_ERROR
, LOCATION
, in_addr
,
1521 "failed to bind (%s).\n", strerror(errno
));
1529 /* open ISAKMP sockets. */
1537 for (p
= lcconf
->myaddrs
; p
; p
= p
->next
) {
1541 /* warn if wildcard address - should we forbid this? */
1542 switch (p
->addr
->sa_family
) {
1544 if (((struct sockaddr_in
*)p
->addr
)->sin_addr
.s_addr
== 0)
1545 plog(LLV_WARNING
, LOCATION
, NULL
,
1546 "listening to wildcard address,"
1547 "broadcast IKE packet may kill you\n");
1551 if (IN6_IS_ADDR_UNSPECIFIED(&((struct sockaddr_in6
*)p
->addr
)->sin6_addr
))
1552 plog(LLV_WARNING
, LOCATION
, NULL
,
1553 "listening to wildcard address, "
1554 "broadcast IKE packet may kill you\n");
1558 plog(LLV_ERROR
, LOCATION
, NULL
,
1559 "unsupported address family %d\n",
1560 lcconf
->default_af
);
1564 p
->sock
= isakmp_setup_socket(p
->addr
);
1565 if (p
->sock
< 0) goto err_and_next
;
1567 plog(LLV_DEBUG
, LOCATION
, NULL
,
1568 "%s used as isakmp port (fd=%d)\n",
1569 saddr2str(p
->addr
), p
->sock
);
1575 * We have to listen on 4500 in addition to 500 with IPv4
1576 * to support NAT traversal.
1578 if (p
->addr
->sa_family
== AF_INET
)
1580 struct sockaddr_in sin
= *(struct sockaddr_in
*)p
->addr
;
1582 sin
.sin_port
= ntohs(PORT_ISAKMP_NATT
);
1583 p
->nattsock
= isakmp_setup_socket((struct sockaddr
*)&sin
);
1584 if (p
->nattsock
>= 0)
1586 plog(LLV_DEBUG
, LOCATION
, NULL
,
1587 "%s used as nat-t isakmp port (fd=%d)\n",
1588 saddr2str((struct sockaddr
*)&sin
), p
->nattsock
);
1596 racoon_free(p
->addr
);
1598 if (! lcconf
->autograbaddr
&& lcconf
->strict_address
)
1604 plog(LLV_ERROR
, LOCATION
, NULL
,
1605 "no address could be bound.\n");
1615 struct myaddrs
*p
, *next
;
1617 for (p
= lcconf
->myaddrs
; p
; p
= next
) {
1626 if (p
->nattsock
>= 0) close(p
->nattsock
);
1628 racoon_free(p
->addr
);
1632 lcconf
->myaddrs
= NULL
;
1636 isakmp_send(iph1
, sbuf
)
1637 struct ph1handle
*iph1
;
1642 vchar_t
*newbuf
= NULL
;
1644 /* select the socket to be sent */
1645 s
= getsockmyaddr(iph1
->local
);
1650 /* prepend four bytes of zeros if source or destination port is PORT_ISAKMP_NATT */
1651 if (iph1
->remote
->sa_family
== AF_INET
&&
1652 (((struct sockaddr_in
*)(iph1
->remote
))->sin_port
== htons(PORT_ISAKMP_NATT
)) ||
1653 ((struct sockaddr_in
*)(iph1
->local
))->sin_port
== htons(PORT_ISAKMP_NATT
))
1656 /* There's probably a better way to do this */
1657 newbuf
= vmalloc(sbuf
->l
+ 4);
1658 if (newbuf
== NULL
) {
1659 plog(LLV_ERROR
, LOCATION
, NULL
, "sendfromto natt prepend failed\n");
1663 memset(newbuf
->v
, 0, 4);
1664 memcpy(newbuf
->v
+ 4, sbuf
->v
, sbuf
->l
);
1669 len
= sendfromto(s
, sbuf
->v
, sbuf
->l
,
1670 iph1
->local
, iph1
->remote
, lcconf
->count_persend
);
1672 plog(LLV_ERROR
, LOCATION
, NULL
, "sendfromto failed\n");
1676 if (newbuf
) vfree(newbuf
);
1681 /* called from scheduler */
1683 isakmp_ph1resend_stub(p
)
1686 (void)isakmp_ph1resend((struct ph1handle
*)p
);
1690 isakmp_ph1resend(iph1
)
1691 struct ph1handle
*iph1
;
1693 if (iph1
->retry_counter
< 0) {
1694 plog(LLV_ERROR
, LOCATION
, NULL
,
1695 "phase1 negotiation failed due to time up. %s\n",
1696 isakmp_pindex(&iph1
->index
, iph1
->msgid
));
1703 if (isakmp_send(iph1
, iph1
->sendbuf
) < 0)
1706 plog(LLV_DEBUG
, LOCATION
, NULL
,
1707 "resend phase1 packet %s\n",
1708 isakmp_pindex(&iph1
->index
, iph1
->msgid
));
1710 iph1
->retry_counter
--;
1712 iph1
->scr
= sched_new(iph1
->rmconf
->retry_interval
,
1713 isakmp_ph1resend_stub
, iph1
);
1718 /* called from scheduler */
1720 isakmp_ph2resend_stub(p
)
1724 (void)isakmp_ph2resend((struct ph2handle
*)p
);
1728 isakmp_ph2resend(iph2
)
1729 struct ph2handle
*iph2
;
1731 if (iph2
->retry_counter
< 0) {
1732 plog(LLV_ERROR
, LOCATION
, NULL
,
1733 "phase2 negotiation failed due to time up. %s\n",
1734 isakmp_pindex(&iph2
->ph1
->index
, iph2
->msgid
));
1741 if (isakmp_send(iph2
->ph1
, iph2
->sendbuf
) < 0)
1744 plog(LLV_DEBUG
, LOCATION
, NULL
,
1745 "resend phase2 packet %s\n",
1746 isakmp_pindex(&iph2
->ph1
->index
, iph2
->msgid
));
1748 iph2
->retry_counter
--;
1750 iph2
->scr
= sched_new(iph2
->ph1
->rmconf
->retry_interval
,
1751 isakmp_ph2resend_stub
, iph2
);
1756 /* called from scheduler */
1758 isakmp_ph1expire_stub(p
)
1762 isakmp_ph1expire((struct ph1handle
*)p
);
1766 isakmp_ph1expire(iph1
)
1767 struct ph1handle
*iph1
;
1771 src
= strdup(saddr2str(iph1
->local
));
1772 dst
= strdup(saddr2str(iph1
->remote
));
1773 plog(LLV_INFO
, LOCATION
, NULL
,
1774 "ISAKMP-SA expired %s-%s spi:%s\n",
1776 isakmp_pindex(&iph1
->index
, 0));
1780 SCHED_KILL(iph1
->sce
);
1782 iph1
->status
= PHASE1ST_EXPIRED
;
1785 * the phase1 deletion is postponed until there is no phase2.
1787 if (LIST_FIRST(&iph1
->ph2tree
) != NULL
) {
1788 iph1
->sce
= sched_new(1, isakmp_ph1expire_stub
, iph1
);
1792 iph1
->sce
= sched_new(1, isakmp_ph1delete_stub
, iph1
);
1795 /* called from scheduler */
1797 isakmp_ph1delete_stub(p
)
1801 isakmp_ph1delete((struct ph1handle
*)p
);
1805 isakmp_ph1delete(iph1
)
1806 struct ph1handle
*iph1
;
1810 SCHED_KILL(iph1
->sce
);
1812 if (LIST_FIRST(&iph1
->ph2tree
) != NULL
) {
1813 iph1
->sce
= sched_new(1, isakmp_ph1delete_stub
, iph1
);
1817 /* don't re-negosiation when the phase 1 SA expires. */
1819 src
= strdup(saddr2str(iph1
->local
));
1820 dst
= strdup(saddr2str(iph1
->remote
));
1821 plog(LLV_INFO
, LOCATION
, NULL
,
1822 "ISAKMP-SA deleted %s-%s spi:%s\n",
1823 src
, dst
, isakmp_pindex(&iph1
->index
, 0));
1833 /* called from scheduler.
1834 * this function will call only isakmp_ph2delete().
1835 * phase 2 handler remain forever if kernel doesn't cry a expire of phase 2 SA
1836 * by something cause. That's why this function is called after phase 2 SA
1837 * expires in the userland.
1840 isakmp_ph2expire_stub(p
)
1844 isakmp_ph2expire((struct ph2handle
*)p
);
1848 isakmp_ph2expire(iph2
)
1849 struct ph2handle
*iph2
;
1853 SCHED_KILL(iph2
->sce
);
1855 src
= strdup(saddrwop2str(iph2
->src
));
1856 dst
= strdup(saddrwop2str(iph2
->dst
));
1857 plog(LLV_INFO
, LOCATION
, NULL
,
1858 "phase2 sa expired %s-%s\n", src
, dst
);
1862 iph2
->status
= PHASE2ST_EXPIRED
;
1864 iph2
->sce
= sched_new(1, isakmp_ph2delete_stub
, iph2
);
1869 /* called from scheduler */
1871 isakmp_ph2delete_stub(p
)
1875 isakmp_ph2delete((struct ph2handle
*)p
);
1879 isakmp_ph2delete(iph2
)
1880 struct ph2handle
*iph2
;
1884 SCHED_KILL(iph2
->sce
);
1886 src
= strdup(saddrwop2str(iph2
->src
));
1887 dst
= strdup(saddrwop2str(iph2
->dst
));
1888 plog(LLV_INFO
, LOCATION
, NULL
,
1889 "phase2 sa deleted %s-%s\n", src
, dst
);
1901 * Interface between PF_KEYv2 and ISAKMP
1904 * receive ACQUIRE from kernel, and begin either phase1 or phase2.
1905 * if phase1 has been finished, begin phase2.
1908 isakmp_post_acquire(iph2
)
1909 struct ph2handle
*iph2
;
1911 struct remoteconf
*rmconf
;
1912 struct ph1handle
*iph1
= NULL
;
1914 /* search appropreate configuration with masking port. */
1915 rmconf
= getrmconf(iph2
->dst
);
1916 if (rmconf
== NULL
) {
1917 plog(LLV_ERROR
, LOCATION
, NULL
,
1918 "no configuration found for %s.\n",
1919 saddrwop2str(iph2
->dst
));
1923 /* if passive mode, ignore the acquire message */
1924 if (rmconf
->passive
) {
1925 plog(LLV_DEBUG
, LOCATION
, NULL
,
1926 "because of passive mode, "
1927 "ignore the acquire message for %s.\n",
1928 saddrwop2str(iph2
->dst
));
1932 /* search isakmp status table by address with masking port */
1933 iph1
= getph1byaddr(iph2
->src
, iph2
->dst
);
1935 /* no ISAKMP-SA found. */
1939 iph2
->retry_checkph1
= lcconf
->retry_checkph1
;
1940 sc
= sched_new(1, isakmp_chkph1there_stub
, iph2
);
1941 plog(LLV_INFO
, LOCATION
, NULL
,
1942 "IPsec-SA request for %s queued "
1943 "due to no phase1 found.\n",
1944 saddrwop2str(iph2
->dst
));
1946 /* start phase 1 negotiation as a initiator. */
1947 if (isakmp_ph1begin_i(rmconf
, iph2
->dst
) < 0) {
1956 /* found ISAKMP-SA, but on negotiation. */
1957 if (iph1
->status
!= PHASE1ST_ESTABLISHED
) {
1958 iph2
->retry_checkph1
= lcconf
->retry_checkph1
;
1959 sched_new(1, isakmp_chkph1there_stub
, iph2
);
1960 plog(LLV_INFO
, LOCATION
, iph2
->dst
,
1961 "request for establishing IPsec-SA was queued "
1962 "due to no phase1 found.\n");
1967 /* found established ISAKMP-SA */
1968 /* i.e. iph1->status == PHASE1ST_ESTABLISHED */
1970 /* found ISAKMP-SA. */
1971 plog(LLV_DEBUG
, LOCATION
, NULL
, "begin QUICK mode.\n");
1973 /* begin quick mode */
1974 if (isakmp_ph2begin_i(iph1
, iph2
))
1981 * receive GETSPI from kernel.
1984 isakmp_post_getspi(iph2
)
1985 struct ph2handle
*iph2
;
1988 struct timeval start
, end
;
1991 /* don't process it because there is no suitable phase1-sa. */
1992 if (iph2
->ph1
->status
== PHASE2ST_EXPIRED
) {
1993 plog(LLV_ERROR
, LOCATION
, iph2
->ph1
->remote
,
1994 "the negotiation is stopped, "
1995 "because there is no suitable ISAKMP-SA.\n");
2000 gettimeofday(&start
, NULL
);
2002 if ((ph2exchange
[etypesw2(ISAKMP_ETYPE_QUICK
)]
2004 [iph2
->status
])(iph2
, NULL
) != 0)
2007 gettimeofday(&end
, NULL
);
2008 syslog(LOG_NOTICE
, "%s(%s): %8.6f",
2010 s_isakmp_state(ISAKMP_ETYPE_QUICK
, iph2
->side
, iph2
->status
),
2011 timedelta(&start
, &end
));
2017 /* called by scheduler */
2019 isakmp_chkph1there_stub(p
)
2022 isakmp_chkph1there((struct ph2handle
*)p
);
2026 isakmp_chkph1there(iph2
)
2027 struct ph2handle
*iph2
;
2029 struct ph1handle
*iph1
;
2031 iph2
->retry_checkph1
--;
2032 if (iph2
->retry_checkph1
< 0) {
2033 plog(LLV_ERROR
, LOCATION
, iph2
->dst
,
2034 "phase2 negotiation failed "
2035 "due to time up waiting for phase1. %s\n",
2036 sadbsecas2str(iph2
->dst
, iph2
->src
,
2037 iph2
->satype
, 0, 0));
2038 plog(LLV_INFO
, LOCATION
, NULL
,
2039 "delete phase 2 handler.\n");
2041 /* send acquire to kernel as error */
2042 pk_sendeacquire(iph2
);
2051 iph1
= getph1byaddr(iph2
->src
, iph2
->dst
);
2053 /* XXX Even if ph1 as responder is there, should we not start
2054 * phase 2 negotiation ? */
2056 && iph1
->status
== PHASE1ST_ESTABLISHED
) {
2057 /* found isakmp-sa */
2058 /* begin quick mode */
2059 (void)isakmp_ph2begin_i(iph1
, iph2
);
2063 /* no isakmp-sa found */
2064 sched_new(1, isakmp_chkph1there_stub
, iph2
);
2069 /* copy variable data into ALLOCATED buffer. */
2071 isakmp_set_attr_v(buf
, type
, val
, len
)
2077 struct isakmp_data
*data
;
2079 data
= (struct isakmp_data
*)buf
;
2080 data
->type
= htons((u_int16_t
)type
| ISAKMP_GEN_TLV
);
2081 data
->lorv
= htons((u_int16_t
)len
);
2082 memcpy(data
+ 1, val
, len
);
2084 return buf
+ sizeof(*data
) + len
;
2087 /* copy fixed length data into ALLOCATED buffer. */
2089 isakmp_set_attr_l(buf
, type
, val
)
2094 struct isakmp_data
*data
;
2096 data
= (struct isakmp_data
*)buf
;
2097 data
->type
= htons((u_int16_t
)type
| ISAKMP_GEN_TV
);
2098 data
->lorv
= htons((u_int16_t
)val
);
2100 return buf
+ sizeof(*data
);
2103 /* add a variable data attribute to the buffer by reallocating it. */
2105 isakmp_add_attr_v(buf0
, type
, val
, len
)
2111 vchar_t
*buf
= NULL
;
2112 struct isakmp_data
*data
;
2116 tlen
= sizeof(*data
) + len
;
2120 buf
= vrealloc(buf0
, oldlen
+ tlen
);
2122 buf
= vmalloc(tlen
);
2124 plog(LLV_ERROR
, LOCATION
, NULL
,
2125 "failed to get a attribute buffer.\n");
2129 data
= (struct isakmp_data
*)(buf
->v
+ oldlen
);
2130 data
->type
= htons((u_int16_t
)type
| ISAKMP_GEN_TLV
);
2131 data
->lorv
= htons((u_int16_t
)len
);
2132 memcpy(data
+ 1, val
, len
);
2137 /* add a fixed data attribute to the buffer by reallocating it. */
2139 isakmp_add_attr_l(buf0
, type
, val
)
2144 vchar_t
*buf
= NULL
;
2145 struct isakmp_data
*data
;
2149 tlen
= sizeof(*data
);
2153 buf
= vrealloc(buf0
, oldlen
+ tlen
);
2155 buf
= vmalloc(tlen
);
2157 plog(LLV_ERROR
, LOCATION
, NULL
,
2158 "failed to get a attribute buffer.\n");
2162 data
= (struct isakmp_data
*)(buf
->v
+ oldlen
);
2163 data
->type
= htons((u_int16_t
)type
| ISAKMP_GEN_TV
);
2164 data
->lorv
= htons((u_int16_t
)val
);
2170 * calculate cookie and set.
2173 isakmp_newcookie(place
, remote
, local
)
2175 struct sockaddr
*remote
;
2176 struct sockaddr
*local
;
2178 vchar_t
*buf
= NULL
, *buf2
= NULL
;
2188 if (remote
->sa_family
!= local
->sa_family
) {
2189 plog(LLV_ERROR
, LOCATION
, NULL
,
2190 "address family mismatch, remote:%d local:%d\n",
2191 remote
->sa_family
, local
->sa_family
);
2194 switch (remote
->sa_family
) {
2196 alen
= sizeof(struct in_addr
);
2197 sa1
= (caddr_t
)&((struct sockaddr_in
*)remote
)->sin_addr
;
2198 sa2
= (caddr_t
)&((struct sockaddr_in
*)local
)->sin_addr
;
2202 alen
= sizeof(struct in_addr
);
2203 sa1
= (caddr_t
)&((struct sockaddr_in6
*)remote
)->sin6_addr
;
2204 sa2
= (caddr_t
)&((struct sockaddr_in6
*)local
)->sin6_addr
;
2208 plog(LLV_ERROR
, LOCATION
, NULL
,
2209 "invalid family: %d\n", remote
->sa_family
);
2212 blen
= (alen
+ sizeof(u_short
)) * 2
2213 + sizeof(time_t) + lcconf
->secret_size
;
2214 buf
= vmalloc(blen
);
2216 plog(LLV_ERROR
, LOCATION
, NULL
,
2217 "failed to get a cookie.\n");
2222 /* copy my address */
2223 memcpy(p
, sa1
, alen
);
2225 port
= ((struct sockaddr_in
*)remote
)->sin_port
;
2226 memcpy(p
, &port
, sizeof(u_short
));
2227 p
+= sizeof(u_short
);
2229 /* copy target address */
2230 memcpy(p
, sa2
, alen
);
2232 port
= ((struct sockaddr_in
*)local
)->sin_port
;
2233 memcpy(p
, &port
, sizeof(u_short
));
2234 p
+= sizeof(u_short
);
2238 memcpy(p
, (caddr_t
)&t
, sizeof(t
));
2241 /* copy random value */
2242 buf2
= eay_set_random(lcconf
->secret_size
);
2245 memcpy(p
, buf2
->v
, lcconf
->secret_size
);
2246 p
+= lcconf
->secret_size
;
2249 buf2
= eay_sha1_one(buf
);
2250 memcpy(place
, buf2
->v
, sizeof(cookie_t
));
2252 sa1
= val2str(place
, sizeof (cookie_t
));
2253 plog(LLV_DEBUG
, LOCATION
, NULL
, "new cookie:\n%s\n", sa1
);
2266 * save partner's(payload) data into phhandle.
2269 isakmp_p2ph(buf
, gen
)
2271 struct isakmp_gen
*gen
;
2273 /* XXX to be checked in each functions for logging. */
2275 plog(LLV_WARNING
, LOCATION
, NULL
,
2276 "ignore this payload, same payload type exist.\n");
2280 *buf
= vmalloc(ntohs(gen
->len
) - sizeof(*gen
));
2282 plog(LLV_ERROR
, LOCATION
, NULL
,
2283 "failed to get buffer.\n");
2286 memcpy((*buf
)->v
, gen
+ 1, (*buf
)->l
);
2292 isakmp_newmsgid2(iph1
)
2293 struct ph1handle
*iph1
;
2298 msgid2
= arc4random();
2299 } while (getph2bymsgid(iph1
, msgid2
));
2305 * set values into allocated buffer of isakmp header for phase 1
2308 set_isakmp_header(vbuf
, iph1
, nptype
)
2310 struct ph1handle
*iph1
;
2313 struct isakmp
*isakmp
;
2315 if (vbuf
->l
< sizeof(*isakmp
))
2318 isakmp
= (struct isakmp
*)vbuf
->v
;
2319 memcpy(&isakmp
->i_ck
, &iph1
->index
.i_ck
, sizeof(cookie_t
));
2320 memcpy(&isakmp
->r_ck
, &iph1
->index
.r_ck
, sizeof(cookie_t
));
2321 isakmp
->np
= nptype
;
2322 isakmp
->v
= iph1
->version
;
2323 isakmp
->etype
= iph1
->etype
;
2324 isakmp
->flags
= iph1
->flags
;
2325 isakmp
->msgid
= iph1
->msgid
;
2326 isakmp
->len
= htonl(vbuf
->l
);
2328 return vbuf
->v
+ sizeof(*isakmp
);
2332 * set values into allocated buffer of isakmp header for phase 2
2335 set_isakmp_header2(vbuf
, iph2
, nptype
)
2337 struct ph2handle
*iph2
;
2340 struct isakmp
*isakmp
;
2342 if (vbuf
->l
< sizeof(*isakmp
))
2345 isakmp
= (struct isakmp
*)vbuf
->v
;
2346 memcpy(&isakmp
->i_ck
, &iph2
->ph1
->index
.i_ck
, sizeof(cookie_t
));
2347 memcpy(&isakmp
->r_ck
, &iph2
->ph1
->index
.r_ck
, sizeof(cookie_t
));
2348 isakmp
->np
= nptype
;
2349 isakmp
->v
= iph2
->ph1
->version
;
2350 isakmp
->etype
= ISAKMP_ETYPE_QUICK
;
2351 isakmp
->flags
= iph2
->flags
;
2352 memcpy(&isakmp
->msgid
, &iph2
->msgid
, sizeof(isakmp
->msgid
));
2353 isakmp
->len
= htonl(vbuf
->l
);
2355 return vbuf
->v
+ sizeof(*isakmp
);
2359 * set values into allocated buffer of isakmp payload.
2362 set_isakmp_payload(buf
, src
, nptype
)
2367 struct isakmp_gen
*gen
;
2370 plog(LLV_DEBUG
, LOCATION
, NULL
, "add payload of len %d, next type %d\n",
2373 gen
= (struct isakmp_gen
*)p
;
2375 gen
->len
= htons(sizeof(*gen
) + src
->l
);
2377 memcpy(p
, src
->v
, src
->l
);
2388 case ISAKMP_ETYPE_IDENT
:
2390 case ISAKMP_ETYPE_AGG
:
2392 case ISAKMP_ETYPE_BASE
:
2405 case ISAKMP_ETYPE_QUICK
:
2413 #ifdef HAVE_PRINT_ISAKMP_C
2414 /* for print-isakmp.c */
2416 extern void isakmp_print
__P((const u_char
*, u_int
, const u_char
*));
2418 char *getname
__P((const u_char
*));
2420 char *getname6
__P((const u_char
*));
2422 int safeputchar
__P((int));
2425 * Return a name for the IP address pointed to by ap. This address
2426 * is assumed to be in network byte order.
2432 struct sockaddr_in addr
;
2433 static char ntop_buf
[NI_MAXHOST
];
2435 memset(&addr
, 0, sizeof(addr
));
2436 addr
.sin_len
= sizeof(struct sockaddr_in
);
2437 addr
.sin_family
= AF_INET
;
2438 memcpy(&addr
.sin_addr
, ap
, sizeof(addr
.sin_addr
));
2439 if (getnameinfo((struct sockaddr
*)&addr
, addr
.sin_len
,
2440 ntop_buf
, sizeof(ntop_buf
), NULL
, 0,
2441 NI_NUMERICHOST
| niflags
))
2442 strlcpy(ntop_buf
, "?", sizeof(ntop_buf
));
2449 * Return a name for the IP6 address pointed to by ap. This address
2450 * is assumed to be in network byte order.
2456 struct sockaddr_in6 addr
;
2457 static char ntop_buf
[NI_MAXHOST
];
2459 memset(&addr
, 0, sizeof(addr
));
2460 addr
.sin6_len
= sizeof(struct sockaddr_in6
);
2461 addr
.sin6_family
= AF_INET6
;
2462 memcpy(&addr
.sin6_addr
, ap
, sizeof(addr
.sin6_addr
));
2463 if (getnameinfo((struct sockaddr
*)&addr
, addr
.sin6_len
,
2464 ntop_buf
, sizeof(ntop_buf
), NULL
, 0,
2465 NI_NUMERICHOST
| niflags
))
2466 strlcpy(ntop_buf
, "?", sizeof(ntop_buf
));
2478 ch
= (unsigned char)(c
& 0xff);
2479 if (c
< 0x80 && isprint(c
))
2480 return printf("%c", c
& 0xff);
2482 return printf("\\%03o", c
& 0xff);
2486 isakmp_printpacket(msg
, from
, my
, decoded
)
2488 struct sockaddr
*from
;
2489 struct sockaddr
*my
;
2495 char hostbuf
[NI_MAXHOST
];
2496 char portbuf
[NI_MAXSERV
];
2497 struct isakmp
*isakmp
;
2501 if (loglevel
< LLV_DEBUG
)
2505 plog(LLV_DEBUG
, LOCATION
, NULL
, "begin.\n");
2507 gettimeofday(&tv
, NULL
);
2508 s
= tv
.tv_sec
% 3600;
2509 printf("%02d:%02d.%06u ", s
/ 60, s
% 60, (u_int32_t
)tv
.tv_usec
);
2512 if (getnameinfo(from
, from
->sa_len
, hostbuf
, sizeof(hostbuf
),
2513 portbuf
, sizeof(portbuf
),
2514 NI_NUMERICHOST
| NI_NUMERICSERV
| niflags
)) {
2515 strlcpy(hostbuf
, "?", sizeof(hostbuf
));
2516 strlcpy(portbuf
, "?", sizeof(portbuf
));
2518 printf("%s:%s", hostbuf
, portbuf
);
2523 if (getnameinfo(my
, my
->sa_len
, hostbuf
, sizeof(hostbuf
),
2524 portbuf
, sizeof(portbuf
),
2525 NI_NUMERICHOST
| NI_NUMERICSERV
| niflags
)) {
2526 strlcpy(hostbuf
, "?", sizeof(hostbuf
));
2527 strlcpy(portbuf
, "?", sizeof(portbuf
));
2529 printf("%s:%s", hostbuf
, portbuf
);
2536 printf("(malloc fail)\n");
2540 isakmp
= (struct isakmp
*)buf
->v
;
2541 if (isakmp
->flags
& ISAKMP_FLAG_E
) {
2544 pad
= *(u_char
*)(buf
->v
+ buf
->l
- 1);
2545 if (buf
->l
< pad
&& 2 < vflag
)
2546 printf("(wrong padding)");
2548 isakmp
->flags
&= ~ISAKMP_FLAG_E
;
2552 snapend
= buf
->v
+ buf
->l
;
2553 isakmp_print(buf
->v
, buf
->l
, NULL
);
2561 #endif /*HAVE_PRINT_ISAKMP_C*/
2564 copy_ph1addresses(iph1
, rmconf
, remote
, local
)
2565 struct ph1handle
*iph1
;
2566 struct remoteconf
*rmconf
;
2567 struct sockaddr
*remote
, *local
;
2569 u_short
*port
= NULL
;
2571 /* address portion must be grabbed from real remote address "remote" */
2572 iph1
->remote
= dupsaddr(remote
);
2573 if (iph1
->remote
== NULL
) {
2579 * if remote has no port # (in case of initiator - from ACQUIRE msg)
2580 * - if remote.conf specifies port #, use that
2581 * - if remote.conf does not, use 500
2582 * if remote has port # (in case of responder - from recvfrom(2))
2583 * respect content of "remote".
2585 switch (iph1
->remote
->sa_family
) {
2587 port
= &((struct sockaddr_in
*)iph1
->remote
)->sin_port
;
2590 *port
= ((struct sockaddr_in
*)rmconf
->remote
)->sin_port
;
2593 *port
= htons(PORT_ISAKMP
);
2597 port
= &((struct sockaddr_in6
*)iph1
->remote
)->sin6_port
;
2600 *port
= ((struct sockaddr_in6
*)rmconf
->remote
)->sin6_port
;
2603 *port
= htons(PORT_ISAKMP
);
2607 plog(LLV_ERROR
, LOCATION
, NULL
,
2608 "invalid family: %d\n", iph1
->remote
->sa_family
);
2613 iph1
->local
= getlocaladdr(iph1
->remote
);
2615 iph1
->local
= dupsaddr(local
);
2616 if (iph1
->local
== NULL
) {
2620 switch (iph1
->local
->sa_family
) {
2622 ((struct sockaddr_in
*)iph1
->local
)->sin_port
2623 = getmyaddrsport(iph1
->local
);
2627 ((struct sockaddr_in6
*)iph1
->local
)->sin6_port
2628 = getmyaddrsport(iph1
->local
);
2632 plog(LLV_ERROR
, LOCATION
, NULL
,
2633 "invalid family: %d\n", iph1
->remote
->sa_family
);
2643 struct ph1handle
*iph1
;
2646 plog(LLV_ERROR
, LOCATION
, iph1
->remote
, "wrong state %u.\n",
2653 struct ph2handle
*iph2
;
2656 plog(LLV_ERROR
, LOCATION
, iph2
->ph1
->remote
, "wrong state %u.\n",
2662 log_ph1established(iph1
)
2663 const struct ph1handle
*iph1
;
2667 src
= strdup(saddr2str(iph1
->local
));
2668 dst
= strdup(saddr2str(iph1
->remote
));
2669 plog(LLV_INFO
, LOCATION
, NULL
,
2670 "ISAKMP-SA established %s-%s spi:%s\n",
2672 isakmp_pindex(&iph1
->index
, 0));