diff options
-rw-r--r-- | sbin/iked/eap.c | 24 | ||||
-rw-r--r-- | sbin/iked/iked.h | 3 | ||||
-rw-r--r-- | sbin/iked/ikev2.c | 92 | ||||
-rw-r--r-- | sbin/iked/ikev2_msg.c | 10 | ||||
-rw-r--r-- | sbin/iked/imsg_util.c | 10 |
5 files changed, 66 insertions, 73 deletions
diff --git a/sbin/iked/eap.c b/sbin/iked/eap.c index 013805434b6..06db86d376e 100644 --- a/sbin/iked/eap.c +++ b/sbin/iked/eap.c @@ -1,4 +1,4 @@ -/* $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> @@ -51,7 +51,7 @@ eap_add_id_request(struct ibuf *e) { 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; @@ -124,7 +124,7 @@ eap_identity_request(struct iked *env, struct iked_sa *sa) /* 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) @@ -139,7 +139,7 @@ eap_identity_request(struct iked *env, struct iked_sa *sa) 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) @@ -154,7 +154,7 @@ eap_identity_request(struct iked *env, struct iked_sa *sa) /* 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) @@ -193,7 +193,7 @@ eap_challenge_request(struct iked *env, struct iked_sa *sa, 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; @@ -205,7 +205,7 @@ eap_challenge_request(struct iked *env, struct iked_sa *sa, 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; @@ -244,7 +244,7 @@ eap_message_send(struct iked *env, struct iked_sa *sa, int eap_code, int 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; @@ -278,7 +278,7 @@ eap_mschap_challenge(struct iked *env, struct iked_sa *sa, int 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; @@ -286,7 +286,7 @@ eap_mschap_challenge(struct iked *env, struct iked_sa *sa, int eap_id, 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; @@ -314,13 +314,13 @@ eap_mschap_success(struct iked *env, struct iked_sa *sa, int eap_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; diff --git a/sbin/iked/iked.h b/sbin/iked/iked.h index 76bf8625867..059c1fe0a20 100644 --- a/sbin/iked/iked.h +++ b/sbin/iked/iked.h @@ -1,4 +1,4 @@ -/* $OpenBSD: iked.h,v 1.212 2023/05/23 13:12:19 claudio Exp $ */ +/* $OpenBSD: iked.h,v 1.213 2023/05/23 13:57:14 claudio Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -1280,7 +1280,6 @@ struct ibuf * struct ibuf * ibuf_random(size_t); int ibuf_prepend(struct ibuf *, void *, size_t); -void *ibuf_advance(struct ibuf *, size_t); int ibuf_strcat(struct ibuf **, const char *); int ibuf_strlen(struct ibuf *); diff --git a/sbin/iked/ikev2.c b/sbin/iked/ikev2.c index 04e905b849c..9a63edff58d 100644 --- a/sbin/iked/ikev2.c +++ b/sbin/iked/ikev2.c @@ -1,4 +1,4 @@ -/* $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> @@ -1414,7 +1414,7 @@ ikev2_init_ike_sa_peer(struct iked *env, struct iked_policy *pol, 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; @@ -1444,7 +1444,7 @@ ikev2_init_ike_sa_peer(struct iked *env, struct iked_policy *pol, /* 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__); @@ -1618,7 +1618,7 @@ ikev2_init_ike_auth(struct iked *env, struct iked_sa *sa) 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) @@ -1633,7 +1633,7 @@ ikev2_init_ike_auth(struct iked *env, struct iked_sa *sa) 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) @@ -1658,7 +1658,7 @@ ikev2_init_ike_auth(struct iked *env, struct iked_sa *sa) /* 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) @@ -1869,7 +1869,7 @@ ikev2_add_header(struct ibuf *buf, struct iked_sa *sa, { 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); } @@ -1909,7 +1909,7 @@ ikev2_add_payload(struct ibuf *buf) { 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); } @@ -1938,7 +1938,7 @@ ikev2_add_ts_payload(struct ibuf *buf, unsigned int type, struct iked_sa *sa) 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); @@ -1962,7 +1962,7 @@ ikev2_add_ts_payload(struct ibuf *buf, unsigned int type, struct iked_sa *sa) 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; @@ -1989,7 +1989,7 @@ ikev2_add_ts_payload(struct ibuf *buf, unsigned int type, struct iked_sa *sa) 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; @@ -2008,7 +2008,7 @@ ikev2_add_ts_payload(struct ibuf *buf, unsigned int type, struct iked_sa *sa) 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; @@ -2083,7 +2083,7 @@ ikev2_add_certreq(struct ibuf *e, struct ikev2_payload **pld, ssize_t len, 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; @@ -2149,7 +2149,7 @@ ikev2_add_ipcompnotify(struct iked *env, struct ibuf *e, 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; @@ -2175,7 +2175,7 @@ ikev2_add_notify(struct ibuf *e, struct ikev2_payload **pld, ssize_t len, 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; @@ -2235,7 +2235,7 @@ ikev2_add_sighashnotify(struct ibuf *e, struct ikev2_payload **pld, /* 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; @@ -2397,11 +2397,11 @@ ikev2_add_nat_detection(struct iked *env, struct ibuf *buf, /* 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) @@ -2413,11 +2413,11 @@ ikev2_add_nat_detection(struct iked *env, struct ibuf *buf, 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) @@ -2442,7 +2442,7 @@ ikev2_add_cp(struct iked *env, struct iked_sa *sa, int type, struct ibuf *buf) 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); @@ -2474,7 +2474,7 @@ ikev2_add_cp(struct iked *env, struct iked_sa *sa, int type, struct ibuf *buf) } } - 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); @@ -2569,7 +2569,7 @@ ikev2_add_cp(struct iked *env, struct iked_sa *sa, int type, struct ibuf *buf) /* 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); @@ -2647,7 +2647,7 @@ ikev2_add_proposals(struct iked *env, struct iked_sa *sa, struct ibuf *buf, 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); } @@ -2751,7 +2751,7 @@ ikev2_add_transform(struct ibuf *buf, 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); } @@ -2762,7 +2762,7 @@ ikev2_add_transform(struct ibuf *buf, 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); } @@ -2780,7 +2780,7 @@ ikev2_add_data(struct ibuf *buf, void *data, size_t length) { void *msgbuf; - if ((msgbuf = ibuf_advance(buf, length)) == NULL) { + if ((msgbuf = ibuf_reserve(buf, length)) == NULL) { log_debug("%s: failed", __func__); return (-1); } @@ -2794,7 +2794,7 @@ ikev2_add_buf(struct ibuf *buf, struct ibuf *data) { 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); } @@ -2846,7 +2846,7 @@ ikev2_resp_informational(struct iked *env, struct iked_sa *sa, } 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; @@ -3117,7 +3117,7 @@ ikev2_handle_delete(struct iked *env, struct iked_message *msg, 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; @@ -3363,7 +3363,7 @@ ikev2_resp_ike_sa_init(struct iked *env, struct iked_message *msg) /* 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__); @@ -3464,7 +3464,7 @@ ikev2_send_auth_failed(struct iked *env, struct iked_sa *sa) /* 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; @@ -3519,7 +3519,7 @@ ikev2_add_error(struct iked *env, struct ibuf *buf, struct iked_message *msg) 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); @@ -3896,7 +3896,7 @@ ikev2_resp_ike_auth(struct iked *env, struct iked_sa *sa) 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) @@ -3911,7 +3911,7 @@ ikev2_resp_ike_auth(struct iked *env, struct iked_sa *sa) 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; @@ -3930,7 +3930,7 @@ ikev2_resp_ike_auth(struct iked *env, struct iked_sa *sa) /* 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) @@ -4175,7 +4175,7 @@ ikev2_send_create_child_sa(struct iked *env, struct iked_sa *sa, /* 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__); @@ -4197,12 +4197,12 @@ ikev2_send_create_child_sa(struct iked *env, struct iked_sa *sa, /* 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); @@ -4308,7 +4308,7 @@ ikev2_ike_sa_rekey(struct iked *env, void *arg) /* 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__); @@ -4558,7 +4558,7 @@ ikev2_init_create_child_sa(struct iked *env, struct iked_message *msg) 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; @@ -4757,7 +4757,7 @@ ikev2_ikesa_delete(struct iked *env, struct iked_sa *sa, int initiator) /* 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; @@ -5043,7 +5043,7 @@ ikev2_resp_create_child_sa(struct iked *env, struct iked_message *msg) /* 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__); @@ -5255,7 +5255,7 @@ ikev2_send_informational(struct iked *env, struct iked_message *msg) 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; @@ -6055,7 +6055,7 @@ ikev2_childsa_delete_proposed(struct iked *env, struct iked_sa *sa, 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; @@ -6850,7 +6850,7 @@ ikev2_child_sa_drop(struct iked *env, struct iked_spi *drop) 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; diff --git a/sbin/iked/ikev2_msg.c b/sbin/iked/ikev2_msg.c index d279d9fb86f..a3fe326e7ec 100644 --- a/sbin/iked/ikev2_msg.c +++ b/sbin/iked/ikev2_msg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ikev2_msg.c,v 1.91 2023/05/23 13:12:19 claudio Exp $ */ +/* $OpenBSD: ikev2_msg.c,v 1.92 2023/05/23 13:57:14 claudio Exp $ */ /* * Copyright (c) 2019 Tobias Heider <tobias.heider@stusta.de> @@ -425,7 +425,7 @@ ikev2_msg_encrypt(struct iked *env, struct iked_sa *sa, struct ibuf *src, * Pad the payload and encrypt it */ if (pad) { - if ((ptr = ibuf_advance(src, pad)) == NULL) + if ((ptr = ibuf_reserve(src, pad)) == NULL) goto done; arc4random_buf(ptr, pad); } @@ -470,7 +470,7 @@ ikev2_msg_encrypt(struct iked *env, struct iked_sa *sa, struct ibuf *src, if (outlen && ibuf_add(dst, ibuf_data(out), outlen) != 0) goto done; - if ((ptr = ibuf_advance(dst, integrlen)) == NULL) + if ((ptr = ibuf_reserve(dst, integrlen)) == NULL) goto done; explicit_bzero(ptr, integrlen); @@ -852,7 +852,7 @@ ikev2_send_encrypted_fragments(struct iked *env, struct iked_sa *sa, goto done; /* Fragment header */ - if ((frag = ibuf_advance(buf, sizeof(*frag))) == NULL) { + if ((frag = ibuf_reserve(buf, sizeof(*frag))) == NULL) { log_debug("%s: failed to add SKF fragment header", __func__); goto done; @@ -959,7 +959,7 @@ ikev2_msg_auth(struct iked *env, struct iked_sa *sa, int response) if (hash_keylength(sa->sa_prf) != hash_length(sa->sa_prf)) goto fail; - if ((ptr = ibuf_advance(authmsg, hash_keylength(sa->sa_prf))) == NULL) + if ((ptr = ibuf_reserve(authmsg, hash_keylength(sa->sa_prf))) == NULL) goto fail; hash_init(sa->sa_prf); diff --git a/sbin/iked/imsg_util.c b/sbin/iked/imsg_util.c index abbd3e5ef99..6774e2e3b89 100644 --- a/sbin/iked/imsg_util.c +++ b/sbin/iked/imsg_util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imsg_util.c,v 1.15 2023/05/23 13:12:19 claudio Exp $ */ +/* $OpenBSD: imsg_util.c,v 1.16 2023/05/23 13:57:14 claudio Exp $ */ /* * Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org> @@ -55,7 +55,7 @@ ibuf_new(const void *data, size_t len) return (buf); if (data == NULL) { - if (ibuf_advance(buf, len) == NULL) { + if (ibuf_reserve(buf, len) == NULL) { ibuf_free(buf); return (NULL); } @@ -75,12 +75,6 @@ ibuf_static(void) return ibuf_open(IKED_MSGBUF_MAX); } -void * -ibuf_advance(struct ibuf *buf, size_t len) -{ - return ibuf_reserve(buf, len); -} - size_t ibuf_length(struct ibuf *buf) { |