1 /* $KAME: proposal.c,v 1.45 2001/11/16 04:08:10 sakane Exp $ */
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <sys/queue.h>
37 #include <netkey/key_var.h>
38 #include <netinet/in.h>
39 #include <netinet6/ipsec.h>
55 #include "isakmp_var.h"
57 #include "ipsec_doi.h"
58 #include "algorithm.h"
61 #include "localconf.h"
62 #include "remoteconf.h"
69 * modules for ipsec sa spec
76 new = racoon_calloc(1, sizeof(*new));
88 new = racoon_calloc(1, sizeof(*new));
95 /* set saprop to last part of the prop tree */
108 for (p
= *head
; p
->next
; p
= p
->next
)
115 /* set saproto to the end of the proto tree in saprop */
123 for (p
= pp
->head
; p
&& p
->next
; p
= p
->next
)
133 /* set saproto to the top of the proto tree in saprop */
135 inssaprotorev(pp
, new)
139 new->next
= pp
->head
;
150 new = racoon_calloc(1, sizeof(*new));
157 /* set saproto to last part of the proto tree in saprop */
165 for (tr
= pr
->head
; tr
&& tr
->next
; tr
= tr
->next
)
176 * take a single match between saprop. allocate a new proposal and return it
177 * for future use (like picking single proposal from a bundle).
178 * pp1: peer's proposal.
180 * NOTE: In the case of initiator, must be ensured that there is no
181 * modification of the proposal by calling cmp_aproppair_i() before
183 * XXX cannot understand the comment!
186 cmpsaprop_alloc(ph1
, pp1
, pp2
, side
)
187 struct ph1handle
*ph1
;
188 const struct saprop
*pp1
, *pp2
;
191 struct saprop
*newpp
= NULL
;
192 struct saproto
*pr1
, *pr2
, *newpr
= NULL
;
193 struct satrns
*tr1
, *tr2
, *newtr
;
194 const int ordermatters
= 0;
200 plog(LLV_ERROR
, LOCATION
, NULL
,
201 "failed to allocate saprop.\n");
204 newpp
->prop_no
= pp1
->prop_no
;
206 /* see proposal.h about lifetime/key length and PFS selection. */
208 /* check time/bytes lifetime and PFS */
209 switch (ph1
->rmconf
->pcheck_level
) {
210 case PROP_CHECK_OBEY
:
211 newpp
->lifetime
= pp1
->lifetime
;
212 newpp
->lifebyte
= pp1
->lifebyte
;
213 newpp
->pfs_group
= pp1
->pfs_group
;
215 case PROP_CHECK_STRICT
:
216 if (pp1
->lifetime
> pp2
->lifetime
) {
217 plog(LLV_ERROR
, LOCATION
, NULL
,
218 "long lifetime proposed: "
220 pp2
->lifetime
, pp1
->lifetime
);
223 if (pp1
->lifebyte
> pp2
->lifebyte
) {
224 plog(LLV_ERROR
, LOCATION
, NULL
,
225 "long lifebyte proposed: "
227 pp2
->lifebyte
, pp1
->lifebyte
);
230 newpp
->lifetime
= pp1
->lifetime
;
231 newpp
->lifebyte
= pp1
->lifebyte
;
234 if (pp2
->pfs_group
!= 0 && pp1
->pfs_group
!= pp2
->pfs_group
) {
235 plog(LLV_ERROR
, LOCATION
, NULL
,
236 "pfs group mismatched: "
238 pp2
->pfs_group
, pp1
->pfs_group
);
241 newpp
->pfs_group
= pp1
->pfs_group
;
243 case PROP_CHECK_CLAIM
:
245 if (pp1
->lifetime
<= pp2
->lifetime
) {
246 newpp
->lifetime
= pp1
->lifetime
;
248 newpp
->lifetime
= pp2
->lifetime
;
249 newpp
->claim
|= IPSECDOI_ATTR_SA_LD_TYPE_SEC
;
250 plog(LLV_NOTIFY
, LOCATION
, NULL
,
253 pp2
->lifetime
, pp1
->lifetime
);
257 if (pp1
->lifebyte
> pp2
->lifebyte
) {
258 newpp
->lifebyte
= pp2
->lifebyte
;
259 newpp
->claim
|= IPSECDOI_ATTR_SA_LD_TYPE_SEC
;
260 plog(LLV_NOTIFY
, LOCATION
, NULL
,
263 pp2
->lifebyte
, pp1
->lifebyte
);
265 newpp
->lifebyte
= pp1
->lifebyte
;
269 case PROP_CHECK_EXACT
:
270 if (pp1
->lifetime
!= pp2
->lifetime
) {
271 plog(LLV_ERROR
, LOCATION
, NULL
,
272 "lifetime mismatched: "
274 pp2
->lifetime
, pp1
->lifetime
);
277 if (pp1
->lifebyte
!= pp2
->lifebyte
) {
278 plog(LLV_ERROR
, LOCATION
, NULL
,
279 "lifebyte mismatched: "
281 pp2
->lifebyte
, pp1
->lifebyte
);
284 if (pp1
->pfs_group
!= pp2
->pfs_group
) {
285 plog(LLV_ERROR
, LOCATION
, NULL
,
286 "pfs group mismatched: "
288 pp2
->pfs_group
, pp1
->pfs_group
);
291 newpp
->lifebyte
= pp1
->lifebyte
;
292 newpp
->lifebyte
= pp1
->lifebyte
;
293 newpp
->pfs_group
= pp1
->pfs_group
;
296 plog(LLV_ERROR
, LOCATION
, NULL
,
297 "invalid pcheck_level why?.\n");
302 for (pr1
= pp1
->head
; pr1
; pr1
= pr1
->next
)
304 for (pr2
= pp2
->head
; pr2
; pr2
= pr2
->next
)
309 /* check protocol order */
316 * XXX does not work if we have multiple proposals
317 * with the same proto_id
323 for (pr1
= pp1
->head
; pr1
; pr1
= pr1
->next
) {
324 if (pr1
->proto_id
== pr2
->proto_id
)
331 for (pr2
= pp2
->head
; pr2
; pr2
= pr2
->next
) {
332 if (pr2
->proto_id
== pr1
->proto_id
)
341 if (pr1
->proto_id
!= pr2
->proto_id
) {
342 plog(LLV_ERROR
, LOCATION
, NULL
,
343 "proto_id mismatched: "
345 pr2
->proto_id
, pr1
->proto_id
);
349 if (pr1
->spisize
== pr2
->spisize
)
351 else if (pr1
->proto_id
== IPSECDOI_PROTO_IPCOMP
) {
353 * draft-shacham-ippcp-rfc2393bis-05.txt:
354 * need to accept 16bit and 32bit SPI (CPI) for IPComp.
356 if (pr1
->spisize
== sizeof(u_int16_t
) &&
357 pr2
->spisize
== sizeof(u_int32_t
)) {
359 } else if (pr1
->spisize
== sizeof(u_int16_t
) &&
360 pr2
->spisize
== sizeof(u_int32_t
)) {
364 plog(LLV_ERROR
, LOCATION
, NULL
,
365 "IPComp SPI size promoted "
366 "from 16bit to 32bit\n");
370 plog(LLV_ERROR
, LOCATION
, NULL
,
371 "spisize mismatched: "
373 pr2
->spisize
, pr1
->spisize
);
376 if (pr1
->encmode
!= pr2
->encmode
) {
377 plog(LLV_ERROR
, LOCATION
, NULL
,
378 "encmode mismatched: "
380 pr2
->encmode
, pr1
->encmode
);
384 for (tr1
= pr1
->head
; tr1
; tr1
= tr1
->next
) {
385 for (tr2
= pr2
->head
; tr2
; tr2
= tr2
->next
) {
386 if (cmpsatrns(tr1
, tr2
) == 0)
394 newpr
= newsaproto();
396 plog(LLV_ERROR
, LOCATION
, NULL
,
397 "failed to allocate saproto.\n");
400 newpr
->proto_id
= pr1
->proto_id
;
401 newpr
->spisize
= pr1
->spisize
;
402 newpr
->encmode
= pr1
->encmode
;
403 newpr
->spi
= pr2
->spi
; /* copy my SPI */
404 newpr
->spi_p
= pr1
->spi
; /* copy peer's SPI */
405 newpr
->reqid_in
= pr2
->reqid_in
;
406 newpr
->reqid_out
= pr2
->reqid_out
;
410 plog(LLV_ERROR
, LOCATION
, NULL
,
411 "failed to allocate satrns.\n");
414 newtr
->trns_no
= tr1
->trns_no
;
415 newtr
->trns_id
= tr1
->trns_id
;
416 newtr
->encklen
= tr1
->encklen
;
417 newtr
->authtype
= tr1
->authtype
;
419 inssatrns(newpr
, newtr
);
420 inssaproto(newpp
, newpr
);
426 /* XXX should check if we have visited all items or not */
440 /* should be matched all protocols in a proposal */
441 if (pr1
!= NULL
|| pr2
!= NULL
)
451 /* take a single match between saprop. returns 0 if pp1 equals to pp2. */
454 const struct saprop
*pp1
, *pp2
;
456 if (pp1
->pfs_group
!= pp2
->pfs_group
) {
457 plog(LLV_WARNING
, LOCATION
, NULL
,
458 "pfs_group mismatch. mine:%d peer:%d\n",
459 pp1
->pfs_group
, pp2
->pfs_group
);
463 if (pp1
->lifetime
> pp2
->lifetime
) {
464 plog(LLV_WARNING
, LOCATION
, NULL
,
465 "less lifetime proposed. mine:%d peer:%d\n",
466 pp1
->lifetime
, pp2
->lifetime
);
469 if (pp1
->lifebyte
> pp2
->lifebyte
) {
470 plog(LLV_WARNING
, LOCATION
, NULL
,
471 "less lifebyte proposed. mine:%d peer:%d\n",
472 pp1
->lifebyte
, pp2
->lifebyte
);
480 * take a single match between satrns. returns 0 if tr1 equals to tr2.
486 const struct satrns
*tr1
, *tr2
;
488 if (tr1
->trns_id
!= tr2
->trns_id
) {
489 plog(LLV_ERROR
, LOCATION
, NULL
,
490 "trns_id mismatched: "
492 tr2
->trns_id
, tr1
->trns_id
);
495 if (tr1
->authtype
!= tr2
->authtype
) {
496 plog(LLV_ERROR
, LOCATION
, NULL
,
497 "authtype mismatched: "
499 tr2
->authtype
, tr1
->authtype
);
504 * At this moment for interoperability, the responder obey
505 * the initiator. It should be defined a notify message.
507 if (tr1
->encklen
> tr2
->encklen
) {
508 plog(LLV_WARNING
, LOCATION
, NULL
,
509 "less key length proposed, "
510 "mine:%d peer:%d. Use initiaotr's one.\n",
511 tr2
->encklen
, tr1
->encklen
);
519 set_satrnsbysainfo(pr
, sainfo
)
521 struct sainfo
*sainfo
;
523 struct sainfoalg
*a
, *b
;
524 struct satrns
*newtr
;
527 switch (pr
->proto_id
) {
528 case IPSECDOI_PROTO_IPSEC_AH
:
529 if (sainfo
->algs
[algclass_ipsec_auth
] == NULL
) {
530 plog(LLV_ERROR
, LOCATION
, NULL
,
531 "no auth algorithm found\n");
535 for (a
= sainfo
->algs
[algclass_ipsec_auth
]; a
; a
= a
->next
) {
537 if (a
->alg
== IPSECDOI_ATTR_AUTH_NONE
)
540 /* allocate satrns */
543 plog(LLV_ERROR
, LOCATION
, NULL
,
544 "failed to allocate satrns.\n");
548 newtr
->trns_no
= t
++;
549 newtr
->trns_id
= ipsecdoi_authalg2trnsid(a
->alg
);
550 newtr
->authtype
= a
->alg
;
552 inssatrns(pr
, newtr
);
555 case IPSECDOI_PROTO_IPSEC_ESP
:
556 if (sainfo
->algs
[algclass_ipsec_enc
] == NULL
) {
557 plog(LLV_ERROR
, LOCATION
, NULL
,
558 "no encryption algorithm found\n");
562 for (a
= sainfo
->algs
[algclass_ipsec_enc
]; a
; a
= a
->next
) {
563 for (b
= sainfo
->algs
[algclass_ipsec_auth
]; b
; b
= b
->next
) {
564 /* allocate satrns */
567 plog(LLV_ERROR
, LOCATION
, NULL
,
568 "failed to allocate satrns.\n");
572 newtr
->trns_no
= t
++;
573 newtr
->trns_id
= a
->alg
;
574 newtr
->encklen
= a
->encklen
;
575 newtr
->authtype
= b
->alg
;
577 inssatrns(pr
, newtr
);
581 case IPSECDOI_PROTO_IPCOMP
:
582 if (sainfo
->algs
[algclass_ipsec_comp
] == NULL
) {
583 plog(LLV_ERROR
, LOCATION
, NULL
,
584 "no ipcomp algorithm found\n");
588 for (a
= sainfo
->algs
[algclass_ipsec_comp
]; a
; a
= a
->next
) {
590 /* allocate satrns */
593 plog(LLV_ERROR
, LOCATION
, NULL
,
594 "failed to allocate satrns.\n");
598 newtr
->trns_no
= t
++;
599 newtr
->trns_id
= a
->alg
;
600 newtr
->authtype
= IPSECDOI_ATTR_AUTH_NONE
; /*no auth*/
602 inssatrns(pr
, newtr
);
606 plog(LLV_ERROR
, LOCATION
, NULL
,
607 "unknown proto_id (%d).\n", pr
->proto_id
);
611 /* no proposal found */
612 if (pr
->head
== NULL
) {
613 plog(LLV_ERROR
, LOCATION
, NULL
, "no algorithms found.\n");
620 flushsatrns(pr
->head
);
626 struct prop_pair
*p0
;
628 struct prop_pair
*p
, *t
;
629 struct saprop
*newpp
;
630 struct saproto
*newpr
;
631 struct satrns
*newtr
;
637 /* allocate ipsec a sa proposal */
640 plog(LLV_ERROR
, LOCATION
, NULL
,
641 "failed to allocate saprop.\n");
644 newpp
->prop_no
= p0
->prop
->p_no
;
645 /* lifetime & lifebyte must be updated later */
647 for (p
= p0
; p
; p
= p
->next
) {
649 /* allocate ipsec sa protocol */
650 newpr
= newsaproto();
652 plog(LLV_ERROR
, LOCATION
, NULL
,
653 "failed to allocate saproto.\n");
658 /* XXX should be handled isakmp cookie */
659 if (sizeof(newpr
->spi
) < p
->prop
->spi_size
) {
660 plog(LLV_ERROR
, LOCATION
, NULL
,
661 "invalid spi size %d.\n", p
->prop
->spi_size
);
666 * XXX SPI bits are left-filled, for use with IPComp.
667 * we should be switching to variable-length spi field...
669 newpr
->proto_id
= p
->prop
->proto_id
;
670 newpr
->spisize
= p
->prop
->spi_size
;
671 memset(&newpr
->spi
, 0, sizeof(newpr
->spi
));
672 spi
= (u_int8_t
*)&newpr
->spi
;
673 spi
+= sizeof(newpr
->spi
);
674 spi
-= p
->prop
->spi_size
;
675 memcpy(spi
, p
->prop
+ 1, p
->prop
->spi_size
);
677 newpr
->reqid_out
= 0;
679 for (t
= p
; t
; t
= t
->tnext
) {
681 plog(LLV_DEBUG
, LOCATION
, NULL
,
682 "prop#=%d prot-id=%s spi-size=%d "
683 "#trns=%d trns#=%d trns-id=%s\n",
685 s_ipsecdoi_proto(t
->prop
->proto_id
),
686 t
->prop
->spi_size
, t
->prop
->num_t
,
688 s_ipsecdoi_trns(t
->prop
->proto_id
,
691 /* allocate ipsec sa transform */
694 plog(LLV_ERROR
, LOCATION
, NULL
,
695 "failed to allocate satrns.\n");
699 if (ipsecdoi_t2satrns(t
->trns
, newpp
, newpr
, newtr
) < 0) {
704 inssatrns(newpr
, newtr
);
708 * If the peer does not specify encryption mode, use
709 * transport mode by default. This is to conform to
710 * draft-shacham-ippcp-rfc2393bis-08.txt (explicitly specifies
711 * that unspecified == transport), as well as RFC2407
712 * (unspecified == implementation dependent default).
714 if (newpr
->encmode
== 0)
715 newpr
->encmode
= IPSECDOI_ATTR_ENC_MODE_TRNS
;
717 inssaproto(newpp
, newpr
);
731 struct saprop
*p
, *save
;
733 for (p
= head
; p
!= NULL
; p
= save
) {
735 flushsaproto(p
->head
);
744 struct saproto
*head
;
746 struct saproto
*p
, *save
;
748 for (p
= head
; p
!= NULL
; p
= save
) {
750 flushsatrns(p
->head
);
763 struct satrns
*p
, *save
;
765 for (p
= head
; p
!= NULL
; p
= save
) {
774 * print multiple proposals
779 const struct saprop
*pp
;
781 const struct saprop
*p
;
784 plog(pri
, LOCATION
, NULL
, "(null)");
788 for (p
= pp
; p
; p
= p
->next
) {
789 printsaprop0(pri
, p
);
796 * print one proposal.
799 printsaprop0(pri
, pp
)
801 const struct saprop
*pp
;
803 const struct saproto
*p
;
808 for (p
= pp
->head
; p
; p
= p
->next
) {
809 printsaproto(pri
, p
);
816 printsaproto(pri
, pr
)
818 const struct saproto
*pr
;
825 plog(pri
, LOCATION
, NULL
,
826 " (proto_id=%s spisize=%d spi=%08lx spi_p=%08lx "
827 "encmode=%s reqid=%d:%d)\n",
828 s_ipsecdoi_proto(pr
->proto_id
),
830 (unsigned long)ntohl(pr
->spi
),
831 (unsigned long)ntohl(pr
->spi_p
),
832 s_ipsecdoi_attr_v(IPSECDOI_ATTR_ENC_MODE
, pr
->encmode
),
833 pr
->reqid_in
, pr
->reqid_out
);
835 for (tr
= pr
->head
; tr
; tr
= tr
->next
) {
836 printsatrns(pri
, pr
->proto_id
, tr
);
843 printsatrns(pri
, proto_id
, tr
)
846 const struct satrns
*tr
;
852 case IPSECDOI_PROTO_IPSEC_AH
:
853 plog(pri
, LOCATION
, NULL
,
854 " (trns_id=%s authtype=%s)\n",
855 s_ipsecdoi_trns(proto_id
, tr
->trns_id
),
856 s_ipsecdoi_attr_v(IPSECDOI_ATTR_AUTH
, tr
->authtype
));
858 case IPSECDOI_PROTO_IPSEC_ESP
:
859 plog(pri
, LOCATION
, NULL
,
860 " (trns_id=%s encklen=%d authtype=%s)\n",
861 s_ipsecdoi_trns(proto_id
, tr
->trns_id
),
863 s_ipsecdoi_attr_v(IPSECDOI_ATTR_AUTH
, tr
->authtype
));
865 case IPSECDOI_PROTO_IPCOMP
:
866 plog(pri
, LOCATION
, NULL
,
868 s_ipsecdoi_trns(proto_id
, tr
->trns_id
));
871 plog(pri
, LOCATION
, NULL
,
872 "(unknown proto_id %d)\n", proto_id
);
879 print_proppair0(pri
, p
, level
)
886 memset(spc
, ' ', sizeof(spc
));
887 spc
[sizeof(spc
) - 1] = '\0';
892 plog(pri
, LOCATION
, NULL
,
893 "%s%p: next=%p tnext=%p\n", spc
, p
, p
->next
, p
->tnext
);
895 print_proppair0(pri
, p
->next
, level
+ 1);
897 print_proppair0(pri
, p
->tnext
, level
+ 1);
901 print_proppair(pri
, p
)
905 print_proppair0(pri
, p
, 1);
909 set_proposal_from_policy(iph2
, sp_main
, sp_sub
)
910 struct ph2handle
*iph2
;
911 struct secpolicy
*sp_main
, *sp_sub
;
913 struct saprop
*newpp
;
914 struct ipsecrequest
*req
;
915 int encmodesv
= IPSEC_MODE_TRANSPORT
; /* use only when complex_bundle */
919 plog(LLV_ERROR
, LOCATION
, NULL
,
920 "failed to allocate saprop.\n");
924 newpp
->lifetime
= iph2
->sainfo
->lifetime
;
925 newpp
->lifebyte
= iph2
->sainfo
->lifebyte
;
926 newpp
->pfs_group
= iph2
->sainfo
->pfs_group
;
928 if (lcconf
->complex_bundle
)
932 * decide the encryption mode of this SA bundle.
933 * the mode becomes tunnel mode when there is even one policy
934 * of tunnel mode in the SPD. otherwise the mode becomes
937 encmodesv
= IPSEC_MODE_TRANSPORT
;
938 for (req
= sp_main
->req
; req
; req
= req
->next
) {
939 if (req
->saidx
.mode
== IPSEC_MODE_TUNNEL
) {
940 encmodesv
= pfkey2ipsecdoi_mode(req
->saidx
.mode
);
946 for (req
= sp_main
->req
; req
; req
= req
->next
) {
947 struct saproto
*newpr
;
948 caddr_t paddr
= NULL
;
951 * check if SA bundle ?
952 * nested SAs negotiation is NOT supported.
953 * me +--- SA1 ---+ peer1
954 * me +--- SA2 --------------+ peer2
956 if (req
->saidx
.src
.ss_len
&& req
->saidx
.dst
.ss_len
) {
958 /* check the end of ip addresses of SA */
959 if (iph2
->side
== INITIATOR
)
960 paddr
= (caddr_t
)&req
->saidx
.dst
;
962 paddr
= (caddr_t
)&req
->saidx
.src
;
964 if (memcmp(iph2
->dst
, paddr
, iph2
->dst
->sa_len
)){
965 plog(LLV_ERROR
, LOCATION
, NULL
,
966 "not supported nested SA.");
971 /* allocate ipsec sa protocol */
972 newpr
= newsaproto();
974 plog(LLV_ERROR
, LOCATION
, NULL
,
975 "failed to allocate saproto.\n");
979 newpr
->proto_id
= ipproto2doi(req
->saidx
.proto
);
981 if (lcconf
->complex_bundle
)
982 newpr
->encmode
= pfkey2ipsecdoi_mode(req
->saidx
.mode
);
984 newpr
->encmode
= encmodesv
;
986 newpr
->reqid_out
= req
->saidx
.reqid
;
988 if (set_satrnsbysainfo(newpr
, iph2
->sainfo
) < 0) {
989 plog(LLV_ERROR
, LOCATION
, NULL
,
990 "failed to get algorithms.\n");
994 /* set new saproto */
995 inssaprotorev(newpp
, newpr
);
998 /* get reqid_in from inbound policy */
1005 pr
->reqid_in
= req
->saidx
.reqid
;
1010 plog(LLV_NOTIFY
, LOCATION
, NULL
,
1011 "There is a difference "
1012 "between the in/out bound policies in SPD.\n");
1016 iph2
->proposal
= newpp
;
1018 printsaprop0(LLV_DEBUG
, newpp
);
1026 * generate a policy from peer's proposal.
1027 * this function unconditionally choices first proposal in SA payload
1031 set_proposal_from_proposal(iph2
)
1032 struct ph2handle
*iph2
;
1034 struct saprop
*newpp
= NULL
, *pp0
, *pp_peer
;
1035 struct saproto
*newpr
= NULL
, *pr
;
1036 struct prop_pair
**pair
;
1040 /* get proposal pair */
1041 pair
= get_proppair(iph2
->sa
, IPSECDOI_TYPE_PH2
);
1046 * make my proposal according as the client proposal.
1047 * XXX assumed there is only one proposal even if it's the SA bundle.
1049 for (i
= 0; i
< MAXPROPPAIRLEN
; i
++) {
1050 if (pair
[i
] == NULL
)
1052 pp_peer
= aproppair2saprop(pair
[i
]);
1053 if (pp_peer
== NULL
)
1058 plog(LLV_ERROR
, LOCATION
, NULL
,
1059 "failed to allocate saprop.\n");
1063 pp0
->lifetime
= iph2
->sainfo
->lifetime
;
1064 pp0
->lifebyte
= iph2
->sainfo
->lifebyte
;
1065 pp0
->pfs_group
= iph2
->sainfo
->pfs_group
;
1067 if (pp_peer
->next
!= NULL
) {
1068 plog(LLV_ERROR
, LOCATION
, NULL
,
1069 "pp_peer is inconsistency, ignore it.\n");
1073 for (pr
= pp_peer
->head
; pr
; pr
= pr
->next
) {
1075 newpr
= newsaproto();
1076 if (newpr
== NULL
) {
1077 plog(LLV_ERROR
, LOCATION
, NULL
,
1078 "failed to allocate saproto.\n");
1081 newpr
->proto_id
= pr
->proto_id
;
1082 newpr
->spisize
= pr
->spisize
;
1083 newpr
->encmode
= pr
->encmode
;
1085 newpr
->spi_p
= pr
->spi
; /* copy peer's SPI */
1086 newpr
->reqid_in
= 0;
1087 newpr
->reqid_out
= 0;
1090 if (set_satrnsbysainfo(newpr
, iph2
->sainfo
) < 0) {
1091 plog(LLV_ERROR
, LOCATION
, NULL
,
1092 "failed to get algorithms.\n");
1096 inssaproto(pp0
, newpr
);
1097 inssaprop(&newpp
, pp0
);
1100 plog(LLV_DEBUG
, LOCATION
, NULL
, "make a proposal from peer's:\n");
1101 printsaprop0(LLV_DEBUG
, newpp
);
1103 iph2
->proposal
= newpp
;
1111 free_proppair(pair
);