#include <sys/types.h>
#include <sys/param.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
#include "var.h"
#include "misc.h"
#include "vmbuf.h"
#include "plog.h"
#include "sockmisc.h"
#include "schedule.h"
#include "debug.h"
#include "localconf.h"
#include "remoteconf.h"
#include "isakmp_var.h"
#include "isakmp.h"
#include "oakley.h"
#include "handler.h"
#include "ipsec_doi.h"
#include "crypto_openssl.h"
#include "pfkey.h"
#include "isakmp_base.h"
#include "isakmp_inf.h"
#include "vendorid.h"
int
base_i1send(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
struct isakmp_gen *gen;
caddr_t p;
int tlen;
int error = -1;
if (msg != NULL) {
plog(LLV_ERROR, LOCATION, NULL,
"msg has to be NULL in this function.\n");
goto end;
}
if (iph1->status != PHASE1ST_START) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
memset(&iph1->index, 0, sizeof(iph1->index));
isakmp_newcookie((caddr_t)&iph1->index, iph1->remote, iph1->local);
if (ipsecdoi_setid1(iph1) < 0)
goto end;
iph1->sa = ipsecdoi_setph1proposal(iph1->rmconf->proposal);
if (iph1->sa == NULL)
goto end;
iph1->nonce = eay_set_random(iph1->rmconf->nonce_size);
if (iph1->nonce == NULL)
goto end;
tlen = sizeof(struct isakmp)
+ sizeof(*gen) + iph1->sa->l
+ sizeof(*gen) + iph1->id->l
+ sizeof(*gen) + iph1->nonce->l;
iph1->sendbuf = vmalloc(tlen);
if (iph1->sendbuf == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get buffer to send.\n");
goto end;
}
p = set_isakmp_header(iph1->sendbuf, iph1, ISAKMP_NPTYPE_SA);
if (p == NULL)
goto end;
p = set_isakmp_payload(p, iph1->sa, ISAKMP_NPTYPE_ID);
p = set_isakmp_payload(p, iph1->id, ISAKMP_NPTYPE_NONCE);
p = set_isakmp_payload(p, iph1->nonce, ISAKMP_NPTYPE_NONE);
#ifdef HAVE_PRINT_ISAKMP_C
isakmp_printpacket(iph1->sendbuf, iph1->local, iph1->remote, 0);
#endif
iph1->retry_counter = iph1->rmconf->retry_counter;
if (isakmp_ph1resend(iph1) == -1)
goto end;
iph1->status = PHASE1ST_MSG1SENT;
error = 0;
end:
return error;
}
int
base_i2recv(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
vchar_t *pbuf = NULL;
struct isakmp_parse_t *pa;
vchar_t *satmp = NULL;
int error = -1;
if (iph1->status != PHASE1ST_MSG1SENT) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
pbuf = isakmp_parse(msg);
if (pbuf == NULL)
goto end;
pa = (struct isakmp_parse_t *)pbuf->v;
if (pa->type != ISAKMP_NPTYPE_SA) {
plog(LLV_ERROR, LOCATION, iph1->remote,
"received invalid next payload type %d, "
"expecting %d.\n",
pa->type, ISAKMP_NPTYPE_SA);
goto end;
}
if (isakmp_p2ph(&satmp, pa->ptr) < 0)
goto end;
pa++;
for (;
pa->type != ISAKMP_NPTYPE_NONE;
pa++) {
switch (pa->type) {
case ISAKMP_NPTYPE_NONCE:
if (isakmp_p2ph(&iph1->nonce_p, pa->ptr) < 0)
goto end;
break;
case ISAKMP_NPTYPE_ID:
if (isakmp_p2ph(&iph1->id_p, pa->ptr) < 0)
goto end;
break;
case ISAKMP_NPTYPE_VID:
(void)check_vendorid(pa->ptr);
break;
default:
plog(LLV_ERROR, LOCATION, iph1->remote,
"ignore the packet, "
"received unexpecting payload type %d.\n",
pa->type);
goto end;
}
}
if (iph1->nonce_p == NULL || iph1->id_p == NULL) {
plog(LLV_ERROR, LOCATION, iph1->remote,
"few isakmp message received.\n");
goto end;
}
if (ipsecdoi_checkid1(iph1) != 0) {
plog(LLV_ERROR, LOCATION, iph1->remote,
"invalid ID payload.\n");
goto end;
}
if (ipsecdoi_checkph1proposal(satmp, iph1) < 0) {
plog(LLV_ERROR, LOCATION, iph1->remote,
"failed to get valid proposal.\n");
goto end;
}
if (iph1->sa_ret) {
vfree(iph1->sa_ret);
iph1->sa_ret = NULL;
}
iph1->status = PHASE1ST_MSG2RECEIVED;
error = 0;
end:
if (pbuf)
vfree(pbuf);
if (satmp)
vfree(satmp);
if (error) {
VPTRINIT(iph1->nonce_p);
VPTRINIT(iph1->id_p);
}
return error;
}
int
base_i2send(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
struct isakmp_gen *gen;
caddr_t p;
vchar_t *vid = NULL;
int tlen;
int need_cert = 0;
int error = -1;
if (iph1->status != PHASE1ST_MSG2RECEIVED) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
memcpy(&iph1->index.r_ck, &((struct isakmp *)msg->v)->r_ck,
sizeof(cookie_t));
if (oakley_dh_generate(iph1->approval->dhgrp,
&iph1->dhpub, &iph1->dhpriv) < 0)
goto end;
if (iph1->approval->authmethod != OAKLEY_ATTR_AUTH_METHOD_RSASIG
&& iph1->approval->authmethod != OAKLEY_ATTR_AUTH_METHOD_DSSSIG) {
if (oakley_skeyid(iph1) < 0)
goto end;
}
plog(LLV_DEBUG, LOCATION, NULL, "generate HASH_I\n");
iph1->hash = oakley_ph1hash_base_i(iph1, GENERATE);
if (iph1->hash == NULL)
goto end;
tlen = sizeof(struct isakmp);
switch (iph1->approval->authmethod) {
case OAKLEY_ATTR_AUTH_METHOD_PSKEY:
tlen += sizeof(*gen) + iph1->dhpub->l
+ sizeof(*gen) + iph1->hash->l;
if ((vid = set_vendorid(iph1->approval->vendorid)) != NULL)
tlen += sizeof(*gen) + vid->l;
iph1->sendbuf = vmalloc(tlen);
if (iph1->sendbuf == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get buffer to send.\n");
goto end;
}
p = set_isakmp_header(iph1->sendbuf, iph1, ISAKMP_NPTYPE_KE);
if (p == NULL)
goto end;
p = set_isakmp_payload(p, iph1->dhpub, ISAKMP_NPTYPE_HASH);
p = set_isakmp_payload(p, iph1->hash,
vid ? ISAKMP_NPTYPE_VID : ISAKMP_NPTYPE_NONE);
if (vid)
p = set_isakmp_payload(p, vid, ISAKMP_NPTYPE_NONE);
break;
#ifdef HAVE_SIGNING_C
case OAKLEY_ATTR_AUTH_METHOD_DSSSIG:
case OAKLEY_ATTR_AUTH_METHOD_RSASIG:
if (oakley_getmycert(iph1) < 0)
goto end;
if (oakley_getsign(iph1) < 0)
goto end;
if (iph1->cert && iph1->rmconf->send_cert)
need_cert = 1;
tlen += sizeof(*gen) + iph1->dhpub->l
+ sizeof(*gen) + iph1->sig->l;
if (need_cert)
tlen += sizeof(*gen) + iph1->cert->pl->l;
iph1->sendbuf = vmalloc(tlen);
if (iph1->sendbuf == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get buffer to send.\n");
goto end;
}
p = set_isakmp_header(iph1->sendbuf, iph1, ISAKMP_NPTYPE_KE);
if (p == NULL)
goto end;
p = set_isakmp_payload(p, iph1->dhpub, need_cert
? ISAKMP_NPTYPE_CERT
: ISAKMP_NPTYPE_SIG);
if (need_cert)
p = set_isakmp_payload(p, iph1->cert->pl, ISAKMP_NPTYPE_SIG);
p = set_isakmp_payload(p, iph1->sig, ISAKMP_NPTYPE_NONE);
break;
#endif
case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB:
break;
case OAKLEY_ATTR_AUTH_METHOD_RSAENC:
case OAKLEY_ATTR_AUTH_METHOD_RSAREV:
tlen += sizeof(*gen) + iph1->hash->l;
break;
}
#ifdef HAVE_PRINT_ISAKMP_C
isakmp_printpacket(iph1->sendbuf, iph1->local, iph1->remote, 0);
#endif
iph1->retry_counter = iph1->rmconf->retry_counter;
if (isakmp_ph1resend(iph1) == -1)
goto end;
if (add_recvdpkt(iph1->remote, iph1->local, iph1->sendbuf, msg) == -1) {
plog(LLV_ERROR , LOCATION, NULL,
"failed to add a response packet to the tree.\n");
goto end;
}
iph1->status = PHASE1ST_MSG2SENT;
error = 0;
end:
if (vid)
vfree(vid);
return error;
}
int
base_i3recv(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
vchar_t *pbuf = NULL;
struct isakmp_parse_t *pa;
int error = -1;
if (iph1->status != PHASE1ST_MSG2SENT) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
pbuf = isakmp_parse(msg);
if (pbuf == NULL)
goto end;
for (pa = (struct isakmp_parse_t *)pbuf->v;
pa->type != ISAKMP_NPTYPE_NONE;
pa++) {
switch (pa->type) {
case ISAKMP_NPTYPE_KE:
if (isakmp_p2ph(&iph1->dhpub_p, pa->ptr) < 0)
goto end;
break;
case ISAKMP_NPTYPE_HASH:
iph1->pl_hash = (struct isakmp_pl_hash *)pa->ptr;
break;
#ifdef HAVE_SIGNING_C
case ISAKMP_NPTYPE_CERT:
if (oakley_savecert(iph1, pa->ptr) < 0)
goto end;
break;
case ISAKMP_NPTYPE_SIG:
if (isakmp_p2ph(&iph1->sig_p, pa->ptr) < 0)
goto end;
break;
#endif
case ISAKMP_NPTYPE_VID:
(void)check_vendorid(pa->ptr);
break;
default:
plog(LLV_ERROR, LOCATION, iph1->remote,
"ignore the packet, "
"received unexpecting payload type %d.\n",
pa->type);
goto end;
}
}
{
int type;
type = oakley_validate_auth(iph1);
if (type != 0) {
if (type == -1) {
goto end;
}
isakmp_info_send_n1(iph1, type, NULL);
goto end;
}
}
if (oakley_dh_compute(iph1->approval->dhgrp, iph1->dhpub,
iph1->dhpriv, iph1->dhpub_p, &iph1->dhgxy) < 0)
goto end;
if (iph1->approval->authmethod == OAKLEY_ATTR_AUTH_METHOD_RSASIG
|| iph1->approval->authmethod == OAKLEY_ATTR_AUTH_METHOD_DSSSIG) {
if (oakley_skeyid(iph1) < 0)
goto end;
}
if (oakley_skeyid_dae(iph1) < 0)
goto end;
if (oakley_compute_enckey(iph1) < 0)
goto end;
if (oakley_newiv(iph1) < 0)
goto end;
memcpy(iph1->ivm->iv->v, iph1->ivm->ive->v, iph1->ivm->iv->l);
iph1->flags |= ISAKMP_FLAG_E;
iph1->status = PHASE1ST_MSG3RECEIVED;
error = 0;
end:
if (pbuf)
vfree(pbuf);
if (error) {
VPTRINIT(iph1->dhpub_p);
oakley_delcert(iph1->cert_p);
iph1->cert_p = NULL;
oakley_delcert(iph1->crl_p);
iph1->crl_p = NULL;
VPTRINIT(iph1->sig_p);
}
return error;
}
int
base_i3send(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
int error = -1;
if (iph1->status != PHASE1ST_MSG3RECEIVED) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
iph1->status = PHASE1ST_ESTABLISHED;
error = 0;
end:
return error;
}
int
base_r1recv(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
vchar_t *pbuf = NULL;
struct isakmp_parse_t *pa;
int error = -1;
if (iph1->status != PHASE1ST_START) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
pbuf = isakmp_parse(msg);
if (pbuf == NULL)
goto end;
pa = (struct isakmp_parse_t *)pbuf->v;
if (pa->type != ISAKMP_NPTYPE_SA) {
plog(LLV_ERROR, LOCATION, iph1->remote,
"received invalid next payload type %d, "
"expecting %d.\n",
pa->type, ISAKMP_NPTYPE_SA);
goto end;
}
if (isakmp_p2ph(&iph1->sa, pa->ptr) < 0)
goto end;
pa++;
for (;
pa->type != ISAKMP_NPTYPE_NONE;
pa++) {
switch (pa->type) {
case ISAKMP_NPTYPE_NONCE:
if (isakmp_p2ph(&iph1->nonce_p, pa->ptr) < 0)
goto end;
break;
case ISAKMP_NPTYPE_ID:
if (isakmp_p2ph(&iph1->id_p, pa->ptr) < 0)
goto end;
break;
case ISAKMP_NPTYPE_VID:
(void)check_vendorid(pa->ptr);
break;
default:
plog(LLV_ERROR, LOCATION, iph1->remote,
"ignore the packet, "
"received unexpecting payload type %d.\n",
pa->type);
goto end;
}
}
if (iph1->nonce_p == NULL || iph1->id_p == NULL) {
plog(LLV_ERROR, LOCATION, iph1->remote,
"few isakmp message received.\n");
goto end;
}
if (ipsecdoi_checkid1(iph1) != 0) {
plog(LLV_ERROR, LOCATION, iph1->remote,
"invalid ID payload.\n");
goto end;
}
if (ipsecdoi_checkph1proposal(iph1->sa, iph1) < 0) {
plog(LLV_ERROR, LOCATION, iph1->remote,
"failed to get valid proposal.\n");
goto end;
}
iph1->status = PHASE1ST_MSG1RECEIVED;
error = 0;
end:
if (pbuf)
vfree(pbuf);
if (error) {
VPTRINIT(iph1->sa);
VPTRINIT(iph1->nonce_p);
VPTRINIT(iph1->id_p);
}
return error;
}
int
base_r1send(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
struct isakmp_gen *gen;
caddr_t p;
int tlen;
int error = -1;
if (iph1->status != PHASE1ST_MSG1RECEIVED) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
isakmp_newcookie((caddr_t)&iph1->index.r_ck, iph1->remote, iph1->local);
if (ipsecdoi_setid1(iph1) < 0)
goto end;
iph1->nonce = eay_set_random(iph1->rmconf->nonce_size);
if (iph1->nonce == NULL)
goto end;
tlen = sizeof(struct isakmp)
+ sizeof(*gen) + iph1->sa_ret->l
+ sizeof(*gen) + iph1->id->l
+ sizeof(*gen) + iph1->nonce->l;
iph1->sendbuf = vmalloc(tlen);
if (iph1->sendbuf == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get buffer to send.\n");
goto end;
}
p = set_isakmp_header(iph1->sendbuf, iph1, ISAKMP_NPTYPE_SA);
if (p == NULL)
goto end;
p = set_isakmp_payload(p, iph1->sa_ret, ISAKMP_NPTYPE_ID);
p = set_isakmp_payload(p, iph1->id, ISAKMP_NPTYPE_NONCE);
p = set_isakmp_payload(p, iph1->nonce, ISAKMP_NPTYPE_NONE);
#ifdef HAVE_PRINT_ISAKMP_C
isakmp_printpacket(iph1->sendbuf, iph1->local, iph1->remote, 0);
#endif
iph1->retry_counter = iph1->rmconf->retry_counter;
if (isakmp_ph1resend(iph1) == -1)
goto end;
if (add_recvdpkt(iph1->remote, iph1->local, iph1->sendbuf, msg) == -1) {
plog(LLV_ERROR , LOCATION, NULL,
"failed to add a response packet to the tree.\n");
goto end;
}
iph1->status = PHASE1ST_MSG1SENT;
error = 0;
end:
if (iph1->sa_ret) {
vfree(iph1->sa_ret);
iph1->sa_ret = NULL;
}
return error;
}
int
base_r2recv(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
vchar_t *pbuf = NULL;
struct isakmp_parse_t *pa;
int error = -1;
if (iph1->status != PHASE1ST_MSG1SENT) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
pbuf = isakmp_parse(msg);
if (pbuf == NULL)
goto end;
iph1->pl_hash = NULL;
for (pa = (struct isakmp_parse_t *)pbuf->v;
pa->type != ISAKMP_NPTYPE_NONE;
pa++) {
switch (pa->type) {
case ISAKMP_NPTYPE_KE:
if (isakmp_p2ph(&iph1->dhpub_p, pa->ptr) < 0)
goto end;
break;
case ISAKMP_NPTYPE_HASH:
iph1->pl_hash = (struct isakmp_pl_hash *)pa->ptr;
break;
#ifdef HAVE_SIGNING_C
case ISAKMP_NPTYPE_CERT:
if (oakley_savecert(iph1, pa->ptr) < 0)
goto end;
break;
case ISAKMP_NPTYPE_SIG:
if (isakmp_p2ph(&iph1->sig_p, pa->ptr) < 0)
goto end;
break;
#endif
case ISAKMP_NPTYPE_VID:
(void)check_vendorid(pa->ptr);
break;
default:
plog(LLV_ERROR, LOCATION, iph1->remote,
"ignore the packet, "
"received unexpecting payload type %d.\n",
pa->type);
goto end;
}
}
if (oakley_dh_generate(iph1->approval->dhgrp,
&iph1->dhpub, &iph1->dhpriv) < 0)
goto end;
if (oakley_dh_compute(iph1->approval->dhgrp, iph1->dhpub,
iph1->dhpriv, iph1->dhpub_p, &iph1->dhgxy) < 0)
goto end;
if (oakley_skeyid(iph1) < 0)
goto end;
{
int type;
type = oakley_validate_auth(iph1);
if (type != 0) {
if (type == -1) {
goto end;
}
isakmp_info_send_n1(iph1, type, NULL);
goto end;
}
}
iph1->status = PHASE1ST_MSG2RECEIVED;
error = 0;
end:
if (pbuf)
vfree(pbuf);
if (error) {
VPTRINIT(iph1->dhpub_p);
oakley_delcert(iph1->cert_p);
iph1->cert_p = NULL;
oakley_delcert(iph1->crl_p);
iph1->crl_p = NULL;
VPTRINIT(iph1->sig_p);
}
return error;
}
int
base_r2send(iph1, msg)
struct ph1handle *iph1;
vchar_t *msg;
{
struct isakmp_gen *gen;
char *p;
vchar_t *vid = NULL;
int tlen;
int need_cert = 0;
int error = -1;
if (iph1->status != PHASE1ST_MSG2RECEIVED) {
plog(LLV_ERROR, LOCATION, NULL,
"status mismatched %d.\n", iph1->status);
goto end;
}
plog(LLV_DEBUG, LOCATION, NULL, "generate HASH_I\n");
switch (iph1->approval->authmethod) {
case OAKLEY_ATTR_AUTH_METHOD_PSKEY:
case OAKLEY_ATTR_AUTH_METHOD_RSAENC:
case OAKLEY_ATTR_AUTH_METHOD_RSAREV:
iph1->hash = oakley_ph1hash_common(iph1, GENERATE);
break;
case OAKLEY_ATTR_AUTH_METHOD_DSSSIG:
case OAKLEY_ATTR_AUTH_METHOD_RSASIG:
case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB:
iph1->hash = oakley_ph1hash_base_r(iph1, GENERATE);
break;
default:
plog(LLV_ERROR, LOCATION, NULL,
"invalid authentication method %d\n",
iph1->approval->authmethod);
goto end;
}
if (iph1->hash == NULL)
goto end;
tlen = sizeof(struct isakmp);
switch (iph1->approval->authmethod) {
case OAKLEY_ATTR_AUTH_METHOD_PSKEY:
tlen += sizeof(*gen) + iph1->dhpub->l
+ sizeof(*gen) + iph1->hash->l;
if ((vid = set_vendorid(iph1->approval->vendorid)) != NULL)
tlen += sizeof(*gen) + vid->l;
iph1->sendbuf = vmalloc(tlen);
if (iph1->sendbuf == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get iph1->sendbuf to send.\n");
goto end;
}
p = set_isakmp_header(iph1->sendbuf, iph1, ISAKMP_NPTYPE_KE);
if (p == NULL)
goto end;
p = set_isakmp_payload(p, iph1->dhpub, ISAKMP_NPTYPE_HASH);
p = set_isakmp_payload(p, iph1->hash,
vid ? ISAKMP_NPTYPE_VID : ISAKMP_NPTYPE_NONE);
if (vid)
p = set_isakmp_payload(p, vid, ISAKMP_NPTYPE_NONE);
break;
#ifdef HAVE_SIGNING_C
case OAKLEY_ATTR_AUTH_METHOD_DSSSIG:
case OAKLEY_ATTR_AUTH_METHOD_RSASIG:
if (oakley_getmycert(iph1) < 0)
goto end;
if (oakley_getsign(iph1) < 0)
goto end;
if (iph1->cert && iph1->rmconf->send_cert)
need_cert = 1;
tlen += sizeof(*gen) + iph1->dhpub->l
+ sizeof(*gen) + iph1->sig->l;
if (need_cert)
tlen += sizeof(*gen) + iph1->cert->pl->l;
iph1->sendbuf = vmalloc(tlen);
if (iph1->sendbuf == NULL) {
plog(LLV_ERROR, LOCATION, NULL,
"failed to get buffer to send.\n");
goto end;
}
p = set_isakmp_header(iph1->sendbuf, iph1, ISAKMP_NPTYPE_KE);
if (p == NULL)
goto end;
p = set_isakmp_payload(p, iph1->dhpub, need_cert
? ISAKMP_NPTYPE_CERT
: ISAKMP_NPTYPE_SIG);
if (need_cert)
p = set_isakmp_payload(p, iph1->cert->pl, ISAKMP_NPTYPE_SIG);
p = set_isakmp_payload(p, iph1->sig, ISAKMP_NPTYPE_NONE);
break;
#endif
case OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB:
break;
case OAKLEY_ATTR_AUTH_METHOD_RSAENC:
case OAKLEY_ATTR_AUTH_METHOD_RSAREV:
tlen += sizeof(*gen) + iph1->hash->l;
break;
}
#ifdef HAVE_PRINT_ISAKMP_C
isakmp_printpacket(iph1->sendbuf, iph1->local, iph1->remote, 0);
#endif
if (isakmp_send(iph1, iph1->sendbuf) < 0)
goto end;
if (add_recvdpkt(iph1->remote, iph1->local, iph1->sendbuf, msg) == -1) {
plog(LLV_ERROR , LOCATION, NULL,
"failed to add a response packet to the tree.\n");
goto end;
}
if (oakley_skeyid_dae(iph1) < 0)
goto end;
if (oakley_compute_enckey(iph1) < 0)
goto end;
if (oakley_newiv(iph1) < 0)
goto end;
iph1->flags |= ISAKMP_FLAG_E;
iph1->status = PHASE1ST_ESTABLISHED;
error = 0;
end:
if (vid)
vfree(vid);
return error;
}