From: claudio Date: Mon, 3 Jul 2023 09:51:38 +0000 (+0000) Subject: Use ibuf_data() instead of direct access to ibuf->buf, X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=bf2cf3053df3551d6121df7fcab39bf211c112b2;p=openbsd Use ibuf_data() instead of direct access to ibuf->buf, use ibuf_size() instead of direct access to ibuf->wpos, use ibuf_left() in places where the code checks if there is enough space left in the ibuf. OK tb@ --- diff --git a/usr.sbin/ospf6d/lsreq.c b/usr.sbin/ospf6d/lsreq.c index 29d4133b8b4..fff9ac63eaf 100644 --- a/usr.sbin/ospf6d/lsreq.c +++ b/usr.sbin/ospf6d/lsreq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsreq.c,v 1.14 2023/03/08 04:43:14 guenther Exp $ */ +/* $OpenBSD: lsreq.c,v 1.15 2023/07/03 09:51:38 claudio Exp $ */ /* * Copyright (c) 2004, 2005, 2007 Esben Norby @@ -59,8 +59,9 @@ send_ls_req(struct nbr *nbr) goto fail; /* LSA header(s) */ - for (le = TAILQ_FIRST(&nbr->ls_req_list); le != NULL && - buf->wpos + sizeof(struct ls_req_hdr) < buf->max; le = nle) { + for (le = TAILQ_FIRST(&nbr->ls_req_list); + le != NULL && sizeof(ls_req_hdr) < ibuf_left(buf); + le = nle) { nbr->ls_req = nle = TAILQ_NEXT(le, entry); ls_req_hdr.zero = 0; ls_req_hdr.type = le->le_lsa->type; diff --git a/usr.sbin/ospf6d/lsupdate.c b/usr.sbin/ospf6d/lsupdate.c index 3873771a7f4..935b3de97ce 100644 --- a/usr.sbin/ospf6d/lsupdate.c +++ b/usr.sbin/ospf6d/lsupdate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lsupdate.c,v 1.23 2023/06/21 07:45:47 claudio Exp $ */ +/* $OpenBSD: lsupdate.c,v 1.24 2023/07/03 09:51:38 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -194,7 +194,7 @@ add_ls_update(struct ibuf *buf, struct iface *iface, void *data, u_int16_t len, size_t ageoff; u_int16_t age; - if (buf->wpos + len >= buf->max) + if (len >= ibuf_left(buf)) return (0); ageoff = ibuf_size(buf); diff --git a/usr.sbin/ospf6d/ospfe.c b/usr.sbin/ospf6d/ospfe.c index bb8eb975bd2..e10926de61f 100644 --- a/usr.sbin/ospf6d/ospfe.c +++ b/usr.sbin/ospf6d/ospfe.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ospfe.c,v 1.69 2023/06/21 07:45:47 claudio Exp $ */ +/* $OpenBSD: ospfe.c,v 1.70 2023/07/03 09:51:38 claudio Exp $ */ /* * Copyright (c) 2005 Claudio Jeker @@ -954,18 +954,18 @@ orig_rtr_lsa(struct area *area) lsa_hdr.ls_id = 0; lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr; lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); - lsa_hdr.len = htons(buf->wpos); + lsa_hdr.len = htons(ibuf_size(buf)); lsa_hdr.ls_chksum = 0; /* updated later */ if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1) fatal("orig_rtr_lsa: ibuf_set failed"); - chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET); + chksum = iso_cksum(ibuf_data(buf), ibuf_size(buf), LS_CKSUM_OFFSET); if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1) fatal("orig_rtr_lsa: ibuf_set_n16 failed"); if (self) imsg_compose_event(iev_rde, IMSG_LS_UPD, self->peerid, 0, - -1, buf->buf, buf->wpos); + -1, ibuf_data(buf), ibuf_size(buf)); else log_warnx("orig_rtr_lsa: empty area %s", inet_ntoa(area->id)); @@ -1018,7 +1018,7 @@ orig_net_lsa(struct iface *iface) lsa_hdr.ls_id = htonl(iface->ifindex); lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr; lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); - lsa_hdr.len = htons(buf->wpos); + lsa_hdr.len = htons(ibuf_size(buf)); lsa_hdr.ls_chksum = 0; /* updated later */ if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1) fatal("orig_net_lsa: ibuf_set failed"); @@ -1027,12 +1027,12 @@ orig_net_lsa(struct iface *iface) if (ibuf_set(buf, sizeof(lsa_hdr), &lsa_net, sizeof(lsa_net)) == -1) fatal("orig_net_lsa: ibuf_set failed"); - chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET); + chksum = iso_cksum(ibuf_data(buf), ibuf_size(buf), LS_CKSUM_OFFSET); if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1) fatal("orig_net_lsa: ibuf_set_n16 failed"); imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0, - -1, buf->buf, buf->wpos); + -1, ibuf_data(buf), ibuf_size(buf)); ibuf_free(buf); } @@ -1116,17 +1116,17 @@ orig_link_lsa(struct iface *iface) lsa_hdr.ls_id = htonl(iface->ifindex); lsa_hdr.adv_rtr = oeconf->rtr_id.s_addr; lsa_hdr.seq_num = htonl(INIT_SEQ_NUM); - lsa_hdr.len = htons(buf->wpos); + lsa_hdr.len = htons(ibuf_size(buf)); lsa_hdr.ls_chksum = 0; /* updated later */ if (ibuf_set(buf, 0, &lsa_hdr, sizeof(lsa_hdr)) == -1) fatal("orig_link_lsa: ibuf_set failed"); - chksum = iso_cksum(buf->buf, buf->wpos, LS_CKSUM_OFFSET); + chksum = iso_cksum(ibuf_data(buf), ibuf_size(buf), LS_CKSUM_OFFSET); if (ibuf_set_n16(buf, LS_CKSUM_OFFSET, chksum) == -1) fatal("orig_link_lsa: ibuf_set_n16 failed"); imsg_compose_event(iev_rde, IMSG_LS_UPD, iface->self->peerid, 0, - -1, buf->buf, buf->wpos); + -1, ibuf_data(buf), ibuf_size(buf)); ibuf_free(buf); } diff --git a/usr.sbin/ospf6d/packet.c b/usr.sbin/ospf6d/packet.c index 26a54ad4ddf..2ed0e4361bb 100644 --- a/usr.sbin/ospf6d/packet.c +++ b/usr.sbin/ospf6d/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.21 2023/06/21 07:45:47 claudio Exp $ */ +/* $OpenBSD: packet.c,v 1.22 2023/07/03 09:51:38 claudio Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby @@ -103,7 +103,7 @@ send_packet(struct iface *iface, struct ibuf *buf, return (-1); } - if (sendto(iface->fd, buf->buf, ibuf_size(buf), 0, + if (sendto(iface->fd, ibuf_data(buf), ibuf_size(buf), 0, (struct sockaddr *)&sa6, sizeof(sa6)) == -1) { log_warn("send_packet: error sending packet on interface %s", iface->name);