-/* $OpenBSD: eap.c,v 1.23 2023/05/23 13:12:19 claudio Exp $ */
+/* $OpenBSD: eap.c,v 1.24 2023/05/23 13:57:14 claudio Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
{
struct eap_message *eap;
- if ((eap = ibuf_advance(e, sizeof(*eap))) == NULL)
+ if ((eap = ibuf_reserve(e, sizeof(*eap))) == NULL)
return (-1);
eap->eap_code = EAP_CODE_REQUEST;
eap->eap_id = 0;
/* CERT payload */
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((cert = ibuf_advance(e, sizeof(*cert))) == NULL)
+ if ((cert = ibuf_reserve(e, sizeof(*cert))) == NULL)
goto done;
cert->cert_type = certid->id_type;
if (ibuf_cat(e, certid->id_buf) != 0)
goto done;
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((cert = ibuf_advance(e, sizeof(*cert))) == NULL)
+ if ((cert = ibuf_reserve(e, sizeof(*cert))) == NULL)
goto done;
cert->cert_type = sa->sa_scert[i].id_type;
if (ibuf_cat(e, sa->sa_scert[i].id_buf) != 0)
/* AUTH payload */
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((auth = ibuf_advance(e, sizeof(*auth))) == NULL)
+ if ((auth = ibuf_reserve(e, sizeof(*auth))) == NULL)
goto done;
auth->auth_method = sa->sa_localauth.id_type;
if (ibuf_cat(e, sa->sa_localauth.id_buf) != 0)
if ((e = ibuf_static()) == NULL)
return (-1);
- if ((eap = ibuf_advance(e, sizeof(*eap))) == NULL)
+ if ((eap = ibuf_reserve(e, sizeof(*eap))) == NULL)
goto done;
eap->eap_code = EAP_CODE_REQUEST;
eap->eap_id = eap_id + 1;
eap->eap_length = htobe16(sizeof(*eap) +
sizeof(*ms) + strlen(name));
- if ((ms = ibuf_advance(e, sizeof(*ms))) == NULL)
+ if ((ms = ibuf_reserve(e, sizeof(*ms))) == NULL)
return (-1);
ms->msc_opcode = EAP_MSOPCODE_CHALLENGE;
ms->msc_id = eap->eap_id;
if ((e = ibuf_static()) == NULL)
return (-1);
- if ((resp = ibuf_advance(e, sizeof(*resp))) == NULL)
+ if ((resp = ibuf_reserve(e, sizeof(*resp))) == NULL)
goto done;
resp->eap_code = eap_code;
resp->eap_id = eap_id;
msg = " M=Welcome";
- if ((resp = ibuf_advance(eapmsg, sizeof(*resp))) == NULL)
+ if ((resp = ibuf_reserve(eapmsg, sizeof(*resp))) == NULL)
goto done;
resp->eap_code = EAP_CODE_REQUEST;
resp->eap_id = eap_id + 1;
success_size + strlen(msg));
resp->eap_type = EAP_TYPE_MSCHAP_V2;
- if ((mss = ibuf_advance(eapmsg, sizeof(*mss))) == NULL)
+ if ((mss = ibuf_reserve(eapmsg, sizeof(*mss))) == NULL)
goto done;
mss->mss_opcode = EAP_MSOPCODE_SUCCESS;
mss->mss_id = msr_id;
if ((eapmsg = ibuf_static()) == NULL)
return (-1);
- if ((resp = ibuf_advance(eapmsg, sizeof(*resp))) == NULL)
+ if ((resp = ibuf_reserve(eapmsg, sizeof(*resp))) == NULL)
goto done;
resp->eap_code = EAP_CODE_RESPONSE;
resp->eap_id = eap_id;
resp->eap_length = htobe16(sizeof(*resp) + sizeof(*ms));
resp->eap_type = EAP_TYPE_MSCHAP_V2;
- if ((ms = ibuf_advance(eapmsg, sizeof(*ms))) == NULL)
+ if ((ms = ibuf_reserve(eapmsg, sizeof(*ms))) == NULL)
goto done;
ms->ms_opcode = EAP_MSOPCODE_SUCCESS;
-/* $OpenBSD: ikev2.c,v 1.366 2023/05/23 13:12:19 claudio Exp $ */
+/* $OpenBSD: ikev2.c,v 1.367 2023/05/23 13:57:14 claudio Exp $ */
/*
* Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de>
if (cookie) {
if ((pld = ikev2_add_payload(buf)) == NULL)
goto done;
- if ((n = ibuf_advance(buf, sizeof(*n))) == NULL)
+ if ((n = ibuf_reserve(buf, sizeof(*n))) == NULL)
goto done;
n->n_protoid = IKEV2_SAPROTO_NONE;
n->n_spisize = 0;
/* KE payload */
if ((pld = ikev2_add_payload(buf)) == NULL)
goto done;
- if ((ke = ibuf_advance(buf, sizeof(*ke))) == NULL)
+ if ((ke = ibuf_reserve(buf, sizeof(*ke))) == NULL)
goto done;
if ((group = sa->sa_dhgroup) == NULL) {
log_debug("%s: invalid dh", __func__);
goto done;
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((cert = ibuf_advance(e, sizeof(*cert))) == NULL)
+ if ((cert = ibuf_reserve(e, sizeof(*cert))) == NULL)
goto done;
cert->cert_type = certid->id_type;
if (ibuf_cat(e, certid->id_buf) != 0)
goto done;
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((cert = ibuf_advance(e, sizeof(*cert))) == NULL)
+ if ((cert = ibuf_reserve(e, sizeof(*cert))) == NULL)
goto done;
cert->cert_type = sa->sa_scert[i].id_type;
if (ibuf_cat(e, sa->sa_scert[i].id_buf) != 0)
/* AUTH payload */
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((auth = ibuf_advance(e, sizeof(*auth))) == NULL)
+ if ((auth = ibuf_reserve(e, sizeof(*auth))) == NULL)
goto done;
auth->auth_method = sa->sa_localauth.id_type;
if (ibuf_cat(e, sa->sa_localauth.id_buf) != 0)
{
struct ike_header *hdr;
- if ((hdr = ibuf_advance(buf, sizeof(*hdr))) == NULL) {
+ if ((hdr = ibuf_reserve(buf, sizeof(*hdr))) == NULL) {
log_debug("%s: failed to add header", __func__);
return (NULL);
}
{
struct ikev2_payload *pld;
- if ((pld = ibuf_advance(buf, sizeof(*pld))) == NULL) {
+ if ((pld = ibuf_reserve(buf, sizeof(*pld))) == NULL) {
log_debug("%s: failed to add payload", __func__);
return (NULL);
}
bzero(&pooladdr, sizeof(pooladdr));
- if ((tsp = ibuf_advance(buf, sizeof(*tsp))) == NULL)
+ if ((tsp = ibuf_reserve(buf, sizeof(*tsp))) == NULL)
return (-1);
len = sizeof(*tsp);
return (-1);
TAILQ_FOREACH(tsi, tss, ts_entry) {
- if ((ts = ibuf_advance(buf, sizeof(*ts))) == NULL)
+ if ((ts = ibuf_reserve(buf, sizeof(*ts))) == NULL)
return (-1);
addr = &tsi->ts_addr;
ts->ts_type = IKEV2_TS_IPV4_ADDR_RANGE;
ts->ts_length = htobe16(sizeof(*ts) + 8);
- if ((ptr = ibuf_advance(buf, 8)) == NULL)
+ if ((ptr = ibuf_reserve(buf, 8)) == NULL)
return (-1);
in4 = (struct sockaddr_in *)&addr->addr;
ts->ts_type = IKEV2_TS_IPV6_ADDR_RANGE;
ts->ts_length = htobe16(sizeof(*ts) + 32);
- if ((ptr = ibuf_advance(buf, 32)) == NULL)
+ if ((ptr = ibuf_reserve(buf, 32)) == NULL)
return (-1);
in6 = (struct sockaddr_in6 *)&addr->addr;
if ((*pld = ikev2_add_payload(e)) == NULL)
return (-1);
- if ((cert = ibuf_advance(e, sizeof(*cert))) == NULL)
+ if ((cert = ibuf_reserve(e, sizeof(*cert))) == NULL)
return (-1);
cert->cert_type = type;
if ((*pld = ikev2_add_payload(e)) == NULL)
return (-1);
len = sizeof(*n) + sizeof(cpi) + sizeof(transform);
- if ((ptr = ibuf_advance(e, len)) == NULL)
+ if ((ptr = ibuf_reserve(e, len)) == NULL)
return (-1);
n = (struct ikev2_notify *)ptr;
n->n_protoid = 0;
if ((*pld = ikev2_add_payload(e)) == NULL)
return (-1);
len = sizeof(*n);
- if ((n = ibuf_advance(e, len)) == NULL)
+ if ((n = ibuf_reserve(e, len)) == NULL)
return (-1);
n->n_protoid = 0;
n->n_spisize = 0;
/* NOTIFY payload */
if ((*pld = ikev2_add_payload(e)) == NULL)
return (-1);
- if ((ptr = ibuf_advance(e, len)) == NULL)
+ if ((ptr = ibuf_reserve(e, len)) == NULL)
return (-1);
n = (struct ikev2_notify *)ptr;
/* NAT-T notify payloads */
if ((*pld = ikev2_add_payload(buf)) == NULL)
return (-1);
- if ((n = ibuf_advance(buf, sizeof(*n))) == NULL)
+ if ((n = ibuf_reserve(buf, sizeof(*n))) == NULL)
return (-1);
n->n_type = htobe16(IKEV2_N_NAT_DETECTION_SOURCE_IP);
len = ikev2_nat_detection(env, msg, NULL, 0, 0, 0);
- if ((ptr = ibuf_advance(buf, len)) == NULL)
+ if ((ptr = ibuf_reserve(buf, len)) == NULL)
return (-1);
if ((len = ikev2_nat_detection(env, msg, ptr, len,
betoh16(n->n_type), 0)) == -1)
if ((*pld = ikev2_add_payload(buf)) == NULL)
return (-1);
- if ((n = ibuf_advance(buf, sizeof(*n))) == NULL)
+ if ((n = ibuf_reserve(buf, sizeof(*n))) == NULL)
return (-1);
n->n_type = htobe16(IKEV2_N_NAT_DETECTION_DESTINATION_IP);
len = ikev2_nat_detection(env, msg, NULL, 0, 0, 0);
- if ((ptr = ibuf_advance(buf, len)) == NULL)
+ if ((ptr = ibuf_reserve(buf, len)) == NULL)
return (-1);
if ((len = ikev2_nat_detection(env, msg, ptr, len,
betoh16(n->n_type), 0)) == -1)
int sent_addr4 = 0, sent_addr6 = 0;
int have_mask4 = 0, sent_mask4 = 0;
- if ((cp = ibuf_advance(buf, sizeof(*cp))) == NULL)
+ if ((cp = ibuf_reserve(buf, sizeof(*cp))) == NULL)
return (-1);
len = sizeof(*cp);
}
}
- if ((cfg = ibuf_advance(buf, sizeof(*cfg))) == NULL)
+ if ((cfg = ibuf_reserve(buf, sizeof(*cfg))) == NULL)
return (-1);
cfg->cfg_type = htobe16(ikecfg->cfg_type);
/* derive netmask from pool */
if (type == IKEV2_CP_REPLY && have_mask4 && !sent_mask4) {
- if ((cfg = ibuf_advance(buf, sizeof(*cfg))) == NULL)
+ if ((cfg = ibuf_reserve(buf, sizeof(*cfg))) == NULL)
return (-1);
cfg->cfg_type = htobe16(IKEV2_CFG_INTERNAL_IP4_NETMASK);
len += sizeof(*cfg);
prop->prop_localspi.spi_protoid = prop->prop_protoid;
}
- if ((sap = ibuf_advance(buf, sizeof(*sap))) == NULL) {
+ if ((sap = ibuf_reserve(buf, sizeof(*sap))) == NULL) {
log_debug("%s: failed to add proposal", __func__);
return (-1);
}
struct ikev2_transform *xfrm;
struct ikev2_attribute *attr;
- if ((xfrm = ibuf_advance(buf, sizeof(*xfrm))) == NULL) {
+ if ((xfrm = ibuf_reserve(buf, sizeof(*xfrm))) == NULL) {
log_debug("%s: failed to add transform", __func__);
return (-1);
}
if (length) {
xfrm->xfrm_length = htobe16(sizeof(*xfrm) + sizeof(*attr));
- if ((attr = ibuf_advance(buf, sizeof(*attr))) == NULL) {
+ if ((attr = ibuf_reserve(buf, sizeof(*attr))) == NULL) {
log_debug("%s: failed to add attribute", __func__);
return (-1);
}
{
void *msgbuf;
- if ((msgbuf = ibuf_advance(buf, length)) == NULL) {
+ if ((msgbuf = ibuf_reserve(buf, length)) == NULL) {
log_debug("%s: failed", __func__);
return (-1);
}
{
void *msgbuf;
- if ((msgbuf = ibuf_advance(buf, ibuf_size(data))) == NULL) {
+ if ((msgbuf = ibuf_reserve(buf, ibuf_size(data))) == NULL) {
log_debug("%s: failed", __func__);
return (-1);
}
}
if ((pld = ikev2_add_payload(buf)) == NULL)
goto done;
- if ((n = ibuf_advance(buf, sizeof(*n))) == NULL)
+ if ((n = ibuf_reserve(buf, sizeof(*n))) == NULL)
goto done;
n->n_protoid = IKEV2_SAPROTO_IKE;
n->n_spisize = 0;
goto done;
*firstpayload = IKEV2_PAYLOAD_DELETE;
- if ((localdel = ibuf_advance(resp, sizeof(*localdel))) == NULL)
+ if ((localdel = ibuf_reserve(resp, sizeof(*localdel))) == NULL)
goto done;
localdel->del_protoid = msg->msg_del_protoid;
/* KE payload */
if ((pld = ikev2_add_payload(buf)) == NULL)
goto done;
- if ((ke = ibuf_advance(buf, sizeof(*ke))) == NULL)
+ if ((ke = ibuf_reserve(buf, sizeof(*ke))) == NULL)
goto done;
if ((group = sa->sa_dhgroup) == NULL) {
log_debug("%s: invalid dh", __func__);
/* Notify payload */
if ((buf = ibuf_static()) == NULL)
goto done;
- if ((n = ibuf_advance(buf, sizeof(*n))) == NULL)
+ if ((n = ibuf_reserve(buf, sizeof(*n))) == NULL)
goto done;
n->n_protoid = IKEV2_SAPROTO_IKE;
n->n_spisize = 0;
log_info("%s: %s", SPI_SA(msg->msg_sa, __func__),
print_map(msg->msg_error, ikev2_n_map));
len = sizeof(*n);
- if ((ptr = ibuf_advance(buf, len)) == NULL)
+ if ((ptr = ibuf_reserve(buf, len)) == NULL)
return (-1);
n = (struct ikev2_notify *)ptr;
n->n_type = htobe16(msg->msg_error);
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((cert = ibuf_advance(e, sizeof(*cert))) == NULL)
+ if ((cert = ibuf_reserve(e, sizeof(*cert))) == NULL)
goto done;
cert->cert_type = certid->id_type;
if (ibuf_cat(e, certid->id_buf) != 0)
goto done;
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((cert = ibuf_advance(e,
+ if ((cert = ibuf_reserve(e,
sizeof(*cert))) == NULL)
goto done;
cert->cert_type = sa->sa_scert[i].id_type;
/* AUTH payload */
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((auth = ibuf_advance(e, sizeof(*auth))) == NULL)
+ if ((auth = ibuf_reserve(e, sizeof(*auth))) == NULL)
goto done;
auth->auth_method = sa->sa_localauth.id_type;
if (ibuf_cat(e, sa->sa_localauth.id_buf) != 0)
/* KE payload */
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((ke = ibuf_advance(e, sizeof(*ke))) == NULL)
+ if ((ke = ibuf_reserve(e, sizeof(*ke))) == NULL)
goto done;
if ((group = sa->sa_dhgroup) == NULL) {
log_debug("%s: invalid dh", __func__);
/* REKEY_SA notification */
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((n = ibuf_advance(e, sizeof(*n))) == NULL)
+ if ((n = ibuf_reserve(e, sizeof(*n))) == NULL)
goto done;
n->n_type = htobe16(IKEV2_N_REKEY_SA);
n->n_protoid = rekey->spi_protoid;
n->n_spisize = rekey->spi_size;
- if ((ptr = ibuf_advance(e, rekey->spi_size)) == NULL)
+ if ((ptr = ibuf_reserve(e, rekey->spi_size)) == NULL)
goto done;
len = rekey->spi_size;
spi = htobe32((uint32_t)csa->csa_peerspi);
/* KE payload */
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((ke = ibuf_advance(e, sizeof(*ke))) == NULL)
+ if ((ke = ibuf_reserve(e, sizeof(*ke))) == NULL)
goto done;
if ((group = nsa->sa_dhgroup) == NULL) {
log_debug("%s: invalid dh", __func__);
if ((buf = ibuf_static()) == NULL)
goto done;
- if ((del = ibuf_advance(buf, sizeof(*del))) == NULL)
+ if ((del = ibuf_reserve(buf, sizeof(*del))) == NULL)
goto done;
del->del_protoid = prop->prop_protoid;
/* Send PAYLOAD_DELETE */
if ((buf = ibuf_static()) == NULL)
goto done;
- if ((del = ibuf_advance(buf, sizeof(*del))) == NULL)
+ if ((del = ibuf_reserve(buf, sizeof(*del))) == NULL)
goto done;
del->del_protoid = IKEV2_SAPROTO_IKE;
del->del_spisize = 0;
/* KE payload */
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((ke = ibuf_advance(e, sizeof(*ke))) == NULL)
+ if ((ke = ibuf_reserve(e, sizeof(*ke))) == NULL)
goto done;
if (kex->kex_dhgroup == NULL) {
log_debug("%s: invalid dh", __func__);
if ((pld = ikev2_add_payload(e)) == NULL)
goto done;
- if ((n = ibuf_advance(e, sizeof(*n))) == NULL)
+ if ((n = ibuf_reserve(e, sizeof(*n))) == NULL)
goto done;
n->n_protoid = IKEV2_SAPROTO_IKE; /* XXX ESP etc. */
n->n_spisize = 0;
return (0);
if ((buf = ibuf_static()) == NULL)
return (-1);
- if ((del = ibuf_advance(buf, sizeof(*del))) == NULL)
+ if ((del = ibuf_reserve(buf, sizeof(*del))) == NULL)
goto done;
/* XXX we assume all have the same protoid */
del->del_protoid = protoid;
if ((buf = ibuf_static()) == NULL)
return (0);
- if ((del = ibuf_advance(buf, sizeof(*del))) == NULL)
+ if ((del = ibuf_reserve(buf, sizeof(*del))) == NULL)
goto done;
del->del_protoid = drop->spi_protoid;
del->del_spisize = 4;