Like ospfd use ibuf_data() consistently, also use ibuf_size() instead of
ibuf->wpos and ibuf_left() to check if there is enough space left.

-- 
:wq Claudio

Index: lsreq.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/lsreq.c,v
retrieving revision 1.14
diff -u -p -r1.14 lsreq.c
--- lsreq.c     8 Mar 2023 04:43:14 -0000       1.14
+++ lsreq.c     19 Apr 2023 13:13:01 -0000
@@ -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;
Index: lsupdate.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/lsupdate.c,v
retrieving revision 1.23
diff -u -p -r1.23 lsupdate.c
--- lsupdate.c  21 Jun 2023 07:45:47 -0000      1.23
+++ lsupdate.c  30 Jun 2023 08:10:37 -0000
@@ -194,7 +194,7 @@ add_ls_update(struct ibuf *buf, struct i
        size_t          ageoff;
        u_int16_t       age;
 
-       if (buf->wpos + len >= buf->max)
+       if (len >= ibuf_left(buf))
                return (0);
 
        ageoff = ibuf_size(buf);
Index: ospfe.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/ospfe.c,v
retrieving revision 1.69
diff -u -p -r1.69 ospfe.c
--- ospfe.c     21 Jun 2023 07:45:47 -0000      1.69
+++ ospfe.c     30 Jun 2023 08:58:37 -0000
@@ -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);
 }
Index: packet.c
===================================================================
RCS file: /cvs/src/usr.sbin/ospf6d/packet.c,v
retrieving revision 1.21
diff -u -p -r1.21 packet.c
--- packet.c    21 Jun 2023 07:45:47 -0000      1.21
+++ packet.c    30 Jun 2023 08:59:02 -0000
@@ -103,7 +103,7 @@ send_packet(struct iface *iface, struct 
                        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);

Reply via email to